protocol

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: AGPL-3.0 Imports: 31 Imported by: 0

README

这个包是提供快速接入第三方协议的sdk

Documentation

Index

Constants

View Source
const (
	DeviceMqttDevice   = "device:mqtt:device"
	DeviceMqttClientID = "device:mqtt:clientID"
	DeviceLastActivity = "device:lastActivity"
)

Variables

This section is empty.

Functions

func DeleteDeviceActivity

func DeleteDeviceActivity(ctx context.Context, dev devices.Core)

func GenDeviceTopicKey

func GenDeviceTopicKey(dev devices.Core) string

func GetActivityDevices

func GetActivityDevices(ctx context.Context) (map[devices.Core]struct{}, error)

func UpdateDeviceActivity

func UpdateDeviceActivity(ctx context.Context, dev devices.Core)

func UpdatesDeviceActivity

func UpdatesDeviceActivity(ctx context.Context, devs []devices.Core)

Types

type CloudProtocol

type CloudProtocol[pConf ConfImp] struct {
	ConfMap      map[string]ConfInfo[pConf]
	ConfMapMutex sync.RWMutex
	SyncDevices  SyncDevicesFunc[pConf]
	InitFunc     func(conf pConf) (close func(), err error)
	*LightProtocol
}

func NewCloudProtocol

func NewCloudProtocol[pConf ConfImp](c conf.EventConf, pi *dm.ProtocolInfo, pc *CloudProtocolConf[pConf]) (*CloudProtocol[pConf], error)

func (*CloudProtocol[pConf]) ConfigChange

func (p *CloudProtocol[pConf]) ConfigChange(ctx context.Context, opt ConfigOpt, c pConf) error

func (*CloudProtocol[pConf]) GetAllConf

func (p *CloudProtocol[pConf]) GetAllConf() (ret []pConf)

func (*CloudProtocol[pConf]) GetConf

func (p *CloudProtocol[pConf]) GetConf(key string) *pConf

func (*CloudProtocol[pConf]) RegisterConfigChange

func (p *CloudProtocol[pConf]) RegisterConfigChange() error

func (*CloudProtocol[pConf]) RegisterDeviceSync

func (p *CloudProtocol[pConf]) RegisterDeviceSync(fieldName string, f SyncDevicesFunc[pConf]) error

func (*CloudProtocol[pConf]) RegisterInitHandler

func (p *CloudProtocol[pConf]) RegisterInitHandler(
	handle func(conf pConf) (close func(), err error)) error

func (*CloudProtocol[pConf]) ReportDevConn

func (p *CloudProtocol[pConf]) ReportDevConn(ctx context.Context, conn devices.DevConn) (err error)

func (*CloudProtocol[pConf]) Start

func (p *CloudProtocol[pConf]) Start() error

func (*CloudProtocol[pConf]) UpdateConfig

func (p *CloudProtocol[pConf]) UpdateConfig(ctx context.Context, c []pConf) error

type CloudProtocolConf

type CloudProtocolConf[pConf ConfImp] struct {
	ServerName string
	DmClient   zrpc.Client
	TimedM     zrpc.Client
	NodeID     int64
}

type ConfImp

type ConfImp interface {
	GenKey() string
	Equal(imp ConfImp) bool
	Init() error //配置初始化
}

type ConfInfo

type ConfInfo[pConf ConfImp] struct {
	Conf  pConf
	Close func()
}

type ConfigOpt

type ConfigOpt int64
const (
	ConfigOptCreate ConfigOpt = iota
	ConfigOptUpdate
	ConfigOptDelete
)

type ConnHandle

type ConnHandle func(ctx context.Context, info devices.DevConn) (devices.DevConn, error)

type ConnectMsg

type ConnectMsg struct {
	UserName string `json:"username"`
	Ts       int64  `json:"ts"`
	Address  string `json:"ipaddress"`
	ClientID string `json:"clientid"`
	Reason   string `json:"reason"`
}

登录登出消息

type DefaultConf

type DefaultConf struct {
}

func (DefaultConf) Equal

func (p DefaultConf) Equal(in DefaultConf) bool

func (DefaultConf) GenKey

func (p DefaultConf) GenKey() string

type DevHandle

type DevHandle func(ctx context.Context, topic string, payload []byte) error

type LightProtocol

type LightProtocol struct {
	FastEvent             *eventBus.FastEvent
	Pi                    *dm.ProtocolInfo
	ServerName            string
	ProductIDMap          map[string]string //key 是外部的产品ID,value是内部的产品ID
	UnitedRhinoProductIDs []string          //iThings 的产品ID列表
	ProductIDMapMutex     sync.RWMutex
	LightSvrClient
	ThirdProductIDFieldName devices.ProtocolKey
	// contains filtered or unexported fields
}

func NewLightProtocol

func NewLightProtocol(c conf.EventConf, pi *dm.ProtocolInfo, pc *LightProtocolConf) (*LightProtocol, error)

func (*LightProtocol) DevPubMsg

func (p *LightProtocol) DevPubMsg(ctx context.Context, publishMsg *devices.DevPublish) error

func (*LightProtocol) GetProductID

func (p *LightProtocol) GetProductID(productID string) string

通过外部的产品iD查询联犀的产品iD

func (*LightProtocol) GetUnitedRhinoProductIDs added in v0.2.3

func (p *LightProtocol) GetUnitedRhinoProductIDs() []string

func (*LightProtocol) RegisterDeviceMsgDownHandler

func (p *LightProtocol) RegisterDeviceMsgDownHandler(
	handle func(ctx context.Context, info *devices.InnerPublish) error) error

func (*LightProtocol) RegisterProductIDSync

func (p *LightProtocol) RegisterProductIDSync() error

func (*LightProtocol) RegisterTimerHandler

func (p *LightProtocol) RegisterTimerHandler(f func(ctx context.Context, t time.Time) error) error

定时同步设备信息,产品信息 如果不需要可以不注册

func (*LightProtocol) RunTimerHandles

func (p *LightProtocol) RunTimerHandles()

func (*LightProtocol) Start

func (p *LightProtocol) Start() error

type LightProtocolConf

type LightProtocolConf struct {
	ServerName string
	DmClient   zrpc.Client
	TimedM     zrpc.Client
	NodeID     int64
	Port       int64
}

type LightSvrClient

type LightSvrClient struct {
	ProtocolM      protocolmanage.ProtocolManage
	ProductM       productmanage.ProductManage
	ProductCache   dmExport.ProductCacheT
	DeviceCache    dmExport.DeviceCacheT
	SchemaCache    dmExport.DeviceSchemaCacheT
	DeviceM        devicemanage.DeviceManage
	DeviceInteract deviceinteract.DeviceInteract
	TimedM         timedmanage.TimedManage
	TimerHandles   []func(ctx context.Context, t time.Time) error
}

type MqttProtocol

type MqttProtocol struct {
	*LightProtocol
	MqttClient   *clients.MqttClient
	DevSubHandle map[string]DevHandle
	ConnHandle   ConnHandle
}

func NewMqttProtocol

func NewMqttProtocol(c conf.EventConf, pi *dm.ProtocolInfo, pc *LightProtocolConf, mqttc conf.DevLinkConf) (*MqttProtocol, error)

func (*MqttProtocol) PublishToDev

func (m *MqttProtocol) PublishToDev(ctx context.Context, topic string, payload []byte) error

func (*MqttProtocol) Start

func (m *MqttProtocol) Start() error

func (*MqttProtocol) SubscribeDevConn

func (m *MqttProtocol) SubscribeDevConn(handle ConnHandle) error

func (*MqttProtocol) SubscribeDevMsg

func (m *MqttProtocol) SubscribeDevMsg(topic string, handle DevHandle) error

type SyncDevicesFunc

type SyncDevicesFunc[pConf ConfImp] func(ctx context.Context, conf pConf, product *dm.ProductInfo) error

Jump to

Keyboard shortcuts

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