Browse Source

update 添加 振动加速度上报

pull/2/head
lucas 2 months ago
parent
commit
be231c81bb
  1. 94
      adaptors/振动to江苏省农村公路桥梁监测.go
  2. 4
      adaptors/统一采集to江苏省农村公路桥梁监测.go
  3. 4
      consumers/consumerJSNCGLQL.go
  4. 19
      testUnit/江苏质感测试_test.go

94
adaptors/振动to江苏省农村公路桥梁监测.go

@ -0,0 +1,94 @@
package adaptors
import (
"bytes"
"encoding/binary"
"encoding/json"
"fmt"
"goInOut/models"
"goInOut/utils"
"log"
"time"
)
// Adaptor_ZD_JSNCGLQL 数据 转换 江苏农村公路桥梁监测系统
type Adaptor_ZD_JSNCGLQL struct {
IdMap map[string]string
}
func (the Adaptor_ZD_JSNCGLQL) Transform(inTopic, rawMsg string) []NeedPush {
zd := models.ZD{}
err := json.Unmarshal([]byte(rawMsg), &zd)
if err != nil {
return nil
}
return the.ZDtoJSNCGLQL(zd)
}
func (the Adaptor_ZD_JSNCGLQL) ZDtoJSNCGLQL(zd models.ZD) (result []NeedPush) {
Atime := time.UnixMilli(zd.Ticks)
sensorDataList := zd.AccValues
//获取对方系统 id
sensorCode := the.getSensorCode(zd.Module)
if sensorCode == "" {
log.Printf("振动 设备[%s] 无匹配的 江苏农村公路桥梁监测系统 测点id,请检查配置文件", zd.Module)
return
}
//todo 桥梁编码
bridgeCode := sensorCode
topic := fmt.Sprintf("data/%s/%s", bridgeCode, sensorCode)
//数据秒数
seconds := len(zd.AccValues) / zd.Frequency
for i := 0; i < seconds; i++ {
var transBytes []byte
onceTime := Atime.Add(time.Duration(i) * time.Second)
//1.添加时间段
transBytes = append(transBytes, the.getTimeBytes(onceTime)...)
startIndex := (0 + i) * zd.Frequency
endIndex := (1 + i) * zd.Frequency
subDataList := sensorDataList[startIndex:endIndex]
for _, sensorData := range subDataList {
//4.添加数据值段
bs := utils.Float32ToBytes(sensorData)
transBytes = append(transBytes, bs...)
}
result = append(result, NeedPush{
Topic: topic,
Payload: transBytes,
})
}
return result
}
func (the Adaptor_ZD_JSNCGLQL) getSensorCode(rawSensorName string) string {
v, isValid := the.IdMap[rawSensorName]
if !isValid {
v = ""
}
return v
}
func (the Adaptor_ZD_JSNCGLQL) getTimeBytes(sensorTime time.Time) []byte {
year := uint16(sensorTime.Year())
month := int8(sensorTime.Month())
day := int8(sensorTime.Day())
hour := int8(sensorTime.Hour())
minute := int8(sensorTime.Minute())
second := int8(sensorTime.Second())
bytesBuffer := bytes.NewBuffer([]byte{})
binary.Write(bytesBuffer, binary.BigEndian, year)
binary.Write(bytesBuffer, binary.BigEndian, month)
binary.Write(bytesBuffer, binary.BigEndian, day)
binary.Write(bytesBuffer, binary.BigEndian, hour)
binary.Write(bytesBuffer, binary.BigEndian, minute)
binary.Write(bytesBuffer, binary.BigEndian, second)
return bytesBuffer.Bytes()
}

4
adaptors/统一采集to江苏省农村公路桥梁监测.go

@ -11,12 +11,12 @@ import (
"time"
)
// Adaptor_TYCJ_JSNCGLQL 统一采集软件数据 转换 江苏农村公路桥梁监测系统
// Adaptor_TYCJ_JSNCGLQL 数据 转换 江苏农村公路桥梁监测系统
type Adaptor_TYCJ_JSNCGLQL struct {
IdMap map[string]string
}
func (the Adaptor_TYCJ_JSNCGLQL) Transform(rawMsg string) []NeedPush {
func (the Adaptor_TYCJ_JSNCGLQL) Transform(inTopic, rawMsg string) []NeedPush {
tycj := models.TYCJ{}
json.Unmarshal([]byte(rawMsg), &tycj)
return the.TYCJtoJSNCGLQL(tycj)

4
consumers/consumerJSNCGLQL.go

@ -95,7 +95,7 @@ func (the *consumerJSNCGLQL) onData(inTopic string, Msg string) {
matchTopic := inTopic[:topicPrefixIndex]
adaptor := the.getAdaptor(matchTopic)
if adaptor != nil {
needPush := adaptor.Transform(inTopic, Msg)
needPush := adaptor.Transform(matchTopic, Msg)
if len(needPush) > 0 {
the.ch <- needPush
}
@ -105,7 +105,7 @@ func (the *consumerJSNCGLQL) getAdaptor(flag string) (adaptor adaptors.IAdaptor4
switch flag {
case "upload/uds":
log.Printf("[统一采集软件]-上报,准备处理")
//adaptor = adaptors.Adaptor_TYCJ_JSNCGLQL{IdMap: the.Info.TYCJsensorMap}
adaptor = adaptors.Adaptor_TYCJ_JSNCGLQL{IdMap: the.Info.TYCJsensorMap}
case "upload/ZD":
log.Printf("[振动软件]-上报,准备处理")
//adaptor = adaptors.Adaptor_ZD_CQZG{IdMap: the.Info.SensorMap.ZDsensorMCMap, RC4Key: RC4Key}

19
testUnit/江苏质感测试_test.go

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save