Browse Source

update 添加江苏质感的测试用例 修改数据大小端转换

pull/2/head
lucas 2 months ago
parent
commit
bc2e575067
  1. 23
      adaptors/统一采集to江苏省农村公路桥梁监测.go
  2. 1
      config/init.go
  3. 2
      dbHelper/_kafka/consumerGroupHandler.go
  4. 2
      dbHelper/httpHelper.go
  5. 2
      main_test.go
  6. 4
      testUnit/mqttPush_test.go
  7. 2
      testUnit/mqttRecv_test.go
  8. 2
      testUnit/udpPush_test.go
  9. 47
      testUnit/江苏质感测试_test.go
  10. 2
      testUnit/湘潭监测测试_test.go
  11. 2
      utils/valueHelper.go

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

@ -1,6 +1,8 @@
package adaptors
import (
"bytes"
"encoding/binary"
"encoding/json"
"fmt"
"goInOut/models"
@ -31,9 +33,6 @@ func (the Adaptor_TYCJ_JSNCGLQL) TYCJtoJSNCGLQL(tycj models.TYCJ) (result []Need
switch tycj.SensorData.FactorType {
case models.TYCJ_FactorType_YLYB, models.TYCJ_FactorType_DTQYB: //应变23,挡土墙应变13 FS-BM50
sensorDataList = append(sensorDataList, tycj.SensorData.Data.ThemeValues[0])
case models.TYCJ_FactorType_QDQX: //桥墩倾斜20 X (mm) Y (mm)
sensorDataList = append(sensorDataList, tycj.SensorData.Data.ThemeValues[0])
sensorDataList = append(sensorDataList, tycj.SensorData.Data.ThemeValues[1])
default:
log.Printf("监测因素[%d] 无匹配", tycj.SensorData.FactorType)
return
@ -80,14 +79,12 @@ func (the Adaptor_TYCJ_JSNCGLQL) getTimeBytes(sensorTime time.Time) []byte {
hour := int8(sensorTime.Hour())
minute := int8(sensorTime.Minute())
second := int8(sensorTime.Second())
bytes := make([]byte, 0)
bytes = append(bytes,
byte(year),
byte(month),
byte(day),
byte(hour),
byte(minute),
byte(second),
)
return bytes
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()
}

1
config/init.go

@ -8,7 +8,6 @@ import (
)
func LoadConfigJson() map[string]string {
//加载目录下所有文件
allConfig := make(map[string]string)
files, err := os.ReadDir("configFiles")

2
dbHelper/_kafka/consumerGroupHandler.go

@ -82,7 +82,7 @@ func (h *ConsumerGroupHandler) Worker() {
config := sarama.NewConfig()
config.Consumer.Return.Errors = false
config.Version = sarama.V2_0_0_0
config.Consumer.Offsets.Initial = sarama.OffsetNewest
config.Consumer.Offsets.Initial = sarama.OffsetOldest
config.Consumer.Offsets.AutoCommit.Enable = true
config.Consumer.Group.Rebalance.GroupStrategies = []sarama.BalanceStrategy{sarama.NewBalanceStrategyRoundRobin()}
group, err := sarama.NewConsumerGroup(h.brokers, h.groupId, config)

2
dbHelper/httpHelper.go

@ -49,6 +49,8 @@ func (the *HttpHelper) HttpGetWithHeader(queryBody string, headerMap map[string]
for k, v := range headerMap {
req.Header.Set(k, v)
}
//取消证书校验,避免证书过期问题
client.Transport = &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}
resp, err := client.Do(req)
if err != nil {

2
main_test.go

@ -4,7 +4,7 @@ import (
"bytes"
"crypto/rc4"
"encoding/hex"
"goUpload/utils"
"goInOut/utils"
"log"
"testing"
"text/template"

4
testUnit/mqttPush_test.go

@ -2,8 +2,8 @@ package testUnit
import (
"encoding/hex"
"goUpload/consumers/CQZG/protoFiles"
"goUpload/dbHelper"
"goInOut/consumers/CQZG/protoFiles"
"goInOut/dbHelper"
"google.golang.org/protobuf/proto"
"log"
"testing"

2
testUnit/mqttRecv_test.go

@ -1,7 +1,7 @@
package testUnit
import (
"goUpload/dbHelper"
"goInOut/dbHelper"
"log"
"testing"
"time"

2
testUnit/udpPush_test.go

@ -1,7 +1,7 @@
package testUnit
import (
"goUpload/dbHelper"
"goInOut/dbHelper"
"strconv"
"testing"
"time"

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

@ -0,0 +1,47 @@
package testUnit
import (
"goInOut/adaptors"
"log"
"testing"
)
func Test_江苏质感_应变(t *testing.T) {
Msg := `
{
"dtuInfo": {
"id": 0,
"code": "COM3"
},
"sensorData": {
"id": 25,
"name": "m1c1",
"module": "1",
"channel": "1",
"factorType": 23,
"productCode": "MD-BM15",
"structId": 0,
"data": {
"RawValues": [
880.05609130859375,
17.250148773193359,
426.63839721679687
],
"ThemeValues": [
1.254
]
},
"time": "2022-01-06T14:30:00.000"
}
}
`
adp := adaptors.Adaptor_TYCJ_JSNCGLQL{
IdMap: map[string]string{
"m1c1": "JY-HSD-G05-001-01",
"m1c2": "LHTDQ-RSG-L04-001-03",
},
}
bytes := adp.Transform(Msg)
log.Println(bytes)
}

2
testUnit/湘潭监测测试_test.go

@ -1,7 +1,7 @@
package testUnit
import (
"goUpload/adaptors"
"goInOut/adaptors"
"log"
"testing"
)

2
utils/valueHelper.go

@ -41,6 +41,6 @@ func LimitStringLength(s string, maxLength int) string {
func Float32ToBytes(float float32) []byte {
bits := math.Float32bits(float)
bytes := make([]byte, 4)
binary.LittleEndian.PutUint32(bytes, bits)
binary.BigEndian.PutUint32(bytes, bits)
return bytes
}

Loading…
Cancel
Save