udp

package
v0.0.0-...-60b8695 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const CompactFormat = "2006-01-02T15:04:05.999999Z07:00"

CompactFormat formats a time as ISO 8601 'compact' with µs precision

View Source
const ExpandedFormat = "2006-01-02 15:04:05 MST"

ExpandedFormat formats a time as ISO 8601 'expanded'

Variables

This section is empty.

Functions

func FromGatewayUp

func FromGatewayUp(up *ttnpb.GatewayUp) (rxs []*RxPacket, stat *Stat, ack *TxPacketAck)

FromGatewayUp converts the upstream message to the UDP format.

func ToDownlinkMessage

func ToDownlinkMessage(tx *TxPacket) (*ttnpb.DownlinkMessage, error)

ToDownlinkMessage converts the UDP format to a downlink message.

func ToGatewayUp

func ToGatewayUp(data Data, md UpstreamMetadata) (*ttnpb.GatewayUp, error)

ToGatewayUp converts the UDP message to a gateway upstream message.

Types

type CompactTime

type CompactTime time.Time

CompactTime is a time.Time that is encoded as ISO 8601 'compact' format

func (CompactTime) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface.

func (*CompactTime) UnmarshalJSON

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

UnmarshalJSON implements the json.Unmarshaler interface.

type Data

type Data struct {
	RxPacket    []*RxPacket  `json:"rxpk,omitempty"`
	Stat        *Stat        `json:"stat,omitempty"`
	TxPacket    *TxPacket    `json:"txpk,omitempty"`
	TxPacketAck *TxPacketAck `json:"txpk_ack,omitempty"`
}

Data contains a LoRaWAN packet

type ExpandedTime

type ExpandedTime time.Time

ExpandedTime is a time.Time that is encoded as ISO 8601 'expanded' format

func (ExpandedTime) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface.

func (*ExpandedTime) UnmarshalJSON

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

UnmarshalJSON implements the json.Unmarshaler interface.

type Packet

type Packet struct {
	GatewayAddr *net.UDPAddr
	ReceivedAt  time.Time

	ProtocolVersion ProtocolVersion
	Token           [2]byte
	PacketType      PacketType
	GatewayEUI      *types.EUI64
	Data            *Data
}

Packet struct

func (Packet) BuildAck

func (p Packet) BuildAck() (Packet, error)

BuildAck builds the corresponding Ack back to the gateway. If the received packet does not require an Ack, the function returns nil without an error.

func (Packet) MarshalBinary

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

MarshalBinary implements the encoding.BinaryMarshaler

func (*Packet) UnmarshalBinary

func (p *Packet) UnmarshalBinary(b []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler

type PacketType

type PacketType uint8

PacketType of the packet

const (
	PushData PacketType = iota
	PushAck
	PullData
	PullResp
	PullAck
	TxAck
)

PacketTypes that we know

func (PacketType) HasData

func (p PacketType) HasData() bool

HasData returns true iff a packet of this type has a Data field

func (PacketType) HasGatewayEUI

func (p PacketType) HasGatewayEUI() bool

HasGatewayEUI returns true iff a packet of this type has a GatewayEUI field

func (PacketType) String

func (p PacketType) String() string

String implements the fmt.Stringer interface

type ProtocolVersion

type ProtocolVersion uint8

ProtocolVersion of the forwarder

const (
	Version1 ProtocolVersion = 0x01
	Version2 ProtocolVersion = 0x02
)

ProtocolVersions that we know

type RSig

type RSig struct {
	Ant    uint8   `json:"ant"`    // Antenna number on which signal has been received
	Chan   uint    `json:"chan"`   // Concentrator "IF" channel used for Rx (unsigned integer)
	RSSIC  int     `json:"rssic"`  // RSSI in dBm of the channel (signed integer, 1 dB precision)
	RSSIS  *int    `json:"rssis"`  // RSSI in dBm of the signal (signed integer, 1 dB precision) (Optional)
	RSSISD *uint   `json:"rssisd"` // Standard deviation of RSSI during preamble (unsigned integer) (Optional)
	LSNR   float64 `json:"lsnr"`   // Lora SNR ratio in dB (signed float, 0.1 dB precision)
	ETime  string  `json:"etime"`  // Encrypted fine timestamp, ns precision [0..999999999] (Optional)
	FTime  *uint32 `json:"ftime"`  // Fine timestamp, ns precision [0..999999999] (Optional)
	FOff   int32   `json:"foff"`   // Frequency offset in Hz [-125kHz..+125Khz] (Optional)
}

RSig contains the metadata associated with the received signal

type RxPacket

type RxPacket struct {
	Time *CompactTime `json:"time,omitempty"` // UTC time of pkt Rx, us precision, ISO 8601 'compact' format
	Tmms *uint64      `json:"tmms,omitempty"` // 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)
	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 datarate.DR  `json:"datr"`           // LoRa datarate or FSK datarate
	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)
	Brd  uint         `json:"brd"`            // Concentrator board used for Rx (unsigned integer)
	Aesk uint         `json:"aesk"`           // AES key index used for encrypting fine timestamps (unsigned integer)
}

RxPacket contains a Rx message

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)
	Boot *ExpandedTime `json:"boot,omitempty"` // UTC 'boot' time of the gateway, ISO 8601 'expanded' format (e.g 2014-01-12 08:59:28 GMT)
	Lati *float64      `json:"lati,omitempty"` // GPS latitude of the gateway in degree (float, N is +)
	Long *float64      `json:"long,omitempty"` // GPS latitude of the gateway in degree (float, E is +)
	Alti *int32        `json:"alti,omitempty"` // 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)
	LMOK *uint32       `json:"lmok,omitempty"` // Number of packets received from link testing mote, with CRC OK (unsigned inteter)
	LMST *uint32       `json:"lmst,omitempty"` // Sequence number of the first packet received from link testing mote (unsigned integer)
	LMNW *uint32       `json:"lmnw,omitempty"` // Sequence number of the last packet received from link testing mote (unsigned integer)
	LPPS *uint32       `json:"lpps,omitempty"` // Number of lost PPS pulses (unsigned integer)
	Temp *float32      `json:"temp,omitempty"` // Temperature of the Gateway (signed float)
	FPGA *uint32       `json:"fpga,omitempty"` // Version of Gateway FPGA (unsigned integer)
	DSP  *uint32       `json:"dsp,omitempty"`  // Version of Gateway DSP software (unsigned interger)
	HAL  *string       `json:"hal,omitempty"`  // Version of Gateway driver (format X.X.X)
}

Stat contains a status message

type TxError

type TxError string

TxError is returned in the TxPacketAck

var (
	// TxErrNone is returned if packet has been programmed for downlink
	TxErrNone TxError = "NONE"
	// TxErrTooLate is returned if packet rejected because it was already too late to program this packet for downlink
	TxErrTooLate TxError = "TOO_LATE"
	// TxErrTooEarly is returned if packet rejected because downlink packet timestamp is too much in advance
	TxErrTooEarly TxError = "TOO_EARLY"
	// TxErrCollisionPacket is returned if packet rejected because there was already a packet programmed in requested timeframe
	TxErrCollisionPacket TxError = "COLLISION_PACKET"
	// TxErrCollisionBeacon is returned if packet rejected because there was already a beacon planned in requested timeframe
	TxErrCollisionBeacon TxError = "COLLISION_BEACON"
	// TxErrTxFreq is returned if packet rejected because requested frequency is not supported by Tx RF chain
	TxErrTxFreq TxError = "TX_FREQ"
	// TxErrTxPower is returned if packet rejected because requested power is not supported by gateway
	TxErrTxPower TxError = "TX_POWER"
	// TxErrGPSUnlocked is returned if packet rejected because GPS is unlocked, so GPS timestamp cannot be used
	TxErrGPSUnlocked TxError = "GPS_UNLOCKED"
)

type TxPacket

type TxPacket 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 *uint64      `json:"tmms,omitempty"` // Send packet at a certain GPS time (GPS synchronization required)
	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)
	Brd  uint8        `json:"brd,omitempty"`  // Concentrator board used for Tx (unsigned integer)
	Ant  uint8        `json:"ant,omitempty"`  // Concentrator antenna used for Tx (unsigned integer)
	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 datarate.DR  `json:"datr"`           // LoRa datarate or FSK datarate
	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
}

TxPacket contains a Tx message

func FromDownlinkMessage

func FromDownlinkMessage(msg *ttnpb.DownlinkMessage) (*TxPacket, error)

FromDownlinkMessage converts to the downlink message to the UDP format.

func (*TxPacket) UnmarshalJSON

func (p *TxPacket) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

type TxPacketAck

type TxPacketAck struct {
	Error TxError `json:"error"`
}

TxPacketAck contains a Tx acknowledgment packet

type UpstreamMetadata

type UpstreamMetadata struct {
	ID ttnpb.GatewayIdentifiers
	IP string
}

UpstreamMetadata related to an uplink.

Jump to

Keyboard shortcuts

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