diff --git a/applications/flight/Tasks/radio.py b/applications/flight/Tasks/radio.py index 5b11fec2..56a5da56 100644 --- a/applications/flight/Tasks/radio.py +++ b/applications/flight/Tasks/radio.py @@ -26,11 +26,11 @@ def should_transmit(): Return if we should transmit """ tx_ready = settings.TX_ALLOWED and not tq.empty() and cubesat.radio.fifo_empty() - tx_time_ready = time.time() < tx_before_time + # tx_time_ready = time.time() < tx_before_time if tx_ready: global tx_ready_counter tx_ready_counter += 1 - return tx_ready and (tx_ready_counter % TX_SKIP != 0) and tx_time_ready + return tx_ready and (tx_ready_counter % TX_SKIP != 0) class task(Task): name = 'radio' diff --git a/applications/flight/Tasks/telemetry.py b/applications/flight/Tasks/telemetry.py index 935425b5..14500a51 100644 --- a/applications/flight/Tasks/telemetry.py +++ b/applications/flight/Tasks/telemetry.py @@ -1,10 +1,15 @@ # Transmit "Hello World" beacon -from Tasks.log import LogTask as Task -from pycubed import cubesat +import time + import files import logs -import time +from pycubed import cubesat +from radio_utils import headers +from radio_utils.message import Message +from radio_utils.transmission_queue import transmission_queue as tq +from Tasks.log import LogTask as Task + class task(Task): name = 'beacon' @@ -33,6 +38,11 @@ def write_telemetry(self): boot = cubesat.c_boot current_file = f"/sd/logs/telemetry/{boot:05}/{hour_stamp}" telemetry_packet = logs.telemetry_packet(t) + self.downlink_telemetry(telemetry_packet) file = open(current_file, "ab+") file.write(telemetry_packet) file.close() + + def downlink_telemetry(self, packet): + tq.push(Message(10, packet, header=headers.BEACON, with_ack=False)) + self.debug("beacon added to transmission queue") diff --git a/applications/flight/lib/logs.py b/applications/flight/lib/logs.py index 5a5e1951..0d41f8b4 100644 --- a/applications/flight/lib/logs.py +++ b/applications/flight/lib/logs.py @@ -11,13 +11,13 @@ # 3 uint8 + 1 uint16 + 11 float32 # = 49 bytes of data # = 52 byte c struct (1 extra to align chars, 2 extra to align short) -beacon_format = 3 * 'B' + 'H' + 'f' * 11 +beacon_format = 3 * 'B' + 'H' + 'f' * 14 # Defines what the unpack_beacon will return beacon_tuple = namedtuple("beacon_tuple", ("state_index", "datetime_valid_flag", "contact_flag", "burn_flag", "software_error_count", "boot_count", "battery_voltage", "cpu_temperature_C", "imu_temperature_C", - "gyro", "mag", "RSSI_dB", "FEI_Hz")) + "gyro", "mag", "accel", "RSSI_dB", "FEI_Hz")) # 6 float32 # = 24 bytes of data @@ -55,6 +55,7 @@ def beacon_packet(): imu_temp = cubesat.temperature_imu if cubesat.imu and cubesat.has_imu_temp else nan gyro = cubesat.gyro if cubesat.imu else array([nan, nan, nan]) mag = cubesat.magnetic if cubesat.imu else array([nan, nan, nan]) + accel = cubesat.acceleration if cubesat.imu else array([nan, nan, nan]) rssi = cubesat.radio.last_rssi if cubesat.radio else nan fei = cubesat.radio.frequency_error if cubesat.radio else nan return struct.pack(beacon_format, @@ -62,6 +63,7 @@ def beacon_packet(): vbatt, cpu_temp, imu_temp, gyro[0], gyro[1], gyro[2], mag[0], mag[1], mag[2], + accel[0], accel[1], accel[2], rssi, fei) def system_packet(): @@ -118,16 +120,18 @@ def unpack_beacon(bytes): vbatt, cpu_temp, imu_temp, gyro0, gyro1, gyro2, mag0, mag1, mag2, + accel0, accel1, accel2, rssi, fei) = struct.unpack(beacon_format, bytes) gyro = array([gyro0, gyro1, gyro2]) mag = array([mag0, mag1, mag2]) + accel = array([accel0, accel1, accel2]) return beacon_tuple(state_byte, bool(flags & (0b1 << 2)), bool(flags & (0b1 << 1)), bool(flags & (0b1 << 0)), software_error, boot_count, vbatt, cpu_temp, imu_temp, gyro, mag, - rssi, fei) + accel, rssi, fei) def unpack_system(bytes):