Пример #1
0
    def __init__(self):
        self.radio = MidLevel()

        self.packet = UAVPacket()
        self.loc = 0
Пример #2
0
class NodeA(object):
    def __init__(self):
        self.radio = MidLevel()

        self.packet = UAVPacket()
        self.loc = 0

    def startup(self):
        self.radio.startup()

    def shutdown(self):
        self.radio.shutdown()


    def _listen(self, freq):
        status = self.radio.listen(freq, rssi_threshold=100, timeout=1.0)
        if status == 'clear':
            print "channel clear"
    


    def _receive(self, freq):
        # ack = []
        # for i in range(64):
        #     ack.append(0xff)


        # # ack = [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
        # #        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
        # #        0xff, 0xff, 0xff]


        rx_packet = self.radio.receive(freq, rx_fifo_threshold=17, timeout=2.0)

        # print "rx_packet: ", rx_packet


        (rx_packet_num, rx_flags, rx_data) = self.packet.parse_packet(rx_packet)

        # this chunk of code should probably be moved into
        # packet_utils: UAVPacket.unpack_data()
        s = ''
        for i in range(8):
            s = s + chr(rx_data[i])
        # print "rx_data          # 

        (goodput,) = struct.unpack('!d', s)

        a4, a3, a2, a1 = rx_data[8:12]
        ack_number = (a4 << 24) + (a3 << 16) + (a2 << 8) + a1

        # print "ack_number: ", ack_number
        # print "goodput = %f bits/sec" %(goodput)


        print "Calculated goodput for packet %d = %f" %(ack_number, goodput)



        # if (packet == ack):
        #     print "ACK received"



    def _transmit(self, freq):
        data = []
        for i in range(50):
            data.append(0xff)
        flags = 0x00
        tx_packet = self.packet.make_packet(self.loc, flags, data)
        # print "tx_packet: ", tx_packet
        # data = [0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 
        #         0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D,
        #         0x3E, 0x3F, 0x78]
        self.radio.transmit(tx_packet, freq)
        self.loc += 1


    def fsm(self):
        """
        Primary control loop.

        This function is the finite state machine that controls the
        operation of the system.
        """

        self.startup()

        state = "listen"
        f = 434e6

        while True:
            if state == "listen":
                self._listen(f)
                state = "transmit"

            elif state == "transmit":
                self._transmit(f)
                state = "receive"

            elif state == "receive":
                self._receive(f)
                state = "listen"

            else:
                print "+++ Melon melon melon +++"
                state = "listen"
Пример #3
0
class NodeA(object):
    def __init__(self):
        self.radio = MidLevel()

        self.packet = UAVPacket()
        self.loc = 0

    def startup(self):
        self.radio.startup()

    def shutdown(self):
        self.radio.shutdown()


    def _listen(self, freq):
        status = self.radio.listen(freq, rssi_threshold=100, timeout=1.0)
        if status == 'clear':
            print "channel clear"
    


    def _receive(self, freq):
        rx_packet = self.radio.receive(freq, rx_fifo_threshold=17, timeout=2.0)
        if rx_packet == []:
            return
        else:
            (rx_packet_num, rx_flags, rx_data) = self.packet.parse_packet(rx_packet)

            # this chunk of code should probably be moved into
            # packet_utils: UAVPacket.unpack_data()
            s = ''
            for i in range(8):
                s = s + chr(rx_data[i])

            (goodput,) = struct.unpack('!d', s)

            a4, a3, a2, a1 = rx_data[8:12]
            ack_number = (a4 << 24) + (a3 << 16) + (a2 << 8) + a1
            print "Calculated goodput for packet %d = %f" %(ack_number, goodput)






    def _transmit(self, freq):
        data = []
        for i in range(50):
            data.append(0xff)
        flags = 0x00
        tx_packet = self.packet.make_packet(self.loc, flags, data)
        self.radio.transmit(tx_packet, freq)
        self.loc += 1


    def fsm(self):
        """
        Primary control loop.

        This function is the finite state machine that controls the
        operation of the system.
        """

        self.startup()

        state = "listen"
        f = 434e6

        while True:
            if state == "listen":
                self._listen(f)
                state = "transmit"

            elif state == "transmit":
                self._transmit(f)
                state = "receive"

            elif state == "receive":
                self._receive(f)
                state = "listen"

            else:
                print "+++ Melon melon melon +++"
                state = "listen"
Пример #4
0
class NodeA(object):
    def __init__(self):
        self.radio = MidLevel()

        self.packet = UAVPacket()
        self.loc = 0

    def startup(self):
        self.radio.startup()

    def shutdown(self):
        self.radio.shutdown()

    def _listen(self, freq):
        status = self.radio.listen(freq, rssi_threshold=100, timeout=1.0)
        if status == 'clear':
            print "channel clear"

    def _receive(self, freq):
        # ack = []
        # for i in range(64):
        #     ack.append(0xff)

        # # ack = [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
        # #        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
        # #        0xff, 0xff, 0xff]

        rx_packet = self.radio.receive(freq, rx_fifo_threshold=17, timeout=2.0)

        # print "rx_packet: ", rx_packet

        (rx_packet_num, rx_flags,
         rx_data) = self.packet.parse_packet(rx_packet)

        # this chunk of code should probably be moved into
        # packet_utils: UAVPacket.unpack_data()
        s = ''
        for i in range(8):
            s = s + chr(rx_data[i])
        # print "rx_data          #

        (goodput, ) = struct.unpack('!d', s)

        a4, a3, a2, a1 = rx_data[8:12]
        ack_number = (a4 << 24) + (a3 << 16) + (a2 << 8) + a1

        # print "ack_number: ", ack_number
        # print "goodput = %f bits/sec" %(goodput)

        print "Calculated goodput for packet %d = %f" % (ack_number, goodput)

        # if (packet == ack):
        #     print "ACK received"

    def _transmit(self, freq):
        data = []
        for i in range(50):
            data.append(0xff)
        flags = 0x00
        tx_packet = self.packet.make_packet(self.loc, flags, data)
        # print "tx_packet: ", tx_packet
        # data = [0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,
        #         0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D,
        #         0x3E, 0x3F, 0x78]
        self.radio.transmit(tx_packet, freq)
        self.loc += 1

    def fsm(self):
        """
        Primary control loop.

        This function is the finite state machine that controls the
        operation of the system.
        """

        self.startup()

        state = "listen"
        f = 434e6

        while True:
            if state == "listen":
                self._listen(f)
                state = "transmit"

            elif state == "transmit":
                self._transmit(f)
                state = "receive"

            elif state == "receive":
                self._receive(f)
                state = "listen"

            else:
                print "+++ Melon melon melon +++"
                state = "listen"