gateway

package
v2.7.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2019 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProtocolVersion1 uint8 = 0x01
	ProtocolVersion2 uint8 = 0x02
)

Protocol versions

Variables

View Source
var (
	ErrInvalidProtocolVersion = errors.New("gateway: invalid protocol version")
)

Errors

Functions

This section is empty.

Types

type Backend

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

Backend implements a Semtech packet-forwarder gateway backend.

func NewBackend

func NewBackend(bind string, onNew func(lorawan.EUI64) error, onDelete func(lorawan.EUI64) error, skipCRCCheck bool, configurations []semtech.PFConfiguration) (*Backend, error)

NewBackend creates a new backend.

func (*Backend) ApplyConfiguration

func (b *Backend) ApplyConfiguration(config gw.GatewayConfigPacket) error

ApplyConfiguration applies the given configuration.

func (*Backend) Close

func (b *Backend) Close() error

Close closes the backend.

func (*Backend) RXPacketChan

func (b *Backend) RXPacketChan() chan gw.RXPacketBytes

RXPacketChan returns the channel containing the received RX packets.

func (*Backend) Send

func (b *Backend) Send(txPacket gw.TXPacketBytes) error

Send sends the given packet to the gateway.

func (*Backend) StatsChan

func (b *Backend) StatsChan() chan gw.GatewayStatsPacket

StatsChan returns the channel containing the received gateway stats.

func (*Backend) TXAckChan

func (b *Backend) TXAckChan() chan gw.TXAck

TXAckChan returns the channel containing the TX acknowledgements (or errors).

type CompactTime

type CompactTime time.Time

CompactTime implements time.Time but (un)marshals to and from ISO 8601 'compact' format.

func (CompactTime) MarshalJSON

func (t CompactTime) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*CompactTime) UnmarshalJSON

func (t *CompactTime) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type DatR

type DatR struct {
	LoRa string
	FSK  uint32
}

DatR implements the data rate which can be either a string (LoRa identifier) or an unsigned integer in case of FSK (bits per second).

func (DatR) MarshalJSON

func (d DatR) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*DatR) UnmarshalJSON

func (d *DatR) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type ExpandedTime

type ExpandedTime time.Time

ExpandedTime implements time.Time but (un)marshals to and from ISO 8601 'expanded' format.

func (ExpandedTime) MarshalJSON

func (t ExpandedTime) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*ExpandedTime) UnmarshalJSON

func (t *ExpandedTime) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type PacketType

type PacketType byte

PacketType defines the packet type.

const (
	PushData PacketType = iota
	PushACK
	PullData
	PullResp
	PullACK
	TXACK
)

Available packet types

func GetPacketType

func GetPacketType(data []byte) (PacketType, error)

GetPacketType returns the packet type for the given packet data.

func (PacketType) String

func (i PacketType) String() string

type PullACKPacket

type PullACKPacket struct {
	ProtocolVersion uint8
	RandomToken     uint16
}

PullACKPacket is used by the server to confirm that the network route is open and that the server can send PULL_RESP packets at any time.

func (PullACKPacket) MarshalBinary

func (p PullACKPacket) MarshalBinary() ([]byte, error)

MarshalBinary marshals the object in binary form.

func (*PullACKPacket) UnmarshalBinary

func (p *PullACKPacket) UnmarshalBinary(data []byte) error

UnmarshalBinary decodes the object from binary form.

type PullDataPacket

type PullDataPacket struct {
	ProtocolVersion uint8
	RandomToken     uint16
	GatewayMAC      [8]byte
}

PullDataPacket is used by the gateway to poll data from the server.

func (PullDataPacket) MarshalBinary

func (p PullDataPacket) MarshalBinary() ([]byte, error)

MarshalBinary marshals the object in binary form.

func (*PullDataPacket) UnmarshalBinary

func (p *PullDataPacket) UnmarshalBinary(data []byte) error

UnmarshalBinary decodes the object from binary form.

type PullRespPacket

type PullRespPacket struct {
	ProtocolVersion uint8
	RandomToken     uint16
	Payload         PullRespPayload
}

PullRespPacket is used by the server to send RF packets and associated metadata that will have to be emitted by the gateway.

func (PullRespPacket) MarshalBinary

func (p PullRespPacket) MarshalBinary() ([]byte, error)

MarshalBinary marshals the object in binary form.

func (*PullRespPacket) UnmarshalBinary

func (p *PullRespPacket) UnmarshalBinary(data []byte) error

UnmarshalBinary decodes the object from binary form.

type PullRespPayload

type PullRespPayload struct {
	TXPK TXPK `json:"txpk"`
}

PullRespPayload represents the downstream JSON data structure.

type PushACKPacket

type PushACKPacket struct {
	ProtocolVersion uint8
	RandomToken     uint16
}

PushACKPacket is used by the server to acknowledge immediately all the PUSH_DATA packets received.

func (PushACKPacket) MarshalBinary

func (p PushACKPacket) MarshalBinary() ([]byte, error)

MarshalBinary marshals the object in binary form.

func (*PushACKPacket) UnmarshalBinary

func (p *PushACKPacket) UnmarshalBinary(data []byte) error

UnmarshalBinary decodes the object from binary form.

type PushDataPacket

type PushDataPacket struct {
	ProtocolVersion uint8
	RandomToken     uint16
	GatewayMAC      lorawan.EUI64
	Payload         PushDataPayload
}

PushDataPacket type is used by the gateway mainly to forward the RF packets received, and associated metadata, to the server.

func (PushDataPacket) MarshalBinary

func (p PushDataPacket) MarshalBinary() ([]byte, error)

MarshalBinary marshals the object in binary form.

func (*PushDataPacket) UnmarshalBinary

func (p *PushDataPacket) UnmarshalBinary(data []byte) error

UnmarshalBinary decodes the object from binary form.

type PushDataPayload

type PushDataPayload struct {
	RXPK []RXPK `json:"rxpk,omitempty"`
	Stat *Stat  `json:"stat,omitempty"`
}

PushDataPayload represents the upstream JSON data structure.

type RSig

type RSig struct {
	Ant   uint8   `json:"ant"`   // Antenna number on which signal has been received
	Chan  uint8   `json:"chan"`  // Concentrator "IF" channel used for RX (unsigned integer)
	LSNR  float64 `json:"lsnr"`  // Lora SNR ratio in dB (signed float, 0.1 dB precision)
	RSSIC int16   `json:"rssic"` // RSSI in dBm of the channel (signed integer, 1 dB precision)
}

RSig contains the received signal information per antenna.

type RXPK

type RXPK struct {
	Time *CompactTime `json:"time"` // UTC time of pkt RX, us precision, ISO 8601 'compact' format (e.g. 2013-03-31T16:21:17.528002Z)
	Tmms *int64       `json:"tmms"` // GPS time of pkt RX, number of milliseconds since 06.Jan.1980
	Tmst uint32       `json:"tmst"` // Internal timestamp of "RX finished" event (32b unsigned)
	Freq float64      `json:"freq"` // RX central frequency in MHz (unsigned float, Hz precision)
	Brd  uint8        `json:"brd"`  // Concentrator board used for RX (unsigned integer)
	Chan uint8        `json:"chan"` // Concentrator "IF" channel used for RX (unsigned integer)
	RFCh uint8        `json:"rfch"` // Concentrator "RF chain" used for RX (unsigned integer)
	Stat int8         `json:"stat"` // CRC status: 1 = OK, -1 = fail, 0 = no CRC
	Modu string       `json:"modu"` // Modulation identifier "LORA" or "FSK"
	DatR DatR         `json:"datr"` // LoRa datarate identifier (eg. SF12BW500) || FSK datarate (unsigned, in bits per second)
	CodR string       `json:"codr"` // LoRa ECC coding rate identifier
	RSSI int16        `json:"rssi"` // RSSI in dBm (signed integer, 1 dB precision)
	LSNR float64      `json:"lsnr"` // Lora SNR ratio in dB (signed float, 0.1 dB precision)
	Size uint16       `json:"size"` // RF packet payload size in bytes (unsigned integer)
	Data string       `json:"data"` // Base64 encoded RF packet payload, padded
	RSig []RSig       `json:"rsig"` // Received signal information, per antenna (Optional)
}

RXPK contain a RF packet and associated metadata.

type Stat

type Stat struct {
	Time ExpandedTime `json:"time"` // UTC 'system' time of the gateway, ISO 8601 'expanded' format (e.g 2014-01-12 08:59:28 GMT)
	Lati *float64     `json:"lati"` // GPS latitude of the gateway in degree (float, N is +)
	Long *float64     `json:"long"` // GPS latitude of the gateway in degree (float, E is +)
	Alti *int32       `json:"alti"` // GPS altitude of the gateway in meter RX (integer)
	RXNb uint32       `json:"rxnb"` // Number of radio packets received (unsigned integer)
	RXOK uint32       `json:"rxok"` // Number of radio packets received with a valid PHY CRC
	RXFW uint32       `json:"rxfw"` // Number of radio packets forwarded (unsigned integer)
	ACKR float64      `json:"ackr"` // Percentage of upstream datagrams that were acknowledged
	DWNb uint32       `json:"dwnb"` // Number of downlink datagrams received (unsigned integer)
	TXNb uint32       `json:"txnb"` // Number of packets emitted (unsigned integer)
}

Stat contains the status of the gateway.

type TXACKPacket

type TXACKPacket struct {
	ProtocolVersion uint8
	RandomToken     uint16
	GatewayMAC      lorawan.EUI64
	Payload         *TXACKPayload
}

TXACKPacket is used by the gateway to send a feedback to the server to inform if a downlink request has been accepted or rejected by the gateway.

func (TXACKPacket) MarshalBinary

func (p TXACKPacket) MarshalBinary() ([]byte, error)

MarshalBinary marshals the object into binary form.

func (*TXACKPacket) UnmarshalBinary

func (p *TXACKPacket) UnmarshalBinary(data []byte) error

UnmarshalBinary decodes the object from binary form.

type TXACKPayload

type TXACKPayload struct {
	TXPKACK TXPKACK `json:"txpk_ack"`
}

TXACKPayload contains the TXACKPacket payload.

type TXPK

type TXPK struct {
	Imme bool    `json:"imme"`           // Send packet immediately (will ignore tmst & time)
	Tmst *uint32 `json:"tmst,omitempty"` // Send packet on a certain timestamp value (will ignore time)
	Tmms *int64  `json:"tmms,omitempty"` // Send packet at a certain GPS time (GPS synchronization required)
	Freq float64 `json:"freq"`           // TX central frequency in MHz (unsigned float, Hz precision)
	RFCh uint8   `json:"rfch"`           // Concentrator "RF chain" used for TX (unsigned integer)
	Powe uint8   `json:"powe"`           // TX output power in dBm (unsigned integer, dBm precision)
	Modu string  `json:"modu"`           // Modulation identifier "LORA" or "FSK"
	DatR DatR    `json:"datr"`           // LoRa datarate identifier (eg. SF12BW500) || FSK datarate (unsigned, in bits per second)
	CodR string  `json:"codr,omitempty"` // LoRa ECC coding rate identifier
	FDev uint16  `json:"fdev,omitempty"` // FSK frequency deviation (unsigned integer, in Hz)
	IPol bool    `json:"ipol"`           // Lora modulation polarization inversion
	Prea uint16  `json:"prea,omitempty"` // RF preamble size (unsigned integer)
	Size uint16  `json:"size"`           // RF packet payload size in bytes (unsigned integer)
	NCRC bool    `json:"ncrc,omitempty"` // If true, disable the CRC of the physical layer (optional)
	Data string  `json:"data"`           // Base64 encoded RF packet payload, padding optional
	Brd  uint8   `json:"brd"`            // Concentrator board used for RX (unsigned integer)
	Ant  uint8   `json:"ant"`            // Antenna number on which signal has been received
}

TXPK contains a RF packet to be emitted and associated metadata.

type TXPKACK

type TXPKACK struct {
	Error string `json:"error"`
}

TXPKACK contains the status information of the associated PULL_RESP packet.

Jump to

Keyboard shortcuts

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