예제 #1
0
def test_get_mode():
    cmd = OBDCommand("", "", b"0123", 4, noop, ECU.ENGINE)
    assert cmd.mode == 0x01

    cmd = OBDCommand("", "", b"", 4, noop, ECU.ENGINE)
    assert cmd.mode == None

    cmd = OBDCommand("", "", b"totally not hex", 4, noop, ECU.ENGINE)
    assert cmd.mode == None
예제 #2
0
def test_pid():
    cmd = OBDCommand("", "", b"0123", 4, noop, ECU.ENGINE)
    assert cmd.pid == 0x23

    cmd = OBDCommand("", "", b"01", 4, noop, ECU.ENGINE)
    assert cmd.pid == None

    cmd = OBDCommand("", "", b"totally not hex", 4, noop, ECU.ENGINE)
    assert cmd.mode == None
예제 #3
0
def test_clone():
    #                 name       description        mode  cmd bytes decoder
    cmd = OBDCommand("", "", b"0123", 2, noop, ECU.ENGINE)
    other = cmd.clone()

    assert cmd.name == other.name
    assert cmd.desc == other.desc
    assert cmd.command == other.command
    assert cmd.bytes == other.bytes
    assert cmd.decode == other.decode
    assert cmd.ecu == other.ecu
    assert cmd.fast == cmd.fast
예제 #4
0
def test_clone():
    #                 name       description        mode  cmd bytes decoder
    cmd = OBDCommand("", "", b"0123", 2, noop, ECU.ENGINE)
    other = cmd.clone()

    assert cmd.name == other.name
    assert cmd.desc == other.desc
    assert cmd.command == other.command
    assert cmd.bytes == other.bytes
    assert cmd.decode == other.decode
    assert cmd.ecu == other.ecu
    assert cmd.fast == cmd.fast
예제 #5
0
def test_constructor():
    # default constructor
    #                 name       description        cmd  bytes decoder ECU
    cmd = OBDCommand("Test", "example OBD command", b"0123", 2, noop,
                     ECU.ENGINE)
    assert cmd.name is "Test"
    assert cmd.desc is "example OBD command"
    assert cmd.command == b"0123"
    assert cmd.bytes == 2
    assert cmd.decode == noop
    assert cmd.ecu == ECU.ENGINE
    assert cmd.fast is False

    assert cmd.mode == 1
    assert cmd.pid == 35

    # a case where "fast", and "supported" were set explicitly
    #                 name       description        cmd  bytes decoder ECU         fast
    cmd = OBDCommand("Test 2", "example OBD command", b"0123", 2, noop,
                     ECU.ENGINE, True)
    assert cmd.fast is True
예제 #6
0
def test_call():
    p = SAE_J1850_PWM(["48 6B 10 41 00 FF FF FF FF AA"
                       ])  # train the ecu_map to identify the engine
    messages = p(["48 6B 10 41 00 BE 1F B8 11 AA"
                  ])  # parse valid data into response object

    print(messages[0].data)

    # valid response size
    cmd = OBDCommand("", "", b"0123", 6, noop, ECU.ENGINE)
    r = cmd(messages)
    assert r.value == bytearray([0x41, 0x00, 0xBE, 0x1F, 0xB8, 0x11])

    # response too short (pad)
    cmd = OBDCommand("", "", b"0123", 7, noop, ECU.ENGINE)
    r = cmd(messages)
    assert r.value == bytearray([0x41, 0x00, 0xBE, 0x1F, 0xB8, 0x11, 0x00])

    # response too long (clip)
    cmd = OBDCommand("", "", b"0123", 5, noop, ECU.ENGINE)
    r = cmd(messages)
    assert r.value == bytearray([0x41, 0x00, 0xBE, 0x1F, 0xB8])
예제 #7
0
def test_call():
    p = SAE_J1850_PWM(["48 6B 10 41 00 FF FF FF FF AA"
                       ])  # train the ecu_map to identify the engine
    messages = p(["48 6B 10 41 00 BE 1F B8 11 AA"
                  ])  # parse valid data into response object

    print(messages[0].data)

    # valid response size
    cmd = OBDCommand("", "", "0123", 4, noop, ECU.ENGINE)
    r = cmd(messages)
    assert r.value == b'\xBE\x1F\xB8\x11'

    # response too short (pad)
    cmd = OBDCommand("", "", "0123", 5, noop, ECU.ENGINE)
    r = cmd(messages)
    assert r.value == b'\xBE\x1F\xB8\x11\x00'

    # response too long (clip)
    cmd = OBDCommand("", "", "0123", 3, noop, ECU.ENGINE)
    r = cmd(messages)
    assert r.value == b'\xBE\x1F\xB8'
예제 #8
0
        message = Message([])
        message.data = bytearray(b'response data')
        message.ecu = ECU.ENGINE  # picked engine so that simple commands like RPM will work
        return [message]

    def _test_last_command(self, expected):
        r = self._last_command == expected
        self._last_command = None
        return r


# a toy command to test with
command = OBDCommand("Test_Command", \
                     "A test command", \
                     "0123456789ABCDEF", \
                     0, \
                     noop, \
                     ECU.ALL, \
                     True)


def test_is_connected():
    o = obd.OBD("/dev/null")
    assert not o.is_connected()

    # our fake ELM class always returns success for connections
    o.interface = FakeELM("/dev/null")
    assert o.is_connected()


def test_status():
예제 #9
0
def test_pid_int():
    cmd = OBDCommand("", "", "0123", 4, noop, ECU.ENGINE)
    assert cmd.pid_int == 0x23

    cmd = OBDCommand("", "", "01", 4, noop, ECU.ENGINE)
    assert cmd.pid_int == 0
예제 #10
0
def test_get_mode_int():
    cmd = OBDCommand("", "", "0123", 4, noop, ECU.ENGINE)
    assert cmd.mode_int == 0x01

    cmd = OBDCommand("", "", "", "23", 4, noop, ECU.ENGINE)
    assert cmd.mode_int == 0
예제 #11
0
        message = Message([])
        message.data = bytearray(b'response data')
        message.ecu = ECU.ENGINE  # picked engine so that simple commands like RPM will work
        return [message]

    def _test_last_command(self, expected):
        r = self._last_command == expected
        self._last_command = None
        return r


# a toy command to test with
command = OBDCommand("Test_Command",
                     "A test command",
                     "0123456789ABCDEF",
                     0,
                     noop,
                     ECU.ALL,
                     True)


def test_is_connected():
    o = obd.OBD("/dev/null")
    assert not o.is_connected()

    # our fake ELM class always returns success for connections
    o.interface = FakeELM("/dev/null")
    assert o.is_connected()


def test_status():