Compare commits

..

2 commits

Author SHA1 Message Date
1712ebbded Parser fixes, phone
Do not consume possible leading digits of the SERIAL as CHKS.

Parse additional field MESSAGE, for battery status.

Test if PHONE is printable, else print ***.  After restart of the
tracker, it will continue sending data, but with noninitialized PHONE
field.
2023-09-18 22:55:38 +02:00
78709deb87 limit cron gpx to the last 24 hours 2023-09-18 22:55:16 +02:00
3 changed files with 20 additions and 9 deletions

View file

@ -1,16 +1,18 @@
FILES=tk102-1 FILES=tk102-1
TIMELIMIT=
all: $(patsubst %, %.gpx, $(FILES)) all: $(patsubst %, %.gpx, $(FILES))
%.gpx: %.log %.gpx: %.log
./tk102gpx.py $< > $@ ./tk102gpx.py $(TIMELIMIT) $< > $@
nc%: tk102-%.log nc%: tk102-%.log
(while true; do nc -lp 1020$* -w 999; done) | tee -a $< | cat -v (while true; do nc -lp 1020$* -w 999; done) | tee -a $< | cat -v
tail%: tk102-%.log tail%: tk102-%.log
./tk102gpx.py -t1w -CFf $< | tee tk102-$*.txt ./tk102gpx.py $(TIMELIMIT) -CFf $< | tee tk102-$*.txt
%.txt: %.log %.txt: %.log
./tk102gpx.py -CF $< > $@ ./tk102gpx.py -CF $< > $@

View file

@ -1,3 +1,3 @@
#! /bin/bash #! /bin/bash
make -C /home/ncrs1/stephan/tk102gpx tk102-1.gpx tk102-1.png make -C /home/ncrs1/stephan/tk102gpx TIMELIMIT=-t1d tk102-1.gpx tk102-1.png tk102-2.gpx tk102-2.png

View file

@ -57,15 +57,15 @@ for o,v in options:
print(f"--serial={serial}", file=sys.stderr) print(f"--serial={serial}", file=sys.stderr)
tk_re = re.compile(b"".join(( tk_re = re.compile(b"".join((
b"(?P<SERIAL>[0-9]+)?,", b"(?P<SERIAL>23[0-9]+)?,",
b"(?P<PHONE>\+?[0-9]+)?,", b"(?P<PHONE>\+?[^,]+)?,",
b"GPRMC,", b"GPRMC,",
b"(?P<TIME>[0-9]{6}(\.[0-9]+)?)?,", b"(?P<TIME>[0-9]{6}(\.[0-9]+)?)?,",
b"(?P<AV>[AV])?,", b"(?P<AV>[AV])?,",
b"(?P<LAT>[0-9]+\.[0-9]+)?,", b"(?P<LAT>[0-9]+\.[0-9]+)?,",
b"(?P<NS>[NS])?,", b"(?P<NS>[NS]),",
b"(?P<LON>[0-9]+\.[0-9]+)?,", b"(?P<LON>[0-9]+\.[0-9]+)?,",
b"(?P<EW>[EW])?,", b"(?P<EW>[EW]),",
b"(?P<SOG>[0-9]+\.[0-9]+)?,", b"(?P<SOG>[0-9]+\.[0-9]+)?,",
b"(?P<COG>[0-9]+\.[0-9]+)?,", b"(?P<COG>[0-9]+\.[0-9]+)?,",
b"(?P<DATE>[0-9]{6})?,", b"(?P<DATE>[0-9]{6})?,",
@ -73,9 +73,10 @@ tk_re = re.compile(b"".join((
b"(?P<WHAT>[^,]*,)?", b"(?P<WHAT>[^,]*,)?",
b"A\*(?P<GPCKS>[0-9A-F][0-9A-F]),", b"A\*(?P<GPCKS>[0-9A-F][0-9A-F]),",
b"(?P<SIGNAL>[FL])?,", b"(?P<SIGNAL>[FL])?,",
b"(?P<MESSAGE>[^,]+,)?",
b"imei:(?P<IMEI>[0-9]+),", b"imei:(?P<IMEI>[0-9]+),",
b"(?P<LEN>[0-9]{3})", b"(?P<LEN>[0-9]{3})",
b"(?P<BCKS>..)" b"(?P<BCKS>2[^23]|[^2][^2])?"
)), flags=re.DOTALL) )), flags=re.DOTALL)
def gprmc2deg(d,dd): def gprmc2deg(d,dd):
@ -154,6 +155,9 @@ class TKGPX(gpxpy.gpx.GPX):
if verbose>0 and rd["SIGNAL"] != b"F": if verbose>0 and rd["SIGNAL"] != b"F":
print(f"Signal is {repr(rd['SIGNAL'])} at {rd['SERIAL']}", file=sys.stderr) print(f"Signal is {repr(rd['SIGNAL'])} at {rd['SERIAL']}", file=sys.stderr)
if verbose>0 and rd["MESSAGE"]:
print(f"MESAAGE is {repr(rd['MESSAGE'])} at {rd['SERIAL']}", file=sys.stderr)
pd = { pd = {
"latitude": gprmc2deg(rd["LAT"], rd["NS"]), "latitude": gprmc2deg(rd["LAT"], rd["NS"]),
"longitude": gprmc2deg(rd["LON"], rd["EW"]), "longitude": gprmc2deg(rd["LON"], rd["EW"]),
@ -185,12 +189,17 @@ class TKGPX(gpxpy.gpx.GPX):
cd = {} cd = {}
cd.update(strorbytes(rd, 'SIGNAL')) cd.update(strorbytes(rd, 'SIGNAL'))
cd.update(strorbytes(rd, 'SERIAL')) cd.update(strorbytes(rd, 'SERIAL'))
cd.update(strorbytes(rd, 'PHONE')) if rd['PHONE'].isascii():
cd.update(strorbytes(rd, 'PHONE'))
else:
cd['PHONE'] = "*"*14
cd['time'] = pd['time'].isoformat()[:19]+'Z' cd['time'] = pd['time'].isoformat()[:19]+'Z'
cd['lat'] = f"{rd['LAT'][:2].decode()}°{rd['LAT'][2:].decode()}'{rd['NS'].decode()}" cd['lat'] = f"{rd['LAT'][:2].decode()}°{rd['LAT'][2:].decode()}'{rd['NS'].decode()}"
cd['lon'] = f"{rd['LON'][:3].decode()}°{rd['LAT'][3:].decode()}'{rd['EW'].decode()}" cd['lon'] = f"{rd['LON'][:3].decode()}°{rd['LAT'][3:].decode()}'{rd['EW'].decode()}"
cd.update(strorbytes(rd, 'SOG')) cd.update(strorbytes(rd, 'SOG'))
cd.update(strorbytes(rd, 'COG')) cd.update(strorbytes(rd, 'COG'))
if rd['MESSAGE']:
cd.update(strorbytes(rd, 'MESSAGE'))
if fieldnames: if fieldnames:
print(", ".join([f"{k}={cd[k]}" for k in cd])) print(", ".join([f"{k}={cd[k]}" for k in cd]))
else: else: