zhangzengfei
2024-05-22 f946512f64f1e2e9aa887f62f04f8ebedb53d810
service/nvcs.go
@@ -6,7 +6,7 @@
   "fmt"
   "io/ioutil"
   "net"
   "strings"
   "time"
   "gat1400Exchange/config"
   "gat1400Exchange/models"
@@ -35,8 +35,14 @@
   Elevator []Elevator `json:"Elevator"`
}
const (
   RunStop = iota
   RunUp
   RunDown
)
// 对接网络视频字符叠加器,接收udp发送的楼层信息, 更新device地址
func NVCSServer() {
func NVCSA1UDPServer() {
   // 指定监听的端口
   port := config.ServeConf.Port
@@ -75,15 +81,32 @@
      decodedBytes, err := ioutil.ReadAll(reader)
      var data ElevatorData
      // Unmarshal JSON into the struct
      err = json.Unmarshal(decodedBytes, &data)
      if err != nil {
         logger.Warn("ElevatorData unmarshal error:%s", err.Error())
         continue
      }
      logger.Debug("Received %d bytes from %s, %+v", numBytes, clientAddr, data)
      if len(data.Elevator) == 0 {
         continue
      }
      // 设置osd  格式 "1F 固 枪"
      if config.NVCSConf.OSD != "" {
         floorText := data.Elevator[0].Status.FloorName
         //if data.Elevator[0].Status.RunDir == RunStop {
         //   floorText = floorText + "停"
         //} else if data.Elevator[0].Status.RunDir == RunUp {
         //   floorText = floorText + "上"
         //} else {
         //   floorText = floorText + "下"
         //}
         floorText = floorText + " " + config.NVCSConf.OSD
         // 调用hik api 将文字添加到osd的左下角
         AddFloorToOSD(floorText)
      }
      if data.Elevator[0].Status.RunDir > 0 {
@@ -91,24 +114,28 @@
      }
      elevator := data.Elevator[0]
      elevator.Name = strings.Trim(elevator.Name, " ")
      // 程序部署在设备端, 字符叠加器上报的名称允许为空. 在云端, 名称必须与摄像机相同
      if elevator.Name == "" {
         continue
         elevator.Name = "1"
      }
      var d = models.Device{
         Id:    elevator.Name,
         Floor: elevator.Status.FloorName,
         Ip:    elevator.IP,
      var d = models.Positions{
         DeviceId:   elevator.Name,
         Pos:        elevator.Status.FloorName,
         CreateTime: time.Now().Unix(),
         TimeString: time.Now().Format("2006-01-02 15:04:05"),
      }
      err = d.Upsert()
      err = d.Save()
      if err != nil {
         logger.Warn("Device db update error:%s", err.Error())
         logger.Warn("Device position update error:%s", err.Error())
      }
   }
}
      deviceAliveCache.Add(elevator.Name, true)
      logger.Debug("Received %d bytes from %s, %+v", numBytes, clientAddr, data)
func StartNVCSServer() {
   if config.NVCSConf.Model == "A1" {
      go NVCSA1UDPServer()
   }
}