From 15dc6df83a839f5913997e4e2a252a0714dc2978 Mon Sep 17 00:00:00 2001 From: zhangzengfei <zhangzengfei@smartai.com> Date: 星期四, 13 六月 2024 11:39:33 +0800 Subject: [PATCH] osd 添加上下行 --- service/osd.go | 27 ++++++++++++++++----------- service/nvcs.go | 29 ++++++++++++++++++----------- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/service/nvcs.go b/service/nvcs.go index 3cbd488..e2f3f2b 100644 --- a/service/nvcs.go +++ b/service/nvcs.go @@ -65,6 +65,7 @@ logger.Info("UDP server listening on port %s...", port) + var runState string // 鏃犻檺寰幆绛夊緟鎺ユ敹鏁版嵁 for { // 鍒涘缓涓�涓紦鍐插尯鏉ュ瓨鍌ㄦ帴鏀剁殑鏁版嵁 @@ -94,18 +95,24 @@ 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 + "涓�" - //} + // 璁板綍鐢垫杩愯鐘舵��, 鍙褰曚笂琛屽拰涓嬭 + if data.Elevator[0].Status.RunDir == RunUp { + runState = "涓�" + } else if data.Elevator[0].Status.RunDir == RunDown { + runState = "涓�" + } - floorText = floorText + " " + config.NVCSConf.OSD + // 宸插埌鏈�涓嬪眰 + if data.Elevator[0].Status.Floor == 0 { + runState = "涓�" + } + if data.Elevator[0].Status.Floor == data.Elevator[0].Status.TotalFloors { + runState = "涓�" + } + + // 璁剧疆osd 鏍煎紡 "1F涓� 鍥� 鏋�" + if config.NVCSConf.OSD != "" { + floorText := fmt.Sprintf("%s%s %s", data.Elevator[0].Status.FloorName, runState, config.NVCSConf.OSD) // 璋冪敤hik api 灏嗘枃瀛楁坊鍔犲埌osd鐨勫乏涓嬭 AddFloorToOSD(floorText) diff --git a/service/osd.go b/service/osd.go index e5f5728..3961ca3 100644 --- a/service/osd.go +++ b/service/osd.go @@ -16,6 +16,8 @@ CameraWebPassword = "a1234567" ) +var overlayText TextOverlay + type TextOverlay struct { Id int64 `xml:"id"` Enabled bool `xml:"enabled"` @@ -28,22 +30,25 @@ 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 + // 鑾峰彇宸︿笅瑙掔涓�涓瓧绗︾殑浣嶇疆 + if overlayText.DisplayText == "" { + rsp, err := ISAPIRequest(CameraWebUser, CameraWebPassword, "GET", overlay7Url, "") + if err != nil { + logger.Warn("Get osd info failure") + return + } + + 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)) + _, err := ISAPIRequest(CameraWebUser, CameraWebPassword, "PUT", overlay7Url, string(body)) if err != nil { logger.Warn("Camera osd set failure!!") return -- Gitblit v1.8.0