def getUartLogPayload(packet):
    """
    Get a Quanto Log Entry from the UART packet.
    Returns None if the AM type of the packet is not 
     QUANTO_LOG_AM_TYPE (c.f. QuantoLog/RawUartMsg.h)
    """ 
    #From MoteIF.py
    try:
        # Message.py ignores base_offset, so we'll just chop off
        # the first byte (the SERIAL_AMTYPE) here.
        serial_pkt = SerialPacket(packet[1:],
                                  data_length=len(packet)-1)
    except:
        traceback.print_exc()


    try:
        data_start = serial_pkt.offset_data(0) + 1
        data_end = data_start + serial_pkt.get_header_length()
        data = packet[data_start:data_end]
        amType = serial_pkt.get_header_type()

    except Exception, x:
        print >>sys.stderr, x
        print >>sys.stderr, traceback.print_tb(sys.exc_info()[2])
Exemple #2
0
    def dispatchPacket(self, source, packet):
        #try:
            #print "Packet length: ", len(packet)
            #            print "Dispatching from MoteIF"
            #             for i in packet:
            #                 print ord(i)," ",
            #             print
        try:
            # Message.py ignores base_offset, so we'll just chop off
            # the first byte (the SERIAL_AMTYPE) here.
            serial_pkt = SerialPacket(packet[1:],
                                      data_length=len(packet)-1)
        except:
            traceback.print_exc()


        try:
            data_start = serial_pkt.offset_data(0) + 1
            data_end = data_start + serial_pkt.get_header_length()
            data = packet[data_start:data_end]
            amType = serial_pkt.get_header_type()

        except Exception, x:
            print >>sys.stderr, x
            print >>sys.stderr, traceback.print_tb(sys.exc_info()[2])
Exemple #3
0
def getUartLogPayload(packet):
    """
    Get a Quanto Log Entry from the UART packet.
    Returns None if the AM type of the packet is not 
     QUANTO_LOG_AM_TYPE (c.f. QuantoLog/RawUartMsg.h)
    """
    #From MoteIF.py
    try:
        # Message.py ignores base_offset, so we'll just chop off
        # the first byte (the SERIAL_AMTYPE) here.
        serial_pkt = SerialPacket(packet[1:], data_length=len(packet) - 1)
    except:
        traceback.print_exc()

    try:
        data_start = serial_pkt.offset_data(0) + 1
        data_end = data_start + serial_pkt.get_header_length()
        data = packet[data_start:data_end]
        amType = serial_pkt.get_header_type()

    except Exception, x:
        print >> sys.stderr, x
        print >> sys.stderr, traceback.print_tb(sys.exc_info()[2])
Exemple #4
0
    def dispatchPacket(self, source, packet):
        #try:
            #print "Packet length: ", len(packet)
            #            print "Dispatching from MoteIF"
            #             for i in packet:
            #                 print ord(i)," ",
            #             print
        try:
            # Message.py ignores base_offset, so we'll just chop off
            # the first byte (the SERIAL_AMTYPE) here.
            serial_pkt = SerialPacket(packet[1:],
                                      data_length=len(packet)-1)
        except:
            traceback.print_exc()


        try:
            data_start = serial_pkt.offset_data(0) + 1
            data_end = data_start + serial_pkt.get_header_length()
            data = packet[data_start:data_end]
            amType = serial_pkt.get_header_type()

        except Exception as x:
            print(x, file=sys.stderr)
            print(traceback.print_tb(sys.exc_info()[2]), file=sys.stderr)

        for l in self.listeners:
            amTypes = self.listeners[l]
            if amType in amTypes:
                try:
                    msgClass = amTypes[amType]
                    msg = msgClass(data=data,
                                   data_length = len(data),
                                   addr=serial_pkt.get_header_src(),
                                   gid=serial_pkt.get_header_group())
                    l.receive(source, msg)
                except Exception as x:
                    print(x, file=sys.stderr)
                    print(traceback.print_tb(sys.exc_info()[2]), file=sys.stderr)
Exemple #5
0
    def sendMsg(self, dest, addr, amType, group, msg):
        try:
            payload = msg.dataGet()
            msg = SerialPacket(None)
            msg.set_header_dest(int(addr))
            msg.set_header_group(int(group))
            msg.set_header_type(int(amType))
            msg.set_header_length(len(payload))

            # from tinyos.packet.Serial
            data = chr(Serial.TOS_SERIAL_ACTIVE_MESSAGE_ID)
            data += msg.dataGet()[0:msg.offset_data(0)]
            data += payload

            dest.writePacket(data)
        except Exception, x:
            print >>sys.stderr, x
            print >>sys.stderr, traceback.print_tb(sys.exc_info()[2])
Exemple #6
0
 def _message_to_packet(self, msg, dest=0xFFFF, group=0xAA):
     """
     Wraps a message in an AM (Serial) packet.
     """
     payload = msg.dataGet()
     am_type = msg.amType()
     pkt = SerialPacket(None)
     pkt.set_header_dest(dest)
     pkt.set_header_group(group)
     pkt.set_header_type(int(am_type))
     pkt.set_header_length(len(payload))
     # first byte, always 0, identifies as AM packet
     return chr(0) + pkt.dataGet()[0:pkt.offset_data(0)] + payload