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/dxNet.js |  341 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 341 insertions(+), 0 deletions(-)

diff --git a/vf205_access/dxmodules/dxNet.js b/vf205_access/dxmodules/dxNet.js
new file mode 100644
index 0000000..ad7df4c
--- /dev/null
+++ b/vf205_access/dxmodules/dxNet.js
@@ -0,0 +1,341 @@
+//build:20240626
+//閫氳繃杩欎釜缁勪欢鏉ラ厤缃綉缁滃拰鐩戝惉缃戠粶鐘舵�佸彉鍖�
+//渚濊禆缁勪欢: dxMap,dxLogger,dxDriver,dxEventBus
+import dxMap from './dxMap.js'
+import bus from './dxEventBus.js'
+import { netClass } from './libvbar-m-dxnet.so'
+const netObj = new netClass();
+const map = dxMap.get("default")
+
+const net = {}
+net.TYPE = {
+    "UNKNOWN": 0,
+    "ETHERNET": 1,
+    "WIFI": 2,
+    "4G": 4
+}
+net.DHCP = {
+    STATIC: 1,
+    DYNAMIC: 2,
+    WIFI_AP: 3 //WiFi AP鐑偣妯″紡
+}
+
+/**
+ * 缃戠粶鍒濆鍖�,wifi鎴栦互澶綉锛屽鏋滆繛涓嶄笂缃戠粶浼氳嚜鍔ㄤ笉鏂殑閲嶈瘯锛屾棤闇�閲嶅init銆備絾鏄痠nit鍚庨渶瑕佽疆璇㈠幓鑾峰彇缃戠粶鐘舵�侊紙閫氳繃msgReceive)
+ * 涔熷彲浠ョ洿鎺ヤ娇鐢ㄧ畝鍖栨柟娉昫xNet.run锛屾棤闇�杞
+ * @param {object} options 鍒濆鍖栫綉缁滅殑鍙傛暟
+ *       @param {number} type 蹇呭~ 缃戠粶绫诲瀷锛屽弬鑰僴et.TYPE鏋氫妇
+ *       @param {number} dhcp 蹇呭~ DHCP锛屽弬鑰僴et.DHCP鏋氫妇
+ *       @param {string} macAddr 蹇呭~ mac鍦板潃,缂虹渷浣跨敤dxCommon.getUuid2mac()鏂规硶鏉ヨ幏鍙杕ac鍦板潃
+ *       @param {string} ip 闈炲繀濉� 缃戠粶ip鍦板潃
+ *       @param {string} gateway 闈炲繀濉� 缃戝叧鍦板潃
+ *       @param {string} netmask 闈炲繀濉� 瀛愮綉鎺╃爜
+ *       @param {string} dns0 闈炲繀濉� DNS鍦板潃
+ *       @param {string} dns1 闈炲繀濉� 澶囬�塂NS鍦板潃
+ * @returns 
+ */
+net.init = function (options) {
+    let ret = netObj.init()
+    if (!ret) {
+        return false
+    }
+    if (!options) {
+        throw new Error("dxNet.init: 'options' parameter should not be null or empty")
+    }
+    ret = netObj.setMasterCard(options.type)
+    if (!ret) {
+        return false
+    }
+    netObj.setMacaddr(options.type, options.macAddr)
+    ret = netObj.cardEnable(options.type, true)
+    if (!ret) {
+        return false
+    }
+    if (options.dhcp === 1) {
+        return netObj.setModeByCard(options.type, 1, {
+            ip: options.ip,
+            gateway: options.gateway,
+            netmask: options.netmask,
+            dns0: options.dns0,
+            dns1: options.dns1,
+        })
+    } else if (options.dhcp === 2) {
+        return netObj.setModeByCard(options.type, options.dhcp)
+    }
+    return false
+}
+
+/**
+ * 鑾峰彇Mac鍦板潃 
+ * @param {number} type  蹇呭~ 缃戠粶绫诲瀷锛屽弬鑰僴et.TYPE鏋氫妇
+ * @returns   Mac鍦板潃
+ */
+net.getMacaddr = function (type) {
+    return netObj.getMacaddr(type)
+}
+/**
+ * 璁剧疆Mac鍦板潃
+ * @param {number} type  蹇呭~ 缃戠粶绫诲瀷锛屽弬鑰僴et.TYPE鏋氫妇
+ * @param {string} addr  Mac鍦板潃,蹇呭~锛屾牸寮忕被浼� b2:a1:63:3f:99:b6
+ * @returns   true锛氭垚鍔� 涓荤綉鍗$被鍨嬶紝false 澶辫触
+ */
+net.setMacaddr = function (type, addr) {
+    if (type === null || type === undefined) {
+        throw new Error("dxNet.setMacaddr:'type' paramter should not be null or empty")
+    }
+    if (addr === null || addr === undefined || addr.length < 1) {
+        throw new Error("dxNet.setMacaddr:'addr' paramter should not be null or empty")
+    }
+    return netObj.setMacaddr(type, addr)
+}
+/**
+ * 浣胯兘缃戝崱锛屽苟娣诲姞鍒扮綉缁滅鐞嗘ā鍧�
+ * @param {number} type  蹇呭~ 缃戠粶绫诲瀷锛屽弬鑰僴et.TYPE鏋氫妇
+ * @param {boolean} on  寮�鍚�/鍏抽棴
+ * @returns   0锛氭垚鍔� <0 澶辫触
+ */
+net.cardEnable = function (type, on) {
+    if (type === null || type === undefined) {
+        throw new Error("dxNet.cardEnable: 'type' parameter should not be null or empty")
+    }
+    if (on === null) {
+        throw new Error("dxNet.cardEnable: 'on' parameter should not be null or empty")
+    }
+    return netObj.cardEnable(type, on)
+}
+/**
+ * net缃戠粶閿�姣�
+ * @return true锛氭垚鍔燂紝false 澶辫触
+ */
+net.exit = function () {
+    return netObj.exit()
+}
+/**
+ * 璁剧疆鎸囧畾缃戝崱鐨勬ā寮忓強瀵瑰簲鍙傛暟缃戠粶鍙傛暟
+ * @param {number} type   蹇呭~ 缃戠粶绫诲瀷锛屽弬鑰僴et.TYPE鏋氫妇
+ * @param {number} mode   蹇呭~ DHCP锛屽弬鑰僴et.DHCP鏋氫妇
+ * @param param  缃戠粶鍙傛暟
+ * @return true锛氭垚鍔燂紝false 澶辫触
+ */
+net.setModeByCard = function (type, mode, param) {
+    if (type === null || type === undefined) {
+        throw new Error("dxNet.setModeByCard: 'type' parameter should not be null or empty")
+    }
+    if (mode === null) {
+        throw new Error("dxNet.setModeByCard:'mode' parameter should not be null or empty")
+    }
+    return netObj.setModeByCard(type, mode, param)
+}
+/**
+ * 鑾峰彇鎸囧畾缃戝崱鐨勬ā寮忓強瀵瑰簲鍙傛暟缃戠粶鍙傛暟
+ * @param {number} type  蹇呭~ 缃戠粶绫诲瀷锛屽弬鑰僴et.TYPE鏋氫妇
+ * @returns   濡傛灉鏄潤鎬佺綉缁滄ā寮忥紝灏变細杩斿洖ip銆佺綉鍏崇瓑淇℃伅
+ */
+net.getModeByCard = function (type) {
+    if (type === null || type === undefined) {
+        throw new Error("dxNet.getModeByCard: 'type' parameter should not be null or empty")
+    }
+
+    return netObj.getModeByCard(type)
+}
+/**
+ * 璁剧疆涓荤綉鍗★紝搴旂敤绋嬪簭缃戠粶鐘舵�佺敱娆$綉鍗″喅瀹�
+ * @param {number} type  蹇呭~ 缃戠粶绫诲瀷锛屽弬鑰僴et.TYPE鏋氫妇
+ * @returns    true锛氭垚鍔燂紝false 澶辫触
+ */
+net.setMasterCard = function (type) {
+    if (type === null || type === undefined) {
+        throw new Error("dxNet.setMasterCard: 'type' parameter should not be null or empty")
+    }
+    return netObj.setMasterCard(type)
+}
+/**
+ * 鑾峰彇涓荤綉鍗�
+ * @returns   >0锛氭垚鍔� 涓荤綉鍗$被鍨嬶紝<0 澶辫触
+ */
+net.getMasterCard = function () {
+    return netObj.getMasterCard()
+}
+/**
+ * 鑾峰彇缃戠粶鐘舵�� 绫讳技{"status":4锛�"connected":true} ,鍏朵腑status濡備笅
+ *  0,    鏈垵濮嬫��
+    1,    缃戝崱澶勪簬鍏抽棴鐘舵��
+    2,    缃戝崱澶勪簬鎵撳紑鐘舵��
+    3,    缃戠嚎宸叉彃鍏ユ垨鑰厀ifi宸茶繛鎺sid 浣嗘湭鍒嗛厤ip
+    4,    宸叉垚鍔熷垎閰峣p
+    5     宸茶繛鎺ユ寚瀹氭湇鍔℃垨鑰呴�氳繃娴嬭瘯鍙互杩炴帴鍒板箍鍩熺綉
+ * @returns   缃戠粶鐘舵��
+ */
+net.getStatus = function () {
+    let status = netObj.getStatus()
+    return { "status": status, "connected": status >= 4 }
+}
+/**
+ * 璁剧疆缃戠粶鐘舵��
+ * @param {number} status 缃戠粶鐘舵�侊紝蹇呭~
+ * @returns true锛氭垚鍔燂紝false 澶辫触
+ */
+net.setStatus = function (status) {
+    if (status === null || status === undefined) {
+        throw new Error("dxNet.setStatus: 'status' parameter should not be null or empty")
+    }
+    return netObj.setStatus(status)
+}
+
+/**
+ * 閲嶆柊浣胯兘缃戝崱
+ * @param {number} type         缃戠粶绫诲瀷锛屽繀濉�
+ * @param {number} phy_reset    寮�鍚�/鍏抽棴锛屽繀濉�
+ * @returns true锛氭垚鍔燂紝false 澶辫触
+ */
+net.netCardReset = function (type, phy_reset) {
+    if (type === null || type === undefined) {
+        throw new Error("dxNet.setStatus: 'status' parameter should not be null or empty")
+    }
+    if (phy_reset === null || phy_reset === undefined) {
+        throw new Error("dxNet.setStatus: 'status' parameter should not be null or empty")
+    }
+    return netObj.netCardReset(type, phy_reset)
+}
+
+/**
+ * 鑾峰彇wifi鍒楄〃
+ * @param {*} timeout 蹇呭~
+ * @param {*} interval 蹇呭~
+ * @returns wifi鍒楄〃
+ */
+net.netGetWifiSsidList = function (timeout, interval) {
+    if (timeout === null || timeout === undefined) {
+        throw new Error("dxNet.netGetWifiSsidList: 'timeout' parameter should not be null or empty")
+    }
+    if (interval === null) {
+        throw new Error("dxNet.netGetWifiSsidList: 'interval' parameter should not be null or empty")
+    }
+    return netObj.netGetWifiSsidList(timeout, interval)
+}
+/**
+ * 杩炴帴鍒皐ifi
+ * @param {*} ssid 蹇呭~
+ * @param {*} psk 蹇呭~
+ * @param {*} params 蹇呭~
+ * @returns 
+ */
+net.netConnectWifiSsid = function (ssid, psk, params) {
+    if (ssid === null) {
+        throw new Error("dxNet.netConnectWifiSsid: 'ssid' parameter should not be null or empty")
+    }
+    if (psk === null) {
+        throw new Error("dxNet.netConnectWifiSsid: 'psk' parameter should not be null or empty")
+    }
+    if (params === null) {
+        throw new Error("dxNet.netConnectWifiSsid: 'params' parameter should not be null or empty")
+    }
+    return netObj.netConnectWifiSsid(ssid, psk, params)
+}
+/**
+ * 鑾峰彇宸蹭繚瀛樼殑鐑偣鍒楄〃
+ * @returns  宸蹭繚瀛樼殑鐑偣鍒楄〃
+ */
+net.netGetWifiSavedList = function () {
+    return netObj.netGetWifiSavedList()
+}
+/**
+ * 鏂紑褰撳墠杩炴帴鐨剋ifi鐑偣
+ * @returns  
+ */
+net.netDisconnetWifi = function () {
+    return netObj.netDisconnetWifi()
+}
+/**
+ * 鑾峰彇褰撳墠鐑偣鐨勪俊鎭�
+ * @param timeout 蹇呭~
+ * @returns  
+ */
+net.netGetCurrentWifiInfo = function (timeout) {
+    if (timeout === null) {
+        throw new Error("dxNet.netGetCurrentWifiInfo: 'timeout' parameter should not be null or empty")
+    }
+    return netObj.netGetCurrentWifiInfo(timeout)
+}
+
+/**
+ * 妫�鏌ユ秷鎭槦鍒楁槸鍚︿负绌�
+ * @returns true涓虹┖ false涓嶄负绌�
+ */
+net.msgIsEmpty = function () {
+    return netObj.msgIsEmpty()
+}
+/**
+ * 浠庢秷鎭槦鍒椾腑鍙栫綉缁滃綋鍓嶇姸鎬佹暟鎹紝杩斿洖缁撴瀯绫讳技{"type":1,"status":4锛�"connected":true}
+ * 鍏朵腑type鍙傝�僴et.TYPE鏋氫妇
+ * 鍏朵腑status鐨勫�艰鏄庡涓嬶細
+ *  0,    鏈垵濮嬫��
+    1,    缃戝崱澶勪簬鍏抽棴鐘舵��
+    2,    缃戝崱澶勪簬鎵撳紑鐘舵��
+    3,    缃戠嚎宸叉彃鍏ユ垨鑰厀ifi宸茶繛鎺sid 浣嗘湭鍒嗛厤ip
+    4,    宸叉垚鍔熷垎閰峣p
+    5     宸茶繛鎺ユ寚瀹氭湇鍔℃垨鑰呴�氳繃娴嬭瘯鍙互杩炴帴鍒板箍鍩熺綉
+ * @returns   瀛楃涓茬被鍨嬬殑娑堟伅鏁版嵁
+ */
+net.msgReceive = function () {
+    let res = JSON.parse(netObj.msgReceive());
+    if (res.status >= 4) {
+        res.connected = true
+    } else {
+        res.connected = false
+    }
+    return res
+}
+
+net.STATUS_CHANGE = '__netstatus__changed'
+
+/**
+ * 绠�鍖栫綉缁滅粍浠剁殑浣跨敤锛屾棤闇�杞鍘昏幏鍙栫綉缁滅姸鎬侊紝缃戠粶鐨勭姸鎬佷細閫氳繃eventBus鍙戦�佸嚭鍘�
+ * run 鍙細鎵ц涓�娆★紝鎵ц涔嬪悗缃戠粶鍩烘湰閰嶇疆涓嶈兘淇敼
+ * 濡傛灉闇�瑕佸疄鏃惰幏鍙栫綉缁滅姸鎬佸彉鍖栵紝鍙互璁㈤槄 eventBus鐨勪簨浠讹紝浜嬩欢鐨則opic鏄痭et.STATUS_CHANGE锛屼簨浠剁殑鍐呭鏄被浼納"type":1,"status":4锛�"connected":true}
+ * 鍏朵腑type鍙傝�僴et.TYPE鏋氫妇
+ * 鍏朵腑status鐨勫�艰鏄庡涓嬶細
+ *  0,    鏈垵濮嬫��
+    1,    缃戝崱澶勪簬鍏抽棴鐘舵��
+    2,    缃戝崱澶勪簬鎵撳紑鐘舵��
+    3,    缃戠嚎宸叉彃鍏ユ垨鑰厀ifi宸茶繛鎺sid 浣嗘湭鍒嗛厤ip
+    4,    宸叉垚鍔熷垎閰峣p
+    5     宸茶繛鎺ユ寚瀹氭湇鍔℃垨鑰呴�氳繃娴嬭瘯鍙互杩炴帴鍒板箍鍩熺綉
+ * @param {object} options 鍙傝�僫nit鐨刼ptions鎻忚堪
+ */
+net.run = function (options) {
+    if (options === undefined || options.length === 0) {
+        throw new Error("dxnet.run:'options' parameter should not be null or empty")
+    }
+    let workerFile = '/app/code/dxmodules/netWorker.js'
+    let init = map.get("__net__run_init")
+    if (!init) {//纭繚鍙垵濮嬪寲涓�娆�
+        map.put("__net__run_init", options)
+        bus.newWorker('__net', workerFile)
+    }
+}
+
+/**
+ * 濡傛灉net鍗曠嫭涓�涓嚎绋嬶紝鍙互鐩存帴浣跨敤run鍑芥暟锛屼細鑷姩鍚姩涓�涓嚎绋嬶紝
+ * 濡傛灉鎯冲姞鍏ュ埌鍏朵粬宸叉湁鐨勭嚎绋嬶紝鍙互浣跨敤浠ヤ笅灏佽鐨勫嚱鏁�
+ */
+net.worker = {
+    //鍦╳hile寰幆鍓�
+    beforeLoop: function (options) {
+        net.init(options)
+    },
+    //鍦╳hile寰幆閲�
+    loop: function () {
+        if (!net.msgIsEmpty()) {
+            let res = net.msgReceive();
+            if (res.status >= 4) {
+                res.connected = true
+            } else {
+                res.connected = false
+            }
+            bus.fire(net.STATUS_CHANGE, res)
+        }
+    }
+}
+
+export default net;

--
Gitblit v1.9.3