Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
Penguidom
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
domotika
Penguidom
Commits
5a6ea953
Commit
5a6ea953
authored
Jan 05, 2018
by
Franco (nextime) Lanza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Start reading from serial for paradox alarm
parent
a3197384
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
8 deletions
+60
-8
paradox.py
penguidom/plugins/paradox/paradox.py
+56
-5
penguidomd
penguidomd
+4
-3
No files found.
penguidom/plugins/paradox/paradox.py
View file @
5a6ea953
...
...
@@ -3,23 +3,74 @@ from zope.interface import implements
from
twisted.plugin
import
IPlugin
from
twisted.internet.serialport
import
SerialPort
from
twisted.
protocols.basic
import
LineReceiver
from
twisted.
internet.protocol
import
BaseProtocol
from
twisted.internet
import
reactor
import
serial
class
ParadoxProtocol
(
LineReceiver
):
SERIAL_PORT
=
"/dev/ttyUSB0"
BAUDRATE
=
9600
def
lineReceived
(
self
,
lin
e
):
print
line
def
format37ByteMessage
(
messag
e
):
checksum
=
0
if
len
(
message
)
%
37
!=
0
:
for
val
in
message
:
checksum
+=
ord
(
val
)
while
checksum
>
255
:
checksum
=
checksum
-
(
checksum
/
256
)
*
256
message
+=
bytes
(
bytearray
([
checksum
]))
# Add check to end of message
return
message
class
ParadoxProtocol
(
BaseProtocol
):
packet
=
[]
def
__init__
(
self
,
logger
,
core
):
self
.
log
=
logger
self
.
core
=
core
def
dataReceived
(
self
,
data
):
if
len
(
self
.
packet
)
<
37
:
self
.
packet
+=
[
data
]
if
len
(
self
.
packet
)
>=
37
:
self
.
log
.
debug
(
"RECEIVED: "
+
str
(
self
.
packet
))
self
.
packet
=
[]
def
connectionMade
(
self
):
self
.
log
.
info
(
"Serial port correctly connected"
)
self
.
login
()
def
login
(
self
):
message
=
'
\x72\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
'
self
.
transport
.
write
(
format37ByteMessage
(
message
))
class
Paradox
(
object
):
implements
(
IPlugin
,
imodules
.
IModules
)
def
_openSerial
(
self
,
port
=
SERIAL_PORT
,
retry
=
3
):
if
retry
>
0
:
try
:
self
.
port
=
SerialPort
(
ParadoxProtocol
(
self
.
log
,
self
.
core
),
port
,
reactor
,
baudrate
=
BAUDRATE
)
except
serial
.
SerialException
as
err
:
self
.
log
.
info
(
"Serial Port ERROR: "
+
str
(
err
))
reactor
.
callLater
(
1
,
self
.
_openSerial
,
port
,
retry
-
1
)
else
:
self
.
log
.
info
(
"Unable to open Serial Port: retry in 1 minute"
)
reactor
.
callLater
(
60
,
self
.
_openSerial
,
port
)
def
initialize
(
self
,
callback
,
logger
):
self
.
log
=
logger
self
.
core
=
callback
self
.
port
=
SerialPort
(
ParadoxProtocol
(),
'/dev/ttyUSB0'
,
reactor
)
logger
.
info
(
"Initialize Serial Connection..."
)
self
.
_openSerial
()
logger
.
info
(
"Plugin initialized"
)
...
...
penguidomd
View file @
5a6ea953
...
...
@@ -93,7 +93,8 @@ class penguidomDaemon(Daemonizer):
if
__name__
==
"__main__"
:
# Starting all loggers
# file di log da 100 mega, per 5 rotazioni
formatter
=
logging
.
Formatter
(
'
%(asctime)
s =>
%(name)-12
s:
%(levelname)-8
s
%(message)
s'
)
LOGFORMAT
=
'
%(asctime)
s =>
%(name)-12
s:
%(levelname)-8
s
%(message)
s'
formatter
=
logging
.
Formatter
(
LOGFORMAT
)
logdict
=
{
"corelog"
:
{
"file"
:
"penguidom.log"
,
"name"
:[(
"Core"
,
"general"
)]},
...
...
@@ -110,7 +111,7 @@ if __name__ == "__main__":
logdict
[
l
][
"handler"
]
.
setLevel
(
logging
.
DEBUG
)
logdict
[
l
][
"handler"
]
.
setFormatter
(
formatter
)
logging
.
basicConfig
()
logging
.
basicConfig
(
format
=
LOGFORMAT
)
log
=
logging
.
getLogger
(
'DaemonStarter'
)
log
.
addHandler
(
logdict
[
"corelog"
][
"handler"
])
...
...
@@ -127,7 +128,7 @@ if __name__ == "__main__":
lh
.
setLevel
(
loglevels
[
daemoncfg
.
get
(
n
[
1
],
'loglevel'
)]
)
lh
.
addHandler
(
logdict
[
l
][
"handler"
]
)
logging
.
basicConfig
()
logging
.
basicConfig
(
format
=
LOGFORMAT
)
# staring the application
if
len
(
sys
.
argv
)
>
1
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment