From e491cdb48129752324c4e3764f99bd9203c56dec Mon Sep 17 00:00:00 2001
From: lgq <1015864684@qq.com>
Date: 星期二, 31 三月 2026 09:48:44 +0800
Subject: [PATCH] 1.新增VF205门禁机代码

---
 vf205_access/dxmodules/dxNtp.js |   63 +++++++++++++++++++++++++++++++
 1 files changed, 63 insertions(+), 0 deletions(-)

diff --git a/vf205_access/dxmodules/dxNtp.js b/vf205_access/dxmodules/dxNtp.js
new file mode 100644
index 0000000..1e79146
--- /dev/null
+++ b/vf205_access/dxmodules/dxNtp.js
@@ -0,0 +1,63 @@
+//build: 20240523
+//鍚屾鏃堕棿,杩愯鏃堕渶瑕佹妸杩欎釜缁勪欢鍔犺浇鍒颁竴涓嚎绋嬮噷鐨剋hile寰幆,
+//缂虹渷姣忛殧24灏忔椂鍚屾涓�娆★紝涔熸敮鎸佷簨浠惰Е鍙戜富鍔ㄥ悓姝� eventcetner.fire(ntp.MANUAL_SYNC)
+//渚濊禆缁勪欢 dxLogger,dxCommon,dxCenter
+
+import common from "./dxCommon.js"
+import dxNet from './dxNet.js'
+import log from './dxLogger.js'
+const ntp = {}
+/**
+ * 鍚屾鏃堕棿寰幆鍒濆鍖�
+ * @param {string} server 鍚屾鏃堕棿鏈嶅姟鍣ㄥ湴鍧�锛岀己鐪佹槸182.92.12.11 
+ * @param {number} interval 鍚屾鏃堕棿鐨勯棿闅旓紝鍗曚綅鏄垎閽燂紝缂虹渷鏄�24灏忔椂鍚屾涓�娆�
+ * 
+ */
+ntp.beforeLoop = function (server = '182.92.12.11', interval = 24 * 60) {
+    this.server = server
+    this.interval = interval
+    this.tempinterval = 1000//绗竴娆¢殧1绉掑氨寮�濮嬬涓�娆″鏃�
+    this.last = new Date().getTime()
+}
+/**
+ * 鏇存柊鏃跺尯GMT锛屾瘮濡�8锛岃〃绀篏MT8鍖椾含鏃堕棿
+ * @param {number} gmt  鍙栧�艰寖鍥存槸0,1,2....24琛ㄧず鏃跺尯锛�
+ */
+ntp.updateGmt = function (gmt) {
+    if (gmt != undefined && gmt != null) {
+        let cmd = `cp /etc/localtimes/localtime${gmt} /etc/localtime`
+        common.systemBrief(cmd)
+    }
+}
+/**
+ * 绔嬪埢鍚屾
+ */
+ntp.syncnow = false
+/**
+ * 鍚屾鏃堕棿
+ */
+ntp.loop = function () {
+    if (!dxNet.getStatus().connected) {//娌℃湁缃戠粶
+        return
+    }
+    const now = new Date().getTime()
+    const minus = now - this.last
+    if (ntp.syncnow || (minus > (this.tempinterval))) {
+        ntp.syncnow = false
+        let cmd = `ntpdate -u -t 1 '${this.server}' > /dev/null && echo 'Y' || echo 'N'`
+        let res = common.systemWithRes(cmd, 100).split(/\s/)[0]
+        if (res != "Y" ) {
+            // 瀵规椂澶辫触锛�1鍒嗗悗閲嶈瘯
+            log.error('ntp sync failed')
+            this.tempinterval = 60 * 1000
+        } else {
+            // 瀵规椂鎴愬姛
+            log.info('ntp sync success')
+            this.tempinterval = this.interval * 60 * 1000
+            common.systemBrief("hwclock -u -w")
+        }
+        this.last = new Date().getTime()
+    }
+}
+
+export default ntp;
\ No newline at end of file

--
Gitblit v1.9.3