コード例 #1
0
ファイル: test_socketcan.py プロジェクト: menschel/socketcan
    def test_bcm_msg_creation_with_2_extended_frames_and_ival1(self):
        can_id = 0x12345678
        data = bytes(range(0, 0x88, 0x11))

        frame1 = CanFrame(can_id=can_id, data=data)
        can_id2 = 0x1FFFF456
        data2 = bytes(range(0, 0x44, 0x11))
        frame2 = CanFrame(can_id=can_id2, data=data2)

        opcode = BcmOpCodes.TX_SETUP
        flags = (BCMFlags.SETTIMER | BCMFlags.STARTTIMER)
        frames = [
            frame1,
            frame2,
        ]
        interval1 = 0.1
        interval2 = 5
        bcm1 = BcmMsg(
            opcode=opcode,
            flags=flags,
            can_id=can_id,
            frames=frames,
            ival1=interval1,
            ival2=interval2,
        )
        bcm_as_bytes = bcm1.to_bytes()
        assert len(bcm_as_bytes) == BcmMsg.get_size() + (CanFrame.get_size() *
                                                         len(frames))

        bcm2 = BcmMsg.from_bytes(bcm_as_bytes)
        assert bcm1 == bcm2
コード例 #2
0
ファイル: test_socketcan.py プロジェクト: menschel/socketcan
    def test_unequal_bcm_msgs(self):
        can_id = 0x123
        data = bytes(range(0, 0x88, 0x11))

        frame1 = CanFrame(can_id=can_id, data=data)
        opcode = BcmOpCodes.TX_SETUP
        flags = (BCMFlags.SETTIMER | BCMFlags.STARTTIMER)
        frames = [
            frame1,
        ]
        interval = 0.1
        bcm1 = BcmMsg(
            opcode=opcode,
            flags=flags,
            can_id=can_id,
            frames=frames,
            ival2=interval,
        )
        bcm_as_bytes = bcm1.to_bytes()
        assert len(bcm_as_bytes) == BcmMsg.get_size() + (CanFrame.get_size() *
                                                         len(frames))

        interval2 = 1
        bcm2 = BcmMsg(
            opcode=opcode,
            flags=flags,
            can_id=can_id,
            frames=frames,
            ival2=interval2,
        )

        assert bcm1 != bcm2
コード例 #3
0
ファイル: test_socketcan.py プロジェクト: menschel/socketcan
    def test_unequal_frames(self):
        can_id1 = 0x123
        data1 = bytes(range(0, 0x88, 0x11))
        frame1 = CanFrame(can_id=can_id1, data=data1)

        can_id2 = 0x12345678
        data2 = bytes(range(0, 0x44, 0x11))
        frame2 = CanFrame(can_id=can_id2, data=data2)

        assert frame1 != frame2
コード例 #4
0
ファイル: test_socketcan.py プロジェクト: menschel/socketcan
    def test_can_frame_creation_with_long_id_and_no_eff_flag(self):
        can_id = 0x12345678
        data = bytes(range(0, 0x88, 0x11))
        frame1 = CanFrame(can_id=can_id, data=data)
        flags = frame1.flags
        assert (flags & CanFlags.CAN_EFF_FLAG)
        assert not (flags & CanFlags.CAN_RTR_FLAG)
        assert not (flags & CanFlags.CAN_ERR_FLAG)
        frame_as_bytes = frame1.to_bytes()

        assert len(frame_as_bytes) == CanFrame.get_size()

        frame2 = CanFrame.from_bytes(frame_as_bytes)
        assert frame1 == frame2
コード例 #5
0
ファイル: test_socketcan.py プロジェクト: menschel/socketcan
    def test_can_raw_socket(self):
        interface = "vcan0"
        s = CanRawSocket(interface=interface)
        can_id = 0x12345678
        data = bytes(range(0, 0x88, 0x11))
        frame1 = CanFrame(can_id=can_id, data=data)

        q = Queue()
        p = Thread(target=self.receive_from_can_raw_socket,
                   args=(
                       interface,
                       q,
                   ))
        p.setDaemon(True)
        p.start()
        time.sleep(1)
        s.send(frame1)
        frame2 = q.get()
        p.join()

        assert frame1 == frame2
コード例 #6
0
ファイル: test_socketcan.py プロジェクト: menschel/socketcan
    def test_bcm_msg_and_bcm_socket_send_operation(self):
        interface = "vcan0"
        s = CanBcmSocket(interface=interface)

        can_id = 0x12345678
        data = bytes(range(0, 0x88, 0x11))
        frame1 = CanFrame(can_id=can_id, data=data)

        bcm = BcmMsg(
            opcode=BcmOpCodes.TX_SETUP,
            flags=(BCMFlags.SETTIMER | BCMFlags.STARTTIMER),
            can_id=can_id,
            frames=[
                frame1,
            ],
            ival1=0,
            ival2=1,
        )
        q = Queue()
        p = Thread(target=self.receive_from_can_raw_socket,
                   args=(
                       interface,
                       q,
                   ))
        p.setDaemon(True)
        p.start()
        try:
            s.send(bcm)
        except OSError:
            assert False, "The length of bcm_msg is false. Length {0} Platform {1}".format(
                len(bcm.to_bytes()), platform.machine())
        else:
            time.sleep(1)
            frame2 = q.get()
            p.join()

            assert frame1 == frame2
コード例 #7
0
ファイル: can.py プロジェクト: Lufftre/maximeter
def polar_performance(percentage, src=35, dst=255, prio=3):
    can_id = to_can_id(130313, src, dst, prio)
    data = humidity_data(0xff, 0x01, 0x01, percentage, 0)
    frame = CanFrame(can_id=can_id, data=data)
    return frame
コード例 #8
0
ファイル: can.py プロジェクト: Lufftre/maximeter
def iso_address_claim(src=35, dst=255, prio=6):
    can_id = to_can_id(60928, src, dst, prio)
    frame = CanFrame(can_id=can_id, data=b'\xff\xff\xff\xff\xff\xff\xff\xff')
    return frame