Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added better output + agcCnt #6

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
*.pyc
venv
venv3
# test files
test_output.dat
output.dat
*.log
# private config file
config.yml
*.db
.DS_Store
.DS_Store
.vscode
# ignore locale data folder
15 changes: 6 additions & 9 deletions ublox_mon/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(self, device, output_prefix, db_path):

# List of the last GPS fixes
self._gps_fixes = deque([], 5)
self._gps_utc = None
self._gps_utc = deque([], 5)

def rotate_output_file(self):
"""
Expand Down Expand Up @@ -93,7 +93,7 @@ def setup_output_file(self):
if not os.path.exists(self._output):
with open(self._output, 'a') as f:
os.utime(self._output, None)
f.write("#id;utc;jamInd;lat;lon;gps_utc\n")
f.write("#id;utc;jamInd;agcCnt;lat;lon;gps_utc\n")

self._file = open(self._output, 'a+')

Expand Down Expand Up @@ -123,16 +123,16 @@ def write(self, packet):
last_gps_fix = self._gps_fixes[-1]
else:
last_gps_fix = {'lat': -1, 'lon': -1}
packet.update(last_gps_fix)

packet.update(last_gps_fix)
packet["gps_ts"] = packet.get("utc")

jam_ts = models.JamTimeseries(packet.get("timestamp_id"),
packet.get("jamInd"), packet.get("utc"), packet.get("lat"),
packet.get("lon"), packet.get("gps_ts"))
self._session.add(jam_ts)

fmt = "{timestamp_id};{utc};{jamInd};{lat};{lon};{gps_utc}\n"
fmt = "{timestamp_id};{utc};{jamInd};{agcCnt};{lat};{lon};{gps_utc}\n"
self._file.write(fmt.format(**packet))

def close(self):
Expand Down Expand Up @@ -196,7 +196,7 @@ def run(self, notify_callback=None):
hour = msg.fields.get("hour")
minutes = msg.fields.get("min")
seconds = msg.fields.get("sec")
self._gps_utc = datetime.datetime(year, month, day, hour, minutes, seconds)
self._gps_utc.append(datetime.datetime(year, month, day, hour, minutes, seconds))

if msg.msg_type() == (ublox.CLASS_NAV, ublox.MSG_NAV_CLOCK):
# log.debug("MSG-NAV-TIMEUTC: {}".format(msg.fields))
Expand All @@ -207,16 +207,13 @@ def run(self, notify_callback=None):

packet = msg.fields
packet['utc'] = datetime.datetime.now().replace(microsecond=0)
packet['gps_utc'] = self._gps_utc
packet['gps_utc'] = self._gps_utc[-1]
packet['timestamp_id'] = self._next_id
if 'jamInd' not in msg.fields:
packet['jamInd'] = -1
packet['lat'] = 0
packet['lon'] = 0

# TODO: Hent ut 'agcCnt' og logg.
# >> AGC Monitor (counts SIGHI xor SIGLO, range 0 to 8191)

log.debug("{}: {}".format(self._next_id, packet))

# Write data to timeseries output file
Expand Down