diff --git a/connections/connection.py b/connections/connection.py index 48d4806e..9188a2bc 100644 --- a/connections/connection.py +++ b/connections/connection.py @@ -2,7 +2,7 @@ from collections import namedtuple from typing import Callable -ConnectionMessage = namedtuple('ConnectionMessage', ['device_address', 'connection', 'data']) +ConnectionMessage = namedtuple('ConnectionMessage', ['device_address', 'connection', 'data','signal_strength']) class Connection(ABC): diff --git a/connections/debug/debug_connection.py b/connections/debug/debug_connection.py index 650d4d97..1eb23cc0 100644 --- a/connections/debug/debug_connection.py +++ b/connections/debug/debug_connection.py @@ -59,17 +59,18 @@ def _run(self) -> None: # full_arr.extend(self.bad_subpacket_id_mock()) # bad id, to see handling of itself and remaining data full_arr.extend(self.gps_mock_random()) full_arr.extend(self.orientation_mock_random()) - self.receive(full_arr) + signal_strength = random.uniform(0,255) + self.receive(full_arr,signal_strength) LOGGER.warning(f"Debug connection thread shut down (device_address={self.device_address})") - def receive(self, data): + def receive(self, data, signal_strength): with self.lock: if not self.callback: raise Exception("Can't receive data. Callback not set.") - message = ConnectionMessage(device_address=self.device_address, connection=self, data=data) + message = ConnectionMessage(device_address=self.device_address, connection=self, data=data, signal_strength=signal_strength) self.callback(message) @@ -196,9 +197,9 @@ def broadcast(self, data) -> None: # must be thead safe elif data == bytes([0x44]): DISARMED_EVENT.increment() elif data == bytes([0x50]): - self.receive(self.status_ping_mock_set_values()) + self.receive(self.status_ping_mock_set_values(),25) #TODO: FIX THIS 25 SHOUDL BE STRENGTH elif data == bytes([0x43]): - self.receive(self.config_mock_set_values()) + self.receive(self.config_mock_set_values(),25) def shutdown(self) -> None: if not self.connectionThread.is_alive(): diff --git a/connections/serial/serial_connection.py b/connections/serial/serial_connection.py index b84f651c..31014ffb 100644 --- a/connections/serial/serial_connection.py +++ b/connections/serial/serial_connection.py @@ -21,7 +21,10 @@ def _newData(self, xbee_message): message = ConnectionMessage( device_address=str(xbee_message.remote_device.get_64bit_addr()), connection=self, - data=xbee_message.data) + data=xbee_message.data, + signal_strength = int(self.device.get_parameter("DB"),16)) + #seems like you can get signal strength value (hex) through DB parameter + #https://www.digi.com/resources/documentation/Digidocs/90001456-13/concepts/c_rssi_pin_and_signal_strength.htm self.callback(message) diff --git a/main_window/data_entry_id.py b/main_window/data_entry_id.py index 064d056a..0cff7261 100644 --- a/main_window/data_entry_id.py +++ b/main_window/data_entry_id.py @@ -37,6 +37,8 @@ class DataEntryIds(Enum): ACCELEROMETER = auto() IMU = auto() + SIGNAL_STRENGTH = auto() + # Status OVERALL_STATUS = auto() DROGUE_IGNITER_CONTINUITY = auto() diff --git a/main_window/read_thread.py b/main_window/read_thread.py index c84045e9..3279be71 100644 --- a/main_window/read_thread.py +++ b/main_window/read_thread.py @@ -78,6 +78,7 @@ def run(self): full_address = FullAddress(connection_name=self.connection_to_name[connection], device_address=connection_message.device_address) data = connection_message.data + signal_strength = connection_message.signal_strength byte_stream: BytesIO = BytesIO(data) @@ -91,6 +92,7 @@ def run(self): try: self.packet_parser.set_endianness(connection.isIntBigEndian(), connection.isFloatBigEndian()) parsed_data: Dict[DataEntryIds, any] = self.packet_parser.extract(byte_stream) + parsed_data[DataEntryIds.SIGNAL_STRENGTH] = signal_strength if DataEntryIds.DEVICE_TYPE in parsed_data and DataEntryIds.VERSION_ID in parsed_data: self.device_manager.register_device(parsed_data[DataEntryIds.DEVICE_TYPE], parsed_data[DataEntryIds.VERSION_ID], full_address) diff --git a/profiles/label.py b/profiles/label.py index 636a4573..49a93164 100644 --- a/profiles/label.py +++ b/profiles/label.py @@ -84,6 +84,12 @@ def update_acceleration(rocket_data: RocketData, device: DeviceType) -> str: else: return VALUE_NOT_AVAILABLE +def update_signal_strength(rocket_data: RocketData, device: DeviceType) -> str: + sig_strength = rocket_data.last_value_by_device(device, DataEntryIds.SIGNAL_STRENGTH) + if sig_strength is not None: + return f'{sig_strength:.2f} -dBm' + else: + return VALUE_NOT_AVAILABLE # TODO: Implement Tantalus test separation label update. def update_test_separation(rocket_data: RocketData, device: DeviceType) -> str: diff --git a/profiles/rockets/tantalus.py b/profiles/rockets/tantalus.py index 3ccf03fa..b2626463 100644 --- a/profiles/rockets/tantalus.py +++ b/profiles/rockets/tantalus.py @@ -6,6 +6,7 @@ update_max_altitude, update_pressure, update_state, + update_signal_strength ) from ..rocket_profile import RocketProfile, FlightPoint from connections.serial.serial_connection import SerialConnection @@ -51,6 +52,7 @@ def labels(self): Label(DeviceType.TANTALUS_STAGE_1_FLARE, "Pressure", update_pressure), Label(DeviceType.TANTALUS_STAGE_1_FLARE, "Acceleration", update_acceleration), Label(DeviceType.TANTALUS_STAGE_2_FLARE, "Stage2State", update_state, "Stage 2 State"), + Label(DeviceType.TANTALUS_STAGE_1_FLARE, "SignalStrength", update_signal_strength, "Signal Strength") ] @property