iot_last.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package tower
  2. import (
  3. "context"
  4. "fmt"
  5. "smart-site-management/errors"
  6. "smart-site-management/model"
  7. v1 "smart-site-management/pb/v1"
  8. )
  9. func getTowerLast(sn string, projectId int64) (reply *v1.IotLastReply, err error) {
  10. treq := &v1.LatestTowerMonitorDataRequest{
  11. Sn:sn,
  12. ProjectId:projectId,
  13. }
  14. treply, err := LatestTowerMonitorData(context.Background(), treq)
  15. if err != nil {
  16. return nil, err
  17. }
  18. reply = &v1.IotLastReply{}
  19. item := &v1.IotDataItem{}
  20. item.Name = "回转"
  21. item.Value = fmt.Sprintf("%.1f", treply.Data.BackTurn)
  22. item.Unit = "°"
  23. reply.List = append(reply.List, item)
  24. item = &v1.IotDataItem{}
  25. item.Name = "幅度"
  26. item.Value = fmt.Sprintf("%.1f", treply.Data.Scope)
  27. item.Unit = "m"
  28. reply.List = append(reply.List, item)
  29. item = &v1.IotDataItem{}
  30. item.Name = "高度"
  31. item.Value = fmt.Sprintf("%.1f", treply.Data.Hight)
  32. item.Unit = "m"
  33. reply.List = append(reply.List, item)
  34. item = &v1.IotDataItem{}
  35. item.Name = "称重"
  36. item.Value = fmt.Sprintf("%.2f", treply.Data.Weight)
  37. item.Unit = "t"
  38. reply.List = append(reply.List, item)
  39. item = &v1.IotDataItem{}
  40. item.Name = "力矩"
  41. item.Value = fmt.Sprintf("%v", treply.Data.Moment)
  42. item.Unit = ""
  43. reply.List = append(reply.List, item)
  44. item = &v1.IotDataItem{}
  45. item.Name = "电池电量"
  46. item.Value = fmt.Sprintf("%v", treply.Data.Battery)
  47. item.Unit = ""
  48. reply.List = append(reply.List, item)
  49. item = &v1.IotDataItem{}
  50. item.Name = "风速"
  51. item.Value = fmt.Sprintf("%.1f", treply.Data.WindSpeed)
  52. item.Unit = "m/s"
  53. reply.List = append(reply.List, item)
  54. item = &v1.IotDataItem{}
  55. item.Name = "塔身倾角X"
  56. item.Value = fmt.Sprintf("%.1f", treply.Data.AngleX)
  57. item.Unit = "°"
  58. reply.List = append(reply.List, item)
  59. item = &v1.IotDataItem{}
  60. item.Name = "塔身倾角Y"
  61. item.Value = fmt.Sprintf("%.1f", treply.Data.AngleY)
  62. item.Unit = "°"
  63. reply.List = append(reply.List, item)
  64. return reply, nil
  65. }
  66. func IotLast(ctx context.Context, req *v1.IotLastRequest) (reply *v1.IotLastReply, err error) {
  67. if req.ProjectId < 1 || req.Sn == "" || req.DeviceCode < 1{
  68. return nil, errors.ParamsError
  69. }
  70. switch req.DeviceCode {
  71. case model.DeviceTypeTower:
  72. return getTowerLast(req.Sn, req.ProjectId)
  73. }
  74. return &v1.IotLastReply{}, nil
  75. }