msgThing

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2023 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package repo 本文件是提供设备模型数据存储的信息

Index

Constants

View Source
const (
	TypeProperty = "property" //事件-操作类型:属性或信息上报(Topic:$thing/up/property/{ProductID}/{DeviceName})
	TypeEvent    = "event"    //事件-操作类型:事件上报(Topic:$thing/up/event/{ProductID}/{DeviceName})
	TypeAction   = "action"   //事件-操作类型:行为上报(Topic:$thing/up/action/{ProductID}/{DeviceName})

	EventReport = "report" //设备上报的信息
	EventInfo   = "info"   //信息
	EventAlert  = "alert"  //告警
	EventFault  = "fault"  //故障
)

Variables

This section is empty.

Functions

func GetVal

func GetVal(d *schema.Define, val any) (any, error)

func ToVal

func ToVal(tp map[string]Param) (map[string]any, error)

Types

type DeviceBasicInfo added in v0.5.1

type DeviceBasicInfo struct {
	devices.Core
	Imei     string            `json:"imei,omitempty"`     //设备的 IMEI 号信息,非必填项
	Mac      string            `json:"mac,omitempty"`      //设备的 MAC 信息,非必填项
	Version  string            `json:"version,omitempty"`  //固件版本
	HardInfo string            `json:"hardInfo,omitempty"` //模组具体硬件型号
	SoftInfo string            `json:"softInfo,omitempty"` //模组软件版本
	Position *def.Point        `json:"position,omitempty"` //设备基础信息-坐标信息
	Tags     map[string]string `json:"tags,omitempty"`     //设备标签信息
}

设备基础信息

type EventData

type EventData struct {
	Identifier string         `json:"identifier"` //标识符
	Type       string         `json:"type" `      //事件类型: 信息:info  告警alert  故障:fault
	Params     map[string]any `json:"params" `    //事件参数
	TimeStamp  time.Time      `json:"timeStamp" ` //时间戳
}

EventData 事件数据

type FilterOpt

type FilterOpt struct {
	Page        def.PageInfo2
	ProductID   string
	DeviceNames []string
	DataID      string
	Types       []string //事件类型: 信息:info  告警alert  故障:fault
	Order       int32    //0:aes(默认,从久到近排序) 1:desc(时间从近到久排序)
	Interval    int64    //间隔(单位毫秒) 如果这个值不为零值 则时间的开始和结束必须有效及聚合函数不应该为空
	Fill        string   //指定窗口区间数据缺失的情况下的填充模式
	ArgFunc     string   //聚合函数 avg:平均值 first:第一个参数 last:最后一个参数 count:总数 twa: 时间加权平均函数 参考:https://docs.taosdata.com/taos-sql/function
}

FILL 语句指定某一窗口区间数据缺失的情况下的填充模式。填充模式包括以下几种: 不进行填充:NONE(默认填充模式)。 VALUE 填充:固定值填充,此时需要指定填充的数值。例如:FILL(VALUE, 1.23)。这里需要注意,最终填充的值受由相应列的类型决定,如 FILL(VALUE, 1.23),相应列为 INT 类型,则填充值为 1。 PREV 填充:使用前一个非 NULL 值填充数据。例如:FILL(PREV)。 NULL 填充:使用 NULL 填充数据。例如:FILL(NULL)。 LINEAR 填充:根据前后距离最近的非 NULL 值做线性插值填充。例如:FILL(LINEAR)。 NEXT 填充:使用下一个非 NULL 值填充数据。例如:FILL(NEXT)。

func (FilterOpt) Check

func (f FilterOpt) Check() error

type LatestFilter added in v0.4.1

type LatestFilter struct {
	ProductID  string
	DeviceName string
	DataID     string
}

type Param

type Param struct {
	Identifier string              `json:"identifier"` //标识符
	Name       string              `json:"name"`       //功能名称
	Desc       string              `json:"gesc"`       //描述
	Mode       schema.PropertyMode `json:"mode"`       //读写乐行:rw(可读可写) r(只读)
	Required   bool                `json:"required"`   //是否必须
	Type       schema.EventType    `json:"type"`       //事件类型: 信息:info  告警alert  故障:fault
	Value      struct {
		Type    schema.DataType   `json:"type"`              //参数类型:bool int string struct float timestamp array enum
		Mapping map[string]string `json:"mapping,omitempty"` //枚举及bool类型:bool enum
		Min     string            `json:"min,omitempty"`     //数值最小值:int string float
		Max     string            `json:"max,omitempty"`     //数值最大值:int string float
		Start   string            `json:"start,omitempty"`   //初始值:int float
		Step    string            `json:"step,omitempty"`    //步长:int float
		Unit    string            `json:"unit,omitempty"`    //单位:int float
		Value   any               `json:"value"`
	} `json:"value"` //数据定义
}

func (*Param) SetByDefine added in v0.5.1

func (tp *Param) SetByDefine(d *schema.Define, val any) (err error)

func (*Param) ToVal

func (tp *Param) ToVal() (any, error)

type PropertyData

type PropertyData struct {
	Identifier string    `json:"identifier"` //标识符
	Param      any       `json:"property" `  //一个属性的参数
	TimeStamp  time.Time `json:"timeStamp" ` //时间戳
}

PropertyData 属性数据

func (PropertyData) String added in v0.4.1

func (p PropertyData) String() string

type Req

type Req struct {
	deviceMsg.CommonMsg
	Params      map[string]any `json:"params,omitempty"`      //参数列表
	Identifiers []string       `json:"identifiers,omitempty"` //内为希望设备上报的属性列表,不填为获取全部
	Version     string         `json:"version,omitempty"`     //协议版本,默认为1.0。
	EventID     string         `json:"eventID,omitempty"`     //事件的 Id,在数据模板事件中定义。
	ActionID    string         `json:"actionID,omitempty"`    //数据模板中的行为标识符,由开发者自行根据设备的应用场景定义
	Type        string         `json:"type,omitempty"`        //表示获取什么类型的信息(report:表示设备上报的信息 info:信息 alert:告警 fault:故障)
}

func (Req) AddStatus

func (d Req) AddStatus(err error) Req

func (*Req) FmtReqParam added in v0.5.1

func (d *Req) FmtReqParam(t *schema.Model, tt schema.ParamType) error

func (*Req) GetTimeStamp

func (d *Req) GetTimeStamp(defaultTime int64) time.Time

func (*Req) VerifyReqParam

func (d *Req) VerifyReqParam(t *schema.Model, tt schema.ParamType) (map[string]Param, error)

校验设备上报的参数合法性

type Resp

type Resp struct {
	deviceMsg.CommonMsg
	Version  string         `json:"version,omitempty"`  //协议版本,默认为1.0。
	Type     string         `json:"type,omitempty"`     //	表示什么类型的信息。report:表示设备上报的信息
	Response map[string]any `json:"response,omitempty"` //设备行为中定义的返回参数,设备行为执行成功后,向云端返回执行结果
	ActionID string         `json:"actionID,omitempty"` //数据模板中的行为标识符,由开发者自行根据设备的应用场景定义
}

func (*Resp) FmtRespParam added in v0.6.0

func (d *Resp) FmtRespParam(t *schema.Model, id string, tt schema.ParamType) error

func (*Resp) GetTimeStamp

func (d *Resp) GetTimeStamp(defaultTime time.Time) time.Time

func (*Resp) VerifyRespParam

func (d *Resp) VerifyRespParam(t *schema.Model, id string,
	tt schema.ParamType) (map[string]Param, error)

type SchemaDataRepo

type SchemaDataRepo interface {
	// InsertEventData 插入事件数据
	InsertEventData(ctx context.Context, productID string, deviceName string, event *EventData) error
	// InsertPropertyData 插入一条属性数据
	InsertPropertyData(ctx context.Context, t *schema.Model, productID string, deviceName string, property *PropertyData) error
	// InsertPropertiesData 插入多条属性数据 params key为属性的id,val为属性的值
	InsertPropertiesData(ctx context.Context, t *schema.Model, productID string, deviceName string, params map[string]any, timestamp time.Time) error
	// GetEventDataWithID 根据事件id获取事件信息
	GetEventDataByFilter(ctx context.Context, filter FilterOpt) ([]*EventData, error)
	GetEventCountByFilter(ctx context.Context, filter FilterOpt) (int64, error)
	// GetPropertyDataByID 根据属性id获取属性信息
	GetPropertyDataByID(ctx context.Context, filter FilterOpt) ([]*PropertyData, error)
	GetLatestPropertyDataByID(ctx context.Context, filter LatestFilter) (*PropertyData, error)
	GetPropertyCountByID(ctx context.Context, filter FilterOpt) (int64, error)
}

Jump to

Keyboard shortcuts

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