zhangzengfei
2024-10-11 539a78196da60eb97cf7057c5c85dfaa9b240741
添加A3平层传感器数据获取方式
1个文件已修改
70 ■■■■■ 已修改文件
service/nvcs.go 70 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/nvcs.go
@@ -407,11 +407,81 @@
    }
}
type A3ElevatorData struct {
    Id     string `json:"id"`
    Time   string `json:"time"`
    Total  int    `json:"total"`
    Status int    `json:"status"`
    Floor  int    `json:"floor"`
}
func NVCSA3WebServer() {
    r := gin.Default()
    r.POST("/", func(c *gin.Context) {
        var req A3ElevatorData
        var runState string
        var iRunState int
        err := c.BindJSON(&req)
        if err != nil {
            c.JSON(http.StatusBadRequest, nil)
            return
        }
        iRunState = req.Status
        logger.Debug("Received A2 report data %+v", req)
        // 记录电梯运行状态
        if iRunState == RunUp {
            runState = "上"
        } else if iRunState == RunDown {
            runState = "下"
        }
        if !config.NVCSConf.RunState {
            runState = ""
        }
        if config.NVCSConf.OSD != "" {
            floorText := fmt.Sprintf("%dF%s %s", req.Floor, runState, config.NVCSConf.OSD)
            // 调用hik api 将文字添加到osd的左下角
            AddFloorToOSD(floorText)
        }
        var d = models.Positions{
            DeviceId:   req.Id,
            Pos:        fmt.Sprintf("%dF", req.Floor),
            RunDir:     iRunState,
            CreateTime: time.Now().Unix(),
            TimeString: time.Now().Format("2006-01-02 15:04:05"),
        }
        err = d.Save()
        if err != nil {
            logger.Warn("Device position update error:%s", err.Error())
        }
        c.JSON(http.StatusOK, "ok")
    })
    err := r.Run(fmt.Sprintf(":%s", config.NVCSConf.Port))
    if err != nil {
        logger.Warn("Start NVCS WebServer error, %s", err.Error())
    }
}
func StartNVCSServer() {
    if config.NVCSConf.Model == "A1" {
        go NVCSA1UDPServer()
    }
    if config.NVCSConf.Model == "A2" {
        go NVCSA2WebServer()
    }
    if config.NVCSConf.Model == "A3" {
        go NVCSA3WebServer()
    }
}