def test_raw_string():
    assert d.raw_string([Message([])]) == ("", Unit.NONE)
    assert d.raw_string([Message([Frame("NO DATA")])]) == ("NO DATA",
                                                           Unit.NONE)
    assert d.raw_string([Message([Frame("A"),
                                  Frame("B")])]) == ("A\nB", Unit.NONE)
    assert d.raw_string([Message([Frame("A")]),
                         Message([Frame("B")])]) == ("A\nB", Unit.NONE)
Exemple #2
0
	def __read(self):
		result = []
		for _ in range(1):
			message = Message([Frame("1" * 256)])
			message.ecu = ECU.ALL
			message.data = bytearray([randint(0, 255) for _ in range(6)])
			result.append(message)
		return result
Exemple #3
0
    def send_and_parse(self, cmd):
        # stow this, so we can check that the API made the right request
        print(cmd)
        self._last_command = cmd

        # all commands succeed
        message = Message([])
        message.data = bytearray(b'response data')
        message.ecu = ECU.ENGINE # picked engine so that simple commands like RPM will work
        return [ message ]
Exemple #4
0
    def send(self, cmd):
        # stow this, so we can check that the API made the right request
        print(cmd)
        self._last_command = cmd

        # all commands succeed
        message = Message([])
        message.data = bytearray(b'response data')
        message.ecu = ECU.ENGINE  # picked engine so that simple commands like RPM will work
        return [message]
Exemple #5
0
def test_message():

    # constructor
    frame = Frame("raw input from OBD tool")
    frame.tx_id = 42

    frames = [frame]

    # a message is simply a special container for a bunch of frames
    message = Message(frames)

    assert message.frames == frames
    assert message.ecu == ECU.UNKNOWN
    assert message.tx_id == 42  # this is dynamically read from the first frame

    assert Message(
        []
    ).tx_id == None  # if no frames are given, then we can't report a tx_id
Exemple #6
0
def test_message_hex():
    message = Message([])
    message.data = b'\x00\x01\x02'

    assert message.hex() == b'000102'
    assert unhex(message.hex()[0:2]) == 0x00
    assert unhex(message.hex()[2:4]) == 0x01
    assert unhex(message.hex()[4:6]) == 0x02
    assert unhex(message.hex()) == 0x000102
def test_message_hex():
    message = Message([])
    message.data = b'\x00\x01\x02'

    assert message.hex() == b'000102'
    assert int(message.hex()[0:2], 16) == 0x00
    assert int(message.hex()[2:4], 16) == 0x01
    assert int(message.hex()[4:6], 16) == 0x02
    assert int(message.hex(), 16) == 0x000102
def test_message_hex():
    message = Message([])
    message.data = b'\x00\x01\x02'

    assert message.hex() == b'000102'
    assert unhex(message.hex()[0:2]) == 0x00
    assert unhex(message.hex()[2:4]) == 0x01
    assert unhex(message.hex()[4:6]) == 0x02
    assert unhex(message.hex()) == 0x000102
Exemple #9
0
def test_message_hex():
    message = Message([])
    message.data = b'\x00\x01\x02'

    assert message.hex() == b'000102'
    assert int(message.hex()[0:2], 16) == 0x00
    assert int(message.hex()[2:4], 16) == 0x01
    assert int(message.hex()[4:6], 16) == 0x02
    assert int(message.hex(), 16) == 0x000102
Exemple #10
0
def m(hex_data, frames=None):
    # most decoders don't look at the underlying frame objects
    message = Message(frames or [])
    message.data = bytearray(unhexlify(hex_data))
    return [message]
def m(hex_data, frames=[]):
    # most decoders don't look at the underlying frame objects
    message = Message(frames)
    message.data = bytearray(unhexlify(hex_data))
    return [message]
def test_elm_voltage():
    # these aren't parsed as standard hex messages, so manufacture our own
    assert d.elm_voltage([Message([Frame("12.875")])]) == (12.875, Unit.VOLT)
    assert d.elm_voltage([Message([Frame("12")])]) == (12, Unit.VOLT)
    assert d.elm_voltage([Message([Frame("12ABCD")])]) == (None, Unit.NONE)
Exemple #13
0
def test_raw_string():
    assert d.raw_string([Message([])]) == ""
    assert d.raw_string([Message([Frame("NO DATA")])]) == "NO DATA"
    assert d.raw_string([Message([Frame("A"), Frame("B")])]) == "A\nB"
    assert d.raw_string([Message([Frame("A")]),
                         Message([Frame("B")])]) == "A\nB"
Exemple #14
0
def test_elm_voltage():
    # these aren't parsed as standard hex messages, so manufacture our own
    assert d.elm_voltage([Message([Frame("12.875")])]) == 12.875 * Unit.volt
    assert d.elm_voltage([Message([Frame("12")])]) == 12 * Unit.volt
    assert d.elm_voltage([Message([Frame(u"12.3V")])]) == 12.3 * Unit.volt
    assert d.elm_voltage([Message([Frame("12ABCD")])]) is None