SXXXXXXX_PyBusMonitor1553/tests/test_a7_pack.py
2026-01-07 10:41:14 +01:00

33 lines
986 B
Python

import struct
import sys, os
import math
# ensure local package path is first so we import the workspace Grifo_E_1553lib
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'pybusmonitor1553')))
from Grifo_E_1553lib.messages.msg1_data_link_target import Msg1DataLinkTarget
def dump_message_words(msg):
b = bytes(msg)
nwords = len(b)//2
le = struct.unpack("<%dH" % nwords, b)
be = struct.unpack(">%dH" % nwords, b)
print(f"msg len={len(b)} bytes, words={nwords}")
print("LE words:", [hex(x) for x in le])
print("BE words:", [hex(x) for x in be])
return le, be
def main():
m = Msg1DataLinkTarget()
# populate target 1 using helper
try:
# positions are meters; angles are provided in radians
m.set_target(1, 100.0, 200.0, math.radians(123), presentation_raw=0x1234, call_sign_chars=(0x41,0x42))
except Exception:
pass
dump_message_words(m)
if __name__ == '__main__':
main()