def enroll_F0(long_id, dev_type, zone_num, customer_mid=0, customer_did=0): long_id = prutils.num_to_chars(long_id) if dev_type.upper() in _DeviceType: dev_type = _DeviceType[dev_type.upper()] else: raise Exception("Incorrect device type specified") return None # "32 01 00 [] 00 08 00 " $ iDeviceTypeNumber $ " " $ iDeviceSubTypeNumber $ " 01 14 03 00 00 01 03 00 00 00 02 07 00 70 09 28 03 08 01 C7 0A" rssi = "\x32" tx_power = "\x01" association_request_data = "\x00" attached_device_information = dev_type + "\x01\x14\x03\x00\x00" attached_device_information = "\x00" + chr(len(attached_device_information)) manufacturing_information = "\x01\x03" + chr(customer_mid) + prutils.num_to_chars(customer_did, 2, 0) rf_module_information = "\x02\x07\x00\x70\x09\x28\x03\x08\x01" data = ( "\x01" + chr(zone_num) + "\x22\x41" + long_id + rssi + tx_power + association_request_data + attached_device_information + manufacturing_information + rf_module_information ) packet = prutils.make_f0_packet(0x02, 0x33, data) return packet
def file_info(long_id, short_id, film_id, row, file_status, prime_file_id, secondary_file_id, frame_number, file_type,\ film_type, time_stamp, crc, index, zone, file_size, sequence=-1): data = chr(film_id) + chr(row) + chr(file_status) + chr(prime_file_id) + chr(secondary_file_id) + chr(frame_number) + \ chr(file_type) + chr(film_type) + prutils.num_to_chars(time_stamp, 4, 0) + prutils.num_to_chars(crc, 2 ,0) + \ chr(index) + chr(zone) + prutils.num_to_chars(file_size, 2, 0) packet = prutils.make_device_packet(long_id, short_id, Config.REPLY, 181, data, 0, 0, 0, 0, 1, 4, sequence) return packet
def enroll_to_zone(self, long_id, dev_type, zone_num): # non works on the GSM automation if (not self.is_AUTO_port_ready()): return False if (dev_type.upper() in _DeviceType): dev_type = _DeviceType[dev_type.upper()] else: log.wrte("Incorrect device type specified") return -1 if not (self.open_test_mode()): log.write("Can't open test mode") return -1 ack = '\x0D\xF0\x01\x43\x00\x00\x80\x40\x0A' enroll = '\x0D\xF0\x02\x00\x00\x26\x33\x01' + chr(zone_num) + '\x22\x41' + prutils.num_to_chars(long_id, 4, 0) + \ '\x32\x01\x00\x00\x08\x00' + dev_type + \ '\x01\x14\x03\x00\x00\x01\x03\x00\x00\x00\x02\x07\x00\x70\x09\x28\x03\x08\x01\xC7\x0A' crc = prutils.crc16_F0(enroll[1:]) enroll = enroll + prutils.num_to_chars(crc, 2, 0) + '\x0A' # enroll = dpr.enroll_F0(long_id, dev_type, zone_num) short_id = -1 self._Communicator.send(enroll) result = self._Communicator.wait(0x01, 3) if result and result == ack : result = self._Communicator.wait(0x04, 10) # enroll answer if result: if ord(result[7]) != 1: log.write('Device rejected') else: short_id = ord(result[13]) self._Communicator.send(ack) log.write('ShortId=%d' % short_id) else: log.write('Can\'t enroll device, no answer') else: log.write('Can\'t enroll device, no ACK') self.close_test_mode() return short_id pass
def request_configuration_data(self, short_id, long_id, parameter): if (not self.is_AUTO_port_ready()): return final_hop_info = '\x00\x00\x00\x00\x80\x00\x84\x00\x00\x00\x00' repeater_hop_info = '\x00' * 12 dpr_seq = prutils.generate_seq('dpr') hpr_seq = prutils.generate_seq('hpr') if parameter == 0x46: data = chr(short_id) + chr(hpr_seq) + chr(0xF8) + final_hop_info + repeater_hop_info\ + prutils.str_l('\x64\x00' + chr(dpr_seq) + prutils.num_to_chars(long_id, 3, 0) + "\x02\x02" + chr(parameter) + '\x00') else: data = chr(short_id) + chr(hpr_seq) + chr(0x30) + final_hop_info + repeater_hop_info\ + prutils.str_l('\x64\x00' + chr(dpr_seq) + prutils.num_to_chars(long_id, 3, 0) + "\x02\x02" + chr(parameter) + '\x00') packet = prutils.make_host_packet(0x30, data) self._Communicator.send(packet)
def film_info(long_id, short_id, film_id, film_status, film_type, pre_alarm_length, post_alarm_length,\ frame_rate, time_stamp, index, zone, files_amount): # film_status: # 0 does not exist # 1 existing, closed and permitted for delete # 2 existing, opened film # 3 existing, closed film # 4 error # print long_id, short_id, film_id, film_status, film_type, pre_alarm_length, post_alarm_length,\ # frame_rate, time_stamp, index, zone, files_amount # return data = chr(film_id) data += chr(film_status) data += chr(film_type) data += chr(pre_alarm_length) data += chr(post_alarm_length) data += chr(frame_rate) data += prutils.num_to_chars(time_stamp, 4, 0) data += chr(index) data += chr(zone) data += chr(files_amount) packet = prutils.make_device_packet(long_id, short_id, Config.REPORT, 180, data, 0, 1, 1, 1, 0) return packet
def enroll(long_id, dev_type, customer_mid=0, customer_did=0): serial_num = prutils.convert_longid(long_id) rssi = "\x32" tx_power = "\x01" association_request_data = "\x00" # TODO: Get device type if dev_type.upper() in _DeviceType: dev_type = _DeviceType[dev_type.upper()] else: raise Exception("Incorrect device type specified") return None attached_device_information = "\x00" + dev_type + "\x01\x14\x03\x00\x00" # Counting customer id manufacturing_information = chr(customer_mid) + prutils.num_to_chars(customer_did, 2, 0) rf_module_information = "\x00\x70\x09\x28\x03\x08\x01" packet = ( serial_num + rssi + tx_power + association_request_data + "\x00" + prutils.str_l(attached_device_information) + "\x01" + prutils.str_l(manufacturing_information) + "\x02" + prutils.str_l(rf_module_information) ) host_protocol_message = prutils.make_host_packet(0x41, packet, False) enroll_packet = "\x01" + host_protocol_message enroll_packet = prutils._make_f2_packet(enroll_packet, 13) return enroll_packet
def enroll(long_id, dev_type, customer_mid=0, customer_did=0): serial_num = prutils.convert_longid(long_id) rssi = '\x32' tx_power = '\x01' association_request_data = '\x00' #TODO: Get device type if (dev_type.upper() in _DeviceType): dev_type = _DeviceType[dev_type.upper()] else: raise Exception("Incorrect device type specified") return None attached_device_information = '\x00' + dev_type + '\x01\x14\x03\x00\x00' #Counting customer id manufacturing_information = chr(customer_mid) + prutils.num_to_chars( customer_did, 2, 0) rf_module_information = '\x00\x70\x09\x28\x03\x08\x01' packet = serial_num + rssi + tx_power + association_request_data + '\x00' + prutils.str_l( attached_device_information) + '\x01' + prutils.str_l( manufacturing_information) + '\x02' + prutils.str_l( rf_module_information) host_protocol_message = prutils.make_host_packet(0x41, packet, False) enroll_packet = '\x01' + host_protocol_message enroll_packet = prutils._make_f2_packet(enroll_packet, 13) return enroll_packet
def file_block(long_id, short_id, data, film_id, row, block, sequence): data = chr(film_id) + chr(row) + prutils.num_to_chars(block, 2, 0) + chr( len(data)) + data packet = prutils.make_device_packet_without_type(long_id, short_id, Config.FILE_REPLY, data, 0, 1, 0, 0, 0, 0, 4, sequence) return packet
def enroll_to_zone(self, long_id, dev_type, zone_num): # non works on the GSM automation if (not self.is_AUTO_port_ready()): return False if (dev_type.upper() in _DeviceType): dev_type = _DeviceType[dev_type.upper()] else: log.wrte("Incorrect device type specified") return -1 if not (self.open_test_mode()): log.write("Can't open test mode") return -1 ack = '\x0D\xF0\x01\x43\x00\x00\x80\x40\x0A' enroll = '\x0D\xF0\x02\x00\x00\x26\x33\x01' + chr(zone_num) + '\x22\x41' + prutils.num_to_chars(long_id, 4, 0) + \ '\x32\x01\x00\x00\x08\x00' + dev_type + \ '\x01\x14\x03\x00\x00\x01\x03\x00\x00\x00\x02\x07\x00\x70\x09\x28\x03\x08\x01\xC7\x0A' crc = prutils.crc16_F0(enroll[1:]) enroll = enroll + prutils.num_to_chars(crc, 2, 0) + '\x0A' # enroll = dpr.enroll_F0(long_id, dev_type, zone_num) short_id = -1 self._Communicator.send(enroll) result = self._Communicator.wait(0x01, 3) if result and result == ack: result = self._Communicator.wait(0x04, 10) # enroll answer if result: if ord(result[7]) != 1: log.write('Device rejected') else: short_id = ord(result[13]) self._Communicator.send(ack) log.write('ShortId=%d' % short_id) else: log.write('Can\'t enroll device, no answer') else: log.write('Can\'t enroll device, no ACK') self.close_test_mode() return short_id pass
def change_transmission_privileges(long_id, short_id, restricted_bitmap, timeout_sec): # restricted_bitmap - bitmap of restricted slots (8 bytes): # 0 - not restricted # 1 - slot is restricted for transmission # timeout_sec need to be 2 bytes length timeout_sec = prutils.num_to_chars(timeout_sec, 2) packet = prutils.make_device_packet(long_id, short_id, Config.REPORT, 63, restricted_bitmap + timeout_sec) return packet
def get_network_data(self, integrity=False): supervision_period = 0x2D0 enrollment_sate = 1 data = prutils.num_to_chars(self._long_id, 4, 0) + self._dev_type_code + \ chr(self._short_id) + chr(enrollment_sate) # + prutils.num_to_chars(supervision_period, 2, 0) # data = prutils.str_l(data) log.write("network data = %s" % prutils.hexdump(data)) if integrity: return prutils.crc_PGH_20(data) return data
def send_diagnostics(short_id, long_id, seq): #22 3F 0A 01 30 00 08 B5 0C 95 28 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 53 06 00 00 81 0A #53 06 00 00 - Supervision message (06 00 - Long ID) #Long is 13 bits of the real Long ID: [LSB] [MSB], 2100 = [0x34] [0x08] #long_id_packed = chr(long_id % 256) + chr(long_id &0xff00)/ 256 long_id_packed = prutils.num_to_chars(long_id, 0, 0)[:2] data = chr(short_id) + chr(seq) +'\x30\x00\x08\xB5\x0C\x95\x28\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x53' + long_id_packed + '\x00' packet = prutils.make_host_packet(0x3F, data) return packet
def change_listen_mode(long_id, short_id, mode, timeout_sec): # mode: # 0 - Notification Only # 1 - Always Open # 255 - Default # timeout_sec need to be 2 bytes length timeout_sec = prutils.num_to_chars(timeout_sec, 2) packet = prutils.make_device_packet(long_id, short_id, Config.REPORT, 61, chr(mode) + timeout_sec) return packet
def send_diagnostics(short_id, long_id, seq): #22 3F 0A 01 30 00 08 B5 0C 95 28 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 53 06 00 00 81 0A #53 06 00 00 - Supervision message (06 00 - Long ID) #Long is 13 bits of the real Long ID: [LSB] [MSB], 2100 = [0x34] [0x08] #long_id_packed = chr(long_id % 256) + chr(long_id &0xff00)/ 256 long_id_packed = prutils.num_to_chars(long_id, 0, 0)[:2] data = chr(short_id) + chr( seq ) + '\x30\x00\x08\xB5\x0C\x95\x28\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x53' + long_id_packed + '\x00' packet = prutils.make_host_packet(0x3F, data) return packet
def enroll_F0(long_id, dev_type, zone_num, customer_mid=0, customer_did=0): long_id = prutils.num_to_chars(long_id) if (dev_type.upper() in _DeviceType): dev_type = _DeviceType[dev_type.upper()] else: raise Exception("Incorrect device type specified") return None # "32 01 00 [] 00 08 00 " $ iDeviceTypeNumber $ " " $ iDeviceSubTypeNumber $ " 01 14 03 00 00 01 03 00 00 00 02 07 00 70 09 28 03 08 01 C7 0A" rssi = '\x32' tx_power = '\x01' association_request_data = '\x00' attached_device_information = dev_type + '\x01\x14\x03\x00\x00' attached_device_information = '\x00' + chr( len(attached_device_information)) manufacturing_information = '\x01\x03' + chr( customer_mid) + prutils.num_to_chars(customer_did, 2, 0) rf_module_information = '\x02\x07\x00\x70\x09\x28\x03\x08\x01' data = '\x01' + chr( zone_num ) + '\x22\x41' + long_id + rssi + tx_power + association_request_data + attached_device_information + manufacturing_information + rf_module_information packet = prutils.make_f0_packet(0x02, 0x33, data) return packet
def file_info( long_id, short_id, film_id, row, file_status, prime_file_id, secondary_file_id, frame_number, file_type, film_type, time_stamp, crc, index, zone, file_size, sequence=-1, ): data = ( chr(film_id) + chr(row) + chr(file_status) + chr(prime_file_id) + chr(secondary_file_id) + chr(frame_number) + chr(file_type) + chr(film_type) + prutils.num_to_chars(time_stamp, 4, 0) + prutils.num_to_chars(crc, 2, 0) + chr(index) + chr(zone) + prutils.num_to_chars(file_size, 2, 0) ) packet = prutils.make_device_packet(long_id, short_id, Config.REPLY, 181, data, 0, 0, 0, 0, 1, 4, sequence) return packet
def change_notification_period(long_id, short_id, mode, timeout_sec): # mode: # 0 - 1 second # 1 - 2 seconds # 2 - 4 seconds # 3 - 8 seconds # 4 - 16 seconds # 5 - 32 seconds # 6 - 64 seconds # 255 - Default # timeout_sec need to be 2 bytes length timeout_sec = prutils.num_to_chars(timeout_sec, 2) packet = prutils.make_device_packet(long_id, short_id, Config.REPORT, 62, chr(mode) + timeout_sec) return packet
def film_info( long_id, short_id, film_id, film_status, film_type, pre_alarm_length, post_alarm_length, frame_rate, time_stamp, index, zone, files_amount, ): # film_status: # 0 does not exist # 1 existing, closed and permitted for delete # 2 existing, opened film # 3 existing, closed film # 4 error # print long_id, short_id, film_id, film_status, film_type, pre_alarm_length, post_alarm_length,\ # frame_rate, time_stamp, index, zone, files_amount # return data = chr(film_id) data += chr(film_status) data += chr(film_type) data += chr(pre_alarm_length) data += chr(post_alarm_length) data += chr(frame_rate) data += prutils.num_to_chars(time_stamp, 4, 0) data += chr(index) data += chr(zone) data += chr(files_amount) packet = prutils.make_device_packet(long_id, short_id, Config.REPORT, 180, data, 0, 1, 1, 1, 0) return packet
def file_block(long_id, short_id, data, film_id, row, block, sequence): data = chr(film_id) + chr(row) + prutils.num_to_chars(block, 2, 0) + chr(len(data)) + data packet = prutils.make_device_packet_without_type( long_id, short_id, Config.FILE_REPLY, data, 0, 1, 0, 0, 0, 0, 4, sequence ) return packet
def auto_cmd(self, cmd, data): data = prutils.num_to_chars(data) packet = prutils._make_f2_packet(data, cmd) self._Communicator.send(packet)
def get_application_data(self, fn_sniffer_wait, integrity=False): # use request to get configuration according to device type config_cache = {} cur_seq = 0xff snum = 0xff data = '' for cfg in self._config_types: device_config_template = self._get_config_type(cfg) if device_config_template is None: log.write("Don't know how to get the 0x%04X device configuration" % cfg) return None dpr_type = device_config_template[1] # log.write("ASK FOR dpr_type = %x" % dpr_type) if dpr_type in config_cache.keys(): packet = config_cache[dpr_type] else: packet = self._Procedures.request_configuration_data(self._short_id, self._long_id, dpr_type) # filter out retransmittions while snum == cur_seq: packet = fn_sniffer_wait(0x10) if packet == False: break packet = packet[5:] # dpr only dprp = DPR_Packet(packet) snum = dprp.snum.value if snum == 0xff: break # special case cur_seq = snum if packet : config_cache[dpr_type] = packet self.send_response(0x07, dprp.snum.value) if packet: dprp = DPR_Packet(packet) rcv_dpr_type = ord(packet[8]) # if dpr_type != rcv_dpr_type: # log.write("wrong TLDV:%d != %d" % (dpr_type, rcv_dpr_type)) value_len_off = dprp.data_len.offset + 2 value_len = ord(packet[value_len_off]) # add config to cash # log.write("len = %d " % value_len) add = prutils.num_to_chars(cfg, 2, 0) # add += prutils.num_to_chars(cfg, 2, 0) # BF [07 05 01 00 01 00 08 20] if len(device_config_template) > 2 : # extract the tldv parameter offset = device_config_template[2][0] size = device_config_template[2][1] tldv_data = dprp.data[offset + 2: offset + size + 2] # log.write("template:%s" % device_config_template) # log.write("dpr data = %s" % prutils.hexdump(dprp.data)) # log.write("0x%X:%d extraction: %s" % (offset, size, prutils.hexdump(tldv_data))) add += chr(len(tldv_data)) + tldv_data # log.write("TLDV:%s => %s" % (prutils.hexdump(packet[8:11]), prutils.hexdump(add))) else: add += chr(value_len) add += packet[value_len_off + 1: value_len_off + value_len + 1] data += add # data = chr(len(data)) + data time.sleep(0.3) else: return None log.write("application data = %s" % prutils.hexdump(data)) if integrity == True: if len(self._config_types) != 0: data = prutils.crc_PGH_20(data) else: data = 0x0000 return data