in mapillary_tools/geotag/gpmf.py [0:0]
def parse_bin(path: str) -> list:
# f = open(path, "rb")
s: dict = {} # the current Scale data to apply to next requester
output = []
# handlers for various fourCC codes
methods = {
b"GPS5": parse_gps,
b"GPSU": parse_time,
b"GPSF": parse_fix,
b"GPSP": parse_precision,
b"ACCL": parse_accl,
b"GYRO": parse_gyro,
}
d: dict = {"gps": []} # up to date dictionary, iterate and fill then flush
with open(path, "rb") as f:
while True:
label: bytes = f.read(4)
if not label: # eof
break
desc: bytes = f.read(4)
if not desc: # eof
break
# null length
if b"00" == binascii.hexlify(desc[:1]):
continue
val_size: int = struct.unpack(">b", desc[1:2])[0]
num_values: int = struct.unpack(">h", desc[2:4])[0]
length = val_size * num_values
if label == b"DVID":
if len(d["gps"]): # first one is empty
output.append(d)
d = {"gps": []} # reset
for i in range(num_values):
data: bytes = f.read(val_size)
if label in methods:
methods[label](data, d, s)
if label == b"SCAL":
if 2 == val_size:
s[i] = struct.unpack(">h", data)[0]
elif 4 == val_size:
s[i] = struct.unpack(">i", data)[0]
else:
raise Exception("unknown scal size")
# pack
mod = length % 4
if mod != 0:
seek = 4 - mod
f.read(seek) # discarded
return output