|
14 | 14 |
|
15 | 15 |
|
16 | 16 | LOG = logging.getLogger(__name__) |
17 | | -# An example: [1623057074211]$GPVTG,,T,,M,0.078,N,0.144,K,D*28[1623057075215] |
18 | 17 | NMEA_LINE_REGEX = re.compile( |
19 | 18 | rb""" |
20 | 19 | ^\s* |
@@ -83,8 +82,12 @@ def extract_camera_model(fp: T.BinaryIO) -> str: |
83 | 82 |
|
84 | 83 |
|
85 | 84 | 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 | + """ |
88 | 91 | cprt_bytes = cprt_bytes.strip().strip(b"\x00") |
89 | 92 |
|
90 | 93 | try: |
@@ -112,12 +115,22 @@ def _extract_camera_model_from_cprt(cprt_bytes: bytes) -> str: |
112 | 115 |
|
113 | 116 |
|
114 | 117 | 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 | + """ |
115 | 126 | for line_bytes in gps_data.splitlines(): |
116 | 127 | match = NMEA_LINE_REGEX.match(line_bytes) |
117 | 128 | if match is None: |
118 | 129 | continue |
119 | 130 | 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 | + ): |
121 | 134 | try: |
122 | 135 | nmea_line = nmea_line_bytes.decode("utf8") |
123 | 136 | except UnicodeDecodeError: |
|
0 commit comments