From 6d979cbe2c0bd195329e2261d9c0302c78081994 Mon Sep 17 00:00:00 2001 From: lucas Date: Wed, 25 Dec 2024 09:31:30 +0800 Subject: [PATCH] =?UTF-8?q?update=20=20gnss=E4=B8=8A=E6=8A=A5=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- adaptors/司南GNSS_MySql库to安心云.go | 22 +++++++++++++++------- consumers/consumerSinoGnssMySQL.go | 2 +- dbOperate/mqttHelper.go | 2 +- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/adaptors/司南GNSS_MySql库to安心云.go b/adaptors/司南GNSS_MySql库to安心云.go index b9f1b57..065cfae 100644 --- a/adaptors/司南GNSS_MySql库to安心云.go +++ b/adaptors/司南GNSS_MySql库to安心云.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "goInOut/consumers/SinoGnssMySQL" + "strconv" ) // Adaptor_SINOMYSQL_AXYMQTT 数据 转换 江苏农村公路桥梁监测系统 @@ -12,25 +13,32 @@ type Adaptor_SINOMYSQL_AXYMQTT struct { func (the Adaptor_SINOMYSQL_AXYMQTT) Transform(gnssDataList []SinoGnssMySQL.GnssData) []NeedPush { var needPush []NeedPush - var allDxFiles map[string][]SinoGnssMySQL.DxFile + allDxFiles := make(map[string][]SinoGnssMySQL.DxFile) for _, gnssData := range gnssDataList { OnceDxFiles := allDxFiles[gnssData.GroupName] OnceDxFiles = append(OnceDxFiles, SinoGnssMySQL.DxFile{ Module: gnssData.StationName, + Channel: 1, Timespan: gnssData.Time.UnixMilli(), - RawValue: []float64{gnssData.X, gnssData.Y, gnssData.H}, - PhyValue: []float64{gnssData.X, gnssData.Y, gnssData.H}, - ThemeValue: []float64{gnssData.X, gnssData.Y, gnssData.H}, + RawValue: []float64{gnssData.X, gnssData.Y, gnssData.H}, //file_mqtt协议里面只解析RV + LimitValue: []float64{}, + PhyValue: []float64{}, + ThemeValue: []float64{}, }) allDxFiles[gnssData.GroupName] = OnceDxFiles } - for groupName, groupFile := range allDxFiles { - bs, _ := json.Marshal(groupFile) + for groupName, groupFileList := range allDxFiles { + contentMap := make(map[string]string) + for i, file := range groupFileList { + bs, _ := json.Marshal(file) + contentMap[strconv.Itoa(i)] = string(bs) + } + gpContent, _ := json.Marshal(contentMap) topic := fmt.Sprintf("SinoGnss/%s/", groupName) needPush = append(needPush, NeedPush{ Topic: topic, - Payload: bs, + Payload: gpContent, }) } diff --git a/consumers/consumerSinoGnssMySQL.go b/consumers/consumerSinoGnssMySQL.go index a12f18e..6876446 100644 --- a/consumers/consumerSinoGnssMySQL.go +++ b/consumers/consumerSinoGnssMySQL.go @@ -68,7 +68,7 @@ func (the *consumerSinoGnssMySQL) Work() { for _, outTopic := range the.Info.IoConfig.Out.Mqtt.Topics { for _, push := range needPushList { - log.Printf("推送[%s]: len=%d", outTopic, len(push.Payload)) + log.Printf("推送[%s]: len=%d", push.Topic, len(push.Payload)) //hex.EncodeToString(pushBytes) if push.Topic != "" { outTopic = push.Topic diff --git a/dbOperate/mqttHelper.go b/dbOperate/mqttHelper.go index eef3fa8..1888293 100644 --- a/dbOperate/mqttHelper.go +++ b/dbOperate/mqttHelper.go @@ -83,7 +83,7 @@ func NewTlsConfig(sslPath string) *tls.Config { func (the *MqttHelper) Publish(topic string, messageBytes []byte) { if the.client != nil { - token := the.client.Publish(topic, 0, false, messageBytes) + token := the.client.Publish(topic, 1, false, messageBytes) token.Wait() //the.client.Disconnect(200) fmt.Printf("[%s] -[%v]推送Msg 长度=%d \n", topic, the.client.IsConnected(), len(messageBytes))