source

package
v0.5.1 Latest Latest
Warning

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

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

README

开发模板

资源需要实现以下接口:


type XSource interface {
	Test(inEndId string) bool
	Init(inEndId string, cfg map[string]interface{}) error
	Start(CCTX) error
	Enabled() bool
	DataModels() []XDataModel
	Configs() *XConfig
	Reload()
	Pause()
	Status() SourceState
	Details() *InEnd
	Driver() XExternalDriver
	Topology() []TopologyPoint
	Stop()
}

加载配置

我们以一个 COAP Server 为例来解释,首先定义一个配置结构体:

type coAPConfig struct {
	Port       uint16             `json:"port" validate:"required" title:"端口"`
	DataModels []typex.XDataModel `json:"dataModels" title:"数据模型"`
}

然后在Init里面解析外部配置到资源的配置结构体,相当于是加载配置:


func (cc *coAPInEndSource) Init(inEndId string, cfg map[string]interface{}) error {
	cc.PointId = inEndId
	var mainConfig coAPConfig
	if err := utils.BindSourceConfig(cfg, &mainConfig); err != nil {
		return err
	}
	cc.port = mainConfig.Port
	cc.dataModels = mainConfig.DataModels
	return nil
}

参数说明

  • inEndId:资源元数据的ID
  • cfg:配置数据的Map形式结构

Documentation

Index

Constants

View Source
const (
	// 属性下发称之为控制指令
	METHOD_CONTROL       string = "control"
	METHOD_CONTROL_REPLY string = "control_reply"
	// 属性下发称之为控制指令[这是为了兼容一些其他平台,实际上和上面功能完全一一样]
	METHOD_PROPERTY       string = "property"
	METHOD_PROPERTY_REPLY string = "property_reply"
	// 动作请求
	METHOD_ACTION       string = "action"
	METHOD_ACTION_REPLY string = "action_reply"
)
{
    "method":"${method}_reply",
    "requestId":"20a4ccfd-d308",
    "code": 0,
    "status":"some message"
}

Variables

Functions

func LoadSt

func LoadSt()

func NewCoAPInEndSource

func NewCoAPInEndSource(e typex.RuleX) typex.XSource

func NewGenericIothubSource

func NewGenericIothubSource(e typex.RuleX) typex.XSource

func NewGrpcInEndSource

func NewGrpcInEndSource(e typex.RuleX) typex.XSource

func NewHttpInEndSource

func NewHttpInEndSource(e typex.RuleX) typex.XSource

func NewIThingsSource

func NewIThingsSource(e typex.RuleX) typex.XSource

func NewMqttInEndSource

func NewMqttInEndSource(e typex.RuleX) typex.XSource

func NewNatsSource

func NewNatsSource(e typex.RuleX) typex.XSource

func NewTencentIothubSource

func NewTencentIothubSource(e typex.RuleX) typex.XSource

func NewUdpInEndSource

func NewUdpInEndSource(e typex.RuleX) typex.XSource

Types

type RulexRpcServer

type RulexRpcServer struct {
	rulexrpc.UnimplementedRulexRpcServer
	// contains filtered or unexported fields
}

func (*RulexRpcServer) Work

type TopologyDevice

type TopologyDevice struct {
	ProductID  string `json:"productID"`
	DeviceName string `json:"deviceName"`
}

* * 下发拓扑结构 *

{
	"method":"describesubDevices",
	"clientToken":"3160be0b-6d4f-e6fa-d614-8fb422c0d16c",
	"timestamp":1681625336600,
	"status":"成功",
	"payload":{
		"devices":[
			{
				"productID":"268dGhSTdOE",
				"deviceName":"RULEX-大屏1"
			}
		]
	}
}

func (TopologyDevice) OfflineTopic

func (tt TopologyDevice) OfflineTopic() string

$gateway/status/${productid}/${devicename}

func (TopologyDevice) OnlineTopic

func (tt TopologyDevice) OnlineTopic() string

$gateway/status/${productid}/${devicename}

func (TopologyDevice) ReportTopic

func (tt TopologyDevice) ReportTopic() string

$thing/up/property/{ProductID}/{DeviceName}

type TopologyDownMsg

type TopologyDownMsg struct {
	Method      string          `json:"method"`
	ClientToken string          `json:"clientToken"`
	Timestamp   int64           `json:"timestamp"`
	Status      string          `json:"status"`
	Payload     TopologyPayload `json:"payload"`
}

type TopologyPayload

type TopologyPayload struct {
	Devices []TopologyDevice `json:"devices"`
}

Jump to

Keyboard shortcuts

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