From e2d5bedd5d955b0956f09bc148ca539dde1aaffb Mon Sep 17 00:00:00 2001 From: Jacob Willis Date: Wed, 4 Jan 2023 17:37:26 -0500 Subject: [PATCH 1/4] fix incorrect boot folder name, use mkdirp --- state_machine/applications/flight/Tasks/log.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/state_machine/applications/flight/Tasks/log.py b/state_machine/applications/flight/Tasks/log.py index ef3d1379..dbeded3a 100644 --- a/state_machine/applications/flight/Tasks/log.py +++ b/state_machine/applications/flight/Tasks/log.py @@ -1,6 +1,7 @@ from lib.template_task import Task from pycubed import cubesat import logs +import files import traceback import time @@ -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: @@ -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 From 889b867358c216aba2133715b6518e4896d58288 Mon Sep 17 00:00:00 2001 From: Jacob Willis Date: Wed, 4 Jan 2023 19:49:56 -0500 Subject: [PATCH 2/4] print packet as hex string --- .../pycubedmini/lib/pycubed_rfm9x_fsk.py | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/state_machine/drivers/pycubedmini/lib/pycubed_rfm9x_fsk.py b/state_machine/drivers/pycubedmini/lib/pycubed_rfm9x_fsk.py index 582f58a9..bc1c4b96 100644 --- a/state_machine/drivers/pycubedmini/lib/pycubed_rfm9x_fsk.py +++ b/state_machine/drivers/pycubedmini/lib/pycubed_rfm9x_fsk.py @@ -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 @@ -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) @@ -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 @@ -925,7 +928,7 @@ async def _process_packet(self, with_header=False, with_ack=False, debug=False): # 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 @@ -935,7 +938,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] @@ -944,8 +947,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: @@ -959,8 +963,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 @@ -983,7 +987,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] @@ -1002,3 +1006,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 From 8056850849b863bd533c125e4a80b6864efcca5d Mon Sep 17 00:00:00 2001 From: Jacob Willis Date: Wed, 4 Jan 2023 19:51:29 -0500 Subject: [PATCH 3/4] print hex packet --- state_machine/drivers/pycubedmini/lib/pycubed_rfm9x_fsk.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/state_machine/drivers/pycubedmini/lib/pycubed_rfm9x_fsk.py b/state_machine/drivers/pycubedmini/lib/pycubed_rfm9x_fsk.py index bc1c4b96..6b11e01d 100644 --- a/state_machine/drivers/pycubedmini/lib/pycubed_rfm9x_fsk.py +++ b/state_machine/drivers/pycubedmini/lib/pycubed_rfm9x_fsk.py @@ -924,6 +924,8 @@ 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: From ec5a65a3812a44acf2600878c36cd9427fcbd1e9 Mon Sep 17 00:00:00 2001 From: Jacob Willis Date: Thu, 5 Jan 2023 11:48:15 -0500 Subject: [PATCH 4/4] fewer prints --- state_machine/drivers/pycubedmini/lib/pycubed_rfm9x_fsk.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/state_machine/drivers/pycubedmini/lib/pycubed_rfm9x_fsk.py b/state_machine/drivers/pycubedmini/lib/pycubed_rfm9x_fsk.py index 6b11e01d..f28cbe6f 100644 --- a/state_machine/drivers/pycubedmini/lib/pycubed_rfm9x_fsk.py +++ b/state_machine/drivers/pycubedmini/lib/pycubed_rfm9x_fsk.py @@ -924,13 +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)}") + # 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, \n\tpacket = {tohexstring(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