Пример #1
0
def tagmessages_test():
    tmpoll = TagPoll()
    tmrsp = TagResponse(tmpoll)
    printmsg(tmpoll)
    printmsg(tmrsp)

    txpoll = tmpoll.build()
    cmpoll = TagMessage(txpoll)
    printmsg(cmpoll)
    cxpoll = cmpoll.build()
    print('tx', hexlify(txpoll))
    print('cx', hexlify(cxpoll))

    hdr_size = tagnet_message_header_s.sizeof()
    print('txheader == xxheader',
          hexlify(txpoll[0:hdr_size]) == hexlify(cxpoll[0:hdr_size]),
          hexlify(txpoll[0:hdr_size]), hexlify(cxpoll[0:hdr_size]))

    tmbeacon = TagBeacon()
    printmsg(tmbeacon)
    nm = TagName('/tag/info/') + TagTlv(tlv_types.NODE_ID, -1)\
         + TagName('/sens/gps/pos')
    #         + TagTlv('sensor') + TagTlv('gps') + TagTlv('fix')
    pl = TagTlvList([
        (tlv_types.INTEGER, 123456789),
    ])
    tmput = TagPut(nm, pl)
    printmsg(tmput)
    tbput = TagPut(nm, bytearray(b'abc'))
    printmsg(tbput)

    return tmpoll, txpoll, tmrsp, cmpoll, cxpoll, tmput, tbput
Пример #2
0
 def parse(self, v):
     """
     deconstruct a wire formated byte string into the message class
     """
     # verify crc8
     if (self.crc8.crc(v[:-1]) == v[-1]):
         hdr_size = tagnet_message_header_s.sizeof()
         try:
             self.header = tagnet_message_header_s.parse(v[0:hdr_size])
             self.name = TagName(v[hdr_size:self.header.name_length +
                                   hdr_size])
             if len(v) > (hdr_size + self.header.name_length):
                 if (self.header.options.tlv_payload == 'TLV_LIST'):
                     self.payload = TagTlvList(v[self.header.name_length +
                                                 hdr_size:-1])
                 else:
                     self.payload = bytearray(v[self.header.name_length +
                                                hdr_size:-1])
             else:
                 self.payload = None
         except (construct.adapters.MappingError, TlvBadException,
                 TlvListBadException):
             self.header = None
             self.name = None
             self.payload = None
Пример #3
0
 def __init__(self, node_id=None):
     if (not node_id): node_id = get_mac()
     pl = TagTlvList([(tlv_types.NODE_ID, node_id),
                      (tlv_types.NODE_NAME, platform.node()),
                      (tlv_types.TIME, datetime.now())])
     nm = TagName('/tag/beacon') + TagTlv(tlv_types.NODE_ID, -1)
     super(TagBeacon, self).__init__(nm, pl)
     self.header.options.message_type = 'BEACON'
     self.hop_count(1)  # never forward this message
Пример #4
0
 def __init__(self, slot_time=100, slot_count=10):
     nm = TagName('/tag/poll') \
                    + TagTlv(tlv_types.NODE_ID, -1) \
                    + TagTlv(tlv_types.STRING, 'ev')
     pl = TagTlvList([(tlv_types.TIME, datetime.now()),
                      (tlv_types.INTEGER, slot_time),
                      (tlv_types.INTEGER, slot_count),
                      (tlv_types.NODE_ID, get_mac()),
                      (tlv_types.NODE_NAME, platform.node())])
     super(TagPoll, self).__init__(nm, pl)
     self.header.options.message_type = 'POLL'
     self.hop_count(1)  # never forward this message
Пример #5
0
 def parse(self, v):
     """
     deconstruct a wire formated byte string into the message class
     """
     hdr_size = tagnet_message_header_s.sizeof()
     self.header = tagnet_message_header_s.parse(v[0:hdr_size])
     self.name = TagName(v[hdr_size:self.header.name_length + hdr_size])
     if len(v) > (hdr_size + self.header.name_length):
         if (self.header.options.tlv_payload == 'TLV_LIST'):
             self.payload = TagTlvList(v[self.header.name_length +
                                         hdr_size:])
         else:
             self.payload = bytearray(v[self.header.name_length +
                                        hdr_size:])
     else:
         self.payload = None
Пример #6
0
 def __init__(self, slot_width=1000, slot_count=10):
     nm = TagName([
         TagTlv(tlv_types.NODE_ID, -1),
         TagTlv('tag'),
         TagTlv('poll'),
         TagTlv('ev')
     ])
     pl = TagTlvList([
         (tlv_types.NODE_ID, get_mac()),
         (tlv_types.NODE_NAME, platform.node()),
         (tlv_types.INTEGER, slot_width),
         (tlv_types.INTEGER, slot_count),
         #(tlv_types.TIME,datetime.now()),
     ])
     super(TagPoll, self).__init__(nm, pl)
     self.header.options.message_type = 'POLL'
     self.hop_count(1)  # never forward this message
Пример #7
0
def im_send_request(fd, write_max, vers, eof=False):
    # base image name
    req_name = TagName ('/tag/sd')                 + TagTlv(tlv_types.NODE_ID, -1)                 + TagTlv(0)                 + TagTlv('img')                 + TagTlv(tlv_types.VERSION, vers)

    # optionally add offset to name
    if (fd.tell() > 0):
        req_name += TagTlv(tlv_types.OFFSET, fd.tell())

    # build the PUT mesage object
    req_obj = TagPut(req_name)

    # optionally add payload
    if eof:
        # send end of file indication
        pload = [TagTlv(tlv_types.EOF)]
    elif (fd.tell() < write_max):
        # determine payload to send
        max_write = 254 - req_obj.pkt_len()
        if ((file_size - fd.tell()) < max_write):
                max_write = file_size - fd.tell()
        pload = bytearray(f.read(max_write))
    # else
        # just send without payload
    
    # print out details of request
    print("REQUEST MSG")
    print(req_obj.header)
    print(req_obj.name)
    if (pload is not None):
        req_obj.payload = pload
    req_msg = req.build()
    print("   req len: {},  payload len: {}".format(len(req_msg), len(load)))
    print("   ", hexlify(req_msg[:PRINT_MAX]),"...", hexlify(req_msg[-PRINT_MAX:]))
    
    # send request msg
    si446x_device_send_msg(radio, im_req_buf, RADIO_POWER)
    xcnt += 1
    return req_obj, req_msg
Пример #8
0
    infile.close()

except LoadException, reason:
    print("load exception", reason)

except IOError, e:
    print("i/o error", e)

print('\ndone')


# ## Get Directory

# In[ ]:

image_manager_name = TagName ('/tag/sd')                 + TagTlv(tlv_types.NODE_ID, -1)                 + TagTlv(0)                 + TagTlv('img') dir_info = TagGet(image_manager_name)
print(dir_info.name)
dir_msg = dir_info.build()
print(len(dir_msg),hexlify(dir_msg))


# In[ ]:

l = si446x_device_send_msg(radio, dir_msg, pwr)
dir_msg, rssi, status = si446x_device_receive_msg(radio, MAX_RECV, MAX_WAIT)
if (dir_msg):
    dir_obj = TagMessage(dir_msg)
    print("DIRECTORY LISTING")
    print(dir_obj.header)
    print(obj_obj.name)
    print(obj_obj.payload)