24 lines
817 B
Python
24 lines
817 B
Python
from protocan.periph28335 import (
|
|
bits_lsb_first, build_command, build_read_registers,
|
|
build_write_register, crc16_modbus, word_from_bits,
|
|
)
|
|
|
|
|
|
def test_read_request_matches_delphi_byte_order():
|
|
request = build_read_registers(16, 24, 64)
|
|
assert request[:6] == bytes.fromhex("10 03 00 18 00 40")
|
|
assert int.from_bytes(request[-2:], "little") == crc16_modbus(request[:-2])
|
|
|
|
|
|
def test_write_and_command_use_register_127():
|
|
request = build_write_register(16, 7, 0x1234)
|
|
assert request[:6] == bytes.fromhex("10 06 00 07 12 34")
|
|
command = build_command(16, 15)
|
|
assert command[:6] == bytes.fromhex("10 06 00 7F 80 00")
|
|
|
|
|
|
def test_bits_keep_original_lsb_first_order():
|
|
bits = bits_lsb_first(0x8005)
|
|
assert bits[0] and bits[2] and bits[15]
|
|
assert word_from_bits(bits) == 0x8005
|