objects

package
v0.0.0-...-7c66ffc Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2020 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ManufacturerID               = 0
	ModelNumberID                = 1
	SerialNumberID               = 2
	FirmwareVersionID            = 3
	BatteryLevelID               = 9
	FirmwareURIID                = 1
	FirmwareStateID              = 3
	FirmwareUpdateResultID       = 5
	FirmwarePackageNameID        = 6
	FirmwarePackageVersionID     = 7
	FirmwareSupportedProtocolsID = 8
	FirmwareDeliveryMethodID     = 9
)

Copyright 2019 Telenor Digital AS

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

These are the resource numbers for the device information block

View Source
const (
	// Idle ie the client is idle before downloading or update
	Idle = FirmwareUpdateState(0)
	// Downloading ie the client is downloading the firmware
	Downloading = FirmwareUpdateState(1)
	// Downloaded ie firmware is downloaded but not applied
	Downloaded = FirmwareUpdateState(2)
	// Updating ie firmware is currently updated
	Updating = FirmwareUpdateState(3)
)
View Source
const (
	// Success updating firmware
	Success = FirmwareUpdateResult(1)
	// NotEnoughFlash not enough flash to update
	NotEnoughFlash = FirmwareUpdateResult(2)
	// OutOfMemory while updating
	OutOfMemory = FirmwareUpdateResult(3)
	// ConnectionLost while receiving or reading firmware
	ConnectionLost = FirmwareUpdateResult(4)
	// IntegrityCheckFailure on downloaded firmware
	IntegrityCheckFailure = FirmwareUpdateResult(5)
	// UnsupportedPackageType when checking downloaded firmware
	UnsupportedPackageType = FirmwareUpdateResult(6)
	// InvalidURI when attempting download
	InvalidURI = FirmwareUpdateResult(7)
	// UpdateFailed when updating firmware (probably one of the most used errors TBH)
	UpdateFailed = FirmwareUpdateResult(8)
	// UnsupportedProtocol in firmware URI
	UnsupportedProtocol = FirmwareUpdateResult(9)
)
View Source
const (
	// CoAP over UDP, ie regular coap:// URIs (RFC 7252)
	CoAP = UpdateProtocol(0)
	// CoAPS over DTLS, ie coaps:// URIs (RFC 7252)
	CoAPS = UpdateProtocol(1)
	// HTTP protocol support, ie http:// URIs (RFC 7230)
	HTTP = UpdateProtocol(2)
	// HTTPS protocol support, ie https:// URIs (RFC 7230)
	HTTPS = UpdateProtocol(3)
	// CoAPTCP is CoAP over TCP , ie coap+tcp:// URIs (RFC 7230)
	CoAPTCP = UpdateProtocol(4)
	// CoAPTLS is CoAP over TLS, ie coaps+tcp:// URIs (RFC 7230)
	CoAPTLS = UpdateProtocol(5)
)
View Source
const (
	// PullDelivery is delivery via package URI field
	PullDelivery = DeliveryMethod(0)
	// PushDelivery is delivery via the package resource
	PushDelivery = DeliveryMethod(1)
	// PushAndPullDelivery are both delivery methods
	PushAndPullDelivery = DeliveryMethod(2)
)

Variables

This section is empty.

Functions

func EncodeBytes

func EncodeBytes(id int, value []byte) []byte

EncodeBytes encodes a byte array into a TLV byte buffer

func EncodeString

func EncodeString(id int, value string) []byte

EncodeString encodes a string into a TLV byte buffer

Types

type DeliveryMethod

type DeliveryMethod byte

DeliveryMethod is the supported firmware delivery methods

type DeviceInformation

type DeviceInformation struct {
	// Manufacturer is the human readable name. Resource 0
	Manufacturer string
	// ModelNumber is the module identifier. Resource 1
	ModelNumber string
	// SerialNumber is the device's serial number. Resource 2
	SerialNumber string
	// FirmwareVersion  is the current firmware version of the device. Resource 3
	FirmwareVersion string
	// BatteryLevel is the current battery level 0-100. Resource 9
	BatteryLevel byte
}

DeviceInformation is the response message from the device when object 3 is queried. The object isn't complete. The object is defined in http://www.openmobilealliance.org/release/LightweightM2M/V1_1-20180710-A/OMA-TS-LightweightM2M_Core-V1_1-20180710-A.pdf section E.4

func NewDeviceInformation

func NewDeviceInformation(b TLVBuffer) DeviceInformation

NewDeviceInformation creates and initializes a new DeviceInformation type with values read from a byte buffer

func (*DeviceInformation) Buffer

func (d *DeviceInformation) Buffer() []byte

Buffer encodes the device information block to a TLV buffer

type FirmwareUpdate

type FirmwareUpdate struct {
	// PackageURI is the URI for the package that the device will download/have
	// downloaded. Object ID is 1.
	PackageURI string
	// State is the current state of the firmware update wrt the URI or uploaded
	// firmware. Object ID is 3.
	State FirmwareUpdateState
	// UpdateResult is the result after the firmware update. Object ID is 5
	UpdateResult FirmwareUpdateResult
	// PackageName is the name of the firmware package. Object ID is 6
	PackageName string
	// PackageVersion is the version of the package. Object ID is 7
	PackageVersion string
	// SupportedProtocols is the list of protocols the firmware supports. Object ID is 8
	SupportedProtocols []UpdateProtocol
	// SupportedDelivery is the delivery method supported by the device. Object ID is 9
	SupportedDelivery DeliveryMethod
}

FirmwareUpdate is the response message from the device when object 5 is queried. The object isn't complete. The object is defined in http://www.openmobilealliance.org/release/LightweightM2M/V1_1-20180710-A/OMA-TS-LightweightM2M_Core-V1_1-20180710-A.pdf section E.6

func NewFirmwareUpdate

func NewFirmwareUpdate(b TLVBuffer) FirmwareUpdate

NewFirmwareUpdate creates and initializes a FirmwareUpdate type with values from an ObjectInstanceTLV buffer

func (*FirmwareUpdate) SetPackageName

func (f *FirmwareUpdate) SetPackageName(b TLVBuffer)

SetPackageName sets the package name from the buffer

func (*FirmwareUpdate) SetPackageVersion

func (f *FirmwareUpdate) SetPackageVersion(b TLVBuffer)

SetPackageVersion sets the package version

func (*FirmwareUpdate) SetState

func (f *FirmwareUpdate) SetState(b TLVBuffer)

SetState sets the state field

func (*FirmwareUpdate) SetSupportedDelivery

func (f *FirmwareUpdate) SetSupportedDelivery(b TLVBuffer)

SetSupportedDelivery reads the object at /5/0/9

func (*FirmwareUpdate) SetSupportedProtocols

func (f *FirmwareUpdate) SetSupportedProtocols(b TLVBuffer)

SetSupportedProtocols reads the object at /5/0/8

func (*FirmwareUpdate) SetUpdateResult

func (f *FirmwareUpdate) SetUpdateResult(b TLVBuffer)

SetUpdateResult sets the UpdateResult field

type FirmwareUpdateResult

type FirmwareUpdateResult byte

FirmwareUpdateResult is the result of the firmware update

func (FirmwareUpdateResult) String

func (r FirmwareUpdateResult) String() string

type FirmwareUpdateState

type FirmwareUpdateState byte

FirmwareUpdateState is the state of the firmware update

func (FirmwareUpdateState) String

func (s FirmwareUpdateState) String() string

type Payload

type Payload struct {
	// ID is the array of IDs that points to this payload. The first ID will be
	// the enclosing object
	ID []int
	// Buffer is the payload itself
	Buffer []byte
}

Payload is a single binary payload. The ID field contains a set of IDs that identify the payload.

func (*Payload) Byte

func (p *Payload) Byte() byte

Byte returns the first byte of the payload

func (Payload) String

func (p Payload) String() string

String returns the payload as a string

func (*Payload) Uint16

func (p *Payload) Uint16() uint16

Uint16 returns the uint16 value of the payload

type TLVBuffer

type TLVBuffer struct {
	// ID is the object ID
	ID int
	// Resources hold all of the resources
	Resources []Payload
}

TLVBuffer does (T)LV decoding of LwM2M response objects.

The LwM2M spec says it's "TLV" but in reality the fields are just LV, ie just and ID, length and a byte buffer. The type is inferred by the ID and there's no type information embedded in the buffer. We only need to access the byte buffers to decode the data structs.

The hierarchy is fairly simple; there's a top level Object ID. Each element inside of that object has a ID. Some of those elements might contain additional sub-elements. At most there's three elements to keep track of. The first top level object has ID 0. The type of the data structure is known up front. Each element inside of that object has an unique ID. Each element might consist of sub-elements which is numbered individually, ie we might have the top level object 0 with the elements 0, 1, 2, 3... and element 2 might contain additional elements numbered 0, 1, 3.

Objects are managed in the OMA registry at http://www.openmobilealliance.org/wp/OMNA/LwM2M/LwM2MRegistry.html

The standard objects are defined in http://www.openmobilealliance.org/release/LightweightM2M/V1_1-20180710-A/OMA-TS-LightweightM2M_Core-V1_1-20180710-A.pdf

Typically we are just interested in the binary payload for a given ID or the payloads in a sequence of IDs.

func NewTLVBuffer

func NewTLVBuffer(buffer []byte) TLVBuffer

NewTLVBuffer decodes a byte buffer

func (*TLVBuffer) GetPayload

func (t *TLVBuffer) GetPayload(id ...int) *Payload

GetPayload returns the payload with the specified ID(s). Nil is returned if the payload doesn't exist.

func (*TLVBuffer) GetPayloadList

func (t *TLVBuffer) GetPayloadList(id ...int) []Payload

GetPayloadList returns a list of payloads matching the IDs

type UpdateProtocol

type UpdateProtocol byte

UpdateProtocol is the protocols the device supports for URIs

Jump to

Keyboard shortcuts

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