device.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. package models
  2. import (
  3. "errors"
  4. "github.com/jinzhu/gorm"
  5. )
  6. // Device device model
  7. // device is a product instance, which is managed by our platform
  8. type Device struct {
  9. gorm.Model
  10. RecordId string `gorm:"column:record_id;size:32;index"`
  11. // which product the device belongs to
  12. ProductID string `gorm:"column:product_id;size:32;index"`
  13. // universal device identifier, generated from vendorid-productid-deviceserial
  14. DeviceIdentifier string `sql:"type:varchar(200);not null;unique;key"`
  15. // device secret which is auto generated by the platform
  16. DeviceSecret string `sql:"type:varchar(200);not null;"`
  17. // device key is used to auth a device
  18. DeviceKey string `sql:"type:varchar(200);not null;key;"`
  19. // device name
  20. DeviceName string `sql:"type:varchar(200);not null;"`
  21. // device desc
  22. DeviceDescription string `sql:"type:text;not null;"`
  23. // device version(the agent version)
  24. DeviceVersion string `sql:"type:text;not null;"`
  25. // vendor id
  26. VendorID string `gorm:"column:vendor_id;size:32;index"`
  27. //通讯模组名称
  28. ModuleName string
  29. }
  30. // DeviceQuery device query
  31. type DeviceQuery struct {
  32. Device
  33. ProductName string
  34. }
  35. // Devices
  36. type Devices struct {
  37. Device
  38. Status int
  39. }
  40. // DeviceChartData 设备数据图表
  41. type DeviceChartData struct {
  42. Dt string
  43. Count int
  44. }
  45. type UpgradeParams struct {
  46. VendorID string `json:"vendor_id"`
  47. DeviceID string `json:"device_id"`
  48. FileID int `json:"file_id"`
  49. File []byte `json:"file"`
  50. FileName string `json:"file_name"`
  51. FileSize int64 `json:"file_size"`
  52. }
  53. // Validate 验证
  54. func (a *UpgradeParams) Validate() error {
  55. if a.DeviceID == "" {
  56. return errors.New("非法参数[DeviceIDs, Label]")
  57. }
  58. return nil
  59. }
  60. type Command string
  61. const (
  62. Report Command = "report" // 获取设备状态
  63. Restart Command = "restart" // 重启设备
  64. ClearData Command = "clearData" // 清除设备配置数据
  65. SetDataTrans Command = "setDataTrans" // 设备端自动上报配置
  66. GetInfo Command = "getInfo" // 获取网关信息(分控)
  67. ForceRun Command = "forceRun" // 远程控制某个模块强制运行
  68. SetDeviceId Command = "setDeviceId" // 写入设备 ID
  69. SetFjsqStatus Command = "setFjsqStatus" // 智能分集水器控制
  70. SetOutdoorPower Command = "setOutdoorPower" // 设置水系统外机电源状态
  71. SetOutdoorTemp Command = "setOutdoorTemp" // 设置水系统外机出水温度
  72. OtaUpgrade Command = "devUpgrade" // ota升级
  73. )
  74. type SendCommandParams struct {
  75. DeviceId string `json:"device_id"`
  76. Enable int `json:"enable"` // 是否启用(0:禁用,1:启用)
  77. Internal int `json:"internal"` // 间隔时间,单位:秒,范围:30~180,默认:30秒
  78. Module int `json:"module"` // 对应模块(1:新风模块2:加湿模块)
  79. ModulePower int `json:"module_power"` // 电源状态,1:开启,2关闭
  80. Id int `json:"id"` // 长度12个字节,如 YHK-16777216
  81. Prefix string `json:"prefix"` // 字符串
  82. Num int `json:"num"` // 1-8 对应1-8路电热执行器
  83. NumPower int `json:"num_power"` // 1:开启,0:关闭
  84. OutdoorPower int `json:"outdoor_power"` // 1:开启,0:关闭
  85. CoolModeTemp int `json:"cool_mode_temp"` // 制冷模式出水温度,0:代表不设置
  86. HeatModeTemp int `json:"heat_mode_temp"` // 制热模式出水温度,0:代表不设置
  87. }
  88. // Validate 验证
  89. func (a *SendCommandParams) Validate() error {
  90. if a.DeviceId == "" {
  91. return errors.New("非法参数[DeviceIDs, Label]")
  92. }
  93. return nil
  94. }
  95. type SplitDeviceStatus struct {
  96. Power int `json:"power"`
  97. Mode int `json:"mode"`
  98. FanSpeed int `json:"fan_speed"`
  99. SetTemp int `json:"set_temp"`
  100. EnvTemp int `json:"env_temp"`
  101. EnvHumidity int `json:"env_humidity"`
  102. EnvCo2 int `json:"env_co2"`
  103. EnvPm25 int `json:"env_pm25"`
  104. StatusCode int `json:"status_code"`
  105. StatusCodeMap map[string]int `json:"status_code_map"`
  106. AirMode int `json:"air_mode"`
  107. AcType int `json:"ac_type"`
  108. AirType int `json:"air_type"`
  109. HumType int `json:"hum_type"`
  110. }