source

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 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

This section is empty.

Variables

Functions

func LoadSt

func LoadSt()

func NewCoAPInEndSource

func NewCoAPInEndSource(e typex.RuleX) typex.XSource

func NewGrpcInEndSource

func NewGrpcInEndSource(e typex.RuleX) typex.XSource

func NewHttpInEndSource

func NewHttpInEndSource(e typex.RuleX) typex.XSource

func NewIoTHubSource added in v0.5.2

func NewIoTHubSource(e typex.RuleX) typex.XSource

func NewMqttInEndSource

func NewMqttInEndSource(e typex.RuleX) typex.XSource

func NewNatsSource

func NewNatsSource(e typex.RuleX) typex.XSource

func NewUdpInEndSource

func NewUdpInEndSource(e typex.RuleX) typex.XSource

Types

type IotHUBTopologyDevice added in v0.5.2

type IotHUBTopologyDevice 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 (IotHUBTopologyDevice) OfflineTopic added in v0.5.2

func (tt IotHUBTopologyDevice) OfflineTopic() string

$thing/status/${productid}/${devicename}

func (IotHUBTopologyDevice) OnlineTopic added in v0.5.2

func (tt IotHUBTopologyDevice) OnlineTopic() string

$thing/status/${productid}/${devicename}

func (IotHUBTopologyDevice) ReportTopic added in v0.5.2

func (tt IotHUBTopologyDevice) ReportTopic() string

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

type IotHUBTopologyDownMsg added in v0.5.2

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

type IotHUBTopologyPayload added in v0.5.2

type IotHUBTopologyPayload struct {
	Devices []IotHUBTopologyDevice `json:"devices"`
}

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

$thing/status/${productid}/${devicename}

func (TopologyDevice) OnlineTopic

func (tt TopologyDevice) OnlineTopic() string

$thing/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