Skip to content

Commit

Permalink
Merge pull request #48 from anime-song/master
Browse files Browse the repository at this point in the history
Add GPS9 support
  • Loading branch information
juanmcasillas authored Dec 23, 2024
2 parents 960ba4c + e8d498c commit 7aee429
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
22 changes: 21 additions & 1 deletion gopro2gpx/fourCC.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -403,7 +423,7 @@ def __init__(self):
"DISP": LabelEmpty, # Disparity track (360 modes)

# gopro 11
"GPS9": LabelEmpty
"GPS9": LabelGPS9
}

def Manage(klvdata):
Expand Down
36 changes: 36 additions & 0 deletions gopro2gpx/gopro2gpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 7aee429

Please sign in to comment.