start checksumming and parsing messages

parent 5a6ea953
Byte Value Description
00 0xE0 High Nibble : Command
Low Nibble : Bit 3 - Event Report Enable (0) / Disable (1)
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
......@@ -6,23 +6,29 @@ from twisted.internet.serialport import SerialPort
from twisted.internet.protocol import BaseProtocol
from twisted.internet import reactor
import serial
import time
SERIAL_PORT="/dev/ttyUSB0"
BAUDRATE=9600
PKTTIMEOUT=2 # Seconds
def format37ByteMessage(message):
def checkSumCalc(message):
checksum = 0
return chr(sum(map(ord, m)) % 256)
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
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
......@@ -30,17 +36,38 @@ class ParadoxProtocol(BaseProtocol):
packet=[]
queue=[]
packettimeout = 0
waitreply = 0
def __init__(self, logger, core):
self.log = logger
self.core = core
def dataReceived(self, data):
if len(self.packet) < 37:
self.packet+=[data]
def _queueData(self):
if len(self.packet) >= 37:
self.log.debug("RECEIVED: "+str(self.packet))
self.packet=[]
if self.waitreply > 0:
self.waitreply-=1
packet="".join(self.packet[:37])
self.log.debug("MESSAGE QUEUED: "+''.join( [ "\\x%02X" % ord( x ) for x in packet ] ).strip()) #+str(packet).encode("hex"))
print packet
self.queue+=[packet]
self.packet=self.packet[37:]
reactor.callLater(0, self._queueData)
reactor.callLater(0, self._processQueue)
elif len(self.packet) > 0:
self.packettimeout = time.time()
def _processQueue(self):
pass
def dataReceived(self, data):
if len(self.packet) > 0 and (time.time()-self.packettimeout) > PKTTIMEOUT:
self.log.debug("Serial Timeout: discard packet "+''.join( [ "\\x%02X" % ord( x ) for x in self.packet ] ).strip())
self.packet = []
self.packet+=list(data)
self._queueData()
def connectionMade(self):
......@@ -48,8 +75,23 @@ class ParadoxProtocol(BaseProtocol):
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))
#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)
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)
message = '\x5f\x20\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.write(message)
def write(self, message):
if self.waitreply == 0:
self.transport.write(format37ByteMessage(message))
self.waitreply+=1
else:
reactor.callLater(0, self.write, message)
class Paradox(object):
implements(IPlugin, imodules.IModules)
......
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