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 send_response(self, long_id, short_id, dpr_seq, mcode=0x06, state=0, notification_period=0): #log.write('RESPONSE') # state: 0 - OK, 1 .. see device protocol # prepare device protocol # mcode = 0x06 #print type(state) state = chr(state) seq = prutils.generate_seq("hpr") ser_num = prutils.convert_longid(int(long_id))[:3] mdata_value = chr(mcode) + chr(len(state)) + state device_packet = '\x14\x00' + chr(dpr_seq) + ser_num + mdata_value # prepare host protocol #final_hop_info = '\x00' * 11 final_hop_info = '\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00' relaying_repeater_ID = 0 repeater_hop_info = '\x00' * 11 data = chr(short_id) + chr(seq) + chr(0x30 + notification_period) + final_hop_info + chr(relaying_repeater_ID)\ + repeater_hop_info + prutils.str_l(device_packet) cmd = 0x30 data = chr(cmd) + data cmd_l = 2 + len(data) data = chr(cmd_l) + data host_protocol_message = data + prutils.crc16(data)[0] + '\x0A' packet = prutils._make_f2_packet( host_protocol_message ) #self._Procedures._Communicator.add_to_queue(packet, 0, 5) self._Communicator.send(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 send_hello(self, seq=0xFF, notification_period=0): log.write('** hello from [%d:%d] **' % (self._short_id, self._long_id)) self._Procedures.hello(self._long_id, self._short_id, 0, notification_period) return ser_num = prutils.convert_longid(int(self._long_id))[:3] mcode = 5 mdata_type = 64 mdata_value = chr(0) if seq == 0xFF: seq = self._dpr_seq.next() mdata = chr(mcode) + prutils.str_l( chr(mdata_type) + prutils.str_l(mdata_value) ) device_packet = '\xE4\x00' + chr(seq) + ser_num + mdata # prepare host protocol #final_hop_info = '\x00' * 11 final_hop_info = '\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00' relaying_repeater_ID = 0 repeater_hop_info = '\x00' * 11 #data = chr(short_id) + '\x01\xF8' + final_hop_info + chr(relaying_repeater_ID) + repeater_hop_info + str_l(device_packet) data = chr(self._short_id) + chr(prutils.generate_seq('hpr')) + chr(0x30 + notification_period) + final_hop_info + chr(relaying_repeater_ID) + repeater_hop_info + prutils.str_l(device_packet) cmd = 0x30 data = chr(cmd) + data cmd_l = 2 + len(data) data = chr(cmd_l) + data host_protocol_message = data + prutils.crc16(data)[0] + '\x0A' #TODO: Use "make_host_packet" function to create device packet #host_protocol_message = make_host_packet( 0x30, data) #preparing packet to send #print hexdump(host_protocol_message) packet = host_protocol_message packet = prutils._make_f2_packet( host_protocol_message ) # self.prepare_transmitter() self._Procedures._Communicator.send(packet, 9)
def send_response(self, long_id, short_id, dpr_seq, mcode=0x06, state=0, notification_period=0): #log.write('RESPONSE') # state: 0 - OK, 1 .. see device protocol # prepare device protocol # mcode = 0x06 #print type(state) state = chr(state) seq = prutils.generate_seq("hpr") ser_num = prutils.convert_longid(int(long_id))[:3] mdata_value = chr(mcode) + chr(len(state)) + state device_packet = '\x14\x00' + chr(dpr_seq) + ser_num + mdata_value # prepare host protocol #final_hop_info = '\x00' * 11 final_hop_info = '\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00' relaying_repeater_ID = 0 repeater_hop_info = '\x00' * 11 data = chr(short_id) + chr(seq) + chr(0x30 + notification_period) + final_hop_info + chr(relaying_repeater_ID)\ + repeater_hop_info + prutils.str_l(device_packet) cmd = 0x30 data = chr(cmd) + data cmd_l = 2 + len(data) data = chr(cmd_l) + data host_protocol_message = data + prutils.crc16(data)[0] + '\x0A' packet = prutils._make_f2_packet(host_protocol_message) #self._Procedures._Communicator.add_to_queue(packet, 0, 5) self._Communicator.send(packet)
def send_response(self, mcode, seq=0xFF, amount=1, notification_period=0, state=0, return_packet=False): if(mcode == 0x06): log.write('** response from [%d:%d] **' % (self._short_id, self._long_id)) elif(mcode == 0x07): log.write('** confirm from [%d:%d] **' % (self._short_id, self._long_id)) if amount > 1: log.write("--multiply--: %d" % amount) # state: 0 - OK, 1 .. see device protocol # prepare device protocol #print type(state) state = chr(state) if seq == 0xFF: seq = self._dpr_seq.next() ser_num = prutils.convert_longid(int(self._long_id))[:3] mdata_value = '' # mdata_value = chr(mcode) + chr(len(state)) + state for i in range(amount): mdata_value += chr(len(state)) + state mdata_value = chr(mcode) + mdata_value device_packet = '\x14\x00' + chr(seq) + ser_num + mdata_value # prepare host protocol #final_hop_info = '\x00' * 11 final_hop_info = '\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00' relaying_repeater_ID = 0 repeater_hop_info = '\x00' * 11 data = chr(self._short_id) + chr(prutils.generate_seq("hpr")) + chr(0x30 + notification_period) + final_hop_info + chr(relaying_repeater_ID)\ + repeater_hop_info + prutils.str_l(device_packet) cmd = 0x30 data = chr(cmd) + data cmd_l = 2 + len(data) data = chr(cmd_l) + data host_protocol_message = data + prutils.crc16(data)[0] + '\x0A' packet = prutils._make_f2_packet( host_protocol_message ) #self._Procedures._Communicator.add_to_queue(packet, 0, 5) if return_packet == False: # self.prepare_transmitter() self._Procedures._Communicator.send(packet) else: 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)