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

31 lines
869 B
Python

import struct
import sys, os
import math
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'pybusmonitor1553')))
from Grifo_E_1553lib.messages.msg2_data_link_target import Msg2DataLinkTarget
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 = Msg2DataLinkTarget()
try:
# positions are meters; angles are provided in radians
m.set_target(6, -150.0, 50.0, math.radians(321), presentation_raw=0x4142, call_sign_chars=(0x43,0x44))
except Exception:
pass
dump_message_words(m)
if __name__ == '__main__':
main()