test_hth6400.py 747 B

1234567891011121314151617
  1. from hth6400 import (
  2. SetAll, set_all_uart, set_all_i2c, snapshot_reads,
  3. uart_frame, decode_frame, decode_ack_nack, decode_snapshot,
  4. )
  5. v = SetAll((0,) * 18 + (100,) * 6, (20, 20, 20, 30), (20, 20, 20, 10))
  6. assert set_all_uart(v).hex().upper() == 'A55A01200000000000000000000000000000000000006464646464641414141E1414140A4205'
  7. assert len(set_all_i2c(v)) == 2
  8. assert [x[2] for x in snapshot_reads(201)] == [64, 64, 64, 9]
  9. ack = uart_frame(0x06, bytes((1, 0x01, 0, 0)))
  10. assert decode_frame(ack)[0] == 0x06
  11. assert decode_ack_nack(ack) == {
  12. 'ok': True, 'request': 1, 'status': 0, 'status_name': 'OK', 'detail': 0,
  13. }
  14. snapshot = uart_frame(0x82, bytes(range(16)))
  15. assert decode_snapshot(snapshot, 16) == bytes(range(16))
  16. print('PY6400_PASS')