DEV Community

Yongchang He
Yongchang He

Posted on

6 2

Parse RTCM 3.x correction data from serial input

This article illustrates how to parse the RTCM 3.x correction data from serial port input of your GPS base station module.

Prerequisites

  • Have RTCM 3.x correction data streamed correctly from some serial port of your GPS module
  • Have python3 and pip3 installed
  • CLI

Getting started

First, you want to know which ports are used by your GPS base module. Run this code (The resource was found here).

Run python3 NAME_OF_CODE_1.py

import sys
import glob
import serial


def serial_ports():
    """ Lists serial port names

        :raises EnvironmentError:
            On unsupported or unknown platforms
        :returns:
            A list of the serial ports available on the system
    """
    if sys.platform.startswith('win'):
        ports = ['COM%s' % (i + 1) for i in range(256)]
    elif sys.platform.startswith('linux') or sys.platform.startswith('cygwin'):
        # this excludes your current terminal "/dev/tty"
        ports = glob.glob('/dev/tty[A-Za-z]*')
    elif sys.platform.startswith('darwin'):
        ports = glob.glob('/dev/tty.*')
    else:
        raise EnvironmentError('Unsupported platform')

    result = []
    for port in ports:
        try:
            s = serial.Serial(port)
            s.close()
            result.append(port)
        except (OSError, serial.SerialException):
            pass
    return result


if __name__ == '__main__':
    print(serial_ports())
Enter fullscreen mode Exit fullscreen mode

Then, time to parse the streaming RTCM correction data:
(resource code from here).

Run python3 NAME_OF_CODE_2.py

Should update the serial port name and the baud rate of your application

from serial import Serial
from pyrtcm import RTCMReader

stream = Serial('/dev/ttyS10', 921600, timeout=3)
rtr = RTCMReader(stream)

for (raw_data, parsed_data) in rtr: print(parsed_data)
Enter fullscreen mode Exit fullscreen mode

part of the results

You can print either raw data or parsed data

Image description

References

https://stackoverflow.com/questions/12090503/listing-available-com-ports-with-python

https://github.com/semuconsulting/pyrtcm

Neon image

Serverless Postgres in 300ms (!)

10 free databases with autoscaling, scale-to-zero, and read replicas. Start building without infrastructure headaches. No credit card needed.

Try for Free →

Top comments (1)

Collapse
 
gangaputrabhshm profile image
Bhishma

Good day. How can one make the "parsed_data" iterable? The idea is to create something like a dataframe from the decoded observations.

Neon image

Set up a Neon project in seconds and connect from a Python application

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Get started →

👋 Kindness is contagious

Dive into this informative piece, backed by our vibrant DEV Community

Whether you’re a novice or a pro, your perspective enriches our collective insight.

A simple “thank you” can lift someone’s spirits—share your gratitude in the comments!

On DEV, the power of shared knowledge paves a smoother path and tightens our community ties. Found value here? A quick thanks to the author makes a big impact.

Okay