wialonretr

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

README

= Wialon Retranslator

The Wialon Retranslator protocol (v. 1.0) is used to retransmit data in binary format using TCP. Using the protocol, you can transfer location information, values of various sensors, and JPEG images.

#Only Decoder is implemented for now!#

.Data Type Table
[%autowidth]
|===
| *Size (Bytes)* | *Type* | *Byte Order* | *Description*
| N | Binary .5+| Big-endian | Binary data.
| N | String | The value must be converted according to ASCII encoding. Its limit is determined by the zero byte `0x00`.
| 2 | Short | An unassigned integer.
| 4 | Integer | A signed integer.
| 8 | Long | A signed integer.
| 8 | Double | Little-endian | A signed fractional number.
| 1 | Byte | - | An unassigned integer.
|===

.Packet Structure
[%autowidth]
|===
| Packet Size | UID | Time | Bitmask | Posinfo Block | Pwr_ext Block | Avl_inputs Block | Data Block ...
|===

.Packet Structure Table
[%autowidth]
|===
| *Field Type* | *Field Value* | *Field Description*
| Integer | Packet size | The size of the whole packet, excluding the current field. Little-endian byte order. The only exception from the Data Type Table.
| String | Unique identifier of the controller | Corresponds to the unique identifier of the Wialon unit.
| Integer | Time | Timestamp in seconds since January 1, 1970 (UTC±00:00).
| Integer | Message bit mask
a|
[%autowidth]
!===
2+! *Bitmask Description Table*
! `0x00000001` ! Information about location.
! `0x00000002` ! Information about digital inputs.
! `0x00000004` ! Information about digital outputs.
! `0x00000010` ! Alarm bit.
! `0x00000020` ! Driver ID information.
! `0xFFFFFFC8` ! Bits are reserved.
!===
| - | Data block structure | A substructure that contains data blocks. Description is below.
|===

.Data Block
[%autowidth]
|===
| *Size (bytes)* | *Field Type* | *Field Description*
| 2 | Short | Block delimiter
| 4 | Integer | Block size
| 1 | Byte
a|
[%autowidth]
!===
2+! *Security attribute*
! `1` ! parameter hidden
! `0` ! parameter shown
!===
For `posinfo`, `avl_inputs`, `avl_outputs`, `avl_driver` must be `1`.

For others must be `0`
| 1 | Byte
a|
[%autowidth]
!===
2+! *Data block type*
! `1` ! text
! `2` ! binary
! `3` ! integer
! `4` ! double
! `5` ! long
!===
| - | String
a|
[%autowidth]
!===
2+! *Block name*
! `posinfo` ! block with coordinates
! `imag` ! image in JPEG format
! `pwr_ext` ! voltage supply
! `avl_inputs` ! digital inputs value
! `avl_outputs` ! digital outputs value
! `avl_driver` ! driver ID value
! `adc1`, `adc2`, ... ! analog sensors value
! `gsm` ! gsm signal level
! `ign` ! ignition
! `can1`, `can2`, ... ! CAN value (bus topology)
! ... ! any names with 38 bytes max length
!===
| - | - | Block value
|===

.Posinfo Block Binary Value
[%autowidth]
|===
| *Field Type* | *Field Value* | *Field Description*
| Double | Longitude | Longitude.
| Double | Latitude | Latitude.
| Double | Altitude | Absolute altitude above sea level. Measured in meters.
| Short | Speed | Measured in km/h.
| Short | Course | Degrees 0 – 359.
| Byte | Sats | Number of satellites.
|===

.Image Block Binary Value
[%autowidth]
|===
| *Field Type* | *Field Value* | *Field Description*
| Long | Title | Constant: `0x0000000000000000`.
| Integer | Image Size | Only the binary part of the block is included in the size.
| Binary | Image | JPEG data.
|===
#!Warning! Implementation is not suitable to process big size JPEG data.#

== Confirmation of Data Processing

To each valid incoming packet, Wialon sends 0x11 as a response. If data is retransmitted from Wialon to a third-party platform, the response is not required.

== Example of Packet Parsing

Source packet:
`74000000333533393736303133343435343835005D515DBB000000030BBB000000270102706F73696E666F00A027AFDF5D9848403AC7253383DD4B400000000000805A40003601460B0BBB0000001200047077725F657874002B8716D9CE973B400BBB00000011010361766C5F696E707574730000000001`

.Explain table
[%autowidth]
|===
| *Bytes* | *Description* | *Value*
| `74000000` | Packet size | 116
| `33353339373630313334343534383500`  | Controller identifier | 353976013445485
| `5D515DBB` | UTC time | 1565613499 = 2019/08/12 15:38:19
| `00000003` | Bitmask  | 3
| `0BBB` | Block delimiter  | 3003
| `00000027` | Block size | 39
| `01` | Stealth attribute | 1
| `02` | Data type of the block  | 2
| `706F73696E666F00` | Name of the block | posinfo
| `A027AFDF5D984840` | Longitude | 49.1903648
| `3AC7253383DD4B40` | Latitude | 55.7305664
| `0000000000805A40` | Altitude | 106.0
| `0036` | Speed | 54
| `0146` | Course | 326
| `0B` | Number of satellites | 11
| `0BBB` | Block delimiter | 3003
| `00000012` | Block size | 18
| `00` | Stealth attribute | 0
| `04` | Type of block data | 4
| `7077725F65787400` | Name of the block | pwr_ext
| `2B8716D9CE973B40` | Value | 27.593
| `0BBB` | Block delimiter | 3003
| `00000011` | Block size | 17
| `01` | Stealth attribute | 1
| `03` | Type of block data | 3
| `61766C5F696E7075747300` | Name of the block | avl_inputs
| `00000001` | Value  | 1

Documentation

Overview

wialonretr is package that implements the Wialon Retranslator protocol (v. 1.0) is used to retransmit data in binary format using TCP. Using the protocol, you can transfer location information, values of various sensors, and JPEG images.

Index

Constants

View Source
const (
	PosInfoName    = "posinfo"
	ImageName      = "imag"
	AvlInputsName  = "avl_inputs"
	AvlOutputsName = "avl_outputs"
	AvlDriverName  = "avl_driver"
)

Variables

View Source
var (
	ErrWialonRetranslatorBadDeviceID  = fmt.Errorf("failed to get device id: %w", common.ErrBadData)
	ErrWialonRetranslatorCutBlockName = errors.New("cut block data name")
)

Functions

This section is empty.

Types

type Data

type Data interface {
	Decode([]byte) error
}

Data provides contract for decoding data blocks of WialonRetranslator protocol.

type DataBlock

type DataBlock struct {
	Value interface{}
	// contains filtered or unexported fields
}

DataBlock represents WialonRetranslator data block.

func (*DataBlock) Decode

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

Decode decodes WialonRetranslator data block from bytes.

type DataBlocks

type DataBlocks map[string]DataBlock

func (*DataBlocks) AddDataBlock

func (db *DataBlocks) AddDataBlock(name string, b DataBlock)

func (*DataBlocks) AddImage

func (db *DataBlocks) AddImage(i Image)

func (*DataBlocks) AddPosInfo

func (db *DataBlocks) AddPosInfo(pi PositionInfo)

type Image

type Image []byte

Image represents WialonRetranslator image data block.

func (*Image) Decode

func (i *Image) Decode(data []byte) error

Decode decodes WialonRetranslator image data block from bytes.

type Packet

type Packet struct {
	DeviceID     string
	RegisteredAt time.Time
	DataBlocks   DataBlocks
	// contains filtered or unexported fields
}

Packet represents WialonRetranslator data packet.

func (*Packet) Decode

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

Decode decodes WialonRetranslator data packet from bytes.

func (*Packet) Error

func (p *Packet) Error() error

Error returns error if some got due Decoding or Encoding.

func (*Packet) HasAlerts

func (p *Packet) HasAlerts() bool

HasAlerts returns true if package has alerts data.

func (*Packet) HasDigitalInputs

func (p *Packet) HasDigitalInputs() bool

HasDigitalInputs returns true if package has digital inputs data.

func (*Packet) HasDigitalOutputs

func (p *Packet) HasDigitalOutputs() bool

HasDigitalOutputs returns true if package has digital outputs data.

func (*Packet) HasDriverID

func (p *Packet) HasDriverID() bool

HasDriverID returns true if package has driver id data.

func (*Packet) HasLocation

func (p *Packet) HasLocation() bool

HasLocation returns true if package has location data.

func (*Packet) Response

func (p *Packet) Response() []byte

Response returns WialonRetranslator response bytes.

type PositionInfo

type PositionInfo struct {
	Lon    float64
	Lat    float64
	Alt    float64
	Speed  int16
	Course int16
	Sats   int8
}

PositionInfo represents WialonRetranslator posinfo data block.

func (*PositionInfo) Decode

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

Decode decodes WialonRetranslator posinfo data block from bytes.

type Splitter added in v0.0.3

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

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

func NewSplitter added in v0.0.3

func NewSplitter() *Splitter

NewSplitter creates a new Splitter instance for WialonRetranslator protocol.

func (*Splitter) BadData added in v0.0.3

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

BadData returns bad data if error was registered. Use it to log which bytes couldn't be parsed as WialonRetranslator 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 WialonRetranslator protocol.

func (*Splitter) Splitter added in v0.0.3

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

Splitter implements bufio.SplitFunc contract to extract WialonRetranslator data packet from incoming bytes stream. Data packets start with 4 little endian bytes of packet length.

Jump to

Keyboard shortcuts

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