Documentation ¶
Overview ¶
Package gw implements a generic gateway interface to Span. The gRPC command stream is realtively simple to implement but requires a bit of wiring that will be common for all gateway implementations and this package handles that. Implement the CommandHandler interface for new gateways to support more gateway types
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CommandHandler ¶
type CommandHandler interface { // UpdateConfig updates the gateway configuration. The returned ID is the mapping for the gateway // into another ID. On the initial call this ID might be blank UpdateConfig(localID string, config map[string]string) (string, error) // RemoveDevice removes a device from the gateway. The deviceID might be blank if the device isn't mapped // yet. If the device doesn't exist in the gatewy nil should be returned. RemoveDevice(localID string, deviceID string) error // UpdateDevice creates or updates a device on the gateway. If the device has an updated configuration // (f.e. updated configuration as a result of a change on the device) the updated config is returned as a // map of strings. If there is no updates to communicate back to Span the configuration is nil UpdateDevice(localID string, localDeviceID string, config map[string]string) (string, map[string]string, error) // DownstreamMessage sends a message to a device on the gateway DownstreamMessage(localID, localDeviceID, messageID string, payload []byte) error // UpstreamMessage sets a callback function for upstream messages UpstreamMessage(upstreamCb UpstreamMessageFunc) // Shutdown is an optional shut down call if the handler requires it. Shutdown() }
The CommandHandler interface handles the gateway commands
type GatewayProcess ¶
type GatewayProcess struct { Stream gateway.UserGatewayService_ControlStreamClient Commands CommandHandler // contains filtered or unexported fields }
GatewayProcess is the command processor for gateways
func Create ¶
func Create(config Parameters, handler CommandHandler) (*GatewayProcess, error)
Create creates a new gateway process, connects to the Span service and launches the command processing. The handler implements the actual gateway
func NewGatewayProcess ¶
func NewGatewayProcess(stateFile string, stream gateway.UserGatewayService_ControlStreamClient, commands CommandHandler) *GatewayProcess
NewGatewayProcess creates a new stream processor
func (*GatewayProcess) Run ¶
func (sp *GatewayProcess) Run() error
Run runs the stream processor. It will not return unless an error occurs
type GatewayState ¶
type GatewayState struct { GatewayID string `json:"gatewayId"` LocalID string `json:"localId"` IDMappings map[string]string `json:"deviceMapping"` // contains filtered or unexported fields }
GatewayState is a state object for the gateway. The state object keeps track of the device -> lora device ID mappings
func NewStateFromFile ¶
func NewStateFromFile(filename string) (*GatewayState, error)
NewStateFromFile reads the state from a file. If the file name is empty or if the file doesn't exist an empty state struct will be returned
func (*GatewayState) GetMapping ¶
func (g *GatewayState) GetMapping(deviceID string) string
GetMapping retrieves the mapping between the Span device ID and the internal ID
func (*GatewayState) GetReverseMapping ¶
func (g *GatewayState) GetReverseMapping(localID string) string
GetReverseMapping returns the device ID corresponding to the local ID
func (*GatewayState) RemoveMapping ¶
func (g *GatewayState) RemoveMapping(id string)
RemoveMapping removes a mapping between the Span device ID and the internal ID
func (*GatewayState) Save ¶
func (g *GatewayState) Save(filename string) error
Save writes the state to a file if the file name is set.
func (*GatewayState) SetMapping ¶
func (g *GatewayState) SetMapping(deviceID, otherID string)
SetMapping sets the ID mapping for the Span device ID to the gateway internal ID
type Parameters ¶
type Parameters struct { CertFile string `kong:"help='Client Certificate',required,file"` KeyFile string `kong:"help='Client key file',required,file"` StateFile string `kong:"help='State file for gateway',default=''"` SpanEndpoint string `kong:"help='Endpoint for the Span service',default='gw.lab5e.com:6674'"` }
Parameters holds the main command line parameters for the gateway interface