#!/usr/bin/env python3 # -*- coding: utf-8 -*- # this code indented with actual 0x09 tabs from gps import * import sys, time, datetime, fileinput, os base_dir = "/import/home/ghz" wx_dir = base_dir+'/projects/gps' wxlib_dir = base_dir+'/wxlib' plot_d = wx_dir+'/plots/' dat_fname = 'gps_alt.dat' sys.path.append(wxlib_dir) import wxlib as wx wx.proof_dir(plot_d) gps_inst = gps(mode=WATCH_ENABLE|WATCH_NEWSTYLE) vdop = alt = sat_count = epv = gtime = gmode = avg_alt = avg_evp = 0 alt_lst = [] debug = 1 time0 = time1 = time.time() while True: report = gps_inst.next() if debug: print(report) if (report['class'] == 'SKY'): sat_count = sum(i['used'] for i in report['satellites']) vdop = getattr(report, 'vdop', '0.0') if (report['class'] == 'TPV'): alt = getattr(report, 'alt', '0.0') epv = getattr(report, 'epv', '0.0') gtime = getattr(report, 'time', '0.0') gmode = getattr(report, 'mode', '0.0') if (gmode == 3 and sat_count != 0): if debug: dbg_str0 = "time: %s\talt: %sm\tepv: %sm\tvdop: %s\tsat_count: %s" % (gtime, alt, epv, vdop, sat_count) print(dbg_str0) if isinstance(vdop, float): if (vdop < 2.5 and isinstance(alt, float) and isinstance(epv, float)): # ignore lower quality data, strings alt_lst.append((alt, epv)) time1 = time.time() if ((time1 - time0) > 60 and len(alt_lst) >= 1024): ts = time.strftime("%Y%m%d%H%M%S", time.gmtime(float(time1))) lst_len = len(alt_lst) if (lst_len > 0): avg_alt = sum(a[0] for a in alt_lst) / lst_len avg_evp = sum(a[1] for a in alt_lst) / lst_len dat_string = u"%s\tavg alt: %.1f m\tavg evp: %.1f m\n" % (ts, avg_alt, avg_evp) wx.write_out_dat_stamp(ts, dat_fname, dat_string, wx_dir) time0 = time1 = time.time() if (len(alt_lst) > 1024): alt_lst.remove(alt_lst[0])