common

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package common gives a set of generic structs and functions for geodata manipulations. It is used to process geodata in a universal format, regardless of the source of this data.

Index

Constants

View Source
const (
	Proto      = "proto"
	Odometer   = "odometer"
	Satellites = "sats"
	HDOP       = "hdop"
	VDOP       = "vdop"
	PDOP       = "pdop"
	NavSystem  = "navsys"
	Move       = "move"
	DigInput   = "dinput"
	DigOutput  = "doutput"
	AnInput    = "ainput"
)

Variables

View Source
var (
	// ErrAttributesNoItem is returned when the attribute with given key is not present.
	ErrAttributesNoItem = errors.New("no item with given key")
	// ErrAttributesNotInt64 is returned when the attribute with given key is not of type int64.
	ErrAttributesNotInt64 = errors.New("value is not int64")
	// ErrAttributesNotFloat64 is returned when the attribute with given key is not of type float64.
	ErrAttributesNotFloat64 = errors.New("value is not float64")
	// ErrAttributesNotString is returned when the attribute with given key is not of type string.
	ErrAttributesNotString = errors.New("value is not string")
)
View Source
var (
	// ErrBadData is returned when the data is inconsistent with protocol specification.
	// It signals that communication session can be terminated.
	ErrBadData = errors.New("data is bad to protocol specification")
)

Functions

This section is empty.

Types

type Attributes

type Attributes map[string]interface{}

Attributes is a generic attributes struct. It is used for key-value attributes for common purposes.

func (Attributes) AppendNullFloat

func (a Attributes) AppendNullFloat(name string, f null.Float) Attributes

AppendNullFloat appends a null float to the attribute.

func (Attributes) AppendNullFloatSlice

func (a Attributes) AppendNullFloatSlice(name string, s []null.Float) Attributes

AppendNullFloatSlice appends a null float slice to the attribute.

func (Attributes) AppendNullInt

func (a Attributes) AppendNullInt(name string, i null.Int) Attributes

AppendNullInt appends a null int to the attribute.

func (Attributes) AppendNullString

func (a Attributes) AppendNullString(name string, s null.String) Attributes

AppendNullString appends a null string to the attribute.

func (Attributes) GetFloat64

func (a Attributes) GetFloat64(key string) (f float64, err error)

GetFloat64 returns the float64 value of the attribute.

func (Attributes) GetInt64

func (a Attributes) GetInt64(key string) (i int64, err error)

GetInt64 returns the int64 value of the attribute.

func (Attributes) GetString

func (a Attributes) GetString(key string) (f string, err error)

GetString returns the string value of the attribute.

func (Attributes) GetType

func (a Attributes) GetType(key string) (string, error)

GetType returns the type of the attribute.

type AxisWGS84

type AxisWGS84 struct {
	Coordinate float64
	Cardinal   CardinalAxis
}

AxisWGS84 is the WGS84 axis of a coordinate system.

func ParseAxisWGS84

func ParseAxisWGS84(coord string, c CardinalAxis) (AxisWGS84, error)

ParseAxisWGS84 parses a string into a AxisWGS84.

func (AxisWGS84) Float64

func (a AxisWGS84) Float64() float64

Float64 returns the floating point value of the coordinate. Example: 5544.6025;N 55 is a degree value. 44.6025 / 60 = 0,743375 is a minute value. N is north latitude (positive sign). 55 + 0,743375 = +55,743375 .

type CardinalAxis

type CardinalAxis string

CardinalAxis is the cardinal axis of a coordinate system.

const (
	North CardinalAxis = "N"
	South CardinalAxis = "S"
	East  CardinalAxis = "E"
	West  CardinalAxis = "W"
)

func ParseCardinalAxis

func ParseCardinalAxis(raw string) (cp CardinalAxis, err error)

ParseCardinalAxis parses a string into a CardinalAxis.

func (CardinalAxis) Sign

func (c CardinalAxis) Sign() float64

Sign returns the floating point sign of the coordinate.

type Cellular

type Cellular struct {
	// CellID - CID, CI - A GSM Cell ID
	CellID int64
	// LAC - Location Area Code
	LAC int64
	// MCC - Mobile Country Code
	MCC int64
	// MNC - Mobile Network Code
	MNC int64
}

Cellular is a generic cellular struct.

type FrameSplitter

type FrameSplitter interface {
	// Splitter returns bufio.SplitFunc to split incoming bytes stream into byte data frames that can be decoded later.
	Splitter() bufio.SplitFunc
	// Error returns error if any registered.
	// Use it to signal that communication session can be terminated.
	Error() error
	// BadData returns bad data if any registered.
	// Use it to log which bytes couldn't be parsed.
	BadData() []byte
}

FrameSplitter is a contract to split incoming bytes stream into byte data frames that can be decoded later.

type Location

type Location struct {
	geom.Coordinates
	Valid bool
}

Location is a generic location struct.

type PointWGS84

type PointWGS84 struct {
	Lon, Lat AxisWGS84
	Valid    bool
}

PointWGS84 is the WGS84 point of a coordinate system.

func ParsePointWGS84

func ParsePointWGS84(lon string, cardLon CardinalAxis, lat string, cardLat CardinalAxis) (PointWGS84, error)

ParsePointWGS84 parses a pair string lon/lat into a PointWGS84.

func (PointWGS84) LocationXY

func (w PointWGS84) LocationXY() Location

LocationXY is the XY location of a coordinate system.

func (PointWGS84) LocationXYZ

func (w PointWGS84) LocationXYZ(z float64) Location

LocationXYZ is the XYZ location of a coordinate system.

type Position

type Position struct {
	Location
	Cellular   *Cellular
	Protocol   string
	DeviceID   string
	Attributes Attributes
	DeviceTime time.Time
	Speed      null.Float
	Course     null.Float
}

Position is a generic position struct.

func (Position) MarshalZerologObject

func (p Position) MarshalZerologObject(e *zerolog.Event)

MarshalZerologObject implements zerolog.LogObjectMarshaler.

Jump to

Keyboard shortcuts

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