gateway

package
v0.0.0-...-3a83b89 Latest Latest
Warning

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

Go to latest
Published: May 12, 2017 License: MIT Imports: 14 Imported by: 1

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 Client

type Client struct {
	CheckCrc bool
	// contains filtered or unexported fields
}

Client implements a Semtech gateway client/backend.

func NewClient

func NewClient(bind string, onNew func(Mac) error, onDelete func(Mac) error) (*Client, error)

NewClient creates a new Client.

func (*Client) Close

func (c *Client) Close() error

Close closes the client.

func (*Client) RXPacketChan

func (c *Client) RXPacketChan() chan RXPacketBytes

RXPacketChan returns the channel containing the received RX packets.

func (*Client) Send

func (c *Client) Send(txPacket TXPacketBytes) error

Send sends the given packet to the gateway.

func (*Client) SetLogger

func (c *Client) SetLogger(logger *log.Logger)

func (*Client) StatsChan

func (c *Client) StatsChan() chan GatewayStatsPacket

StatsChan returns the channel containg the received gateway stats.

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 GatewayStatsPacket

type GatewayStatsPacket struct {
	MAC                 Mac                    `json:"mac"`
	Time                time.Time              `json:"time,omitempty"`
	Latitude            float64                `json:"latitude"`
	Longitude           float64                `json:"longitude"`
	Altitude            float64                `json:"altitude"`
	RXPacketsReceived   int                    `json:"rxPacketsReceived"`
	RXPacketsReceivedOK int                    `json:"rxPacketsReceivedOK"`
	TXPacketsEmitted    int                    `json:"txPacketsEmitted"`
	CustomData          map[string]interface{} `json:"customData"` // custom fields defined by alternative packet_forwarder versions (e.g. TTN sends platform, contactEmail, and description)
}

GatewayStatsPacket contains the information of a gateway.

type Mac

type Mac [8]byte

64 bit MacAddress of Gateway

func (Mac) MarshalBinary

func (m Mac) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler.

func (Mac) MarshalText

func (m Mac) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (*Mac) Scan

func (m *Mac) Scan(src interface{}) error

Scan implements sql.Scanner.

func (Mac) String

func (m Mac) String() string

String implement fmt.Stringer.

func (*Mac) UnmarshalBinary

func (m *Mac) UnmarshalBinary(data []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler.

func (*Mac) UnmarshalText

func (m *Mac) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

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      Mac
	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 RXInfo

type RXInfo struct {
	MAC       Mac           `json:"mac"`            // MAC address of the gateway
	Time      time.Time     `json:"time,omitempty"` // receive time
	Timestamp uint32        `json:"timestamp"`      // gateway internal receive timestamp with microsecond precision, will rollover every ~ 72 minutes
	Frequency int           `json:"frequency"`      // frequency in Hz
	Channel   int           `json:"channel"`        // concentrator IF channel used for RX
	RFChain   int           `json:"rfChain"`        // RF chain used for RX
	CRCStatus int           `json:"crcStatus"`      // 1 = OK, -1 = fail, 0 = no CRC
	CodeRate  string        `json:"codeRate"`       // ECC code rate
	RSSI      int           `json:"rssi"`           // RSSI in dBm
	LoRaSNR   float64       `json:"loRaSNR"`        // LoRa signal-to-noise ratio in dB
	Size      int           `json:"size"`           // packet payload size
	DataRate  band.DataRate `json:"dataRate"`       // RX datarate (either LoRa or FSK)
}

RXInfo contains the RX information.

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)
	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)
	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
}

RXPK contain a RF packet and associated metadata.

type RXPacket

type RXPacket struct {
	RXInfo     RXInfo `json:"rxInfo"`
	PHYPayload []byte `json:"phyPayload"`
}

RXPacket contains the PHYPayload received from the gateway.

type RXPacketBytes

type RXPacketBytes struct {
	RXInfo     RXInfo `json:"rxInfo"`
	PHYPayload []byte `json:"phyPayload"`
}

RXPacketBytes contains the PHYPayload as []byte received from the gateway. The JSON output is compatible with RXPacket.

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)
	Pfrm string       `json:"pfrm"` // Platform definition, max 24 chars
	Mail string       `json:"mail"` // Email of gateway operator, max 40 chars
	Desc string       `json:"desc"` // Public description of this device, max 64 chars
}

Stat contains the status of the gateway.

type TXACKPacket

type TXACKPacket struct {
	ProtocolVersion uint8
	RandomToken     uint16
	GatewayMAC      Mac
	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 TXInfo

type TXInfo struct {
	MAC         Mac           `json:"mac"`         // MAC address of the gateway
	Immediately bool          `json:"immediately"` // send the packet immediately (ignore Time)
	Timestamp   uint32        `json:"timestamp"`   // gateway internal receive timestamp with microsecond precision, will rollover every ~ 72 minutes
	Frequency   int           `json:"frequency"`   // frequency in Hz
	Power       int           `json:"power"`       // TX power to use in dBm
	DataRate    band.DataRate `json:"dataRate"`    // TX datarate (either LoRa or FSK)
	CodeRate    string        `json:"codeRate"`    // ECC code rate
	IPol        *bool         `json:"iPol"`        // when left nil, the gateway-bridge will use the default (true for LoRa modulation)
}

TXInfo contains the information used for TX.

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)
	Time *CompactTime `json:"time,omitempty"` // Send packet at a certain 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
}

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.

type TXPacket

type TXPacket struct {
	TXInfo     TXInfo `json:"txInfo"`
	PHYPayload []byte `json:"phyPayload"`
}

TXPacket contains the PHYPayload which should be send to the gateway.

type TXPacketBytes

type TXPacketBytes struct {
	TXInfo     TXInfo `json:"txInfo"`
	PHYPayload []byte `json:"phyPayload"`
}

TXPacketBytes contains the PHYPayload as []byte which should be send to the gateway. The JSON output is compatible with TXPacket.

Directories

Path Synopsis
Package band provides band specific defaults and configuration.
Package band provides band specific defaults and configuration.

Jump to

Keyboard shortcuts

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