Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
10 changes: 5 additions & 5 deletions state_machine/applications/flight/Tasks/log.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from lib.template_task import Task
from pycubed import cubesat
import logs
import files
import traceback
import time

Expand Down Expand Up @@ -37,9 +38,10 @@ def log(self, msg):
t = cubesat.rtc.datetime
else:
t = time.localtime()
boot = cubesat.c_boot
boot_str = f'{cubesat.c_boot:05}'
hour_stamp = f'{t.tm_year:04}.{t.tm_mon:02}.{t.tm_mday:02}.{t.tm_hour:02}'
new_log_fd_str = f'/sd/logs/debug/{boot:05}/{hour_stamp}.txt'
new_log_fd_path_str = f'/sd/logs/debug/{boot_str}'
new_log_fd_str = f'{new_log_fd_path_str}/{hour_stamp}.txt'
global log_fd
global log_fd_str
if new_log_fd_str != log_fd_str:
Expand All @@ -48,9 +50,7 @@ def log(self, msg):
try:
log_fd = open(new_log_fd_str, 'a')
except Exception:
logs.try_mkdir('/sd/logs/')
logs.try_mkdir('/sd/logs/debug/')
logs.try_mkdir(f'/sd/logs/debug/{boot}/')
files.mkdirp(new_log_fd_path_str)
log_fd = open(new_log_fd_str, 'a')
log_fd_str = new_log_fd_str

Expand Down
31 changes: 22 additions & 9 deletions state_machine/drivers/pycubedmini/lib/pycubed_rfm9x_fsk.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,8 @@ async def send(
destination=None,
node=None,
identifier=None,
flags=None
flags=None,
debug=True
):
"""Send a string of data using the transmitter.
You can only send 57 bytes at a time
Expand Down Expand Up @@ -780,6 +781,8 @@ async def send(
checksum = bsd_checksum(payload)
payload = payload + checksum

if debug:
print(f"RFM9X Sending: {tohexstring(payload)}")
# Write payload.
self._write_from(_RH_RF95_REG_00_FIFO, payload)

Expand Down Expand Up @@ -825,7 +828,7 @@ async def send_with_ack(self, data, debug=False):
self.sequence_number = (self.sequence_number + 1) & 0xFF
while not got_ack and retries_remaining:
self.identifier = self.sequence_number
await self.send(data, keep_listening=True)
await self.send(data, keep_listening=True, debug=debug)
# Don't look for ACK from Broadcast message
if self.destination == _RH_BROADCAST_ADDRESS:
got_ack = True
Expand Down Expand Up @@ -921,11 +924,13 @@ async def _process_packet(self, with_header=False, with_ack=False, debug=False):
packet = bytearray(_MAX_FIFO_LENGTH)
packet_length = self._read_until_flag(_RH_RF95_REG_00_FIFO, packet, self.fifo_empty)

# if debug:
# print(f"RFM9X: Received {tohexstring(packet)}")
# Reject if the received packet is too small to include the 1 byte length, the
# 4 byte RadioHead header and at least one byte of data
if packet_length < 6:
if debug:
print(f"RFM9X: Incomplete message (packet_length = {packet_length} < 6, packet = {str(packet)})")
print(f"RFM9X: Incomplete message (packet_length = {packet_length} < 6") # , \n\tpacket = {tohexstring(packet)})")
return None

# Reject if the length recorded in the packet doesn't match the amount of data we got
Expand All @@ -935,7 +940,7 @@ async def _process_packet(self, with_header=False, with_ack=False, debug=False):
print(
f"RFM9X: Received packet length ({packet_length}) " +
f"does not match transmitted packet length ({internal_packet_length}), " +
f"packet = {str(packet)}")
f"\n\tpacket = {tohexstring(packet)}")
return None

packet = packet[:packet_length]
Expand All @@ -944,8 +949,9 @@ async def _process_packet(self, with_header=False, with_ack=False, debug=False):
if not bsd_checksum(packet[:-2]) == packet[-2:]:
if debug:
print(
f"RFM9X: Checksum failed, packet = {str(packet)}, bsd_checksum(packet[:-2])" +
f" = {bsd_checksum(packet[:-2])}, packet[-2:] = {packet[-2:]}")
f"RFM9X: Checksum failed, bsd_checksum(packet[:-2]) = {tohexstring(bsd_checksum(packet[:-2]))}, " +
f"packet[-2:] = {tohexstring(packet[-2:])}" +
f"\n\tpacket = {tohexstring(packet)}")
self.checksum_error_count += 1
return None
else:
Expand All @@ -959,8 +965,8 @@ async def _process_packet(self, with_header=False, with_ack=False, debug=False):
if debug:
print(
"RFM9X: Incorrect Address " +
f"(packet address = {packet[1]} != my address = {self.node}), " +
f"packet = {str(packet)}")
f"(packet address = {packet[1]:02x} != my address = {self.node:02x}), " +
f"\n\tpacket = {tohexstring(packet)}")
return None

# send ACK unless this was an ACK or a broadcast
Expand All @@ -983,7 +989,7 @@ async def _process_packet(self, with_header=False, with_ack=False, debug=False):
if (self.seen_ids[packet[2]] == packet[3]) and (
packet[4] & _RH_FLAGS_RETRY):
if debug:
print(f"RFM9X: dropping retried packet, packet = {str(packet)}")
print(f"RFM9X: dropping retried packet, \n\tpacket = {tohexstring(packet)}")
return None
else: # save the packet identifier for this source
self.seen_ids[packet[2]] = packet[3]
Expand All @@ -1002,3 +1008,10 @@ def bsd_checksum(bytedata):
checksum += b
checksum &= 0xffff
return bytes([checksum >> 8, checksum & 0xff])


def tohexstring(b):
s = ""
for bi in b:
s += f"{bi:02x} "
return s