liuxiaolong
2019-11-13 f26a0cab5bca17b7eab57f6330e576271e17a17f
controllers/cameraPTZ.go
@@ -1 +1,74 @@
package controllers
import (
   "basic.com/dbapi.git"
   "basic.com/gb28181api.git"
   "webserver/extend/code"
   "webserver/extend/config"
   "webserver/extend/util"
   "github.com/gin-gonic/gin"
)
type PanTiltZoomController struct {
}
type PTZInstruct struct {
   CameraId   string `json:"cameraId"`   //摄像机id
   CameraType int    `json:"cameraType"` //摄像机类型
   PTZType    string `json:"ptzType"`    //控制类型 left right top ... stop
}
/*
// @Summary 云台
// @Description 摄像机云台控制
// @Security ApiKeyAuth
// @Accept json
// @Produce json
// @Tags camera
// @Param ptzBody body controllers.PTZInstruct true "控制类型:up,down,left,right,zoomin,zoomout,stop"
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
// @Router /data/api-v/camera/ptzControl [post]
*/
func (ptz PanTiltZoomController) Move(c *gin.Context) {
   var param PTZInstruct
   if err := c.BindJSON(&param); err != nil {
      util.ResponseFormat(c, code.RequestParamError, "参数有误")
      return
   }
   ptzSpeed := config.Server.PTZSpeed
   if ptzSpeed == 0 {
      ptzSpeed = 50
   }
   if param.CameraType == 1 {
      var api dbapi.SysSetApi
      r, gb28182Config := api.Gb28181ConfigShow()
      if r {
         conf, ok := gb28182Config.(map[string]interface{})
         if ok {
            gb28181api.Init(conf["ServerIp"].(string), int(conf["ServerPort"].(float64)))
         } else {
            util.ResponseFormat(c, code.ComError, "国标配置读取失败")
            return
         }
      } else {
         util.ResponseFormat(c, code.ComError, "国标接口查询失败")
         return
      }
      var gbApi gb28181api.Gb28181Api
      if r := gbApi.SetCameraPtz(param.CameraId, param.PTZType, ptzSpeed); r {
         util.ResponseFormat(c, code.Success, "")
      } else {
         util.ResponseFormat(c, code.Success, "国标接口操作失败")
      }
   } else {
      util.ResponseFormat(c, code.Success, "不支持的摄像机类型")
   }
}