layrzprotocol

package module
v2.7.7 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

README

Layrz Protocol

Managed by Golden M, Inc.

Description

Is the official Development Kit for Layrz Protocol, allowing to translate all of the packages sent and received by the Layrz Protocol. Also, includes the the wrapper to send and receive messages from the Layrz Protocol.

Requirements

This library uses at least Golang 1.23 or higher to work.

Documentation

For more information about the protocol, check out the Layrz Protocol Documentation

Work with us

Golden M is a software/hardware development company what is working on a new, innovative and disruptive technologies.

For more information, contact us at sales@layrz.com

License

This project is under MIT License, for more information, check out the LICENCE

Progress

Module Status
PaPacket
PbPacket
PcPacket
PdPacket
PiPacket
PmPacket
PrPacket
PsPacket
AbPacket
AcPacket
AoPacket
ArPacket
AsPacket
AuPacket
LayrzProtocolTcp
LayrzProtocolHttp
ParsePacket

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AbPacket

type AbPacket struct {
	// Is the list of devices that the server wants to send from the device
	Devices *[]BleData
}

Based on the `Layrz Protocol v2` specification. AbPacket is the Blueooth Low Energy packet sent from the server to the device

func (*AbPacket) FromPacket

func (p *AbPacket) FromPacket(raw *string) error

FromPacket is a method that converts a raw packet to a PaPacket based on the `Layrz Protocol v2` specification

Returns an error if the packet is invalid

func (*AbPacket) ToPacket

func (p *AbPacket) ToPacket() *string

ToPacket is a method that converts a PaPacket to a raw packet based on the `Layrz Protocol v2` specification

type AcPacket

type AcPacket struct {
	// Is the list of commands that the server wants to send to the device
	Commands []CommandDefinition
}

Based on the `Layrz Protocol v2` specification. AcPacket is the Command queue packet sent from the server to the device

func (*AcPacket) FromPacket

func (p *AcPacket) FromPacket(raw *string) error

FromPacket is a method that converts a raw packet to a PaPacket based on the `Layrz Protocol v2` specification

Returns an error if the packet is invalid

func (*AcPacket) ToPacket

func (p *AcPacket) ToPacket() *string

ToPacket is a method that converts a PaPacket to a raw packet based on the `Layrz Protocol v2` specification

type AoPacket

type AoPacket struct {
	// Is the timestamp of the response packet
	Timestamp time.Time
}

Based on the `Layrz Protocol v2` specification. AoPacket is the success packet sent from the server to the device

func (*AoPacket) FromPacket

func (p *AoPacket) FromPacket(raw *string) error

FromPacket is a method that converts a raw packet to a PaPacket based on the `Layrz Protocol v2` specification

Returns an error if the packet is invalid

func (*AoPacket) ToPacket

func (p *AoPacket) ToPacket() *string

ToPacket is a method that converts a PaPacket to a raw packet based on the `Layrz Protocol v2` specification

type ArPacket

type ArPacket struct {
	// Is the reason of the error
	Reason string
}

Based on the `Layrz Protocol v2` specification. ArPacket is the error packet sent from the server to the device

func (*ArPacket) FromPacket

func (p *ArPacket) FromPacket(raw *string) error

FromPacket is a method that converts a raw packet to a PaPacket based on the `Layrz Protocol v2` specification

Returns an error if the packet is invalid

func (*ArPacket) ToPacket

func (p *ArPacket) ToPacket() *string

ToPacket is a method that converts a PaPacket to a raw packet based on the `Layrz Protocol v2` specification

type AsPacket

type AsPacket struct{}

Based on the `Layrz Protocol v2` specification. AsPacket is the success authentication packet sent from the server to the device

func (*AsPacket) FromPacket

func (p *AsPacket) FromPacket(raw *string) error

FromPacket is a method that converts a raw packet to a AsPacket based on the `Layrz Protocol v2` specification

Returns an error if the packet is invalid

func (*AsPacket) ToPacket

func (p *AsPacket) ToPacket() *string

ToPacket is a method that converts a PaPacket to a raw packet based on the `Layrz Protocol v2` specification

type AuPacket

type AuPacket struct{}

Based on the `Layrz Protocol v2` specification. AuPacket is the authorization request packet sent from the server to the device

func (*AuPacket) FromPacket

func (p *AuPacket) FromPacket(raw *string) error

FromPacket is a method that converts a raw packet to a AuPacket based on the `Layrz Protocol v2` specification

Returns an error if the packet is invalid

func (*AuPacket) ToPacket

func (p *AuPacket) ToPacket() *string

ToPacket is a method that converts a PaPacket to a raw packet based on the `Layrz Protocol v2` specification

type BleAdvertisement

type BleAdvertisement struct {
	// Is the detected Mac Address. This Mac Adress came from the detected device, not the
	// device that is detecting.
	MacAddress string
	// Is when the device was detected.
	Timestamp time.Time

	// Is the closest latitude of the device. Defined by the device that is detecting.
	// This value is optional
	Latitude float64

	// Is the closest longitude of the device. Defined by the device that is detecting.
	// This value is optional
	Longitude float64

	// Is the closest altitude of the device. Defined by the device that is detecting.
	// This value is optional
	Altitude float64

	// Is the signal strength of the detected device.
	Rssi int

	// Is the transmission power of the detected device.
	// This value is optional
	TxPower int

	// Is the model of the detected device. This model should be equals to the model of the device
	// and the model defined by Layrz.
	Model string

	// Is the list of manufacturer data advertised by the device.
	ManufacturerData []BleManufacturerData

	// Is the list of service data advertised by the device.
	ServiceData []BleServiceData

	// Is the name of the device. This name is optional.
	DeviceName string
}

Defines a detection of a BLE advertisement.

type BleData

type BleData struct {
	// Is the MAC address of the device
	MacAddress *string

	// Is the Model identifier of the device
	Model *string
}

type BleManufacturerData

type BleManufacturerData struct {
	// Is the manufacturer identifier.
	CompanyId int

	// Is the manufacturer data.
	Data []byte
}

Defines the manufacturer data advertised by the device.

type BleServiceData

type BleServiceData struct {
	// Is the service UUID.
	Uuid int

	// Is the service data.
	Data []byte
}

Defines the service data advertised by the device.

type CommandDefinition

type CommandDefinition struct {
	// Is the command id, this value is unique and should be used to
	// send the ACK packet PdPacket to the server
	CommandId int

	// Is the command name, this value is used to identify the command
	CommandName *string

	// Is the command arguments, may contain any value depending of
	// the command definition
	Args *map[string]interface{}
}

Defines the command structure based on the `Layrz Protocol v2` specification

type FirmwareBranch

type FirmwareBranch string
const (
	Development FirmwareBranch = "1"
	Stable      FirmwareBranch = "0"
)

type HttpComm

type HttpComm struct {
	Scheme HttpScheme
	Host   string
	Ident  string
	Passwd string
	// contains filtered or unexported fields
}

func (*HttpComm) GetCommands

func (p *HttpComm) GetCommands() (*interface{}, error)

Get new commands from the server

func (*HttpComm) New

func (p *HttpComm) New(scheme HttpScheme, host, ident, password string)

New creates a new intance of LayrzProtocol using HTTP communication

func (*HttpComm) Send

func (p *HttpComm) Send(packet interface{}) (*interface{}, error)

Send sends a packet to the server

Returns an error if the packet is invalid And, may return an Packet stored on an interface{}

type HttpScheme

type HttpScheme string
const (
	HTTP  HttpScheme = "http"
	HTTPS HttpScheme = "https"
)

type PaPacket

type PaPacket struct {
	// Defines the ident of the device
	Ident *string

	// Defines the password of the device
	Password *string
}

Based on the `Layrz Protocol v2` specification. PaPacket is the Authentication packet sent from the device to the server.

func (*PaPacket) FromPacket

func (p *PaPacket) FromPacket(raw *string) error

FromPacket is a method that converts a raw packet to a PaPacket based on the `Layrz Protocol v2` specification

Returns an error if the packet is invalid

func (*PaPacket) ToPacket

func (p *PaPacket) ToPacket() *string

ToPacket is a method that converts a PaPacket to a raw packet based on the `Layrz Protocol v2` specification

type PbPacket

type PbPacket struct {
	// Is the list of BLE advertisements detected by the device.
	Advertisements *[]BleAdvertisement
}

Based on the `Layrz Protocol v2` specification. PbPacket is the Bluetooth low energy packet sent from the device to the server.

func (*PbPacket) FromPacket

func (p *PbPacket) FromPacket(raw *string) error

FromPacket is a method that converts a raw packet to a PaPacket based on the `Layrz Protocol v2` specification

Returns an error if the packet is invalid

func (*PbPacket) ToPacket

func (p *PbPacket) ToPacket() *string

ToPacket is a method that converts a PaPacket to a raw packet based on the `Layrz Protocol v2` specification

type PcPacket

type PcPacket struct {
	// Is the timestamp of the response packet
	Timestamp time.Time

	// Is the command id of the response packet
	CommandId int

	// Is the message of the response packet
	Message *string
}

Based on the `Layrz Protocol v2` specification. PcPacket is the Packet command response sent from the device to the server

func (*PcPacket) FromPacket

func (p *PcPacket) FromPacket(raw *string) error

FromPacket is a method that converts a raw packet to a PaPacket based on the `Layrz Protocol v2` specification

Returns an error if the packet is invalid

func (*PcPacket) ToPacket

func (p *PcPacket) ToPacket() *string

ToPacket is a method that converts a PaPacket to a raw packet based on the `Layrz Protocol v2` specification

type PdPacket

type PdPacket struct {
	// Is the timestamp of the response packet
	Timestamp time.Time

	// Is the position of the device
	Position *Position

	// Is the extra data sent by the device
	ExtraData *map[string]interface{}
}

Based on the `Layrz Protocol v2` specification. PdPacket is the Data packet sent from the device to the server

func (*PdPacket) FromPacket

func (p *PdPacket) FromPacket(raw *string) error

FromPacket is a method that converts a raw packet to a PaPacket based on the `Layrz Protocol v2` specification

Returns an error if the packet is invalid

func (*PdPacket) ToPacket

func (p *PdPacket) ToPacket() *string

ToPacket is a method that converts a PaPacket to a raw packet based on the `Layrz Protocol v2` specification

type PiPacket

type PiPacket struct {
	// [ident] is the Unique identifier, sent as part of the package as `IMEI`
	Ident string

	// [firmwareId] is the firmware internal ID, this is in newer versions is a Layrz ID, otherwise is a unique
	// identifier set by the hardware department of Layrz LTD. Also, is idenfified in the package as `FW_ID`
	FirmwareId string

	// [firmwareBuild] is the firmware version, is an incremental number that is increased in each release.
	// This is identified in the package as `FW_BUILD`
	FirmwareBuild int

	// [deviceId] is the device internal ID, this is in newer versions is a Layrz ID, otherwise is a unique
	// identifier set by the hardware department of Layrz LTD. Also, is idenfified in the package as `SYS_DEV_ID`
	DeviceId int

	// [hardwareId] is the hardware internal ID, this is in newer versions is a Layrz ID, otherwise is a unique
	// identifier set by the hardware department of Layrz LTD. Also, is idenfified in the package as `SYS_DEV_HW_ID`
	HardwareId int

	// [modelId] is the model internal ID, this is in newer versions is a Layrz ID, otherwise is a unique
	// identifier set by the hardware department of Layrz LTD. Also, is idenfified in the package
	// as `SYS_DEV_MODEL_ID`
	ModelId int

	// [firmwareBranch] is the branch of the firmware, this is identified in the package as `SYS_DEV_FW_BRANCH`
	FirmwareBranch FirmwareBranch

	// [fotaEnabled] is a boolean that indicates if the device is capable of receiving FOTA updates.
	// This is identified in the package as `FOTA_ENABLED`
	FotaEnabled bool
}

Based on the `Layrz Protocol v2` specification. PiPacket is the identification packet sent from the device to the server

func (*PiPacket) FromPacket

func (p *PiPacket) FromPacket(raw *string) error

FromPacket is a method that converts a raw packet to a PaPacket based on the `Layrz Protocol v2` specification

Returns an error if the packet is invalid

func (*PiPacket) ToPacket

func (p *PiPacket) ToPacket() *string

ToPacket is a method that converts a PaPacket to a raw packet based on the `Layrz Protocol v2` specification

type PmPacket

type PmPacket struct {
	// Is the timestamp of the response packet
	Filename *string

	// Is the command id of the response packet
	ContentType *string

	// Is the message of the response packet
	Data *[]byte
}

Based on the `Layrz Protocol v2` specification. PmPacket is the media packet sent from the device to the server

func (*PmPacket) FromPacket

func (p *PmPacket) FromPacket(raw *string) error

FromPacket is a method that converts a raw packet to a PaPacket based on the `Layrz Protocol v2` specification

Returns an error if the packet is invalid

func (*PmPacket) ToPacket

func (p *PmPacket) ToPacket() *string

ToPacket is a method that converts a PaPacket to a raw packet based on the `Layrz Protocol v2` specification

type Position

type Position struct {
	// Is the latitude of the device
	Latitude *float64

	// Is the longitude of the device
	Longitude *float64

	// Is the altitude of the device
	Altitude *float64

	// Is the speed of the device
	Speed *float64

	// Is the direction of the device
	Direction *float64

	// Is the satellite count of the device
	SatelliteCount *int

	// Is the horizontal accuracy of the device
	Hdop *float64
}

type PrPacket

type PrPacket struct{}

Based on the `Layrz Protocol v2` specification. PrPacket is the syncronization packet sent from the device to the server

func (*PrPacket) FromPacket

func (p *PrPacket) FromPacket(raw *string) error

FromPacket is a method that converts a raw packet to a PrPacket based on the `Layrz Protocol v2` specification

Returns an error if the packet is invalid

func (*PrPacket) ToPacket

func (p *PrPacket) ToPacket() *string

ToPacket is a method that converts a PaPacket to a raw packet based on the `Layrz Protocol v2` specification

type PsPacket

type PsPacket struct {
	// Is the timestamp of the response packet
	Timestamp time.Time

	// Is the current configuration of the device
	Params *map[string]interface{}
}

Based on the `Layrz Protocol v2` specification. PsPacket is the Settings packet sent from the device to the server

func (*PsPacket) FromPacket

func (p *PsPacket) FromPacket(raw *string) error

FromPacket is a method that converts a raw packet to a PaPacket based on the `Layrz Protocol v2` specification

Returns an error if the packet is invalid

func (*PsPacket) ToPacket

func (p *PsPacket) ToPacket() *string

ToPacket is a method that converts a PaPacket to a raw packet based on the `Layrz Protocol v2` specification

type TcpComm

type TcpComm struct {
	Host   string
	Port   int
	Ident  string
	Passwd string
	// contains filtered or unexported fields
}

func (*TcpComm) Close

func (p *TcpComm) Close() error

Close closes the connection

func (*TcpComm) Connect

func (p *TcpComm) Connect() error

Connect connects to the server

func (*TcpComm) New

func (p *TcpComm) New(host string, port int, ident, password string)

New creates a new intance of LayrzProtocol using TCP communication

func (*TcpComm) Send

func (p *TcpComm) Send(packet interface{}) error

Send sends a packet to the server

func (*TcpComm) SetCallback

func (p *TcpComm) SetCallback(callback func(*interface{})) error

SetCallback sets the callback function to be called when a packet is received

Jump to

Keyboard shortcuts

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