33 lines
1.3 KiB
Python
33 lines
1.3 KiB
Python
import sys
|
|
import os
|
|
import struct
|
|
import ctypes
|
|
|
|
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
|
|
if ROOT not in sys.path:
|
|
sys.path.insert(0, ROOT)
|
|
|
|
from pymsc.lib1553.structures import Udp1553Header, Udp1553Message, CommandWord
|
|
from pymsc.lib1553.constants import Marker
|
|
from pymsc.lib1553.messages.a3_graphic_setting import MsgA3Payload
|
|
from pymsc.lib1553.message_base import BaseMessage
|
|
|
|
|
|
def test_base_message_pack_inverted_cw():
|
|
# Create BaseMessage for A3
|
|
# is_transmit=True -> include payload in packed bytes
|
|
msg = BaseMessage('A3', MsgA3Payload, sub_addr=3, frequency=0, is_transmit=True)
|
|
packed = msg.pack()
|
|
# Find CTRL_BEGIN marker somewhere in the packed bytes (may be without Udp1553Header)
|
|
ctrl_begin = struct.pack('<H', Marker.CTRL_BEGIN)
|
|
pos = packed.find(ctrl_begin)
|
|
assert pos != -1, 'CTRL_BEGIN not found in packed bytes'
|
|
|
|
wrapper = Udp1553Message.from_buffer_copy(packed[pos:pos+ctypes.sizeof(Udp1553Message)])
|
|
cw_raw = int(wrapper.cw.raw)
|
|
# payload length after wrapper
|
|
payload_start = pos + ctypes.sizeof(Udp1553Message)
|
|
payload_len = ctypes.sizeof(MsgA3Payload)
|
|
inv_in_packet = struct.unpack_from('<H', packed, payload_start + payload_len)[0]
|
|
assert inv_in_packet == ((~cw_raw) & 0xFFFF)
|