dtuDevice.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package dataStruct
  2. import "encoding/json"
  3. type DTUDevice struct {
  4. SN string `json:"sn"`
  5. Name string `json:"name"`
  6. SimId string `json:"simId"`
  7. Configs string `json:"configs"`
  8. TmOnline string `json:"tmOnline"`
  9. TmOffline string `json:"tmOffline"`
  10. }
  11. type DTUDeviceState struct {
  12. Info *DTUDevice `json:"info"`
  13. Online bool `json:"online"` //true在线
  14. PwrOff bool `json:"pwrOff"` //true掉电
  15. }
  16. type DtuDevice struct {
  17. ID int `json:"id"` // 设备ID
  18. Enable bool `json:"enable"` // 是否启用
  19. SN string `json:"sn"` // 设备编码SN
  20. Name string `json:"name"` // 设备名称
  21. SimId string `json:"simId"` // sim卡ID
  22. IP string `json:"ip"` // 平台IP
  23. Port int `json:"port"` // 平台端口
  24. Protocol string `json:"protocol"` // 平台协议
  25. Pw string `json:"pw"` // 平台密码
  26. Mn string `json:"mn"` // 设备MN
  27. Secs int `json:"secs"` // 上报周期
  28. St string `json:"st"` // 设备ST
  29. Cn string `json:"cn"` // 设备CN
  30. Others string `json:"others"` // 其他
  31. Slave []DtuSlave `json:"slave"` // 从机
  32. }
  33. func (d *DtuDevice) ToDtu() (*DTUDevice, error) {
  34. var dtuSlave []*DtuSlave
  35. for _, slave := range d.Slave {
  36. dtuSlave = append(dtuSlave, &DtuSlave{
  37. Addr: slave.Addr,
  38. BmYz: slave.BmYz,
  39. LvRef: slave.LvRef,
  40. MType: slave.MType,
  41. PvRef: slave.PvRef,
  42. NO: slave.NO,
  43. })
  44. }
  45. dtuConfig := &DtuConfig{
  46. Enable: d.Enable,
  47. ID: d.ID,
  48. IP: d.IP,
  49. Secs: d.Secs,
  50. St: d.St,
  51. Cn: d.Cn,
  52. Others: d.Others,
  53. Port: d.Port,
  54. Protocol: d.Protocol,
  55. Pw: d.Pw,
  56. Mn: d.Mn,
  57. Slave: dtuSlave,
  58. }
  59. dtuConfigStr, err := json.Marshal(dtuConfig)
  60. if err != nil {
  61. return nil, err
  62. }
  63. dtuDevice := &DTUDevice{
  64. Configs: string(dtuConfigStr),
  65. Name: d.Name,
  66. SimId: d.SimId,
  67. SN: d.SN,
  68. }
  69. return dtuDevice, nil
  70. }
  71. type HJBaseInfo struct {
  72. // Name string
  73. // Protocol string
  74. Host string
  75. Port string
  76. ST string
  77. CN string
  78. PW string
  79. MN string
  80. // Interval int //上报周期,单位分钟,最小1分钟
  81. // IsUpload bool //是否允许上报
  82. }