|
@@ -6,9 +6,11 @@ import (
|
|
|
"regexp"
|
|
"regexp"
|
|
|
"runtime"
|
|
"runtime"
|
|
|
"runtime/debug"
|
|
"runtime/debug"
|
|
|
|
|
+ "server/dao"
|
|
|
"server/global"
|
|
"server/global"
|
|
|
"server/utils/mqtt"
|
|
"server/utils/mqtt"
|
|
|
"server/utils/protocol"
|
|
"server/utils/protocol"
|
|
|
|
|
+ "strconv"
|
|
|
"strings"
|
|
"strings"
|
|
|
"sync"
|
|
"sync"
|
|
|
"time"
|
|
"time"
|
|
@@ -43,7 +45,7 @@ func GetHandler() *MqttHandler {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (o *MqttHandler) SubscribeTopics() {
|
|
func (o *MqttHandler) SubscribeTopics() {
|
|
|
- mqtt.GetMQTTMgr().Subscribe("screens/#", mqtt.AtLeastOnce, o.HandlerData)
|
|
|
|
|
|
|
+ mqtt.GetMQTTMgr().Subscribe("smart_intersectionV2.0/#", mqtt.AtLeastOnce, o.HandlerData)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (o *MqttHandler) HandlerData(m mqtt.Message) {
|
|
func (o *MqttHandler) HandlerData(m mqtt.Message) {
|
|
@@ -78,14 +80,23 @@ func (o *MqttHandler) Handler() interface{} {
|
|
|
continue
|
|
continue
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- _, topic, err := parseTopic(m.Topic())
|
|
|
|
|
|
|
+ sn, topic, err := parseTopic(m.Topic())
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
global.GVA_LOG.Error("parseTopic err")
|
|
global.GVA_LOG.Error("parseTopic err")
|
|
|
continue
|
|
continue
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
switch topic {
|
|
switch topic {
|
|
|
|
|
+ case TopicHighSpeed: //存储超速事件
|
|
|
|
|
|
|
|
|
|
+ case TopicLowSpeed: //存储低俗时间
|
|
|
|
|
+
|
|
|
|
|
+ case TopicChanStatus: //修改屏幕状态
|
|
|
|
|
+ status, _ := strconv.Atoi(m.PayloadString())
|
|
|
|
|
+ err := dao.UpdateScreensStatusBySn(sn, status)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ global.GVA_LOG.Error(fmt.Sprintf("修改屏幕状态失败:%s", err.Error()))
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -96,7 +107,7 @@ func (o *MqttHandler) Publish(topic string, data interface{}) error {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (o *MqttHandler) GetTopic(deviceSn, protocol string) string {
|
|
func (o *MqttHandler) GetTopic(deviceSn, protocol string) string {
|
|
|
- return fmt.Sprintf("screens/%s/%s", deviceSn, protocol)
|
|
|
|
|
|
|
+ return fmt.Sprintf("smart_intersectionV2.0/%s/%s", deviceSn, protocol)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// parseTopic 获取设备SN, topic
|
|
// parseTopic 获取设备SN, topic
|
|
@@ -117,3 +128,11 @@ func Sending(sn, json string) error {
|
|
|
}
|
|
}
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+const (
|
|
|
|
|
+ TopicChanStatus = "chanStatus" //上报状态
|
|
|
|
|
+ TopicHighSpeed = "highSpeed" //超速时
|
|
|
|
|
+ TopicLowSpeed = "lowSpeed" //低速时
|
|
|
|
|
+
|
|
|
|
|
+ TopicSetControl = "setControl" //云台下发控制
|
|
|
|
|
+)
|