wbgo

package module
v0.0.0-...-d61f662 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2023 License: MIT Imports: 29 Imported by: 0

README

wbgo

Wiren Board MQTT abstraction layer for Go

Documentation

Index

Constants

View Source
const (
	RELOAD_DELAY                = 1000 * time.Millisecond
	DIRWATCHER_OP_LIST_CAPACITY = 128
	DIRWATCHER_OP_CHANGE        = dirWatcherOpType(iota)
	DIRWATCHER_OP_REMOVE
)
View Source
const (
	EVENT_QUEUE_LEN       = 100
	DEFAULT_POLL_INTERVAL = 5 * time.Second
	CONTROL_LIST_CAPACITY = 32

	DefaultWritability Writability = iota
	ForceReadOnly
	ForceWritable
)
View Source
const (
	DISCONNECT_WAIT_MS = 100
	TOKEN_QUEUE_LEN    = 512
)
View Source
const (
	RPC_MESSAGE_QUEUE_LEN = 32
	RPC_APP_PREFIX        = "/rpc/v1/"
	RPC_RESERVED_CODE_MIN = -32700
	RPC_RESERVED_CODE_MAX = -32000
)
View Source
const DEFERRED_CAPACITY = 256

Variables

View Source
var (
	Error *log.Logger
	Warn  *log.Logger
	Info  *log.Logger
	Debug *log.Logger
)

Functions

func DebuggingEnabled

func DebuggingEnabled() bool

func EnableMQTTDebugLog

func EnableMQTTDebugLog(use_syslog bool)

func GetStack

func GetStack() string

func IsSubpath

func IsSubpath(basepath, maybeSubpath string) bool

IsSubpath returns true if maybeSubpath is a subpath of basepath. It uses filepath to be compatible with os-dependent paths.

func MaybeInitProfiling

func MaybeInitProfiling(readyCh <-chan struct{})

func SetDebugLogger

func SetDebugLogger(logger *log.Logger, keep bool)

func SetDebuggingEnabled

func SetDebuggingEnabled(enable bool)

func Truename

func Truename(filePath string) (string, error)

Truename returns the shortest absolute pathname leading to the specified existing file. Note that a single file may have multiple hard links or be accessible via multiple bind mounts. Truename doesn't account for these situations.

func UseSyslog

func UseSyslog()

func Visit

func Visit(visitor interface{}, thing interface{}, prefix string, args ...interface{})

Types

type ContentTracker

type ContentTracker struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewContentTracker

func NewContentTracker() *ContentTracker

func (*ContentTracker) Track

func (tracker *ContentTracker) Track(key, path string) (bool, error)

type Control

type Control struct {
	Name        string
	Title       string
	Type        string
	Value       string
	Units       string
	Writability Writability
	HasMax      bool
	Max         float64
	Forget      bool
	Order       int
}

func (Control) GetType

func (c Control) GetType() string

FIXME: don't use 'type:units' notation for Type

func (Control) GetUnits

func (c Control) GetUnits() string

func (Control) Retain

func (c Control) Retain() bool

type DeferredList

type DeferredList struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewDeferredList

func NewDeferredList(executor func(func())) *DeferredList

func (*DeferredList) MaybeDefer

func (dl *DeferredList) MaybeDefer(thunk func())

func (*DeferredList) Ready

func (dl *DeferredList) Ready()

type DeviceBase

type DeviceBase struct {
	DevName  string
	DevTitle string
	Observer DeviceObserver
}

func (*DeviceBase) Name

func (dev *DeviceBase) Name() string

func (*DeviceBase) Observe

func (dev *DeviceBase) Observe(observer DeviceObserver)

func (*DeviceBase) SetTitle

func (dev *DeviceBase) SetTitle(title string)

func (*DeviceBase) Title

func (dev *DeviceBase) Title() string

type DeviceModel

type DeviceModel interface {
	Name() string
	Title() string
	Observe(observer DeviceObserver)
	// AcceptValue accepts the specified control value sent via an MQTT value topic
	// (not .../on). For local devices, that can be a retained value, for external
	// devices, the current control value
	AcceptValue(name, value string)
}

type DeviceObserver

type DeviceObserver interface {
	OnNewControl(dev LocalDeviceModel, control Control) string
	OnValue(dev DeviceModel, name, value string)
	OnError(dev DeviceModel, name, value string)
}

type DirWatcher

type DirWatcher struct {
	// contains filtered or unexported fields
}

func NewDirWatcher

func NewDirWatcher(pattern string, client DirWatcherClient) *DirWatcher

func (*DirWatcher) Load

func (dw *DirWatcher) Load(filePath string) error

func (*DirWatcher) SetDelay

func (dw *DirWatcher) SetDelay(delay time.Duration)

func (*DirWatcher) Stop

func (dw *DirWatcher) Stop()

type DirWatcherClient

type DirWatcherClient interface {
	LoadFile(path string) error
	LiveLoadFile(path string) error
	LiveRemoveFile(path string) error
}

type Driver

type Driver struct {
	// contains filtered or unexported fields
}

Driver transfers data between Model with MQTTClient

func NewDriver

func NewDriver(model Model, client MQTTClient) (drv *Driver)

func (*Driver) AcceptsExternalDevices

func (drv *Driver) AcceptsExternalDevices() bool

func (*Driver) AutoPoll

func (drv *Driver) AutoPoll() bool

func (*Driver) CallSync

func (drv *Driver) CallSync(thunk func())

func (*Driver) HandleMessageSync

func (drv *Driver) HandleMessageSync(thunk func())

func (*Driver) OnError

func (drv *Driver) OnError(dev DeviceModel, controlName, value string)

func (*Driver) OnNewControl

func (drv *Driver) OnNewControl(dev LocalDeviceModel, control Control) string

func (*Driver) OnNewDevice

func (drv *Driver) OnNewDevice(dev DeviceModel)

func (*Driver) OnValue

func (drv *Driver) OnValue(dev DeviceModel, controlName, value string)

func (*Driver) Poll

func (drv *Driver) Poll()

func (*Driver) PollInterval

func (drv *Driver) PollInterval() time.Duration

func (*Driver) RemoveDevice

func (drv *Driver) RemoveDevice(dev DeviceModel)

func (*Driver) SetAcceptsExternalDevices

func (drv *Driver) SetAcceptsExternalDevices(accepts bool)

func (*Driver) SetAutoPoll

func (drv *Driver) SetAutoPoll(autoPoll bool)

func (*Driver) SetPollInterval

func (drv *Driver) SetPollInterval(pollInterval time.Duration)

func (*Driver) Start

func (drv *Driver) Start() error

func (*Driver) Stop

func (drv *Driver) Stop()

func (*Driver) WhenReady

func (drv *Driver) WhenReady(thunk func())

type ExtendedModel

type ExtendedModel interface {
	Model
	AddExternalDevice(name string) (ExternalDeviceModel, error)
}

ExtendedModel is a Model that supports external devices

type ExternalDeviceModel

type ExternalDeviceModel interface {
	DeviceModel
	SetTitle(title string)
	AcceptControlType(name, controlType string)
	AcceptControlRange(name string, max float64)
}

type LocalDeviceModel

type LocalDeviceModel interface {
	DeviceModel
	// AcceptOnValue accepts the specified control value sent via an MQTT .../on topic
	// for the target device and returns true if the value should be automatically
	// echoed back
	AcceptOnValue(name, value string) bool
	IsVirtual() bool
}

type MQTTClient

type MQTTClient interface {
	WaitForReady() <-chan struct{}
	Start()
	Stop()
	Publish(message MQTTMessage)
	Subscribe(callback MQTTMessageHandler, topics ...string)
	Unsubscribe(topics ...string)
}

type MQTTMessage

type MQTTMessage struct {
	Topic    string
	Payload  string
	QoS      byte
	Retained bool
}

type MQTTMessageHandler

type MQTTMessageHandler func(message MQTTMessage)

type MQTTRPCServer

type MQTTRPCServer struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewMQTTRPCServer

func NewMQTTRPCServer(appName string, mqttClient MQTTClient) (server *MQTTRPCServer)

func (*MQTTRPCServer) Register

func (server *MQTTRPCServer) Register(rcvr interface{}) error

Register publishes in the server the set of methods of the receiver value that satisfy the following conditions:

  • exported method
  • two arguments, both of exported type
  • the second argument is a pointer
  • one return value, of type error

It returns an error if the receiver is not an exported type or has no suitable methods. It also logs the error using package log. The client accesses each method using a string of the form "Type.Method", where Type is the receiver's concrete type.

func (*MQTTRPCServer) RegisterName

func (server *MQTTRPCServer) RegisterName(name string, rcvr interface{}) error

RegisterName is like Register but uses the provided name for the type instead of the receiver's concrete type.

func (*MQTTRPCServer) Start

func (server *MQTTRPCServer) Start()

func (*MQTTRPCServer) Stop

func (server *MQTTRPCServer) Stop()

type MQTTSubscriptionMap

type MQTTSubscriptionMap map[string][]MQTTMessageHandler

type Model

type Model interface {
	Start() error
	Stop()
	Observe(observer ModelObserver)
	Poll()
}

type ModelBase

type ModelBase struct {
	Observer ModelObserver
}

func (*ModelBase) Observe

func (model *ModelBase) Observe(observer ModelObserver)

func (*ModelBase) Poll

func (model *ModelBase) Poll()

func (*ModelBase) Stop

func (model *ModelBase) Stop()

type ModelObserver

type ModelObserver interface {
	CallSync(thunk func())
	WhenReady(thunk func())
	RemoveDevice(dev DeviceModel)
	OnNewDevice(dev DeviceModel)
}

type PahoMQTTClient

type PahoMQTTClient struct {
	// contains filtered or unexported fields
}

func NewPahoMQTTClient

func NewPahoMQTTClient(server, clientID string, waitForRetained bool) (client *PahoMQTTClient)

func (*PahoMQTTClient) Publish

func (client *PahoMQTTClient) Publish(message MQTTMessage)

func (*PahoMQTTClient) Start

func (client *PahoMQTTClient) Start()

func (*PahoMQTTClient) Stop

func (client *PahoMQTTClient) Stop()

func (*PahoMQTTClient) Subscribe

func (client *PahoMQTTClient) Subscribe(callback MQTTMessageHandler, topics ...string)

func (*PahoMQTTClient) Unsubscribe

func (client *PahoMQTTClient) Unsubscribe(topics ...string)

func (*PahoMQTTClient) WaitForReady

func (client *PahoMQTTClient) WaitForReady() <-chan struct{}

type RPCError

type RPCError interface {
	error
	ErrorCode() int32
}

type RTimer

type RTimer interface {
	// embed generic Timer here
	Timer

	// Reset changes the timer to expire after new duration d
	Reset(d time.Duration)
}

RTimer is reusable Timer with Reset method

type RealRTimer

type RealRTimer struct {
	RealTimer
}

RealRTimer incapsulates a real time.Timer with Reset() method

func NewRealRTimer

func NewRealRTimer(d time.Duration) *RealRTimer

func (*RealRTimer) Reset

func (timer *RealRTimer) Reset(d time.Duration)

Reset resets an existing timer or creates a new one with given duration

type RealTicker

type RealTicker struct {
	// contains filtered or unexported fields
}

RealTicker incapsulates a real time.Ticker

func NewRealTicker

func NewRealTicker(d time.Duration) *RealTicker

func (*RealTicker) GetChannel

func (ticker *RealTicker) GetChannel() <-chan time.Time

func (*RealTicker) Stop

func (ticker *RealTicker) Stop()

type RealTimer

type RealTimer struct {
	// contains filtered or unexported fields
}

RealTimer incapsulates a real time.Ticker

func NewRealTimer

func NewRealTimer(d time.Duration) *RealTimer

func (*RealTimer) GetChannel

func (timer *RealTimer) GetChannel() <-chan time.Time

func (*RealTimer) Stop

func (timer *RealTimer) Stop()

type Timer

type Timer interface {
	// GetChannel retrieves a channel that signals timer expiration
	GetChannel() <-chan time.Time

	// Stop stops the timer
	Stop()
}

Timer is fakeable timer interface

type Writability

type Writability int

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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