dmcontext

package
v2.2.3 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2021 License: Apache-2.0 Imports: 18 Imported by: 14

Documentation

Index

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

func ParseTopic(topic string) (string, error)

func Run

func Run(handle func(Context) error)

Run service

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

func NewContext(confFile string) Context

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 DeviceInfo struct {
	Name    string `yaml:"name,omitempty" json:"name,omitempty"`
	Version string `yaml:"version,omitempty" json:"version,omitempty"`
	Topic   `yaml:",inline" json:",inline"`
}

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 DeviceShadow struct {
	Name   string    `yaml:"name,omitempty" json:"name,omitempty"`
	Report v1.Report `yaml:"report,omitempty" json:"report,omitempty"`
	Desire v1.Desire `yaml:"desire,omitempty" json:"desire,omitempty"`
}

type DmCtx

type DmCtx struct {
	context.Context
	// contains filtered or unexported fields
}

func (*DmCtx) Close

func (c *DmCtx) Close() error

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 (c *DmCtx) GetDriverConfig() string

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

func (*DmCtx) Start

func (c *DmCtx) Start()

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 OpcuaAuth added in v2.1.45

type OpcuaAuth struct {
	Username string `yaml:"username,omitempty" json:"username,omitempty"`
	Password string `yaml:"password,omitempty" json:"password,omitempty"`
}

type OpcuaCertificate added in v2.1.45

type OpcuaCertificate struct {
	Cert string `yaml:"certFile,omitempty" json:"certFile,omitempty"`
	Key  string `yaml:"keyFile,omitempty" json:"keyFile,omitempty"`
}

type OpcuaSecurity added in v2.1.45

type OpcuaSecurity struct {
	Policy string `yaml:"policy,omitempty" json:"policy,omitempty"`
	Mode   string `yaml:"mode,omitempty" json:"mode,omitempty"`
}

type OpcuaVisitor added in v2.1.26

type OpcuaVisitor struct {
	NodeID string `yaml:"nodeid,omitempty" json:"nodeid,omitempty"`
	Type   string `yaml:"type,omitempty" json:"type,omitempty" validate:"regexp=^(int16|int32|int64|float32|float64|string|bool)?$"`
}

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 TcpConfig added in v2.1.45

type TcpConfig struct {
	Address string `yaml:"address,omitempty" json:"address,omitempty" validate:"required"`
	Port    uint16 `yaml:"port,omitempty" json:"port,omitempty" validate:"required"`
}

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"`
}

Jump to

Keyboard shortcuts

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