From cf949b6ae947e105f606bc439eb95f9ac2bc15e2 Mon Sep 17 00:00:00 2001 From: anime-song <52844453+anime-song@users.noreply.github.com> Date: Sat, 19 Oct 2024 20:20:00 +0900 Subject: [PATCH 1/2] Add GPS9 support --- gopro2gpx/fourCC.py | 22 +++++++++++++++++++++- gopro2gpx/gopro2gpx.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/gopro2gpx/fourCC.py b/gopro2gpx/fourCC.py index a130fb7..c91f821 100644 --- a/gopro2gpx/fourCC.py +++ b/gopro2gpx/fourCC.py @@ -37,6 +37,7 @@ def map_type(type): KARMAUNIT10Data = collections.namedtuple("KARMAUNIT10Data","A Ah J degC V1 V2 V3 V4 s p1") KARMAUNIT15Data = collections.namedtuple("KARMAUNIT15Data","A Ah J degC V1 V2 V3 V4 s p1 e1 e2 e3 e4 p2") GPSData = collections.namedtuple("GPSData","lat lon alt speed speed3d") +GPS9Data = collections.namedtuple("GPS9Data", "lat lon alt speed speed3d days_since_2000 secs_since_midnight dop fix") KARMAGPSData = collections.namedtuple("KARMAGPSData", "tstamp lat lon alt speed speed3d unk1 unk2 unk3 unk4") SYSTData = collections.namedtuple("SYSTData", "seconds miliseconds") @@ -243,6 +244,25 @@ def Build(self, klvdata): data.append(data_item) return(data) +class LabelGPS9(LabelBase): + def __init__(self): + LabelBase.__init__(self) + + def Build(self, klvdata): + if not klvdata.rawdata: + # empty point + data = [ GPS9Data(0,0,0,0,0,0,0,0,0) ] + else: + data = [] + for r in range(klvdata.repeat): + gps9_type = 'lllllllSS' + stype = "".join( [map_type(ord(x)) for x in gps9_type ]) + + s = struct.Struct('>' + stype ) + data_item = GPS9Data._make(s.unpack_from(klvdata.rawdata[r * (4 * 7 + 2 * 2):(r + 1) * (4 * 7 * 2 * 2)])) + data.append(data_item) + return(data) + class LabelGPRI(LabelBase): def __init__(self): LabelBase.__init__(self) @@ -403,7 +423,7 @@ def __init__(self): "DISP": LabelEmpty, # Disparity track (360 modes) # gopro 11 - "GPS9": LabelEmpty + "GPS9": LabelGPS9 } def Manage(klvdata): diff --git a/gopro2gpx/gopro2gpx.py b/gopro2gpx/gopro2gpx.py index 3a7d11c..72f3d3e 100644 --- a/gopro2gpx/gopro2gpx.py +++ b/gopro2gpx/gopro2gpx.py @@ -69,6 +69,7 @@ def BuildGPSPoints(data, skip=False, skipDop=False, dopLimit=2000): GPSFIX = 0 # no lock. TSMP = 0 DVNM = "Unknown" + for d in data: if d.fourCC == 'SCAL': SCAL = d.data @@ -126,6 +127,41 @@ def BuildGPSPoints(data, skip=False, skipDop=False, dopLimit=2000): stats['ok'] += 1 sample_count += 1 + elif d.fourCC == 'GPS9': + for item in d.data: + GPSFIX = item.fix + GPSP = item.dop + + if item.lon == item.lat == item.alt == 0: + print("Warning: Skipping empty point") + stats['empty'] += 1 + continue + + if GPSFIX == 0: + stats['badfix'] += 1 + if skip: + print("Warning: Skipping point due GPSFIX==0") + stats['badfixskip'] += 1 + continue + if GPSP is not None and GPSP > dopLimit: + stats["baddop"] += 1 + if skipDop: + print("Warning: skipping point due to GPSP>limit. GPSP: %s, limit: %s" %(GPSP, dopLimit)) + stats["baddopskip"] += 1 + continue + + retdata = [ float(x) / float(y) for x,y in zip( item._asdict().values() ,list(SCAL) ) ] + + gpsdata = fourCC.GPS9Data._make(retdata) + target_date = datetime.datetime(2000, 1, 1) + datetime.timedelta(days=gpsdata.days_since_2000) + time_of_day = datetime.timedelta(seconds=gpsdata.secs_since_midnight) + gps_time = target_date + time_of_day + if start_time is None: + start_time = gps_time + p = gpshelper.GPSPoint(gpsdata.lat, gpsdata.lon, gpsdata.alt, gps_time, gpsdata.speed) + points.append(p) + stats['ok'] += 1 + elif d.fourCC == 'SYST': data = [ float(x) / float(y) for x,y in zip( d.data._asdict().values() ,list(SCAL) ) ] if data[0] != 0 and data[1] != 0: From e8d498c6d43235f7004302672e1fa580911141dd Mon Sep 17 00:00:00 2001 From: anime-song <52844453+anime-song@users.noreply.github.com> Date: Sun, 20 Oct 2024 17:19:40 +0900 Subject: [PATCH 2/2] Fix incorrect data slice size --- gopro2gpx/fourCC.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gopro2gpx/fourCC.py b/gopro2gpx/fourCC.py index c91f821..131044d 100644 --- a/gopro2gpx/fourCC.py +++ b/gopro2gpx/fourCC.py @@ -259,7 +259,7 @@ def Build(self, klvdata): stype = "".join( [map_type(ord(x)) for x in gps9_type ]) s = struct.Struct('>' + stype ) - data_item = GPS9Data._make(s.unpack_from(klvdata.rawdata[r * (4 * 7 + 2 * 2):(r + 1) * (4 * 7 * 2 * 2)])) + data_item = GPS9Data._make(s.unpack_from(klvdata.rawdata[r * (4 * 7 + 2 * 2):(r + 1) * (4 * 7 + 2 * 2)])) data.append(data_item) return(data)