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/dxUart.js | 242 ++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 242 insertions(+), 0 deletions(-)
diff --git a/vf205_access/dxmodules/dxUart.js b/vf205_access/dxmodules/dxUart.js
new file mode 100644
index 0000000..8e01ebe
--- /dev/null
+++ b/vf205_access/dxmodules/dxUart.js
@@ -0,0 +1,242 @@
+//build: 20240715
+//鏁版嵁閫氫俊閫氶亾锛屽寘鎷覆鍙o紙Serial port锛夈�乁SB锛圲niversal Serial Bus锛夊拰闊︽牴锛圵iegand锛�
+//渚濊禆缁勪欢:dxDriver锛宒xStd锛宒xLogger锛宒xMap锛宒xEventBus,dxCommon
+import { channelClass } from './libvbar-m-dxchannel.so'
+import std from './dxStd.js'
+import dxMap from './dxMap.js'
+import dxCommon from './dxCommon.js'
+import bus from './dxEventBus.js'
+const uartObj = new channelClass();
+const map = dxMap.get('default')
+const uart = {}
+uart.TYPE = {
+ USBKBW: 1,//USB Keyboard Wedge閫氳繃USB鎺ュ彛杩炴帴閿洏锛屽苟浠ラ煢鏍瑰崗璁殑褰㈠紡浼犺緭鏁版嵁
+ USBHID: 2,//USB浜轰綋鎺ュ彛璁惧锛圲SB Human Interface Device锛夐�氶亾绫诲瀷
+ UART: 3,//琛ㄧずUART閫氶亾绫诲瀷锛屽嵆涓插彛閫氶亾
+ WIEGAND: 4//闊︽牴锛圵iegand锛夐�氶亾绫诲瀷
+}
+
+/* 鍚勭被閫氶亾 IO 鎺у埗鎿嶄綔鐨勮缃�夐」鏋氫妇 */
+uart.IOC_SET_CMD = {
+ /* 璁剧疆KBW閫氶亾鐨勯厤缃弬鏁� */
+ CHANNEL_IOC_SET_KBW_CONFIG : 1,
+ /* 璁剧疆KBW閫氶亾鐨勪笂浣嶆満鍙傛暟 */
+ CHANNEL_IOC_SET_KBW_UPPER : 2,
+ /* KBW涓婄嚎鏃堕棿 */
+ CHANNEL_IOC_SET_KBW_UPTIME : 3,
+ /* KBW涓嬬嚎鏃堕棿 */
+ CHANNEL_IOC_SET_KBW_DOWNTIME : 4,
+ /* 璁剧疆HID閫氶亾鐨勬姤鍛婇暱搴� */
+ CHANNEL_IOC_SET_HID_REPORT_LEN : 5,
+ /* 璁剧疆UART閫氶亾鐨勫弬鏁� */
+ CHANNEL_IOC_SET_UART_PARAM : 6,
+ /* 璁剧疆闊︽牴閫氶亾鐨勫伐浣滄ā寮� */
+ CHANNEL_IOC_SET_WIEGAND_MODE : 7,
+ /* 璁剧疆闊︽牴閫氶亾鐨凣PIO閰嶇疆 */
+ CHANNEL_IOC_SET_WIEGAND_GPIO : 8,
+ /* 璁剧疆闊︽牴閫氶亾鐨勫欢杩熸椂闂� */
+ CHANNEL_IOC_SET_WIEGAND_DELAY : 9,
+ /* 璁剧疆闊︽牴閫氶亾鐨勬棩蹇楄褰曞姛鑳� */
+ CHANNEL_IOC_SET_WIEGAND_LOG : 10
+
+};
+
+/* 闊︽牴閫氶亾鐨勪笉鍚屽伐浣滄ā寮� */
+uart.WIEGAND_MODE = {
+ /* 闊︽牴妯″紡鍒濆鍖栧�� */
+ WIEGAND_MODE_INIT : 0,
+ /* 闊︽牴 26 浣嶆ā寮� */
+ WIEGAND_MODE_26 : 1,
+ /* 闊︽牴 34 浣嶆ā寮� */
+ WIEGAND_MODE_34 : 2,
+ /* 闊︽牴 128 浣嶆ā寮� */
+ WIEGAND_MODE_128 : 3,
+ /* 闊︽牴 256 浣嶆ā寮� */
+ WIEGAND_MODE_256 : 4,
+ /* 闊︽牴 2048 浣嶆ā寮� */
+ WIEGAND_MODE_2048 : 5,
+ /* 鑷畾涔夌殑闊︽牴妯″紡, 鏈�澶у彂閫� 6400 浣� */
+ WIEGAND_MODE_CUSTOM : 6
+};
+
+/**
+ * 鎵撳紑淇¢亾
+ * @param {number} type 閫氶亾绫诲瀷锛屽弬鑰冩灇涓� TYPE锛屽繀濉�
+ * @param {string} path 涓嶅悓鐨勮澶囨垨鍚屼竴璁惧鐨勪笉鍚岀被鍨嬮�氶亾瀵瑰簲鐨刾ath涓嶄竴鏍凤紝姣斿DW200鐨�485瀵瑰簲鐨勫�兼槸"/dev/ttyS2"锛屽繀濉�
+ * @param {string} id 鍙ユ焺id锛岄潪蹇呭~锛堣嫢鎵撳紑澶氫釜瀹炰緥闇�瑕佷紶鍏ュ敮涓�id锛�
+ */
+uart.open = function (type, path, id) {
+ if (type === undefined || type === null) {
+ throw new Error("uart.open:'type' should not be null or empty")
+ }
+ if (path === undefined || path === null) {
+ throw new Error("uart.open:'path' should not be null or empty")
+ }
+
+ let pointer = uartObj.open(type, path);
+
+ if (pointer === undefined || pointer === null) {
+ throw new Error("uart.open: open failed")
+ }
+
+ dxCommon.handleId("uart", id, pointer)
+}
+
+/**
+ * 淇¢亾鏁版嵁鍙戦��
+ * @param {ArrayBuffer} buffer 瑕佸彂閫佺殑鏁版嵁锛屽繀濉�
+ * @param {string} id 鍙ユ焺id锛岄潪蹇呭~锛堥渶淇濇寔鍜宨nit涓殑id涓�鑷达級
+ * @returns true/false
+ */
+uart.send = function (buffer, id) {
+ if (buffer === undefined || buffer === null) {
+ throw new Error("uart.send: 'buffer' should not be null or empty")
+ }
+ let pointer = dxCommon.handleId("uart", id)
+
+ return uartObj.send(pointer, buffer);
+}
+
+/**
+ * 淇¢亾鏁版嵁鍙戦�侊紝浣跨敤寰厜閫氫俊鍗忚鏍煎紡
+ * @param {string/object} data 瑕佸彂閫佺殑鏁版嵁锛屽繀濉�
+ * @param {string} id 鍙ユ焺id锛岄潪蹇呭~锛堥渶淇濇寔鍜宨nit涓殑id涓�鑷达級
+ * @returns true/false
+ */
+uart.sendVg = function (data, id) {
+ if (!data) {
+ return
+ }
+ if (typeof data === 'string') {
+ uart.send(dxCommon.hexStringToArrayBuffer(data), id)
+ return
+ }
+ let pack = '55aa' + data.cmd
+ if (data.hasOwnProperty('result')) {
+ pack += data.result
+ }
+ pack += (data.length % 256).toString(16).padStart(2, '0')
+ pack += (Math.floor(data.length / 256)).toString(16).padStart(2, '0')
+ pack += data.data
+ let all = dxCommon.hexToArr(pack)
+ let bcc = dxCommon.calculateBcc(all)
+ all.push(bcc)
+ uart.send(new Uint8Array(all).buffer, id)
+}
+
+/**
+ * 鎺ユ敹鏁版嵁锛岄渶瑕佸湪绾跨▼閲岃疆璇㈠幓鑾峰彇,杩斿洖Uint8Array绫诲瀷
+ * 濡傛灉鎺ユ敹鍒扮殑鏁版嵁娌℃湁杈惧埌size闀垮害锛屼細缁х画绛夊緟鐩村埌鎺ユ敹鍒皊ize闀垮害锛屼絾鏄鏋渢imeout寰堢煭锛屽氨浼氭湁鍙兘娌℃敹瀹屽氨缁撴潫杩欎竴娆℃搷浣�
+ * @param {number} size 鎺ユ敹鏁版嵁鐨勫瓧鑺傛暟锛屽繀濉�
+ * @param {number} timeout 瓒呮椂鏃堕棿锛堟绉掞級杩欎釜鍑芥暟浼氶樆濉炵瓑寰呮渶澶氳繖涓椂闂村氨缁撴潫锛屽鏋滄彁鍓嶆帴鏀跺埌浜唖ize涓暟鎹篃浼氱粨鏉燂紝闈炲繀濉紝缂虹渷鏄�10ms
+ * @param {string} id 鍙ユ焺id锛岄潪蹇呭~锛堥渶淇濇寔鍜宨nit涓殑id涓�鑷达級
+ * @returns Uint8Array,杩斿洖鍊肩殑byteLength琛ㄧず鎺ユ敹鍒扮殑闀垮害锛屽鏋滀负0琛ㄧず娌℃湁鎺ユ敹鍒颁换浣曟暟鎹�
+ */
+uart.receive = function (size, timeout, id) {
+ if (size === undefined || size === null) {
+ throw new Error("uart.receive:'size' should not be null or empty")
+ }
+
+ if (timeout === undefined || timeout === null) {
+ timeout = 10
+ }
+
+ let pointer = dxCommon.handleId("uart", id)
+
+ let res = uartObj.receive(pointer, size, timeout)
+ if (res === null) {
+ return null
+ }
+ return new Uint8Array(res)
+}
+
+/**
+ * 璋冪敤淇¢亾鐗规畩IO鎺ュ彛
+ * @param {*} request
+ * @param {*} arg
+ * @param {string} id 鍙ユ焺id锛岄潪蹇呭~锛堥渶淇濇寔鍜宨nit涓殑id涓�鑷达級
+ * @returns true/false
+ */
+uart.ioctl = function (request, arg, id) {
+ let pointer = dxCommon.handleId("uart", id)
+
+ return uartObj.ioctl(pointer, request, arg)
+}
+
+/**
+ * 鍏抽棴淇¢亾
+ * @param {string} id 鍙ユ焺id锛岄潪蹇呭~锛堥渶淇濇寔鍜宨nit涓殑id涓�鑷达級
+ * @returns true/false
+ */
+uart.close = function (id) {
+ let pointer = dxCommon.handleId("uart", id)
+
+ return uartObj.close(pointer)
+}
+
+
+/**
+ * 鍒锋柊淇¢亾
+ * @param {number} queue_selector 蹇呭~
+ * @param {string} id 鍙ユ焺id锛岄潪蹇呭~锛堥渶淇濇寔鍜宨nit涓殑id涓�鑷达級
+ * @returns true/false
+ */
+uart.flush = function (queue_selector, id) {
+ if (queue_selector == null) {
+ throw new Error("queue_selector should not be null or empty")
+ }
+ let pointer = dxCommon.handleId("uart", id)
+
+ return uartObj.flush(pointer, queue_selector);
+}
+
+
+uart.VG = {
+ RECEIVE_MSG: '__uartvg__MsgReceive',
+}
+
+/**
+ * 绠�鍖栧井鍏夐�氫俊鍗忚鐨勪娇鐢紝
+ * 1. 鎺ュ彈鏁版嵁锛氭妸TLV鐨勪簩杩涘埗鐨勬暟鎹帴鍙楀埌鍚庤В鏋愭垚瀵硅薄锛屽苟浠ventbus鐨別vent鍙戦�佸嚭鍘�(uart.VG.RECEIVE_MSG+options.id)
+ * 杩斿洖鐨勫璞℃牸寮忥細{cmd:"2a",result:"01",length:7,data:"0a1acc320fee32",bcc:true}
+ * cmd: 1涓瓧鑺傜殑鍛戒护瀛楋紝16杩涘埗瀛楃涓�
+ * result:1涓瓧鑺傜殑鏍囪瘑瀛楋紝琛ㄧず鏁版嵁澶勭悊鐨勭粨鏋滐紝鎴愬姛鎴栧け璐ユ垨鍏朵粬鐘舵�併�傚彧鏈夊弽棣堟暟鎹墠鏈夋爣璇嗗瓧锛�16杩涘埗瀛楃涓�
+ * length锛氭暟鎹殑闀垮害锛屽湪TLV閲岀敤2涓瓧鑺傛潵瀹氫箟锛岃繖閲岀洿鎺ヨ浆鎴�10杩涘埗鐨勬暟瀛�
+ * data锛氬涓瓧鑺傜殑鏁版嵁鍩燂紝16杩涘埗瀛楃涓�
+ * bcc: bcc鏍¢獙鎴愬姛鎴栧け璐�
+ * 2. 鍙戦�佹暟鎹細鎶婂璞¤浆鎴怲LV鏍煎紡鐨勪簩杩涘埗鏁版嵁鍐嶅彂閫佸嚭鍘伙紝鍙互閫氳繃uart.sendVg('瑕佸彂閫佺殑鏁版嵁',id)锛屾暟鎹牸寮忓涓�
+ * 鍙戦�佺殑鏁版嵁鏍煎紡鏈変簩绉� 1.瀵硅薄鏍煎紡 锛歿cmd:"2a",result:"01",length:7,data:"0a1acc320fee32"} 2. 瀹屾暣鐨�16杩涘埗瀛楃涓�'55AA09000000F6'
+ * 3. 鍚屾牱鐨刬d锛屽娆¤皟鐢╮unvg涔熷彧浼氭墽琛屼竴娆�
+ *
+ * @param {object} options 鍚姩鐨勫弬鏁�
+ * @param {number} options.type 閫氶亾绫诲瀷锛屽弬鑰冩灇涓� TYPE锛屽繀濉� 锛堝吋瀹筓SBHID鍧椾紶杈擄紝榛樿1024姣忓潡锛�
+ * @param {string} options.path 涓嶅悓鐨勮澶囨垨鍚屼竴璁惧鐨勪笉鍚岀被鍨嬮�氶亾瀵瑰簲鐨刾ath涓嶄竴鏍凤紝姣斿DW200鐨�485瀵瑰簲鐨勫�兼槸"/dev/ttyS2"锛屽繀濉�
+ * @param {number} options.result 0鍜�1(缂虹渷鏄�0)锛屾爣璇嗘槸鎺ユ敹鐨勬暟鎹繕鏄彂閫佺殑鏁版嵁鍖呭惈鏍囪瘑瀛楄妭锛�0琛ㄧず鎺ュ彈鐨勬暟鎹笉鍖呮嫭鏍囪瘑瀛楋紝鍙戦�佺殑鏁版嵁鍖呮嫭锛�1鏄弽涔�
+ * @param {number} options.passThrough passThrough涓簍rue鍒欐帴鏀剁殑鏁版嵁浣跨敤閫忎紶妯″紡锛岄潪蹇呭~
+ * @param {string} options.id 鍙ユ焺id锛岄潪蹇呭~锛堣嫢鍒濆鍖栧涓疄渚嬮渶瑕佷紶鍏ュ敮涓�id锛�
+ */
+uart.runvg = function (options) {
+ if (options === undefined || options.length === 0) {
+ throw new Error("dxuart.runvg:'options' parameter should not be null or empty")
+ }
+ if (options.id === undefined || options.id === null || typeof options.id !== 'string') {
+ // 鍙ユ焺id
+ options.id = ""
+ }
+ if (options.type === undefined || options.type === null) {
+ throw new Error("dxuart.runvg:'type' should not be null or empty")
+ }
+ if (options.path === undefined || options.path === null) {
+ throw new Error("dxuart.runvg:'path' should not be null or empty")
+ }
+ let oldfilepre = '/app/code/dxmodules/vgUartWorker'
+ let content = std.loadFile(oldfilepre + '.js').replace("{{id}}", options.id)
+ let newfile = oldfilepre + options.id + '.js'
+ std.saveFile(newfile, content)
+ let init = map.get("__vguart__run_init" + options.id)
+ if (!init) {//纭繚鍙垵濮嬪寲涓�娆�
+ map.put("__vguart__run_init" + options.id, options)
+ bus.newWorker(options.id || "__uart",newfile)
+ }
+}
+export default uart;
\ No newline at end of file
--
Gitblit v1.9.3