shadow

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BindPointDataErr = errors.New("bind online point data can't be parsed")
View Source
var DeviceRepeatErr = errors.New("device already exists")
View Source
var UnknownDeviceErr = errors.New("unknown device")
View Source
var UnknownDevicePointErr = errors.New("unknown device point")

Functions

This section is empty.

Types

type Device

type Device struct {
	// contains filtered or unexported fields
}

Device 设备结构

func NewDevice

func NewDevice(device config.Device, modelName string, points map[string]DevicePoint) Device

func (*Device) GetDevicePoint added in v0.7.0

func (d *Device) GetDevicePoint(pointName string) (DevicePoint, bool)

GetDevicePoint 获取设备指定点位数据

func (*Device) GetDevicePointAPI added in v0.7.0

func (d *Device) GetDevicePointAPI(pointName string) (DevicePointAPI, bool)

GetDevicePointAPI 获取设备指定点位数据(开放 API 使用)

func (*Device) SetOnlineBindPoint

func (d *Device) SetOnlineBindPoint(pointName string)

SetOnlineBindPoint 设备在线状态绑定指定点位

func (*Device) ToDeviceAPI added in v0.7.0

func (d *Device) ToDeviceAPI() DeviceAPI

ToDeviceAPI 转换设备 API

type DeviceAPI added in v0.7.0

type DeviceAPI struct {
	SN              string           `json:"sn"`
	Points          []DevicePointAPI `json:"points"`
	Online          bool             `json:"online"`
	TTL             string           `json:"ttl"`
	DisconnectTimes int              `json:"disconnect_times"`
	UpdatedAt       string           `json:"updated_at"`
}

DeviceAPI 对外开放设备数据

type DevicePoint

type DevicePoint struct {
	Name      string      // 点位名称
	Value     interface{} // 点位值
	UpdatedAt time.Time   // 点位最后更新时间(用于点位缓存过期判断)
}

DevicePoint 设备点位结构

func (DevicePoint) ToDevicePointAPI added in v0.7.0

func (dp DevicePoint) ToDevicePointAPI() DevicePointAPI

type DevicePointAPI added in v0.7.0

type DevicePointAPI struct {
	Name      string `json:"name"`
	Value     any    `json:"value"`
	UpdatedAt string `json:"updated_at"`
}

DevicePointAPI 对外开放设备点位

type DeviceShadow

type DeviceShadow interface {
	AddDevice(device Device) (err error)
	GetDevice(deviceSn string) (device Device, err error)

	SetDevicePoint(deviceSn, pointName string, value interface{}) (err error)
	GetDevicePoint(deviceSn, pointName string) (value interface{}, err error)
	GetDevicePoints(deviceSn string) (points map[string]DevicePoint, err error)

	GetDeviceUpdateAt(deviceSn string) (time.Time, error)

	GetDeviceStatus(deviceSn string) (online bool, err error)

	SetOnline(deviceSn string) (err error)
	SetOffline(deviceSn string) (err error)

	// MayBeOffline 可能离线事件(60秒内超过3次判定离线)
	MayBeOffline(deviceSn string) (err error)

	SetOnlineChangeCallback(handlerFunc OnlineChangeCallback)

	// StopStatusListener 停止设备状态监听
	StopStatusListener()

	// GetDevices 获取所有设备
	GetDevices() []Device
}

DeviceShadow 设备影子

func NewDeviceShadow

func NewDeviceShadow() DeviceShadow

type OnlineChangeCallback

type OnlineChangeCallback func(deviceSn string, online bool) // 设备上/下线回调

Jump to

Keyboard shortcuts

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