spartn

package module
v0.0.0-...-e2e51fb Latest Latest
Warning

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

Go to latest
Published: May 2, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

README

SPARTN Format Parsing Library for Go

Format specification: https://www.spartnformat.org/

TODO: Add Message definitions and deserialization methods (currently only frames)

TODO: Find some SPARTN data to test with - I have no idea if the CRC methods are correct

Documentation

Index

Constants

View Source
const (
	FramePreamble uint8 = 0x73
)

Variables

View Source
var (
	FrameHash *crc.Hash = crc.NewHash(&crc.Parameters{
		Width:      8,
		Polynomial: 0x09,
	})
)

Functions

func DeserializeFrameStart

func DeserializeFrameStart(r *bufio.Reader, frame *Frame) (frameHeader []byte, err error)

DeserializeFrameStart discards bytes from Reader only if CRC is valid.

func DeserializeMessageCRC

func DeserializeMessageCRC(t MessageCRCType, r *bufio.Reader) (c uint32, err error)

func DeserializePayloadDescriptionBlock

func DeserializePayloadDescriptionBlock(r *bufio.Reader, frame *Frame) (parsedBytes []byte, err error)

Types

type Frame

type Frame struct {
	Preamble                     uint8          // 8
	MessageType                  uint8          // 7
	PayloadLength                uint16         // 10
	EAF                          bool           // 1
	MessageCRCType               MessageCRCType // 2
	CRC                          uint8          // 4
	MessageSubtype               uint8          // 4
	TimeTagType                  bool           // 1
	TimeTag                      uint32         // TimeTagType ? 16bits : 32bits
	SolutionID                   uint8          // 7
	SolutionProcessorID          uint8          // 4
	EncryptionID                 uint8          // 4
	EncryptionSequenceNumber     uint8          // 6
	AuthenticationIndicator      uint8          // 3
	EmbeddedAuthenticationLength uint8          // 3
	MessagePayload               []byte         // SizeOf MessageLength - padded
	EmbeddedAuthenticationData   []byte         // SizeOf EmbeddedAuthenticationLength
	MessageCRC                   uint32         // 8 - 32
}

Frame is used to encapsulate encoded SPARTN Messages, supplying encryption and authentication information.

func DeserializeFrame

func DeserializeFrame(r *bufio.Reader) (frame Frame, err error)

DeserializeFrame only discards a single byte from the given Reader if no valid preamble is found, or if the Frame CRC is invalid.

Discards bytes from Reader whether or not the MessageCRC is valid.

type MessageCRCType

type MessageCRCType uint8
const (
	// TODD: Consider making these types so we only need one case statement (in Deserialization)
	CRC8CCITT    MessageCRCType = 0
	CRC16CCITT   MessageCRCType = 1
	CRC24Radix64 MessageCRCType = 2
	CRC32CCITT   MessageCRCType = 3
)

func (MessageCRCType) CalculateCRC

func (t MessageCRCType) CalculateCRC(data []byte) (c uint32, err error)

Jump to

Keyboard shortcuts

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