plugin

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Connector

type Connector interface {
	Send(data interface{}) (err error) // 发送数据
	Release() (err error)              // 释放连接资源
}

Connector 连接器

type DeviceData

type DeviceData struct {
	DeviceName string      `json:"device_name"`
	Values     []PointData `json:"values"`
}

DeviceData 设备数据

func (DeviceData) ToJSON

func (d DeviceData) ToJSON() string

ToJSON 设备数据转 json

type EncodeMode

type EncodeMode string

EncodeMode 编码模式

const (
	ReadMode  EncodeMode = "read"  // 读模式
	WriteMode EncodeMode = "write" // 写模式
)

type H

type H map[string]interface{}

H map[string]interface{} 别名

type OnReceiveHandler

type OnReceiveHandler func(plugin Plugin, raw interface{}) (result interface{}, err error)

OnReceiveHandler 接收数据回调函数

type Plugin

type Plugin interface {
	// Initialize 初始化日志、配置、接收回调
	Initialize(logger *zap.Logger, c config.Config, handler OnReceiveHandler, ls *lua.LState) (err error)
	// ProtocolAdapter 协议适配器
	ProtocolAdapter() ProtocolAdapter
	// Connector 连接器
	Connector(deviceName, pointName string) (connector Connector, err error)
	// Destroy 销毁驱动
	Destroy() error
}

Plugin 驱动插件

type PointData

type PointData struct {
	PointName string      `json:"name"`  // 点位名称
	Type      string      `json:"type"`  // 点位值类型
	Value     interface{} `json:"value"` // 点位值
}

PointData 点位数据

type ProtocolAdapter

type ProtocolAdapter interface {
	Encode(deviceName string, mode EncodeMode, value PointData) (res interface{}, err error) // 编码
	Decode(raw interface{}) (res []DeviceData, err error)                                    // 解码
}

ProtocolAdapter 协议适配器 点位数据 <=> 协议数据

Jump to

Keyboard shortcuts

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