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
eb80e75b
Commit
eb80e75b
authored
Jan 11, 2018
by
Franco (nextime) Lanza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Map label names
parent
8722afa4
Changes
4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
131 additions
and
144 deletions
+131
-144
mapping.py
penguidom/plugins/paradox/mapping.py
+1
-1
MG5050.py
penguidom/plugins/paradox/panels/MG5050.py
+68
-121
paradox.py
penguidom/plugins/paradox/paradox.py
+42
-19
paradox37b.py
penguidom/plugins/paradox/paradox37b.py
+20
-3
No files found.
penguidom/plugins/paradox/mapping.py
View file @
eb80e75b
...
...
@@ -155,7 +155,7 @@ class ParadoxRegisters(Singleton):
def
getzoneLabelRegister
(
self
):
return
self
.
registers
.
zoneLabel
def
getpartitionLabelRegister
():
def
getpartitionLabelRegister
(
self
):
return
self
.
registers
.
partitionLabel
def
getuserLabelRegister
(
self
):
...
...
penguidom/plugins/paradox/panels/MG5050.py
View file @
eb80e75b
This diff is collapsed.
Click to expand it.
penguidom/plugins/paradox/paradox.py
View file @
eb80e75b
...
...
@@ -39,10 +39,12 @@ from mapping import EVENTMAP, REGISTERS
SERIAL_PORT
=
"/dev/ttyS0"
BAUDRATE
=
9600
PKTTIMEOUT
=
2
# Seconds
REPLYTIMEOUT
=
1
# Seconds
BOARDTYPE
=
"MG5050"
# Just a default
PKTTIMEOUT
=
2
# Seconds before discard incorrect lenght packets
REPLYTIMEOUT
=
1
# Seconds before to start reply checks
SEND_INTERVAL
=
.5
# Seconds between messages sent
REPLY_INTERVAL
=
.3
# Seconds between reply checks
class
ParadoxProtocol
(
BaseProtocol
):
...
...
@@ -86,8 +88,8 @@ class ParadoxProtocol(BaseProtocol):
elif
len
(
self
.
packet
)
>
0
:
self
.
packettimeout
=
time
.
time
()
def
_queueSendData
(
self
,
data
,
callback
=
False
,
expected_reply
=
Non
e
):
self
.
sendqueue
+=
[{
'msg'
:
data
,
'cb'
:
callback
,
'try'
:
3
,
'expected_reply'
:
expected_reply
}]
def
_queueSendData
(
self
,
data
,
callback
=
False
,
expected_reply
=
False
,
callback_args
=
Fals
e
):
self
.
sendqueue
+=
[{
'msg'
:
data
,
'cb'
:
callback
,
'try'
:
3
,
'expected_reply'
:
expected_reply
,
'callback_args'
:
callback_args
}]
reactor
.
callLater
(
0
,
self
.
_processSendQueue
)
def
_processQueue
(
self
):
...
...
@@ -96,17 +98,17 @@ class ParadoxProtocol(BaseProtocol):
if
expected
:
if
isinstance
(
expected
,
(
list
,
tuple
)):
for
i
in
expected
:
if
p37b
.
checkCmd
(
replystart
,
i
):
if
p37b
.
checkCmd
(
replystart
,
i
,
nibble
=
True
):
return
True
else
:
if
p37b
.
checkCmd
(
replystart
,
expected
):
if
p37b
.
checkCmd
(
replystart
,
expected
,
nibble
=
True
):
return
True
else
:
return
True
return
False
if
len
(
self
.
queue
)
>
0
:
if
p37b
.
checkCmd
(
ord
(
self
.
queue
[
0
][
0
]),
p37b
.
CMD_EVENT
):
if
p37b
.
checkCmd
(
ord
(
self
.
queue
[
0
][
0
]),
p37b
.
CMD_EVENT
,
nibble
=
True
):
reactor
.
callLater
(
0
,
self
.
_processEvent
,
self
.
queue
[
0
])
else
:
if
len
(
self
.
replyqueue
)
>
0
:
...
...
@@ -116,7 +118,7 @@ class ParadoxProtocol(BaseProtocol):
# until the reply is received, but it would be more error
# prone that way...
if
self
.
replyqueue
[
0
][
'cb'
]
and
callable
(
self
.
replyqueue
[
0
][
'cb'
]):
reactor
.
callLater
(
0
,
self
.
replyqueue
[
0
][
'cb'
],
self
.
queue
[
0
])
reactor
.
callLater
(
0
,
self
.
replyqueue
[
0
][
'cb'
],
self
.
queue
[
0
]
,
self
.
replyqueue
[
0
][
'callback_args'
]
)
del
self
.
replyqueue
[
0
]
else
:
if
isinstance
(
self
.
replyqueue
[
0
][
'expected_reply'
],
(
list
,
tuple
)):
...
...
@@ -138,7 +140,7 @@ class ParadoxProtocol(BaseProtocol):
self
.
transport
.
write
(
packet
)
reactor
.
callLater
(
REPLYTIMEOUT
,
self
.
_checkReplies
)
else
:
reactor
.
callLater
(
.1
,
self
.
_processSendQueue
)
reactor
.
callLater
(
SEND_INTERVAL
,
self
.
_processSendQueue
)
def
_checkReplies
(
self
):
if
len
(
self
.
replyqueue
)
>
0
:
...
...
@@ -146,7 +148,7 @@ class ParadoxProtocol(BaseProtocol):
if
self
.
replyqueue
[
0
][
'try'
]
>
0
:
self
.
replyqueue
[
0
][
'try'
]
-=
1
self
.
sendqueue
+=
[
self
.
replyqueue
[
0
]]
reactor
.
callLater
(
.
1
,
self
.
_processSendQueue
,
False
)
reactor
.
callLater
(
.
3
,
self
.
_processSendQueue
,
False
)
else
:
self
.
log
.
error
(
"FAILED TO SEND MESSAGE: "
+
''
.
join
(
[
"
\\
x
%02
X"
%
ord
(
x
)
for
x
in
self
.
replyqueue
[
0
][
'msg'
]
]
)
.
strip
())
del
self
.
replyqueue
[
0
]
...
...
@@ -181,16 +183,16 @@ class ParadoxProtocol(BaseProtocol):
self
.
write
(
p37b
.
MSG_SYNC
,
self
.
_replySync
,
expected_reply
=
p37b
.
REPLY_SYNC
)
def
write
(
self
,
message
,
reply_callback
=
False
,
expected_reply
=
False
):
self
.
_queueSendData
(
p37b
.
format37ByteMessage
(
message
),
reply_callback
,
expected_reply
)
def
write
(
self
,
message
,
reply_callback
=
False
,
expected_reply
=
False
,
callback_args
=
False
):
self
.
_queueSendData
(
p37b
.
format37ByteMessage
(
message
),
reply_callback
,
expected_reply
,
callback_args
)
def
_replySync
(
self
,
reply
):
def
_replySync
(
self
,
reply
,
cbargs
):
self
.
log
.
debug
(
"REPLY SYNC RECEIVED"
)
self
.
write
(
reply
,
self
.
_endHandshacke
)
def
_endHandshacke
(
self
,
reply
=
None
):
def
_endHandshacke
(
self
,
reply
=
None
,
cbargs
=
None
):
# XXX Here things starts to get weird.
# I have no idea of what exactly those two messages do,
# but they seems to be needed for the initial handshake
...
...
@@ -199,11 +201,11 @@ class ParadoxProtocol(BaseProtocol):
#
# After the end of the handshake we proceed to map zone names,
# so, callback for last message drive the runflow in that direction.
self
.
write
(
p37b
.
MSG_UNKWNOWN_HS1
)
self
.
write
(
p37b
.
MSG_UNKWNOWN_HS2
,
self
.
mapNames
)
self
.
write
(
p37b
.
MSG_UNKWNOWN_HS1
,
expected_reply
=
p37b
.
REPLY_QUERY
)
self
.
write
(
p37b
.
MSG_UNKWNOWN_HS2
,
self
.
mapNames
,
expected_reply
=
p37b
.
REPLY_QUERY
)
def
_detectBoard
(
self
,
reply
):
def
_detectBoard
(
self
,
reply
,
cbargs
=
None
):
board
=
p37b
.
getPanelName
(
reply
)
self
.
log
.
info
(
'Detected Panel Board as '
+
board
)
if
self
.
autodetect
:
...
...
@@ -220,13 +222,34 @@ class ParadoxProtocol(BaseProtocol):
pass
def
mapNames
(
self
,
reply
=
None
):
def
_setNames
(
self
,
reply
,
item
):
if
item
in
REGISTERS
.
getsupportedItems
():
reglist
=
getattr
(
REGISTERS
,
'get'
+
item
+
'Register'
)()
setfunc
=
getattr
(
EVENTMAP
,
'set'
+
item
)
reg
=
reply
[
1
:
4
]
if
reg
in
reglist
.
keys
():
nums
=
reglist
[
reg
]
for
num
in
range
(
0
,
len
(
nums
)):
if
nums
[
num
]
is
not
None
:
label
=
reply
[
4
+
(
16
*
num
):
20
+
(
16
*
num
)]
.
strip
()
self
.
log
.
info
(
'Set label for '
+
item
+
' '
+
str
(
nums
[
num
])
+
' as
\"
'
+
label
+
'
\"
'
)
setfunc
(
nums
[
num
],
label
)
def
_mapItemNames
(
self
,
item
):
try
:
items
=
getattr
(
REGISTERS
,
'get'
+
item
+
'Register'
)()
for
i
in
items
.
keys
():
self
.
write
(
p37b
.
SEND_QUERY
+
i
,
self
.
_setNames
,
expected_reply
=
p37b
.
REPLY_QUERY
,
callback_args
=
item
)
except
:
self
.
log
.
error
(
"Cannot find item named "
+
item
+
" in registers"
)
def
mapNames
(
self
,
reply
=
None
,
cbargs
=
None
):
if
self
.
mapnames
:
self
.
log
.
info
(
"Start Mapping names..."
)
self
.
log
.
info
(
"Supported Items:"
)
for
i
in
REGISTERS
.
getsupportedItems
():
self
.
log
.
info
(
" "
+
i
)
reactor
.
callLater
(
0
,
self
.
_mapItemNames
,
i
)
class
ParadoxTCPProxy
(
Protocol
):
...
...
penguidom/plugins/paradox/paradox37b.py
View file @
eb80e75b
...
...
@@ -102,8 +102,17 @@ CMD_EVENT = 0xe
# 36 0xXX Checksum
def
checkCmd
(
byte
,
cmd
):
return
(
byte
>>
4
)
==
cmd
def
checkCmd
(
msg
,
cmd
,
nibble
=
False
):
if
isinstance
(
cmd
,
str
):
if
isinstance
(
msg
,
str
):
if
len
(
msg
)
>=
len
(
cmd
):
return
msg
[:
len
(
cmd
)]
==
cmd
return
False
if
isinstance
(
msg
,
str
):
msg
=
ord
(
msg
[
0
])
if
nibble
:
return
(
msg
>>
4
)
==
cmd
return
msg
==
cmd
# XXX I don't really like i don't fully understand
...
...
@@ -121,11 +130,17 @@ MSG_SYNC= '\x5F\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0
MSG_UNKWNOWN_HS1
=
'
\x50\x00\x1F\xE0\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\x4F
'
MSG_UNKWNOWN_HS2
=
'
\x50\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\x50
'
# Command sent starts with
SEND_QUERY
=
'
\x50
'
SEND_CONTROL
=
'
\x40
'
# Expected replies command
REPLY_CONNECT
=
0x7
REPLY_GETSTATUS
=
[
0x5
,
0x7
]
REPLY_SYNC
=
0x0
REPLY_QUERY
=
0x5
def
checkSumCalc
(
message
):
checksum
=
0
...
...
@@ -150,3 +165,5 @@ def getPanelName(message):
return
str
(
message
[
28
:
36
])
.
strip
(
'
\x00
'
)
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