From cf5a63e3ba397649cb1cbf379f0ad6cd3c2a937e Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期日, 20 十月 2024 16:59:42 +0800
Subject: [PATCH] debug osd

---
 nvcs/cache.go |   45 +++++++++++++++++++++++++++------------------
 1 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/nvcs/cache.go b/nvcs/cache.go
index 55baeef..011ebf6 100644
--- a/nvcs/cache.go
+++ b/nvcs/cache.go
@@ -24,6 +24,9 @@
 
 // 瀛樺偍鏁版嵁鍒扮紦瀛樹腑
 func (c *simpleCache) store(data elevatorRunData) {
+	var floorChanged = true
+
+	// 鍙朢FID妤煎眰
 	if config.RFIDConf.ReadFloor && gRFIDFloor != data.Floor {
 		if data.RunState == RunStop {
 			logger.Warn("A floor error has occurred rfid epc %s, nvcs floor %s", gRFIDFloor, data.Floor)
@@ -35,27 +38,34 @@
 	lastData := c.data.Back()
 
 	// 濡傛灉妤煎眰鐩稿悓锛屽苟涓旀暟鎹湪1绉掑唴锛屽垯蹇界暐
-	if lastData != nil && lastData.Value.(elevatorRunData).Timestamp == data.Timestamp {
+	if lastData != nil {
 		if lastData.Value.(elevatorRunData).Floor == data.Floor {
-			return
+			floorChanged = false
+			if lastData.Value.(elevatorRunData).Timestamp == data.Timestamp {
+				return
+			}
 		}
 	}
 
-	// 鏁版嵁搴撲繚瀛樹竴浠�
-	go func() {
-		var d = models.Positions{
-			DeviceId:   data.Device,
-			Pos:        data.Floor,
-			RunDir:     data.RunState,
-			CreateTime: time.Now().Unix(),
-			TimeString: time.Now().Format("2006-01-02 15:04:05"),
-		}
+	c.data.PushBack(data)
 
-		err := d.Save()
-		if err != nil {
-			logger.Warn("Device position update error:%s", err.Error())
-		}
-	}()
+	if !floorChanged {
+		return
+	}
+
+	// 鏁版嵁搴撲繚瀛樹竴浠�
+	var d = models.Positions{
+		DeviceId:   data.Device,
+		Pos:        data.Floor,
+		RunDir:     data.RunState,
+		CreateTime: time.Now().Unix(),
+		TimeString: time.Now().Format("2006-01-02 15:04:05"),
+	}
+
+	err := d.Save()
+	if err != nil {
+		logger.Warn("Device position update error:%s", err.Error())
+	}
 
 	// 鍐橭SD
 	var runStateStr string
@@ -72,10 +82,9 @@
 		floorText := fmt.Sprintf("%s%s %s", data.Floor, runStateStr, config.NVCSConf.OSD)
 
 		// 璋冪敤hik api 灏嗘枃瀛楁坊鍔犲埌osd鐨勫乏涓嬭
-		go addFloorToOSD(floorText)
+		addFloorToOSD(floorText)
 	}
 
-	c.data.PushBack(data)
 }
 
 // 鍒犻櫎杩囨湡鏁版嵁

--
Gitblit v1.8.0