Documentation ¶
Index ¶
- Constants
- Variables
- type Client
- type CompactTime
- type DatR
- type ExpandedTime
- type GatewayStatsPacket
- type Mac
- type PacketType
- type PullACKPacket
- type PullDataPacket
- type PullRespPacket
- type PullRespPayload
- type PushACKPacket
- type PushDataPacket
- type PushDataPayload
- type RXInfo
- type RXPK
- type RXPacket
- type RXPacketBytes
- type Stat
- type TXACKPacket
- type TXACKPayload
- type TXInfo
- type TXPK
- type TXPKACK
- type TXPacket
- type TXPacketBytes
Constants ¶
const ( ProtocolVersion1 uint8 = 0x01 ProtocolVersion2 uint8 = 0x02 )
Protocol versions
Variables ¶
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 (*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) StatsChan ¶
func (c *Client) StatsChan() chan GatewayStatsPacket
StatsChan returns the channel containg the received gateway stats.
type CompactTime ¶
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 ¶
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 ¶
MarshalJSON implements the json.Marshaler interface.
func (*DatR) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
type ExpandedTime ¶
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 ¶
MarshalBinary implements encoding.BinaryMarshaler.
func (Mac) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*Mac) UnmarshalBinary ¶
UnmarshalBinary implements encoding.BinaryUnmarshaler.
func (*Mac) UnmarshalText ¶
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 ¶
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 ¶
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 ¶
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 RXPacketBytes ¶
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 TXPacketBytes ¶
TXPacketBytes contains the PHYPayload as []byte which should be send to the gateway. The JSON output is compatible with TXPacket.