瀏覽代碼

Adds logging for modem reconnections.

master
Lukas Prause 3 年之前
父節點
當前提交
69e6284550
共有 1 個檔案被更改,包括 43 行新增4 行删除
  1. +43
    -4
      measurement_main.py

+ 43
- 4
measurement_main.py 查看文件

ser.readline() ser.readline()
try: try:
while ser.is_open: while ser.is_open:
nmea_sentence = ser.readline() #GPRMC
nmea_sentence = ser.readline() # GPRMC
nmea_str = nmea_sentence.decode("utf-8") nmea_str = nmea_sentence.decode("utf-8")
if nmea_str.startswith("$GPRMC"): if nmea_str.startswith("$GPRMC"):
write_to_file(output_file, nmea_str) write_to_file(output_file, nmea_str)
sleep(2) sleep(2)
print_message("done...") print_message("done...")



def ping(self): def ping(self):
c = "ping {} -I {} -i {} -c {}".format( c = "ping {} -I {} -i {} -c {}".format(
self.config["server"], self.config["server"],
print_message("Use ws filter: {}".format(ws_filter)) print_message("Use ws filter: {}".format(ws_filter))
for n in range(1, self.config["number_of_measurements"] + 1): for n in range(1, self.config["number_of_measurements"] + 1):
if not is_modem_connected(): if not is_modem_connected():
background_write_to_file(
filepath="{}{}_reconnect.log".format(
self.config["folder"], self.config["prefix"]
),
content='{}"'.format(datetime.timestamp(datetime.now())),
)
reconnect_modem() reconnect_modem()
print_message( print_message(
"{} of {}".format(n, self.config["number_of_measurements"]) "{} of {}".format(n, self.config["number_of_measurements"])
iperf_return = 0 iperf_return = 0
while not is_measurement_done or iperf_return != 0: while not is_measurement_done or iperf_return != 0:
if iperf_return != 0: if iperf_return != 0:
background_write_to_file(
filepath="{}{}_reconnect.log".format(
self.config["folder"], self.config["prefix"]
),
content='{}"'.format(datetime.timestamp(datetime.now())),
)
reconnect_modem() reconnect_modem()
try: try:
try: try:
iperf_return = subprocess.call(iperf_command, timeout=float(time) + TIMEOUT_OFFSET)
iperf_return = subprocess.call(
iperf_command, timeout=float(time) + TIMEOUT_OFFSET
)
except: except:
print_message("iPerf timed out...") print_message("iPerf timed out...")
background_write_to_file(
filepath="{}{}_reconnect.log".format(
self.config["folder"], self.config["prefix"]
),
content='{}"'.format(datetime.timestamp(datetime.now())),
)
reconnect_modem() reconnect_modem()
except KeyboardInterrupt: except KeyboardInterrupt:
exit() exit()
print_message("tcp probe is now enabled") print_message("tcp probe is now enabled")
for n in range(1, self.config["number_of_measurements"] + 1): for n in range(1, self.config["number_of_measurements"] + 1):
if not is_modem_connected(): if not is_modem_connected():
background_write_to_file(
filepath="{}{}_reconnect.log".format(
self.config["folder"], self.config["prefix"]
),
content='{}"'.format(datetime.timestamp(datetime.now())),
)
reconnect_modem() reconnect_modem()
print_message( print_message(
"{} of {}".format(n, self.config["number_of_measurements"]) "{} of {}".format(n, self.config["number_of_measurements"])
iperf_return = 0 iperf_return = 0
while not is_measurement_done or iperf_return != 0: while not is_measurement_done or iperf_return != 0:
if iperf_return != 0: if iperf_return != 0:
background_write_to_file(
filepath="{}{}_reconnect.log".format(
self.config["folder"], self.config["prefix"]
),
content='{}"'.format(datetime.timestamp(datetime.now())),
)
reconnect_modem() reconnect_modem()
try: try:
try: try:
iperf_return = subprocess.call(iperf_command, timeout=float(time) + TIMEOUT_OFFSET)
iperf_return = subprocess.call(
iperf_command, timeout=float(time) + TIMEOUT_OFFSET
)
except: except:
print_message("iPerf timed out...") print_message("iPerf timed out...")
background_write_to_file(
filepath="{}{}_reconnect.log".format(
self.config["folder"], self.config["prefix"]
),
content='{}"'.format(datetime.timestamp(datetime.now())),
)
reconnect_modem() reconnect_modem()
except KeyboardInterrupt: except KeyboardInterrupt:
exit() exit()

Loading…
取消
儲存