writedata.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package service
  2. import (
  3. "encoding/json"
  4. "time"
  5. wdcc "dashoo.cn/labsop"
  6. "github.com/nsqio/go-nsq"
  7. )
  8. //tag说明f:fields,t:tag,-:不赋值
  9. type ChannelValue struct {
  10. Time time.Time
  11. TimeUnix int64
  12. Sequence int64
  13. Mxinh int64
  14. T2bxh float64
  15. Lat float64 //纬度
  16. Lng float64 //经度
  17. Speed float64 //速度
  18. Temperature float64 //温度
  19. Humidity float64 //湿度
  20. Voltage float64 //电压
  21. RSSI float64 //信号 Signal (sensor到blackbox)
  22. CSTime time.Time //传输时间
  23. SensorNo int64 //Sensor序列号 Zbackup4
  24. BBVoltage float64 //bb电压
  25. BBCSTime time.Time //BB传输time Zbackup2
  26. BBMac string //bbmac
  27. BBMacTag string //bbmactag
  28. BBNo int64 //bb序列号 SensorNo
  29. SimSignal int64 //移动信号 Zbackup3
  30. SimIP string //sim900 IP Zbackup7
  31. ServiceTime time.Time //服务器时间 Zbackup5
  32. RequestData string //请求原数据 Zbackup1
  33. O2 float64 //氧气浓度 Zbackup8
  34. SO2 float64 //二氧化硫 Zbackup8
  35. Isreplace int64 //是否替换(0未替换,1已替换) Zbackup9
  36. RealTemperature float64 //原温度 Zbackup10
  37. Co2 float64 //Co2
  38. H2O float64 //水质
  39. WindSpeed float64 //风速
  40. Pressure float64 //气压
  41. Ots float64 //压力大港
  42. Displacement float64 //位移
  43. ClO2 float64 //二氧化氯
  44. C2H4 float64 //乙烯
  45. C2H2 float64 //乙炔
  46. Cl2 float64 //氯气
  47. O3 float64 //臭氧
  48. TVOC float64 //TVOC
  49. Waterflow float64 //waterflow
  50. DeviceState int64 // 监控设备状态
  51. ElectricalPower int64 // 电器功率
  52. ElectricalSupply int64 // 市电电压
  53. NTCR float64 // Sensor端NTC热敏电阻
  54. ThreeACVA float64 // A相电压
  55. ThreeACVB float64 // B相电压
  56. ThreeACVC float64 // C相电压
  57. ThreeACAA float64 // A相电流
  58. ThreeACAB float64 // B相电流
  59. ThreeACAC float64 // C相电流
  60. ThreeACW float64 // 三相有功总电能
  61. InfraredBarrier int64 // 红外阻挡物(0 无阻碍物 1有障碍物 other 其他)
  62. GpsBaseStation string // gps基站信息
  63. LiquidLevel float64 // 液位
  64. Doorlock float64 // 门锁
  65. }
  66. var Producernsq *nsq.Producer
  67. type blackboxddata struct {
  68. Code string
  69. Datapoint wdcc.DatapointLabSop
  70. }
  71. func Writedata(tagmac, bbmac, zbackup1, gpsbasestation string, v1, v2, v3, v4, v5, v6 float64, cjtime, cstime, bbtime time.Time, xulieh, mobilexh, sensornum, isreplace, infraredbarrier int64, o2, realtemperature, co2, waterflow, lng, lat float64, devicestate, wdtype int, electricalpower, electricalsupply int64, ntrc, threeacva, threeacaa, threeacvb, threeacab, threeacvc, threeacac, threeacw, doorlock float64) (wdcc.DatapointLabSop, error) {
  72. var data wdcc.DatapointLabSop
  73. data = wdcc.DatapointLabSop{Time: cjtime, Temperature: v1, Humidity: v2, Voltage: v3, RSSI: v4, CSTime: cstime, BBVoltage: v5, BBMac: bbmac, BBNo: xulieh, RequestData: zbackup1, BBCSTime: bbtime, SimSignal: mobilexh, SensorNo: sensornum, ServiceTime: time.Now(), O2: o2, Isreplace: isreplace, RealTemperature: realtemperature, Co2: co2, Waterflow: waterflow, Lat: lat, Lng: lng, DeviceState: int64(devicestate), ElectricalPower: electricalpower, ElectricalSupply: electricalsupply, GpsBaseStation: gpsbasestation, NTCR: ntrc, ThreeACVA: threeacva, ThreeACVB: threeacvb, ThreeACVC: threeacvc, ThreeACAA: threeacaa, ThreeACAB: threeacab, ThreeACAC: threeacac, ThreeACW: threeacw, InfraredBarrier: infraredbarrier, Doorlock: doorlock}
  74. bdata, err := json.Marshal(blackboxddata{tagmac, data})
  75. if err == nil {
  76. errnsq := Producernsq.Publish(Config.Send.Controller.Topic, bdata)
  77. return data, errnsq
  78. // return data, nil
  79. }
  80. return data, err
  81. }