| | |
| | | "fmt" |
| | | "io/ioutil" |
| | | "net" |
| | | "strings" |
| | | "time" |
| | | |
| | | "gat1400Exchange/config" |
| | | "gat1400Exchange/models" |
| | |
| | | Elevator []Elevator `json:"Elevator"` |
| | | } |
| | | |
| | | const ( |
| | | RunStop = iota |
| | | RunUp |
| | | RunDown |
| | | ) |
| | | |
| | | // 对接网络视频字符叠加器,接收udp发送的楼层信息, 更新device地址 |
| | | func NVCSServer() { |
| | | func NVCSA1UDPServer() { |
| | | // 指定监听的端口 |
| | | port := config.ServeConf.Port |
| | | |
| | |
| | | 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 { |
| | |
| | | } |
| | | |
| | | elevator := data.Elevator[0] |
| | | elevator.Name = strings.Trim(elevator.Name, " ") |
| | | |
| | | // 程序部署在设备端, 字符叠加器上报的名称允许为空. 在云端, 名称必须与摄像机相同 |
| | | if elevator.Name == "" { |
| | | continue |
| | | elevator.Name = "1" |
| | | } |
| | | |
| | | var d = models.Device{ |
| | | Id: elevator.Name, |
| | | Pos: 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() |
| | | } |
| | | } |