Documentation ¶
Index ¶
- Constants
- Variables
- func ParseTopic(topic string) (string, error)
- func Run(handle func(Context) error)
- type AccessConfig
- type Context
- type CustomAccessConfig
- type CustomVisitor
- type DeltaCallback
- type DeviceInfo
- type DeviceProperty
- type DeviceShadow
- type DmCtx
- func (c *DmCtx) Close() error
- func (c *DmCtx) GetAccessConfig() map[string]AccessConfig
- func (c *DmCtx) GetAllDevices() []DeviceInfo
- func (c *DmCtx) GetDeviceAccessConfig(device *DeviceInfo) (*AccessConfig, error)
- func (c *DmCtx) GetDeviceProperties(info *DeviceInfo) (*DeviceShadow, error)
- func (c *DmCtx) GetDevicePropertiesConfig(device *DeviceInfo) ([]DeviceProperty, error)
- func (c *DmCtx) GetDriverConfig() string
- func (c *DmCtx) GetPropertiesConfig() map[string][]DeviceProperty
- func (c *DmCtx) Offline(info *DeviceInfo) error
- func (c *DmCtx) Online(info *DeviceInfo) error
- func (c *DmCtx) RegisterDeltaCallback(cb DeltaCallback) error
- func (c *DmCtx) RegisterEventCallback(cb EventCallback) error
- func (c *DmCtx) ReportDeviceProperties(info *DeviceInfo, report v1.Report) error
- func (c *DmCtx) Start()
- type Event
- type EventCallback
- type ModbusAccessConfig
- type ModbusVisitor
- type OpcuaAccessConfig
- type OpcuaAuth
- type OpcuaCertificate
- type OpcuaSecurity
- type OpcuaVisitor
- type PropertyVisitor
- type RtuConfig
- type TcpConfig
- type Topic
Constants ¶
View Source
const ( DefaultAccessConf = "etc/baetyl/access.yml" DefaultPropsConf = "etc/baetyl/props.yml" DefaultDriverConf = "etc/baetyl/conf.yml" KeyDevice = "device" KeyStatus = "status" OnlineStatus = "online" OfflineStatus = "offline" TypeReportEvent = "report" )
View Source
const ( TypeInt16 = "int16" TypeInt32 = "int32" TypeInt64 = "int64" TypeFloat32 = "float32" TypeFloat64 = "float64" TypeBool = "bool" TypeString = "string" )
View Source
const (
DeviceTopicRe = "\\$baetyl/device/(.+)/(.+)"
)
Variables ¶
View Source
var ( ErrInvalidMessage = errors.New("invalid device message") ErrInvalidChannel = errors.New("invalid channel") ErrResponseChannelNotExist = errors.New("response channel not exist") ErrAccessConfigNotExist = errors.New("access config not exist") ErrPropsConfigNotExist = errors.New("properties config not exist") ErrDeviceNotExist = errors.New("device not exist") ErrTypeNotSupported = errors.New("type not supported") )
Functions ¶
func ParseTopic ¶ added in v2.1.8
Types ¶
type AccessConfig ¶ added in v2.1.45
type AccessConfig struct { Modbus *ModbusAccessConfig `yaml:"modbus,omitempty" json:"modbus,omitempty"` Opcua *OpcuaAccessConfig `yaml:"opcua,omitempty" json:"opcua,omitempty"` Custom *CustomAccessConfig `yaml:"custom,omitempty" json:"custom,omitempty"` }
func (*AccessConfig) UnmarshalYAML ¶ added in v2.1.45
func (a *AccessConfig) UnmarshalYAML(unmarshal func(interface{}) error) error
type Context ¶
type Context interface { context.Context GetAllDevices() []DeviceInfo ReportDeviceProperties(*DeviceInfo, v1.Report) error GetDeviceProperties(device *DeviceInfo) (*DeviceShadow, error) RegisterDeltaCallback(cb DeltaCallback) error RegisterEventCallback(cb EventCallback) error Online(device *DeviceInfo) error Offline(device *DeviceInfo) error GetDriverConfig() string GetAccessConfig() map[string]AccessConfig GetDeviceAccessConfig(device *DeviceInfo) (*AccessConfig, error) GetPropertiesConfig() map[string][]DeviceProperty GetDevicePropertiesConfig(device *DeviceInfo) ([]DeviceProperty, error) Start() io.Closer }
func NewContext ¶
type CustomAccessConfig ¶ added in v2.1.45
type CustomAccessConfig string
type CustomVisitor ¶ added in v2.1.26
type CustomVisitor string
type DeltaCallback ¶
type DeltaCallback func(*DeviceInfo, v1.Delta) error
type DeviceInfo ¶
type DeviceProperty ¶ added in v2.1.26
type DeviceProperty struct { Name string `yaml:"name,omitempty" json:"name,omitempty"` Type string `yaml:"type,omitempty" json:"type,omitempty" validate:"regexp=^(int16|int32|int64|float32|float64|string|bool)?$"` Mode string `yaml:"mode,omitempty" json:"mode,omitempty" validate:"regexp=^(ro|rw)?$"` Visitor PropertyVisitor `yaml:"visitor,omitempty" json:"visitor,omitempty"` }
type DeviceShadow ¶
type DmCtx ¶
func (*DmCtx) GetAccessConfig ¶ added in v2.1.43
func (c *DmCtx) GetAccessConfig() map[string]AccessConfig
func (*DmCtx) GetAllDevices ¶
func (c *DmCtx) GetAllDevices() []DeviceInfo
func (*DmCtx) GetDeviceAccessConfig ¶ added in v2.1.24
func (c *DmCtx) GetDeviceAccessConfig(device *DeviceInfo) (*AccessConfig, error)
func (*DmCtx) GetDeviceProperties ¶
func (c *DmCtx) GetDeviceProperties(info *DeviceInfo) (*DeviceShadow, error)
func (*DmCtx) GetDevicePropertiesConfig ¶ added in v2.1.43
func (c *DmCtx) GetDevicePropertiesConfig(device *DeviceInfo) ([]DeviceProperty, error)
func (*DmCtx) GetDriverConfig ¶
func (*DmCtx) GetPropertiesConfig ¶ added in v2.1.43
func (c *DmCtx) GetPropertiesConfig() map[string][]DeviceProperty
func (*DmCtx) Offline ¶
func (c *DmCtx) Offline(info *DeviceInfo) error
func (*DmCtx) Online ¶
func (c *DmCtx) Online(info *DeviceInfo) error
func (*DmCtx) RegisterDeltaCallback ¶
func (c *DmCtx) RegisterDeltaCallback(cb DeltaCallback) error
func (*DmCtx) RegisterEventCallback ¶
func (c *DmCtx) RegisterEventCallback(cb EventCallback) error
func (*DmCtx) ReportDeviceProperties ¶
func (c *DmCtx) ReportDeviceProperties(info *DeviceInfo, report v1.Report) error
type Event ¶ added in v2.1.24
type Event struct { Type string `yaml:"type,omitempty" json:"type,omitempty"` Payload interface{} `yaml:"payload,omitempty" json:"payload,omitempty"` }
type EventCallback ¶
type EventCallback func(*DeviceInfo, *Event) error
type ModbusAccessConfig ¶ added in v2.1.45
type ModbusAccessConfig struct { Id byte `yaml:"id,omitempty" json:"id,omitempty"` Interval time.Duration `yaml:"interval,omitempty" json:"interval,omitempty"` Timeout time.Duration `yaml:"timeout,omitempty" json:"timeout,omitempty" default:"10s"` IdleTimeout time.Duration `yaml:"idletimeout,omitempty" json:"idletimeout,omitempty" default:"1m"` Tcp *TcpConfig `yaml:"tcp,omitempty" json:"tcp,omitempty"` Rtu *RtuConfig `yaml:"rtu,omitempty" json:"rtu,omitempty"` }
type ModbusVisitor ¶ added in v2.1.26
type ModbusVisitor struct { Function byte `yaml:"function" json:"function" validate:"min=1,max=4"` Address string `yaml:"address" json:"address"` Quantity uint16 `yaml:"quantity" json:"quantity"` Type string `yaml:"type,omitempty" json:"type,omitempty" validate:"regexp=^(int16|int32|int64|float32|float64|string|bool)?$"` Scale float64 `yaml:"scale" json:"scale"` SwapByte bool `yaml:"swapByte" json:"swapByte"` SwapRegister bool `yaml:"swapRegister" json:"swapRegister"` }
type OpcuaAccessConfig ¶ added in v2.1.45
type OpcuaAccessConfig struct { Id byte `yaml:"id,omitempty" json:"id,omitempty"` Endpoint string `yaml:"endpoint,omitempty" json:"endpoint,omitempty"` Interval time.Duration `yaml:"interval,omitempty" json:"interval,omitempty"` Timeout time.Duration `yaml:"timeout,omitempty" json:"timeout,omitempty"` Security OpcuaSecurity `yaml:"security,omitempty" json:"security,omitempty"` Auth OpcuaAuth `yaml:"auth,omitempty" json:"auth,omitempty"` Certificate OpcuaCertificate `yaml:"certificate,omitempty" json:"certificate,omitempty"` }
type OpcuaCertificate ¶ added in v2.1.45
type OpcuaSecurity ¶ added in v2.1.45
type OpcuaVisitor ¶ added in v2.1.26
type PropertyVisitor ¶ added in v2.1.26
type PropertyVisitor struct { Modbus *ModbusVisitor `yaml:"modbus,omitempty" json:"modbus,omitempty"` Opcua *OpcuaVisitor `yaml:"opcua,omitempty" json:"opcua,omitempty"` Custom *CustomVisitor `yaml:"custom,omitempty" json:"custom,omitempty"` }
type RtuConfig ¶ added in v2.1.45
type RtuConfig struct { Port string `yaml:"port,omitempty" json:"port,omitempty" validate:"required"` BaudRate int `yaml:"baudrate,omitempty" json:"baudrate,omitempty" default:"19200"` Parity string `yaml:"parity,omitempty" json:"parity,omitempty" default:"E" validate:"regexp=^(E|N|O)?$"` DataBit int `yaml:"databit,omitempty" json:"databit,omitempty" default:"8" validate:"min=5, max=8"` StopBit int `yaml:"stopbit,omitempty" json:"stopbit,omitempty" default:"1" validate:"min=1, max=2"` }
type Topic ¶
type Topic struct { Delta mqtt2.QOSTopic `yaml:"delta,omitempty" json:"delta,omitempty"` Report mqtt2.QOSTopic `yaml:"report,omitempty" json:"report,omitempty"` Event mqtt2.QOSTopic `yaml:"event,omitempty" json:"event,omitempty"` Get mqtt2.QOSTopic `yaml:"get,omitempty" json:"get,omitempty"` GetResponse mqtt2.QOSTopic `yaml:"getResponse,omitempty" json:"getResponse,omitempty"` }
Click to show internal directories.
Click to hide internal directories.