device.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. File []byte `json:"file"`
  49. FileName string `json:"file_name"`
  50. FileSize int64 `json:"file_size"`
  51. }
  52. // Validate 验证
  53. func (a *UpgradeParams) Validate() error {
  54. if a.DeviceID == "" {
  55. return errors.New("非法参数[DeviceID, Label]")
  56. }
  57. return nil
  58. }
  59. type Command string
  60. const (
  61. Report Command = "report" // 获取设备状态
  62. Restart Command = "restart" // 重启设备
  63. ClearData Command = "clearData" // 清除设备配置数据
  64. SetDataTrans Command = "setDataTrans" // 设备端自动上报配置
  65. GetInfo Command = "getInfo" // 获取网关信息(分控)
  66. ForceRun Command = "forceRun" // 远程控制某个模块强制运行
  67. SetDeviceId Command = "setDeviceId" // 写入设备 ID
  68. SetFjsqStatus Command = "setFjsqStatus" // 智能分集水器控制
  69. SetOutdoorPower Command = "setOutdoorPower" // 设置水系统外机电源状态
  70. SetOutdoorTemp Command = "setOutdoorTemp" // 设置水系统外机出水温度
  71. )
  72. type SendCommandParams struct {
  73. DeviceId string `json:"device_id"`
  74. Enable int `json:"enable"` // 是否启用(0:禁用,1:启用)
  75. Internal int `json:"internal"` // 间隔时间,单位:秒,范围:30~180,默认:30秒
  76. Module int `json:"module"` // 对应模块(1:新风模块2:加湿模块)
  77. ModulePower int `json:"module_power"` // 电源状态,1:开启,2关闭
  78. Id int `json:"id"` // 长度12个字节,如 YHK-16777216
  79. Prefix string `json:"prefix"` // 字符串
  80. Num int `json:"num"` // 1-8 对应1-8路电热执行器
  81. NumPower int `json:"num_power"` // 1:开启,0:关闭
  82. OutdoorPower int `json:"outdoor_power"` // 1:开启,0:关闭
  83. CoolModeTemp int `json:"cool_mode_temp"` // 制冷模式出水温度,0:代表不设置
  84. HeatModeTemp int `json:"heat_mode_temp"` // 制热模式出水温度,0:代表不设置
  85. }
  86. // Validate 验证
  87. func (a *SendCommandParams) Validate() error {
  88. if a.DeviceId == "" {
  89. return errors.New("非法参数[DeviceID, Label]")
  90. }
  91. return nil
  92. }
  93. type SplitDeviceStatus struct {
  94. Power int `json:"power"`
  95. Mode int `json:"mode"`
  96. FanSpeed int `json:"fan_speed"`
  97. SetTemp int `json:"set_temp"`
  98. EnvTemp int `json:"env_temp"`
  99. EnvHumidity int `json:"env_humidity"`
  100. EnvCo2 int `json:"env_co2"`
  101. EnvPm25 int `json:"env_pm25"`
  102. StatusCode int `json:"status_code"`
  103. StatusCodeMap map[string]int `json:"status_code_map"`
  104. AirMode int `json:"air_mode"`
  105. AcType int `json:"ac_type"`
  106. AirType int `json:"air_type"`
  107. HumType int `json:"hum_type"`
  108. }