From 829fe6c6bc33d53fda9c31fd45a37e1df87befff Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期五, 30 一月 2026 11:16:24 +0800
Subject: [PATCH] Merge branch 'clh' into liuyang
---
SourceCode/Bond/Servo/ConfigurationProduction.cpp | 75 +++++++++++++++++++++++++++++++++++++
1 files changed, 75 insertions(+), 0 deletions(-)
diff --git a/SourceCode/Bond/Servo/ConfigurationProduction.cpp b/SourceCode/Bond/Servo/ConfigurationProduction.cpp
new file mode 100644
index 0000000..3aa9bcc
--- /dev/null
+++ b/SourceCode/Bond/Servo/ConfigurationProduction.cpp
@@ -0,0 +1,75 @@
+#include "stdafx.h"
+#include "Configuration.h"
+
+#include <mutex>
+#include <string>
+#include <unordered_map>
+
+static bool TryParseHHMM(const std::string& text, int& outMinutes)
+{
+ int hour = 0;
+ int minute = 0;
+ if (sscanf_s(text.c_str(), "%d:%d", &hour, &minute) != 2) return false;
+ if (hour < 0 || hour >= 24) return false;
+ if (minute < 0 || minute >= 60) return false;
+ outMinutes = hour * 60 + minute;
+ return true;
+}
+
+BOOL CConfiguration::getProductionShiftStartMinutes(int& dayStartMinutes, int& nightStartMinutes)
+{
+ struct CachedShift {
+ BOOL ok = FALSE;
+ int day = 0;
+ int night = 0;
+ bool inited = false;
+ };
+
+ static std::mutex s_mtx;
+ static std::unordered_map<std::string, CachedShift> s_cache;
+
+ const std::string filePath((LPCSTR)(LPCTSTR)m_strFilepath);
+ {
+ std::lock_guard<std::mutex> g(s_mtx);
+ auto it = s_cache.find(filePath);
+ if (it != s_cache.end() && it->second.inited) {
+ dayStartMinutes = it->second.day;
+ nightStartMinutes = it->second.night;
+ return it->second.ok;
+ }
+ }
+
+ char buf[64] = {};
+ GetPrivateProfileStringA("Production", "DayShiftStart", "08:00", buf, (DWORD)sizeof(buf), m_strFilepath);
+ std::string dayStr(buf);
+
+ GetPrivateProfileStringA("Production", "NightShiftStart", "", buf, (DWORD)sizeof(buf), m_strFilepath);
+ std::string nightStr(buf);
+
+ const int kDefaultDay = 8 * 60;
+ const int kDefaultNight = 20 * 60;
+
+ bool okDay = TryParseHHMM(dayStr, dayStartMinutes);
+ bool okNight = false;
+ if (!nightStr.empty()) okNight = TryParseHHMM(nightStr, nightStartMinutes);
+
+ if (!okDay) dayStartMinutes = kDefaultDay;
+ if (!okNight) nightStartMinutes = (dayStartMinutes + 12 * 60) % (24 * 60);
+
+ if (dayStartMinutes == nightStartMinutes) {
+ dayStartMinutes = kDefaultDay;
+ nightStartMinutes = kDefaultNight;
+ {
+ std::lock_guard<std::mutex> g(s_mtx);
+ s_cache[filePath] = CachedShift{ FALSE, dayStartMinutes, nightStartMinutes, true };
+ }
+ return FALSE;
+ }
+
+ const BOOL ok = (okDay && (nightStr.empty() ? TRUE : okNight)) ? TRUE : FALSE;
+ {
+ std::lock_guard<std::mutex> g(s_mtx);
+ s_cache[filePath] = CachedShift{ ok, dayStartMinutes, nightStartMinutes, true };
+ }
+ return ok;
+}
--
Gitblit v1.9.3