Добавить общий протокол Periph28335

This commit is contained in:
2026-09-04 18:59:54 +03:00
parent 01ffc0e496
commit 454baeed98
2 changed files with 121 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
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