Esempio n. 1
0
    def test_not_equal(self):
        c1 = UbxCID(0x05, 0x00)
        c2 = UbxCID(0x05, 0x01)
        assert c1 != c2

        c1 = UbxCID(0x05, 0x01)
        c2 = UbxCID(0x06, 0x01)
        assert c1 != c2
Esempio n. 2
0
    def test_immutable(self):
        c1 = UbxCID(0x05, 0x01)
        with pytest.raises(AttributeError):
            c1.cls = 0x06

        with pytest.raises(AttributeError):
            c1.id = 0x44

        res = str(c1)
        assert res == 'cls:05 id:01'
Esempio n. 3
0
    def test_change_filter(self):
        uut = UbxParser(UbxCID(0x00, 0x02))
        uut.set_filter(UbxCID(0x13, 0x40))
        uut.process(self.FRAME_1)
        cid, packet = uut.packet()
        assert cid == UbxCID(0x13, 0x40)

        uut.set_filter(UbxCID(0x00, 0x00))
        uut.process(self.FRAME_1)
        cid, packet = uut.packet()
        assert cid is None and packet is None
Esempio n. 4
0
 def test_cinvalid_length(self):
     frame = [
         0xB5, 0x62, 0x13, 0x40, 0xe9, 0x03, 0x10, 0x00, 0x00, 0x12, 0xE4,
         0x07, 0x09, 0x05, 0x06, 0x28, 0x30, 0x00, 0x40, 0x28, 0xEF, 0x0C,
         0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x51, 0xAC
     ]
     uut = UbxParser(UbxCID(0x00, 0x02))
     uut.set_filter(UbxCID(0x13, 0x41))
     uut.process(frame)  # CRC packet
     cid, packet = uut.packet(
     )  # Should be None because frame is too long (MAX_MESSAGE_LENGTH)
     assert cid is None and packet is None
Esempio n. 5
0
 def test_crc_error(self):
     # B5 62 13 40 18 00 10 00 00 12 E4 07 09 05 06 28 30 00 40 28 EF 0C 0A 00 00 00 00 00 00 00 51 AC
     # hdr  | <--                                 checksum                                  --> | chksum
     frame = [
         0xB5, 0x62, 0x13, 0x40, 0x18, 0x00, 0x10, 0x00, 0x00, 0x12, 0xE4,
         0x07, 0x09, 0x05, 0x06, 0x28, 0x30, 0x00, 0x40, 0x28, 0xEF, 0x0C,
         0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x51, 0xAC + 1
     ]
     uut = UbxParser(UbxCID(0x00, 0x02))
     uut.set_filter(UbxCID(0x13, 0x41))
     uut.process(frame)  # CRC packet
     cid, packet = uut.packet()
     assert cid == UbxCID(0x00, 0x02)
Esempio n. 6
0
    def test_throws_when_unknown_frame_shall_be_built(self, frame_factory):
        unregistered_cid = UbxCID(0xCA, 0xFE)
        with pytest.raises(KeyError):
            frame_factory.build(unregistered_cid)

        with pytest.raises(KeyError):
            frame_factory.build_with_data(unregistered_cid, "12345")
Esempio n. 7
0
    def _state_crc2(self, d):
        self.ckb = d

        # if checksum matches received checksum ..
        if self.checksum.matches(self.cka, self.ckb):
            self.frames_rx += 1

            # .. and frame passes filter ..
            cid = UbxCID(self.msg_class, self.msg_id)

            if self.wait_cids and cid in self.wait_cids:
                # .. queue packet (CID and data)
                packet = (cid, self.msg_data)
                self.rx_queue.append(packet)
            else:
                if logger.isEnabledFor(logging.DEBUG):
                    logger.debug(
                        f'no match - dropping {cid}, {self.msg_len} bytes')
        else:
            logger.warning('checksum error in frame, discarding')
            logger.warning(
                f'{self.msg_class:02x} {self.msg_id:02x} {binascii.hexlify(self.msg_data)}'
            )

            crc_error_message = (self.crc_error_cid, None)
            self.rx_queue.append(crc_error_message)

        self.state = __class__.State.INIT
Esempio n. 8
0
    def test_frame_construct(self, frame_factory):
        frame_factory.register(UbxAckAck)

        data = bytearray.fromhex('11 22')
        f = frame_factory.build_with_data(UbxAckAck.CID, data)
        assert f.CID == UbxCID(0x05, 0x01)
        assert f.f.clsId == 0x11
        assert f.f.msgId == 0x22
Esempio n. 9
0
    def __init__(self):
        super().__init__()

        self.cid_crc_error = UbxCID(0x00, 0x02)
        self.parser = UbxParser(self.cid_crc_error)
        self.frame_factory = FrameFactory.getInstance()
        self.max_retries = 2
        self.retry_delay_in_ms = 1800
Esempio n. 10
0
class UbxAckAck(UbxFrame):
    CID = UbxCID(UbxCID.CLASS_ACK, 0x01)
    NAME = 'UBX-ACK-ACK'

    def __init__(self):
        super().__init__()

        self.f.add(U1('clsId'))
        self.f.add(U1('msgId'))
Esempio n. 11
0
 def _check_ack_nak(self, request, res):
     if res.CID == UbxAckAck.CID:
         ack_cid = UbxCID(res.f.clsId, res.f.msgId)
         if ack_cid == request.CID:
             # if logger.isEnabledFor(logging.DEBUG):
             #     logger.debug('ACK matches request')
             return "ACK"
         else:
             # ACK is for another request
             logger.warning(
                 f'ACK {ack_cid} does not match request {request.CID}')
     elif res.CID == UbxAckNak.CID:
         logger.warning(f'request {request.CID} rejected, NAK received')
         return "NAK"
     else:
         # Must never happen. Only ACK/NAK in expected list
         logger.error(f'invalid frame received {res.CID}')
Esempio n. 12
0
 def test_multiple_filters(self):
     uut = UbxParser(UbxCID(0x00, 0x02))
     cids = [
         UbxCID(0x12, 0x12),
         UbxCID(0x13, 0x40),
         UbxCID(0xFF, 0x00),
         UbxCID(0xFF, 0x00)
     ]
     uut.set_filters(cids)
     uut.process(self.FRAME_1)
     cid, packet = uut.packet()
     assert cid == UbxCID(0x13, 0x40)
Esempio n. 13
0
 def test_passes_filter(self):
     uut = UbxParser(UbxCID(0x00, 0x02))
     uut.set_filter(UbxCID(0x13, 0x40))
     uut.process(self.FRAME_1)
     cid, packet = uut.packet()
     assert cid == UbxCID(0x13, 0x40)
Esempio n. 14
0
 def test_no_frames(self):
     uut = UbxParser(UbxCID(0x00, 0x02))
     packet = uut.packet()
     assert packet == (None, None)
Esempio n. 15
0
 def test_filters(self):
     uut = UbxParser(UbxCID(0x00, 0x02))
     uut.set_filters([UbxCID(0x05, 0x00), UbxCID(0x05, 0x01)])
     assert len(uut.wait_cids) == 2
     assert UbxCID(0x05, 0x00) in uut.wait_cids
     assert UbxCID(0x05, 0x01) in uut.wait_cids
Esempio n. 16
0
 def test_registration(self, frame_factory):
     frame_factory.register(UbxAckAck)
     f1 = frame_factory.build(UbxCID(5, 1))
     assert type(f1) == UbxAckAck
Esempio n. 17
0
 def test_creation(self):
     c = UbxCID(0x05, 0x01)
     assert c.cls == 0x05
     assert c.id == 0x01
Esempio n. 18
0
class UbxCfgEsfAlg_(UbxFrame):
    CID = UbxCID(UbxCID.CLASS_CFG, 0x56)
    NAME = 'UBX-CFG-ESFALG'
Esempio n. 19
0
 def test_equal(self):
     c1 = UbxCID(0x05, 0x01)
     c2 = UbxCID(0x05, 0x01)
     assert c1 == c2
Esempio n. 20
0
class UbxCfgNmea_(UbxFrame):
    CID = UbxCID(UbxCID.CLASS_CFG, 0x17)
    NAME = 'UBX-CFG-NMEA'
Esempio n. 21
0
class UbxCfgEsfla_(UbxFrame):
    CID = UbxCID(UbxCID.CLASS_CFG, 0x2f)
    NAME = 'UBX-CFG-ESFLA'

    TYPE_VRP_Antenna = 0
    TYPE_VRP_IMU = 1
Esempio n. 22
0
class UbxMonVer_(UbxFrame):
    CID = UbxCID(UbxCID.CLASS_MON, 0x04)
    NAME = 'UBX-MON-VER'
Esempio n. 23
0
class UbxEsfStatus_(UbxFrame):
    CID = UbxCID(UbxCID.CLASS_ESF, 0x10)
    NAME = 'UBX-ESF-STATUS'
Esempio n. 24
0
 def test_dropped_id(self):
     uut = UbxParser(UbxCID(0x00, 0x02))
     uut.set_filter(UbxCID(0x13, 0x41))
     uut.process(self.FRAME_1)
     cid, packet = uut.packet()
     assert cid is None and packet is None
Esempio n. 25
0
class UbxUpdSos_(UbxFrame):
    NAME = 'UBX-UPD-SOS'
    CID = UbxCID(UbxCID.CLASS_UPD, 0x14)
Esempio n. 26
0
    def test_unkown_frame(self, frame_factory):
        frame_factory.register(UbxAckAck)

        with pytest.raises(KeyError):
            frame_factory.build(UbxCID(99, 99))
Esempio n. 27
0
class UbxCfgNav5_(UbxFrame):
    CID = UbxCID(UbxCID.CLASS_CFG, 0x24)
    NAME = 'UBX-CFG-NAV5'
Esempio n. 28
0
class UbxCfgPrt_(UbxFrame):
    CID = UbxCID(UbxCID.CLASS_CFG, 0x00)
    NAME = 'UBX-CFG-PRT'

    PORTID_Uart = 1
Esempio n. 29
0
class UbxMgaAckData0_(UbxFrame):
    CID = UbxCID(UbxCID.CLASS_MGA, 0x60)
    NAME = 'UBX-MGA-ACK-DATA0'
Esempio n. 30
0
 def test_print(self):
     c = UbxCID(0x05, 0x01)
     res = str(c)
     assert res == 'cls:05 id:01'