| return | 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: | class Server: | ||||
| def __init__(self, config): | def __init__(self, config): | ||||
| self.config = config | self.config = config | ||||
| ) | ) | ||||
| ser_thread.start() | 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"]: | if self.config["bandwidth"]: | ||||
| self.bandwidth() | self.bandwidth() | ||||
| elif self.config["drx"]: | elif self.config["drx"]: | ||||
| type=int, | type=int, | ||||
| help="Serial device baudrate", | 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() | args = parser.parse_args() | ||||