Ejemplo n.º 1
0
    def get_sensors(self):
        """
        return: a namedtuple

        WARNING: now this only returns pkt 100, everything. And it is the default
            packet reques now.
        """

        opcode = OPCODES.SENSORS
        cmd = (100, )
        sensor_pkt_len = 80

        self.SCI.write(opcode, cmd)
        time.sleep(0.015)  # wait 15 msec

        packet_byte_data = self.SCI.read(sensor_pkt_len)

        flash_msg = packet_byte_data.find(b'(0x0)\n\r')
        wakeup_msg = packet_byte_data.find(b'conds\r\n')
        msg = max(flash_msg, wakeup_msg)

        if not msg == -1:
            print(packet_byte_data)
            packet_byte_data_continue = self.SCI.read(msg + 7)
            packet_byte_data = packet_byte_data[msg +
                                                7:] + packet_byte_data_continue
            print(len(packet_byte_data_continue), len(packet_byte_data))
        #print(packet_byte_data)

        sensors = SensorPacketDecoder(packet_byte_data)

        return sensors
Ejemplo n.º 2
0
def test_process_packet():
    try:
        # i need to get a known packet and check values
        data = bytearray(os.urandom(80))
        sensors = SensorPacketDecoder(data)
        assert isinstance(sensors, tuple)
    except:
        assert False
Ejemplo n.º 3
0
    def get_sensors(self):
        """
        return: a namedtuple

        WARNING: now this only returns pkt 100, everything. And it is the default
            packet reques now.
        """

        opcode = OPCODES.SENSORS
        cmd = (100, )
        sensor_pkt_len = 80

        self.SCI.write(opcode, cmd)
        time.sleep(0.015)  # wait 15 msec
        packet_byte_data = self.SCI.read(sensor_pkt_len)
        sensors = SensorPacketDecoder(packet_byte_data)

        return sensors
Ejemplo n.º 4
0
    def get_sensors(self, pkts=None):
        """
		pkts: an array of packets to read.
		return: a hash of the roomba's sensors/variables requeted

		WARNING: now this only returns pkt 100, everything. And it is the default
				packet reques now.
		"""
        if not pkts:
            pkts = [100]

        length = len(pkts)
        sensor_pkt_len = calc_query_data_len(pkts)

        if length == 1:
            opcode = OPCODES.SENSORS
            cmd = tuple(pkts)
        else:
            opcode = OPCODES.QUERY_LIST
            cmd = (len(pkts), ) + tuple(pkts)

        self.SCI.write(opcode, cmd)
        time.sleep(0.015)  # wait 15 msec

        packet_byte_data = list(self.SCI.read(sensor_pkt_len))
        packet_byte_data = array.array('B', packet_byte_data).tostring()

        # print('-'*60)
        # print('returned data len({})'.format(len(packet_byte_data)))
        # print('type:', type(packet_byte_data))
        # print(packet_byte_data)

        # if data was returned, then decode it
        # if packet_byte_data:
        # 	for p in pkts:
        # 		self.decoder.decode_packet(p, packet_byte_data, sensors)

        if pkts[0] == 100:
            sensors = SensorPacketDecoder(packet_byte_data)

        return sensors
Ejemplo n.º 5
0
    def get_sensors(self):
        """
        return: a namedtuple

        WARNING: now this only returns pkt 100, everything. And it is the default
            packet reques now.

        Modified get sensor, instead of finding partiular debug string, it discards 
        the readings if read length is not 80 (we expected)
        """

        opcode = OPCODES.SENSORS
        cmd = (100, )
        sensor_pkt_len = 80

        packet_byte_data = None

        while True:

            self.SCI.write(opcode, cmd)
            time.sleep(0.5)  # wait 15 msec

            packet_byte_data = self.SCI.read_all()

            if len(packet_byte_data) == sensor_pkt_len:

                break

            print('Sensor data not 80 bytes long, it is: {}'.format(
                len(packet_byte_data)))
            print(packet_byte_data)
            print("Failed to get sensor, retrying in 0.5 sec")
            time.sleep(0.5)

        sensors = SensorPacketDecoder(packet_byte_data)

        return sensors