Documentation ¶
Overview ¶
Package ws provides common interface for Web Socket front end.
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 ¶ added in v3.22.2
func ConcentratorTimeFromXTime(xTime int64) scheduling.ConcentratorTime
ConcentratorTimeFromXTime constructs the scheduling.ConcentratorTime associated with the provided XTime.
func ConcentratorTimeToXTime ¶ added in v3.22.2
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 ¶ added in v3.22.2
GetSessionID returns the session ID.
func GetSessionTimeSync ¶ added in v3.22.2
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 ¶ added in v3.22.2
SessionIDFromXTime constructs the session ID associated with the provided XTime.
func TimeFromGPSTime ¶ added in v3.22.2
TimeFromGPSTime constructs a time.Time from the provided GPS time in microseconds.
func TimeFromUnixSeconds ¶ added in v3.22.2
TimeFromUnixSeconds constructs a time.Time from the provided UNIX fractional timestamp.
func TimePtrFromGPSTime ¶ added in v3.22.2
TimePtrFromGPSTime constructs a *time.Time from the provided GPS time in microseconds. If the timestamp is 0, this function returns nil.
func TimePtrFromUnixSeconds ¶ added in v3.22.2
TimeFromUnixSeconds constructs a *time.Time from the provided UNIX fractional timestamp. If the timestamp is 0, this function returns nil.
func TimePtrFromUpInfo ¶ added in v3.22.2
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 ¶ added in v3.22.2
TimePtrToUpInfoTime constructs the RxTime and GPSTime from the provided *time.Time. If the time is nil, this function returns (0.0, 0).
func TimeToGPSTime ¶ added in v3.22.2
TimeToGPSTime contructs a GPS timestamp from the provided time.Time.
func TimeToUnixSeconds ¶ added in v3.22.2
TimeToUnixSeconds constructs a UNIX fractional timestamp from the provided time.Time.
func TimestampFromXTime ¶ added in v3.22.2
TimestampFromXTime constructs the concentrator timestamp associated with the provided XTime.
func UpdateSessionID ¶ added in v3.22.2
UpdateSessionID updates the session ID.
func UpdateSessionTimeSync ¶ added in v3.22.2
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 WS 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 { // 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, receivedAt time.Time) []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) ([]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) ([]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.