import socket
import struct
import ctypes
from Grifo_E_1553lib import mil1553udp
from Grifo_E_1553lib.mil1553udp import UDP1553Header
from Grifo_E_1553lib.messages.msg_rdr_operation_command import MsgRdrOperationCommand
from Grifo_E_1553lib.data_types.enums import RdrModes

UDP_IP = "127.0.0.1"
UDP_PORT = 5005

print(f"Sending A2 to {UDP_IP}:{UDP_PORT}")

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

# Crea un header UDP1553 di esempio
header = UDP1553Header()
header.marker1553 = 0x1553
header.otype = 0x4342  # BC
packed_header = bytes(header)

# Crea un messaggio MsgRdrOperationCommand di esempio
message = MsgRdrOperationCommand()
message.rdr_mode_command.set_master_mode(RdrModes.ACM)
packed_message = bytes(message)

# Combina l'header e il messaggio
message = packed_header + packed_message

sock.sendto(message, (UDP_IP, UDP_PORT))

print("Message A2 sent!")