wialonips

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: 12 Imported by: 0

README

= Wialon IPS

The Wialon IPS (v. 2.0) communication protocol was developed by
Gurtam for use in personal and automotive GPS and GLONASS trackers which
transfer data to a satellite monitoring server using the TCP or the UDP protocol.

== TCP Data Transfer
The TCP connection must be maintained throughout the entire data transfer process.
If the device disconnects immediately after sending the message,
the server does not have time to send a response to the device, and traffic consumption increases.
While using one TCP connection, you should transfer data from one device.
Otherwise, the system registers only the data of the device whose ID is the first in the incoming data list.
To save traffic, you can use the UDP protocol. However, it does not guarantee that the messages will be delivered.

.Packet Types
[%autowidth]
|===
| Type | Description | Sender | Decoder | Encoder
| L | Login packet | Device | Y | N
| AL | Answer to the login packet | Server | N | N
| SD | Short data packet | Device | Y | N
| ASD | Answer to the short data packet | Server | N | N
| D | Extended data packet | Device | Y | N
| AD | Answer to the extended data packet | Server | N | N
| B | Black box packet | Device | Y | N
| AB | Answer to the black box packet | Server | N | N
| P | Ping packet | Device | N | N
| AP | Answer to the ping packet | Server | N | N
| US | Firmware packet | Server | N | N
| UC | Configuration packet | Server | N | N
| M | Message to/from the driver | Server/Device | N | N
| AM | Answer to the message from the driver | Server | N | N
| QI | Query snapshot command | Server | N | N
| I | Snapshot packet | Device | N | N
| AI | Answer to the snapshot packet | Server | N | N
| QT | Query DDD file command | Server | N | N
| IT | DDD file information packet | Device | N | N
| AIT | Answer to the DDD file information packet | Server | N | N
| T | DDD file block packet | Device | N | N
| AT | Answer to the DDD file block packet | Server | N | N
|===

== UDP Data Transfer (not implemented yet)
The UDP protocol is used only to transfer data from the controller to the
server. It is not possible to send commands from the server to the device using
this protocol.

== Data Compression (not implemented yet)
To save traffic, it is appropriate to use data compression while
transferring packets which contain a large amount of data. The DEFLATE
algorithm of the cross-platform «z lib» library is used for compression. Both TCP
and UDP transport protocols are supported. The container should consist of
only one packet in text format.

Documentation

Overview

Packet wialonips implements the Wialon IPS communication protocol that was developed by Gurtam for use in personal and automotive GPS and GLONASS trackers which transfer data to a satellite monitoring server using the TCP or the UDP protocol.

The TCP connection must be maintained throughout the entire data transfer process. If the device disconnects immediately after sending the message, the server does not have time to send a response to the device, and traffic consumption increases. While using one TCP connection, you should transfer data from one device. Otherwise, the system registers only the data of the device whose ID is the first in the incoming data list. To save traffic, you can use the UDP protocol. However, it does not guarantee that the messages will be delivered.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrWialonIPSUnsupportedPacketType = errors.New("unsupported packet type")
	ErrWialonIPSInvalidLoginMessage   = errors.New("invalid login #L# message")
	ErrWialonIPSInvalidSDMessage      = errors.New("invalid shortened data #SD# message")
	ErrWialonIPSInvalidDataMessage    = errors.New("invalid data #D# message")
	ErrWialonIPSParseDateTime         = errors.New("invalid date or time data")
	ErrWialonIPSParsePoint            = errors.New("invalid coordinates data")
	ErrWialonIPSParseSCA              = errors.New("invalid speed, course or altitude data")
	ErrWialonIPSParseSats             = errors.New("invalid sats data")
	ErrWialonIPSParseHDOP             = errors.New("invalid hdop data")
	ErrWialonIPSParseInOutput         = errors.New("invalid input or output data")
	ErrWialonIPSParseADC              = errors.New("invalid adc data")
	ErrWialonIPSParseAttribute        = errors.New("invalid parameter data")
	ErrWialonIPSCRC16Validation       = errors.New("CRC16 validation not passed")
)

Functions

func MapErrToRespCode

func MapErrToRespCode(p PacketType, err error) string

MapErrToRespCode maps errors to WialonIPS respond codes.

Types

type BlackBoxMessage

type BlackBoxMessage struct {
	ShortenedMessages []ShortenedDataMessage
	DataMessages      []DataMessage
	// contains filtered or unexported fields
}

BlackBoxMessage is a WialonIPS black box message.

func (*BlackBoxMessage) Decode

func (bb *BlackBoxMessage) Decode(data []byte) error

Decode decodes a WialonIPS message. The black box packet is used to transmit messages for the past period. The maximum number of messages that can be transmitted in one packet is 5000. The packet looks as follows: #B#Date;Time;Lat1;Lat2;Lon1;Lon2;Speed;Course;Alt;Sats|Date;Time;Lat1;Lat 2;Lon1;Lon2;Speed;Course;Alt;Sats|Date ;Time;Lat1;Lat2;Lon1;Lon2;Speed; Course;Alt;Sats|CRC16\r\n.

func (*BlackBoxMessage) Error

func (m *BlackBoxMessage) Error() error

func (*BlackBoxMessage) IMEI

func (m *BlackBoxMessage) IMEI() string

func (*BlackBoxMessage) Response

func (bb *BlackBoxMessage) Response() []byte

Response returns a WialonIPS response message.

func (*BlackBoxMessage) Version

func (m *BlackBoxMessage) Version() Version

type DataMessage

type DataMessage struct {
	ShortenedDataMessage
	HDOP       null.Float
	Inputs     null.Int // bit map.
	Outputs    null.Int // bit map.
	ADC        []null.Float
	IButton    null.String
	Attributes common.Attributes
}

DataMessage is a WialonIPS data message. The packet contains additional data structures and looks as follows: #D#Date;Time;Lat1;Lat2;Lon1;Lon2;Speed;Course;Alt;Sats;HDOP;Inputs; Outputs;ADC;Ibutton;Params;CRC16\r\n Each parameter has the following structure: Name:Type:Value Examples of additional parameters: count1:1:564, fuel:2:45.8, hw:3:V4.5, SOS:1:1.

func (*DataMessage) Decode

func (d *DataMessage) Decode(data []byte) error

Decode decodes a WialonIPS message.

func (*DataMessage) Error

func (m *DataMessage) Error() error

func (*DataMessage) IMEI

func (m *DataMessage) IMEI() string

func (*DataMessage) Response

func (d *DataMessage) Response() []byte

Response returns a WialonIPS response message.

func (*DataMessage) Version

func (m *DataMessage) Version() Version

type LoginMessage

type LoginMessage struct {
	Password string
	// contains filtered or unexported fields
}

LoginMessage is a WialonIPS login message. The packet is used for the device authorization on the server. Every TCP connection starts with sending this packet from the device to the server. Other data should be transferred only after the server confirms the successful authorization of the device. The login package looks as follows: #L#Protocol_version;IMEI;Password;CRC16\r\n.

func (*LoginMessage) Decode

func (l *LoginMessage) Decode(data []byte) error

Decode decodes a WialonIPS message.

func (*LoginMessage) Error

func (m *LoginMessage) Error() error

func (*LoginMessage) IMEI

func (m *LoginMessage) IMEI() string

func (*LoginMessage) Response

func (l *LoginMessage) Response() []byte

Response returns a WialonIPS response message.

func (*LoginMessage) Version

func (m *LoginMessage) Version() Version

type Message

type Message interface {
	Decode(data []byte) error
	// Version returns version of Wialon IPS protocol. To avoid reflection use.
	Version() Version
	IMEI() string
	Response() []byte
}

Message is the message of Wialon IPS protocol.

type Packet added in v0.0.3

type Packet struct {
	Type    PacketType
	Version Version
	IMEI    string // IMEI is the unique identifier of the device.
	Message Message
}

Packet is the packet of Wialon IPS protocol. All data is received in text format as a packet which looks as follows: #PT#msgCRC\r\n.

func NewPacket added in v0.0.3

func NewPacket(v Version, imei string) Packet

NewPacket creates a new packet of Wialon IPS protocol.

func (*Packet) Decode added in v0.0.3

func (p *Packet) Decode(data []byte) error

Decode decodes bytes to the package of Wialon IPS protocol.

type PacketType

type PacketType string

PacketType is the type of packet of Wialon IPS.

const (
	UnknownPacket       PacketType = ""   // Unknown packet type. Used for initializing PacketType.
	LoginPacket         PacketType = "L"  // Login packet.
	ShortenedDataPacket PacketType = "SD" // Shortened data packet.
	DataPacket          PacketType = "D"  // Data packet.
	BlackBoxPacket      PacketType = "B"  // Black box packet.
	PingPacket          PacketType = "P"  // Ping packet.
)

type ShortenedDataMessage

type ShortenedDataMessage struct {
	RegisteredAt time.Time
	Point        common.PointWGS84
	// Speed is type of int according specs, but there is found it comes in float xxx.yyy thru retranslation.
	Speed  null.Float
	Course null.Int
	// Altitude is type of int according specs, but there is found it comes in float xxx.yyy thru retranslation.
	Altitude null.Float
	Sat      null.Int
	// contains filtered or unexported fields
}

ShortenedDataMessage is a WialonIPS shortened data message. The packet contains only navigation data and looks as follows: #SD#Date;Time;Lat1;Lat2;Lon1;Lon2;Speed;Course;Alt;Sats;CRC16\r\n.

func (*ShortenedDataMessage) Decode

func (s *ShortenedDataMessage) Decode(data []byte) error

Decode decodes a WialonIPS message.

func (*ShortenedDataMessage) Error

func (m *ShortenedDataMessage) Error() error

func (*ShortenedDataMessage) IMEI

func (m *ShortenedDataMessage) IMEI() string

func (*ShortenedDataMessage) Response

func (s *ShortenedDataMessage) Response() []byte

Response returns a WialonIPS response message.

func (*ShortenedDataMessage) Version

func (m *ShortenedDataMessage) Version() Version

type Splitter added in v0.0.3

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

Splitter implements common.FrameSplitter contract to extract WialonIPS data packet from incoming bytes.

func NewSplitter added in v0.0.3

func NewSplitter() *Splitter

NewSplitter creates a new Splitter instance for WialonIPS protocol.

func (*Splitter) BadData added in v0.0.3

func (s *Splitter) BadData() []byte

BadData returns bad data if any registered. Use it to log which bytes couldn't be parsed as WialonIPS protocol.

func (*Splitter) Error added in v0.0.3

func (s *Splitter) Error() error

Error returns error if any registered. Use it to check that data corresponds to WialonIPS protocol.

func (*Splitter) Splitter added in v0.0.3

func (s *Splitter) Splitter() bufio.SplitFunc

Splitter implements bufio.SplitFunc contract to extract WialonIPS data packet from incoming bytes stream.

type Version

type Version int

Version is the version of Wialon IPS protocol.

const (
	UnknownVersion Version = iota // Unknown version. Used for initializing Version.
	V1_1                          // Version 1.1
	V2_0                          // Version 2.0
)

func (Version) IsValid

func (s Version) IsValid() bool

IsValid returns true if the version is valid.

func (Version) String

func (s Version) String() string

String returns the string representation of the version.

Jump to

Keyboard shortcuts

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