model

package
v0.0.0-...-cfba5c7 Latest Latest
Warning

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

Go to latest
Published: May 2, 2018 License: Apache-2.0 Imports: 14 Imported by: 9

Documentation

Overview

Package model contains the high-level entities in the LoRaWAN spec.package model

Index

Constants

View Source
const (
	// TransportTypeKey is the key used to identify the output (and configuration)
	TransportTypeKey = TransportConfigKey("type")
)

Variables

View Source
var (
	// ErrInvalidChars is returned when a tag contains invalid chars
	ErrInvalidChars = errors.New("invalid characters in tag")
)

Functions

This section is empty.

Types

type APIToken

type APIToken struct {
	Token    string
	UserID   UserID
	Write    bool
	Resource string
	Tags
}

APIToken represents an API token that the users can use to access the API. There are two basic roles -- "read" and "write", set by the ReadOnly flag.

The resource is a HTTP URI. A token with the resource

/applications/<eui>

would give access to that particular application while a token with the resource set to

/applications

would give access to all of the applications. The most relaxed resource is a single `/` which gives access to *all* resources owned by the user. The user ID is the CONNECT ID user id. The token itself is a string of alphanumeric characters.

func NewAPIToken

func NewAPIToken(userID UserID, resource string, write bool) (APIToken, error)

NewAPIToken creates a new API token.

func (*APIToken) Equals

func (t *APIToken) Equals(other APIToken) bool

Equals return true if the token is equal to the provided token

type AppOutput

type AppOutput struct {
	EUI           protocol.EUI    // Unique identifier for output
	AppEUI        protocol.EUI    // The associated application
	Configuration TransportConfig // Output configuration
}

AppOutput is configuration for application outputs (MQTT et al)

func NewAppOutput

func NewAppOutput() AppOutput

NewAppOutput creates a new output instance

type Application

type Application struct {
	AppEUI protocol.EUI // Application EUI
	Tags
}

Application represents a LoRa application instance.

func NewApplication

func NewApplication() Application

NewApplication creates a new application instance

func (*Application) Equals

func (a *Application) Equals(other Application) bool

Equals returns true if the other application has identical fields. Just like ...Equals

func (*Application) GenerateAppNonce

func (a *Application) GenerateAppNonce() ([3]byte, error)

GenerateAppNonce generates a new AppNonce, three random bytes that will be used to generate new devices.

type Device

type Device struct {
	DeviceEUI       protocol.EUI     // EUI for device
	DevAddr         protocol.DevAddr // Device address
	AppKey          protocol.AESKey  // AES key for application
	AppSKey         protocol.AESKey  // Application session key
	NwkSKey         protocol.AESKey  // Network session key
	AppEUI          protocol.EUI     // The application associated with the device. Set by storage backend
	State           DeviceState      // Current state of the device
	FCntUp          uint16           // Frame counter up (from device)
	FCntDn          uint16           // Frame counter down (to device)
	RelaxedCounter  bool             // Relaxed frame count checks
	DevNonceHistory []uint16         // Log of DevNonces sent from the device
	KeyWarning      bool             // Duplicate key warning flag
	Tags
}

Device represents a device. Devices are associated with one and only one Application

func NewDevice

func NewDevice() Device

NewDevice creates a new device

func (*Device) GetRX1Window

func (d *Device) GetRX1Window() time.Duration

GetRX1Window returns the 1st receive window for the device BUG(stlaehd): Returns constant. Should be set based on device settings and frequency plan.

func (*Device) GetRX2Window

func (d *Device) GetRX2Window() time.Duration

GetRX2Window returns the 2nd receive window for the device BUG(stalehd): Returns a constant. Should be set based on frequency plan (EU, US, CN)

func (*Device) HasDevNonce

func (d *Device) HasDevNonce(devNonce uint16) bool

HasDevNonce returns true if the specified nonce exists in the nonce history

type DeviceData

type DeviceData struct {
	DeviceEUI  protocol.EUI     // Device address used
	Timestamp  int64            // Timestamp for message. Data type might change.
	Data       []byte           // The data the end-device sent
	GatewayEUI protocol.EUI     // The gateway the message was received from.
	RSSI       int32            // Radio stats; RSSI
	SNR        float32          // Radio; SNR
	Frequency  float32          // Radio; Frequency
	DataRate   string           // Data rate (ie "SF7BW125" or similar)
	DevAddr    protocol.DevAddr // The reported DevAddr (at the time)
}

DeviceData contains a single transmission from an end-device.

func (*DeviceData) Equals

func (d *DeviceData) Equals(other DeviceData) bool

Equals compares two DeviceData instances

type DeviceState

type DeviceState uint8

DeviceState represents the device state

const (
	OverTheAirDevice   DeviceState = 1
	PersonalizedDevice DeviceState = 8 // Note: 8 is for backwards compatibility
	DisabledDevice     DeviceState = 0
)

Types of devices. A device can either be OTAA, ABP or disabled.

func DeviceStateFromString

func DeviceStateFromString(str string) (DeviceState, error)

DeviceStateFromString converts a string representation of DeviceState into a DeviceState value. Unknown strings returns the DisabledDevice state. Conversion is not case sensitive. White space is trimmed.

func (DeviceState) String

func (d DeviceState) String() string

String converts the device state into a human-readable string representation.

type DownstreamMessage

type DownstreamMessage struct {
	DeviceEUI protocol.EUI
	Data      string
	Port      uint8

	Ack         bool
	CreatedTime int64
	SentTime    int64
	AckTime     int64
}

DownstreamMessage is messages sent downstream (ie to devices from the server).

func NewDownstreamMessage

func NewDownstreamMessage(deviceEUI protocol.EUI, port uint8) DownstreamMessage

NewDownstreamMessage creates a new DownstreamMessage

func (*DownstreamMessage) IsComplete

func (d *DownstreamMessage) IsComplete() bool

IsComplete returns true if the message processing is completed. If the ack flag isn't set the message would only have to be sent to the device. If the ack flag is set the device must acknowledge the message before it is considered completed.

func (*DownstreamMessage) Payload

func (d *DownstreamMessage) Payload() []byte

Payload returns the payload as a byte array. If there's an error decoding the data it will return an empty byte array

func (*DownstreamMessage) State

State returns the message's state based on the value of the time stamps

type DownstreamMessageState

type DownstreamMessageState uint8

DownstreamMessageState is the state of the downstream messages

const (
	UnsentState DownstreamMessageState = iota
	SentState
	AcknowledgedState
)

States for the downstream message

type Gateway

type Gateway struct {
	GatewayEUI protocol.EUI // EUI of gateway.
	IP         net.IP       // IP address of gateway. This might not be fixed.
	StrictIP   bool         // Strict IP address check
	Latitude   float32      // Latitude, in decimal degrees, positive N <-90-90>
	Longitude  float32      // Longitude, in decimal degrees, positive E [-180-180>
	Altitude   float32      // Altitude, meters
	Tags
}

Gateway represents - you guessed it - a gateway.

func NewGateway

func NewGateway() Gateway

NewGateway creates a new gateway

func (*Gateway) Equals

func (g *Gateway) Equals(other Gateway) bool

Equals checks gateways for equality

type PublicGatewayInfo

type PublicGatewayInfo struct {
	EUI       string  // EUI of gateway.
	Latitude  float32 // Latitude, in decimal degrees, positive N <-90-90>
	Longitude float32 // Longitude, in decimal degrees, positive E [-180-180>
	Altitude  float32 // Altitude, meters
}

PublicGatewayInfo contains public information for gateways. This information is available to all users, even the ones not owning a gateway.

type Tags

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

Tags contains

func NewTags

func NewTags() Tags

NewTags create a new set of tags

func NewTagsFromBuffer

func NewTagsFromBuffer(buf []byte) (*Tags, error)

NewTagsFromBuffer unmarshals a JSON struct into a Tags structure

func NewTagsFromMap

func NewTagsFromMap(values map[string]string) (*Tags, error)

NewTagsFromMap builds a new tags structure from a map

func (*Tags) Equals

func (t *Tags) Equals(other Tags) bool

Equals checks if the tags are the same for both

func (*Tags) Exists

func (t *Tags) Exists(name string) bool

Exists checks if the tag already exists

func (*Tags) GetTag

func (t *Tags) GetTag(name string) (string, bool)

GetTag returns the tag value

func (*Tags) RemoveTag

func (t *Tags) RemoveTag(name string)

RemoveTag removes the tag from the collection

func (*Tags) SetTag

func (t *Tags) SetTag(name string, value string) error

SetTag adds or replaces a tag. ErrInvalidChars are returned if the tag name or value contains invalid characters

func (*Tags) TagJSON

func (t *Tags) TagJSON() []byte

TagJSON returns the tags formatted as a JSON struct

func (*Tags) Tags

func (t *Tags) Tags() map[string]string

Tags return a copy of the tags

type TransportConfig

type TransportConfig map[TransportConfigKey]interface{}

TransportConfig is a generic configuration for outputs. This is in effect a simple map keyed on a string.

func NewTransportConfig

func NewTransportConfig(jsonString string) (TransportConfig, error)

NewTransportConfig creates a new OutputConfig from a JSON string

func (TransportConfig) Bool

func (t TransportConfig) Bool(key TransportConfigKey, def bool) bool

Bool returns the key value as a boolean. If the key doesn't exist or the key is of a different type the default will be returned

func (TransportConfig) Int

func (t TransportConfig) Int(key TransportConfigKey, def int) int

Int returns the key value as a boolean. If the key doesn't exist or the key is of a different type the default will be returned

func (TransportConfig) String

func (t TransportConfig) String(key TransportConfigKey, def string) string

String returns the key value as a string. If the key doesn't exist or the key is of a different type the default will be returned

type TransportConfigKey

type TransportConfigKey string

TransportConfigKey is the key for configuration items

type User

type User struct {
	ID    UserID
	Name  string
	Email string
}

User is the user owning/administering applications. Authentication and authorization are performed by external systems.

type UserID

type UserID string

UserID is a type representing the users

const (
	// SystemUserID is the user ID for the "system user". It should not be used for
	// anything but internal access.
	SystemUserID UserID = "system"
	// InvalidUserID is an user ID that is invalid.
	InvalidUserID UserID = ""
)

Notes

Bugs

  • Returns constant. Should be set based on device settings and frequency plan.

  • Returns a constant. Should be set based on frequency plan (EU, US, CN)

Jump to

Keyboard shortcuts

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