Try common GPS baud rates and look for NMEA sentences. Many modules ship at 9600 but Garmin and some older receivers default to 4800; u-blox configured for higher data rates can be at 38400 or 115200. We try each in order until we see a recognizable NMEA prefix or run out of options
(dev, timeout_per_baud=1.5)
| 81 | # portID 3 = USB; mode/baud are ignored there but must be present. |
| 82 | # outProtoMask bit0=UBX bit1=NMEA -> 0x0003. |
| 83 | _ubx_frame(0x06, 0x00, struct.pack('<BBHIIHHHH', |
| 84 | 3, 0, 0, 0, 0, 0x0007, 0x0003, 0, 0)), |
| 85 | ] |
| 86 | for msg_id in (0x00, 0x02, 0x03, 0x04): # GGA, GSA, GSV, RMC |
| 87 | frames.append(_ubx_frame(0x06, 0x01, bytes((0xF0, msg_id, 1)))) |
| 88 | if save: |
| 89 | frames.append(_ubx_frame(0x06, 0x09, |
| 90 | struct.pack('<IIIB', 0, 0x0000FFFF, 0, 0x17))) |
| 91 | return frames |
| 92 | |
| 93 | |
| 94 | def ubx_enable_nmea_sequence(save=True): |
| 95 | """The same frames as one byte string (drift check against the script).""" |
| 96 | return b''.join(ubx_enable_nmea_frames(save)) |
| 97 | |
| 98 | |
| 99 | def _nmea_to_decimal(raw, direction): |
| 100 | """Convert NMEA lat/lon (ddmm.mmmm) to decimal degrees.""" |
| 101 | if not raw or not direction: |
| 102 | return None |
| 103 | try: |
| 104 | if direction in ('N', 'S'): |
| 105 | degrees = int(raw[:2]) |
| 106 | minutes = float(raw[2:]) |
| 107 | else: |
| 108 | degrees = int(raw[:3]) |
no test coverage detected