Documentation
¶
Index ¶
Constants ¶
const ( FlagProgenitive flags = 1 << iota // May have children FlagWantsHttpPort // HTTP port not optional )
Variables ¶
var Models = ModelMap{}
Functions ¶
func GenerateUf2s ¶
Types ¶
type Config ¶
type Config struct {
// Model is the device model name
Model string
// Flags see FlagXxxx
Flags flags
// The device state
State any
// The device's embedded static file system
FS *embed.FS
// Targets support by device
Targets []string
// PollPeriod is the device polling period. The default is 1 second.
// The range is [1..forever) seconds.
PollPeriod time.Duration
// BgColor is the device background color
BgColor string
// FgColor is the device forground (text, border) color
FgColor string
}
Config is the device model configuration
type Devicer ¶
type Devicer interface {
// GetConfig returns the device configuration
GetConfig() Config
// GetHandlers returns the device message Handlers
GetHandlers() Handlers
// Setup prepares the device for operation. Device hardware and other
// initializations are done here. Returning an error fails the device load.
Setup() error
// Poll services the device. Poll is called every Config.PollPeriod
// seconds. The Packet can be used to send a message.
Poll(*Packet)
// DemoSetup is DEMO mode Setup
DemoSetup() error
// DemoPoll is DEMO mode Poll
DemoPoll(*Packet)
}
Devicer is the device model interface. A device is a concrete Devicer.
type Handler ¶
type Handler[T any] struct { // Callback is called with packet containing type T message Callback func(pkt *Packet) }
Handler for message type T
type Packet ¶
type Packet struct {
// Dst is the device id of the destination device
Dst string
// Path identifies the message content. Path format is same as
// url.URL.Path, with the leading slash. e.g. /takeone.
Path string
// Msg is the packet payload. Use NoMsg for no message.
Msg json.RawMessage
}
Packet is the basic container for messages sent between devices.
func (*Packet) RouteDown ¶
func (p *Packet) RouteDown()
RouteDown routes the packet down to a downlink. Which downlink is determined by a lookup in the routing table for the "next-hop" downlink, the downlink which is towards the destination.
func (*Packet) RouteUp ¶
func (p *Packet) RouteUp()
RouteUp routes the packet up to:
Each listening session, where a session is an http(s) client (browser, etc) that has also opened, and is listening on, a websocket at /wsx.
The packet is transformed into an html snippet before being sent on the websocket to the client (see htmx, websockets). The packet path and the current session's view name the html template used for the transformation. The template name is in the format:
{path}-{view}.tmpl
For example, consider routing the packet with the message:
var msg = MsgClicked{Relay: 2, State: true} pkt.SetPath("/clicked").Marshal(&msg).RouteUp()
And say the current view is "overview". The template name is:
clicked-overview.tmpl
The template is executed and the resulting html snippet is sent on the websocket. Per htmx, the html snippet is swap by DOM id, so using a unique id in the template like:
<div id="{{uniq `relay`}}"> ... </div>
Each active uplink the device is dialed into. Each uplink is a websocket connected on /ws. The packet is JSON-encoded before sending on the websocket, and JSON-decoded by the receiving uplink device.