Пример #1
0
 def __init__(self, long_id, short_id, dev_num, Procedures, ka_time_sec, update_needed):
     self._dev_type = _DeviceNames[3]
     Device.__init__(self, self._dev_type, long_id, short_id, dev_num, Procedures, ka_time_sec, update_needed)
     # delete source device
     # if device._dev_type != _DeviceNames[MOTION_CAMERA]:
     #     log.write("Incorrect device for motion camera")
     self.image_data = FAKE_IMAGE
     self.crc16 = prutils.chars_to_int(prutils.crc16(self.image_data)) # !!!??
     self.file_size = len(self.image_data)
     self.row = 1
     self.zone = 255
     self.files_amount = 10
Пример #2
0
 def dispatch_message(self, dpr_list):
     if not self._auto_response:
         return None
     # log.write('Device::dispatch_message')
     # dpr_list : ['\xA4\x00\x8E\x00\x00\x00\x04\x03\xF1\x01\x02','\x04\x00\xFF\x00\x00\x00\x04\x05\x3E\x03\x00\x84\x03']        
     response_amount = 0
     for dpr_msg in dpr_list:
         seq = ord(dpr_msg[2])
         mcode = ord(dpr_msg[6])
         tldv_len = ord(dpr_msg[7])
         tldv = dpr_msg[7 : 8 + tldv_len]
         log.write("device [%d:%d] got mcode[%d] type=%02X, tldv = %s, seq = %d" % \
             (self._short_id, self._long_id, mcode, ord(tldv[1]), prutils.hexdump(tldv), seq), "debug")
         if mcode == 0x04:
             # response_amount += 1
             if tldv[1] == '\xF1':
                 # log.write("set device state")
                 self._state = prutils.chars_to_int(tldv[3:].strip())
                 self.send_response(0x06, seq) #, response_amount)
                 # log.write("device [%d:%d]:state = %d, seq = %d" % (self._short_id, self._long_id, self._state, seq))
             elif tldv[1] == '\x3E':
                 # log.write("set notification period")
                 response_amount -= 1
                 notification_period = ord(tldv[3])
                 #log.write('** hello from [%d:%d] **' % (self._short_id, self._long_id))
                 self.send_hello(seq, notification_period)
                 #self._Procedures.hello(self._long_id, self._short_id, 0, notification_period)
             elif tldv[1] == '\xFC':
                 # log.write("set update config")
                 self.send_response(0x06, seq) #, response_amount)
                 # response comes first !!!
                 #response_amount -= 1
                 log.write('** update from [%d:%d] **' % (self._short_id, self._long_id))
                 self._Procedures.update(self._long_id, self._short_id)
             else:
                 # other set commands
                 self.send_response(0x06, seq) # , response_amount)
             # if response_amount > 0:
                 
         elif mcode == 5:
             if tldv[1] == '\x40': # hello
                 self.send_hello()
             # confirm to report
             self.send_response(0x07, seq)