sunty
2020-08-20 9303b69ea569bcb5e581147543a3fd58e90d0d25
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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, "不支持的摄像机类型")
    }
}