Map label names

parent 8722afa4
......@@ -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):
......
......@@ -19,143 +19,90 @@ class Registers(object):
}
zoneLabel = {
1: {"Send": "\x50\x00\x00\x10", "Receive": {"Start": 20, "Finish": 36}}, # I.e. get data from register \x50000010, extract text from posisiton 20 to 36
2: {"Send": "\x50\x00\x00\x10", "Receive": {"Start": 36, "Finish": 52}},
3: {"Send": "\x50\x00\x00\x30", "Receive": {"Start": 20, "Finish": 36}},
4: {"Send": "\x50\x00\x00\x30", "Receive": {"Start": 36, "Finish": 52}},
5: {"Send": "\x50\x00\x00\x50", "Receive": {"Start": 20, "Finish": 36}},
6: {"Send": "\x50\x00\x00\x50", "Receive": {"Start": 36, "Finish": 52}},
7: {"Send": "\x50\x00\x00\x70", "Receive": {"Start": 20, "Finish": 36}},
8: {"Send": "\x50\x00\x00\x70", "Receive": {"Start": 36, "Finish": 52}},
9: {"Send": "\x50\x00\x00\x90", "Receive": {"Start": 20, "Finish": 36}},
10: {"Send": "\x50\x00\x00\x90", "Receive": {"Start": 36, "Finish": 52}},
11: {"Send": "\x50\x00\x00\xb0", "Receive": {"Start": 20, "Finish": 36}},
12: {"Send": "\x50\x00\x00\xb0", "Receive": {"Start": 36, "Finish": 52}},
13: {"Send": "\x50\x00\x00\xd0", "Receive": {"Start": 20, "Finish": 36}},
14: {"Send": "\x50\x00\x00\xd0", "Receive": {"Start": 36, "Finish": 52}},
15: {"Send": "\x50\x00\x00\xf0", "Receive": {"Start": 20, "Finish": 36}},
16: {"Send": "\x50\x00\x00\xf0", "Receive": {"Start": 36, "Finish": 52}},
17: {"Send": "\x50\x00\x01\x10", "Receive": {"Start": 20, "Finish": 36}},
18: {"Send": "\x50\x00\x01\x10", "Receive": {"Start": 36, "Finish": 52}},
19: {"Send": "\x50\x00\x01\x30", "Receive": {"Start": 20, "Finish": 36}},
20: {"Send": "\x50\x00\x01\x30", "Receive": {"Start": 36, "Finish": 52}},
21: {"Send": "\x50\x00\x01\x50", "Receive": {"Start": 20, "Finish": 36}},
22: {"Send": "\x50\x00\x01\x50", "Receive": {"Start": 36, "Finish": 52}},
23: {"Send": "\x50\x00\x01\x70", "Receive": {"Start": 20, "Finish": 36}},
24: {"Send": "\x50\x00\x01\x70", "Receive": {"Start": 36, "Finish": 52}},
25: {"Send": "\x50\x00\x01\x90", "Receive": {"Start": 20, "Finish": 36}},
26: {"Send": "\x50\x00\x01\x90", "Receive": {"Start": 36, "Finish": 52}},
27: {"Send": "\x50\x00\x01\xb0", "Receive": {"Start": 20, "Finish": 36}},
28: {"Send": "\x50\x00\x01\xb0", "Receive": {"Start": 36, "Finish": 52}},
29: {"Send": "\x50\x00\x01\xd0", "Receive": {"Start": 20, "Finish": 36}},
30: {"Send": "\x50\x00\x01\xd0", "Receive": {"Start": 36, "Finish": 52}},
31: {"Send": "\x50\x00\x01\xf0", "Receive": {"Start": 20, "Finish": 36}},
32: {"Send": "\x50\x00\x01\xf0", "Receive": {"Start": 36, "Finish": 52}},
"\x00\x00\x10": [1,2],
"\x00\x00\x30": [3,4],
"\x00\x00\x50": [5,6],
"\x00\x00\x70": [7,8],
"\x00\x00\x90": [9,10],
"\x00\x00\xb0": [11,12],
"\x00\x00\xd0": [13,14],
"\x00\x00\xf0": [15,16],
"\x00\x01\x10": [17,18],
"\x00\x01\x30": [19,20],
"\x00\x01\x50": [21,22],
"\x00\x01\x70": [23,24],
"\x00\x01\x90": [25,26],
"\x00\x01\xb0": [27,28],
"\x00\x01\xd0": [29,30],
"\x00\x01\xf0": [31,32],
}
outputLabel = {
1: {"Send": "\x50\x00\x02\x10", "Receive": {"Start": 20, "Finish": 36}},
2: {"Send": "\x50\x00\x02\x10", "Receive": {"Start": 36, "Finish": 52}},
3: {"Send": "\x50\x00\x02\x30", "Receive": {"Start": 20, "Finish": 36}},
4: {"Send": "\x50\x00\x02\x30", "Receive": {"Start": 36, "Finish": 52}},
5: {"Send": "\x50\x00\x02\x50", "Receive": {"Start": 20, "Finish": 36}},
6: {"Send": "\x50\x00\x02\x50", "Receive": {"Start": 36, "Finish": 52}},
7: {"Send": "\x50\x00\x02\x70", "Receive": {"Start": 20, "Finish": 36}},
8: {"Send": "\x50\x00\x02\x70", "Receive": {"Start": 36, "Finish": 52}},
9: {"Send": "\x50\x00\x02\x90", "Receive": {"Start": 20, "Finish": 36}},
10: {"Send": "\x50\x00\x02\x90", "Receive": {"Start": 36, "Finish": 52}},
11: {"Send": "\x50\x00\x02\xb0", "Receive": {"Start": 20, "Finish": 36}},
12: {"Send": "\x50\x00\x02\xb0", "Receive": {"Start": 36, "Finish": 52}},
13: {"Send": "\x50\x00\x02\xd0", "Receive": {"Start": 20, "Finish": 36}},
14: {"Send": "\x50\x00\x02\xd0", "Receive": {"Start": 36, "Finish": 52}},
15: {"Send": "\x50\x00\x02\xf0", "Receive": {"Start": 20, "Finish": 36}},
16: {"Send": "\x50\x00\x02\xf0", "Receive": {"Start": 36, "Finish": 52}}
"\x00\x02\x10": [1,2],
"\x00\x02\x30": [3,4],
"\x00\x02\x50": [5,6],
"\x00\x02\x70": [7,8],
"\x00\x02\x90": [9,10],
"\x00\x02\xb0": [11,12],
"\x00\x02\xd0": [13,14],
"\x00\x02\xf0": [15,16],
}
partitionLabel = {
1: {"Send": "\x50\x00\x03\x10", "Receive": {"Start": 20, "Finish": 36}},
2: {"Send": "\x50\x00\x03\x10", "Receive": {"Start": 36, "Finish": 52}}
"\x00\x03\x10": [1,2],
}
userLabel = {
1: {"Send": "\x50\x00\x03\x30", "Receive": {"Start": 20, "Finish": 36}},
2: {"Send": "\x50\x00\x03\x30", "Receive": {"Start": 36, "Finish": 52}},
3: {"Send": "\x50\x00\x03\x50", "Receive": {"Start": 20, "Finish": 36}},
4: {"Send": "\x50\x00\x03\x50", "Receive": {"Start": 36, "Finish": 52}},
5: {"Send": "\x50\x00\x03\x70", "Receive": {"Start": 20, "Finish": 36}},
6: {"Send": "\x50\x00\x03\x70", "Receive": {"Start": 36, "Finish": 52}},
7: {"Send": "\x50\x00\x03\x90", "Receive": {"Start": 20, "Finish": 36}},
8: {"Send": "\x50\x00\x03\x90", "Receive": {"Start": 36, "Finish": 52}},
9: {"Send": "\x50\x00\x03\xb0", "Receive": {"Start": 20, "Finish": 36}},
10: {"Send": "\x50\x00\x03\xb0", "Receive": {"Start": 36, "Finish": 52}},
11: {"Send": "\x50\x00\x03\xd0", "Receive": {"Start": 20, "Finish": 36}},
12: {"Send": "\x50\x00\x03\xd0", "Receive": {"Start": 36, "Finish": 52}},
13: {"Send": "\x50\x00\x03\xf0", "Receive": {"Start": 20, "Finish": 36}},
14: {"Send": "\x50\x00\x03\xf0", "Receive": {"Start": 36, "Finish": 52}},
15: {"Send": "\x50\x00\x04\x10", "Receive": {"Start": 20, "Finish": 36}},
16: {"Send": "\x50\x00\x04\x10", "Receive": {"Start": 36, "Finish": 52}},
17: {"Send": "\x50\x00\x04\x30", "Receive": {"Start": 20, "Finish": 36}},
18: {"Send": "\x50\x00\x04\x30", "Receive": {"Start": 36, "Finish": 52}},
19: {"Send": "\x50\x00\x04\x50", "Receive": {"Start": 20, "Finish": 36}},
20: {"Send": "\x50\x00\x04\x50", "Receive": {"Start": 36, "Finish": 52}},
21: {"Send": "\x50\x00\x04\x70", "Receive": {"Start": 20, "Finish": 36}},
22: {"Send": "\x50\x00\x04\x70", "Receive": {"Start": 36, "Finish": 52}},
23: {"Send": "\x50\x00\x04\x90", "Receive": {"Start": 20, "Finish": 36}},
24: {"Send": "\x50\x00\x04\x90", "Receive": {"Start": 36, "Finish": 52}},
25: {"Send": "\x50\x00\x04\xb0", "Receive": {"Start": 20, "Finish": 36}},
26: {"Send": "\x50\x00\x04\xb0", "Receive": {"Start": 36, "Finish": 52}},
27: {"Send": "\x50\x00\x04\xd0", "Receive": {"Start": 20, "Finish": 36}},
28: {"Send": "\x50\x00\x04\xd0", "Receive": {"Start": 36, "Finish": 52}},
29: {"Send": "\x50\x00\x04\xf0", "Receive": {"Start": 20, "Finish": 36}},
30: {"Send": "\x50\x00\x04\xf0", "Receive": {"Start": 36, "Finish": 52}},
31: {"Send": "\x50\x00\x05\x10", "Receive": {"Start": 20, "Finish": 36}},
32: {"Send": "\x50\x00\x05\x10", "Receive": {"Start": 36, "Finish": 52}},
"\x00\x03\x30": [1,2],
"\x00\x03\x50": [3,4],
"\x00\x03\x70": [5,6],
"\x00\x03\x90": [7,8],
"\x00\x03\xb0": [9,10],
"\x00\x03\xd0": [11,12],
"\x00\x03\xf0": [13,14],
"\x00\x04\x10": [15,16],
"\x00\x04\x30": [17,18],
"\x00\x04\x50": [19,20],
"\x00\x04\x70": [21,22],
"\x00\x04\x90": [23,24],
"\x00\x04\xb0": [25,26],
"\x00\x04\xd0": [27,28],
"\x00\x04\xf0": [29,30],
"\x00\x05\x10": [31,32],
}
busModuleLabel = {
1: {"Send": "\x50\x00\x05\x30", "Receive": {"Start": 20, "Finish": 36}},
2: {"Send": "\x50\x00\x05\x30", "Receive": {"Start": 36, "Finish": 52}},
3: {"Send": "\x50\x00\x05\x50", "Receive": {"Start": 20, "Finish": 36}},
4: {"Send": "\x50\x00\x05\x50", "Receive": {"Start": 36, "Finish": 52}},
5: {"Send": "\x50\x00\x05\x70", "Receive": {"Start": 20, "Finish": 36}},
6: {"Send": "\x50\x00\x05\x70", "Receive": {"Start": 36, "Finish": 52}},
7: {"Send": "\x50\x00\x05\x90", "Receive": {"Start": 20, "Finish": 36}},
8: {"Send": "\x50\x00\x05\x90", "Receive": {"Start": 36, "Finish": 52}},
9: {"Send": "\x50\x00\x05\xb0", "Receive": {"Start": 20, "Finish": 36}},
10: {"Send": "\x50\x00\x05\xb0", "Receive": {"Start": 36, "Finish": 52}},
11: {"Send": "\x50\x00\x05\xd0", "Receive": {"Start": 20, "Finish": 36}},
12: {"Send": "\x50\x00\x05\xd0", "Receive": {"Start": 36, "Finish": 52}},
13: {"Send": "\x50\x00\x05\xf0", "Receive": {"Start": 20, "Finish": 36}},
14: {"Send": "\x50\x00\x05\xf0", "Receive": {"Start": 36, "Finish": 52}},
15: {"Send": "\x50\x00\x06\x10", "Receive": {"Start": 20, "Finish": 36}},
"\x00\x05\x30": [1,2],
"\x00\x05\x50": [3,4],
"\x00\x05\x70": [5,6],
"\x00\x05\x90": [7,8],
"\x00\x05\xb0": [9,10],
"\x00\x05\xd0": [11,12],
"\x00\x05\xf0": [13,14],
"\x00\x06\x10": [15,None],
}
wirelessRepeaterLabel = {
1: {"Send": "\x50\x00\x06\x10", "Receive": {"Start": 36, "Finish": 52}},
2: {"Send": "\x50\x00\x06\x30", "Receive": {"Start": 20, "Finish": 36}}
"\x00\x06\x10": [None,1],
"\x00\x06\x30": [2,None]
}
wirelessKeypadLabel = {
1: {"Send": "\x50\x00\x06\x30", "Receive": {"Start": 36, "Finish": 52}},
2: {"Send": "\x50\x00\x06\x50", "Receive": {"Start": 20, "Finish": 36}},
3: {"Send": "\x50\x00\x06\x50", "Receive": {"Start": 36, "Finish": 52}},
4: {"Send": "\x50\x00\x06\x70", "Receive": {"Start": 20, "Finish": 36}},
5: {"Send": "\x50\x00\x06\x70", "Receive": {"Start": 36, "Finish": 52}},
6: {"Send": "\x50\x00\x06\x90", "Receive": {"Start": 20, "Finish": 36}},
7: {"Send": "\x50\x00\x06\x90", "Receive": {"Start": 36, "Finish": 52}},
8: {"Send": "\x50\x00\x06\xb0", "Receive": {"Start": 20, "Finish": 36}}
"\x00\x06\x30": [None,1],
"\x00\x06\x50": [2,3],
"\x00\x06\x70": [4,5],
"\x00\x06\x90": [6,7],
"\x00\x06\xb0": [8,None]
}
siteNameLabel = {
1: {"Send": "\x50\x00\x06\xb0", "Receive": {"Start": 36, "Finish": 52}}
"\x00\x06\xb0": [None,1]
}
wirelessSirenLabel = {
1: {"Send": "\x50\x00\x06\xd0", "Receive": {"Start": 20, "Finish": 36}},
2: {"Send": "\x50\x00\x06\xd0", "Receive": {"Start": 36, "Finish": 52}},
3: {"Send": "\x50\x00\x06\xf0", "Receive": {"Start": 20, "Finish": 36}},
4: {"Send": "\x50\x00\x06\xf0", "Receive": {"Start": 36, "Finish": 52}}
"\x00\x06\xd0": [1,2],
"\x00\x06\xf0": [3,4],
}
controlOutput = {
......
......@@ -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=None):
self.sendqueue+=[{'msg': data, 'cb': callback, 'try': 3, 'expected_reply': expected_reply}]
def _queueSendData(self, data, callback=False, expected_reply=False, callback_args=False):
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%02X" % 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):
......
......@@ -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')
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