package models import ( "errors" "github.com/jinzhu/gorm" ) // Device device model // device is a product instance, which is managed by our platform type Device struct { gorm.Model RecordId string `gorm:"column:record_id;size:32;index"` // which product the device belongs to ProductID string `gorm:"column:product_id;size:32;index"` // universal device identifier, generated from vendorid-productid-deviceserial DeviceIdentifier string `sql:"type:varchar(200);not null;unique;key"` // device secret which is auto generated by the platform DeviceSecret string `sql:"type:varchar(200);not null;"` // device key is used to auth a device DeviceKey string `sql:"type:varchar(200);not null;key;"` // device name DeviceName string `sql:"type:varchar(200);not null;"` // device desc DeviceDescription string `sql:"type:text;not null;"` // device version(the agent version) DeviceVersion string `sql:"type:text;not null;"` // vendor id VendorID string `gorm:"column:vendor_id;size:32;index"` //通讯模组名称 ModuleName string // 备注 Memo string `sql:"type:varchar(50);"` } // DeviceQuery device query type DeviceQuery struct { Device ProductName string } // Devices type Devices struct { Device Status int } // Validate 验证 func (a *Device) Validate() error { return nil } // DeviceChartData 设备数据图表 type DeviceChartData struct { Dt string Count int } type UpgradeParams struct { VendorID string `json:"vendor_id"` DeviceID string `json:"device_id"` FileID int `json:"file_id"` File []byte `json:"file"` FileName string `json:"file_name"` FileSize int64 `json:"file_size"` } // Validate 验证 func (a *UpgradeParams) Validate() error { if a.DeviceID == "" { return errors.New("非法参数[DeviceIDs, Label]") } return nil } type Command string const ( Report Command = "report" // 获取设备状态 Restart Command = "restart" // 重启设备 ClearData Command = "clearData" // 清除设备配置数据 SetDataTrans Command = "setDataTrans" // 设备端自动上报配置 GetInfo Command = "getInfo" // 获取网关信息(分控) ForceRun Command = "forceRun" // 远程控制某个模块强制运行 SetDeviceId Command = "setDeviceId" // 写入设备 ID SetFjsqStatus Command = "setFjsqStatus" // 智能分集水器控制 SetOutdoorPower Command = "setOutdoorPower" // 设置水系统外机电源状态 SetOutdoorTemp Command = "setOutdoorTemp" // 设置水系统外机出水温度 OtaUpgrade Command = "devUpgrade" // ota升级 ) type SendCommandParams struct { DeviceId string `json:"device_id"` Enable int `json:"enable"` // 是否启用(0:禁用,1:启用) Internal int `json:"internal"` // 间隔时间,单位:秒,范围:30~180,默认:30秒 Module int `json:"module"` // 对应模块(1:新风模块2:加湿模块) ModulePower int `json:"module_power"` // 电源状态,1:开启,2关闭 Id int `json:"id"` // 长度12个字节,如 YHK-16777216 Prefix string `json:"prefix"` // 字符串 Num int `json:"num"` // 1-8 对应1-8路电热执行器 NumPower int `json:"num_power"` // 1:开启,0:关闭 OutdoorPower int `json:"outdoor_power"` // 1:开启,0:关闭 CoolModeTemp int `json:"cool_mode_temp"` // 制冷模式出水温度,0:代表不设置 HeatModeTemp int `json:"heat_mode_temp"` // 制热模式出水温度,0:代表不设置 } // Validate 验证 func (a *SendCommandParams) Validate() error { if a.DeviceId == "" { return errors.New("非法参数[DeviceIDs, Label]") } return nil } type SplitDeviceStatus struct { Power int `json:"power"` Mode int `json:"mode"` FanSpeed int `json:"fan_speed"` SetTemp int `json:"set_temp"` EnvTemp int `json:"env_temp"` EnvHumidity int `json:"env_humidity"` EnvCo2 int `json:"env_co2"` EnvPm25 int `json:"env_pm25"` StatusCode int `json:"status_code"` StatusCodeMap map[string]int `json:"status_code_map"` AirMode int `json:"air_mode"` AcType int `json:"ac_type"` AirType int `json:"air_type"` HumType int `json:"hum_type"` }