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

diff --git a/vf205_access/dxmodules/dxCapturer.js b/vf205_access/dxmodules/dxCapturer.js
new file mode 100644
index 0000000..3943ae3
--- /dev/null
+++ b/vf205_access/dxmodules/dxCapturer.js
@@ -0,0 +1,336 @@
+//build: 20240524
+//鎽勫儚澶村彇鍥剧粍浠讹紝涓昏鐢ㄤ簬鑾峰彇浜岀淮鐮佸浘鍍忕劧鍚庡埄鐢╠xDecoder缁勪欢鏉ヨВ鏋愪簩缁寸爜鍥惧儚
+//渚濊禆缁勪欢锛歞xDriver锛宒xCommon锛宒xStd锛宒xMap
+import { capturerClass } from './libvbar-m-dxcapturer.so'
+import * as os from "os"
+import std from './dxStd.js'
+import dxMap from './dxMap.js'
+import dxCommon from './dxCommon.js';
+import bus from './dxEventBus.js'
+const capturerObj = new capturerClass();
+const map = dxMap.get('default')
+const capturer = {}
+
+/**
+ * 鍙栧浘妯″潡鍒濆鍖�
+ * @param {object} options 閰嶇疆鍙傛暟锛屽ぇ閮ㄥ垎鍙互鐢ㄩ粯璁ゅ��
+ * @param {string} options.path                 蹇呭~锛屽浘鍍忛噰闆嗚澶囪矾寰勶紝姣忕璁惧鏈夊樊寮傦紝姣斿DW200瀵瑰簲鐨勫�兼槸'/dev/video11', M500瀵瑰簲鐨�'/dev/video0'
+ * @param {number} options.width                闈炲繀濉紝鍥惧儚瀹斤紝缂虹渷鏄�0
+ * @param {number} options.height               闈炲繀濉紝鍥惧儚楂橈紝缂虹渷鏄�0
+ * @param {number} options.widthbytes           闈炲繀濉紝姣忎釜鍍忕礌鎵�鍗犲瓧鑺傛暟 GREY : 1锛� YUV : 2锛孌W200缂虹渷鏄�1 VF203缂虹渷鏄�2
+ * @param {number} options.pixel_format          闈炲繀濉紝鍍忕礌鏍煎紡锛� 缂虹渷鏄�1497715271琛ㄧずV4L2_PIX_FMT_GREY
+ * @param {number} options.max_channels          闈炲繀濉紝鏈�澶ф敮鎸佺殑鍚屾杈撳嚭channel鏁伴噺锛岀己鐪佹槸3
+ * @param {number} options.rotation             闈炲繀濉紝鏃嬭浆瑙掑害锛岀己鐪佹槸90
+ * @param {number} options.frame_num             闈炲繀濉紝甯х紪鍙凤紝缂虹渷鏄�3
+ * @param {number} options.preview_enable        闈炲繀濉紝棰勮鏄惁鍚敤锛岀己鐪佹槸3
+ * @param {number} options.preview_left          闈炲繀濉紝棰勮妗嗗乏杈规鍧愭爣锛岀己鐪佹槸0
+ * @param {number} options.preview_top           闈炲繀濉紝棰勮妗嗕笂杈规鍧愭爣锛岀己鐪佹槸0
+ * @param {number} options.preview_width         闈炲繀濉紝棰勮妗嗗搴︼紝VF203缂虹渷鏄�1024
+ * @param {number} options.preview_height        闈炲繀濉紝棰勮妗嗛珮搴︼紝VF203缂虹渷鏄�600
+ * @param {number} options.preview_rotation      闈炲繀濉紝棰勮妗嗘棆杞搴︼紝缂虹渷鏄�0
+ * @param {number} options.preview_mode          闈炲繀濉紝棰勮妗嗘ā寮忥紝缂虹渷鏄�2
+ * @param {number} options.preview_screen_index   闈炲繀濉紝棰勮妗嗙储寮曪紝缂虹渷鏄�0
+ * @param {string} id 鍙ユ焺id锛岄潪蹇呭~锛堣嫢鍒濆鍖栧涓疄渚嬮渶瑕佷紶鍏ュ敮涓�id锛�
+ */
+capturer.init = function (options, id) {
+    if (options.path === undefined || options.path === null || options.path.length < 1) {
+        throw new Error("dxCapturer.init: 'path' parameter should not be null or empty")
+    }
+    let pointer = capturerObj.init(options);
+    if (!pointer) {
+        throw new Error("dxCapturer.init: init failed")
+    }
+    dxCommon.handleId("capturer", id, pointer)
+}
+
+/**
+ * 鍥炶皟娉ㄥ唽
+ * @param {string} id 鍙ユ焺id锛岄潪蹇呭~锛堥渶淇濇寔鍜宨nit涓殑id涓�鑷达級
+ * @param {string} capturerDogId 鎽勫儚澶寸湅闂ㄧ嫍鍙ユ焺id锛岄潪蹇呭~
+ * @returns true/false
+ */
+capturer.registerCallback = function (id, capturerDogId) {
+    let pointer = dxCommon.handleId("capturer", id)
+    let capturerDogPointer = null;
+    print("capturerDogPointer:", capturerDogPointer)
+    if(capturerDogId){
+        capturerDogPointer = dxCommon.handleId("watchdog", capturerDogId)
+        print("capturerDogPointer:", capturerDogPointer)
+    }
+    return capturerObj.registerCallback(pointer, "decoderCapturerImage", capturerDogPointer)
+}
+/**
+ * 鑾峰彇鍩烘湰淇℃伅
+ * @param {string} id 鍙ユ焺id锛岄潪蹇呭~锛堥渶淇濇寔鍜宨nit涓殑id涓�鑷达級
+ * @returns 鏍煎紡绫讳技锛� {"width":800,"widthbytes":1,"height":600,"name":{},"type":6}
+ */
+capturer.getInfo = function (id) {
+    let pointer = dxCommon.handleId("capturer", id)
+    return capturerObj.getInfo(pointer)
+}
+/**
+ * 鍏抽棴鍙栧浘妯″潡
+ * @param {string} id 鍙ユ焺id锛岄潪蹇呭~锛堥渶淇濇寔鍜宨nit涓殑id涓�鑷达級
+ * @returns true/false
+ */
+capturer.close = function (id) {
+    let pointer = dxCommon.handleId("capturer", id)
+    return capturerObj.close(pointer)
+}
+
+/**
+ * 鑾峰彇鍥惧儚鏁版嵁锛岃疆璇㈠彲璋冪敤姝ゆ帴鍙o紝绫讳技capturer.msgReceive鏂规硶鐨勮幏鍙栵紝鑻ヤ娇鐢ㄨ繖涓柟娉曪紝蹇呴』鎵嬪姩閿�姣佽幏鍙栫殑image鎸囬拡
+ * @param {string} id 鍙ユ焺id锛岄潪蹇呭~锛堥渶淇濇寔鍜宨nit涓殑id涓�鑷达級
+ * @returns image鎸囬拡
+ */
+capturer.readImage = function (id) {
+    let pointer = dxCommon.handleId("capturer", id)
+    return capturerObj.readImage(pointer)
+}
+
+/**
+ * 閿�姣佽幏鍙栫殑image鎸囬拡锛屼笌capturer.readImage鏂规硶鍏卞悓浣跨敤
+ * @param {number} image image鎸囬拡锛屽繀濉�
+ * @returns true/false
+ */
+capturer.destroyImage = function (image) {
+    return capturerObj.destroyImage(image)
+}
+
+/**
+ * 浣胯兘/鍏抽棴capture棰勮
+ * @param {number}  鎽勫儚澶村惎鐢�/绂佺敤锛屽繀濉�
+ * @param {string} id 鍙ユ焺id锛岄潪蹇呭~锛堥渶淇濇寔鍜宨nit涓殑id涓�鑷达級
+ * @returns true/false
+ */
+capturer.capturerEnable = function (enable, id) {
+    if (enable == null) {
+        throw new Error("nirEnable should not be null or empty")
+    }
+    let pointer = dxCommon.handleId("capturer", id)
+    return capturerObj.capturerPreviewEnable(pointer, enable)
+}
+
+/**
+ * @brief 鍥剧墖鏂囦欢杞琲mage
+ * @param {string} fileName 鏂囦欢璺緞
+ * @param {number} type 鍥惧儚绫诲瀷 IMAGE_YUV420P = 0, 1IMAGE_YUV420SP = 1,
+ * @return imageId image鍙ユ焺id
+ */
+capturer.pictureFileToImage = function (fileName, type) {
+    if (fileName == null) {
+        throw new Error("fileName should not be null or empty")
+    }
+    if (type == null) {
+        throw new Error("type should not be null or empty")
+    }
+    return capturerObj.pictureFileToImage(fileName, type)
+}
+
+/**
+ * @brief 鍥剧墖瑁佸壀
+ * @param {string} src_pic 婧愭枃浠惰矾寰�
+ * @param {number} width 鍥惧儚瀹藉害
+ * @param {number} height 鍥惧儚楂樺害
+ * @param {string} out_pic 瑁佸壀鍚庣殑鍥剧墖璺緞
+ * @return ture/false
+ */
+capturer.pictureCropping = function (src_pic, width, height, out_pic) {
+    if (src_pic == null) {
+        throw new Error("src_pic should not be null or empty")
+    }
+    if (width == null) {
+        throw new Error("width should not be null or empty")
+    }
+    if (height == null) {
+        throw new Error("height should not be null or empty")
+    }
+    if (out_pic == null) {
+        throw new Error("out_pic should not be null or empty")
+    }
+    return capturerObj.pictureCropping(src_pic, width, height, out_pic)
+}
+
+/**
+ * 鍥剧墖鏁版嵁杞琲mage
+ * @param {string}  base64Data 鍥剧墖base64鏁版嵁
+ * @param {number}  dataLen 鏁版嵁闀垮害dataLen
+ * @param {number}  type 鍥惧儚绫诲瀷 IMAGE_YUV420P = 0, 1IMAGE_YUV420SP = 1,
+ * @returns imageId image鍙ユ焺id
+ */
+capturer.pictureDataToImage = function (base64Data, dataLen, type) {
+    if (base64Data == null) {
+        throw new Error("base64Data should not be null or empty")
+    }
+    if (dataLen == null) {
+        throw new Error("dataLen should not be null or empty")
+    }
+    if (type == null) {
+        throw new Error("type should not be null or empty")
+    }
+    return capturerObj.pictureDataToImage(base64Data, dataLen, type)
+}
+
+// image, (enum image_type)type, (enum vbar_drv_picture_type)save_type, quality, pic_data, data_len
+/**
+ * image 杞浘鐗囨暟鎹�
+ * @param {number}  imageId image鍥剧墖鍙ユ焺id
+ * @param {number}  type 鍥惧儚绫诲瀷 IMAGE_YUV420P = 0, 1IMAGE_YUV420SP = 1,
+ * @param {number}  saveType 杞崲鍚庣殑鍥剧墖绫诲瀷 TYPE_JPEG = 0, TYPE_BMP = 1, TYPE_PNG = 2, TYPE_UNKNOE = 3;
+ * @param {number}  quality 鍘嬬缉姣旓紝jpeg 0-100锛� png 鏃犳崯鍘嬬缉鏃犻渶姝ゅ弬鏁帮紝 bmp浣嶅浘鏃犻渶姝ゅ弬鏁�
+ * @returns 鍥剧墖base64鏁版嵁
+ */
+capturer.imageToPictureData = function (imageId, type, saveType, quality) {
+    if (imageId == null) {
+        throw new Error("imageId should not be null or empty")
+    }
+    if (type == null) {
+        throw new Error("type should not be null or empty")
+    }
+    if (saveType == null) {
+        throw new Error("saveType should not be null or empty")
+    }
+    if (quality == null) {
+        throw new Error("quality should not be null or empty")
+    }
+    return capturerObj.imageToPictureData(imageId, type, saveType, quality)
+}
+
+/**
+ * 杞浘鐗囨枃浠�
+ * @param {number}  imageId image鍥惧儚鍙ユ焺id
+ * @param {string}  type 鍥惧儚绫诲瀷 IMAGE_YUV420P = 0, 1IMAGE_YUV420SP = 1,
+ * @param {number}  saveType 杞崲鍚庣殑鍥剧墖绫诲瀷 YPE_JPEG = 0, TYPE_BMP = 1, TYPE_PNG = 2, TYPE_UNKNOE = 3;
+ * @param {number}  quality 鍘嬬缉姣旓紝jpeg 0-100锛� png 鏃犳崯鍘嬬缉鏃犻渶姝ゅ弬鏁帮紝 bmp浣嶅浘鏃犻渶姝ゅ弬鏁�
+ * @param {number}  savePath 鍥剧墖淇濆瓨璺緞
+ * @returns true/false
+ */
+capturer.imageToPictureFile = function (imageId, type, saveType, quality, savePath) {
+    if (imageId == null) {
+        throw new Error("imageId should not be null or empty")
+    }
+    if (type == null) {
+        throw new Error("type should not be null or empty")
+    }
+    if (saveType == null) {
+        throw new Error("saveType should not be null or empty")
+    }
+    if (quality == null) {
+        throw new Error("quality should not be null or empty")
+    }
+    if (savePath == null) {
+        throw new Error("savePath should not be null or empty")
+    }
+    return capturerObj.imageToPictureFile(imageId, type, saveType, quality, savePath)
+}
+
+/**
+* 鍥剧墖缂╂斁
+* @param {number}   imageId image鍥惧儚鍙ユ焺id
+* @param {number}   width  鐩爣鍥惧儚瀹藉害
+* @param {number}   height 鐩爣鍥惧儚楂樺害
+* @param {number}   mode       婊ゆ尝鍣ㄦā寮�
+*                   FILTER_MODE_NONE     涓嶈繘琛屾护娉紝鐩存帴閲囨牱锛涢�熷害鏈�蹇��
+*                   FILTER_MODE_LINEAR   鍙部姘村钩鏂瑰悜婊ゆ尝銆�
+*                   FILTER_MODE_BILINEAR 鍙岀嚎鎬ф护娉紱姣旂洅婊ゆ尝鏇村揩锛屼絾鍦ㄧ缉灏忓浘鍍忔椂璐ㄩ噺杈冧綆銆�
+*                   FILTER_MODE_BOX      鐩掓护娉紱鎻愪緵鏈�楂樼殑缂╂斁璐ㄩ噺
+*/
+capturer.imageResizeResolution = function (imageId, width, height, mode) {
+    if (imageId == null) {
+        throw new Error("imageId should not be null or empty")
+    }
+    if (width == null) {
+        throw new Error("width should not be null or empty")
+    }
+    if (height == null) {
+        throw new Error("height should not be null or empty")
+    }
+    if (mode == null) {
+        throw new Error("mode should not be null or empty")
+    }
+    return capturerObj.imageResizeResolution(imageId, width, height, mode)
+}
+
+/**
+ * 鍒ゆ柇capturer娑堟伅闃熷垪鏄惁涓虹┖
+ * @param {string} id 鍙ユ焺id锛岄潪蹇呭~锛堥渶淇濇寔鍜宨nit涓殑id涓�鑷达級
+ * @returns true/false
+ */
+capturer.msgIsEmpty = function (id) {
+    let pointer = dxCommon.handleId("capturer", id)
+    return capturerObj.msgIsEmpty(pointer)
+}
+
+/**
+ * 浠巆apturer娑堟伅闃熷垪涓鍙栨暟鎹�
+ * @param {string} id 鍙ユ焺id锛岄潪蹇呭~锛堥渶淇濇寔鍜宨nit涓殑id涓�鑷达級
+ * @returns image鎸囬拡
+ */
+capturer.msgReceive = function (id) {
+    let pointer = dxCommon.handleId("capturer", id)
+    return capturerObj.msgReceive(pointer)
+}
+
+/**
+ * 鏌ヨcapturer娑堟伅闃熷垪澶у皬
+ * @param {string} id 鍙ユ焺id锛岄潪蹇呭~锛堥渶淇濇寔鍜宨nit涓殑id涓�鑷达級
+ * @returns size
+ */
+capturer.msgQueueSize = function (id) {
+    let pointer = dxCommon.handleId("capturer", id)
+    return capturerObj.msgQueueSize(pointer)
+}
+
+capturer.RECEIVE_MSG = '__capturer__MsgReceive'
+
+/**
+ * 鐢ㄤ簬绠�鍖朿apturer缁勪欢鐨勪娇鐢紝鎶奵apturer灏佽鍦ㄨ繖涓獁orker閲岋紝浣跨敤鑰呭彧闇�瑕佽闃卐ventbus鐨勪簨浠跺氨鍙互鐩戝惉capturer
+ * @param {object} options capturer缁勪欢鍙傛暟锛屽弬鑰僣apturer.init锛屽繀濉�
+ * @param {string} options.id  鍙ユ焺id锛岄潪蹇呭~锛堣嫢鍒濆鍖栧涓疄渚嬮渶瑕佷紶鍏ュ敮涓�id锛�
+ */
+capturer.run = function (options) {
+    if (options === undefined || options.length === 0) {
+        throw new Error("dxcapturer.run:'options' parameter should not be null or empty")
+    }
+    if (options.id === undefined || options.id === null || typeof options.id !== 'string') {
+        // 鍙ユ焺id
+        options.id = ""
+    }
+    if (options.path === undefined || options.path === null || options.path.length <= 0) {
+        throw new Error("dxcapturer.run:'path' should not be null or empty")
+    }
+    let oldfilepre = '/app/code/dxmodules/capturerWorker'
+    let content = std.loadFile(oldfilepre + '.js').replace("{{id}}", options.id)
+    let newfile = oldfilepre + options.id + '.js'
+    std.saveFile(newfile, content)
+    let init = map.get("__capturer__run_init" + options.id)
+    if (!init) {//纭繚鍙垵濮嬪寲涓�娆�
+        map.put("__capturer__run_init" + options.id, options)
+        bus.newWorker(options.id || '__capturer', newfile)
+    }
+}
+
+/**
+ * 濡傛灉capturer鍗曠嫭涓�涓嚎绋嬶紝鍙互鐩存帴浣跨敤run鍑芥暟锛屼細鑷姩鍚姩涓�涓嚎绋嬶紝
+ * 濡傛灉鎯冲姞鍏ュ埌鍏朵粬宸叉湁鐨勭嚎绋嬶紝鍙互浣跨敤浠ヤ笅灏佽鐨勫嚱鏁�
+ */
+capturer.worker = {
+    //鍦╳hile寰幆鍓�
+    beforeLoop: function (options) {
+        capturer.init(options, options.id)
+        capturer.registerCallback(options.id)
+    },
+    //鍦╳hile寰幆閲�
+    loop: function (options) {
+        if (!capturer.msgIsEmpty(options.id)) {
+            let res = capturer.msgReceive(options.id);
+            if (options.id === undefined || options.id === null || typeof options.id !== 'string') {
+                // 鍙ユ焺id
+                options.id = ""
+            }
+            bus.fire(capturer.RECEIVE_MSG + options.id, res)
+        }
+    }
+}
+
+export default capturer;

--
Gitblit v1.9.3