From b08117155b2cc95b42cb39be08b22c3a6ba839c8 Mon Sep 17 00:00:00 2001 From: Gabriel Mariano Marcelino Date: Thu, 26 Sep 2024 20:05:26 -0300 Subject: [PATCH] Adding the option to transmit the telecommand over a TCP socket --- .../data/ui/spacelab_transmitter.glade | 173 ++++++++++++++---- spacelab_transmitter/spacelabtransmitter.py | 111 ++++++++--- spacelab_transmitter/version.py | 2 +- 3 files changed, 230 insertions(+), 56 deletions(-) diff --git a/spacelab_transmitter/data/ui/spacelab_transmitter.glade b/spacelab_transmitter/data/ui/spacelab_transmitter.glade index efee586..749a63d 100644 --- a/spacelab_transmitter/data/ui/spacelab_transmitter.glade +++ b/spacelab_transmitter/data/ui/spacelab_transmitter.glade @@ -379,13 +379,13 @@ Author: Vitória Beatriz Bianchin True False start + 5 vertical 5 True False - 5 0.05000000074505806 @@ -393,7 +393,7 @@ Author: Vitória Beatriz Bianchin False 12 - + True False @@ -462,21 +462,6 @@ Author: Vitória Beatriz Bianchin 1 - - - - - - - - - - - - - - - @@ -502,7 +487,6 @@ Author: Vitória Beatriz Bianchin -1 True False - 5 0.05000000074505806 @@ -510,7 +494,7 @@ Author: Vitória Beatriz Bianchin False 12 - + -1 -1 @@ -627,40 +611,167 @@ Author: Vitória Beatriz Bianchin 0 + + + + + + + True + False + start + SDR + + + + + False + True + 1 + + + + + True + False + 0.05000000074505806 + + + True + False + 12 + + + + True + False + 5 + 5 + 5 + 10 + 5 + 5 + + + True + False + start + Address: + + + 0 + 0 + + - + + True + False + start + Port: + + + 0 + 1 + - + + True + True + True + 127.0.0.1 + + + 1 + 0 + - + + True + True + True + 7236 + + + 1 + 1 + - + + True + False + 5 + + + True + True + True + Connect + True + + + True + False + gtk-connect + + + + + False + True + 0 + + + + + True + False + True + True + Disconnect + True + + + True + False + gtk-disconnect + + + + + False + True + 1 + + + + + 0 + 2 + 2 + - + True False - start - SDR + TCP Socket False True - 1 + 2 - - - False @@ -672,7 +783,6 @@ Author: Vitória Beatriz Bianchin True True vertical - True True @@ -946,6 +1056,7 @@ Author: Vitória Beatriz Bianchin True True 5 + 5 in diff --git a/spacelab_transmitter/spacelabtransmitter.py b/spacelab_transmitter/spacelabtransmitter.py index 0c678e4..b2b6180 100644 --- a/spacelab_transmitter/spacelabtransmitter.py +++ b/spacelab_transmitter/spacelabtransmitter.py @@ -29,6 +29,7 @@ import pathlib import json import csv +import socket import gi gi.require_version('Gtk', '3.0') @@ -142,6 +143,8 @@ def __init__(self): else: self.builder.add_from_file(_UI_FILE_LINUX_SYSTEM) + self._client_socket = None + self.builder.connect_signals(self) self._build_widgets() @@ -214,6 +217,14 @@ def _build_widgets(self): self.combobox_satellite.add_attribute(cell, "text", 0) self.combobox_satellite.connect("changed", self.on_combobox_satellite_changed) + # TCP socket + self.entry_tcp_address = self.builder.get_object("entry_tcp_address") + self.entry_tcp_port = self.builder.get_object("entry_tcp_port") + self.button_tcp_connect = self.builder.get_object("button_tcp_connect") + self.button_tcp_connect.connect("clicked", self.on_button_tcp_connect_clicked) + self.button_tcp_disconnect = self.builder.get_object("button_tcp_disconnect") + self.button_tcp_disconnect.connect("clicked", self.on_button_tcp_disconnect_clicked) + # Preferences dialog self.button_preferences = self.builder.get_object("button_preferences") self.button_preferences.connect("clicked", self.on_button_preferences_clicked) @@ -313,6 +324,10 @@ def run(self): def on_main_window_destroy(self, window): self._save_preferences() + + if self._client_socket: + self._client_socket.close() + Gtk.main_quit() def on_button_ping_request_command_clicked(self, button): @@ -632,36 +647,47 @@ def _transmit_tc(self, pkt, tc_name): enc_pkt = prot.encode(pkt) - mod = None - if mod_name == _MODULATION_GMSK: - mod = GMSK(0.5, baud) # BT = 0.5 - else: - error_dialog = Gtk.MessageDialog(None, 0, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, "Error transmitting a" + tc_name + "telecommand!") - error_dialog.format_secondary_text("The" + mod_name + "modulation is not supported yet!") - error_dialog.run() - error_dialog.destroy() + if self.button_tcp_connect.get_sensitive(): + mod = None + if mod_name == _MODULATION_GMSK: + mod = GMSK(0.5, baud) # BT = 0.5 + else: + error_dialog = Gtk.MessageDialog(None, 0, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, "Error transmitting a" + tc_name + "telecommand!") + error_dialog.format_secondary_text("The" + mod_name + "modulation is not supported yet!") + error_dialog.run() + error_dialog.destroy() - return + return - samples, sample_rate, duration_s = mod.modulate(enc_pkt, 1000) + samples, sample_rate, duration_s = mod.modulate(enc_pkt, 1000) - sdr = None - if self.combobox_sdr.get_active() == 0: # USRP - sdr = USRP(int(self.entry_sample_rate.get_text()), int(tx_gain)) - elif self.combobox_sdr.get_active() == 1: # Pluto SDR - sdr = Pluto(int(self.entry_sample_rate.get_text()), int(tx_gain)) - else: - error_dialog = Gtk.MessageDialog(None, 0, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, "Error transmitting a" + tc_name + "telecommand!") - error_dialog.format_secondary_text("SDR device not supported yet!") - error_dialog.run() - error_dialog.destroy() + sdr = None + if self.combobox_sdr.get_active() == 0: # USRP + sdr = USRP(int(self.entry_sample_rate.get_text()), int(tx_gain)) + elif self.combobox_sdr.get_active() == 1: # Pluto SDR + sdr = Pluto(int(self.entry_sample_rate.get_text()), int(tx_gain)) + else: + error_dialog = Gtk.MessageDialog(None, 0, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, "Error transmitting a" + tc_name + "telecommand!") + error_dialog.format_secondary_text("SDR device not supported yet!") + error_dialog.run() + error_dialog.destroy() - return + return - if sdr.transmit(samples, duration_s, sample_rate, int(carrier_frequency)): - self.write_log(tc_name + " transmitted to " + _SATELLITES[self.combobox_satellite.get_active()][0] + " from" + callsign + " in " + carrier_frequency + " Hz with a gain of " + tx_gain + " dB") + if sdr.transmit(samples, duration_s, sample_rate, int(carrier_frequency)): + self.write_log(tc_name + " transmitted to " + _SATELLITES[self.combobox_satellite.get_active()][0] + " from" + callsign + " in " + carrier_frequency + " Hz with a gain of " + tx_gain + " dB") + else: + self.write_log("Error transmitting a " + tc_name + " telecommand!") else: - self.write_log("Error transmitting a " + tc_name + " telecommand!") + if self._client_socket: + try: + self._client_socket.send(bytearray(enc_pkt)) # Send message to server + self.write_log(tc_name + " transmitted to " + _SATELLITES[self.combobox_satellite.get_active()][0] + " from" + callsign + " via " + self.entry_tcp_address.get_text() + ":" + self.entry_tcp_port.get_text()) + except socket.error as e: + error_dialog = Gtk.MessageDialog(None, 0, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, "Error transmitting a" + tc_name + "telecommand!") + error_dialog.format_secondary_text(str(e)) + error_dialog.run() + error_dialog.destroy() def on_button_broadcast_cancel_clicked(self, button): self.dialog_broadcast.hide() @@ -827,6 +853,43 @@ def on_combobox_sdr_changed(self, combobox): self.spinbutton_tx_gain.set_range(0, 90) self.spinbutton_tx_gain.set_value(_DEFAULT_GAIN_USRP) + def on_button_tcp_connect_clicked(self, button): + try: + adr = self.entry_tcp_address.get_text() + port = int(self.entry_tcp_port.get_text()) + self._client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self._client_socket.connect((adr, port)) + self.write_log("Connected to " + adr + ":" + str(port)) + + self.combobox_sdr.set_sensitive(False) + self.entry_carrier_frequency.set_sensitive(False) + self.entry_sample_rate.set_sensitive(False) + self.spinbutton_tx_gain.set_sensitive(False) + self.entry_tcp_address.set_sensitive(False) + self.entry_tcp_port.set_sensitive(False) + self.button_tcp_connect.set_sensitive(False) + self.button_tcp_disconnect.set_sensitive(True) + except socket.error as e: + error_dialog = Gtk.MessageDialog(None, 0, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, "Error connecting to server!") + error_dialog.format_secondary_text(str(e)) + error_dialog.run() + error_dialog.destroy() + + def on_button_tcp_disconnect_clicked(self, button): + self._client_socket.shutdown(socket.SHUT_RDWR) + self._client_socket.close() + + self.write_log("Disconnected from " + self.entry_tcp_address.get_text() + ":" + self.entry_tcp_port.get_text()) + + self.combobox_sdr.set_sensitive(True) + self.entry_carrier_frequency.set_sensitive(True) + self.entry_sample_rate.set_sensitive(True) + self.spinbutton_tx_gain.set_sensitive(True) + self.entry_tcp_address.set_sensitive(True) + self.entry_tcp_port.set_sensitive(True) + self.button_tcp_connect.set_sensitive(True) + self.button_tcp_disconnect.set_sensitive(False) + def _get_link_info(self): sat_config_file = str() diff --git a/spacelab_transmitter/version.py b/spacelab_transmitter/version.py index 8fc5d39..1b9919f 100644 --- a/spacelab_transmitter/version.py +++ b/spacelab_transmitter/version.py @@ -24,7 +24,7 @@ __copyright__ = "Copyright The SpaceLab-Transmitter Contributors" __credits__ = ["Gabriel Mariano Marcelino, Vitória Beatriz Bianchin"] __license__ = "GPLv3" -__version__ = "0.4.15" +__version__ = "0.4.16" __maintainer__ = "Gabriel Mariano Marcelino - PU5GMA" __email__ = "gabriel.mm8@gmail.com" __status__ = "Development"