device.go 4.4 KB

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