From 1f096af76bf2398348c12fe3d3144cdd7c762985 Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期日, 20 十月 2024 23:34:20 +0800
Subject: [PATCH] fix find move dir
---
controller/nvcsCtl.go | 16 +-------
repository/captureRepo.go | 48 ++++++++++++++----------
nvcs/nvcs.go | 10 ++--
nvcs/cache.go | 9 +---
4 files changed, 37 insertions(+), 46 deletions(-)
diff --git a/controller/nvcsCtl.go b/controller/nvcsCtl.go
index f3ed2bc..e7aca45 100644
--- a/controller/nvcsCtl.go
+++ b/controller/nvcsCtl.go
@@ -17,19 +17,7 @@
}
func (n NVCSController) RunStatus(c *gin.Context) {
- var runStatus = make(map[string]string, 0)
- var floor, runState = nvcs.CurrentRunState()
+ var runState = nvcs.CurrentRunState()
- runStatus["floor"] = floor
-
- switch runState {
- case 0:
- runStatus["status"] = "鍋�"
- case 1:
- runStatus["status"] = "涓�"
- case 2:
- runStatus["status"] = "涓�"
- }
-
- c.JSON(http.StatusOK, gin.H{"success": true, "data": runStatus, "msg": "ok"})
+ c.JSON(http.StatusOK, gin.H{"success": true, "data": runState, "msg": "ok"})
}
diff --git a/nvcs/cache.go b/nvcs/cache.go
index eb89865..d229d85 100644
--- a/nvcs/cache.go
+++ b/nvcs/cache.go
@@ -113,10 +113,6 @@
func (c *simpleCache) getPositionByTime(timestamp int64) (runData ElevatorRunData) {
node := c.data.Back() // 浠庨摼琛ㄥ熬閮ㄥ紑濮�
- if node == nil {
- return
- }
-
for node != nil {
if data, ok := node.Value.(ElevatorRunData); ok {
if data.Timestamp >= timestamp {
@@ -134,10 +130,8 @@
}
func (c *simpleCache) getMovePosition(timestamp int64, floor string) (runData ElevatorRunData) {
+ logger.Debug("getMovePosition")
node := c.data.Back() // 浠庨摼琛ㄦ湯灏惧紑濮�
- if node == nil {
- return
- }
// 鎵惧埌鏈�杩戠殑绗﹀悎鏃堕棿鎴崇殑鑺傜偣
for node != nil {
@@ -157,6 +151,7 @@
if current, ok := node.Value.(ElevatorRunData); ok && current.Timestamp >= timestamp {
for node != nil {
if nextNode := node.Next(); nextNode != nil {
+ logger.Debug("next node %v", nextNode.Value.(ElevatorRunData))
if nextData, ok := nextNode.Value.(ElevatorRunData); ok {
if nextData.Floor == floor {
node = nextNode // 鍚戝墠绉诲姩鑺傜偣
diff --git a/nvcs/nvcs.go b/nvcs/nvcs.go
index e8cd45f..17e55aa 100644
--- a/nvcs/nvcs.go
+++ b/nvcs/nvcs.go
@@ -44,13 +44,13 @@
}
}
-func CurrentRunState() (string, int) {
- runState := cache.data.Back().Value
- if runState == nil {
- return "", 0
+func CurrentRunState() (runState ElevatorRunData) {
+ node := cache.data.Back()
+ if node == nil {
+ return
}
- return runState.(ElevatorRunData).Floor, runState.(ElevatorRunData).RunState
+ return node.Value.(ElevatorRunData)
}
func FindPositionByTime(timestamp int64) ElevatorRunData {
diff --git a/repository/captureRepo.go b/repository/captureRepo.go
index 73f0347..92d391c 100644
--- a/repository/captureRepo.go
+++ b/repository/captureRepo.go
@@ -3,6 +3,8 @@
import (
"encoding/base64"
"encoding/json"
+ "strconv"
+ "strings"
"time"
"gat1400Exchange/client"
@@ -218,16 +220,8 @@
floor = runState.Floor
for i := 0; i < config.NVCSConf.WaitRunTime; i++ {
- if runState = nvcs.FindMovePosition(faceAppearTime.Unix()+3, floor); runState.Floor != "" {
- switch runState.RunState {
- case nvcs.RunUp:
- runDir = "in"
- case nvcs.RunDown:
- runDir = "out"
- case nvcs.RunStop:
- runDir = ""
- }
-
+ if runState = nvcs.CurrentRunState(); runState.Floor != "" && runState.Floor != floor {
+ runDir = compareFloor(floor, runState.Floor)
break
}
@@ -279,16 +273,8 @@
floor = runState.Floor
for i := 0; i < config.NVCSConf.WaitRunTime; i++ {
- if runState = nvcs.FindMovePosition(faceAppearTime.Unix()+3, floor); runState.Floor != "" {
- switch runState.RunState {
- case nvcs.RunUp:
- runDir = "in"
- case nvcs.RunDown:
- runDir = "out"
- case nvcs.RunStop:
- runDir = ""
- }
-
+ if runState = nvcs.CurrentRunState(); runState.Floor != "" && runState.Floor != floor {
+ runDir = compareFloor(floor, runState.Floor)
break
}
@@ -355,3 +341,25 @@
logger.Warn(err.Error())
}
}
+
+func compareFloor(str1, str2 string) string {
+ // 鍘绘帀瀛楃涓叉渶鍚庝竴涓瓧绗� 'F'
+ numStr1 := strings.TrimSuffix(str1, "F")
+ numStr2 := strings.TrimSuffix(str2, "F")
+
+ // 杞崲涓� int 绫诲瀷
+ num1, err1 := strconv.Atoi(numStr1)
+ num2, err2 := strconv.Atoi(numStr2)
+
+ // 妫�鏌ヨ浆鎹㈡槸鍚︽垚鍔�
+ if err1 != nil || err2 != nil {
+ return ""
+ }
+
+ // 姣旇緝涓や釜鏁存暟鐨勫ぇ灏�
+ if num1 > num2 {
+ return "out"
+ } else {
+ return "in"
+ }
+}
--
Gitblit v1.8.0