commons

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2023 License: MIT Imports: 8 Imported by: 5

Documentation

Index

Constants

View Source
const (
	// 设备激活状态 未激活、已激活、激活失败
	DeviceActiveStatusInactivated = "inactivated"
	DeviceActiveStatusActivated   = "activated"
	DeviceActiveStatusActiveFail  = "activeFail"
)

//////////////////////////////////////////////////////////////////////////// device

View Source
const (
	DEVICE_REPORT_EVENT = "report"
	DEVICE_ALERT_EVENT  = "alert"
)
View Source
const (
	DebugLevel = "DEBUG"
	InfoLevel  = "INFO"
	WarnLevel  = "WARN"
	ErrorLevel = "ERROR"
)
View Source
const SDKVersion = "v1.0.0"

Variables

Functions

This section is empty.

Types

type AlertLevel

type AlertLevel int

////////////////////////////////////////////////////////////////////////////

const (
	ERROR AlertLevel = iota + 1
	WARN
	NOTIFY
)

type AppCallBack added in v1.0.2

type AppCallBack func(appName string, req AppDriverReq) (Response, error)

type AppDriverReq

type AppDriverReq struct {
	Header  *Header
	Payload []byte
}

func (*AppDriverReq) ToRpc

func (req *AppDriverReq) ToRpc() *proto.Data

type BaseProperty

type BaseProperty struct {
	Name string `json:"name"` //子设备名
	Ip   string `json:"ip"`   //子设备IP地址
	Lat  string `json:"lat"`  //纬度
	Lon  string `json:"lon"`  //经度
}

BaseProperty 子设备基础属性:子设备名、IP地址、经度、纬度

type DataType

type DataType string
const (
	ValueType  DataType = "value" // int64
	BoolType   DataType = "bool"
	StringType DataType = "string"
	RawType    DataType = "raw"   // []byte
	EnumType   DataType = "enum"  // string
	FaultType  DataType = "fault" // []string
	FlotType   DataType = "float"
	DoubleType DataType = "double"
	DateType   DataType = "date"
	BitmapType DataType = "bitmap"
	StructType DataType = "struct"
	ArrayType  DataType = "array"
)

type DeviceInfo

type DeviceInfo struct {
	DeviceMeta           // 原始信息
	ActiveStatus  string // 设备激活状态
	OnLineStatus  string // 设备在线/离线状态
	CloudDeviceId string // 设备云端对应的🆔(如果设备已激活)
}

DeviceInfo 回调接口, 包含激活信息

type DeviceMeta

type DeviceMeta struct {
	Cid          string                        `json:"cid"`          //子设备cid,网关下唯一
	ProductId    string                        `json:"productKey"`   //产品id
	BaseAttr     BaseProperty                  `json:"baseAttr"`     //设备属性
	ExtendedAttr ExtendedProperty              `json:"extendedAttr"` //设备属性
	Protocols    map[string]ProtocolProperties `json:"protocols"`    //设备自定义协议配置
}

DeviceMeta 新增子设备

type DeviceNotifyType

type DeviceNotifyType string
const (
	DeviceAddNotify    DeviceNotifyType = "add"
	DeviceUpdateNotify DeviceNotifyType = "update"
	DeviceDeleteNotify DeviceNotifyType = "delete"
	DeviceActiveNotify DeviceNotifyType = "active"
)

type DeviceOnlineStatus

type DeviceOnlineStatus string
const (
	Online  DeviceOnlineStatus = "online"
	Offline DeviceOnlineStatus = "offline"
)

type DeviceStatus

type DeviceStatus struct {
	Online  []string // 设备上线列表
	Offline []string // 设备下线列表
}

DeviceStatus device status 设备状态上报

type ExtendedProperty

type ExtendedProperty struct {
	//VendorCode      string                 `json:"vendorCode"`      //设备厂商
	InstallLocation string                 `json:"installLocation"` //安装地址
	ExtendData      map[string]interface{} `json:"extendData"`      //扩展字段 //map[string]interface{}
}

ExtendedProperty 子设备扩展属性

type GatewayInfo

type GatewayInfo struct {
	GwId        string `json:"gwId"`
	LocalKey    string `json:"localKey"`
	Env         string `json:"env"`
	Region      string `json:"region"`
	Mode        RunningModel
	CloudState  bool   `json:"cloudState"`
	GatewayName string `json:"gatewayName"`
}
type Header struct {
	Tag    string
	From   string
	Option map[string]string
}

type LoggerConfig

type LoggerConfig struct {
	FileName   string
	Prefix     string // service name
	LogLevel   string
	MaxSize    int
	MaxBackups int
	MaxAge     int
	Compress   bool
}

type MqttDriver

type MqttDriver interface {
	// Auth mqtt设备连接鉴权,broker会将与该驱动相关的mqtt设备连接鉴权信息转发给sdk,sdk会回调该接口,将鉴
	// 权信息发送给驱动应用层做校验,鉴权通过返回true,mqtt broker允许连接,否则拒接连接。
	// clientId:mqtt设备连接时指定的clientID
	// username:mqtt设备连接时指定的username
	// password: mqtt设备连接时指定的password
	Auth(clientId, username, password string) (bool, error)
	// Sub mqtt设备订阅topic校验,broker会将与该驱动相关的mqtt设备订阅topic的信息转发给sdk,sdk会回调该接
	// 口,将topic校验信息发送给驱动应用层做校验,校验通过返回true,mqtt broker允许订阅,否则拒绝订阅。
	// topic:设备要订阅的topic
	// qos:设备要订阅topic的QoS
	Sub(clientId, username, topic string, qos byte) (bool, error)
	// Pub mqtt设备向topic中发布消息前校验,broker会将与该驱动相关的mqtt设备要发布消息的topic的信息转发给
	// sdk,sdk会回调该接口,将topic校验信息发送给驱动应用层做校验,校验通过返回true,mqtt broker允许发布
	// 消息,否则拒绝发布消息
	Pub(clientId, username, topic string, qos byte, retained bool) (bool, error)
	// UnSub mqtt设备取消订阅通知,mqtt设备取消订阅topic后broker会将取消订阅topic的消息通知给对应的驱动
	UnSub(clientId, username string, topics []string)
	// Connected mqtt设备连接成功通知,mqtt设备连接成功后broker会将连接成功消息通知给对应的驱动
	Connected(clientId, username, ip, port string)
	// Closed mqtt设备断开连接后通知,mqtt设备断开连接后broker会将断开连接信息通知给对应的驱动
	Closed(clientId, username string)
}

type Option added in v1.0.2

type Option interface {
	Apply(*Options)
}

type Options added in v1.0.2

type Options struct {
	MqttUsername   string
	MqttDriver     MqttDriver
	ConnHandler    mqtt.OnConnectHandler
	AppService     []string
	AppDataHandler AppCallBack
	EnableRTS      bool
}

func DefaultOptions added in v1.0.2

func DefaultOptions() Options

type ProductNotifyType

type ProductNotifyType string

////////////////////////////////////////////////////////////////////////////

const (
	ProductAddNotify    ProductNotifyType = "add"
	ProductUpdateNotify ProductNotifyType = "update"
	ProductDeleteNotify ProductNotifyType = "delete"
)

type ProtocolProperties

type ProtocolProperties map[string]interface{}

ProtocolProperties 子设备的自定义配置,通过config.json配置

type ProxyInfo

type ProxyInfo struct {
	Host string `json:"host"`
	Port int    `json:"port"`
}

////////////////////////////////////////////////////////////////////////////////////

func DefaultProxyInfo

func DefaultProxyInfo(port int) ProxyInfo

type RWType

type RWType string

////////////////////////////////////////////////////////////////////////////

const (
	ReadOnly  RWType = "ro" // 只上报
	WriteOnly RWType = "wo" // 只下发
	ReadWrite RWType = "rw" // 可上报可下发
)

type Response

type Response struct {
	Success bool   `json:"success"`
	Message string `json:"message"`
	Payload []byte `json:"payload"`
}

type RunningModel

type RunningModel string
const (
	// DPModel dp模型
	DPModel RunningModel = "dp_model"
	// ThingModel 物模型
	ThingModel RunningModel = "thing_model"
)

type SubDataType

type SubDataType string

///////////////////////////////////////////////////////////////////////////////////

const (
	ValueTypeUint8   SubDataType = "uint8"
	ValueTypeUint16  SubDataType = "uint16"
	ValueTypeUint32  SubDataType = "uint32"
	ValueTypeUint64  SubDataType = "uint64"
	ValueTypeInt8    SubDataType = "int8"
	ValueTypeInt16   SubDataType = "int16"
	ValueTypeInt32   SubDataType = "int32"
	ValueTypeInt64   SubDataType = "int64"
	ValueTypeFloat32 SubDataType = "float32"
	ValueTypeFloat64 SubDataType = "float64"
)

type TMDeviceInfo

type TMDeviceInfo struct {
	TMDeviceMeta `json:",inline"`
	DeviceId     string `json:"deviceId"`     // 设备在云端的IotId
	ActiveStatus string `json:"activeStatus"` // 设备激活状态
	OnLineStatus string `json:"onlineStatus"` // 设备在线/离线状态
}

TMDeviceInfo 物模型设备信息

type TMDeviceMeta

type TMDeviceMeta struct {
	Cid          string                        `json:"cid"`          //子设备cid,网关下唯一
	ProductId    string                        `json:"productKey"`   //产品pid
	BaseAttr     BaseProperty                  `json:"baseAttr"`     //设备属性
	ExtendedAttr ExtendedProperty              `json:"extendedAttr"` //设备属性
	Protocols    map[string]ProtocolProperties `json:"protocols"`    //设备自定义协议配置
}

TMDeviceMeta 物模型设备添加

type TedgeLogger

type TedgeLogger interface {
	SetLogLevel(level string)
	Debugf(template string, args ...interface{})
	Infof(template string, args ...interface{})
	Warnf(template string, args ...interface{})
	Errorf(template string, args ...interface{})
}

func DefaultLogger

func DefaultLogger(logLevel, serviceName string) TedgeLogger

func NewDefaultLogger

func NewDefaultLogger(fileName, logLevel, serviceName string) TedgeLogger

Jump to

Keyboard shortcuts

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