typex

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2023 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Warning:

This file is generated by go compiler, don't change it!!!

抽象设备: 1.0 以后的大功能:支持抽象设备,抽象设备就是外挂的设备,Rulex本来是个规则引擎,但是1.0之前的版本没有对硬件设备进行抽象支持 因此,1.0以后增加对硬件的抽象 Target Source 描述了数据的流向,抽象设备描述了数据的载体。 举例:外挂一个设备,这个设备具备双工控制功能,例如电磁开关等,此时它强调的是设备的物理功能,而数据则不是主体。 因此需要抽象出来一个层专门来描述这些设备

Index

Constants

This section is empty.

Variables

View Source
 **  Welcome to RULEX framework world <'_'>
**   Version: v0.5.2-af487b709b8f691
 **  Document: https://hootrhino.github.io
`
View Source
var DefaultVersion = Version{
	Version:     `v0.5.2`,
	ReleaseTime: "2023-08-08 15:05:37",
}

Global context

Functions

func Execute

func Execute(vm *lua.LState, k string, args ...lua.LValue) (interface{}, error)

执行lua函数的接口, 后期可以用这个接口来实现运行 lua 微服务

func NewCCTX

func NewCCTX() (context.Context, context.CancelFunc)

func RunPipline

func RunPipline(vm *lua.LState, funcs map[string]*lua.LFunction, arg lua.LValue) (lua.LValue, error)

RunPipline

Run lua as pipline

func StartQueue

func StartQueue(maxQueueSize int)

此处内置的消息队列用了go的channel, 看似好像很简单,但是经过测试发现完全满足网关需求,甚至都性能过剩了 因此大家看到这里务必担心, 我也知道有很精美的高级框架, 但是用简单的方法来实现功能不是更好吗?

Types

type AI

type AI struct {
	UUID        string                 `json:"uuid"`        // UUID
	Name        string                 `json:"name"`        // 名称
	Type        AIType                 `json:"type"`        // 类型
	IsBuildIn   bool                   `json:"isBuildIn"`   // 是否内建
	Filepath    string                 `json:"filepath"`    // 文件路径, 是相对于main的aispace目录
	Config      map[string]interface{} `json:"config"`      // 内部配置
	Description string                 `json:"description"` // 描述文字
	XAI         XAi                    `json:"-"`
}

* * 内建AI *

func NewAI

func NewAI(UUID, Name, Type, Filepath, Description string) *AI

* * 生成typex.AI应用 *

type AIType

type AIType string
const BODY_POSE_RECOGNITION AIType = "BODY_POSE_RECOGNITION"

内建类型

type AppState

type AppState int

type Application

type Application struct {
	UUID      string   `json:"uuid"`      // 名称
	Name      string   `json:"name"`      // 名称
	Version   string   `json:"version"`   // 版本号
	AutoStart bool     `json:"autoStart"` // 自动启动
	AppState  AppState `json:"appState"`  // 状态: 1 运行中, 0 停止
	Filepath  string   `json:"filepath"`  // 文件路径, 是相对于main的apps目录
	// contains filtered or unexported fields
}

* * 轻量级应用 *

func NewApplication

func NewApplication(uuid, Name, Version, Filepath string) *Application

func (*Application) GetMainFunc

func (app *Application) GetMainFunc() *lua.LFunction

func (*Application) Remove

func (app *Application) Remove()

* * 清理内存 *

func (*Application) SetCnC

func (app *Application) SetCnC(ctx context.Context, cancel context.CancelFunc)

func (*Application) SetMainFunc

func (app *Application) SetMainFunc(f *lua.LFunction)

func (*Application) Stop

func (app *Application) Stop()

* * 源码bug,没有等字节码执行结束就直接给释放stack了,问题处在state.go:1391, 已经给作者提了issue, * 如果1个月内不解决,准备自己fork一个过来维护. * Issue: https://github.com/hootrhino/gopher-lua/discussions/430

func (*Application) VM

func (app *Application) VM() *lua.LState

type CCTX

type CCTX struct {
	Ctx       context.Context
	CancelCTX context.CancelFunc
}

child context

type DCAModel

type DCAModel struct {
	UUID    string      `json:"uuid"`
	Command string      `json:"command"`
	Args    interface{} `json:"args"`
}

type DCAResult

type DCAResult struct {
	Error error
	Data  string
}

type DataCacheQueue

type DataCacheQueue struct {
	Queue chan QueueData
}

* * DataCacheQueue *

func (*DataCacheQueue) GetQueue

func (q *DataCacheQueue) GetQueue() chan QueueData

* * GetQueue *

func (*DataCacheQueue) GetSize

func (q *DataCacheQueue) GetSize() int

func (*DataCacheQueue) Push

func (q *DataCacheQueue) Push(d QueueData) error

* * Push *

type Device

type Device struct {
	UUID string     `json:"uuid"` // UUID
	Name string     `json:"name"` // 设备名称,例如:灯光开关
	Type DeviceType `json:"type"` // 类型,一般是设备-型号,比如 ARDUINO-R3
	// ------------------------------
	// 2023年5月10日00:25, 发现新问题: 当设备被Stop了以后, 永远不会被拉起来, 但是实际情况下如果是
	// 意外导致的失败, 可以用一个开关来控制其是否允许被重启
	// ------------------------------
	AutoRestart bool                   `json:"autoRestart"` // 是否允许挂了的时候重启
	Description string                 `json:"description"` // 设备描述信息
	BindRules   map[string]Rule        `json:"-"`           // 与之关联的规则
	State       DeviceState            `json:"state"`       // 状态
	Config      map[string]interface{} `json:"config"`      // 配置
	Device      XDevice                `json:"-"`           // 实体设备
}

设备元数据, 本质是保存在配置里面的数据的一个内存映射实例

func NewDevice

func NewDevice(t DeviceType,
	name string,
	description string,
	config map[string]interface{}) *Device

type DeviceProperty

type DeviceProperty struct {
	Name  string
	Type  string
	Value interface{}
}

设备的属性,是个描述结构

type DeviceRegistry

type DeviceRegistry interface {
	Register(DeviceType, *XConfig)
	Find(DeviceType) *XConfig
	All() []*XConfig
}

type DeviceState

type DeviceState int
const (
	// 外部停止
	DEV_STOP DeviceState = 0
	// 设备启用
	DEV_UP DeviceState = 1
	// 设备故障
	DEV_DOWN DeviceState = 2
)

func (DeviceState) String added in v0.5.2

func (s DeviceState) String() string

type DeviceTopology

type DeviceTopology struct {
	Id       string                 // 子设备的ID
	Name     string                 // 子设备名
	LinkType int                    // 物理连接方式: 0-ETH 1-WIFI 3-BLE 4 LORA 5 OTHER
	State    int                    // 状态: 0-Down 1-Working
	Info     map[string]interface{} // 子设备的一些额外信息
}

* * 子设备网络拓扑[2023-04-17新增] *

type DeviceType

type DeviceType string
const (
	TSS200V02                  DeviceType = "TSS200V02"                  // Multi params Sensor
	RTU485_THER                DeviceType = "RTU485_THER"                // RS485 Sensor
	YK08_RELAY                 DeviceType = "YK08_RELAY"                 // YK8 RS485 Relay
	S1200PLC                   DeviceType = "S1200PLC"                   // SIEMENS-S71200
	GENERIC_MODBUS             DeviceType = "GENERIC_MODBUS"             // 通用Modbus
	GENERIC_MODBUS_POINT_EXCEL DeviceType = "GENERIC_MODBUS_POINT_EXCEL" // 通用Modbus通过Excel表配置点位
	GENERIC_UART               DeviceType = "GENERIC_UART"               // 通用串口
	GENERIC_SNMP               DeviceType = "GENERIC_SNMP"               // SNMP 支持
	USER_G776                  DeviceType = "USER_G776"                  // 有人 G776 4G模组
	ICMP_SENDER                DeviceType = "ICMP_SENDER"                // ICMP_SENDER
	GENERIC_PROTOCOL           DeviceType = "GENERIC_PROTOCOL"           // 通用自定义协议处理器
	GENERIC_OPCUA              DeviceType = "GENERIC_OPCUA"              // 通用OPCUA
	GENERIC_CAMERA             DeviceType = "GENERIC_CAMERA"             // 通用摄像头
	GENERIC_AIS                DeviceType = "GENERIC_AIS"                // 通用AIS
	GENERIC_BACNET_IP          DeviceType = "GENERIC_BACNET_IP"          // 通用BacnetIP
)

支持的设备类型

type DriverDetail

type DriverDetail struct {
	UUID        string `json:"uuid" binding:"required"`
	Name        string `json:"name" binding:"required"`
	Type        string `json:"type" binding:"required"`
	Description string `json:"description" binding:"required"`
}

外挂驱动, 比如串口, PLC等, 驱动可以挂在输入或者输出资源上。 典型案例: 1. MODBUS TCP模式 ,数据输入后转JSON输出到串口屏幕上 2. MODBUS TCP模式外挂了很多继电器,来自云端的 PLC 控制指令先到网关, 然后网关决定推送到哪个外挂

type DriverState

type DriverState int

Abstract driver interface

const (
	// STOP 状态一般用来直接停止一个资源,监听器不需要重启
	DRIVER_STOP DriverState = 0
	// UP 工作态
	DRIVER_UP DriverState = 1
	// DOWN 状态是某个资源挂了,属于工作意外,需要重启
	DRIVER_DOWN DriverState = 2
)

type Extlib

type Extlib struct {
	Value []string `ini:"extlibs,,allowshadow" json:"extlibs"`
}

Global config

type Goods

type Goods struct {
	UUID string
	// TCP or Unix Socket
	Addr string
	// Description text
	Description string
	// Additional Args
	Args []string
}

* * 子进程的配置, 将 SocketAddr 传入 GRPC 客户端, Args 传入外挂的启动参数 * $> /test_driver Args

type GoodsProcess

type GoodsProcess struct {
	Running     bool
	Uuid        string
	Addr        string
	Description string
	Args        []string
	Ctx         context.Context
	Cmd         *exec.Cmd
	Cancel      context.CancelFunc
}

func NewGoodsProcess

func NewGoodsProcess() *GoodsProcess

func (*GoodsProcess) Stop

func (scm *GoodsProcess) Stop()

func (GoodsProcess) String

func (t GoodsProcess) String() string

type InEnd

type InEnd struct {
	//
	UUID        string          `json:"uuid"`
	State       SourceState     `json:"state"`
	Type        InEndType       `json:"type"`
	Name        string          `json:"name"`
	Description string          `json:"description"`
	BindRules   map[string]Rule `json:"-"`
	//
	Config        map[string]interface{} `json:"config"`
	DataModelsMap map[string]XDataModel  `json:"-"`
	Source        XSource                `json:"-"`
}

func NewInEnd

func NewInEnd(Type InEndType,
	n string,
	d string,
	c map[string]interface{}) *InEnd

func (*InEnd) GetConfig

func (in *InEnd) GetConfig(k string) interface{}

type InEndType

type InEndType string

InEndType

const (
	MQTT        InEndType = "MQTT"
	HTTP        InEndType = "HTTP"
	COAP        InEndType = "COAP"
	GRPC        InEndType = "GRPC"
	UART_MODULE InEndType = "UART_MODULE"
	//
	// MODBUS_MASTER
	//
	MODBUS_MASTER InEndType = "MODBUS_MASTER"
	//
	// MODBUS_SLAVER
	//
	MODBUS_SLAVER InEndType = "MODBUS_SLAVER"
	//
	// From snmp server provider
	//
	SNMP_SERVER InEndType = "SNMP_SERVER"
	//
	// NATS.IO SERVER
	//
	NATS_SERVER InEndType = "NATS_SERVER"
	//
	// 西门子S7客户端
	//
	SIEMENS_S7 InEndType = "SIEMENS_S7"
	//
	// RULEX UDP 自定义简单协议
	//
	RULEX_UDP InEndType = "RULEX_UDP"
	// 通用IotHUB
	GENERIC_IOT_HUB InEndType = "GENERIC_IOT_HUB"
	//
	// Ithings 平台
	//
	ITHINGS_IOT_HUB InEndType = "ITHINGS_IOT_HUB"
)

func (InEndType) String

func (i InEndType) String() string

type LList

type LList []LObject

func (LList) ToString

func (lMap LList) ToString() string

type LMap

type LMap map[string]LObject

LUA 表增强

func (LMap) ToString

func (lMap LMap) ToString() string

type LObject

type LObject struct {
	Type  int
	Value interface{}
}

func (LObject) ToF32

func (obj LObject) ToF32() float32

func (LObject) ToF64

func (obj LObject) ToF64() float64

func (LObject) ToI32

func (obj LObject) ToI32() int32

func (LObject) ToI64

func (obj LObject) ToI64() int64

func (LObject) ToString

func (obj LObject) ToString() string

type MetricStatistics added in v0.6.1

type MetricStatistics struct {
	InSuccess  uint64 `json:"inSuccess"`
	OutSuccess uint64 `json:"outSuccess"`
	InFailed   uint64 `json:"inFailed"`
	OutFailed  uint64 `json:"outFailed"`
}

func NewMetricStatistics added in v0.6.1

func NewMetricStatistics() *MetricStatistics

func (*MetricStatistics) DecIn added in v0.6.1

func (statisticsCache *MetricStatistics) DecIn()

func (*MetricStatistics) DecOut added in v0.6.1

func (statisticsCache *MetricStatistics) DecOut()

func (*MetricStatistics) IncIn added in v0.6.1

func (statisticsCache *MetricStatistics) IncIn()

func (*MetricStatistics) IncInFailed added in v0.6.1

func (statisticsCache *MetricStatistics) IncInFailed()

func (*MetricStatistics) IncOut added in v0.6.1

func (statisticsCache *MetricStatistics) IncOut()

func (*MetricStatistics) IncOutFailed added in v0.6.1

func (statisticsCache *MetricStatistics) IncOutFailed()

func (*MetricStatistics) Reset added in v0.6.1

func (statisticsCache *MetricStatistics) Reset()

type ModelType

type ModelType int

Rule type is for property store, XSource implements struct type is actually worker

const (
	T_INT32  ModelType = iota // int32
	T_FLOAT                   // float
	T_DOUBLE                  // double
	T_TEXT                    // pure text
	T_BOOL                    // boolean
	T_JSON                    // json
	T_BIN                     // byte
)

'T' means Type

type OutEnd

type OutEnd struct {
	UUID        string      `json:"uuid"`
	State       SourceState `json:"state"`
	Type        TargetType  `json:"type"`
	Name        string      `json:"name"`
	Description string      `json:"description"`
	//
	Config map[string]interface{} `json:"config"`
	Target XTarget                `json:"-"`
}

func NewOutEnd

func NewOutEnd(t TargetType,
	n string,
	d string,
	c map[string]interface{}) *OutEnd

func (*OutEnd) GetConfig

func (out *OutEnd) GetConfig(k string) interface{}

type Parity

type Parity string

* * 串口校验形式 *

const (
	ODD  Parity = "O" // 奇校验
	EVEN Parity = "E" // 偶校验
	NONE Parity = "N" // 不校验
)

type QueueData

type QueueData struct {
	Debug bool // 是否是Debug消息
	I     *InEnd
	O     *OutEnd
	D     *Device
	E     RuleX
	Data  string
}

func (QueueData) String

func (qd QueueData) String() string

type Rule

type Rule struct {
	Id         string     `json:"id"`
	UUID       string     `json:"uuid"`
	Type       string     `json:"type"` // 脚本类型,目前支持"lua"和"expr"两种
	Status     RuleStatus `json:"status"`
	Name       string     `json:"name"`
	FromSource []string   `json:"fromSource"` // 来自数据源
	FromDevice []string   `json:"fromDevice"` // 来自设备
	Actions    string     `json:"actions"`
	// 0.5 新增功能:支持另一种脚本来筛选数据:https://github.com/antonmedv/expr
	// 该字段只有在Type=="expr"的时候有效
	Expression  string      `json:"expression"` // Expr脚本
	Success     string      `json:"success"`
	Failed      string      `json:"failed"`
	Description string      `json:"description"`
	LuaVM       *lua.LState `json:"-"` // Lua VM
	ExprVM      *vm.Program `json:"-"` // Expr Vm
}

规则描述

func NewExprRule

func NewExprRule(e RuleX,
	uuid string,
	name string,
	Type string,
	Expression string,
	description string,
	fromSource []string,
	fromDevice []string,
	success string,
	actions string,
	failed string) *Rule

func NewLuaRule

func NewLuaRule(e RuleX,
	uuid string,
	name string,
	description string,
	fromSource []string,
	fromDevice []string,
	success string,
	actions string,
	failed string) *Rule

func NewRule

func NewRule(e RuleX,
	uuid string,
	name string,
	description string,
	fromSource []string,
	fromDevice []string,
	success string,
	actions string,
	failed string) *Rule

New

func (*Rule) AddLib

func (r *Rule) AddLib(rx RuleX, Global string, funcName string,
	f func(l *lua.LState) int)

* * AddLib: 根据 KV形式加载库(推荐) * - Global: 命名空间 * - funcName: 函数名称

func (*Rule) LoadExternLuaLib

func (r *Rule) LoadExternLuaLib(path string) error

* * 加载外部LUA脚本,方便用户自己写一些东西 * 需要注意的: * - 不要和标准库里面的变量冲突了 * - 默认加载到 _G 环境里

type RuleStatus

type RuleStatus int
const RULE_RUNNING RuleStatus = 1
const RULE_STOP RuleStatus = 0

规则状态: 0: 停止 1: 运行中

type RuleX

type RuleX interface {
	//
	// 启动规则引擎
	//
	Start() *RulexConfig
	//
	// 消息推到队列
	//
	PushQueue(QueueData) error
	PushInQueue(in *InEnd, data string) error
	PushOutQueue(out *OutEnd, data string) error
	PushDeviceQueue(device *Device, data string) error
	//
	// 执行任务
	//
	WorkInEnd(*InEnd, string) (bool, error)
	WorkDevice(*Device, string) (bool, error)
	//
	// 获取配置
	//
	GetConfig() *RulexConfig
	//
	// 加载输入
	//
	LoadInEndWithCtx(in *InEnd, ctx context.Context, cancelCTX context.CancelFunc) error
	//
	// 获取输入
	//
	GetInEnd(string) *InEnd
	//
	// 保存输入
	//
	SaveInEnd(*InEnd)
	//
	// 删除输入
	//
	RemoveInEnd(string)
	//
	// 所有输入列表
	//
	AllInEnd() *sync.Map
	//
	// 加载输出
	//
	LoadOutEndWithCtx(in *OutEnd, ctx context.Context, cancelCTX context.CancelFunc) error
	//
	// 所有输出
	//
	AllOutEnd() *sync.Map
	//
	// 获取输出
	//
	GetOutEnd(string) *OutEnd
	//
	// 保存输出
	//
	SaveOutEnd(*OutEnd)
	//
	// 删除输出
	//
	RemoveOutEnd(string)
	//
	// 加载Hook
	//
	LoadHook(XHook) error
	//
	// 加载插件
	//
	LoadPlugin(string, XPlugin) error
	//
	// 所有插件列表
	//
	AllPlugins() *sync.Map
	//
	// 加载规则
	//
	LoadRule(*Rule) error
	//
	// 所有规则列表
	//
	AllRule() *sync.Map
	//
	// 获取规则
	//
	GetRule(id string) *Rule
	//
	// 删除规则
	//
	RemoveRule(uuid string)
	//
	// 运行 lua 回调
	//
	RunSourceCallbacks(*InEnd, string)
	RunDeviceCallbacks(*Device, string)
	//
	// 运行 hook
	//
	RunHooks(string) //TODO Hook 未来某个版本会加强,主要用来加载本地动态库
	//
	// 获取版本
	//
	Version() Version

	//
	// 停止规则引擎
	//
	Stop()
	// 优雅关闭
	Wait(...os.Signal)
	//
	// Snapshot Dump
	//
	SnapshotDump() string
	//
	// 加载设备
	//
	LoadDeviceWithCtx(in *Device, ctx context.Context, cancelCTX context.CancelFunc) error
	//
	// 获取设备
	//
	GetDevice(string) *Device
	//
	// 保存设备
	//
	SaveDevice(*Device)
	//
	//
	//
	AllDevices() *sync.Map
	//
	// 删除设备
	//
	RemoveDevice(string)
	//
	// 取一个进程
	//
	PickUpProcess(uuid string) *GoodsProcess

	//
	// 加载外部驱动
	//
	LoadGoods(goods Goods) error
	//
	// 删除外部驱动
	//
	RemoveGoods(uuid string) error
	//
	// 所有外部驱动
	//
	AllGoods() *sync.Map
	//
	// 获取某个外部驱动
	//
	GetGoods(uuid string) *Goods
	//
	// 重启源
	//
	RestartInEnd(uuid string) error
	//
	// 重启目标
	//
	RestartOutEnd(uuid string) error
	//
	// 重启设备
	//
	RestartDevice(uuid string) error
	//----------------------------------------
	// App
	//----------------------------------------
	AllApp() []*Application
	LoadApp(*Application) error
	GetApp(uuid string) *Application
	StartApp(uuid string) error
	StopApp(uuid string) error
	RemoveApp(uuid string) error
	//----------------------------------------
	// AiBase
	//----------------------------------------
	GetAiBase() XAiRuntime
	GetMetricStatistics() *MetricStatistics
}

RuleX interface

type RulexConfig

type RulexConfig struct {
	AppName               string `ini:"app_name" json:"appName"`
	AppId                 string `ini:"app_id" json:"appId"`
	MaxQueueSize          int    `ini:"max_queue_size" json:"maxQueueSize"`
	SourceRestartInterval int    `ini:"resource_restart_interval" json:"sourceRestartInterval"`
	GomaxProcs            int    `ini:"gomax_procs" json:"gomaxProcs"`
	EnablePProf           bool   `ini:"enable_pprof" json:"enablePProf"`
	EnableConsole         bool   `ini:"enable_console" json:"enableConsole"`
	LogLevel              string `ini:"log_level" json:"logLevel"`
	LogPath               string `ini:"log_path" json:"logPath"`
	LuaLogPath            string `ini:"lua_log_path" json:"luaLogPath"`
	MaxStoreSize          int    `ini:"max_store_size" json:"maxStoreSize"`
	AppDebugMode          bool   `ini:"app_debug_mode" json:"appDebugMode"`
	Extlibs               Extlib `ini:"extlibs,,allowshadow" json:"extlibs"`
	UpdateServer          string `ini:"update_server" json:"updateServer"`
}

type ServiceArg

type ServiceArg struct {
	UUID string      `json:"uuid"` // 插件UUID, Rulex用来查找插件的
	Name string      `json:"name"` // 服务名, 在服务中响应识别
	Args interface{} `json:"args"` // 服务参数
}

插件的服务参数

type ServiceResult

type ServiceResult struct {
	Out interface{} `json:"out"`
}

type SourceRegistry

type SourceRegistry interface {
	Register(InEndType, *XConfig)
	Find(InEndType) *XConfig
	All() []*XConfig
}

type SourceState

type SourceState int

Source State

const (
	SOURCE_DOWN  SourceState = 0 // 此状态需要重启
	SOURCE_UP    SourceState = 1
	SOURCE_PAUSE SourceState = 2
	SOURCE_STOP  SourceState = 3
)

func (SourceState) String added in v0.5.2

func (s SourceState) String() string

type TargetRegistry

type TargetRegistry interface {
	Register(TargetType, *XConfig)
	Find(TargetType) *XConfig
	All() []*XConfig
}

type TargetType

type TargetType string

TargetType

const (
	MONGO_SINGLE  TargetType = "MONGO_SINGLE"
	MONGO_CLUSTER TargetType = "MONGO_CLUSTER"
	REDIS_SINGLE  TargetType = "REDIS_SINGLE"
	FLINK_SINGLE  TargetType = "FLINK_SINGLE"
	MQTT_TARGET   TargetType = "MQTT"
	MYSQL_TARGET  TargetType = "MYSQL"
	PGSQL_TARGET  TargetType = "PGSQL"
	NATS_TARGET   TargetType = "NATS"
	HTTP_TARGET   TargetType = "HTTP"
	//
	// TDENGINE
	//
	TDENGINE_TARGET TargetType = "TDENGINE"
	// GRPC
	GRPC_CODEC_TARGET TargetType = "GRPC_CODEC_TARGET"
	// UDP Server
	UDP_TARGET TargetType = "UDP_TARGET"
	// SQLITE
	SQLITE_TARGET TargetType = "SQLITE_TARGET"
	// USER_G776 DTU
	USER_G776_TARGET TargetType = "USER_G776_TARGET"
)

* * 输出资源类型 *

func (TargetType) String

func (i TargetType) String() string

type TopologyPoint

type TopologyPoint struct {
	UUID   string `json:"uuid"`
	Parent string `json:"parent"`
	Name   string `json:"name"`
	Alive  bool   `json:"alive"`
	Tag    string `json:"tag"`
}

拓扑接入点,比如 modbus 检测点等 UUID: gyh9uo7uh7o67u Name: ModbusMeter001 Alive: true Tag: modbus

type Version

type Version struct {
	Version     string
	ReleaseTime string
	Arch        string
	Dist        string
}

type XAi

type XAi interface {
	Start(map[string]interface{}) error
	Infer([][]float64) [][]float64
	Stop()
}

* * AI 应用层接口 *

type XAiRuntime

type XAiRuntime interface {
	GetRuleX() RuleX
	ListAi() []*AI
	LoadAi(Ai *AI) error
	GetAi(uuid string) *AI
	RemoveAi(uuid string) error
	UpdateAi(Ai *AI) error
	StartAi(uuid string) error
	StopAi(uuid string) error
	Stop()
}

* * AI 应用管理器接口 *

type XAppStack

type XAppStack interface {
	GetRuleX() RuleX
	ListApp() []*Application
	// 把配置里的应用信息加载到内存里
	LoadApp(app *Application) error
	GetApp(uuid string) *Application
	RemoveApp(uuid string) error
	UpdateApp(app Application) error
	// 启动一个停止的进程
	StartApp(uuid string) error
	StopApp(uuid string) error
	Stop()
}

* * APP Stack 管理器 *

type XConfig

type XConfig struct {
	Type      string              `json:"type"` // 类型
	Engine    RuleX               `json:"-"`
	NewDevice func(RuleX) XDevice `json:"-"`
	NewSource func(RuleX) XSource `json:"-"`
	NewTarget func(RuleX) XTarget `json:"-"`
}

type XDataModel

type XDataModel struct {
	Name      string      `json:"name"`      // 字段名
	Tag       string      `json:"tag"`       // 标签
	ValueType ModelType   `json:"valueType"` // 值类型
	Value     interface{} `json:"value"`     // 具体的值
}

* 数据模型, 例如某个Modbus电表可以支持读取电流/C 和电压/V参数: *[ * { * "name":"voltage", * "tag":"voltage", * "valueType":"float", * "value":220 * } *] *

func (XDataModel) String added in v0.5.1

func (m XDataModel) String() string

type XDevice

type XDevice interface {
	// 初始化 通常用来获取设备的配置
	Init(devId string, configMap map[string]interface{}) error
	// 启动, 设备的工作进程
	Start(CCTX) error
	// 从设备里面读数据出来, 第一个参数一般作flag用, 也就是常说的指令类型
	OnRead(cmd []byte, data []byte) (int, error)
	// 把数据写入设备, 第一个参数一般作flag用, 也就是常说的指令类型
	OnWrite(cmd []byte, data []byte) (int, error)
	// 新特性, 适用于自定义协议读写
	OnCtrl(cmd []byte, args []byte) ([]byte, error)
	// 设备当前状态
	Status() DeviceState
	// 停止设备, 在这里释放资源,一般是先置状态为STOP,然后CancelContext()
	Stop()
	//
	// 0.5.2 新增 Reload() error
	//
	// 设备属性,是一系列属性描述
	Property() []DeviceProperty
	// 链接指向真实设备,保存在内存里面,和SQLite里的数据是对应关系
	Details() *Device
	// 状态
	SetState(DeviceState)
	// 驱动接口, 通常用来和硬件交互
	Driver() XExternalDriver
	// 外部调用, 该接口是个高级功能, 准备为了设计分布式部署设备的时候用, 但是相当长时间内都不会开启
	// 默认情况下该接口没有用
	OnDCACall(UUID string, Command string, Args interface{}) DCAResult
}

真实工作设备,即具体实现

type XExternalDriver

type XExternalDriver interface {
	Test() error
	Init(map[string]string) error
	Work() error
	State() DriverState
	Read(cmd []byte, data []byte) (int, error)
	Write(cmd []byte, data []byte) (int, error)
	DriverDetail() DriverDetail
	Stop() error
}

驱动由源(Source)或者设备(Device)启动,驱动的状态(Status)被RULEX获取,或者被源或者设备获取后返回给RULEX

type XHook

type XHook interface {
	Work(data string) error
	Error(error)
	Name() string
}

XHook for enhancement rulex with golang

type XLib

type XLib interface {
	Name() string
	LibFun(RuleX) func(*lua.LState) int
}

XLib: 库函数接口; TODO: V0.1.2废弃

type XPlugin

type XPlugin interface {
	Init(*ini.Section) error // 参数为外部配置
	Start(RuleX) error
	Service(ServiceArg) ServiceResult // 对外提供一些服务
	Stop() error
	PluginMetaInfo() XPluginMetaInfo
}

* * 插件: 用来增强RULEX的外部功能,本色不属于RULEX *

type XPluginMetaInfo

type XPluginMetaInfo struct {
	UUID     string `json:"uuid"`
	Name     string `json:"name"`
	Version  string `json:"version"`
	Homepage string `json:"homepage"`
	HelpLink string `json:"helpLink"`
	Author   string `json:"author"`
	Email    string `json:"email"`
	License  string `json:"license"`
}

* * 插件的元信息结构体 * 注意:插件信息这里uuid,name有些是固定写死的,比较特殊,不要轻易改变已有的,否则会导致接口失效 * 只要是已有的尽量不要改这个UUID。 *

type XQueue

type XQueue interface {
	GetQueue() chan QueueData
	GetSize() int
	Push(QueueData) error
}

* * XQueue *

var DefaultDataCacheQueue XQueue

type XService

type XService interface {
	Load()
	Get()
	List()
	Remove()
	Stop()
}

* * TODO: 定义一系列接口,以后每个涉及到CURD管理的都实现这个接口 * 暂时先放在这里作为参考,短期内不会重构 *

type XSource

type XSource interface {
	//
	// 测试资源是否可用
	//
	Test(inEndId string) bool
	//
	// 用来初始化传递资源配置
	//
	Init(inEndId string, configMap map[string]interface{}) error
	//
	// 启动资源
	//
	Start(CCTX) error
	//
	// 资源是否被启用
	//
	Enabled() bool
	//
	// 数据模型, 用来描述该资源支持的数据, 对应的是云平台的物模型
	//
	DataModels() []XDataModel
	//
	// 获取前端表单定义
	//
	Configs() *XConfig
	//
	// 重载: 比如可以在重启的时候把某些数据保存起来
	//
	Reload()
	//
	// 挂起资源, 用来做暂停资源使用
	//
	Pause()
	//
	// 获取资源状态
	//
	Status() SourceState
	//
	// 获取资源绑定的的详情
	//
	Details() *InEnd
	//
	// 驱动接口, 通常用来和硬件交互
	//
	Driver() XExternalDriver
	//
	//
	//
	Topology() []TopologyPoint
	//
	// 停止资源, 用来释放资源
	//
	Stop()
	//
	// 来自外面的数据
	//
	DownStream([]byte) (int, error)
	//
	// 上行数据
	//
	UpStream([]byte) (int, error)
}

XSource: 终端资源, 比如实际上的 MQTT 客户端

type XStatus

type XStatus struct {
	PointId     string             // Input: Source; Output: Target
	Enable      bool               // 是否开启
	Ctx         context.Context    // context
	CancelCTX   context.CancelFunc // cancel
	XDataModels []XDataModel       // 数据模型
	RuleEngine  RuleX              // rulex
	Busy        bool               // 是否处于忙碌状态, 防止请求拥挤
}

XStatus for source status

type XStore

type XStore interface {
	// 设置值
	Set(k string, v string)
	// 获取值
	Get(k string) string
	// 删除值
	Delete(k string) error
	// 统计数量
	Count() int
	// 模糊查询匹配
	// 支持: *AAA AAA* A*B
	FuzzyGet(k string) string
}

* * 缓存器接口 *

type XStream

type XStream interface {
	Start() error
	State() XStatus
	Close()
}

------------------------------------------------

Remote Stream

------------------------------------------------ ┌───────────────┐ ┌────────────────┐ │ RULEX │ <─────── │ SERVER │ │ RULEX │ ───────>│ SERVER │ └───────────────┘ └────────────────┘ ------------------------------------------------

type XTarget

type XTarget interface {
	//
	// 测试资源是否可用
	//
	Test(outEndId string) bool
	//
	// 用来初始化传递资源配置
	//
	Init(outEndId string, configMap map[string]interface{}) error
	//
	// 启动资源
	//
	Start(CCTX) error
	//
	// 资源是否被启用
	//
	Enabled() bool
	//
	// 重载: 比如可以在重启的时候把某些数据保存起来
	//
	Reload()
	//
	// 挂起资源, 用来做暂停资源使用
	//
	Pause()
	//
	// 获取资源状态
	//
	Status() SourceState
	//
	// 获取资源绑定的的详情
	//
	Details() *OutEnd
	//
	//
	//
	Configs() *XConfig
	//
	// 数据出口
	//
	To(data interface{}) (interface{}, error)
	//
	// 停止资源, 用来释放资源
	//
	Stop()
}

Stream from source and to target

type XTrailer

type XTrailer interface {
	Fork(Goods) error
	Get(addr string) *GoodsProcess
	Save(*GoodsProcess)
	Remove(uuid string)
	AllGoods() *sync.Map
	Stop()
}

Jump to

Keyboard shortcuts

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