rtcm

package module
v0.0.0-...-5225a15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const CLight = 299792458.0

CLight is the speed of light in metres per second

View Source
const CRCLengthBits = crcLengthBytes * 8

CRCLengthBits is the length of the Cyclic Redundancy Check value in bits.

View Source
const HeaderLengthBits = headerLengthBytes * 8

HeaderLengthBits is the length of the RTCM header in bits.

View Source
const P2_10 = P2_6 / 16.0

P2_10 is 2^-10.

View Source
const P2_11 = P2_6 / 32.0

P2_11 is 2^-11.

View Source
const P2_29 = 1.862645149230957e-09

P2_29 is 2^-29.

View Source
const P2_31 = 4.656612873077393e-10

P2_31 is 2^-31.

View Source
const P2_33 = P2_31 / 4.0

P2_33 is 2^-33.

View Source
const P2_34 = P2_31 / 8.0

P2_34 is 2^-34.

View Source
const P2_5 = 0.03125

P2_5 is 2^-5.

View Source
const P2_6 = 0.015625

P2_6 is 2^-6.

View Source
const P2_7 = P2_6 / 2.0

P2_7 is 2^-7.

View Source
const P2_8 = P2_6 / 4.0

P2_8 is 2^-8.

View Source
const P2_9 = P2_6 / 8.0

P2_9 is 2^-9.

View Source
const StartOfMessageFrame = 0xd3

StartOfMessageFrame is the value of the byte that starts an RTCM3 message frame.

Variables

This section is empty.

Functions

func CheckCRC

func CheckCRC(frame []byte) bool

CheckCRC checks the CRC of a message frame.

func DisplayMSM7SatelliteCells

func DisplayMSM7SatelliteCells(satellites []MSM7SatelliteCell) string

DisplayMSM7SatelliteCells returns a text version of a slice of MSM7 satellite data

func DisplayMSM7SignalCells

func DisplayMSM7SignalCells(message *MSM7Message) string

DisplayMSM7SignalCells returns a text version of the MSM7 signal data from an MSM7Message.

func GetSatellites

func GetSatellites(message []byte, pos uint) []uint

GetSatellites gets the list of satellites from the 64-bit satellite mask as a slice of satellite numbers each >= 1, <= 64. The mask starts at bit pos in the message.

func GetScaled5

func GetScaled5(scaled5 int64) (int, int)

getScaled5 takes a scaled integer a.b where b has 5 decimal places and returns the whole component a and the part component b, both as ints.

func GetSignals

func GetSignals(message []byte, pos uint) []uint

GetSignals gets the list of signals from the 32-bit signal mask as a slice of signal numbers each >= 1, <= 32. The mask starts at bit pos in the message.

func GetStartOfLastSundayUTC

func GetStartOfLastSundayUTC(now time.Time) time.Time

GetStartOfLastSundayUTC gets midnight at the start of the last Sunday (which may be today) in UTC.

func Getbits

func Getbits(buff []byte, pos uint, len uint) int64

Getbits extracts len bits from a slice of bytes, starting at bit position pos, interprets the bits as a twos-complement inte and returns the resulting as a signed int.

This does the same as RTKLIB's getbits() function, but the algorithm is from https://en.wikipedia.org/wiki/Two%27s_complement, which includes this Python code:

def twos_complement(input_value: int, num_bits: int) -> int:

"""Calculates a two's complement integer from the given input value's bits."""
mask = 2 ** (num_bits - 1)
return -(input_value & mask) + (input_value & ~mask)

The two's complement version of a positive number is, of course, the number. So if the sign bit is not set, we just return that, otherwise we do the same calculation as the Python code.

func Getbitu

func Getbitu(buff []byte, pos uint, len uint) uint64

Getbitu extracts len bits from a slice of bytes, starting at bit position pos and returns them as a uint.

This is RTKLIB's getbitu, translated from C to Go.

extern unsigned int getbitu(const unsigned char *buff, int pos, int len)

{
    unsigned int bits=0;
    int i;
    for (i=pos;i<pos+len;i++) bits=(bits<<1)+((buff[i/8]>>(7-i%8))&1u);
    return bits;
}

func ParseGlonassEpochTime

func ParseGlonassEpochTime(epochTime uint) (uint, uint)

ParseGlonassEpochTime separates out the two parts of a Glonass epoch time value -3/27 day/milliseconds from start of day.

Types

type MSM7Message

type MSM7Message struct {
	// Header is the MSM Header
	Header *MSMHeader

	// Satellites is a list of the satellites for which signals
	// were observed.
	Satellites []MSM7SatelliteCell

	// Signals is a list of sublists, one sublist per satellite,
	// of signals at different frequencies observed by the base
	// station from the satellites in the Satellite list. If
	// there are, say, eight items in the Satellites list, there
	// will be eight sublists here.  RTCM3 allows for up to 32
	// signals but currently (2021) each satellite only uses two
	// signal channels, so there should be either one or two
	// signals in each sublist.
	Signals [][]MSM7SignalCell
}

MSM7Message is a broken-out version of an MSM7 message.

type MSM7SatelliteCell

type MSM7SatelliteCell struct {
	// SatelliteID is the satellite ID, 1-64.
	SatelliteID uint

	// RangeMillisWhole - uint8 - the number of integer milliseconds
	// in the GNSS Satellite range (ie the transit time of the signals).  0xff
	// indicates an invalid value.  See also the fraction value here and the
	// delta value in the signal cell.
	RangeMillisWhole uint

	// ExtendedInfo - uint4.  Extended Satellite Information.
	ExtendedInfo uint

	// RangeMillisFractional - unit10.  The fractional part of the range
	// in milliseconds.
	RangeMillisFractional uint

	// PhaseRangeRate - int14 - GNSS Satellite phase range rate.  See also
	// the PhaseRangeRateDelta and PhaseRangeRateMS in the signal data.
	PhaseRangeRate int
}

MSM7SatelliteCell holds the MSM7 data for one satellite.

type MSM7SignalCell

type MSM7SignalCell struct {
	// Satellite is the index into the satellite cell list of the satellite
	// that was observed.
	Satellite int

	// SignalID is the ID of the signal that was observed from the satellite.
	// Each signalID has an associated frequency.
	SignalID uint

	// RangeDelta - int20 - to be merged with the range values from the satellite
	// to give RangeMetres. 0x80000 indicates an invalid value.
	RangeDelta int

	// PhaseRangeDelta - int24 - to be merged with the range values and
	// converted to cycles to create PhaseRangeCycles.  0x800000 indicates an
	// invalid value.
	PhaseRangeDelta int

	// LockTimeIndicator - uint10.
	LockTimeIndicator uint

	// HalfCycleAmbiguity flag - 1 bit.
	HalfCycleAmbiguity bool

	// CNR - uint10 - Carrier to Noise Ratio.  0 means invalid value.
	CNR uint

	// PhaseRangeRateDelta - int15 - the offset to the satellite's phase
	// range rate.  This value is in ten thousands of a millisecond.
	PhaseRangeRateDelta int

	// RangeMetres is the range derived from the satellites range values and the
	// signal's range delta, expressed in metres.
	RangeMetres float64

	// PhaseRangeCycles is derived from the satellites range values and the
	// signal's delta value, expressed in cycles.
	PhaseRangeCycles float64

	// PhaseRangeRateMS is derived from the satellite's phase range rate and the
	// signal's delta value and expressed as metres per second.  (This is the
	// speed at which the satellite is approaching the base station, or if
	// negative, the speed that it's moving away from it.)
	PhaseRangeRateMS float64
}

MSM7SignalCell holds the data for one signal from one satellite, plus values gathered from the satellite and signal data and merged together.

type MSMHeader

type MSMHeader struct {

	// MessageType - uint12 - one of 1005, 1077, 1087 etc.
	MessageType uint

	// Constellation - one of "GPS, "BeiDou" etc.
	Constellation string

	// StationID - uint12.
	StationID uint

	// EpochTime - uint30.
	// The structure of the 30 bits varies with the constellation.  For GPS
	// and Galileo it's the number of milliseconds from the start of the
	// current GPS week, which starts at midnight GMT at the start of Sunday
	// (in GPS time, a few leap seconds before UTC).  For Beidou it's
	// similar but with a different number of leap seconds.  For GLONASS the
	// top three bits are the day of the week (0 is Sunday) and the rest are
	// milliseconds from the start of the day in the Moscow time zone.
	//
	EpochTime uint

	// The Epoch time translated to a time in the UTC timezone.
	UTCTime time.Time

	// MultipleMessage - bit(1) - true if more MSMs follow for this station
	// with the same epoch time.
	MultipleMessage bool

	// SequenceNumber - uint3.
	SequenceNumber uint

	// SessionTransmissionTime - uint7.
	SessionTransmissionTime uint

	// ClockSteeringIndicator - uint2.
	ClockSteeringIndicator uint

	// ExternalClockIndicator - uint2.
	ExternalClockIndicator uint

	// GNSSDivergenceFreeSmoothingIndicator - bit(1).
	GNSSDivergenceFreeSmoothingIndicator bool

	// GNSSSmoothingInterval - bit(3).
	GNSSSmoothingInterval uint

	// SatelliteMaskBits is 64 bits, one bit per satellite.  Bit 63
	// is set if signals were observed from satellite 1, bit 62 for
	// satellite 2 and so on.  For example 101000..... means that
	// signals from satellites 1 and 3 were observed.
	SatelliteMaskBits uint64

	// SignalMaskBits is 32 bits, one per signal.  Bit 31 is set if
	// signal 1 was observed from any satellite, bit 30 is set if
	// signal 2 was observed from any satellite, and so on.  For
	// example if signal 1, 3 and 5 were observed from one satellite
	// and signals 1 and 2 from another, then bits 1, 2, 3 and 5
	// will be set in the signal mask.
	SignalMaskBits uint32

	// CellMaskBits is an array of bits nSat X nSig where nSat is the
	// number of observed satellites (the number of bits set in the
	// satellite mask) and nSig is the number of signals types observed
	// across all of the satellites (the number of bits set in the
	// signal mask).  It's guaranteed to be <= 64.
	//
	// For example, if signals 1, 3 and 5 were observed from satellite 1 and
	// signals 1 and 2 were observed from satellite 3, the satellite mask will
	// have bits 63 and 61 set.  The signal mask will have bits 31, 30, 29 and
	// 27 set. The cell mask will be a table 2 X 4 bits long.  In this example,
	// each element indicates whether signals 1, 2, 3 and/or 5 were observed for
	// that satellite so the array would be 1011, 1100.  (In practice all
	// constellations currently (in 2021) use only 2 signals).  Decoding the
	// cell mask requires counting through the bits in the other two masks.
	CellMaskBits uint64

	// Satellites is a slice made from the Satellite Mask bits.  If the satellite
	// mask has bits 63 and 61 set, signals were observed from satellites 1 and 3,
	// the slice will have two elements and will contain {1, 3}.
	Satellites []uint

	// Signals is a slice made from the signal mask.  If signals 1, 2, 3 and 5 were
	// observed from the satellites, the slice will have four elements and will
	// contain {1, 2, 3, 5}
	Signals []uint

	// CellMask is a slice of slices representing the cell mask.  For example, if
	// signals 1,2,3 and 5 were observed from satellites 1 and 3, the CellMask might
	// be arranged like so: {{1,0,1,1}, {1,1,0,0}}, meaning that signals 1, 3 and 5
	// were observed from satellite 1 and signals 1 and 2 were observed from
	// satellite 3.
	CellMask [][]bool

	// NumSignalCells is the total number of signal cells in the message.  Creating
	// this count avoids having to rummage through the masks when you need to know
	// its value.
	NumSignalCells int
}

MSMHeader holds the header for MSM Messages. Message types 1074, 1077, 1084, 1087 etc have an MSM header at the start.

type Message

type Message struct {
	// MessageType is the type of the message (the message number).
	MessageType uint

	// RawData is the message frame in its original binary form
	//including the header and the CRC.
	RawData []byte

	// Readable is a broken out version of the message - if the message type
	// is 1005 it's a Message1005, if it's an MSM7 message, it's an
	// MSM7Message.
	Readable interface{}
}

Message contains an RTCM3 message broken out into readable form.

type Message1005

type Message1005 struct {
	// MessageType - uint12 - always 1005.
	MessageType uint

	// station ID - uint12.
	StationID uint

	// Reserved for ITRF Realisaton Year - uint6.
	ITRFRealisationYear uint

	// GPS bit - bit(1).  True if the device is configured to observe GPS satellites.
	GPS bool

	// Glonass bit - bit(1).  True if the device is configured to observe Glonass satellites.
	Glonass bool

	// Galileo bit - bit(1).  True if the device is configured to observe Galileo satellites.
	Galileo bool

	// Reference-Station Indicator - bit(1)
	ReferenceStation bool

	// Single Receiver Oscillator Indicator - 1 bit
	Oscilator bool

	// Quarter Cycle Indicator - 2 bits
	QuarterCycle uint

	// Reserved - 1 bit.
	ReservedBit bool

	// Antenna Reference Point coordinates in ECEF - int38.
	// Scaled integers in 0.00001 m units (tenth mm).
	AntennaRefX int64
	AntennaRefY int64
	AntennaRefZ int64
}

Message1005 contains a message of type 1005 - antenna position.

type RTCM

type RTCM struct {
	// contains filtered or unexported fields
}

RTCM is the object used to analyse an RTCM3 message.

func New

func New(startTime time.Time) *RTCM

New creates an RTCM object using the given year, month and day to identify which week the times in the messages refer to.

func (*RTCM) Display1005

func (rtcm *RTCM) Display1005(message *Message1005) string

Display1005 returns a text version of a message type 1005

func (*RTCM) DisplayMSM7

func (rtcm *RTCM) DisplayMSM7(message *MSM7Message) string

DisplayMSM7 returns a text version of an MSM7 message.

func (*RTCM) DisplayMSMHeader

func (rtcm *RTCM) DisplayMSMHeader(h *MSMHeader) string

DisplayMSMHeader return a text version of an MSMHeader.

func (*RTCM) DisplayMessage

func (rtcm *RTCM) DisplayMessage(message *Message) string

DisplayMessage takes the given Message object and returns it as a readable string.

func (*RTCM) GetMSM7Message

func (rtcm *RTCM) GetMSM7Message(frame []byte) *MSM7Message

GetMSM7Message extracts the data from an MSM7 messages and presents it as broken out fields.

func (*RTCM) GetMSM7SatelliteCells

func (rtcm *RTCM) GetMSM7SatelliteCells(m []byte, h *MSMHeader, startOfSatelliteData uint) ([]MSM7SatelliteCell, uint)

GetMSM7SatelliteCells extracts the satellite cells from an MSM message. It returns the cells and the number of bits of the message bitstream consumed so far (which is the index of the start of the signal cells).

func (*RTCM) GetMSM7SignalCells

func (rtcm *RTCM) GetMSM7SignalCells(m []byte, h *MSMHeader, satData []MSM7SatelliteCell, startOfSignaldata uint) [][]MSM7SignalCell

GetMSM7SignalCells extracts the signal cells from an MSM message starting at bit (startOfSignaldata). It returns the signal cells as a slice of slices of MSM7SignalCell objects, one outer slice element for each satellite and one inner slice element for each signal from that satellite.

For example, If signal 5 from satellite 1 was observed and signals 5 and 13 from satellite 6 were observed, element 0 of the outer slice will contain a slice with one element (for satellite 1, signal 5) and element 1 will contain a slice with two elements, representing the signals from satellite 6. To make this setup easier to use, each MSM7SignalCell contains a satellite ID and a signal ID along with the data from the cell.

func (*RTCM) GetMSMHeader

func (rtcm *RTCM) GetMSMHeader(m []byte) (header *MSMHeader, startOfSatelliteData uint)

GetMSMHeader extracts the header from an MSM message. It returns the MSMHeader and the bit position of the start of the satellite data (which comes next in the bit stream).

func (*RTCM) GetMessage

func (rtcm *RTCM) GetMessage(data []byte) (*Message, error)

GetMessage extract an RTCM3 message from the given data stream and returns it as a Message. If the data doesn't contain a single valid message, it returns an error.

func (*RTCM) GetMessage1005

func (rtcm *RTCM) GetMessage1005(m []byte) (*Message1005, uint)

GetMessage1005 returns a text version of a message type 1005

func (*RTCM) GetMessageLengthAndType

func (rtcm *RTCM) GetMessageLengthAndType(data []byte) (uint, uint, error)

GetMessageLengthAndType extracts the message length and the message type from an RTCMs message frame or returns an error, implying that this is not the start of a valid message. The data must be at least 5 bytes long.

func (*RTCM) GetMessages

func (rtcm *RTCM) GetMessages(data []byte) []*Message

GetMessages takes the given stream of bytes, exracts all the complete RTCM3 messages and returns it as a slice of Message objects.

func (*RTCM) GetUTCFromBeidouTime

func (rtcm *RTCM) GetUTCFromBeidouTime(epochTime uint) time.Time

GetUTCFromBeidouTime converts a Baidou time to UTC, using the Beidou epoch given by the start time.

func (*RTCM) GetUTCFromGPSTime

func (rtcm *RTCM) GetUTCFromGPSTime(gpsTime uint) time.Time

GetUTCFromGPSTime converts a GPS time to UTC, using the start time to find the correct epoch.

func (*RTCM) GetUTCFromGalileoTime

func (rtcm *RTCM) GetUTCFromGalileoTime(galileoTime uint) time.Time

GetUTCFromGalileoTime converts a Galileo time to UTC, using the same epoch as the start time.

func (*RTCM) GetUTCFromGlonassTime

func (rtcm *RTCM) GetUTCFromGlonassTime(epochTime uint) time.Time

GetUTCFromGlonassTime converts a Glonass epoch time to UTC using the start time to give the correct Glonass epoch.

func (*RTCM) ReadNextMessage

func (rtcm *RTCM) ReadNextMessage(reader io.Reader) (*Message, error)

ReadNextMessage gets the next message frame from a reader, extracts and returns the message. It returns any read error that it encounters, such as EOF.

func (*RTCM) ReadNextMessageFrame

func (rtcm *RTCM) ReadNextMessageFrame(reader io.Reader) ([]byte, error)

ReadNextMessageFrame gets the next message frame from a reader. A message frame is a header, containing the message length, the message and a CRC. It returns any read error that it encounters, such as EOF.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL