Documentation ¶
Overview ¶
Package semtechws implements a common interface for Semtech web socket frontends.
Index ¶
- Constants
- Variables
- func ConcentratorTimeFromXTime(xTime int64) scheduling.ConcentratorTime
- func ConcentratorTimeToXTime(id int32, t scheduling.ConcentratorTime) int64
- func GetSessionID(ctx context.Context) (int32, bool)
- func GetSessionTimeSync(ctx context.Context) (enabled bool, ok bool)
- func New(ctx context.Context, server io.Server, formatter Formatter, cfg Config) (*web.Server, error)
- func NewContextWithSession(ctx context.Context, session *Session) context.Context
- func SessionIDFromXTime(xTime int64) int32
- func TimeFromGPSTime(t int64) time.Time
- func TimeFromUnixSeconds(tf float64) time.Time
- func TimePtrFromGPSTime(t int64) *time.Time
- func TimePtrFromUnixSeconds(tf float64) *time.Time
- func TimePtrFromUpInfo(gpsTime int64, rxTime float64) *time.Time
- func TimePtrToUpInfoTime(t *time.Time) (float64, int64)
- func TimeToGPSTime(t time.Time) int64
- func TimeToUnixSeconds(t time.Time) float64
- func TimestampFromXTime(xTime int64) uint32
- func UpdateSessionID(ctx context.Context, id int32)
- func UpdateSessionTimeSync(ctx context.Context, b bool)
- type Config
- type Endpoints
- type Formatter
- type ServerInfo
- type Session
Constants ¶
const (
// XTime48BitLSBMask is the mask used to extract the lower 48 bits of the XTime.
XTime48BitLSBMask = 0xFFFFFFFFFFFF
)
Variables ¶
var DefaultConfig = Config{ UseTrafficTLSAddress: false, WSPingInterval: 30 * time.Second, MissedPongThreshold: 2, TimeSyncInterval: 200 * time.Second, AllowUnauthenticated: false, }
DefaultConfig contains the default configuration.
Functions ¶
func ConcentratorTimeFromXTime ¶
func ConcentratorTimeFromXTime(xTime int64) scheduling.ConcentratorTime
ConcentratorTimeFromXTime constructs the scheduling.ConcentratorTime associated with the provided XTime.
func ConcentratorTimeToXTime ¶
func ConcentratorTimeToXTime(id int32, t scheduling.ConcentratorTime) int64
ConcentratorTimeToXTime contructs the XTime associated with the provided session ID and concentrator timestamp. Bytes 0-5 (6 bytes = 48 bits) are used for the timestamp. Bytes 6-8 are returned unmodified to the gateway from the xtime read on the latest uplink.
func GetSessionID ¶
GetSessionID returns the session ID.
func GetSessionTimeSync ¶
GetSessionTimeSync returns the session time sync.
func New ¶
func New(ctx context.Context, server io.Server, formatter Formatter, cfg Config) (*web.Server, error)
New creates a new WebSocket frontend.
func NewContextWithSession ¶
NewContextWithSession returns a new context with the session.
func SessionIDFromXTime ¶
SessionIDFromXTime constructs the session ID associated with the provided XTime.
func TimeFromGPSTime ¶
TimeFromGPSTime constructs a time.Time from the provided GPS time in microseconds.
func TimeFromUnixSeconds ¶
TimeFromUnixSeconds constructs a time.Time from the provided UNIX fractional timestamp.
func TimePtrFromGPSTime ¶
TimePtrFromGPSTime constructs a *time.Time from the provided GPS time in microseconds. If the timestamp is 0, this function returns nil.
func TimePtrFromUnixSeconds ¶
TimePtrFromUnixSeconds constructs a *time.Time from the provided UNIX fractional timestamp. If the timestamp is 0, this function returns nil.
func TimePtrFromUpInfo ¶
TimePtrFromUpInfo contructs a *time.Time from the provided uplink metadata information. The GPS timestamp (microseconds) is used if present, then the RxTime. The function returns nil if both timestamps are unavailable.
func TimePtrToUpInfoTime ¶
TimePtrToUpInfoTime constructs the RxTime and GPSTime from the provided *time.Time. If the time is nil, this function returns (0.0, 0).
func TimeToGPSTime ¶
TimeToGPSTime contructs a GPS timestamp from the provided time.Time.
func TimeToUnixSeconds ¶
TimeToUnixSeconds constructs a UNIX fractional timestamp from the provided time.Time.
func TimestampFromXTime ¶
TimestampFromXTime constructs the concentrator timestamp associated with the provided XTime.
func UpdateSessionID ¶
UpdateSessionID updates the session ID.
func UpdateSessionTimeSync ¶
UpdateSessionTimeSync updates the session time sync.
Types ¶
type Config ¶
type Config struct { UseTrafficTLSAddress bool `name:"use-traffic-tls-address" description:"Use WSS for the traffic address regardless of the TLS setting"` WSPingInterval time.Duration `name:"ws-ping-interval" description:"Interval to send websocket ping messages"` MissedPongThreshold int `` /* 163-byte string literal not displayed */ TimeSyncInterval time.Duration `name:"time-sync-interval" description:"Interval to send time transfer messages"` AllowUnauthenticated bool `name:"allow-unauthenticated" description:"Allow unauthenticated connections"` }
Config defines the LoRa Basics Station configuration of the Gateway Server.
type Formatter ¶
type Formatter interface { // ID returns the ID of the formatter. ID() string // Endpoints fetches the connection endpoints for the protocol. Endpoints() Endpoints // HandleConnectionInfo handles connection information requests from web socket based protocols. // This function returns a byte stream that contains connection information (ex: scheme, host, port etc) or an error if applicable. HandleConnectionInfo( ctx context.Context, raw []byte, server io.Server, serverInfo ServerInfo, assertAuth func(context.Context, *ttnpb.GatewayIdentifiers) error, ) []byte // HandleUp handles upstream messages from web socket based gateways. // This function optionally returns a byte stream to be sent as response to the upstream message. HandleUp( ctx context.Context, raw []byte, ids *ttnpb.GatewayIdentifiers, conn *io.Connection, receivedAt time.Time, tokens *io.DownlinkTokens, ) ([]byte, error) // FromDownlink generates a downlink byte stream that can be sent over the WS connection. FromDownlink( ctx context.Context, down *ttnpb.DownlinkMessage, bandID string, dlTime time.Time, tokens *io.DownlinkTokens, ) ([]byte, error) // TransferTime generates a spurious time transfer message for a particular server time. TransferTime( ctx context.Context, serverTime time.Time, gpsTime *time.Time, concentratorTime *scheduling.ConcentratorTime, ) ([]byte, error) }
Formatter abstracts messages to/from websocket based gateways.
type ServerInfo ¶
ServerInfo contains information on the WebSocket server.
type Session ¶
Session contains the session state for a single gateway.
func SessionFromContext ¶
SessionFromContext returns a new session from the context. The session value can be modified by the caller.