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

1
config/init.go

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

2
dbHelper/_kafka/consumerGroupHandler.go

@ -82,7 +82,7 @@ func (h *ConsumerGroupHandler) Worker() {
config := sarama.NewConfig() config := sarama.NewConfig()
config.Consumer.Return.Errors = false config.Consumer.Return.Errors = false
config.Version = sarama.V2_0_0_0 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.Offsets.AutoCommit.Enable = true
config.Consumer.Group.Rebalance.GroupStrategies = []sarama.BalanceStrategy{sarama.NewBalanceStrategyRoundRobin()} config.Consumer.Group.Rebalance.GroupStrategies = []sarama.BalanceStrategy{sarama.NewBalanceStrategyRoundRobin()}
group, err := sarama.NewConsumerGroup(h.brokers, h.groupId, config) 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 { for k, v := range headerMap {
req.Header.Set(k, v) req.Header.Set(k, v)
} }
//取消证书校验,避免证书过期问题
client.Transport = &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}
resp, err := client.Do(req) resp, err := client.Do(req)
if err != nil { if err != nil {

2
main_test.go

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

4
testUnit/mqttPush_test.go

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

2
testUnit/mqttRecv_test.go

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

2
testUnit/udpPush_test.go

@ -1,7 +1,7 @@
package testUnit package testUnit
import ( import (
"goUpload/dbHelper" "goInOut/dbHelper"
"strconv" "strconv"
"testing" "testing"
"time" "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 package testUnit
import ( import (
"goUpload/adaptors" "goInOut/adaptors"
"log" "log"
"testing" "testing"
) )

2
utils/valueHelper.go

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

Loading…
Cancel
Save