.. |br| raw:: html
.. _ex_gnss: GPS/GNSS ======== Configure, generate, read, poll, send and parse GPS/GNSS messages. Read GNSS1 and GNSS2 messages ----------------------------- This code reads the incoming messages from Gps1 and Gps2. |br| In this example, Gps1 is not sending any information, while Gps2 is sending a binary UBX message. |br| You can find more information about the ``Gps`` class here: :ref:`gps`. |br| >>> import sbc >>> gps1 = sbc.Gps( 1, 115200 ) >>> gps2 = sbc.Gps( 2, 115200 ) >>> print(gps1.read()) None >>> print(gps2.read()) b'\x02\x00\xc4\x00\x00\x00\x91\x00\x00\x00\x89p\x00\x00\x00\x00\x00\x00/\x01\x00\x00ho' Poll UBX-PVT message -------------------- This example requests Gps1 to send one UBX-PVT message. |br| You can find more information about the ``ubx.Parser`` class here: :ref:`ubx`. >>> import sbc >>> import time >>> gps2 = sbc.Gps(2, 115200) >>> ubx_parser = sbc.ubx.Parser() >>> msg = sbc.ubx.request( gps2, ubx_parser, "NavPvt" ) >>> print( msg ) NavPvt {'lat': 416087000, 'vAcc': 486, 'itow': 374515700, 'height': 252417, 'year': 2021, 'sAcc': 90, 'flags': 67, 'headVeh': 0, 'hAcc': 373, 'reserved3': 1044519020, 'reserved2': 0, 'magDec': 0, 'magAcc': 0, 'hour': 8, 'day': 25, 'valid': 55, 'min': 1, 'headingAcc': 13376102, 'name': 'NavPvt', 'tAcc': 21, 'numSV': 29, 'velN': -43, 'flags3': 0, 'hMSL': 202610, 'sec': 37, 'gSpeed': 44, 'month': 3, 'fixType': 3, 'nano': 699554746, 'flags2': 234, 'heading': 13758188, 'velD': 28, 'velE': 11, 'pDop': 109, 'lon': 6117282} Set default configuration ------------------------- This example sends the UBX hexadecimal string to bring the GPS/GNSS receiver to its default configuration. |br| You can *discover* this strings in u-center and practically do anything you can in u-center with the SBC. |br| You can find more information about the ``ubx.Parser`` class here: :ref:`ubx`. >>> import sbc >>> payload = bytes( [ 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x03 ] ) >>> gps1 = sbc.Gps(1, uart_baudrate = 38400) >>> ubx_parser = sbc.ubx.Parser() >>> print(sbc.ubx.config( gps1, ubx_parser, 0x06, 0x09, payload )) True Parse UBX messages ------------------ This example parses a UBX message and prints the parsed message with all its fields. |br| You can find more information about the ``ubx.Parser`` class here: :ref:`ubx`. >>> import sbc >>> ubx_parser = sbc.ubx.Parser(raw_payload=False) >>> ubx_msg = bytes([0xB5, 0x62, 0x01, 0x07, 0x5C, 0x00, 0xB8, 0x39, 0x92, 0x17, 0xE5, 0x07, 0x03, 0x12, 0x0D, 0x32, 0x29, 0x37, 0x19, 0x00, 0x00, 0x00, 0xB9, 0xE9, 0xFC, 0xFF, 0x03, 0x03, 0xEA, 0x19, 0x1E, 0x59, 0x5D, 0x00, 0x46, 0xFB, 0xCC, 0x18, 0x8F, 0xDE, 0x03, 0x00, 0xFF, 0x1B, 0x03, 0x00, 0xD8, 0x05, 0x00, 0x00, 0xD5, 0x06, 0x00, 0x00, 0xEF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA5, 0x00, 0x00, 0x00, 0x80, 0xA8, 0x12, 0x01, 0x5F, 0x00, 0x00, 0x00, 0x6C, 0x18, 0x42, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE2, 0x62]) >>> msg = ubx_parser.parse(ubx_msg) >>> print(msg) [NavPvt {'lat': 416086854, 'vAcc': 1749, 'itow': 395459000, 'height': 253583, 'year': 2021, 'sAcc': 165, 'flags': 3, 'headVeh': 0, 'hAcc': 1496, 'reserved3': 1044519020, 'reserved2': 0, 'magDec': 0, 'magAcc': 0, 'hour': 13, 'day': 18, 'valid': 55, 'min': 50, 'headingAcc': 18000000, 'name': 'NavPvt', 'tAcc': 25, 'numSV': 25, 'velN': -17, 'flags3': 0, 'hMSL': 203775, 'sec': 41, 'gSpeed': 17, 'month': 3, 'fixType': 3, 'nano': -202311, 'flags2': 234, 'heading': 0, 'velD': 7, 'velE': 0, 'pDop': 95, 'lon': 6117662}] Parse NMEA messages ------------------- This example parses a NMEA message and prints the parsed message with all its fields. |br| You can find more information about the ``NMEA_parser`` class here: :ref:`nmea`. >>> import sbc >>> nmea = sbc.NMEA_parser(split_payload = True) >>> buf = b'$GPGGA,172814.0,3723.46587704,N,12202.26957864,W,2,6,1.2,18.893,M,-25.669,M,2.0,0031*4F' >>> buf = buf + 'This is not a NMEA message' >>> buf = buf + b'$GPGST,172814.0,0.006,0.023,0.020,273.6,0.023,0.020,0.031*6A' >>> msg = nmea.parse(buf) >>> print(msg) [['GPGGA', '172814.0', '3723.46587704', 'N', '12202.26957864', 'W', '2', '6', '1.2', '18.893', 'M', '-25.669', 'M', '2.0', '0031'], ['GPGST', '172814.0', '0.006', '0.023', '0.020', '273.6', '0.023', '0.020', '0.031']] Generate NMEA message --------------------- This example builds a NMEA message from a defined payload. |br| You can find more information about the ``NMEA_parser`` class here: :ref:`nmea`. >>> import sbc >>> nmea = sbc.NMEA_parser() >>> nmea.payload = b'GPGGA,172814.0,3723.46587704,N,12202.26957864,W,2,6,1.2,18.893,M,-25.669,M,2.0,0031' >>> nmea.payload_len = len(nmea.payload) >>> print(nmea.chksum_nmea()) b'4F' >>> msg = b'$' + nmea.payload + b'*' + nmea.chksum_nmea() >>> print(msg.decode()) $GPGGA,172814.0,3723.46587704,N,12202.26957864,W,2,6,1.2,18.893,M,-25.669,M,2.0,0031*4F