Skip to content

Commit 13aecd1

Browse files
authored
fix: blackvue 900x parsing (#756)
1 parent 29acf6c commit 13aecd1

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

mapillary_tools/blackvue_parser.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515

1616
LOG = logging.getLogger(__name__)
17-
# An example: [1623057074211]$GPVTG,,T,,M,0.078,N,0.144,K,D*28[1623057075215]
1817
NMEA_LINE_REGEX = re.compile(
1918
rb"""
2019
^\s*
@@ -83,8 +82,12 @@ def extract_camera_model(fp: T.BinaryIO) -> str:
8382

8483

8584
def _extract_camera_model_from_cprt(cprt_bytes: bytes) -> str:
86-
# examples: b' {"model":"DR900X Plus","ver":0.918,"lang":"English","direct":1,"psn":"","temp":34,"GPS":1}\x00'
87-
# b' Pittasoft Co., Ltd.;DR900S-1CH;1.008;English;1;D90SS1HAE00661;T69;\x00'
85+
"""
86+
>>> _extract_camera_model_from_cprt(b' {"model":"DR900X Plus","ver":0.918,"lang":"English","direct":1,"psn":"","temp":34,"GPS":1}')
87+
'DR900X Plus'
88+
>>> _extract_camera_model_from_cprt(b' Pittasoft Co., Ltd.;DR900S-1CH;1.008;English;1;D90SS1HAE00661;T69;')
89+
'DR900S-1CH'
90+
"""
8891
cprt_bytes = cprt_bytes.strip().strip(b"\x00")
8992

9093
try:
@@ -112,12 +115,22 @@ def _extract_camera_model_from_cprt(cprt_bytes: bytes) -> str:
112115

113116

114117
def _parse_gps_box(gps_data: bytes) -> T.Generator[geo.Point, None, None]:
118+
"""
119+
>>> list(_parse_gps_box(b"[1623057074211]$GPGGA,202530.00,5109.0262,N,11401.8407,W,5,40,0.5,1097.36,M,-17.00,M,18,TSTR*61"))
120+
[Point(time=1623057074211, lat=51.150436666666664, lon=-114.03067833333333, alt=1097.36, angle=None)]
121+
>>> list(_parse_gps_box(b"[1629874404069]$GNGGA,175322.00,3244.53126,N,11710.97811,W,1,12,0.84,17.4,M,-34.0,M,,*45"))
122+
[Point(time=1629874404069, lat=32.742187666666666, lon=-117.1829685, alt=17.4, angle=None)]
123+
>>> list(_parse_gps_box(b"[1623057074211]$GPVTG,,T,,M,0.078,N,0.144,K,D*28[1623057075215]"))
124+
[]
125+
"""
115126
for line_bytes in gps_data.splitlines():
116127
match = NMEA_LINE_REGEX.match(line_bytes)
117128
if match is None:
118129
continue
119130
nmea_line_bytes = match.group(2)
120-
if nmea_line_bytes.startswith(b"$GPGGA"):
131+
if nmea_line_bytes.startswith(b"$GPGGA") or nmea_line_bytes.startswith(
132+
b"$GNGGA"
133+
):
121134
try:
122135
nmea_line = nmea_line_bytes.decode("utf8")
123136
except UnicodeDecodeError:

0 commit comments

Comments
 (0)