Added UI.
parent
88318b17a1
commit
a6df76b928
|
@ -10,111 +10,21 @@ import time
|
|||
import math
|
||||
import traceback
|
||||
from importlib import util
|
||||
import queue
|
||||
import serial
|
||||
from LoRaMonUIApp import LoRaMonUIApp
|
||||
from LoRaMonHelperClasses import RNS
|
||||
from LoRaMonHelperClasses import RNSSerial
|
||||
from LoRaMonHelperClasses import KISS
|
||||
from LoRaMonHelperClasses import ROM
|
||||
|
||||
class RNS():
|
||||
log_enabled = True
|
||||
|
||||
@staticmethod
|
||||
def log(msg):
|
||||
if RNS.log_enabled:
|
||||
logtimefmt = "%Y-%m-%d %H:%M:%S"
|
||||
timestamp = time.time()
|
||||
logstring = "["+time.strftime(logtimefmt)+"] "+msg
|
||||
print(logstring)
|
||||
|
||||
@staticmethod
|
||||
def hexrep(data, delimit=True):
|
||||
delimiter = ":"
|
||||
if not delimit:
|
||||
delimiter = ""
|
||||
hexrep = delimiter.join("{:02x}".format(c) for c in data)
|
||||
return hexrep
|
||||
|
||||
@staticmethod
|
||||
def prettyhexrep(data):
|
||||
delimiter = ""
|
||||
hexrep = "<"+delimiter.join("{:02x}".format(c) for c in data)+">"
|
||||
return hexrep
|
||||
|
||||
class KISS():
|
||||
FEND = 0xC0
|
||||
FESC = 0xDB
|
||||
TFEND = 0xDC
|
||||
TFESC = 0xDD
|
||||
|
||||
CMD_UNKNOWN = 0xFE
|
||||
CMD_DATA = 0x00
|
||||
CMD_FREQUENCY = 0x01
|
||||
CMD_BANDWIDTH = 0x02
|
||||
CMD_TXPOWER = 0x03
|
||||
CMD_SF = 0x04
|
||||
CMD_CR = 0x05
|
||||
CMD_RADIO_STATE = 0x06
|
||||
CMD_RADIO_LOCK = 0x07
|
||||
CMD_DETECT = 0x08
|
||||
CMD_IMPLICIT = 0x09
|
||||
CMD_PROMISC = 0x0E
|
||||
CMD_READY = 0x0F
|
||||
CMD_STAT_RX = 0x21
|
||||
CMD_STAT_TX = 0x22
|
||||
CMD_STAT_RSSI = 0x23
|
||||
CMD_STAT_SNR = 0x24
|
||||
CMD_STAT_CHTM = 0x25
|
||||
CMD_STAT_PHYPRM = 0x26
|
||||
CMD_STAT_BAT = 0x27
|
||||
CMD_STAT_CSMA = 0x28
|
||||
CMD_BLINK = 0x30
|
||||
CMD_RANDOM = 0x40
|
||||
CMD_FW_VERSION = 0x50
|
||||
CMD_ROM_READ = 0x51
|
||||
CMD_ROM_WRITE = 0x52
|
||||
CMD_CONF_SAVE = 0x53
|
||||
CMD_CONF_DELETE = 0x54
|
||||
DETECT_REQ = 0x73
|
||||
DETECT_RESP = 0x46
|
||||
RADIO_STATE_OFF = 0x00
|
||||
RADIO_STATE_ON = 0x01
|
||||
RADIO_STATE_ASK = 0xFF
|
||||
|
||||
CMD_ERROR = 0x90
|
||||
ERROR_INITRADIO = 0x01
|
||||
ERROR_TXFAILED = 0x02
|
||||
ERROR_EEPROM_LOCKED = 0x03
|
||||
|
||||
@staticmethod
|
||||
def escape(data):
|
||||
data = data.replace(bytes([0xdb]), bytes([0xdb, 0xdd]))
|
||||
data = data.replace(bytes([0xc0]), bytes([0xdb, 0xdc]))
|
||||
return data
|
||||
|
||||
class ROM():
|
||||
PRODUCT_RNODE = chr(0x03)
|
||||
MODEL_A4 = chr(0xA4)
|
||||
MODEL_A9 = chr(0xA9)
|
||||
|
||||
ADDR_PRODUCT = chr(0x00)
|
||||
ADDR_MODEL = chr(0x01)
|
||||
ADDR_HW_REV = chr(0x02)
|
||||
ADDR_SERIAL = chr(0x03)
|
||||
ADDR_MADE = chr(0x07)
|
||||
ADDR_CHKSUM = chr(0x0B)
|
||||
ADDR_SIGNATURE = chr(0x1B)
|
||||
ADDR_INFO_LOCK = chr(0x9B)
|
||||
ADDR_CONF_SF = chr(0x9C)
|
||||
ADDR_CONF_CR = chr(0x9D)
|
||||
ADDR_CONF_TXP = chr(0x9E)
|
||||
ADDR_CONF_BW = chr(0x9F)
|
||||
ADDR_CONF_FREQ = chr(0xA3)
|
||||
ADDR_CONF_OK = chr(0xA7)
|
||||
|
||||
INFO_LOCK_BYTE = chr(0x73)
|
||||
CONF_OK_BYTE = chr(0x73)
|
||||
|
||||
class RNode():
|
||||
def __init__(self, serial_instance):
|
||||
self.serial = serial_instance
|
||||
self.rns_serial = serial_instance
|
||||
self.timeout = 100
|
||||
|
||||
#These are parameters recevied from the radio
|
||||
self.r_frequency = None
|
||||
self.r_bandwidth = None
|
||||
self.r_txpower = None
|
||||
|
@ -123,16 +33,20 @@ class RNode():
|
|||
self.r_lock = None
|
||||
self.r_stat_rssi = 0
|
||||
self.r_stat_snr = 0
|
||||
self.r_battery = None
|
||||
self.r_cr = None
|
||||
self.r_implicit_length = 0
|
||||
|
||||
self.rssi_offset = 157
|
||||
|
||||
# command line arguments
|
||||
self.sf = None
|
||||
self.cr = None
|
||||
self.txpower = None
|
||||
self.frequency = None
|
||||
self.bandwidth = None
|
||||
self.implicit_length = 0
|
||||
self.promiscuous = False
|
||||
|
||||
self.detected = None
|
||||
|
||||
|
@ -191,12 +105,48 @@ class RNode():
|
|||
#flag for printing raw bytes from RNode
|
||||
self.raw_data_enabled = False
|
||||
|
||||
#flag for stopping the thread
|
||||
self.thread_continue = None
|
||||
|
||||
#link back to the ui app, used for updating
|
||||
self.loramon_ui_app = None
|
||||
|
||||
def setCapturDuration(self, seconds):
|
||||
#set the start time, first
|
||||
self.capture_start_time = time.time()
|
||||
#set seconds after setting the time, to eliminate race issues with the thread
|
||||
self.duration_to_capture_for = seconds
|
||||
|
||||
def device_probe(self):
|
||||
deviced_detected = False
|
||||
iterations_to_wait = 10
|
||||
|
||||
sleep(2.5)
|
||||
self.detectRequest()
|
||||
|
||||
while True:
|
||||
if self.detected == True:
|
||||
RNS.log("RNode connected")
|
||||
RNS.log("Firmware version: " + str(self.version))
|
||||
device_detected = True
|
||||
break
|
||||
else:
|
||||
sleep(0.1)
|
||||
iterations_to_wait -= 1
|
||||
if iterations_to_wait == 0:
|
||||
device_detected = False
|
||||
break
|
||||
return device_detected
|
||||
|
||||
def updateIUApp(self):
|
||||
if (self.loramon_ui_app != None):
|
||||
self.loramon_ui_app.frequency = self.r_frequency
|
||||
self.loramon_ui_app.bandwidth = self.r_bandwidth
|
||||
self.loramon_ui_app.spread_factor = self.r_sf
|
||||
self.loramon_ui_app.coding_rate = self.r_cr
|
||||
self.loramon_ui_app.battery = self.r_battery
|
||||
self.loramon_ui_app.packet_received = self.number_of_packets_received
|
||||
|
||||
def packetReadLoop(self):
|
||||
try:
|
||||
in_frame = False
|
||||
|
@ -205,26 +155,29 @@ class RNode():
|
|||
data_buffer = b""
|
||||
command_buffer = b""
|
||||
last_read_ms = int(time.time()*1000)
|
||||
packet_string = ""
|
||||
|
||||
while self.serial.is_open:
|
||||
while self.rns_serial.IsOpen() and self.thread_continue == True:
|
||||
if (self.duration_to_capture_for > 0): #handle case where a capture duration is specified
|
||||
seconds_elapsed = int(time.time() - self.capture_start_time)
|
||||
if(seconds_elapsed > self.duration_to_capture_for):
|
||||
return (self.number_of_packets_received)
|
||||
|
||||
if self.serial.in_waiting:
|
||||
byte = ord(self.serial.read(1))
|
||||
if self.rns_serial.InWaiting():
|
||||
byte = ord(self.rns_serial.Read(1))
|
||||
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 (byte == KISS.FEND):
|
||||
# we have detected end of a frame
|
||||
print(f"{byte:#0{4}x}", end="")
|
||||
print("<--")
|
||||
packet_string += str(f"{byte:#0{4}x}")
|
||||
packet_string += "<--"
|
||||
RNS.log(packet_string)
|
||||
packet_string = ""
|
||||
else:
|
||||
# we are still capturing bytes while a frame was detected
|
||||
print(f"{byte:#0{4}x} ", end="")
|
||||
packet_string += f"{byte:#0{4}x} "
|
||||
|
||||
if (byte == KISS.FEND): #received FEND, which signals end of a frame
|
||||
#first make sure we actually received a command
|
||||
|
@ -247,6 +200,7 @@ class RNode():
|
|||
if (len(data_buffer) == 4):
|
||||
self.r_frequency = data_buffer[0] << 24 | data_buffer[1] << 16 | data_buffer[2] << 8 | data_buffer[3]
|
||||
RNS.log("Radio reporting frequency is "+str(self.r_frequency/1000000.0)+" MHz")
|
||||
self.updateIUApp()
|
||||
self.updateBitrate()
|
||||
else:
|
||||
RNS.log(f"Wrong number of bytes {len(data_buffer)} for frequency")
|
||||
|
@ -254,6 +208,7 @@ class RNode():
|
|||
if (len(data_buffer) == 4):
|
||||
self.r_bandwidth = data_buffer[0] << 24 | data_buffer[1] << 16 | data_buffer[2] << 8 | data_buffer[3]
|
||||
RNS.log("Radio reporting bandwidth is "+str(self.r_bandwidth/1000.0)+" KHz")
|
||||
self.updateIUApp()
|
||||
self.updateBitrate()
|
||||
else:
|
||||
RNS.log(f"Wrong number of bytes {len(data_buffer)} for bandwith")
|
||||
|
@ -274,6 +229,7 @@ class RNode():
|
|||
if (len(data_buffer) == 1):
|
||||
self.r_sf = data_buffer[0]
|
||||
RNS.log("Radio reporting spreading factor is "+str(self.r_sf))
|
||||
self.updateIUApp()
|
||||
self.updateBitrate()
|
||||
else:
|
||||
RNS.log(f"Wrong number of bytes {len(data_buffer)} for spreading factor")
|
||||
|
@ -281,6 +237,7 @@ class RNode():
|
|||
if (len(data_buffer) == 1):
|
||||
self.r_cr = data_buffer[0]
|
||||
RNS.log("Radio reporting coding rate is "+str(self.r_cr))
|
||||
self.updateIUApp()
|
||||
self.updateBitrate()
|
||||
else:
|
||||
RNS.log(f"Wrong number of bytes {len(data_buffer)} for coding rate")
|
||||
|
@ -336,6 +293,8 @@ class RNode():
|
|||
case KISS.CMD_STAT_BAT:
|
||||
if (len(data_buffer) == 2):
|
||||
RNS.log(f"Radio reporting battery state is {data_buffer[0]}, % {data_buffer[1]}")
|
||||
self.r_battery = f"S:{data_buffer[0]}, % {data_buffer[1]}"
|
||||
self.updateIUApp()
|
||||
else:
|
||||
RNS.log(f"Wrong number of bytes {len(data_buffer)} for battery")
|
||||
case KISS.CMD_STAT_CHTM:
|
||||
|
@ -450,9 +409,9 @@ class RNode():
|
|||
minstr = "0"+minstr
|
||||
self.version = str(self.major_version)+"."+minstr
|
||||
|
||||
def detect(self):
|
||||
def detectRequest(self):
|
||||
kiss_command = bytes([KISS.FEND, KISS.CMD_DETECT, KISS.DETECT_REQ, KISS.FEND, KISS.CMD_FW_VERSION, 0x00, KISS.FEND])
|
||||
written = self.serial.write(kiss_command)
|
||||
written = self.rns_serial.Write(kiss_command)
|
||||
if written != len(kiss_command):
|
||||
raise IOError("An IO error occurred while configuring spreading factor for "+self(str))
|
||||
|
||||
|
@ -464,6 +423,8 @@ class RNode():
|
|||
self.setCodingRate()
|
||||
self.setImplicitLength()
|
||||
self.setRadioState(KISS.RADIO_STATE_ON)
|
||||
self.setPromiscuousMode()
|
||||
sleep(0.5)
|
||||
|
||||
def setFrequency(self):
|
||||
c1 = self.frequency >> 24
|
||||
|
@ -473,7 +434,7 @@ class RNode():
|
|||
data = KISS.escape(bytes([c1])+bytes([c2])+bytes([c3])+bytes([c4]))
|
||||
|
||||
kiss_command = bytes([KISS.FEND])+bytes([KISS.CMD_FREQUENCY])+data+bytes([KISS.FEND])
|
||||
written = self.serial.write(kiss_command)
|
||||
written = self.rns_serial.Write(kiss_command)
|
||||
if written != len(kiss_command):
|
||||
raise IOError("An IO error occurred while configuring frequency for "+self(str))
|
||||
|
||||
|
@ -485,7 +446,7 @@ class RNode():
|
|||
data = KISS.escape(bytes([c1])+bytes([c2])+bytes([c3])+bytes([c4]))
|
||||
|
||||
kiss_command = bytes([KISS.FEND])+bytes([KISS.CMD_BANDWIDTH])+data+bytes([KISS.FEND])
|
||||
written = self.serial.write(kiss_command)
|
||||
written = self.rns_serial.Write(kiss_command)
|
||||
if written != len(kiss_command):
|
||||
raise IOError("An IO error occurred while configuring bandwidth for "+self(str))
|
||||
|
||||
|
@ -493,7 +454,7 @@ class RNode():
|
|||
txp = bytes([self.txpower])
|
||||
|
||||
kiss_command = bytes([KISS.FEND])+bytes([KISS.CMD_TXPOWER])+txp+bytes([KISS.FEND])
|
||||
written = self.serial.write(kiss_command)
|
||||
written = self.rns_serial.Write(kiss_command)
|
||||
if written != len(kiss_command):
|
||||
raise IOError("An IO error occurred while configuring TX power for "+self(str))
|
||||
|
||||
|
@ -501,7 +462,7 @@ class RNode():
|
|||
sf = bytes([self.sf])
|
||||
|
||||
kiss_command = bytes([KISS.FEND])+bytes([KISS.CMD_SF])+sf+bytes([KISS.FEND])
|
||||
written = self.serial.write(kiss_command)
|
||||
written = self.rns_serial.Write(kiss_command)
|
||||
if written != len(kiss_command):
|
||||
raise IOError("An IO error occurred while configuring spreading factor for "+self(str))
|
||||
|
||||
|
@ -509,7 +470,7 @@ class RNode():
|
|||
cr = bytes([self.cr])
|
||||
|
||||
kiss_command = bytes([KISS.FEND])+bytes([KISS.CMD_CR])+cr+bytes([KISS.FEND])
|
||||
written = self.serial.write(kiss_command)
|
||||
written = self.rns_serial.Write(kiss_command)
|
||||
if written != len(kiss_command):
|
||||
raise IOError("An IO error occurred while configuring coding rate for "+self(str))
|
||||
|
||||
|
@ -518,23 +479,23 @@ class RNode():
|
|||
length = KISS.escape(bytes([self.implicit_length]))
|
||||
|
||||
kiss_command = bytes([KISS.FEND])+bytes([KISS.CMD_IMPLICIT])+length+bytes([KISS.FEND])
|
||||
written = self.serial.write(kiss_command)
|
||||
written = self.rns_serial.Write(kiss_command)
|
||||
if written != len(kiss_command):
|
||||
raise IOError("An IO error occurred while configuring implicit header mode for "+self(str))
|
||||
|
||||
def setRadioState(self, state):
|
||||
kiss_command = bytes([KISS.FEND])+bytes([KISS.CMD_RADIO_STATE])+bytes([state])+bytes([KISS.FEND])
|
||||
written = self.serial.write(kiss_command)
|
||||
written = self.rns_serial.Write(kiss_command)
|
||||
if written != len(kiss_command):
|
||||
raise IOError("An IO error occurred while configuring radio state for "+self(str))
|
||||
|
||||
def setPromiscuousMode(self, state):
|
||||
if state == True:
|
||||
def setPromiscuousMode(self):
|
||||
if self.promiscuous == True:
|
||||
kiss_command = bytes([KISS.FEND, KISS.CMD_PROMISC, 0x01, KISS.FEND])
|
||||
else:
|
||||
kiss_command = bytes([KISS.FEND, KISS.CMD_PROMISC, 0x00, KISS.FEND])
|
||||
|
||||
written = self.serial.write(kiss_command)
|
||||
written = self.rns_serial.Write(kiss_command)
|
||||
if written != len(kiss_command):
|
||||
raise IOError("An IO error occurred while configuring promiscuous mode for "+self(str))
|
||||
|
||||
|
@ -543,17 +504,6 @@ class RNode():
|
|||
#make this a global for use, even if rnode isn't initialized
|
||||
number_of_packets_received_exit_code = 0
|
||||
|
||||
def device_probe(rnode):
|
||||
sleep(2.5)
|
||||
rnode.detect()
|
||||
sleep(0.1)
|
||||
if rnode.detected == True:
|
||||
RNS.log("RNode connected")
|
||||
RNS.log("Firmware version: " + str(rnode.version))
|
||||
return True
|
||||
else:
|
||||
raise IOError("Got invalid response while detecting device")
|
||||
|
||||
def packet_captured(data, rnode_instance):
|
||||
if rnode_instance.console_output:
|
||||
if rnode_instance.print_hex:
|
||||
|
@ -586,8 +536,6 @@ def main():
|
|||
print("")
|
||||
exit(number_of_packets_received_exit_code)
|
||||
|
||||
import serial
|
||||
|
||||
try:
|
||||
parser = argparse.ArgumentParser(description="LoRa packet sniffer for RNode hardware.")
|
||||
parser.add_argument("-C", "--console", action="store_true", help="Print captured packets to the console")
|
||||
|
@ -603,6 +551,7 @@ def main():
|
|||
parser.add_argument("-Q", action="store_true", help="Quite mode, no logging")
|
||||
parser.add_argument("-R", action="store_true", help="Raw frame mode")
|
||||
parser.add_argument("-P", action="store_true", help="Set promiscuous mode")
|
||||
parser.add_argument("-U", action="store_true", help="Use a URWID based UI")
|
||||
|
||||
parser.add_argument("port", nargs="?", default=None, help="Serial port where RNode is attached", type=str)
|
||||
args = parser.parse_args()
|
||||
|
@ -611,6 +560,47 @@ def main():
|
|||
write_to_disk = False
|
||||
write_dir = None
|
||||
|
||||
if args.duration and args.U:
|
||||
print("UI mode and timed capture are not compatible")
|
||||
exit(number_of_packets_received_exit_code)
|
||||
|
||||
|
||||
if args.port:
|
||||
RNS.log("Opening serial port "+args.port+"...")
|
||||
rnode = None
|
||||
serial_device = None
|
||||
rnode_baudrate = 115200
|
||||
|
||||
try:
|
||||
serial_device = serial.Serial(
|
||||
port = args.port,
|
||||
baudrate = rnode_baudrate,
|
||||
bytesize = 8,
|
||||
parity = serial.PARITY_NONE,
|
||||
stopbits = 1,
|
||||
xonxoff = False,
|
||||
rtscts = False,
|
||||
timeout = 0,
|
||||
inter_byte_timeout = None,
|
||||
write_timeout = None,
|
||||
dsrdtr = False
|
||||
)
|
||||
except Exception as e:
|
||||
RNS.log("Could not open the specified serial port. The contained exception was:")
|
||||
RNS.log(str(e))
|
||||
exit(number_of_packets_received_exit_code)
|
||||
else:
|
||||
print("")
|
||||
parser.print_help()
|
||||
print("")
|
||||
exit(number_of_packets_received_exit_code)
|
||||
|
||||
# create an RNS Serial device that uses locking for read / write
|
||||
rns_serial = RNSSerial(serial_device)
|
||||
|
||||
# create the RNode object and give it the lockable serial device
|
||||
rnode = RNode(rns_serial)
|
||||
|
||||
if args.Q:
|
||||
RNS.log_enabled = False
|
||||
|
||||
|
@ -629,68 +619,17 @@ def main():
|
|||
write_to_disk = True
|
||||
write_dir = args.W
|
||||
|
||||
if args.port:
|
||||
RNS.log("Opening serial port "+args.port+"...")
|
||||
rnode = None
|
||||
rnode_serial = None
|
||||
rnode_baudrate = 115200
|
||||
|
||||
try:
|
||||
rnode_serial = serial.Serial(
|
||||
port = args.port,
|
||||
baudrate = rnode_baudrate,
|
||||
bytesize = 8,
|
||||
parity = serial.PARITY_NONE,
|
||||
stopbits = 1,
|
||||
xonxoff = False,
|
||||
rtscts = False,
|
||||
timeout = 0,
|
||||
inter_byte_timeout = None,
|
||||
write_timeout = None,
|
||||
dsrdtr = False
|
||||
)
|
||||
except Exception as e:
|
||||
RNS.log("Could not open the specified serial port. The contained exception was:")
|
||||
RNS.log(str(e))
|
||||
exit(number_of_packets_received_exit_code)
|
||||
|
||||
rnode = RNode(rnode_serial)
|
||||
|
||||
if (args.R):
|
||||
rnode.raw_data_enabled = True
|
||||
|
||||
rnode.callback = packet_captured
|
||||
rnode.console_output = console_output
|
||||
rnode.write_to_disk = write_to_disk
|
||||
rnode.write_dir = write_dir
|
||||
|
||||
thread = threading.Thread(target=rnode.packetReadLoop)
|
||||
thread.daemon = True
|
||||
thread.start()
|
||||
|
||||
try:
|
||||
device_probe(rnode)
|
||||
except Exception as e:
|
||||
RNS.log("Serial port opened, but RNode did not respond.")
|
||||
print(e)
|
||||
exit(number_of_packets_received_exit_code)
|
||||
|
||||
if not (args.freq and args.bw and args.sf and args.cr):
|
||||
RNS.log("Please input startup configuration:")
|
||||
print("")
|
||||
|
||||
if args.freq:
|
||||
rnode.frequency = args.freq
|
||||
else:
|
||||
print("Frequency in Hz:\t", end=' ')
|
||||
rnode.frequency = int(input())
|
||||
|
||||
RNS.log("Freq is a required parameter.")
|
||||
exit(number_of_packets_received_exit_code)
|
||||
|
||||
if args.bw:
|
||||
rnode.bandwidth = args.bw
|
||||
else:
|
||||
print("Bandwidth in Hz:\t", end=' ')
|
||||
rnode.bandwidth = int(input())
|
||||
RNS.log("BW is a required parameter.")
|
||||
exit(number_of_packets_received_exit_code)
|
||||
|
||||
if args.txp and (args.txp >= 0 and args.txp <= 17):
|
||||
rnode.txpower = args.txp
|
||||
|
@ -700,14 +639,14 @@ def main():
|
|||
if args.sf:
|
||||
rnode.sf = args.sf
|
||||
else:
|
||||
print("Spreading factor:\t", end=' ')
|
||||
rnode.sf = int(input())
|
||||
RNS.log("SF is a required parameter.")
|
||||
exit(number_of_packets_received_exit_code)
|
||||
|
||||
if args.cr:
|
||||
rnode.cr = args.cr
|
||||
else:
|
||||
print("Coding rate:\t\t", end=' ')
|
||||
rnode.cr = int(input())
|
||||
RNS.log("CR is a required parameter.")
|
||||
exit(number_of_packets_received_exit_code)
|
||||
|
||||
if args.implicit:
|
||||
rnode.implicit_length = args.implicit
|
||||
|
@ -719,29 +658,68 @@ def main():
|
|||
else:
|
||||
rnode.print_hex = False
|
||||
|
||||
rnode.initRadio()
|
||||
|
||||
if args.P:
|
||||
rnode.setPromiscuousMode(True)
|
||||
sleep(0.5)
|
||||
rnode.promiscuous = True
|
||||
else:
|
||||
rnode.promiscuous = False
|
||||
|
||||
# set the duration here, after radio has been initialized
|
||||
rnode.setCapturDuration(args.duration)
|
||||
|
||||
RNS.log(f"Capture Duration {rnode.duration_to_capture_for}")
|
||||
if (args.R):
|
||||
rnode.raw_data_enabled = True
|
||||
|
||||
if not args.W and not args.console:
|
||||
RNS.log("Warning! No output destination specified! You won't see any captured packets.")
|
||||
|
||||
|
||||
#turn off all logging until we probe the RNode device
|
||||
RNS.log_enabled = False
|
||||
|
||||
#Get the background thread going that will read from radio and help detect it
|
||||
rnode.callback = packet_captured
|
||||
rnode.console_output = console_output
|
||||
rnode.write_to_disk = write_to_disk
|
||||
rnode.write_dir = write_dir
|
||||
|
||||
#set the flag that keeps the thread running
|
||||
rnode.thread_continue = True
|
||||
thread = threading.Thread(target=rnode.packetReadLoop)
|
||||
thread.daemon = True
|
||||
thread.start()
|
||||
|
||||
#kick off a probe
|
||||
if rnode.device_probe() == False:
|
||||
print("Serial port opened, but RNode did not respond.")
|
||||
rnode.thread_continue = False
|
||||
else:
|
||||
#enable logging again, now that radio is detected
|
||||
RNS.log_enabled = True
|
||||
|
||||
#decide whether we are running on console, or URWID based UI
|
||||
if (args.U):
|
||||
#UI Mode
|
||||
RNS.ui_msg_queue = queue.Queue()
|
||||
loramon_ui_app = LoRaMonUIApp(RNS.ui_msg_queue)
|
||||
|
||||
rnode.loramon_ui_app = loramon_ui_app
|
||||
|
||||
#initialize the radio
|
||||
rnode.initRadio()
|
||||
|
||||
loramon_ui_app.run()
|
||||
rnode.thread_continue = False
|
||||
None
|
||||
else:
|
||||
#Console mode
|
||||
#initialize the radio
|
||||
rnode.initRadio()
|
||||
|
||||
# set the duration here, after radio has been initialized
|
||||
rnode.setCapturDuration(args.duration)
|
||||
RNS.log(f"Capture Duration {rnode.duration_to_capture_for}")
|
||||
|
||||
#program is ending, by the it gets here
|
||||
#wait for the thread to finish
|
||||
thread.join()
|
||||
exit(number_of_packets_received_exit_code)
|
||||
else:
|
||||
print("")
|
||||
parser.print_help()
|
||||
print("")
|
||||
exit(number_of_packets_received_exit_code)
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print("")
|
||||
exit(number_of_packets_received_exit_code)
|
||||
|
|
Loading…
Reference in New Issue