From 29dbb82ed5d96ade6baddde05ec8536e298bb595 Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期二, 21 五月 2024 23:43:47 +0800
Subject: [PATCH] 添加osd设置功能

---
 config/config.go |    1 
 service/osd.go   |   63 +++++++++++++++++++++++++++++++
 service/nvcs.go  |   23 +++++++++++
 3 files changed, 87 insertions(+), 0 deletions(-)

diff --git a/config/config.go b/config/config.go
index d113791..922d680 100644
--- a/config/config.go
+++ b/config/config.go
@@ -54,6 +54,7 @@
 type nvcs struct {
 	Model string `mapstructure:"model"` // 鍨嬪彿
 	Port  string `mapstructure:"port"`  // 绔彛
+	OSD   string `mapstructure:"osd"`
 }
 
 type rateLimitConfig struct {
diff --git a/service/nvcs.go b/service/nvcs.go
index 7af51b1..64464fa 100644
--- a/service/nvcs.go
+++ b/service/nvcs.go
@@ -36,6 +36,12 @@
 	Elevator []Elevator `json:"Elevator"`
 }
 
+const (
+	RunStop = iota
+	RunUp
+	RunDown
+)
+
 // 瀵规帴缃戠粶瑙嗛瀛楃鍙犲姞鍣�,鎺ユ敹udp鍙戦�佺殑妤煎眰淇℃伅, 鏇存柊device鍦板潃
 func NVCSA1UDPServer() {
 	// 鎸囧畾鐩戝惉鐨勭鍙�
@@ -87,6 +93,23 @@
 			continue
 		}
 
+		// 璁剧疆osd  鏍煎紡 "1F鍋� 鍥� 鏋�"
+		if config.NVCSConf.OSD != "" {
+			floorText := data.Elevator[0].Status.FloorName
+			if data.Elevator[0].Status.RunDir == RunStop {
+				floorText = floorText + "鍋�"
+			} else if data.Elevator[0].Status.RunDir == RunUp {
+				floorText = floorText + "涓�"
+			} else {
+				floorText = floorText + "涓�"
+			}
+
+			floorText = floorText + " " + config.NVCSConf.OSD
+
+			// 璋冪敤hik api 灏嗘枃瀛楁坊鍔犲埌osd鐨勫乏涓嬭
+			AddFloorToOSD(floorText)
+		}
+
 		if data.Elevator[0].Status.RunDir > 0 {
 			continue
 		}
diff --git a/service/osd.go b/service/osd.go
new file mode 100644
index 0000000..e5f5728
--- /dev/null
+++ b/service/osd.go
@@ -0,0 +1,63 @@
+package service
+
+import (
+	"encoding/xml"
+	"gat1400Exchange/pkg/logger"
+	dac "github.com/xinsnake/go-http-digest-auth-client"
+	"io/ioutil"
+)
+
+// 璁剧疆鍏朵粬瀛楃鐨勭涓�涓�, 浣嶇疆鍥哄畾浣�7
+// 鎽勫儚鏈轰俊鎭殏鏃跺浐瀹�, 閬垮厤娉勯湶
+const (
+	HikISAPIOverlaySetUrl = "/ISAPI/System/Video/inputs/channels/1/overlays/text/7"
+	CameraWebAddr         = "http://192.168.10.11:40080"
+	CameraWebUser         = "admin"
+	CameraWebPassword     = "a1234567"
+)
+
+type TextOverlay struct {
+	Id               int64  `xml:"id"`
+	Enabled          bool   `xml:"enabled"`
+	PositionX        int64  `xml:"positionX"`
+	PositionY        int64  `xml:"positionY"`
+	DisplayText      string `xml:"displayText"`
+	DirectAngle      string `xml:"directAngle"`
+	IsPersistentText bool   `xml:"isPersistentText"`
+}
+
+func AddFloorToOSD(osdText string) {
+	overlay7Url := CameraWebAddr + HikISAPIOverlaySetUrl
+	rsp, err := ISAPIRequest(CameraWebUser, CameraWebPassword, "GET", overlay7Url, "")
+	if err != nil {
+		logger.Warn("Get osd info failure")
+		return
+	}
+
+	var overlayText TextOverlay
+	err = xml.Unmarshal(rsp, &overlayText)
+	if err != nil {
+		logger.Warn("%s", err.Error())
+		return
+	}
+
+	overlayText.DisplayText = osdText
+	body, _ := xml.Marshal(overlayText)
+	_, err = ISAPIRequest(CameraWebUser, CameraWebPassword, "PUT", overlay7Url, string(body))
+	if err != nil {
+		logger.Warn("Camera osd set failure!!")
+		return
+	}
+}
+
+func ISAPIRequest(username, password, method, url, body string) ([]byte, error) {
+	dr := dac.NewRequest(username, password, method, url, body)
+	resp, err := dr.Execute()
+	if err != nil {
+		return nil, err
+	}
+
+	defer resp.Body.Close()
+
+	return ioutil.ReadAll(resp.Body)
+}

--
Gitblit v1.8.0