From 0b01e7cb78f7e64e52b6faf30f1e7e2b71acf784 Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@iotlink.com>
Date: 星期四, 31 十月 2019 17:37:30 +0800
Subject: [PATCH] fix: camera Pan-Tilt control
---
/dev/null | 32 ----------------
config/test.yaml | 1
controllers/cameraPTZ.go | 71 +++++++++++++++++++++++++++++++++++
extend/sys/system.go | 2
extend/config/config.go | 3 +
router/router.go | 4 +-
6 files changed, 77 insertions(+), 36 deletions(-)
diff --git a/config/test.yaml b/config/test.yaml
index 9365366..655231c 100644
--- a/config/test.yaml
+++ b/config/test.yaml
@@ -34,6 +34,7 @@
-
value: 100
color: '#5d0000'
+ ptzSpeed: 50
database:
driver: sqlite
name: sqlite3
diff --git a/controllers/cameraPTZ.go b/controllers/cameraPTZ.go
new file mode 100644
index 0000000..2cb0af2
--- /dev/null
+++ b/controllers/cameraPTZ.go
@@ -0,0 +1,71 @@
+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"` //鎽勫儚鏈篿d
+ CameraType int `json:"cameraType"` //鎽勫儚鏈虹被鍨�
+ PTZType string `json:"ptzType"` //鎺у埗绫诲瀷 left right top ... stop
+}
+
+// @Summary 浜戝彴
+// @Description 鎽勫儚鏈轰簯鍙版帶鍒�
+// @Security ApiKeyAuth
+// @Produce json
+// @Tags camera
+// @Param ptzBody body controllers.PTZInstruct true "鎺у埗绫诲瀷锛歶p,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(¶m); 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, "涓嶆敮鎸佺殑鎽勫儚鏈虹被鍨�")
+ }
+}
diff --git a/controllers/panTilt.go b/controllers/panTilt.go
deleted file mode 100644
index 5dd318c..0000000
--- a/controllers/panTilt.go
+++ /dev/null
@@ -1,32 +0,0 @@
-package controllers
-
-import (
- "webserver/extend/code"
- "webserver/extend/util"
-
- "github.com/gin-gonic/gin"
-)
-
-type PanTiltController struct {
-}
-
-type PTInstruct struct {
- ChannelId string `json:"channelId"` //鏈嶅姟鍣╥d
- PTZType string `json:"ptzType"` //杞鍛ㄦ湡
- PTZParam int32 `json:"ptzParam"` //寤舵椂鏃堕棿
-}
-
-func (controller PanTiltController) Controlling(c *gin.Context) {
- var param PTInstruct
- if err := c.BindJSON(¶m); err != nil {
- util.ResponseFormat(c, code.RequestParamError, "鍙傛暟鏈夎")
- return
- }
-
- b := true
- if b {
- util.ResponseFormat(c, code.Success, "")
- } else {
- util.ResponseFormat(c, code.ComError, "淇濆瓨澶辫触")
- }
-}
diff --git a/extend/config/config.go b/extend/config/config.go
index c775712..2ab67ab 100644
--- a/extend/config/config.go
+++ b/extend/config/config.go
@@ -26,8 +26,9 @@
ChannelCount string `mapstructure: "channelCount"` //閫氶亾涓暟
DiskCount string `mapstructure: "diskCount"` //纭洏涓暟
- SudoPassword string `mapstructure: "sudoPassword"`
+ SudoPassword string `mapstructure: "sudoPassword"` //绯荤粺瀵嗙爜
SysThresholds []threshold `mapstructure: "sysThresholds"`
+ PTZSpeed int `mapstructure: "ptzSpeed"` // 浜戝彴绉诲姩閫熷害
}
var Server = &server{}
diff --git a/extend/sys/system.go b/extend/sys/system.go
index b1bb46d..647917d 100644
--- a/extend/sys/system.go
+++ b/extend/sys/system.go
@@ -119,7 +119,7 @@
func NTPConfig() (bool, string, string) {
status, server, interval := false, "", ""
- cron, _ := execRootCommand("crontab -l | grep ntpdate | sed -z -r 's/([^0-9* ]+)(.+)//g'")
+ cron, _ := execRootCommand("crontab -l | grep ntpdate | tr -d '\n'")
if task := string(cron); task != "" {
status = true
slice := strings.Split(task, " ")
diff --git a/router/router.go b/router/router.go
index 93aa948..336f552 100644
--- a/router/router.go
+++ b/router/router.go
@@ -42,7 +42,7 @@
sysMenuController := new(controllers.SysMenuController)
clusterController := new(controllers.ClusterController)
sysRoleController := new(controllers.RoleController)
- ptController := new(controllers.PanTiltController)
+ ptzController := new(controllers.PanTiltZoomController)
sysApi := r.Group("/data/api-u/sys")
{
@@ -101,7 +101,7 @@
camera.POST("/changeRunType", cameraController.ChangeRunType)
camera.GET("/getAllCamerasByServer", cameraController.GetAllCamerasByServer)
- camera.POST("/ptControl", ptController.Controlling)
+ camera.POST("/ptzControl", ptzController.Move)
camera.GET("/statisticRunInfo", cameraController.StatisticRunInfo)
}
--
Gitblit v1.8.0