47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
import time
|
|
import socket
|
|
import os
|
|
import sys
|
|
|
|
# Assicuriamoci che la root del repository sia nel PYTHONPATH così possiamo importare il package `pymsc`.
|
|
repo_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
|
|
if repo_root not in sys.path:
|
|
sys.path.insert(0, repo_root)
|
|
|
|
from pymsc.core.app_controller import AppController
|
|
from pymsc.lib1553.structures import Udp1553Header, Udp1553Message, CommandWord
|
|
from pymsc.lib1553.constants import Marker
|
|
|
|
print('Test: avvio AppController')
|
|
app = AppController()
|
|
app.start()
|
|
|
|
# attendi che il receiver sia pronto
|
|
time.sleep(1.0)
|
|
|
|
print('Test: costruisco pacchetto di prova')
|
|
header = Udp1553Header()
|
|
header.marker_1553 = Marker.START_1553
|
|
header.o_type = 0x5452
|
|
|
|
cw = CommandWord(wc=32, sa=1, tr=0, rt=20)
|
|
msg_wrapper = Udp1553Message(marker=Marker.CTRL_BEGIN, cw=cw)
|
|
payload = b'\x00' * 64
|
|
packet = bytes(header) + bytes(msg_wrapper) + payload
|
|
|
|
print(f'Test: invio pacchetto a 127.0.0.1:{app.udp_recv_port}')
|
|
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
|
sock.sendto(packet, ('127.0.0.1', app.udp_recv_port))
|
|
|
|
# lasciare tempo al receiver di processare
|
|
time.sleep(1.0)
|
|
|
|
print('Test: contenuto della monitor_queue (se presente):')
|
|
while not app.monitor_queue.empty():
|
|
item = app.monitor_queue.get()
|
|
print(item)
|
|
|
|
print('Test: fermo AppController')
|
|
app.stop()
|
|
print('Test completato')
|