binmsg

package module
v0.0.0-...-4815e2d Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2021 License: MIT Imports: 13 Imported by: 2

README

go-rmsggpsbinmsg

Binary encoded message with a timestamp (time, data) and GPS data: Lat., Lon., Alt., FixMode, and a HMAC hashsum

Documentation

Overview

Package binmsg can marshal and unmarshal a binary encoded message with a timestamp (time, data) and GPS data: Lat., Lon., Alt., FixMode, and a HMAC hashsum.

Index

Constants

View Source
const PayloadOctets = messageOctets + shaSize

PayloadOctets is the amount of octets (bytes) the 'data' byte slice returned from (*Payload).MarshalBinary() (data []byte, err error) has.

Variables

View Source
var (

	//ErrHMACOctetsWrongSize is the error for HMACOctet with a wrong size.
	ErrHMACOctetsWrongSize = errors.New(
		"The Payload'sHMACOctets slice does not have a slice of " +
			"sha256.Size224 octets in length.")

	//ErrHMACcheckFailed is the error for failed SECURITY check.
	//The payload does _NOT_ has vaild data.
	ErrHMACcheckFailed = errors.New(
		"SECURITY: HMAC check failed")

	//ErrPayloadSizeTooSmall is the error for a payload byte slice with an
	//incorrect length.
	//(The initBinMsg function creates this error).
	ErrPayloadSizeTooSmall error

	//ErrNilHMACSecretKeySlice is the error for a nil or zero length HMACkey secret.
	ErrNilHMACSecretKeySlice = errors.New(
		"The 'HMACSecretKey' byte slice has not been set " +
			"(It is nil or its length is zero).")

	//ErrNiSaltSlice is the error for a nil or zero length salt secret.
	ErrNiSaltSlice = errors.New(
		"The 'Salt' byte slice has not been set " +
			"(It is nil or its length is zero).")

	//ErrNilMessageOctetsSlice is the error for a message byte slice with a
	//wrong length/size.
	ErrNilMessageOctetsSlice = errors.New(
		"The messageoctets byte slice is nil or has a zero length.")
	ErrNilByteSlice = errors.New(
		"<nil> byte slice")
)

Functions

func IsEqual

func IsEqual(got, want *Message, precision int) (s []string, ok bool)

func IsSameFloat64

func IsSameFloat64(a, b float64, precision int) (aTxt string, bTxt string, ok bool)

Types

type Gps

type Gps struct {
	FixMode   gpsfix.FixMode `json:"fixmode"`
	Latitude  float32        `json:"latitude"`
	Longitude float32        `json:"longitude"`
	Altitude  float32        `json:"altitude"`
}

Gps is type that contain a FixMode and the 32-bit floating point values: Latitude, Longitude, and Altitude.

func (*Gps) Alt

func (g *Gps) Alt() float64

Alt return a float64 representation of the Altitude.

func (*Gps) Lat

func (g *Gps) Lat() float64

Lat return a float64 representation of the Latitude.

func (*Gps) Lon

func (g *Gps) Lon() float64

Lon return a float64 representation of the Longitude.

func (*Gps) SetAlt

func (g *Gps) SetAlt(v float64)

SetAlt sets the 32-bit floating point altitude value via a 64-bit floating point value.

func (*Gps) SetLat

func (g *Gps) SetLat(v float64)

SetLat sets the 32-bit floating point latitude value via a 64-bit floating point value.

func (*Gps) SetLon

func (g *Gps) SetLon(v float64)

SetLon sets the 32-bit floating point longitude value via a 64-bit floating point value.

type Message

type Message struct {
	//TimeStamp octets: timeStampOctets(=8) bytes (type time.Duration is an int64 value)
	TimeStamp TimeStamp `json:"timestamp"`
	//Gps octets: gpsOctet bytes
	Gps Gps `json:"gps"`
}

Message is a type that contains a TimeStamp type (when was this message created?), and a Gps type.

func (*Message) MarshalBinary

func (m *Message) MarshalBinary() ([]byte, error)

MarshalBinary marshals the struct fields from type Message into a binary representation of type Message, which are returned in a byte slice.

func (*Message) Strings

func (m *Message) Strings() (fixmode, alt, lat, lon, timestamp string)

func (*Message) UnmarshalBinary

func (m *Message) UnmarshalBinary(data []byte) error

UnmarshalBinary unmarshals a binary representation of a Payload in a byte slice into the data a Payload type contains.

type Payload

type Payload struct {
	Secrets Secrets `json:"-"`
	Message Message
	// contains filtered or unexported fields
}

Payload is a type which is a representaion of the payload transmitted between RMSG.dk programs.

func New

func New(hmacKey []byte, salt []byte) (*Payload, error)

New creates a new Payload with the given 'hmacKey' and 'salt' byte slices. If ('Payload).Init(hmacKey, salt) returns an error, then a nil Payload and the error are returned.

func (*Payload) Init

func (p *Payload) Init(hmacKey []byte, salt []byte) error

Init initializes a Payload type with the given 'hmacKey' and 'salt' slices. Init does a simple zero length/nil check on both given slices, and one of them has the zero length or is nil, then an error is reutned, if there are no errors, then the nil error is returned.

func (*Payload) MarshalBinary

func (p *Payload) MarshalBinary() (data []byte, err error)

MarshalBinary marshals the data a payload type contains into a binary representation of a Payload, which are stored in a byte slice.

func (*Payload) UnmarshalBinary

func (p *Payload) UnmarshalBinary(data []byte) error

UnmarshalBinary unmarshals a binary representation of a Payload in a byte slice into the data a Payload type contains.

type Secrets

type Secrets struct {
	HMACKey []byte //shared HMAC secret key
	Salt    []byte //crypto.Rand generated garbage - lots of it, shared secret
}

Secrets is a type that contains the shared secrets, while a Payload had been initialized.

type TimeStamp

type TimeStamp struct {
	Time time.Time
}

TimeStamp contains the timestamp, which is used to distinghish between an old message and a new message.

func (*TimeStamp) MarshalJSON

func (t *TimeStamp) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface. The time is a quoted string in RFC 3339 format, with sub-second precision added if present.

func (*TimeStamp) UnmarshalJSON

func (t *TimeStamp) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface. The time is expected to be a quoted string in RFC 3339 format.

Directories

Path Synopsis
cmd
Package cmd is tools for go-rmsggpsbinmsg
Package cmd is tools for go-rmsggpsbinmsg

Jump to

Keyboard shortcuts

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