frame

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2023 License: MIT Imports: 9 Imported by: 7

Documentation

Overview

Package frame contains frame definitions and a frame parser.

Index

Constants

View Source
const (
	// V2MagicByte is the magic byte of a V2 frame.
	V2MagicByte = 0xFD

	// V2FlagSigned is the flag of a V2 frame that indicates that the frame is signed.
	V2FlagSigned = 0x01
)
View Source
const (
	// V1MagicByte is the magic byte of a V1 frame.
	V1MagicByte = 0xFE
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Frame

type Frame interface {
	// returns the system id of the author of the frame.
	GetSystemID() byte

	// returns the component id of the author of the frame.
	GetComponentID() byte

	// returns the message wrapped in the frame.
	GetMessage() message.Message

	// returns the checksum of the frame.
	GetChecksum() uint16

	// generates the checksum of the frame.
	GenerateChecksum(byte) uint16
	// contains filtered or unexported methods
}

Frame is the interface implemented by frames of every supported version.

type ReadError

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

ReadError is the error returned in case of non-fatal parsing errors.

func (*ReadError) Error

func (e *ReadError) Error() string

type ReadWriter

type ReadWriter struct {
	*Reader
	*Writer
}

ReadWriter is a Frame Reader and Writer.

func NewReadWriter

func NewReadWriter(conf ReadWriterConf) (*ReadWriter, error)

NewReadWriter allocates a ReadWriter.

type ReadWriterConf

type ReadWriterConf struct {
	// the underlying bytes ReadWriter.
	ReadWriter io.ReadWriter

	// (optional) the dialect which contains the messages that will be read.
	// If not provided, messages are decoded into the MessageRaw struct.
	DialectRW *dialect.ReadWriter

	// (optional) the secret key used to validate incoming frames.
	// Non-signed frames are discarded. This feature requires v2 frames.
	InKey *V2Key

	// Mavlink version used to encode messages.
	OutVersion WriterOutVersion
	// the system id, added to every outgoing frame and used to identify this
	// node in the network.
	OutSystemID byte
	// (optional) the component id, added to every outgoing frame, defaults to 1.
	OutComponentID byte
	// (optional) the value to insert into the signature link id.
	// This feature requires v2 frames.
	OutSignatureLinkID byte
	// (optional) the secret key used to sign outgoing frames.
	// This feature requires v2 frames.
	OutKey *V2Key
}

ReadWriterConf is the configuration of a ReadWriter.

type Reader

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

Reader is a Frame reader.

func NewReader

func NewReader(conf ReaderConf) (*Reader, error)

NewReader allocates a Reader.

func (*Reader) Read

func (r *Reader) Read() (Frame, error)

Read reads a Frame from the reader. It must not be called by multiple routines in parallel.

type ReaderConf

type ReaderConf struct {
	// the underlying bytes reader.
	Reader io.Reader

	// (optional) the dialect which contains the messages that will be read.
	// If not provided, messages are decoded into the MessageRaw struct.
	DialectRW *dialect.ReadWriter

	// (optional) the secret key used to validate incoming frames.
	// Non-signed frames are discarded. This feature requires v2 frames.
	InKey *V2Key
}

ReaderConf is the configuration of a Reader.

type V1Frame

type V1Frame struct {
	SequenceID  byte
	SystemID    byte
	ComponentID byte
	Message     message.Message
	Checksum    uint16
}

V1Frame is a Mavlink V1 frame.

func (V1Frame) GenerateChecksum added in v1.1.0

func (f V1Frame) GenerateChecksum(crcExtra byte) uint16

GenerateChecksum implements Frame.

func (V1Frame) GetChecksum

func (f V1Frame) GetChecksum() uint16

GetChecksum implements Frame.

func (V1Frame) GetComponentID

func (f V1Frame) GetComponentID() byte

GetComponentID implements Frame.

func (V1Frame) GetMessage

func (f V1Frame) GetMessage() message.Message

GetMessage implements Frame.

func (V1Frame) GetSystemID

func (f V1Frame) GetSystemID() byte

GetSystemID implements Frame.

type V2Frame

type V2Frame struct {
	IncompatibilityFlag byte
	CompatibilityFlag   byte
	SequenceID          byte
	SystemID            byte
	ComponentID         byte
	Message             message.Message
	Checksum            uint16
	SignatureLinkID     byte
	SignatureTimestamp  uint64
	Signature           *V2Signature
}

V2Frame is a Mavlink V2 frame.

func (V2Frame) GenerateChecksum added in v1.1.0

func (f V2Frame) GenerateChecksum(crcExtra byte) uint16

GenerateChecksum implements Frame.

func (V2Frame) GenerateSignature added in v1.1.0

func (f V2Frame) GenerateSignature(key *V2Key) *V2Signature

GenerateSignature generates the frame signature.

func (V2Frame) GetChecksum

func (f V2Frame) GetChecksum() uint16

GetChecksum implements Frame.

func (V2Frame) GetComponentID

func (f V2Frame) GetComponentID() byte

GetComponentID implements Frame.

func (V2Frame) GetMessage

func (f V2Frame) GetMessage() message.Message

GetMessage implements Frame.

func (V2Frame) GetSystemID

func (f V2Frame) GetSystemID() byte

GetSystemID implements Frame.

func (V2Frame) IsSigned

func (f V2Frame) IsSigned() bool

IsSigned checks whether the frame contains a signature. It does not validate the signature.

type V2Key

type V2Key [32]byte

V2Key is a key able to sign and validate V2 frames.

func NewV2Key

func NewV2Key(in []byte) *V2Key

NewV2Key allocates a V2Key.

type V2Signature

type V2Signature [6]byte

V2Signature is a V2 frame signature.

type Writer

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

Writer is a Frame writer.

func NewWriter

func NewWriter(conf WriterConf) (*Writer, error)

NewWriter allocates a Writer.

func (*Writer) WriteFrame

func (w *Writer) WriteFrame(fr Frame) error

WriteFrame writes a Frame. It must not be called by multiple routines in parallel. This function is intended only for routing pre-existing frames to other nodes, since all frame fields must be filled manually.

func (*Writer) WriteMessage

func (w *Writer) WriteMessage(m message.Message) error

WriteMessage writes a Message. The Message is wrapped into a Frame whose fields are filled automatically. It must not be called by multiple routines in parallel.

type WriterConf

type WriterConf struct {
	// the underlying bytes writer.
	Writer io.Writer

	// (optional) the dialect which contains the messages that will be written.
	DialectRW *dialect.ReadWriter

	// Mavlink version used to encode messages.
	OutVersion WriterOutVersion
	// the system id, added to every outgoing frame and used to identify this
	// node in the network.
	OutSystemID byte
	// (optional) the component id, added to every outgoing frame, defaults to 1.
	OutComponentID byte
	// (optional) the value to insert into the signature link id.
	// This feature requires v2 frames.
	OutSignatureLinkID byte
	// (optional) the secret key used to sign outgoing frames.
	// This feature requires v2 frames.
	OutKey *V2Key
}

WriterConf is the configuration of a Writer.

type WriterOutVersion

type WriterOutVersion int

WriterOutVersion is a Mavlink version.

const (
	// V1 is Mavlink 1.0
	V1 WriterOutVersion = 1

	// V2 is Mavlink 2.0
	V2 WriterOutVersion = 2
)

func (WriterOutVersion) String

func (v WriterOutVersion) String() string

String implements fmt.Stringer.

Jump to

Keyboard shortcuts

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