qixiaoning
2025-07-08 fe724b50b3f1b3dfe2219eb9af4bcca96c89a158
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
package controllers
 
import (
    "basic.com/gb28181api.git"
    "basic.com/valib/bhomeclient.git"
    "basic.com/valib/bhomedbapi.git"
    "vamicro/config"
)
 
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(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply{
    var param PTZInstruct
    if err := c.BindJSON(&param); err != nil {
        return &bhomeclient.Reply{Success:false, Msg: "参数有误"}
    }
 
    ptzSpeed := config.Server.PTZSpeed
    if ptzSpeed == 0 {
        ptzSpeed = 50
    }
 
    if param.CameraType == 1 {
        var api bhomedbapi.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 {
                return &bhomeclient.Reply{Success:false, Msg: "国标配置读取失败"}
            }
 
        } else {
            return &bhomeclient.Reply{Success:false, Msg: "国标接口查询失败"}
        }
 
        var gbApi gb28181api.Gb28181Api
        if r := gbApi.SetCameraPtz(param.CameraId, param.PTZType, ptzSpeed); r {
            return &bhomeclient.Reply{Success:true, Msg: "配置成功"}
        } else {
            return &bhomeclient.Reply{Success:true, Msg: "国标接口操作失败"}
        }
    } else {
        return &bhomeclient.Reply{Success:true, Msg: "不支持的摄像机类型"}
    }
}