Documentation
¶
Overview ¶
Package device 这个文件提供基础信息的物模型定义
Package schema 这个文件定义和模板相关的接口及dto定义
Index ¶
- Constants
- Variables
- func CheckDefine(oldDef *Define, newDef *Define) bool
- func CheckModify(oldT *Model, newT *Model) error
- func DescValidate(desc string) error
- func DoToAffordanceStr(in any) string
- func GenArray(identifier string, num int) string
- func GetArray(identifier string) (ident string, num int, ok bool)
- func GetDataName(m *Model, dataID string) string
- func IDValidate(id string) error
- func NameValidate(name string) error
- func WhereArray(db *gorm.DB, identifier string, pos string) *gorm.DB
- func WhereArray2(db sq.SelectBuilder, identifier string, pos string) sq.SelectBuilder
- type Action
- type ActionAffordance
- type ActionDir
- type ActionMap
- type ActionSimple
- type Actions
- type ActionsSimple
- type AffordanceType
- type BasicParam
- type CommonParam
- type DataIDInfo
- type DataType
- type Define
- func (d Define) Copy() Define
- func (d *Define) FmtValue(val any) (any, error)
- func (d *Define) GenRandValue() any
- func (d *Define) GetDefaultValue() (retAny any, err error)
- func (d *Define) GetValueDesc(value any) string
- func (d *Define) String() string
- func (d Define) ToSimple() Define
- func (d *Define) ValidateWithFmt() error
- func (d *Define) ValidateWithFmtArray(isMatrix bool) error
- func (d *Define) ValidateWithFmtBool() error
- func (d *Define) ValidateWithFmtEnum() error
- func (d *Define) ValidateWithFmtFloat() error
- func (d *Define) ValidateWithFmtInt() error
- func (d *Define) ValidateWithFmtString() error
- func (d *Define) ValidateWithFmtStruct() error
- func (d *Define) ValidateWithFmtTimeStamp() error
- type Event
- type EventAffordance
- type EventMap
- type EventSimple
- type EventType
- type Events
- type EventsSimple
- type GetSchemaModel
- type Info
- type Model
- type ModelSimple
- type Param
- type ParamSimple
- type ParamSimples
- type ParamType
- type Params
- type Profile
- type Properties
- type PropertiesSimple
- type Property
- type PropertyAffordance
- type PropertyMap
- type PropertyMode
- type PropertySimple
- type ReadRepo
- type RecordMode
- type Repo
- type Spec
- type Specs
- type Tag
Constants ¶
View Source
const ( IDFFormatCheck = true //是否检查ID是否以数字开头 IDLen = 128 //标识符的长度 NameLen = 128 //参数名称的长度 DescLen = 80 //描述的最大长度 DefineMappingLen = 50 DefineUnitLen = 12 DefineIntMax = 9999999999999 DefineIntMin = -9999999999999 DefineStringMax = 2048 DefineArrayMax = 1024 DefineSpecsLen = 20 ParamsLen = 20 )
Variables ¶
View Source
var (
DefaultSchema string
)
Functions ¶
func CheckDefine ¶
func CheckModify ¶
func DescValidate ¶
func DoToAffordanceStr ¶
func GetDataName ¶ added in v1.5.34
func IDValidate ¶
func NameValidate ¶
func WhereArray ¶ added in v1.5.15
func WhereArray2 ¶ added in v1.5.15
func WhereArray2(db sq.SelectBuilder, identifier string, pos string) sq.SelectBuilder
Types ¶
type Action ¶
type Action struct {
CommonParam
Dir ActionDir `json:"dir"` //调用方向
Input Params `json:"input"` //调用参数
Output Params `json:"output"` //返回参数,如果没有返回参数,设备端可以不回复
In map[string]*Param `json:"-"` //内部使用,使用map加速匹配,key为id
Out map[string]*Param `json:"-"` //内部使用,使用map加速匹配,key为id
}
行为
func ActionFromCommonSchema ¶
func (*Action) ValidateWithFmt ¶
type ActionAffordance ¶
type ActionSimple ¶
type ActionSimple struct {
Identifier string `json:"id"` //标识符 (统一)
Name string `json:"name"` //功能名称
Dir ActionDir `json:"dir"` //调用方向
Input ParamSimples `json:"input"` //调用参数
Output ParamSimples `json:"output"` //返回参数
}
行为
type ActionsSimple ¶
type ActionsSimple []ActionSimple
type AffordanceType ¶
type AffordanceType int64
物模型功能类型 1:property属性 2:event事件 3:action行为
const ( //物模型功能类型:1-property 属性 AffordanceTypeProperty AffordanceType = 1 //物模型功能类型:2-event 事件 AffordanceTypeEvent AffordanceType = 2 //物模型功能类型:3-action 行为 AffordanceTypeAction AffordanceType = 3 )
func (AffordanceType) String ¶
func (m AffordanceType) String() string
type BasicParam ¶
type BasicParam struct {
Name string `json:"name"` //设备名(是否保留待定)
Imei string `json:"imei"` //设备的 IMEI 号信息,非必填项
FwVer string `json:"fwVer"` //mcu固件版本
ModuleHardInfo string `json:"moduleHardInfo"` //模组具体硬件型号
ModuleSoftInfo string `json:"moduleSoftInfo"` //模组软件版本
Mac string `json:"mac"` //设备的 MAC 信息,非必填项
DeviceLabel map[string]string `json:"deviceLabel"` //设备商自定义的产品基础信息,以 KV 方式上报
}
BasicParam 小程序或 App 展示设备详细信息时,一般会展示设备的 MAC 地址、IMEI 号、时区等基础信息。设备信息上报使用的 Topic: 上行请求 Topic: $thing/up/property/{ProductID}/{DeviceName} 下行响应 Topic: $thing/down/property/{ProductID}/{DeviceName}
type CommonParam ¶
type CommonParam struct {
Identifier string `json:"identifier"` //标识符 (统一)
Tag Tag `json:"tag"` //物模型标签 1:自定义 2:可选 3:必选 必选不可删除
Name string `json:"name"` //功能名称
Desc string `json:"desc"` //描述
Required bool `json:"required"` //是否必须
ExtendConfig string `json:"extendConfig"` //拓展参数,json格式
IsCanSceneLinkage int64 `json:"isCanSceneLinkage"` //是否支持场景联动控制 (统一)
FuncGroup int64 `json:"funcGroup"` // 功能分类: 1:普通功能 2:系统功能
ControlMode int64 `json:"controlMode"` //控制模式: 1: 可以群控,可以单控 2:只能单控
UserPerm int64 `json:"userPerm"` //用户权限操作: 1:r(只读) 3:rw(可读可写)
RecordMode RecordMode `json:"recordMode"` // 1(默认) 记录历史记录 2 只记录差异值 3 不记录历史记录
IsPassword def.Bool `json:"isPassword"` //是否是密码类型,密码类型需要加掩码
Order int64 `json:"order"` //排序
}
func CommonParamFromCommonSchema ¶
func CommonParamFromCommonSchema(product CommonParam, common CommonParam) CommonParam
type DataIDInfo ¶ added in v1.5.15
func ParseDataID ¶ added in v1.5.15
func ParseDataID(identifier string) (*DataIDInfo, error)
type DataType ¶
type DataType string
数据类型
const ( DataTypeBool DataType = "bool" DataTypeInt DataType = "int" DataTypeString DataType = "string" DataTypeStruct DataType = "struct" DataTypeFloat DataType = "float" DataTypeTimestamp DataType = "timestamp" //时间戳, 毫秒级时间戳 DataTypeArray DataType = "array" //数组,可以使用 a.2=3 的方式修改数组的第二个元素,也可以使用 a[2,3] 的方式修改 DataTypeMatrix DataType = "matrix" //矩阵, 只能使用[123,34]的方式 DataTypeEnum DataType = "enum" //枚举, 只能使用预定义的值 )
type Define ¶
type Define struct {
Type DataType `json:"type"` //参数类型:bool int string struct float timestamp array matrix enum
Mapping map[string]string `json:"mapping,omitempty"` //枚举及bool类型:bool enum
Min string `json:"min,omitempty"` //数值最小值:int float
Max string `json:"max,omitempty"` //数值最大值:int string float array matrix
Start string `json:"start,omitempty"` //初始值:int float
Step string `json:"step,omitempty"` //步长:int float
Unit string `json:"unit,omitempty"` //单位:int float
Specs Specs `json:"specs,omitempty"` //结构体:struct
ArrayInfo *Define `json:"arrayInfo,omitempty"` //数组:array matrix
Spec map[string]*Spec `json:"-"` //内部使用,使用map加速匹配,key为id
}
数据类型定义
func (*Define) GetDefaultValue ¶
func (*Define) GetValueDesc ¶
func (*Define) ValidateWithFmt ¶
func (*Define) ValidateWithFmtArray ¶
func (*Define) ValidateWithFmtBool ¶
func (*Define) ValidateWithFmtEnum ¶
func (*Define) ValidateWithFmtFloat ¶
func (*Define) ValidateWithFmtInt ¶
func (*Define) ValidateWithFmtString ¶
func (*Define) ValidateWithFmtStruct ¶
func (*Define) ValidateWithFmtTimeStamp ¶
type Event ¶
type Event struct {
CommonParam
Type EventType `json:"type"` //事件类型: 1:信息:info 2:告警alert 3:故障:fault
Params Params `json:"params"` //事件参数
Param map[string]*Param `json:"-"` //内部使用,使用map加速匹配,key为id
}
事件
func EventFromCommonSchema ¶
func (*Event) ValidateWithFmt ¶
type EventAffordance ¶
type EventSimple ¶
type EventSimple struct {
Identifier string `json:"id"` //标识符 (统一)
Name string `json:"name"` //功能名称
Type EventType `json:"type"` //事件类型: 1:信息:info 2:告警alert 3:故障:fault
Params ParamSimples `json:"params"` //事件参数
}
事件
type EventsSimple ¶
type EventsSimple []EventSimple
type GetSchemaModel ¶
type Model ¶
type Model struct {
Version string `json:"version,omitempty"` //版本号
Properties Properties `json:"properties,omitempty"` //属性
Events Events `json:"events,omitempty"` //事件
Actions Actions `json:"actions,omitempty"` //行为
Profile Profile `json:"profile"` //配置信息
Property PropertyMap `json:"-"` //内部使用,使用map加速匹配,key为id
Event EventMap `json:"-"` //内部使用,使用map加速匹配,key为id
Action ActionMap `json:"-"` //内部使用,使用map加速匹配,key为id
}
Model 物模型协议-数据模板定义
func NewSchemaTsl ¶
func ValidateWithFmt ¶
func (*Model) Aggregation ¶
func (*Model) ToSimple ¶
func (m *Model) ToSimple() *ModelSimple
func (*Model) ValidateWithFmt ¶
type ModelSimple ¶
type ModelSimple struct {
Properties PropertiesSimple `json:"properties,omitempty"` //属性
Events EventsSimple `json:"events,omitempty"` //事件
Actions ActionsSimple `json:"actions,omitempty"` //行为
}
Model 物模型协议-数据模板定义
func (*ModelSimple) ToHumanDesc ¶ added in v1.4.4
func (m *ModelSimple) ToHumanDesc() string
转换成人看得懂的描述
func (*ModelSimple) ToModel ¶
func (m *ModelSimple) ToModel() *Model
type Param ¶
type Param struct {
Identifier string `json:"identifier"` //参数标识符
Name string `json:"name"` //参数名称
Define Define `json:"define,omitempty"` //参数定义
}
参数
func (Param) ToSimple ¶
func (p Param) ToSimple() ParamSimple
func (*Param) ValidateWithFmt ¶
type ParamSimple ¶
type ParamSimple struct {
Identifier string `json:"id"` //参数标识符
Name string `json:"name"` //参数名称
Define //参数定义
}
func (ParamSimple) ToModel ¶
func (p ParamSimple) ToModel() Param
type ParamSimples ¶
type ParamSimples []ParamSimple
func (ParamSimples) ToModel ¶
func (p ParamSimples) ToModel() Params
type Params ¶
type Params []Param
func (Params) ToSimple ¶
func (p Params) ToSimple() ParamSimples
func (Params) ValidateWithFmt ¶
type Properties ¶
type Properties []Property
type PropertiesSimple ¶
type PropertiesSimple []PropertySimple
type Property ¶
type Property struct {
CommonParam
Mode PropertyMode `json:"mode"` //读写类型:rw(可读可写) r(只读)
Define Define `json:"define"` //数据定义
IsUseShadow bool `json:"isUseShadow"` //是否使用设备影子
IsNoRecord bool `json:"isNoRecord"` //不存储历史记录
}
属性
func (*Property) ValidateWithFmt ¶
type PropertyAffordance ¶
type PropertyAffordance struct {
IsUseShadow bool `json:"isUseShadow"` //是否使用设备影子
IsNoRecord bool `json:"isNoRecord"` //不存储历史记录
Define Define `json:"define"` //数据定义
Mode PropertyMode `json:"mode"` //读写类型: 1:r(只读) 2:rw(可读可写)
}
func DoToPropertyAffordance ¶
func DoToPropertyAffordance(in *Property) *PropertyAffordance
type PropertyMap ¶
内部使用
func (*PropertyMap) GetIDs ¶
func (p *PropertyMap) GetIDs() []string
func (*PropertyMap) GetMap ¶
func (p *PropertyMap) GetMap() map[string]*Property
func (*PropertyMap) GetMapWithIDs ¶
func (p *PropertyMap) GetMapWithIDs(datas ...string) map[string]*Property
type PropertyMode ¶
type PropertyMode string
属性读写类型: r(只读) rw(可读可写)
const ( PropertyModeR PropertyMode = "r" PropertyModeRW PropertyMode = "rw" )
type PropertySimple ¶
type PropertySimple struct {
Identifier string `json:"id"` //标识符 (统一)
Name string `json:"name"` //功能名称
Mode PropertyMode `json:"mode"` //读写类型:rw(可读可写) r(只读)
Define //数据定义
}
属性
type RecordMode ¶ added in v1.5.5
type RecordMode = int64
const ( RecordModeAll RecordMode = 1 //全部记录 RecordModeAuto RecordMode = 2 //只记录差异值 RecordModeNone RecordMode = 3 //不记录 )
type Spec ¶
type Spec struct {
Identifier string `json:"identifier"` //参数标识符
Name string `json:"name"` //参数名称
DataType Define `json:"dataType"` //参数定义
}
结构体说明
func (*Spec) ValidateWithFmt ¶
Click to show internal directories.
Click to hide internal directories.