60 lines
1.9 KiB
Python
60 lines
1.9 KiB
Python
import os
|
|
import sys
|
|
import time
|
|
import socket
|
|
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.core.app_controller import AppController
|
|
from pymsc.lib1553.structures import Udp1553Message, Udp1553Header, CommandWord
|
|
from pymsc.lib1553.constants import Marker
|
|
from pymsc.lib1553.messages.a3_graphic_setting import MsgA3Payload
|
|
|
|
|
|
def build_a3_packet():
|
|
payload = MsgA3Payload()
|
|
payload.graphic_order = 7
|
|
payload.time_to_go = 42
|
|
payload_bytes = bytes(payload)
|
|
|
|
cw = CommandWord(wc=len(payload_bytes)//2, sa=3, tr=1, rt=20)
|
|
wrapper = Udp1553Message(marker=Marker.CTRL_BEGIN, cw=cw, sw=0, error_code=0)
|
|
cw_raw = int(wrapper.cw.raw)
|
|
inv = (~cw_raw) & 0xFFFF
|
|
|
|
packet = bytes(Udp1553Header()) + bytes(wrapper) + payload_bytes + struct.pack('<H', inv) + struct.pack('<H', Marker.CTRL_END) + struct.pack('<H', Marker.END_1553)
|
|
return packet
|
|
|
|
|
|
def test_appcontroller_receives_a3():
|
|
c = AppController()
|
|
c.start()
|
|
try:
|
|
time.sleep(0.05)
|
|
pkt = build_a3_packet()
|
|
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
|
sock.sendto(pkt, ('127.0.0.1', c.udp_recv_port))
|
|
|
|
# wait for monitor queue item
|
|
got = None
|
|
timeout = time.time() + 2.0
|
|
while time.time() < timeout:
|
|
try:
|
|
item = c.monitor_queue.get(timeout=0.2)
|
|
# expect label 'A3' somewhere
|
|
if isinstance(item, tuple) and len(item) >= 3 and item[1] == 'A3':
|
|
got = item
|
|
break
|
|
except Exception:
|
|
pass
|
|
|
|
assert got is not None, 'Did not receive decoded A3 in monitor_queue'
|
|
# if payload decoded, third element contains JSON string or dict
|
|
assert 'graphic_order' in str(got[3]) or 'CW' in str(got[3])
|
|
finally:
|
|
c.stop()
|