Starting to build 37 byte protocol support lib

parent d4ddef56
......@@ -30,30 +30,13 @@ from twisted.internet import reactor
import serial
import time
import paradox37b as p37b
SERIAL_PORT="/dev/ttyUSB0"
BAUDRATE=9600
PKTTIMEOUT=2 # Seconds
def checkSumCalc(message):
checksum = 0
return chr(sum(map(ord, message)) % 256)
def checkSumTest(message):
if len(message) == 37:
if message[36] == checkSumCalc(message[:36]):
return True
return False
def format37ByteMessage(message):
checksum = 0
message = message.ljust(36, '\x00')
if len(message) % 37 != 0:
message += checkSumCalc(message) # Add check to end of message
return message
class ParadoxProtocol(BaseProtocol):
......@@ -65,6 +48,7 @@ class ParadoxProtocol(BaseProtocol):
def __init__(self, logger, core):
self.log = logger
self.core = core
reactor.addSystemEventTrigger('before', 'shutdown', self._terminating)
def _queueData(self):
if len(self.packet) >= 37:
......@@ -96,10 +80,15 @@ class ParadoxProtocol(BaseProtocol):
self.log.info("Serial port correctly connected")
self.login()
def _terminating(self, *a, **kw):
self.log.debug("Send Disconnect message")
self.write(p37b.MSG_DISCONNECT)
def connectionLost(self, reason):
self.log.debug("Connection lost for "+str(reason))
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'
message = '\x72'
self.write(message)
self.write(p37b.MSG_LOGIN)
message = '\x50\x00\x80\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.write(message)
......@@ -109,7 +98,7 @@ class ParadoxProtocol(BaseProtocol):
def write(self, message):
if self.waitreply == 0:
self.transport.write(format37ByteMessage(message))
self.transport.write(p37b.format37ByteMessage(message))
self.waitreply+=1
else:
reactor.callLater(0, self.write, message)
......
......@@ -48,9 +48,92 @@ print( "winload : %i" % flags.winload )
print( "neware : %i" % flags.neware )
"""
CMD_EVENT = 0xe
# This is the only message type we fully know how to parse, and lucky enough
# they are also really what you need to have.
# Byte Value Description
# 00 0xEX High Nibble : Command
# Low Nibble : Bit 3 - Event Report Enable (0) / Disable (1)
# Bit 2 - System in alarm
# Bit 1 - Winload connected
# Bit 0 - NEware connected
# 01 0xXX Century
# 02 0xXX Year
# 03 0xXX Month
# 04 0xXX Day
# 05 0xXX Hour
# 06 0xXX Minute
# 07 0xXX Event Group Number
# 08 0xXX Event Sub Group Number
# 09 0xXX Partition Number
# 10 0xXX Module Serial Number (Digit 1 and 2)
# 11 0xXX Module Serial Number (Digit 3 and 4)
# 12 0xXX Module Serial Number (Digit 5 and 6)
# 13 0xXX Module Serial Number (Digit 6 and 8)
# 14 0xXX Label Type
# 0 = Zone Label
# 1 = User Label
# 2 = Partition Label
# 3 = PGM Label
# 4 = Bus Module Label
# 5 = Wireless Repeater Label
# 6 = Wireless Keypad Label
# 15 0xXX Module / User / Partition Label Byte 00
# 16 0xXX Module / User / Partition Label Byte 01
# 17 0xXX Module / User / Partition Label Byte 02
# 18 0xXX Module / User / Partition Label Byte 03
# 19 0xXX Module / User / Partition Label Byte 04
# 20 0xXX Module / User / Partition Label Byte 05
# 21 0xXX Module / User / Partition Label Byte 06
# 22 0xXX Module / User / Partition Label Byte 07
# 23 0xXX Module / User / Partition Label Byte 08
# 24 0xXX Module / User / Partition Label Byte 09
# 25 0xXX Module / User / Partition Label Byte 10
# 26 0xXX Module / User / Partition Label Byte 11
# 27 0xXX Module / User / Partition Label Byte 12
# 28 0xXX Module / User / Partition Label Byte 13
# 29 0xXX Module / User / Partition Label Byte 14
# 30 0xXX Module / User / Partition Label Byte 15
# 31 0xXX Not Used (Reserved)
# 32 0xXX Not Used (Reserved)
# 33 0xXX Not Used (Reserved)
# 34 0xXX Not Used (Reserved)
# 35 0xXX Not Used (Reserved)
# 36 0xXX Checksum
def checkCmd(byte, cmd):
return (byte >> 4) == cmd
# XXX I don't really like i don't fully understand
# the meaning of some messages (yet?), but those are needed and i know
# what the give me back at least.
#
# To save computational timing there is no need to format those messages
# at runtime, as they are static, so, full string included here.
MSG_LOGIN= '\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'
MSG_DISCONNECT= '\x70\x00\x05\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\x01\x00\x00\x76'
def checkSumCalc(message):
checksum = 0
return chr(sum(map(ord, message)) % 256)
def checkSumTest(message):
if len(message) == 37:
if message[36] == checkSumCalc(message[:36]):
return True
return False
def format37ByteMessage(message):
checksum = 0
message = message.ljust(36, '\x00')
if len(message) % 37 != 0:
message += checkSumCalc(message) # Add check to end of message
return message
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment