コード例 #1
0
ファイル: icn_head.py プロジェクト: prayswear/NCS
 def sum_checksum(self):
     src_guid_hex = binascii.a2b_hex(self.src_guid)
     dst_guid_hex = binascii.a2b_hex(self.dst_guid)
     service_type_hex = binascii.a2b_hex(self.service_type)
     header_len_hex = binascii.a2b_hex(int2byte(self.header_len, 8))
     other = src_guid_hex + dst_guid_hex + service_type_hex + header_len_hex
     return self.checksum(other)
コード例 #2
0
ファイル: icn_head.py プロジェクト: prayswear/NCS
 def icn2byte(self):
     src_guid_hex = binascii.a2b_hex(self.src_guid)
     dst_guid_hex = binascii.a2b_hex(self.dst_guid)
     service_type_hex = binascii.a2b_hex(self.service_type)
     header_len_hex = binascii.a2b_hex(int2byte(self.header_len, 8))
     header_checksum_hex = binascii.a2b_hex(self.header_checksum)
     hex_result = src_guid_hex + dst_guid_hex + service_type_hex + header_len_hex + header_checksum_hex + self.tlv + self.payload
     return hex_result
コード例 #3
0
ファイル: icn_head.py プロジェクト: prayswear/NCS
 def checksum(self, data):
     length = len(data)
     checksum = 0
     for i in range(0, length):
         checksum += int.from_bytes(data[i:i + 1], 'little', signed=False)
     checksum &= 0xffff
     checksum_hex = int2byte(checksum, 16)
     return checksum_hex
コード例 #4
0
 def query_hrn(self, data):
     eid = binascii.b2a_hex(data[1:17]).decode("utf-8")
     result = self.ncsdb.query(self.tbl_name, {"EID": eid})
     if result == None:
         payload = binascii.a2b_hex("06" + "02" + "00")
     else:
         hrn = result["HRN"].encode("utf-8")
         hrn_len = len(hrn)
         payload = binascii.a2b_hex("06" + "01") + binascii.a2b_hex(
             int2byte(hrn_len, 8)) + hrn
     return payload
コード例 #5
0
ファイル: ncs_client.py プロジェクト: prayswear/NCS
 def query_eid(self, hrn):
     icn_packet = ICNPacket()
     icn_packet.setHeader("226cf119b78825f1720cf2ca485c2d85",
                          "00000000000000000000000000000000", "00")
     cmd_type = binascii.a2b_hex("03")
     hrn_hex = hrn.encode("utf-8")
     hrn_len = len(hrn_hex)
     icn_packet.setPayload(cmd_type +
                           binascii.a2b_hex(int2byte(hrn_len, 8)) + hrn_hex)
     icn_packet.fill_packet()
     reply = self.send(icn_packet)
     cmd_type = int(binascii.b2a_hex(reply.payload[:1]), 16)
     ack = int(binascii.b2a_hex(reply.payload[1:2]), 16)
     if cmd_type == 4 and ack == 1:
         eid = binascii.b2a_hex(reply.payload[2:18])
         return eid.decode("utf-8")
     else:
         return None