Adds GPS serial interface support.
This commit is contained in:
@@ -237,6 +237,26 @@ def monitor_serial(ser, output_file):
|
||||
return
|
||||
|
||||
|
||||
def monitor_gps(ser, output_file):
|
||||
ser.flushInput()
|
||||
ser.flushOutput()
|
||||
# skip first maybe uncompleted line
|
||||
ser.readline()
|
||||
try:
|
||||
while ser.is_open:
|
||||
nmea_sentence = ser.readline()
|
||||
write_to_file(output_file, nmea_sentence + "\n")
|
||||
sleep(1)
|
||||
except:
|
||||
if not ser.is_open:
|
||||
print_message("GPS serial port is closed. Exit monitoring thread.")
|
||||
else:
|
||||
print_message(
|
||||
"Something went wrong while monitoring GPS serial interface. Exit monitoring thread."
|
||||
)
|
||||
return
|
||||
|
||||
|
||||
class Server:
|
||||
def __init__(self, config):
|
||||
self.config = config
|
||||
@@ -503,6 +523,24 @@ class Client:
|
||||
)
|
||||
ser_thread.start()
|
||||
|
||||
if self.config["gps"] is not None:
|
||||
gps_ser = serial.Serial(
|
||||
port=self.config["gps"],
|
||||
baudrate=self.config["gps_baudrate"],
|
||||
)
|
||||
gps_ser.isOpen()
|
||||
gps_ser_filepath = "{}{}_gps_serial_monitor_output.txt".format(
|
||||
self.config["folder"], self.config["prefix"]
|
||||
)
|
||||
gps_ser_thread = Thread(
|
||||
target=monitor_gps,
|
||||
args=(
|
||||
gps_ser,
|
||||
gps_ser_filepath,
|
||||
),
|
||||
)
|
||||
gps_ser_thread.start()
|
||||
|
||||
if self.config["bandwidth"]:
|
||||
self.bandwidth()
|
||||
elif self.config["drx"]:
|
||||
@@ -1076,6 +1114,17 @@ if __name__ == "__main__":
|
||||
type=int,
|
||||
help="Serial device baudrate",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--gps",
|
||||
default=None,
|
||||
help="GPS serial device e.g. /dev/serial/by-id/usb-u-blox_AG_-_www.u-blox.com_u-blox_5_-_GPS_Receiver-if00",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--gps_baudrate",
|
||||
default=38400,
|
||||
type=int,
|
||||
help="GPS serial device baudrate",
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user