Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions applications/flight/Tasks/radio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
16 changes: 13 additions & 3 deletions applications/flight/Tasks/telemetry.py
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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_beacon(self, packet):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function should be changed to downlink_telemetry

tq.push(Message(10, packet, header=headers.BEACON, with_ack=False))
self.debug("beacon added to transmission queue")
10 changes: 7 additions & 3 deletions applications/flight/lib/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -55,13 +55,15 @@ 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,
state_byte, flags, software_error, boot_count,
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():
Expand Down Expand Up @@ -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):
Expand Down