Added an option on the UI for turn raw byte print on/off.

The button on the UI sends a message to radio thread for changing the print_raw_data flag.
I could have also done this differently by doing the following:
change the log message type from RNode to UI to differentiate logs from raw data.
do the filtering of whether raw bytes are printed or not on the UI side.
pull/6/head
Alligitor 2025-04-22 16:35:04 +00:00
parent 4fc9fce834
commit 347e062026
3 changed files with 41 additions and 6 deletions

View File

@ -51,7 +51,7 @@ class RNS():
print(logstring)
else:
msg_to_ui = {
"type": "FromRadio",
"type": "LogMessageFromRadio",
"value": logstring
}
RNS.queue_to_ui.put(msg_to_ui)

View File

@ -25,6 +25,9 @@ class LoRaMonUIApp:
#flag that indicates if the output should auto scroll to the bottom
self.auto_scroll_flag = True
#flag that indicates if the output should auto scroll to the bottom
self.print_raw_data_flag = False
# Right pane output list
self.output_lines = []
#scrollable
@ -74,6 +77,11 @@ class LoRaMonUIApp:
urwid.connect_signal(self.auto_scroll_widget, 'click', self.toggleAutoScroll)
menu_widgets.append(self.auto_scroll_widget)
#widget for turn auto scroll on / off
self.print_raw_data_widget = urwid.Button("Print Raw Data: " + str(self.print_raw_data_flag))
urwid.connect_signal(self.print_raw_data_widget, 'click', self.togglePrintRawData)
menu_widgets.append(self.print_raw_data_widget)
# Left-top: Menu
# these are 2 example buttons to put in. i'm using them as a template for other things
# the first item, kicks off a thread to do background activity
@ -188,6 +196,15 @@ class LoRaMonUIApp:
self.auto_scroll_flag = True
self.auto_scroll_widget.set_label("AutoScroll: " + str(self.auto_scroll_flag))
def togglePrintRawData(self, button):
if (self.print_raw_data_flag == True):
self.print_raw_data_flag = False
else:
self.print_raw_data_flag = True
self.print_raw_data_widget.set_label("Print Raw Data: " + str(self.print_raw_data_flag))
#tell the radio the status of the button
self.sendParameterToRadio("print_raw_data", self.print_raw_data_flag)
#this routine is called periodicaly to service incoming events for the UI
#currently, there is a message queue from the radio thread
#that send messages to be shown
@ -201,7 +218,7 @@ class LoRaMonUIApp:
msg = self.queue_from_radio.get()
match msg['type']:
case "FromRadio":
case "LogMessageFromRadio":
self.appendToOutputWidget(msg["value"])
case "r_frequency":
self.caption_text_widgets[0].original_widget.set_text("Radio Freq: " + str(msg["value"]))
@ -215,6 +232,9 @@ class LoRaMonUIApp:
self.battery_text_widget.original_widget.set_text ("Battery: " + str(msg["value"]))
case "r_captured_packets":
self.packets_received_widget.original_widget.set_text("Packets: " + str(msg["value"]))
case "print_raw_data":
self.print_raw_data_flag = msg["value"]
self.print_raw_data_widget.set_label("Print Raw Data: " + str(self.print_raw_data_flag))
case _:
None
#set the alarm again, so it calls the routing again

View File

@ -98,7 +98,7 @@ class RNode():
self.capture_start_time = time.time()
#flag for printing raw bytes from RNode
self.raw_data_enabled = False
self.print_raw_data_enabled = False
#flag for stopping the thread
self.thread_continue = None
@ -165,6 +165,8 @@ class RNode():
#print(f"UI is requesting coding_rate to change to {msg['value']}")
self.cr = msg['value']
self.setCodingRate()
case "print_raw_data":
self.setPrintRawDataBytes(msg['value'])
case _:
None
@ -195,7 +197,7 @@ class RNode():
last_read_ms = int(time.time()*1000)
if (in_frame == True):
if (self.raw_data_enabled == True): #logic to print raw frame data when in frame
if (self.print_raw_data_enabled == True): #logic to print raw frame data when in frame
if (byte == KISS.FEND):
# we have detected end of a frame
packet_string += str(f"{byte:#0{4}x}")
@ -408,7 +410,7 @@ class RNode():
command = KISS.CMD_UNKNOWN
data_buffer = b""
command_buffer = b""
if (self.raw_data_enabled == True):
if (self.print_raw_data_enabled == True):
packet_string += "-->"
packet_string += f"{byte:#0{4}x} "
else:
@ -537,6 +539,16 @@ class RNode():
if written != len(kiss_command):
raise IOError("An IO error occurred while configuring promiscuous mode for "+self(str))
def setPrintRawDataBytes(self, state):
if state == True:
self.print_raw_data_enabled = True
# for debugging
# RNS.log("setPrintRawDataBytes Received True")
else:
self.print_raw_data_enabled = False
# for debugging
# RNS.log("setPrintRawDataBytes Received False")
def packet_captured(data, rnode_instance):
if rnode_instance.console_output:
if rnode_instance.print_hex:
@ -698,7 +710,7 @@ def main():
rnode.promiscuous = False
if (args.R):
rnode.raw_data_enabled = True
rnode.setPrintRawDataBytes(True)
if not args.W and not args.console:
RNS.log("Warning! No output destination specified! You won't see any captured packets.")
@ -741,6 +753,9 @@ def main():
#initialize the radio
rnode.initRadio()
#set the setting for print raw data
rnode.updateIUApp("print_raw_data", args.R)
loramon_ui_app.run()
rnode.thread_continue = False
None