diff --git a/.idea/runConfigurations/tmtcclient_Service_17_UDP.xml b/.idea/runConfigurations/tmtcclient_Service_17_UDP.xml index 9962a4d6b7389082436f47a8ab63fa7923757e19..f8ab43f96a2a4f9497d0d2bd5d76fcd602e00c9b 100644 --- a/.idea/runConfigurations/tmtcclient_Service_17_UDP.xml +++ b/.idea/runConfigurations/tmtcclient_Service_17_UDP.xml @@ -13,7 +13,7 @@ <option name="ADD_SOURCE_ROOTS" value="true" /> <EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" /> <option name="SCRIPT_NAME" value="$PROJECT_DIR$/obsw_tmtc_client.py" /> - <option name="PARAMETERS" value="-m 2 -c 3 -s 17 -t 3" /> + <option name="PARAMETERS" value="-m 3 -c 3 -s 17 -t 3" /> <option name="SHOW_COMMAND_LINE" value="false" /> <option name="EMULATE_TERMINAL" value="true" /> <option name="MODULE_MODE" value="false" /> diff --git a/.idea/runConfigurations/OBSW_UdpClient_Service_2_Test.xml b/.idea/runConfigurations/tmtcclient_Service_2_UDP.xml similarity index 73% rename from .idea/runConfigurations/OBSW_UdpClient_Service_2_Test.xml rename to .idea/runConfigurations/tmtcclient_Service_2_UDP.xml index 921369f6b3d45cef8249650a84a6180b950175fb..3b53a6225f5f28f88c758a9e9877b59a98b56495 100644 --- a/.idea/runConfigurations/OBSW_UdpClient_Service_2_Test.xml +++ b/.idea/runConfigurations/tmtcclient_Service_2_UDP.xml @@ -1,5 +1,5 @@ <component name="ProjectRunConfigurationManager"> - <configuration default="false" name="OBSW_UdpClient Service 2 Test" type="PythonConfigurationType" factoryName="Python" folderName="UDP Communication"> + <configuration default="false" name="tmtcclient Service 2 UDP" type="PythonConfigurationType" factoryName="Python" folderName="UDP Communication"> <module name="tmtc" /> <option name="INTERPRETER_OPTIONS" value="" /> <option name="PARENT_ENVS" value="true" /> @@ -12,8 +12,8 @@ <option name="ADD_CONTENT_ROOTS" value="true" /> <option name="ADD_SOURCE_ROOTS" value="true" /> <EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" /> - <option name="SCRIPT_NAME" value="C:\Users\Robin\NoSyncDokumente\sourceobsw\tmtc\obsw_tmtc_client.py" /> - <option name="PARAMETERS" value="-m 3 -s 2 -p" /> + <option name="SCRIPT_NAME" value="$PROJECT_DIR$/obsw_tmtc_client.py" /> + <option name="PARAMETERS" value="-m 3 -c 3 -s 2" /> <option name="SHOW_COMMAND_LINE" value="false" /> <option name="EMULATE_TERMINAL" value="false" /> <option name="MODULE_MODE" value="false" /> diff --git a/.idea/runConfigurations/OBSW_UdpClient_Service_8.xml b/.idea/runConfigurations/tmtcclient_Service_8_UDP.xml similarity index 81% rename from .idea/runConfigurations/OBSW_UdpClient_Service_8.xml rename to .idea/runConfigurations/tmtcclient_Service_8_UDP.xml index 1be681f48680aeb71575123e0c51db18c82daea1..f7797b9f92b1467733968774111393c5b01dd13f 100644 --- a/.idea/runConfigurations/OBSW_UdpClient_Service_8.xml +++ b/.idea/runConfigurations/tmtcclient_Service_8_UDP.xml @@ -1,5 +1,5 @@ <component name="ProjectRunConfigurationManager"> - <configuration default="false" name="OBSW_UdpClient Service 8" type="PythonConfigurationType" factoryName="Python" folderName="UDP Communication"> + <configuration default="false" name="tmtcclient Service 8 UDP" type="PythonConfigurationType" factoryName="Python" folderName="UDP Communication"> <module name="tmtc" /> <option name="INTERPRETER_OPTIONS" value="" /> <option name="PARENT_ENVS" value="true" /> @@ -12,8 +12,8 @@ <option name="ADD_CONTENT_ROOTS" value="true" /> <option name="ADD_SOURCE_ROOTS" value="true" /> <EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" /> - <option name="SCRIPT_NAME" value="C:\Users\Robin\NoSyncDokumente\sourceobsw\tmtc\obsw_tmtc_client.py" /> - <option name="PARAMETERS" value="-m 3 -s 8 -p" /> + <option name="SCRIPT_NAME" value="$PROJECT_DIR$/obsw_tmtc_client.py" /> + <option name="PARAMETERS" value="-m 3 -c 3 -s 8" /> <option name="SHOW_COMMAND_LINE" value="false" /> <option name="EMULATE_TERMINAL" value="true" /> <option name="MODULE_MODE" value="false" /> diff --git a/comIF/obsw_ethernet_com_if.py b/comIF/obsw_ethernet_com_if.py index 5818e0bb4cc321e09f7b54983a6be848ad85fcca..e2555f97e5f4b1824fab81fe8bae349b3855f6ad 100644 --- a/comIF/obsw_ethernet_com_if.py +++ b/comIF/obsw_ethernet_com_if.py @@ -26,37 +26,35 @@ class EthernetComIF(CommunicationInterface): """ def send_data(self, data: bytearray): - self.sock_send.sendto(data, self.send_address) + self.udp_socket.sendto(data, self.destination_address) def __init__(self, tmtc_printer: TmTcPrinter, tm_timeout: float, tc_timeout_factor: float, receive_address: g.ethernetAddressT, send_address: g.ethernetAddressT): super().__init__(tmtc_printer) self.tm_timeout = tm_timeout self.tc_timeout_factor = tc_timeout_factor - self.sock_send = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - self.sock_receive = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + self.udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.receive_address = receive_address - self.send_address = send_address - self.set_up_socket() + self.destination_address = send_address + self.set_up_socket(self.receive_address) def close(self) -> None: pass def send_telecommand(self, tc_packet: bytearray, tc_packet_info: PusTcInfoT = None) -> None: - self.sock_send.sendto(tc_packet, self.send_address) + self.udp_socket.sendto(tc_packet, self.destination_address) def data_available(self, timeout: float = 0) -> bool: - print("polling" + str(self.sock_receive)) - ready = select.select([self.sock_receive], [], [], timeout) + # print("polling" + str(self.udp_socket)) + ready = select.select([self.udp_socket], [], [], timeout) if ready[0]: - print("test!") return True return False def poll_interface(self, poll_timeout: float = 0) -> Tuple[bool, PusTmListT]: ready = self.data_available(poll_timeout) if ready: - data = self.sock_receive.recvfrom(1024)[0] + data = self.udp_socket.recvfrom(1024)[0] tm_packet = PusTelemetryFactory.create(bytearray(data)) self.tmtc_printer.print_telemetry(tm_packet) packet_list = [tm_packet] @@ -69,14 +67,14 @@ class EthernetComIF(CommunicationInterface): return packet_list return [] - def set_up_socket(self): + def set_up_socket(self, receive_address): """ Sets up the sockets for the UDP communication. :return: """ try: - self.sock_receive.bind(self.receive_address) - self.sock_receive.setblocking(False) + self.udp_socket.bind(receive_address) + self.udp_socket.setblocking(False) except OSError: print("Socket already set-up.") except TypeError: diff --git a/obsw_user_code.py b/obsw_user_code.py index 4bf120419f948c440aeac6d89f5bf58af86ca6bd..60d63ed57d09bf99f588426b3278f5a05f86147a 100644 --- a/obsw_user_code.py +++ b/obsw_user_code.py @@ -1,6 +1,7 @@ """ User defined code can be added here. """ +import socket from typing import Union, Tuple from tc.obsw_pus_tc_base import PusTcInfo from enum import Enum @@ -42,10 +43,12 @@ def prepare_robins_commands(): def global_setup_hook_robin(): import config.obsw_config - # Static IP of board + # Static IP of board. port_send = 7301 - send_address_to_set = ("127.0.0.1", port_send) + destination_address = ('', port_send) + + # Socket will be bound to this address. port_receive = 7302 - recv_address_to_set = ("", port_receive) + recv_address_to_set = ('', port_receive) config.obsw_config.G_REC_ADDRESS = recv_address_to_set - config.obsw_config.G_SEND_ADDRESS = send_address_to_set + config.obsw_config.G_SEND_ADDRESS = destination_address