| ¶Ô±ÈÐÂÎļþ |
| | |
| | | [2026/3/31 08:59:19] --- Start runUsb --- |
| | | [2026/3/31 08:59:19] Platform: win32 |
| | | [2026/3/31 08:59:19] Kill command defined: wmic process where "name='node.exe' and commandline like '%device_manager.js%'" delete || powershell -NoProfile -ExecutionPolicy Bypass -Command "Get-CimInstance Win32_Process | Where-Object { $_.Name -eq 'node.exe' -and $_.CommandLine -like '*device_manager.js*' } | ForEach-Object { Stop-Process -Id $_.ProcessId -Force }" |
| | | [2026/3/31 08:59:20] Node.js check passed |
| | | [2026/3/31 08:59:20] Process exited with code: 0, signal: null |
| | | [2026/3/31 08:59:20] Kill stdout: ɾ��ʵ�� \\ACER-LGQ\ROOT\CIMV2:Win32_Process.Handle="42064"
|
| | | ʵ��ɾ���ɹ��� |
| | | [2026/3/31 08:59:21] Manager script path: c:\Users\lgq10\.vscode\extensions\dxide.dxide-1.0.40\src\device\device_manager.js |
| | | [2026/3/31 08:59:21] Spawning child process... |
| | | [2026/3/31 08:59:21] Sending connect command: {"cmd":"connect","lang":"zh","model":"VF105_V12"} |
| | | [2026/3/31 09:25:48] Process exited with code: 0, signal: null |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | { |
| | | "app.dxproj": "cb10fd21e8e17ada45c25e1e1ba3226e", |
| | | "dxmodules\\cameraCalibrationWorker.js": "5812507304ced88da3677a3c68f79a78", |
| | | "dxmodules\\capturerWorker.js": "a3104a1d73ab1bd4f596495d817ecf39", |
| | | "dxmodules\\dxAlsa.js": "d82fe4f74383edf6198269968a82b5e7", |
| | | "dxmodules\\dxBase64.js": "7cb517ecd99830dde0ec13a501e831ea", |
| | | "dxmodules\\dxCameraCalibration.js": "8e42bf3752616896b88f9e9efbe20783", |
| | | "dxmodules\\dxCapturer.js": "7420d8e269fb8ebfc48c306e0a8fa7de", |
| | | "dxmodules\\dxCommon.js": "19f77916eb02e6fd01106597aca412bd", |
| | | "dxmodules\\dxConfig.js": "24072559b3cb1ec5c206cb358eaaaaae", |
| | | "dxmodules\\dxDriver.js": "c5969e91097030b90e9bcb62a827e344", |
| | | "dxmodules\\dxEid.js": "07d966e53b69629f152baf54cd163372", |
| | | "dxmodules\\dxEventBus.js": "81adf285545c12d49d7784327c41970a", |
| | | "dxmodules\\dxFace.js": "81790e30c6da75ae3bcb96afcafa5b02", |
| | | "dxmodules\\dxGpio.js": "30c34469e2dc8d80026fc5eac5bfd1f7", |
| | | "dxmodules\\dxGpioKey.js": "97ef2763bad50e0c82cfa5fb9b79f1eb", |
| | | "dxmodules\\dxHttp.js": "fa75a0a2951399fb5af7618d7ab4c6f1", |
| | | "dxmodules\\dxLogger.js": "f6d3f73086944fcdeeffa579ef6d1508", |
| | | "dxmodules\\dxMap.js": "2255d584c240c35a567f2c7b92e0a9da", |
| | | "dxmodules\\dxMqtt.js": "277fafb81971c8f3508a8a38f8f2703a", |
| | | "dxmodules\\dxNet.js": "58b13f928daeb1bae680c2350873baca", |
| | | "dxmodules\\dxNfc.js": "feb5bc21d4b13ab9736de1941290312d", |
| | | "dxmodules\\dxNtp.js": "0c90048eeb11e7e3b458e4d6e48932f2", |
| | | "dxmodules\\dxOta.js": "760dc97eb0724280f16f8616a2be171f", |
| | | "dxmodules\\dxPwm.js": "dc0734c231d7d4cd5f26a34c315cc4a2", |
| | | "dxmodules\\dxQrRule.js": "bfa9e2b4725c4fa358a2988f63c67210", |
| | | "dxmodules\\dxSqlite.js": "fb6a2f60b49d67a8ef36148355e5e30e", |
| | | "dxmodules\\dxStd.js": "6f239f2fd7d23e7ed053b762b235bd3c", |
| | | "dxmodules\\dxUart.js": "71edddfd98de79ccbd91e4e013af269b", |
| | | "dxmodules\\dxUi.js": "97bd858defaec480d755c162105a3f76", |
| | | "dxmodules\\dxWatchdog.js": "c4a7d5c8f0c203e6dafbc289a0f4fcbd", |
| | | "dxmodules\\dxWorkerPool.js": "5aad9b8f838d1339fc64083188d3ba69", |
| | | "dxmodules\\faceWorker.js": "d1d0d4f5e5503ca87bd69d1d2ee3ad00", |
| | | "dxmodules\\gpioKeyWorker.js": "78a7489cc3cf098fb4d218b17294175d", |
| | | "dxmodules\\libalc.so": "3128cc7cd0cc978e02db995433962c87", |
| | | "dxmodules\\libid_jpg.so": "18887cb0d0df6256604ed039d47dfc7b", |
| | | "dxmodules\\libid_jpg_codec.so": "c36bd0c28d2b43e9296736856da05129", |
| | | "dxmodules\\libie_jpg.so": "1343b7bc765f6464cf8e483c03edd542", |
| | | "dxmodules\\libie_jpg_codec.so": "508defffc1c72b0ae90afab117d6db80", |
| | | "dxmodules\\libJLReader.so": "ce7f448dea6a1c8988469d03ecfa6575", |
| | | "dxmodules\\liblombo_jpeg.so": "49508ccd603ed795efee3d0f8e7e3e2a", |
| | | "dxmodules\\libvbar-b-dxface.so": "689ee554f67057262860f7726042327b", |
| | | "dxmodules\\libvbar-b-dxgpio.so": "ca009351ab7d9719a71cd6105e9acba6", |
| | | "dxmodules\\libvbar-b-dxpwm.so": "b3e0e7cc950811385ceb204876fd8b19", |
| | | "dxmodules\\libvbar-b-dxwatchdog.so": "878352b309e9a9e17ce3ac83774d0fa9", |
| | | "dxmodules\\libvbar-drv-audio_gain.so": "14d23fe5134ff95982f1655058084709", |
| | | "dxmodules\\libvbar-drv-capturer.so": "295aaa64df97ee08053c26789ff57437", |
| | | "dxmodules\\libvbar-drv-capturer_calibration.so": "cdb2ca2205e36d82ebcce910e457bd9b", |
| | | "dxmodules\\libvbar-drv-display.so": "31c2a7a2ed4166d27359d208e4d34568", |
| | | "dxmodules\\libvbar-drv-face.so": "2c54abd0de9a287be3bbea490d0c45c4", |
| | | "dxmodules\\libvbar-drv-gpio.so": "e663856deb2d403558426455097e0bab", |
| | | "dxmodules\\libvbar-drv-memory.so": "0ed48486e154f24d6681a0195a7525ad", |
| | | "dxmodules\\libvbar-drv-pwm.so": "b9c2154b7020d41b01d63f6caac1510f", |
| | | "dxmodules\\libvbar-drv-soc.so": "73e4b6657af4bcff0affaacf55702096", |
| | | "dxmodules\\libvbar-drv-tts.so": "97076b55a3338196f512c61101ac0e9a", |
| | | "dxmodules\\libvbar-drv-watchdog.so": "9367e995f85cb191da0567d0acd4ed67", |
| | | "dxmodules\\libvbar-m-alsa.so": "1154ff7cb2f84ee378f29e0d03551f96", |
| | | "dxmodules\\libvbar-m-capturer.so": "8f0b6383db39494904294c3f60c5f013", |
| | | "dxmodules\\libvbar-m-channel.so": "6b6f7d8edb178b11b9a93123e0a7abdb", |
| | | "dxmodules\\libvbar-m-common.so": "074eb14e701c5ed910b979339453f484", |
| | | "dxmodules\\libvbar-m-dxalsa.so": "bb4fcf0be6ccb0cc2d7b295002925148", |
| | | "dxmodules\\libvbar-m-dxcapturer.so": "506307dec2552200eaa22412987b643e", |
| | | "dxmodules\\libvbar-m-dxcapturer_calibration.so": "c41e691d69621ab5a96322f47d3eb286", |
| | | "dxmodules\\libvbar-m-dxchannel.so": "ff80aaf50113c160c663a80015471079", |
| | | "dxmodules\\libvbar-m-dxcommon.so": "d4ca3ce51543d07c81cc75974adcbccb", |
| | | "dxmodules\\libvbar-m-dxeid.so": "3458f8221dd572220003e4344837d846", |
| | | "dxmodules\\libvbar-m-dxhttp.so": "1ec2f9ccc26aebc390944340afde6044", |
| | | "dxmodules\\libvbar-m-dxkey.so": "e49a86e25944050bda8565677713431a", |
| | | "dxmodules\\libvbar-m-dxmap.so": "55ebd66234d59490ab56f88398419dde", |
| | | "dxmodules\\libvbar-m-dxmqtt.so": "0cbeb2b46441ee89678516a1a941cd58", |
| | | "dxmodules\\libvbar-m-dxnet.so": "eed60270cabaf872983c6f905b0ceb03", |
| | | "dxmodules\\libvbar-m-dxsqlite.so": "15a0eb0d18b58cad3868f86e9edfb409", |
| | | "dxmodules\\libvbar-m-dxui.so": "ca22e1a0c52977749a32b2cc70e942a9", |
| | | "dxmodules\\libvbar-m-eid.so": "e7d1db4d1bfab4c462c9d22807099268", |
| | | "dxmodules\\libvbar-m-key.so": "f7f1f2ae6c9c1f298376375a8b16b6ee", |
| | | "dxmodules\\libvbar-m-net.so": "afa1adebb44fc9734b26b99e87e0728d", |
| | | "dxmodules\\libvbar-m-vgmqtt.so": "56e94165ba896867fbe3ead167022d3f", |
| | | "dxmodules\\libvbar-p-dxnfc.so": "14d17fe22a0dbfc00b13c4d9cef8512f", |
| | | "dxmodules\\libvbar-p-nfc.so": "f1a1f96558b2509c5b629790cec16386", |
| | | "dxmodules\\libvccore.so": "9c383ca78ee117ea3295baefb1f1fee2", |
| | | "dxmodules\\libyuv.so": "2c4faa3ab51260f5285cd91dda44b3a9", |
| | | "dxmodules\\mqttWorker.js": "4eedadbd41d6bd183cde2830a3347ad1", |
| | | "dxmodules\\netWorker.js": "c5d4c9022f8912b47249b14477aed70a", |
| | | "dxmodules\\nfcWorker.js": "88fadfc469cc397b66fd5e52db073bde", |
| | | "dxmodules\\uiBase.js": "9ea5cd2b5ed52d183fde2d87b8f70ca1", |
| | | "dxmodules\\uiButton.js": "8ffe0ffce9ac6b341c9993e260b52b05", |
| | | "dxmodules\\uiButtons.js": "52cb9727c2225f75ac6144e756a6d511", |
| | | "dxmodules\\uiCheckbox.js": "5aa8c851e8b2333cbe46cdd69452ab8c", |
| | | "dxmodules\\uiDropdown.js": "2b73bfacf3d4b115ab3997c83284c478", |
| | | "dxmodules\\uiFont.js": "257aa2f90ce2f0ace4095a03d3447b0b", |
| | | "dxmodules\\uiImage.js": "b2a0a963993474205bc7dc91c8696ec1", |
| | | "dxmodules\\uiKeyboard.js": "b225c62ff2f4b8aa0bdb675776b236a1", |
| | | "dxmodules\\uiLabel.js": "e0ae808d468459a6fedc7ba9a551359e", |
| | | "dxmodules\\uiLine.js": "cc18bc32c0a6f0f8db7992d6e0b4fd81", |
| | | "dxmodules\\uiList.js": "8b779a85cd54b25bc50ec616ed9f08d1", |
| | | "dxmodules\\uiSlider.js": "91b743902824b5decf5535dad49fc97e", |
| | | "dxmodules\\uiStyle.js": "60350cf77db84793bf093bda341f2cb9", |
| | | "dxmodules\\uiSwitch.js": "9a836405abe0b09f5a2940cf22698968", |
| | | "dxmodules\\uiTextarea.js": "0d5008a5a95b78ea8efde3408ba6fb4a", |
| | | "dxmodules\\uiUtils.js": "a04cc3baa5ba1dc6d1ab65b526464fa6", |
| | | "dxmodules\\uiView.js": "26fe7b992ac82bf5d45447f2921bff2f", |
| | | "dxmodules\\vgUartWorker.js": "fc3e9e0051836d5063c0eecf555d9521", |
| | | "README.md": "c472daef5243f3790f2faee1cf8e2255", |
| | | "README_CN.md": "a46b1c92c09f375881a49d8c42adf6b3", |
| | | "resource\\CN\\wav\\access_f.wav": "f951f3cc1f03aaa794231413fd4efcc6", |
| | | "resource\\CN\\wav\\access_s.wav": "6d1b31bdcaaa13ba719e3223b55d5235", |
| | | "resource\\CN\\wav\\btn11.wav": "a623797305d7b0e6b8cb6b2ab3d43591", |
| | | "resource\\CN\\wav\\btn12.wav": "26bbfc3eed36211713dca9afb423e168", |
| | | "resource\\CN\\wav\\btn13.wav": "67d6fe32693cb2e7653c2ff2141ce873", |
| | | "resource\\CN\\wav\\btn21.wav": "53071472fce6128fdd2ed304e4d78406", |
| | | "resource\\CN\\wav\\btn22.wav": "e35c87d370695099d3b6d7f512496395", |
| | | "resource\\CN\\wav\\btn23.wav": "f25db5592331f1e6deb67beecb3c1131", |
| | | "resource\\CN\\wav\\btn31.wav": "054a4f36ebda08fadca3162d955560bf", |
| | | "resource\\CN\\wav\\btn32.wav": "64eb5fef123eafd7b52108ebcd6bace9", |
| | | "resource\\CN\\wav\\btn33.wav": "67d6fe32693cb2e7653c2ff2141ce873", |
| | | "resource\\CN\\wav\\calibration_s.wav": "d2ff1f1f4a40bf4166130dc079939079", |
| | | "resource\\CN\\wav\\control_f.wav": "4dbaca7e4d227a720620b846544b469a", |
| | | "resource\\CN\\wav\\door_close.wav": "325ca8082f8e9fceb2c7eeeb78d8645b", |
| | | "resource\\CN\\wav\\door_open.wav": "f3b5291fc8babaffd32107198cdd5afa", |
| | | "resource\\CN\\wav\\emergency.wav": "a1855c22f3ef2f69d5c84d3a2852ae1f", |
| | | "resource\\CN\\wav\\emergency_f.wav": "946ac86e74b849ad8f1bec3615cf9b39", |
| | | "resource\\CN\\wav\\emergency_s.wav": "a717e3417891ff306225ac075ba28082", |
| | | "resource\\CN\\wav\\failed.wav": "891194e741b0bc8f6332f78eb607cc85", |
| | | "resource\\CN\\wav\\light_close.wav": "b1ac09e91ac4ce3825614ad1654a3f58", |
| | | "resource\\CN\\wav\\light_open.wav": "16b7b6b8c6eb469645a15e4a54a3e014", |
| | | "resource\\CN\\wav\\network.wav": "7bbc6d740918a20acfb5ef75df685bdb", |
| | | "resource\\CN\\wav\\read.wav": "c83edd035dc15f7a716644319e849215", |
| | | "resource\\CN\\wav\\recg_f.wav": "5cd4d88db4e3f8332b9e73fe05222c83", |
| | | "resource\\CN\\wav\\recg_s.wav": "4afadeb018b08518d5d3dd1cfc5e0d64", |
| | | "resource\\CN\\wav\\recognition.wav": "da00dd97d1e8ca0ed20dc43eb4daafc8", |
| | | "resource\\CN\\wav\\recognition_s.wav": "df9916d6fe3d285894668e63d1aeeb1d", |
| | | "resource\\CN\\wav\\register.wav": "a91d6ebb846dc834816a954168da1352", |
| | | "resource\\CN\\wav\\stranger.wav": "2e6690d7ddcd3609ca3e6d6717b61a9c", |
| | | "resource\\CN\\wav\\user2.wav": "868a9b15aac20b62457f98c955f4e5e0", |
| | | "resource\\CN\\wav\\user2_s.wav": "98904054df059be8cd69e08c302317e7", |
| | | "resource\\CN\\wav\\verify.wav": "2bc2b96e0ca05052985fda98fb552ef9", |
| | | "resource\\CN\\wav\\verify_10x_f.wav": "bf26ce11bbd801f5efeff8c9250f219f", |
| | | "resource\\CN\\wav\\verify_10x_s.wav": "2d04b22277844d9c35e08e4e2c67c11c", |
| | | "resource\\CN\\wav\\verify_200_f.wav": "393036b5fc28a3c04580593d59e26e7e", |
| | | "resource\\CN\\wav\\verify_200_s.wav": "585267371d37f3f45e3826ec7dcafbd3", |
| | | "resource\\CN\\wav\\verify_300_f.wav": "e44977e8b6dcac8adbf304894afd24e0", |
| | | "resource\\CN\\wav\\verify_300_s.wav": "d8e23a91e4999b2d77454aab824bd611", |
| | | "resource\\CN\\wav\\verify_400_f.wav": "05752c8c9c2bf4334943999842529d8b", |
| | | "resource\\CN\\wav\\verify_400_s.wav": "740a63ffe907dda0f2d0e14cb9a83f74", |
| | | "resource\\EN\\wav\\calibration_s.wav": "b5497547d9e7e6fb5b28ee307b27752b", |
| | | "resource\\EN\\wav\\network.wav": "1e8ccfd03ca83976fefdba1edcf1b194", |
| | | "resource\\EN\\wav\\read.wav": "8c1f6ee62c7bf74db5ecab28d3988eeb", |
| | | "resource\\EN\\wav\\recg_f.wav": "e303563b867dd6eaebac18679ca760df", |
| | | "resource\\EN\\wav\\recg_s.wav": "183a843b668aa919311a6d352af80f35", |
| | | "resource\\EN\\wav\\recognition.wav": "1c9e06bc338c49c120aa101b1fac8de0", |
| | | "resource\\EN\\wav\\recognition_s.wav": "f887f2b1615121bbe815fef7f64d3b92", |
| | | "resource\\EN\\wav\\register.wav": "de5d0048f840243fdd1392c09d9ac164", |
| | | "resource\\EN\\wav\\stranger.wav": "31775350903916827fdec25b9c65dd94", |
| | | "resource\\EN\\wav\\verify.wav": "2e77ec2c754e1dea329988d4e462aa2f", |
| | | "resource\\EN\\wav\\verify_10x_f.wav": "7ccc23490436b9f1de32200230953a62", |
| | | "resource\\EN\\wav\\verify_10x_s.wav": "0630e0410fca3c7fd7e701c69e8ea4bc", |
| | | "resource\\EN\\wav\\verify_200_f.wav": "64ce473b0f560cc1613469ab94197ce6", |
| | | "resource\\EN\\wav\\verify_200_s.wav": "e3d28c408cc3bef5461620c75b15abdf", |
| | | "resource\\EN\\wav\\verify_300_f.wav": "7fa0d7bf85d040b72a89cfb9e2f06bcf", |
| | | "resource\\EN\\wav\\verify_300_s.wav": "3e69fd763477d6cc30543d838f33d718", |
| | | "resource\\EN\\wav\\verify_400_f.wav": "d074b8f6e4e968b6d1984b123ed4d387", |
| | | "resource\\EN\\wav\\verify_400_s.wav": "9141136d3310a5fac5917d3f6056249f", |
| | | "resource\\font\\AlibabaPuHuiTi-2-65-Medium.ttf": "092a99ee52bbaef7481cc96c5b85b992", |
| | | "resource\\image\\4g.png": "e5b27ed5a596cb16c7ab695d82fe3014", |
| | | "resource\\image\\4g_dark.png": "414b3a9fcefd8ea6909158b51038d4d8", |
| | | "resource\\image\\accessCtrl.png": "6be30c8f648ec7153ae2c39a15884181", |
| | | "resource\\image\\add.png": "498480ce68e4d6047eb74d3aa5229f56", |
| | | "resource\\image\\advance.png": "d98aeb99a04163bce23b6c2638cd705a", |
| | | "resource\\image\\app.png": "7640c7358a3f5dba1f887b8413b93a9d", |
| | | "resource\\image\\app_btn.png": "aa325cea46fd3918c86d76bf009b1663", |
| | | "resource\\image\\app_qrcode.png": "0a20655d02ff0e473106bf41f7c9687b", |
| | | "resource\\image\\arrow_right.png": "edc6876d6fa1e2d0be2e606c73e0f2ec", |
| | | "resource\\image\\back.png": "aa5869ff78051dbdc5f688f1805064da", |
| | | "resource\\image\\background.jpg": "90d464f4221f62132ebf74e69446b6d7", |
| | | "resource\\image\\backspace.png": "26302e37dd8618e92c3a47d68039d0ec", |
| | | "resource\\image\\back_2.png": "b3f16ab01606d85c2c70124d50b3af1b", |
| | | "resource\\image\\basic.png": "84eedd84efdc5fdb54138dd29cf6fc41", |
| | | "resource\\image\\black_btn.png": "13ee1720aff247ba3f8e22e00f89a316", |
| | | "resource\\image\\card.png": "c05047d2ad6549db001d08790cb5d9ff", |
| | | "resource\\image\\close.png": "a5353c231df804fcc4577672ab3a4302", |
| | | "resource\\image\\close_small.png": "7d6cddddc38ce8d4950789169213add4", |
| | | "resource\\image\\cloudCert.png": "4481cfb9c2d1f44f0a0dd0489cb6fc2b", |
| | | "resource\\image\\co2_f.png": "7e6f00c03b71a4dbe439491083ca731c", |
| | | "resource\\image\\co2_s.png": "4fb691286b8856f1ed25ef8bacdb6099", |
| | | "resource\\image\\commMgmt.png": "5cd157e1b8c82fdf9ddba1f6d5047b9b", |
| | | "resource\\image\\config.png": "50d2091b9f7fba5915dbed0aa0dcf918", |
| | | "resource\\image\\config_btn.png": "e54cbc27d30e7c6480b83107a631e7ef", |
| | | "resource\\image\\delete.png": "014bad6d9a94a133c58ef350e198101e", |
| | | "resource\\image\\delete_fill.png": "947fc08278354a1151d5599382c2c5f3", |
| | | "resource\\image\\deviceInfo.png": "3e40246e01c1f7eede4d76fcbba33825", |
| | | "resource\\image\\devInfo.png": "1a80aba6780a45f8775bdfdcff4df23a", |
| | | "resource\\image\\doorControl.png": "68993ef92bb8c6b2d0dab2c75cc7533d", |
| | | "resource\\image\\down.png": "c4d5c1883db4694ccedb7c1140d89da9", |
| | | "resource\\image\\emergencyOpen.png": "890877dee840dabe60487f8ce57b41f6", |
| | | "resource\\image\\empty.png": "8283ac78099d9c13ef4b552ce86f5c38", |
| | | "resource\\image\\enter.png": "787e076256c8a47e07f2091a57585fb5", |
| | | "resource\\image\\enter_b.png": "02cb6c84fec128a639e3cf0828a6ee5f", |
| | | "resource\\image\\ethernet.png": "f3abb111d96a11a56f7ed77b21abab4c", |
| | | "resource\\image\\ethernet_dark.png": "10656303a6d22e204014f55ed0fb3efb", |
| | | "resource\\image\\eth_disable.png": "7017f5cc2c9b4f802f082f6c0f5bb581", |
| | | "resource\\image\\eth_enable.png": "84d1334e524ac669c3b79e8a69b41eb1", |
| | | "resource\\image\\eye-fill.png": "9ae71914bd47423be04d0a22eb4f3995", |
| | | "resource\\image\\eye-off.png": "295c3e8255ced50cf2667ecda524e11e", |
| | | "resource\\image\\eye_fill.png": "d0ac0d07f13e02e5fae7a12a0858ec49", |
| | | "resource\\image\\eye_fill_show.png": "265cf669797b94a138982c01c29d0bd9", |
| | | "resource\\image\\face.png": "d695a5f29dbf051fc0c6e0d4e177f5c5", |
| | | "resource\\image\\faceAdd.png": "5e0e3d4eb3f034a179a8eef5c08d4c63", |
| | | "resource\\image\\faceEmpty.png": "9ef3bd1d776183e203e69d5c91e4b129", |
| | | "resource\\image\\faceError.png": "19841af9136d4483642a254ab1a6f57c", |
| | | "resource\\image\\faceRec.png": "f1bfcb61f4642c6c1bbc04856fb57905", |
| | | "resource\\image\\faceRec2.png": "580c72783b4cfc64ec0a9593e77c456a", |
| | | "resource\\image\\factoryTest.png": "4bdb36420046870efcabd4a040e31913", |
| | | "resource\\image\\failBg.png": "5d6dca3cc98032a10ef4bc0658f7e546", |
| | | "resource\\image\\grey_btn.png": "b0ca6e44c0e01a17d0bdda5f7e057cc2", |
| | | "resource\\image\\help.png": "7d75da0510ca74870858a639882dc2ef", |
| | | "resource\\image\\idleImage.jpg": "90d464f4221f62132ebf74e69446b6d7", |
| | | "resource\\image\\input_bg.png": "8a8f5c43f1118869a7679ccbaaf47de2", |
| | | "resource\\image\\light_close.png": "607b38280bb5321327cacce5bd6c3fe9", |
| | | "resource\\image\\light_open.png": "1a8df3753b6f0df9e7abb5b53dabd72e", |
| | | "resource\\image\\localUser.png": "6429f43f7fee002d66d50a3d92a087da", |
| | | "resource\\image\\lock.png": "c1419aa2a9c9da4b7dbf3529a1af37f3", |
| | | "resource\\image\\logo.png": "5768b9344bedc53096d2227bee5d52d4", |
| | | "resource\\image\\menu_btn.png": "df98739cd4804d08b23eaf33bb92e1bc", |
| | | "resource\\image\\mini_app.png": "82ee9005b5d162a6fbb0d32764088da4", |
| | | "resource\\image\\mini_background.png": "620bf06dbfffe37f717b91fb3ed8ef40", |
| | | "resource\\image\\mini_config.png": "6bf78553fb53673a89e80613cfbee4c1", |
| | | "resource\\image\\mini_password.png": "6892385a457e084953bcf9acb2ae9957", |
| | | "resource\\image\\mqtt.png": "542ebc6bdbb66ea0f25cf29aeb9d264c", |
| | | "resource\\image\\mqtt_dark.png": "d4aab5adc128846c47a3b8bb015c757b", |
| | | "resource\\image\\mqtt_enable.png": "fc766f5fcbb95eca648ee10d421cc8fe", |
| | | "resource\\image\\network.png": "0a0119e3d5fce101b28575a4e44aaf7e", |
| | | "resource\\image\\networkSetting.png": "3e83d354e8293ed112fe7cc405b94187", |
| | | "resource\\image\\network_dark.png": "3c5f8ce5732e95ad613cdd41dc5adbc0", |
| | | "resource\\image\\o2_f.png": "b787951eba880b3ae82b42594b4e30df", |
| | | "resource\\image\\o2_s.png": "50564fb865bb7f5ed0352e43ea17d853", |
| | | "resource\\image\\ph3_f.png": "e95a348c887298dc4ed0555c577ea5bb", |
| | | "resource\\image\\ph3_s.png": "96e68d741b75fcd6938a6909014cccb0", |
| | | "resource\\image\\pwd_btn.png": "8764458bee98bff728445837e126231e", |
| | | "resource\\image\\qrcode_small.png": "285bbe7e8f968c8bf4506a563dffcac2", |
| | | "resource\\image\\recordQuery.png": "d340255a0c2342382bff6f8c57f6376b", |
| | | "resource\\image\\recQuery.png": "1b8c58663a6e61f4f885e784ee4e87d4", |
| | | "resource\\image\\rectangle.png": "394e2e483120908674f6de7fb879bfcf", |
| | | "resource\\image\\register.png": "7fa975d92007703532ba8011f2a0109f", |
| | | "resource\\image\\right.png": "a6f6bc770ad7a8220effcc96e750aaaa", |
| | | "resource\\image\\select_arrow.png": "9d82daa1092375abc413d581f36aaf2d", |
| | | "resource\\image\\setting.png": "92365fd93f2cfa63c7901ce3d8900a42", |
| | | "resource\\image\\setting32.png": "e531bf8a9ce7f6cf93a8ea9baf95377c", |
| | | "resource\\image\\space.png": "de9816e31308bd7ce187fe03ab634a37", |
| | | "resource\\image\\successBg.png": "1ef294bd7e1688bba47c2337906b1d1d", |
| | | "resource\\image\\success_fill.png": "09166b0cd4da44b76b4f6cdc2c550103", |
| | | "resource\\image\\sysSettings.png": "0a84bbe887481a1cce1ca562f83d5b89", |
| | | "resource\\image\\systemSetting.png": "9aee20d073df321250a5bbc57d16d5f1", |
| | | "resource\\image\\sys_info.png": "20dc23c019d07cd2c3ce32a160b7b63f", |
| | | "resource\\image\\title_bg.png": "82fbdcc4133899d03072dcd57a92f203", |
| | | "resource\\image\\trackFace.png": "e90f92eb629563ede01aadca2b719de9", |
| | | "resource\\image\\unlock.png": "7b97b659c36d3ba4f435f44792b90a80", |
| | | "resource\\image\\user.png": "6429f43f7fee002d66d50a3d92a087da", |
| | | "resource\\image\\userGuide.png": "3227210f670f66cd6c29641e1212b0b8", |
| | | "resource\\image\\userMgmt.png": "5dad96f344513f970c2b582d7feb537d", |
| | | "resource\\image\\user_1.png": "36ab26e22dc39ea28c03f05f4ab891ce", |
| | | "resource\\image\\user_f.png": "d82d235224deccd2235ab15dbf1fda26", |
| | | "resource\\image\\user_s.png": "709953f3695cae9ac1bb50533f1a96ba", |
| | | "resource\\image\\user_w.png": "bc2ca556f37181815c0093d802f2f24f", |
| | | "resource\\image\\view_f.png": "4fbdda957ef2966bc4938990725d0246", |
| | | "resource\\image\\view_s.png": "93ddad11d282c5a8f56233682290b38c", |
| | | "resource\\image\\vip.png": "0e816b4860ee87ed1169154e3f0fc524", |
| | | "resource\\image\\voiceBroadcast.png": "e6f1a31ba7159962d18b77deef71c106", |
| | | "resource\\image\\wifi.png": "fd668b648ac984ed92fad8e40e151283", |
| | | "resource\\image\\wifi_dark.png": "37505f892ac6a43cb8dc5ea685de9740", |
| | | "resource\\langPack.js": "b537e7ad7b7bd36ebef146692604007d", |
| | | "resource\\wav\\alarm.wav": "fe9d43cfb930f873973cc31fd6e8c132", |
| | | "src\\common\\consts\\configConst.js": "8cdbeff06611f7c94fc349afb2d04364", |
| | | "src\\common\\utils\\utils.js": "f45a9074748680b00ba663ad6490acf0", |
| | | "src\\config.json": "c6c52fdf036881dd11081f96b491fee5", |
| | | "src\\controller.js": "f09517062ac2a8641ea17909f9e635fd", |
| | | "src\\driver.js": "02c38e2dcc749c50fb348b94629278d0", |
| | | "src\\main.js": "a893be0e60fcd2ca32c94baf8534f996", |
| | | "src\\screen.js": "a2f377ed5832bb9139dfcaadffe091c7", |
| | | "src\\service\\accessService.js": "ca2abf5ea0cae58a1fc9ccffb9f03454", |
| | | "src\\service\\codeService.js": "63934baff614eedf7f8c7ee4855f9ebe", |
| | | "src\\service\\configService.js": "d991f7261781465e306cd9d4548eab4d", |
| | | "src\\service\\faceService.js": "4e6ef420f61bb617e3b57491f9305cb2", |
| | | "src\\service\\gpiokeyService.js": "71c8f8a2589492153671f1d7ed96e6c8", |
| | | "src\\service\\grainService.js": "99f05184d3fcdf5c4e54fce08500267b", |
| | | "src\\service\\mqttService.js": "78d18810234846a26b49161dc6f193af", |
| | | "src\\service\\nfcService.js": "45705bc6a95206927085f11e7208cac2", |
| | | "src\\service\\platService.js": "a38387366ed212029bb46c6d3a85f2e9", |
| | | "src\\service\\sqliteService.js": "f2f0864ae07d893789bfc1666b584410", |
| | | "src\\service\\uart485Service.js": "c62ad21c538095f950dffe12d6770aa0", |
| | | "src\\services.js": "b87698f1e9e03bcfac820956034b06fe", |
| | | "src\\ui.js": "e9adc3aac685e711427667fa7705be6f", |
| | | "src\\view\\appView.js": "3ada10f0136eb464c035aec809a6e600", |
| | | "src\\view\\config\\configView.js": "6e30bb6aa2a9f6e6187dc6d86d832901", |
| | | "src\\view\\config\\identityVerificationView.js": "aa8cdd417184b2bdcef1a6cbd49df487", |
| | | "src\\view\\config\\menu\\cloudCertView.js": "7c9181ccfa5b5e96a234f1f55307ccb9", |
| | | "src\\view\\config\\menu\\deviceInfo\\dataCapacityInfoView.js": "9b6d8db4b83758d778f84ac2a1a266c8", |
| | | "src\\view\\config\\menu\\deviceInfo\\systemInfoView.js": "9396136cd353b10bb9a56f9bda2315d5", |
| | | "src\\view\\config\\menu\\deviceInfoView.js": "b33452d2a4d7188c5d14c6f76b726e90", |
| | | "src\\view\\config\\menu\\dockingSetting.js": "13a156aa4889a7d032a6fa26605e85b8", |
| | | "src\\view\\config\\menu\\doorControlView.js": "ffd1d5bc1bb7c652bc678c52e9969fda", |
| | | "src\\view\\config\\menu\\factoryTestView.js": "9588321c8282257e9707ebedb5920cda", |
| | | "src\\view\\config\\menu\\helpView.js": "00e750b2b637dc318f75e840d901fb5c", |
| | | "src\\view\\config\\menu\\localUser\\faceEnterView.js": "d993d07711e15cf5f0fee01a22753bfa", |
| | | "src\\view\\config\\menu\\localUser\\localUserAddView.js": "bf4646521acd0e14832eb732bc424e77", |
| | | "src\\view\\config\\menu\\localUserView.js": "c870b92aaaec5aff368e07e9f254e8aa", |
| | | "src\\view\\config\\menu\\networkSettingView.js": "325d70ed8ab1e170ffc1fa03fff637f5", |
| | | "src\\view\\config\\menu\\recordQuery\\recordQueryDetailView.js": "7077207b15bf1d7eae3a9a01dc68dc77", |
| | | "src\\view\\config\\menu\\recordQueryView.js": "67b573825af0639a4103bdc97b0f2c4a", |
| | | "src\\view\\config\\menu\\systemSetting\\displaySettingView.js": "c57f3b9faf85e048864c08d592481a72", |
| | | "src\\view\\config\\menu\\systemSetting\\faceRecognitionSettingView.js": "4d6b4e8b6c0f6e0ccbaaaa169e65b780", |
| | | "src\\view\\config\\menu\\systemSetting\\passLogSettingView.js": "d51958ac39b104846586b1ed6590414c", |
| | | "src\\view\\config\\menu\\systemSetting\\passwordManagementView.js": "98a6ca138cc1e2bc33ff6a3248e11263", |
| | | "src\\view\\config\\menu\\systemSetting\\passwordOpenDoorSettingView.js": "6e2ab3793e6c569097b702c339ef1602", |
| | | "src\\view\\config\\menu\\systemSetting\\swipeCardRecognitionSettingView.js": "871b483fbc3d778df95b803c130101e1", |
| | | "src\\view\\config\\menu\\systemSetting\\timeSettingView.js": "6950faa3a3296a573d048eb782c0e6ca", |
| | | "src\\view\\config\\menu\\systemSettingView.js": "ca3ac7b0e0390c7d542b62d569f57b24", |
| | | "src\\view\\config\\menu\\voiceBroadcastView.js": "a809af8acdae03f15c6e677bef6f20a1", |
| | | "src\\view\\config\\newPwdView.js": "32e3cfb0cc7f88361f1c69797cdb14b8", |
| | | "src\\view\\emergencyPwdView.js": "c6413bc04d38d54e57f590ce44204bcb", |
| | | "src\\view\\i18n.js": "94f43798d35026189125bf2534d1bffd", |
| | | "src\\view\\idleView.js": "b95c100ae4b2757ea2b0844a3df35c9e", |
| | | "src\\view\\mainView.js": "ec96a69994b99ed36778338198f74765", |
| | | "src\\view\\pinyin\\dict.js": "e40764bfc6bab80119c584315c0c48b7", |
| | | "src\\view\\pinyin\\pinyin.js": "c0809d9d1ebe5937cb6831b2b70db439", |
| | | "src\\view\\pwdView.js": "226b8b83a13b82cc925519ae051f8b3f", |
| | | "src\\view\\topView.js": "c9d8a4e3bc362edb1a5007135323beea", |
| | | "src\\view\\viewUtils.js": "ceaaad4fb40024b448a66a03911a7279", |
| | | "src\\worker\\accessWorker.js": "1b1253b5a7fbb2e733be2a9b0714ecca", |
| | | "src\\worker\\httpWorker.js": "47ddc63bdd95ecf36f7eaaa5f409424c" |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | { |
| | | "app.dxproj": "cb10fd21e8e17ada45c25e1e1ba3226e", |
| | | "dxmodules\\cameraCalibrationWorker.js": "5812507304ced88da3677a3c68f79a78", |
| | | "dxmodules\\capturerWorker.js": "a3104a1d73ab1bd4f596495d817ecf39", |
| | | "dxmodules\\dxAlsa.js": "d82fe4f74383edf6198269968a82b5e7", |
| | | "dxmodules\\dxBase64.js": "7cb517ecd99830dde0ec13a501e831ea", |
| | | "dxmodules\\dxCameraCalibration.js": "8e42bf3752616896b88f9e9efbe20783", |
| | | "dxmodules\\dxCapturer.js": "7420d8e269fb8ebfc48c306e0a8fa7de", |
| | | "dxmodules\\dxCommon.js": "19f77916eb02e6fd01106597aca412bd", |
| | | "dxmodules\\dxConfig.js": "24072559b3cb1ec5c206cb358eaaaaae", |
| | | "dxmodules\\dxDriver.js": "c5969e91097030b90e9bcb62a827e344", |
| | | "dxmodules\\dxEid.js": "07d966e53b69629f152baf54cd163372", |
| | | "dxmodules\\dxEventBus.js": "81adf285545c12d49d7784327c41970a", |
| | | "dxmodules\\dxFace.js": "81790e30c6da75ae3bcb96afcafa5b02", |
| | | "dxmodules\\dxGpio.js": "30c34469e2dc8d80026fc5eac5bfd1f7", |
| | | "dxmodules\\dxGpioKey.js": "97ef2763bad50e0c82cfa5fb9b79f1eb", |
| | | "dxmodules\\dxHttp.js": "fa75a0a2951399fb5af7618d7ab4c6f1", |
| | | "dxmodules\\dxLogger.js": "f6d3f73086944fcdeeffa579ef6d1508", |
| | | "dxmodules\\dxMap.js": "2255d584c240c35a567f2c7b92e0a9da", |
| | | "dxmodules\\dxMqtt.js": "277fafb81971c8f3508a8a38f8f2703a", |
| | | "dxmodules\\dxNet.js": "58b13f928daeb1bae680c2350873baca", |
| | | "dxmodules\\dxNfc.js": "feb5bc21d4b13ab9736de1941290312d", |
| | | "dxmodules\\dxNtp.js": "0c90048eeb11e7e3b458e4d6e48932f2", |
| | | "dxmodules\\dxOta.js": "760dc97eb0724280f16f8616a2be171f", |
| | | "dxmodules\\dxPwm.js": "dc0734c231d7d4cd5f26a34c315cc4a2", |
| | | "dxmodules\\dxQrRule.js": "bfa9e2b4725c4fa358a2988f63c67210", |
| | | "dxmodules\\dxSqlite.js": "fb6a2f60b49d67a8ef36148355e5e30e", |
| | | "dxmodules\\dxStd.js": "6f239f2fd7d23e7ed053b762b235bd3c", |
| | | "dxmodules\\dxUart.js": "71edddfd98de79ccbd91e4e013af269b", |
| | | "dxmodules\\dxUi.js": "97bd858defaec480d755c162105a3f76", |
| | | "dxmodules\\dxWatchdog.js": "c4a7d5c8f0c203e6dafbc289a0f4fcbd", |
| | | "dxmodules\\dxWorkerPool.js": "5aad9b8f838d1339fc64083188d3ba69", |
| | | "dxmodules\\faceWorker.js": "d1d0d4f5e5503ca87bd69d1d2ee3ad00", |
| | | "dxmodules\\gpioKeyWorker.js": "78a7489cc3cf098fb4d218b17294175d", |
| | | "dxmodules\\libalc.so": "3128cc7cd0cc978e02db995433962c87", |
| | | "dxmodules\\libid_jpg.so": "18887cb0d0df6256604ed039d47dfc7b", |
| | | "dxmodules\\libid_jpg_codec.so": "c36bd0c28d2b43e9296736856da05129", |
| | | "dxmodules\\libie_jpg.so": "1343b7bc765f6464cf8e483c03edd542", |
| | | "dxmodules\\libie_jpg_codec.so": "508defffc1c72b0ae90afab117d6db80", |
| | | "dxmodules\\libJLReader.so": "ce7f448dea6a1c8988469d03ecfa6575", |
| | | "dxmodules\\liblombo_jpeg.so": "49508ccd603ed795efee3d0f8e7e3e2a", |
| | | "dxmodules\\libvbar-b-dxface.so": "689ee554f67057262860f7726042327b", |
| | | "dxmodules\\libvbar-b-dxgpio.so": "ca009351ab7d9719a71cd6105e9acba6", |
| | | "dxmodules\\libvbar-b-dxpwm.so": "b3e0e7cc950811385ceb204876fd8b19", |
| | | "dxmodules\\libvbar-b-dxwatchdog.so": "878352b309e9a9e17ce3ac83774d0fa9", |
| | | "dxmodules\\libvbar-drv-audio_gain.so": "14d23fe5134ff95982f1655058084709", |
| | | "dxmodules\\libvbar-drv-capturer.so": "295aaa64df97ee08053c26789ff57437", |
| | | "dxmodules\\libvbar-drv-capturer_calibration.so": "cdb2ca2205e36d82ebcce910e457bd9b", |
| | | "dxmodules\\libvbar-drv-display.so": "31c2a7a2ed4166d27359d208e4d34568", |
| | | "dxmodules\\libvbar-drv-face.so": "2c54abd0de9a287be3bbea490d0c45c4", |
| | | "dxmodules\\libvbar-drv-gpio.so": "e663856deb2d403558426455097e0bab", |
| | | "dxmodules\\libvbar-drv-memory.so": "0ed48486e154f24d6681a0195a7525ad", |
| | | "dxmodules\\libvbar-drv-pwm.so": "b9c2154b7020d41b01d63f6caac1510f", |
| | | "dxmodules\\libvbar-drv-soc.so": "73e4b6657af4bcff0affaacf55702096", |
| | | "dxmodules\\libvbar-drv-tts.so": "97076b55a3338196f512c61101ac0e9a", |
| | | "dxmodules\\libvbar-drv-watchdog.so": "9367e995f85cb191da0567d0acd4ed67", |
| | | "dxmodules\\libvbar-m-alsa.so": "1154ff7cb2f84ee378f29e0d03551f96", |
| | | "dxmodules\\libvbar-m-capturer.so": "8f0b6383db39494904294c3f60c5f013", |
| | | "dxmodules\\libvbar-m-channel.so": "6b6f7d8edb178b11b9a93123e0a7abdb", |
| | | "dxmodules\\libvbar-m-common.so": "074eb14e701c5ed910b979339453f484", |
| | | "dxmodules\\libvbar-m-dxalsa.so": "bb4fcf0be6ccb0cc2d7b295002925148", |
| | | "dxmodules\\libvbar-m-dxcapturer.so": "506307dec2552200eaa22412987b643e", |
| | | "dxmodules\\libvbar-m-dxcapturer_calibration.so": "c41e691d69621ab5a96322f47d3eb286", |
| | | "dxmodules\\libvbar-m-dxchannel.so": "ff80aaf50113c160c663a80015471079", |
| | | "dxmodules\\libvbar-m-dxcommon.so": "d4ca3ce51543d07c81cc75974adcbccb", |
| | | "dxmodules\\libvbar-m-dxeid.so": "3458f8221dd572220003e4344837d846", |
| | | "dxmodules\\libvbar-m-dxhttp.so": "1ec2f9ccc26aebc390944340afde6044", |
| | | "dxmodules\\libvbar-m-dxkey.so": "e49a86e25944050bda8565677713431a", |
| | | "dxmodules\\libvbar-m-dxmap.so": "55ebd66234d59490ab56f88398419dde", |
| | | "dxmodules\\libvbar-m-dxmqtt.so": "0cbeb2b46441ee89678516a1a941cd58", |
| | | "dxmodules\\libvbar-m-dxnet.so": "eed60270cabaf872983c6f905b0ceb03", |
| | | "dxmodules\\libvbar-m-dxsqlite.so": "15a0eb0d18b58cad3868f86e9edfb409", |
| | | "dxmodules\\libvbar-m-dxui.so": "ca22e1a0c52977749a32b2cc70e942a9", |
| | | "dxmodules\\libvbar-m-eid.so": "e7d1db4d1bfab4c462c9d22807099268", |
| | | "dxmodules\\libvbar-m-key.so": "f7f1f2ae6c9c1f298376375a8b16b6ee", |
| | | "dxmodules\\libvbar-m-net.so": "afa1adebb44fc9734b26b99e87e0728d", |
| | | "dxmodules\\libvbar-m-vgmqtt.so": "56e94165ba896867fbe3ead167022d3f", |
| | | "dxmodules\\libvbar-p-dxnfc.so": "14d17fe22a0dbfc00b13c4d9cef8512f", |
| | | "dxmodules\\libvbar-p-nfc.so": "f1a1f96558b2509c5b629790cec16386", |
| | | "dxmodules\\libvccore.so": "9c383ca78ee117ea3295baefb1f1fee2", |
| | | "dxmodules\\libyuv.so": "2c4faa3ab51260f5285cd91dda44b3a9", |
| | | "dxmodules\\mqttWorker.js": "4eedadbd41d6bd183cde2830a3347ad1", |
| | | "dxmodules\\netWorker.js": "c5d4c9022f8912b47249b14477aed70a", |
| | | "dxmodules\\nfcWorker.js": "88fadfc469cc397b66fd5e52db073bde", |
| | | "dxmodules\\uiBase.js": "9ea5cd2b5ed52d183fde2d87b8f70ca1", |
| | | "dxmodules\\uiButton.js": "8ffe0ffce9ac6b341c9993e260b52b05", |
| | | "dxmodules\\uiButtons.js": "52cb9727c2225f75ac6144e756a6d511", |
| | | "dxmodules\\uiCheckbox.js": "5aa8c851e8b2333cbe46cdd69452ab8c", |
| | | "dxmodules\\uiDropdown.js": "2b73bfacf3d4b115ab3997c83284c478", |
| | | "dxmodules\\uiFont.js": "257aa2f90ce2f0ace4095a03d3447b0b", |
| | | "dxmodules\\uiImage.js": "b2a0a963993474205bc7dc91c8696ec1", |
| | | "dxmodules\\uiKeyboard.js": "b225c62ff2f4b8aa0bdb675776b236a1", |
| | | "dxmodules\\uiLabel.js": "e0ae808d468459a6fedc7ba9a551359e", |
| | | "dxmodules\\uiLine.js": "cc18bc32c0a6f0f8db7992d6e0b4fd81", |
| | | "dxmodules\\uiList.js": "8b779a85cd54b25bc50ec616ed9f08d1", |
| | | "dxmodules\\uiSlider.js": "91b743902824b5decf5535dad49fc97e", |
| | | "dxmodules\\uiStyle.js": "60350cf77db84793bf093bda341f2cb9", |
| | | "dxmodules\\uiSwitch.js": "9a836405abe0b09f5a2940cf22698968", |
| | | "dxmodules\\uiTextarea.js": "0d5008a5a95b78ea8efde3408ba6fb4a", |
| | | "dxmodules\\uiUtils.js": "a04cc3baa5ba1dc6d1ab65b526464fa6", |
| | | "dxmodules\\uiView.js": "26fe7b992ac82bf5d45447f2921bff2f", |
| | | "dxmodules\\vgUartWorker.js": "fc3e9e0051836d5063c0eecf555d9521", |
| | | "README.md": "c472daef5243f3790f2faee1cf8e2255", |
| | | "README_CN.md": "a46b1c92c09f375881a49d8c42adf6b3", |
| | | "resource\\CN\\wav\\access_f.wav": "f951f3cc1f03aaa794231413fd4efcc6", |
| | | "resource\\CN\\wav\\access_s.wav": "6d1b31bdcaaa13ba719e3223b55d5235", |
| | | "resource\\CN\\wav\\btn11.wav": "a623797305d7b0e6b8cb6b2ab3d43591", |
| | | "resource\\CN\\wav\\btn12.wav": "26bbfc3eed36211713dca9afb423e168", |
| | | "resource\\CN\\wav\\btn13.wav": "67d6fe32693cb2e7653c2ff2141ce873", |
| | | "resource\\CN\\wav\\btn21.wav": "53071472fce6128fdd2ed304e4d78406", |
| | | "resource\\CN\\wav\\btn22.wav": "e35c87d370695099d3b6d7f512496395", |
| | | "resource\\CN\\wav\\btn23.wav": "f25db5592331f1e6deb67beecb3c1131", |
| | | "resource\\CN\\wav\\btn31.wav": "054a4f36ebda08fadca3162d955560bf", |
| | | "resource\\CN\\wav\\btn32.wav": "64eb5fef123eafd7b52108ebcd6bace9", |
| | | "resource\\CN\\wav\\btn33.wav": "67d6fe32693cb2e7653c2ff2141ce873", |
| | | "resource\\CN\\wav\\calibration_s.wav": "d2ff1f1f4a40bf4166130dc079939079", |
| | | "resource\\CN\\wav\\control_f.wav": "4dbaca7e4d227a720620b846544b469a", |
| | | "resource\\CN\\wav\\door_close.wav": "325ca8082f8e9fceb2c7eeeb78d8645b", |
| | | "resource\\CN\\wav\\door_open.wav": "f3b5291fc8babaffd32107198cdd5afa", |
| | | "resource\\CN\\wav\\emergency.wav": "a1855c22f3ef2f69d5c84d3a2852ae1f", |
| | | "resource\\CN\\wav\\emergency_f.wav": "946ac86e74b849ad8f1bec3615cf9b39", |
| | | "resource\\CN\\wav\\emergency_s.wav": "a717e3417891ff306225ac075ba28082", |
| | | "resource\\CN\\wav\\failed.wav": "891194e741b0bc8f6332f78eb607cc85", |
| | | "resource\\CN\\wav\\light_close.wav": "b1ac09e91ac4ce3825614ad1654a3f58", |
| | | "resource\\CN\\wav\\light_open.wav": "16b7b6b8c6eb469645a15e4a54a3e014", |
| | | "resource\\CN\\wav\\network.wav": "7bbc6d740918a20acfb5ef75df685bdb", |
| | | "resource\\CN\\wav\\read.wav": "c83edd035dc15f7a716644319e849215", |
| | | "resource\\CN\\wav\\recg_f.wav": "5cd4d88db4e3f8332b9e73fe05222c83", |
| | | "resource\\CN\\wav\\recg_s.wav": "4afadeb018b08518d5d3dd1cfc5e0d64", |
| | | "resource\\CN\\wav\\recognition.wav": "da00dd97d1e8ca0ed20dc43eb4daafc8", |
| | | "resource\\CN\\wav\\recognition_s.wav": "df9916d6fe3d285894668e63d1aeeb1d", |
| | | "resource\\CN\\wav\\register.wav": "a91d6ebb846dc834816a954168da1352", |
| | | "resource\\CN\\wav\\stranger.wav": "2e6690d7ddcd3609ca3e6d6717b61a9c", |
| | | "resource\\CN\\wav\\user2.wav": "868a9b15aac20b62457f98c955f4e5e0", |
| | | "resource\\CN\\wav\\user2_s.wav": "98904054df059be8cd69e08c302317e7", |
| | | "resource\\CN\\wav\\verify.wav": "2bc2b96e0ca05052985fda98fb552ef9", |
| | | "resource\\CN\\wav\\verify_10x_f.wav": "bf26ce11bbd801f5efeff8c9250f219f", |
| | | "resource\\CN\\wav\\verify_10x_s.wav": "2d04b22277844d9c35e08e4e2c67c11c", |
| | | "resource\\CN\\wav\\verify_200_f.wav": "393036b5fc28a3c04580593d59e26e7e", |
| | | "resource\\CN\\wav\\verify_200_s.wav": "585267371d37f3f45e3826ec7dcafbd3", |
| | | "resource\\CN\\wav\\verify_300_f.wav": "e44977e8b6dcac8adbf304894afd24e0", |
| | | "resource\\CN\\wav\\verify_300_s.wav": "d8e23a91e4999b2d77454aab824bd611", |
| | | "resource\\CN\\wav\\verify_400_f.wav": "05752c8c9c2bf4334943999842529d8b", |
| | | "resource\\CN\\wav\\verify_400_s.wav": "740a63ffe907dda0f2d0e14cb9a83f74", |
| | | "resource\\EN\\wav\\calibration_s.wav": "b5497547d9e7e6fb5b28ee307b27752b", |
| | | "resource\\EN\\wav\\network.wav": "1e8ccfd03ca83976fefdba1edcf1b194", |
| | | "resource\\EN\\wav\\read.wav": "8c1f6ee62c7bf74db5ecab28d3988eeb", |
| | | "resource\\EN\\wav\\recg_f.wav": "e303563b867dd6eaebac18679ca760df", |
| | | "resource\\EN\\wav\\recg_s.wav": "183a843b668aa919311a6d352af80f35", |
| | | "resource\\EN\\wav\\recognition.wav": "1c9e06bc338c49c120aa101b1fac8de0", |
| | | "resource\\EN\\wav\\recognition_s.wav": "f887f2b1615121bbe815fef7f64d3b92", |
| | | "resource\\EN\\wav\\register.wav": "de5d0048f840243fdd1392c09d9ac164", |
| | | "resource\\EN\\wav\\stranger.wav": "31775350903916827fdec25b9c65dd94", |
| | | "resource\\EN\\wav\\verify.wav": "2e77ec2c754e1dea329988d4e462aa2f", |
| | | "resource\\EN\\wav\\verify_10x_f.wav": "7ccc23490436b9f1de32200230953a62", |
| | | "resource\\EN\\wav\\verify_10x_s.wav": "0630e0410fca3c7fd7e701c69e8ea4bc", |
| | | "resource\\EN\\wav\\verify_200_f.wav": "64ce473b0f560cc1613469ab94197ce6", |
| | | "resource\\EN\\wav\\verify_200_s.wav": "e3d28c408cc3bef5461620c75b15abdf", |
| | | "resource\\EN\\wav\\verify_300_f.wav": "7fa0d7bf85d040b72a89cfb9e2f06bcf", |
| | | "resource\\EN\\wav\\verify_300_s.wav": "3e69fd763477d6cc30543d838f33d718", |
| | | "resource\\EN\\wav\\verify_400_f.wav": "d074b8f6e4e968b6d1984b123ed4d387", |
| | | "resource\\EN\\wav\\verify_400_s.wav": "9141136d3310a5fac5917d3f6056249f", |
| | | "resource\\font\\AlibabaPuHuiTi-2-65-Medium.ttf": "092a99ee52bbaef7481cc96c5b85b992", |
| | | "resource\\image\\4g.png": "e5b27ed5a596cb16c7ab695d82fe3014", |
| | | "resource\\image\\4g_dark.png": "414b3a9fcefd8ea6909158b51038d4d8", |
| | | "resource\\image\\accessCtrl.png": "6be30c8f648ec7153ae2c39a15884181", |
| | | "resource\\image\\add.png": "498480ce68e4d6047eb74d3aa5229f56", |
| | | "resource\\image\\advance.png": "d98aeb99a04163bce23b6c2638cd705a", |
| | | "resource\\image\\app.png": "7640c7358a3f5dba1f887b8413b93a9d", |
| | | "resource\\image\\app_btn.png": "aa325cea46fd3918c86d76bf009b1663", |
| | | "resource\\image\\app_qrcode.png": "0a20655d02ff0e473106bf41f7c9687b", |
| | | "resource\\image\\arrow_right.png": "edc6876d6fa1e2d0be2e606c73e0f2ec", |
| | | "resource\\image\\back.png": "aa5869ff78051dbdc5f688f1805064da", |
| | | "resource\\image\\background.jpg": "90d464f4221f62132ebf74e69446b6d7", |
| | | "resource\\image\\backspace.png": "26302e37dd8618e92c3a47d68039d0ec", |
| | | "resource\\image\\back_2.png": "b3f16ab01606d85c2c70124d50b3af1b", |
| | | "resource\\image\\basic.png": "84eedd84efdc5fdb54138dd29cf6fc41", |
| | | "resource\\image\\black_btn.png": "13ee1720aff247ba3f8e22e00f89a316", |
| | | "resource\\image\\card.png": "c05047d2ad6549db001d08790cb5d9ff", |
| | | "resource\\image\\close.png": "a5353c231df804fcc4577672ab3a4302", |
| | | "resource\\image\\close_small.png": "7d6cddddc38ce8d4950789169213add4", |
| | | "resource\\image\\cloudCert.png": "4481cfb9c2d1f44f0a0dd0489cb6fc2b", |
| | | "resource\\image\\co2_f.png": "7e6f00c03b71a4dbe439491083ca731c", |
| | | "resource\\image\\co2_s.png": "4fb691286b8856f1ed25ef8bacdb6099", |
| | | "resource\\image\\commMgmt.png": "5cd157e1b8c82fdf9ddba1f6d5047b9b", |
| | | "resource\\image\\config.png": "50d2091b9f7fba5915dbed0aa0dcf918", |
| | | "resource\\image\\config_btn.png": "e54cbc27d30e7c6480b83107a631e7ef", |
| | | "resource\\image\\delete.png": "014bad6d9a94a133c58ef350e198101e", |
| | | "resource\\image\\delete_fill.png": "947fc08278354a1151d5599382c2c5f3", |
| | | "resource\\image\\deviceInfo.png": "3e40246e01c1f7eede4d76fcbba33825", |
| | | "resource\\image\\devInfo.png": "1a80aba6780a45f8775bdfdcff4df23a", |
| | | "resource\\image\\doorControl.png": "68993ef92bb8c6b2d0dab2c75cc7533d", |
| | | "resource\\image\\down.png": "c4d5c1883db4694ccedb7c1140d89da9", |
| | | "resource\\image\\emergencyOpen.png": "890877dee840dabe60487f8ce57b41f6", |
| | | "resource\\image\\empty.png": "8283ac78099d9c13ef4b552ce86f5c38", |
| | | "resource\\image\\enter.png": "787e076256c8a47e07f2091a57585fb5", |
| | | "resource\\image\\enter_b.png": "02cb6c84fec128a639e3cf0828a6ee5f", |
| | | "resource\\image\\ethernet.png": "f3abb111d96a11a56f7ed77b21abab4c", |
| | | "resource\\image\\ethernet_dark.png": "10656303a6d22e204014f55ed0fb3efb", |
| | | "resource\\image\\eth_disable.png": "7017f5cc2c9b4f802f082f6c0f5bb581", |
| | | "resource\\image\\eth_enable.png": "84d1334e524ac669c3b79e8a69b41eb1", |
| | | "resource\\image\\eye-fill.png": "9ae71914bd47423be04d0a22eb4f3995", |
| | | "resource\\image\\eye-off.png": "295c3e8255ced50cf2667ecda524e11e", |
| | | "resource\\image\\eye_fill.png": "d0ac0d07f13e02e5fae7a12a0858ec49", |
| | | "resource\\image\\eye_fill_show.png": "265cf669797b94a138982c01c29d0bd9", |
| | | "resource\\image\\face.png": "d695a5f29dbf051fc0c6e0d4e177f5c5", |
| | | "resource\\image\\faceAdd.png": "5e0e3d4eb3f034a179a8eef5c08d4c63", |
| | | "resource\\image\\faceEmpty.png": "9ef3bd1d776183e203e69d5c91e4b129", |
| | | "resource\\image\\faceError.png": "19841af9136d4483642a254ab1a6f57c", |
| | | "resource\\image\\faceRec.png": "f1bfcb61f4642c6c1bbc04856fb57905", |
| | | "resource\\image\\faceRec2.png": "580c72783b4cfc64ec0a9593e77c456a", |
| | | "resource\\image\\factoryTest.png": "4bdb36420046870efcabd4a040e31913", |
| | | "resource\\image\\failBg.png": "5d6dca3cc98032a10ef4bc0658f7e546", |
| | | "resource\\image\\grey_btn.png": "b0ca6e44c0e01a17d0bdda5f7e057cc2", |
| | | "resource\\image\\help.png": "7d75da0510ca74870858a639882dc2ef", |
| | | "resource\\image\\idleImage.jpg": "90d464f4221f62132ebf74e69446b6d7", |
| | | "resource\\image\\input_bg.png": "8a8f5c43f1118869a7679ccbaaf47de2", |
| | | "resource\\image\\light_close.png": "607b38280bb5321327cacce5bd6c3fe9", |
| | | "resource\\image\\light_open.png": "1a8df3753b6f0df9e7abb5b53dabd72e", |
| | | "resource\\image\\localUser.png": "6429f43f7fee002d66d50a3d92a087da", |
| | | "resource\\image\\lock.png": "c1419aa2a9c9da4b7dbf3529a1af37f3", |
| | | "resource\\image\\logo.png": "5768b9344bedc53096d2227bee5d52d4", |
| | | "resource\\image\\menu_btn.png": "df98739cd4804d08b23eaf33bb92e1bc", |
| | | "resource\\image\\mini_app.png": "82ee9005b5d162a6fbb0d32764088da4", |
| | | "resource\\image\\mini_background.png": "620bf06dbfffe37f717b91fb3ed8ef40", |
| | | "resource\\image\\mini_config.png": "6bf78553fb53673a89e80613cfbee4c1", |
| | | "resource\\image\\mini_password.png": "6892385a457e084953bcf9acb2ae9957", |
| | | "resource\\image\\mqtt.png": "542ebc6bdbb66ea0f25cf29aeb9d264c", |
| | | "resource\\image\\mqtt_dark.png": "d4aab5adc128846c47a3b8bb015c757b", |
| | | "resource\\image\\mqtt_enable.png": "fc766f5fcbb95eca648ee10d421cc8fe", |
| | | "resource\\image\\network.png": "0a0119e3d5fce101b28575a4e44aaf7e", |
| | | "resource\\image\\networkSetting.png": "3e83d354e8293ed112fe7cc405b94187", |
| | | "resource\\image\\network_dark.png": "3c5f8ce5732e95ad613cdd41dc5adbc0", |
| | | "resource\\image\\o2_f.png": "b787951eba880b3ae82b42594b4e30df", |
| | | "resource\\image\\o2_s.png": "50564fb865bb7f5ed0352e43ea17d853", |
| | | "resource\\image\\ph3_f.png": "e95a348c887298dc4ed0555c577ea5bb", |
| | | "resource\\image\\ph3_s.png": "96e68d741b75fcd6938a6909014cccb0", |
| | | "resource\\image\\pwd_btn.png": "8764458bee98bff728445837e126231e", |
| | | "resource\\image\\qrcode_small.png": "285bbe7e8f968c8bf4506a563dffcac2", |
| | | "resource\\image\\recordQuery.png": "d340255a0c2342382bff6f8c57f6376b", |
| | | "resource\\image\\recQuery.png": "1b8c58663a6e61f4f885e784ee4e87d4", |
| | | "resource\\image\\rectangle.png": "394e2e483120908674f6de7fb879bfcf", |
| | | "resource\\image\\register.png": "7fa975d92007703532ba8011f2a0109f", |
| | | "resource\\image\\right.png": "a6f6bc770ad7a8220effcc96e750aaaa", |
| | | "resource\\image\\select_arrow.png": "9d82daa1092375abc413d581f36aaf2d", |
| | | "resource\\image\\setting.png": "92365fd93f2cfa63c7901ce3d8900a42", |
| | | "resource\\image\\setting32.png": "e531bf8a9ce7f6cf93a8ea9baf95377c", |
| | | "resource\\image\\space.png": "de9816e31308bd7ce187fe03ab634a37", |
| | | "resource\\image\\successBg.png": "1ef294bd7e1688bba47c2337906b1d1d", |
| | | "resource\\image\\success_fill.png": "09166b0cd4da44b76b4f6cdc2c550103", |
| | | "resource\\image\\sysSettings.png": "0a84bbe887481a1cce1ca562f83d5b89", |
| | | "resource\\image\\systemSetting.png": "9aee20d073df321250a5bbc57d16d5f1", |
| | | "resource\\image\\sys_info.png": "20dc23c019d07cd2c3ce32a160b7b63f", |
| | | "resource\\image\\title_bg.png": "82fbdcc4133899d03072dcd57a92f203", |
| | | "resource\\image\\trackFace.png": "e90f92eb629563ede01aadca2b719de9", |
| | | "resource\\image\\unlock.png": "7b97b659c36d3ba4f435f44792b90a80", |
| | | "resource\\image\\user.png": "6429f43f7fee002d66d50a3d92a087da", |
| | | "resource\\image\\userGuide.png": "3227210f670f66cd6c29641e1212b0b8", |
| | | "resource\\image\\userMgmt.png": "5dad96f344513f970c2b582d7feb537d", |
| | | "resource\\image\\user_1.png": "36ab26e22dc39ea28c03f05f4ab891ce", |
| | | "resource\\image\\user_f.png": "d82d235224deccd2235ab15dbf1fda26", |
| | | "resource\\image\\user_s.png": "709953f3695cae9ac1bb50533f1a96ba", |
| | | "resource\\image\\user_w.png": "bc2ca556f37181815c0093d802f2f24f", |
| | | "resource\\image\\view_f.png": "4fbdda957ef2966bc4938990725d0246", |
| | | "resource\\image\\view_s.png": "93ddad11d282c5a8f56233682290b38c", |
| | | "resource\\image\\vip.png": "0e816b4860ee87ed1169154e3f0fc524", |
| | | "resource\\image\\voiceBroadcast.png": "e6f1a31ba7159962d18b77deef71c106", |
| | | "resource\\image\\wifi.png": "fd668b648ac984ed92fad8e40e151283", |
| | | "resource\\image\\wifi_dark.png": "37505f892ac6a43cb8dc5ea685de9740", |
| | | "resource\\langPack.js": "b537e7ad7b7bd36ebef146692604007d", |
| | | "resource\\wav\\alarm.wav": "fe9d43cfb930f873973cc31fd6e8c132", |
| | | "src\\common\\consts\\configConst.js": "8cdbeff06611f7c94fc349afb2d04364", |
| | | "src\\common\\utils\\utils.js": "f45a9074748680b00ba663ad6490acf0", |
| | | "src\\config.json": "c6c52fdf036881dd11081f96b491fee5", |
| | | "src\\controller.js": "f09517062ac2a8641ea17909f9e635fd", |
| | | "src\\driver.js": "02c38e2dcc749c50fb348b94629278d0", |
| | | "src\\main.js": "a893be0e60fcd2ca32c94baf8534f996", |
| | | "src\\screen.js": "a2f377ed5832bb9139dfcaadffe091c7", |
| | | "src\\service\\accessService.js": "ca2abf5ea0cae58a1fc9ccffb9f03454", |
| | | "src\\service\\codeService.js": "63934baff614eedf7f8c7ee4855f9ebe", |
| | | "src\\service\\configService.js": "d991f7261781465e306cd9d4548eab4d", |
| | | "src\\service\\faceService.js": "4e6ef420f61bb617e3b57491f9305cb2", |
| | | "src\\service\\gpiokeyService.js": "71c8f8a2589492153671f1d7ed96e6c8", |
| | | "src\\service\\grainService.js": "99f05184d3fcdf5c4e54fce08500267b", |
| | | "src\\service\\mqttService.js": "78d18810234846a26b49161dc6f193af", |
| | | "src\\service\\nfcService.js": "45705bc6a95206927085f11e7208cac2", |
| | | "src\\service\\platService.js": "a38387366ed212029bb46c6d3a85f2e9", |
| | | "src\\service\\sqliteService.js": "f2f0864ae07d893789bfc1666b584410", |
| | | "src\\service\\uart485Service.js": "c62ad21c538095f950dffe12d6770aa0", |
| | | "src\\services.js": "b87698f1e9e03bcfac820956034b06fe", |
| | | "src\\ui.js": "e9adc3aac685e711427667fa7705be6f", |
| | | "src\\view\\appView.js": "3ada10f0136eb464c035aec809a6e600", |
| | | "src\\view\\config\\configView.js": "6e30bb6aa2a9f6e6187dc6d86d832901", |
| | | "src\\view\\config\\identityVerificationView.js": "aa8cdd417184b2bdcef1a6cbd49df487", |
| | | "src\\view\\config\\menu\\cloudCertView.js": "7c9181ccfa5b5e96a234f1f55307ccb9", |
| | | "src\\view\\config\\menu\\deviceInfo\\dataCapacityInfoView.js": "9b6d8db4b83758d778f84ac2a1a266c8", |
| | | "src\\view\\config\\menu\\deviceInfo\\systemInfoView.js": "9396136cd353b10bb9a56f9bda2315d5", |
| | | "src\\view\\config\\menu\\deviceInfoView.js": "b33452d2a4d7188c5d14c6f76b726e90", |
| | | "src\\view\\config\\menu\\dockingSetting.js": "13a156aa4889a7d032a6fa26605e85b8", |
| | | "src\\view\\config\\menu\\doorControlView.js": "ffd1d5bc1bb7c652bc678c52e9969fda", |
| | | "src\\view\\config\\menu\\factoryTestView.js": "9588321c8282257e9707ebedb5920cda", |
| | | "src\\view\\config\\menu\\helpView.js": "00e750b2b637dc318f75e840d901fb5c", |
| | | "src\\view\\config\\menu\\localUser\\faceEnterView.js": "d993d07711e15cf5f0fee01a22753bfa", |
| | | "src\\view\\config\\menu\\localUser\\localUserAddView.js": "bf4646521acd0e14832eb732bc424e77", |
| | | "src\\view\\config\\menu\\localUserView.js": "c870b92aaaec5aff368e07e9f254e8aa", |
| | | "src\\view\\config\\menu\\networkSettingView.js": "325d70ed8ab1e170ffc1fa03fff637f5", |
| | | "src\\view\\config\\menu\\recordQuery\\recordQueryDetailView.js": "7077207b15bf1d7eae3a9a01dc68dc77", |
| | | "src\\view\\config\\menu\\recordQueryView.js": "67b573825af0639a4103bdc97b0f2c4a", |
| | | "src\\view\\config\\menu\\systemSetting\\displaySettingView.js": "c57f3b9faf85e048864c08d592481a72", |
| | | "src\\view\\config\\menu\\systemSetting\\faceRecognitionSettingView.js": "4d6b4e8b6c0f6e0ccbaaaa169e65b780", |
| | | "src\\view\\config\\menu\\systemSetting\\passLogSettingView.js": "d51958ac39b104846586b1ed6590414c", |
| | | "src\\view\\config\\menu\\systemSetting\\passwordManagementView.js": "98a6ca138cc1e2bc33ff6a3248e11263", |
| | | "src\\view\\config\\menu\\systemSetting\\passwordOpenDoorSettingView.js": "6e2ab3793e6c569097b702c339ef1602", |
| | | "src\\view\\config\\menu\\systemSetting\\swipeCardRecognitionSettingView.js": "871b483fbc3d778df95b803c130101e1", |
| | | "src\\view\\config\\menu\\systemSetting\\timeSettingView.js": "6950faa3a3296a573d048eb782c0e6ca", |
| | | "src\\view\\config\\menu\\systemSettingView.js": "ca3ac7b0e0390c7d542b62d569f57b24", |
| | | "src\\view\\config\\menu\\voiceBroadcastView.js": "a809af8acdae03f15c6e677bef6f20a1", |
| | | "src\\view\\config\\newPwdView.js": "32e3cfb0cc7f88361f1c69797cdb14b8", |
| | | "src\\view\\emergencyPwdView.js": "c6413bc04d38d54e57f590ce44204bcb", |
| | | "src\\view\\i18n.js": "94f43798d35026189125bf2534d1bffd", |
| | | "src\\view\\idleView.js": "b95c100ae4b2757ea2b0844a3df35c9e", |
| | | "src\\view\\mainView.js": "ec96a69994b99ed36778338198f74765", |
| | | "src\\view\\pinyin\\dict.js": "e40764bfc6bab80119c584315c0c48b7", |
| | | "src\\view\\pinyin\\pinyin.js": "c0809d9d1ebe5937cb6831b2b70db439", |
| | | "src\\view\\pwdView.js": "226b8b83a13b82cc925519ae051f8b3f", |
| | | "src\\view\\topView.js": "c9d8a4e3bc362edb1a5007135323beea", |
| | | "src\\view\\viewUtils.js": "ceaaad4fb40024b448a66a03911a7279", |
| | | "src\\worker\\accessWorker.js": "1b1253b5a7fbb2e733be2a9b0714ecca", |
| | | "src\\worker\\httpWorker.js": "47ddc63bdd95ecf36f7eaaa5f409424c" |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | # vf105_v12_access_new Access Control Application Source Code |
| | | |
| | | This directory contains the JavaScript source code for the `vf105_v12_access_new` access control application. |
| | | |
| | | **Important Note:** |
| | | |
| | | The JavaScript source code in this project is identical to the one used in the `vf203_v12_access_new` project (located at `../../vf203_v12/vf203_v12_access_new`). |
| | | |
| | | The only difference between the two projects lies in the underlying native shared library (`.so`) files. The specific version of the `.so` files to be used is determined and configured by the `app.dxproj` project file. |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | # vf105_v12_access_new é¨ç¦åºç¨æºç |
| | | |
| | | æ¤ç®å½å
å« `vf105_v12_access_new` é¨ç¦åºç¨ç JavaScript æºç ã |
| | | |
| | | **éè¦è¯´æï¼** |
| | | |
| | | æ¬é¡¹ç®ç JavaScript æºç ä¸ `vf203_v12_access_new` 项ç®ï¼è·¯å¾ï¼`../../vf203_v12/vf203_v12_access_new`ï¼ä½¿ç¨çæ¯å®å
¨ç¸åçä¸å¥æºç ã |
| | | |
| | | 两个项ç®å¯ä¸çå·®å«å¨äºåºå±çåçå
±äº«åºï¼`.so`ï¼æä»¶ãå
·ä½ä½¿ç¨åªä¸ªçæ¬ç `.so` æä»¶ï¼æ¯éè¿ `app.dxproj` é¡¹ç®æä»¶æ¥åºååé
ç½®çã |
| | | |
| | | --- |
| | | |
| | | å½å项ç®å·²ä¿®æ¹æ¨¡ç»æä»¶-dxmodules/dxEventBus.jsï¼ä½¿äºä»¶æ»çº¿æ¯æå¤ä¸ªäºä»¶å¤ç彿°ï¼ |
| | | |
| | | 1. ä¿®æ¹ bus.on 彿° ï¼å°å个äºä»¶å¤ç彿°æ¹ä¸ºåå¨ä¸ºæ°ç»ï¼æ¯æå¤ä¸ªå¤ç彿° |
| | | 2. ä¿®æ¹ bus.fire 彿° ï¼æ§è¡æææ³¨åçäºä»¶å¤ç彿°ï¼èä¸ä»
ä»
æ¯æåä¸ä¸ª |
| | | 3. æ·»å é误å¤ç ï¼ç¡®ä¿ä¸ä¸ªäºä»¶å¤ç彿°åºéæ¶ä¸ä¼å½±åå
¶ä»å¤ç彿°çæ§è¡ |
| | | |
| | | --- |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | { |
| | | "name": "vf105_v12_access", |
| | | "model": "VF105_V12", |
| | | "components": [ |
| | | { |
| | | "component": "dxAlsa", |
| | | "version": "1.0.0" |
| | | }, |
| | | { |
| | | "component": "dxBase64", |
| | | "version": "1.0.0" |
| | | }, |
| | | { |
| | | "component": "dxCapturer", |
| | | "version": "1.0.2" |
| | | }, |
| | | { |
| | | "component": "dxCommon", |
| | | "version": "1.0.0" |
| | | }, |
| | | { |
| | | "component": "dxConfig", |
| | | "version": "2.0.0" |
| | | }, |
| | | { |
| | | "component": "dxCameraCalibration", |
| | | "version": "test" |
| | | }, |
| | | { |
| | | "component": "dxDriver", |
| | | "version": "1.1.0" |
| | | }, |
| | | { |
| | | "component": "dxEventBus", |
| | | "version": "2.0.0" |
| | | }, |
| | | { |
| | | "component": "dxEid", |
| | | "version": "1.0.0" |
| | | }, |
| | | { |
| | | "component": "dxFace", |
| | | "version": "1.1.8" |
| | | }, |
| | | { |
| | | "component": "dxGpio", |
| | | "version": "1.0.0" |
| | | }, |
| | | { |
| | | "component": "dxGpioKey", |
| | | "version": "1.0.0" |
| | | }, |
| | | { |
| | | "component": "dxHttp", |
| | | "version": "1.0.0" |
| | | }, |
| | | { |
| | | "component": "dxLogger", |
| | | "version": "2.0.0" |
| | | }, |
| | | { |
| | | "component": "dxMap", |
| | | "version": "1.0.0" |
| | | }, |
| | | { |
| | | "component": "dxMqtt", |
| | | "version": "1.0.1" |
| | | }, |
| | | { |
| | | "component": "dxNet", |
| | | "version": "1.0.0" |
| | | }, |
| | | { |
| | | "component": "dxNtp", |
| | | "version": "2.0.0" |
| | | }, |
| | | { |
| | | "component": "dxNfc", |
| | | "version": "1.0.0" |
| | | }, |
| | | { |
| | | "component": "dxOta", |
| | | "version": "1.0.0" |
| | | }, |
| | | { |
| | | "component": "dxPwm", |
| | | "version": "1.0.0" |
| | | }, |
| | | { |
| | | "component": "dxQrRule", |
| | | "version": "1.0.0" |
| | | }, |
| | | { |
| | | "component": "dxStd", |
| | | "version": "1.0.0" |
| | | }, |
| | | { |
| | | "component": "dxSqlite", |
| | | "version": "1.0.0" |
| | | }, |
| | | { |
| | | "component": "dxUi", |
| | | "version": "1.0.2" |
| | | }, |
| | | { |
| | | "component": "dxUart", |
| | | "version": "1.0.0" |
| | | }, |
| | | { |
| | | "component": "dxWorkerPool", |
| | | "version": "2.0.0" |
| | | }, |
| | | { |
| | | "component": "dxWatchdog", |
| | | "version": "1.0.0" |
| | | } |
| | | ], |
| | | "ignore": { |
| | | "folder": ".temp,.git", |
| | | "file": "md5s.json,md5snew.json" |
| | | }, |
| | | "version": "2.0.1.0" |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //build:20240524 |
| | | //ç¨äºç®åcameraCalibrationç»ä»¶ç使ç¨ï¼æcameraCalibrationå°è£
å¨è¿ä¸ªworkeréï¼ä½¿ç¨è
åªéè¦è®¢é
eventcenterçäºä»¶å°±å¯ä»¥çå¬cameraCalibration |
| | | import log from './dxLogger.js' |
| | | import cameraCalibration from './dxCameraCalibration.js' |
| | | import capturer from './dxCapturer.js' |
| | | import std from './dxStd.js' |
| | | import bus from './dxEventBus.js' |
| | | import dxMap from './dxMap.js' |
| | | import * as os from "os"; |
| | | const map = dxMap.get('default') |
| | | const options = map.get("__cameraCalibration__run_init") |
| | | |
| | | function run() { |
| | | cameraCalibration.init() |
| | | log.info('cameraCalibration start......') |
| | | let startTime = new Date().getTime() |
| | | let cnt = 0 |
| | | let timerId = std.setInterval(() => { |
| | | try { |
| | | let imageRgb = capturer.readImage(options.capturerRgbId) |
| | | let imageNir = capturer.readImage(options.capturerNirId) |
| | | let res = cameraCalibration.calibrationFromImage(imageRgb, imageNir, cnt) |
| | | if (res) { |
| | | if (cnt >= 1) { |
| | | log.info("两次æ 宿åï¼ç»ææ å®") |
| | | cameraCalibration.getMap(imageRgb, imageNir, cnt, "/app/path.txt") |
| | | bus.fire(cameraCalibration.RECEIVE_MSG, "success1") |
| | | capturer.destroyImage(imageRgb) |
| | | capturer.destroyImage(imageNir) |
| | | std.clearInterval(timerId) |
| | | } |
| | | log.info("第" + (cnt + 1) + "次æ 宿å") |
| | | bus.fire(cameraCalibration.RECEIVE_MSG, "success0") |
| | | cnt += 1 |
| | | log.info("å¼å§è¿è¡ç¬¬" + (cnt + 1) + "次æ å®") |
| | | } else { |
| | | log.error("第" + (cnt + 1) + "次æ å®å¤±è´¥ï¼éè¯ä¸") |
| | | } |
| | | capturer.destroyImage(imageRgb) |
| | | capturer.destroyImage(imageNir) |
| | | let endTime = new Date().getTime() |
| | | if (endTime - startTime > options.timeout * 1000) { |
| | | log.error('æ å®è¶
æ¶ï¼è¯·éæ°æ§è¡æ å®') |
| | | bus.fire(cameraCalibration.RECEIVE_MSG, "timeout") |
| | | std.clearInterval(timerId) |
| | | } |
| | | } catch (error) { |
| | | log.error(error, error.stack) |
| | | } |
| | | }, 10) |
| | | } |
| | | |
| | | try { |
| | | run() |
| | | } catch (error) { |
| | | log.error(error, error.stack) |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //build:20240524 |
| | | //ç¨äºç®åcapturerç»ä»¶ç使ç¨ï¼æcapturerå°è£
å¨è¿ä¸ªworkeréï¼ä½¿ç¨è
åªéè¦è®¢é
eventbusçäºä»¶å°±å¯ä»¥çå¬capturer |
| | | import log from './dxLogger.js' |
| | | import capturer from './dxCapturer.js' |
| | | import dxMap from './dxMap.js' |
| | | import std from './dxStd.js' |
| | | const map = dxMap.get('default') |
| | | const id = "{{id}}" |
| | | const options = map.get("__capturer__run_init" + id) |
| | | |
| | | function run() { |
| | | capturer.worker.beforeLoop(options) |
| | | log.info('capturer start......,id =', options.id) |
| | | std.setInterval (function() { |
| | | try { |
| | | capturer.worker.loop(options) |
| | | } catch (error) { |
| | | log.error(error) |
| | | } |
| | | },10) |
| | | } |
| | | |
| | | try { |
| | | run() |
| | | } catch (error) { |
| | | log.error(error) |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //build: 20240525 |
| | | //ä¾èµç»ä»¶:dxDriverï¼dxCommon |
| | | import { alsaClass } from './libvbar-m-dxalsa.so' |
| | | import dxCommon from './dxCommon.js' |
| | | const alsaObj = new alsaClass(); |
| | | const alsa = {} |
| | | |
| | | /** |
| | | * alsa åå§å |
| | | * @param {string} id 奿idï¼éå¿
å¡«ï¼è¥åå§åå¤ä¸ªå®ä¾éè¦ä¼ å
¥å¯ä¸idï¼ |
| | | * @param {number} volume é³éï¼éå¿
å¡« |
| | | * @param {number} periodSize 卿大å°ï¼éå¿
å¡« |
| | | * @param {number} bufferSize ç¼å大å°ï¼éå¿
å¡« |
| | | * @returns 奿id |
| | | */ |
| | | alsa.init = function (id, volume, periodSize, bufferSize) { |
| | | if (volume === undefined || volume === null) { |
| | | volume = 35 |
| | | } |
| | | if (periodSize === undefined || periodSize === null) { |
| | | periodSize = 512 |
| | | } |
| | | if (bufferSize === undefined || bufferSize === null) { |
| | | bufferSize = 2048 |
| | | } |
| | | let pointer = alsaObj.alsaInit(volume, periodSize, bufferSize) |
| | | if (!pointer) { |
| | | throw new Error("alsa.init: init failed") |
| | | } |
| | | return dxCommon.handleId("alsa", id, pointer) |
| | | } |
| | | |
| | | /** |
| | | * alsa åæ¶åå§å |
| | | * @param {string} id 奿idï¼éå¿
å¡«ï¼éä¿æåinitä¸çidä¸è´ï¼ |
| | | * @returns true/false |
| | | */ |
| | | alsa.deinit = function (id) { |
| | | let pointer = dxCommon.handleId("alsa", id) |
| | | return alsaObj.alsaDeinit(pointer) |
| | | } |
| | | |
| | | /** |
| | | * ææ¾é³ä¹æä»¶ |
| | | * @param {string} path wavæä»¶ç»å¯¹è·¯å¾ï¼è·¯å¾æ¯ä»¥'/app/code/' å¼å¤´ï¼é常æ¾å¨é¡¹ç®çresourceç®å½ä¸ï¼åsrcå级)ï¼å¿
å¡« |
| | | * @param {string} id 奿idï¼éå¿
å¡«ï¼éä¿æåinitä¸çidä¸è´ï¼ |
| | | * @returns true/false |
| | | */ |
| | | alsa.play = function (path, id) { |
| | | if (!path) { |
| | | throw new Error("alsa.play: 'path' parameter should not be null") |
| | | } |
| | | let pointer = dxCommon.handleId("alsa", id) |
| | | return alsaObj.alsaWav(pointer, path) |
| | | } |
| | | |
| | | /** |
| | | * TTSæå转è¯é³ |
| | | * @param {string} è¦ææ¾çé³é¢æåï¼å¿
å¡« |
| | | * @param {string} id 奿idï¼éå¿
å¡«ï¼éä¿æåinitä¸çidä¸è´ï¼ |
| | | * @returns true/false |
| | | */ |
| | | alsa.ttsPlay = function (str, id) { |
| | | if (!str) { |
| | | throw new Error("alsa.ttsPlay: 'str' parameter should not be null") |
| | | } |
| | | let pointer = dxCommon.handleId("alsa", id) |
| | | return alsaObj.alsaAudioPlayString(pointer, str) |
| | | } |
| | | |
| | | /** |
| | | * è·åé³é |
| | | * @param {string} id 奿idï¼éå¿
å¡«ï¼éä¿æåinitä¸çidä¸è´ï¼ |
| | | * @returns è¿åæ°åç±»åçé³éï¼ä¸ä¼è¶
åºé³éèå´ |
| | | */ |
| | | alsa.getVolume = function (id) { |
| | | let pointer = dxCommon.handleId("alsa", id) |
| | | return alsaObj.alsaGetVolume(pointer) |
| | | } |
| | | |
| | | /** |
| | | * 设置é³é 设置è¿å¤§æè¿å°ä¼ç¼ºççäºé³éèå´çæå¤§ææå°å¼ |
| | | * @param {number} volume é³éï¼å¿
å¡« |
| | | * @param {string} id 奿idï¼éå¿
å¡«ï¼éä¿æåinitä¸çidä¸è´ï¼ |
| | | * @returns true/false |
| | | */ |
| | | alsa.setVolume = function (volume, id) { |
| | | let pointer = dxCommon.handleId("alsa", id) |
| | | return alsaObj.alsaSetVolume(pointer, volume) |
| | | } |
| | | /** |
| | | * ææ¾æµå¼é³é¢ |
| | | * @param {ArrayBuffer} é³é¢æµ ï¼å¿
å¡« |
| | | * @param {string} id 奿idï¼éå¿
å¡«ï¼éä¿æåinitä¸çidä¸è´ï¼ |
| | | * @returns true/false |
| | | */ |
| | | alsa.alsaWavData = function (buffer, id) { |
| | | if (!buffer) { |
| | | throw new Error("alsa.alsaWavData: 'buffer' parameter should not be null") |
| | | } |
| | | let pointer = dxCommon.handleId("alsa", id) |
| | | return alsaObj.alsaWavData(pointer, buffer) |
| | | } |
| | | |
| | | export default alsa; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //build:20240308 |
| | | //Base64ç¼è§£ç å·¥å
· |
| | | //ä¾èµç»ä»¶ï¼æ |
| | | //åºæ¬å
æ¬ä»¥ä¸å½æ°: |
| | | /** |
| | | * 1. encode(str): å符串转base64åç¬¦ä¸²ï¼æ¯å¦Base64.encode("aaçå¥åº·aab")å¾å°YWHnmoTlgaXlurdhYWI= |
| | | * 2. decode(b64): base64å符串转åå符串 |
| | | * 3. fromUint8Array(arr): byteæ°ç»è½¬base64å符串 |
| | | * 4. toUnit8Array(b64):base64å符串转byteæ°ç» |
| | | * 5. fromHexString(hex):16è¿å¶å符串ï¼å°åï¼æ ç©ºæ ¼ï¼è½¬base64å符串 |
| | | * 6. toHexString(b64):base64å符串转16è¿å¶å符串ï¼å°åï¼æ ç©ºæ ¼ |
| | | */ |
| | | /** |
| | | * base64.ts |
| | | * |
| | | * Licensed under the BSD 3-Clause License. |
| | | * http://opensource.org/licenses/BSD-3-Clause |
| | | * |
| | | * References: |
| | | * http://en.wikipedia.org/wiki/Base64 |
| | | * |
| | | * @author Dan Kogai (https://github.com/dankogai) |
| | | */ |
| | | let version = '3.7.7'; |
| | | /** |
| | | * @deprecated use lowercase `version`. |
| | | */ |
| | | let VERSION = version; |
| | | let _hasBuffer = typeof Buffer === 'function'; |
| | | let _TD = typeof TextDecoder === 'function' ? new TextDecoder() : undefined; |
| | | let _TE = typeof TextEncoder === 'function' ? new TextEncoder() : undefined; |
| | | let b64ch = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; |
| | | let b64chs = Array.prototype.slice.call(b64ch); |
| | | let b64tab = (function (a) { |
| | | let tab = {}; |
| | | a.forEach(function (c, i) { return tab[c] = i; }); |
| | | return tab; |
| | | })(b64chs); |
| | | let b64re = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/; |
| | | let _fromCC = String.fromCharCode.bind(String); |
| | | let _U8Afrom = typeof Uint8Array.from === 'function' |
| | | ? Uint8Array.from.bind(Uint8Array) |
| | | : function (it) { return new Uint8Array(Array.prototype.slice.call(it, 0)); }; |
| | | let _mkUriSafe = function (src) { |
| | | return src |
| | | .replace(/=/g, '').replace(/[+\/]/g, function (m0) { return m0 == '+' ? '-' : '_'; }); |
| | | }; |
| | | let _tidyB64 = function (s) { return s.replace(/[^A-Za-z0-9\+\/]/g, ''); }; |
| | | /** |
| | | * polyfill version of `btoa` |
| | | */ |
| | | let btoaPolyfill = function (bin) { |
| | | // console.log('polyfilled'); |
| | | let u32, c0, c1, c2, asc = ''; |
| | | let pad = bin.length % 3; |
| | | for (let i = 0; i < bin.length;) { |
| | | if ((c0 = bin.charCodeAt(i++)) > 255 || |
| | | (c1 = bin.charCodeAt(i++)) > 255 || |
| | | (c2 = bin.charCodeAt(i++)) > 255) |
| | | throw new TypeError('invalid character found'); |
| | | u32 = (c0 << 16) | (c1 << 8) | c2; |
| | | asc += b64chs[u32 >> 18 & 63] |
| | | + b64chs[u32 >> 12 & 63] |
| | | + b64chs[u32 >> 6 & 63] |
| | | + b64chs[u32 & 63]; |
| | | } |
| | | return pad ? asc.slice(0, pad - 3) + "===".substring(pad) : asc; |
| | | }; |
| | | /** |
| | | * does what `window.btoa` of web browsers do. |
| | | * @param {String} bin binary string |
| | | * @returns {string} Base64-encoded string |
| | | */ |
| | | let _btoa = typeof btoa === 'function' ? function (bin) { return btoa(bin); } |
| | | : _hasBuffer ? function (bin) { return Buffer.from(bin, 'binary').toString('base64'); } |
| | | : btoaPolyfill; |
| | | let _fromUint8Array = _hasBuffer |
| | | ? function (u8a) { return Buffer.from(u8a).toString('base64'); } |
| | | : function (u8a) { |
| | | // cf. https://stackoverflow.com/questions/12710001/how-to-convert-uint8-array-to-base64-encoded-string/12713326#12713326 |
| | | let maxargs = 0x1000; |
| | | let strs = []; |
| | | for (let i = 0, l = u8a.length; i < l; i += maxargs) { |
| | | strs.push(_fromCC.apply(null, u8a.subarray(i, i + maxargs))); |
| | | } |
| | | return _btoa(strs.join('')); |
| | | }; |
| | | /** |
| | | * converts a Uint8Array to a Base64 string. |
| | | * @param {boolean} [urlsafe] URL-and-filename-safe a la RFC4648 §5 |
| | | * @returns {string} Base64 string |
| | | */ |
| | | let fromUint8Array = function (u8a, urlsafe) { |
| | | if (urlsafe === void 0) { urlsafe = false; } |
| | | return urlsafe ? _mkUriSafe(_fromUint8Array(u8a)) : _fromUint8Array(u8a); |
| | | }; |
| | | let fromHexString = function (hexString) { |
| | | let byteString = hexString.match(/.{1,2}/g); |
| | | let byteArray = byteString.map(function (byte) { |
| | | return parseInt(byte, 16); |
| | | }); |
| | | let buffer = new Uint8Array(byteArray); |
| | | return fromUint8Array(buffer) |
| | | } |
| | | // This trick is found broken https://github.com/dankogai/js-base64/issues/130 |
| | | // const utob = (src: string) => unescape(encodeURIComponent(src)); |
| | | // reverting good old fationed regexp |
| | | let cb_utob = function (c) { |
| | | if (c.length < 2) { |
| | | let cc = c.charCodeAt(0); |
| | | return cc < 0x80 ? c |
| | | : cc < 0x800 ? (_fromCC(0xc0 | (cc >>> 6)) |
| | | + _fromCC(0x80 | (cc & 0x3f))) |
| | | : (_fromCC(0xe0 | ((cc >>> 12) & 0x0f)) |
| | | + _fromCC(0x80 | ((cc >>> 6) & 0x3f)) |
| | | + _fromCC(0x80 | (cc & 0x3f))); |
| | | } |
| | | else { |
| | | let cc = 0x10000 |
| | | + (c.charCodeAt(0) - 0xD800) * 0x400 |
| | | + (c.charCodeAt(1) - 0xDC00); |
| | | return (_fromCC(0xf0 | ((cc >>> 18) & 0x07)) |
| | | + _fromCC(0x80 | ((cc >>> 12) & 0x3f)) |
| | | + _fromCC(0x80 | ((cc >>> 6) & 0x3f)) |
| | | + _fromCC(0x80 | (cc & 0x3f))); |
| | | } |
| | | }; |
| | | let re_utob = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g; |
| | | /** |
| | | * @deprecated should have been internal use only. |
| | | * @param {string} src UTF-8 string |
| | | * @returns {string} UTF-16 string |
| | | */ |
| | | let utob = function (u) { return u.replace(re_utob, cb_utob); }; |
| | | // |
| | | let _encode = _hasBuffer |
| | | ? function (s) { return Buffer.from(s, 'utf8').toString('base64'); } |
| | | : _TE |
| | | ? function (s) { return _fromUint8Array(_TE.encode(s)); } |
| | | : function (s) { return _btoa(utob(s)); }; |
| | | /** |
| | | * converts a UTF-8-encoded string to a Base64 string. |
| | | * @param {boolean} [urlsafe] if `true` make the result URL-safe |
| | | * @returns {string} Base64 string |
| | | */ |
| | | let encode = function (src, urlsafe) { |
| | | if (urlsafe === void 0) { urlsafe = false; } |
| | | return urlsafe |
| | | ? _mkUriSafe(_encode(src)) |
| | | : _encode(src); |
| | | }; |
| | | /** |
| | | * converts a UTF-8-encoded string to URL-safe Base64 RFC4648 §5. |
| | | * @returns {string} Base64 string |
| | | */ |
| | | let encodeURI = function (src) { return encode(src, true); }; |
| | | // This trick is found broken https://github.com/dankogai/js-base64/issues/130 |
| | | // const btou = (src: string) => decodeURIComponent(escape(src)); |
| | | // reverting good old fationed regexp |
| | | let re_btou = /[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g; |
| | | let cb_btou = function (cccc) { |
| | | switch (cccc.length) { |
| | | case 4: |
| | | let cp = ((0x07 & cccc.charCodeAt(0)) << 18) |
| | | | ((0x3f & cccc.charCodeAt(1)) << 12) |
| | | | ((0x3f & cccc.charCodeAt(2)) << 6) |
| | | | (0x3f & cccc.charCodeAt(3)), offset = cp - 0x10000; |
| | | return (_fromCC((offset >>> 10) + 0xD800) |
| | | + _fromCC((offset & 0x3FF) + 0xDC00)); |
| | | case 3: |
| | | return _fromCC(((0x0f & cccc.charCodeAt(0)) << 12) |
| | | | ((0x3f & cccc.charCodeAt(1)) << 6) |
| | | | (0x3f & cccc.charCodeAt(2))); |
| | | default: |
| | | return _fromCC(((0x1f & cccc.charCodeAt(0)) << 6) |
| | | | (0x3f & cccc.charCodeAt(1))); |
| | | } |
| | | }; |
| | | /** |
| | | * @deprecated should have been internal use only. |
| | | * @param {string} src UTF-16 string |
| | | * @returns {string} UTF-8 string |
| | | */ |
| | | let btou = function (b) { return b.replace(re_btou, cb_btou); }; |
| | | /** |
| | | * polyfill version of `atob` |
| | | */ |
| | | let atobPolyfill = function (asc) { |
| | | // console.log('polyfilled'); |
| | | asc = asc.replace(/\s+/g, ''); |
| | | if (!b64re.test(asc)) |
| | | throw new TypeError('malformed base64.'); |
| | | asc += '=='.slice(2 - (asc.length & 3)); |
| | | let u24, bin = '', r1, r2; |
| | | for (let i = 0; i < asc.length;) { |
| | | u24 = b64tab[asc.charAt(i++)] << 18 |
| | | | b64tab[asc.charAt(i++)] << 12 |
| | | | (r1 = b64tab[asc.charAt(i++)]) << 6 |
| | | | (r2 = b64tab[asc.charAt(i++)]); |
| | | bin += r1 === 64 ? _fromCC(u24 >> 16 & 255) |
| | | : r2 === 64 ? _fromCC(u24 >> 16 & 255, u24 >> 8 & 255) |
| | | : _fromCC(u24 >> 16 & 255, u24 >> 8 & 255, u24 & 255); |
| | | } |
| | | return bin; |
| | | }; |
| | | /** |
| | | * does what `window.atob` of web browsers do. |
| | | * @param {String} asc Base64-encoded string |
| | | * @returns {string} binary string |
| | | */ |
| | | let _atob = typeof atob === 'function' ? function (asc) { return atob(_tidyB64(asc)); } |
| | | : _hasBuffer ? function (asc) { return Buffer.from(asc, 'base64').toString('binary'); } |
| | | : atobPolyfill; |
| | | // |
| | | let _toUint8Array = _hasBuffer |
| | | ? function (a) { return _U8Afrom(Buffer.from(a, 'base64')); } |
| | | : function (a) { return _U8Afrom(_atob(a).split('').map(function (c) { return c.charCodeAt(0); })); }; |
| | | /** |
| | | * converts a Base64 string to a Uint8Array. |
| | | */ |
| | | let toUint8Array = function (a) { return _toUint8Array(_unURI(a)); }; |
| | | // |
| | | let toHexString = function (a) { |
| | | let uint8 = toUint8Array(a) |
| | | return Array.from(uint8) |
| | | .map((i) => i.toString(16).padStart(2, '0')) |
| | | .join('');; |
| | | } |
| | | let _decode = _hasBuffer |
| | | ? function (a) { return Buffer.from(a, 'base64').toString('utf8'); } |
| | | : _TD |
| | | ? function (a) { return _TD.decode(_toUint8Array(a)); } |
| | | : function (a) { return btou(_atob(a)); }; |
| | | let _unURI = function (a) { return _tidyB64(a.replace(/[-_]/g, function (m0) { return m0 == '-' ? '+' : '/'; })); }; |
| | | /** |
| | | * converts a Base64 string to a UTF-8 string. |
| | | * @param {String} src Base64 string. Both normal and URL-safe are supported |
| | | * @returns {string} UTF-8 string |
| | | */ |
| | | let decode = function (src) { return _decode(_unURI(src)); }; |
| | | /** |
| | | * check if a value is a valid Base64 string |
| | | * @param {String} src a value to check |
| | | */ |
| | | let isValid = function (src) { |
| | | if (typeof src !== 'string') |
| | | return false; |
| | | let s = src.replace(/\s+/g, '').replace(/={0,2}$/, ''); |
| | | return !/[^\s0-9a-zA-Z\+/]/.test(s) || !/[^\s0-9a-zA-Z\-_]/.test(s); |
| | | }; |
| | | // |
| | | let _noEnum = function (v) { |
| | | return { |
| | | value: v, enumerable: false, writable: true, configurable: true |
| | | }; |
| | | }; |
| | | /** |
| | | * extend String.prototype with relevant methods |
| | | */ |
| | | let extendString = function () { |
| | | let _add = function (name, body) { return Object.defineProperty(String.prototype, name, _noEnum(body)); }; |
| | | _add('fromBase64', function () { return decode(this); }); |
| | | _add('toBase64', function (urlsafe) { return encode(this, urlsafe); }); |
| | | _add('toBase64URI', function () { return encode(this, true); }); |
| | | _add('toBase64URL', function () { return encode(this, true); }); |
| | | _add('toUint8Array', function () { return toUint8Array(this); }); |
| | | }; |
| | | /** |
| | | * extend Uint8Array.prototype with relevant methods |
| | | */ |
| | | let extendUint8Array = function () { |
| | | let _add = function (name, body) { return Object.defineProperty(Uint8Array.prototype, name, _noEnum(body)); }; |
| | | _add('toBase64', function (urlsafe) { return fromUint8Array(this, urlsafe); }); |
| | | _add('toBase64URI', function () { return fromUint8Array(this, true); }); |
| | | _add('toBase64URL', function () { return fromUint8Array(this, true); }); |
| | | }; |
| | | /** |
| | | * extend Builtin prototypes with relevant methods |
| | | */ |
| | | let extendBuiltins = function () { |
| | | extendString(); |
| | | extendUint8Array(); |
| | | }; |
| | | let gBase64 = { |
| | | version: version, |
| | | VERSION: VERSION, |
| | | atob: _atob, |
| | | atobPolyfill: atobPolyfill, |
| | | btoa: _btoa, |
| | | btoaPolyfill: btoaPolyfill, |
| | | fromBase64: decode, |
| | | toBase64: encode, |
| | | encode: encode, |
| | | encodeURI: encodeURI, |
| | | encodeURL: encodeURI, |
| | | utob: utob, |
| | | btou: btou, |
| | | decode: decode, |
| | | isValid: isValid, |
| | | fromUint8Array: fromUint8Array, |
| | | toUint8Array: toUint8Array, |
| | | fromHexString: fromHexString, |
| | | toHexString: toHexString, |
| | | extendString: extendString, |
| | | extendUint8Array: extendUint8Array, |
| | | extendBuiltins: extendBuiltins |
| | | }; |
| | | export default gBase64 |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //build: 20240528 |
| | | //ä¾èµç»ä»¶:dxDriverï¼dxLoggerï¼dxMapï¼dxCapturer |
| | | import { calibrationClass } from './libvbar-m-dxcapturer_calibration.so' |
| | | import capturer from '../dxmodules/dxCapturer.js' |
| | | import * as os from "os"; |
| | | import dxMap from './dxMap.js' |
| | | import log from './dxLogger.js' |
| | | import bus from './dxEventBus.js' |
| | | const calibrationObj = new calibrationClass(); |
| | | const map = dxMap.get('default') |
| | | const calibration = {} |
| | | let cnt = 0, startTime = 0; |
| | | |
| | | /** |
| | | * calibration åå§å |
| | | * @returns true/false |
| | | */ |
| | | calibration.init = function () { |
| | | return calibrationObj.init(); |
| | | } |
| | | |
| | | /** |
| | | * calibration 鿝 |
| | | * @returns true/false |
| | | */ |
| | | calibration.deinit = function () { |
| | | return calibrationObj.deinit(); |
| | | } |
| | | |
| | | /** |
| | | * è¯å«æ å®ï¼æ¿æ¹æ ¼çº¸å¯¹åå±å¹ä¸çæ¹æ¡ï¼ |
| | | * @param {number} imageRgb imageæéï¼å¿
å¡« |
| | | * @param {number} imageNir imageæéï¼å¿
å¡« |
| | | * @param {number} cnt æ 宿¬¡æ°ï¼å¿
å¡«ï¼0ï¼ç¬¬ä¸æ¬¡æ å®,1ï¼ç¬¬äºæ¬¡æ å®ï¼ |
| | | * @returns true/false |
| | | */ |
| | | calibration.calibrationFromImage = function (imageRgb, imageNir, cnt) { |
| | | return calibrationObj.calibrationFromImage(imageRgb, imageNir, cnt); |
| | | } |
| | | |
| | | /** |
| | | * 计ç®å¹¶å卿 å®ç»æ |
| | | * @param {number} imageNir imageæéï¼å¿
å¡« |
| | | * @param {string} path åå¨è·¯å¾ï¼å¿
å¡« |
| | | * @returns true/false |
| | | */ |
| | | calibration.getMap = function (imageRgb, imageNir,cnt, path) { |
| | | return calibrationObj.getMap(imageRgb, imageNir,cnt, path); |
| | | } |
| | | |
| | | /** |
| | | * è·åç»å¶æ å®uiæ¡ä¿¡æ¯ |
| | | * @param {number} cnt æ 宿¬¡æ°ï¼å¿
å¡«ï¼0ï¼ç¬¬ä¸æ¬¡æ å®,1ï¼ç¬¬äºæ¬¡æ å®ï¼ |
| | | * @param {number} type 横ç«å±ï¼å¿
å¡«ï¼1ï¼æ¨ªå±ï¼0ï¼ç«å±ï¼ |
| | | * @returns {x:æ¨ªåæ ,y:çºµåæ ,w:宽,h:é«} |
| | | */ |
| | | calibration.getBox = function (cnt, type) { |
| | | let box = calibrationObj.getBox(cnt); |
| | | let coordinate = { |
| | | x: type == 1 ? box.x : box.y, |
| | | y: type == 1 ? box.y : box.x, |
| | | w: type == 1 ? box.w : box.h, |
| | | h: type == 1 ? box.h : box.w |
| | | } |
| | | return coordinate; |
| | | } |
| | | |
| | | calibration.RECEIVE_MSG = '__calibration__MsgReceive' |
| | | |
| | | /** |
| | | * ç®åcameraCalibrationç»ä»¶ç使ç¨ï¼æ é轮询å»è·åæ°æ®ï¼æ°æ®ä¼éè¿eventbusåéåºå» |
| | | * ç±äºè¯å«æ å®calibrationFromImageæ¯é»å¡çº¿ç¨çæ¹æ³ï¼æä»¥å¿
é¡»æ°å¼ä¸ä¸ªçº¿ç¨æ§è¡ï¼å¦åä¼é»å¡å
¶ä»çº¿ç¨ |
| | | * run åªä¼æ§è¡ä¸æ¬¡ |
| | | * @param {object} options é
ç½®åæ° |
| | | * @param {string} options.capturerRgbId å¿
å¡«ï¼rgbåå¾å¥æid |
| | | * @param {string} options.capturerNirId å¿
å¡«ï¼niråå¾å¥æid |
| | | * @param {number} options.timeout åä½ç§ï¼éå¿
å¡«ï¼ç¼ºç20ç§ï¼ï¼æ å®çè¶
æ¶æ¶é´ï¼å¨æ¤æé´å
æªå®æä¸¤æ¬¡æ å®ï¼åæ å®å¤±è´¥ç»æçº¿ç¨ï¼å¦ééæ°æ å®ï¼å¿
须忬¡æ§è¡runæ¹æ³ |
| | | */ |
| | | calibration.run = function (options) { |
| | | if (options === undefined || options.length === 0) { |
| | | throw new Error("dxCameraCalibration.run:'options' parameter should not be null or empty") |
| | | } |
| | | if (options.capturerRgbId === undefined || options.capturerRgbId === null || options.capturerRgbId.length <= 0) { |
| | | throw new Error("dxCameraCalibration.run:'capturerRgbId' should not be null or empty") |
| | | } |
| | | if (options.capturerNirId === undefined || options.capturerNirId === null || options.capturerNirId.length <= 0) { |
| | | throw new Error("dxCameraCalibration.run:'capturerNirId' should not be null or empty") |
| | | } |
| | | options.timeout = options.timeout ? options.timeout : 20 |
| | | try { |
| | | if(startTime == null || startTime == 0){ |
| | | startTime = new Date().getTime() |
| | | } |
| | | let imageRgb = capturer.readImage(options.capturerRgbId) |
| | | let imageNir = capturer.readImage(options.capturerNirId) |
| | | let res = this.calibrationFromImage(imageRgb, imageNir, cnt) |
| | | if (res) { |
| | | if (cnt >= 1) { |
| | | log.info("两次æ 宿åï¼ç»ææ å®") |
| | | let path = "/etc/.cameraCalibration" |
| | | if(options.path && options.path.length > 0){ |
| | | path = options.path |
| | | } |
| | | this.getMap(imageRgb, imageNir, cnt, path) |
| | | bus.fire(this.RECEIVE_MSG, "success1") |
| | | capturer.destroyImage(imageRgb) |
| | | capturer.destroyImage(imageNir) |
| | | cnt = 0; |
| | | startTime = 0; |
| | | return "success1" |
| | | } |
| | | log.info("第" + (cnt + 1) + "次æ 宿å") |
| | | bus.fire(this.RECEIVE_MSG, "success0") |
| | | cnt += 1 |
| | | log.info("å¼å§è¿è¡ç¬¬" + (cnt + 1) + "次æ å®") |
| | | return "success0" |
| | | } else { |
| | | log.error("第" + (cnt + 1) + "次æ å®å¤±è´¥ï¼éè¯ä¸") |
| | | } |
| | | capturer.destroyImage(imageRgb) |
| | | capturer.destroyImage(imageNir) |
| | | let endTime = new Date().getTime() |
| | | if (endTime - startTime > options.timeout * 1000) { |
| | | log.error('æ å®è¶
æ¶ï¼è¯·éæ°æ§è¡æ å®') |
| | | bus.fire(this.RECEIVE_MSG, "timeout") |
| | | cnt = 0 |
| | | startTime = 0; |
| | | return "timeout" |
| | | } |
| | | return "failed" |
| | | } catch (error) { |
| | | log.error(error) |
| | | } |
| | | } |
| | | |
| | | export default calibration; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //build: 20240524 |
| | | //æå头åå¾ç»ä»¶ï¼ä¸»è¦ç¨äºè·åäºç»´ç å¾åç¶åå©ç¨dxDecoderç»ä»¶æ¥è§£æäºç»´ç å¾å |
| | | //ä¾èµç»ä»¶ï¼dxDriverï¼dxCommonï¼dxStdï¼dxMap |
| | | 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ï¼DW200ç¼ºçæ¯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ï¼éå¿
å¡«ï¼éä¿æåinitä¸ç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ï¼éå¿
å¡«ï¼éä¿æåinitä¸ç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ï¼éå¿
å¡«ï¼éä¿æåinitä¸çidä¸è´ï¼ |
| | | * @returns true/false |
| | | */ |
| | | capturer.close = function (id) { |
| | | let pointer = dxCommon.handleId("capturer", id) |
| | | return capturerObj.close(pointer) |
| | | } |
| | | |
| | | /** |
| | | * è·åå¾åæ°æ®ï¼è½®è¯¢å¯è°ç¨æ¤æ¥å£ï¼ç±»ä¼¼capturer.msgReceiveæ¹æ³çè·åï¼è¥ä½¿ç¨è¿ä¸ªæ¹æ³ï¼å¿
é¡»æå¨éæ¯è·åçimageæé |
| | | * @param {string} id 奿idï¼éå¿
å¡«ï¼éä¿æåinitä¸ç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ï¼éå¿
å¡«ï¼éä¿æåinitä¸ç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 å¾çæä»¶è½¬image |
| | | * @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) |
| | | } |
| | | |
| | | /** |
| | | * å¾çæ°æ®è½¬image |
| | | * @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ï¼éå¿
å¡«ï¼éä¿æåinitä¸çidä¸è´ï¼ |
| | | * @returns true/false |
| | | */ |
| | | capturer.msgIsEmpty = function (id) { |
| | | let pointer = dxCommon.handleId("capturer", id) |
| | | return capturerObj.msgIsEmpty(pointer) |
| | | } |
| | | |
| | | /** |
| | | * ä»captureræ¶æ¯éåä¸è¯»åæ°æ® |
| | | * @param {string} id 奿idï¼éå¿
å¡«ï¼éä¿æåinitä¸çidä¸è´ï¼ |
| | | * @returns imageæé |
| | | */ |
| | | capturer.msgReceive = function (id) { |
| | | let pointer = dxCommon.handleId("capturer", id) |
| | | return capturerObj.msgReceive(pointer) |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢captureræ¶æ¯éåå¤§å° |
| | | * @param {string} id 奿idï¼éå¿
å¡«ï¼éä¿æåinitä¸çidä¸è´ï¼ |
| | | * @returns size |
| | | */ |
| | | capturer.msgQueueSize = function (id) { |
| | | let pointer = dxCommon.handleId("capturer", id) |
| | | return capturerObj.msgQueueSize(pointer) |
| | | } |
| | | |
| | | capturer.RECEIVE_MSG = '__capturer__MsgReceive' |
| | | |
| | | /** |
| | | * ç¨äºç®åcapturerç»ä»¶ç使ç¨ï¼æcapturerå°è£
å¨è¿ä¸ªworkeréï¼ä½¿ç¨è
åªéè¦è®¢é
eventbusçäºä»¶å°±å¯ä»¥çå¬capturer |
| | | * @param {object} options capturerç»ä»¶åæ°ï¼åècapturer.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 = { |
| | | //å¨while循ç¯å |
| | | beforeLoop: function (options) { |
| | | capturer.init(options, options.id) |
| | | capturer.registerCallback(options.id) |
| | | }, |
| | | //å¨while循ç¯é |
| | | 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; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //build: 20240617 |
| | | // ç³»ç»çä¸äºåºæ¬æä½ãè¿æä¸äºå¸¸ç¨çå·¥å
·å½æ°ï¼åºæ¬ä¸æ¯ä¸ªé¡¹ç®é½éè¦ä¾èµè¿ä¸ªç»ä»¶ï¼å¦å¤dxLoggerä¹ä¾èµè¿ä¸ªç»ä»¶ |
| | | // ä¾èµç»ä»¶ï¼dxDriverï¼dxMap |
| | | import { commonClass } from './libvbar-m-dxcommon.so' |
| | | import dxMap from './dxMap.js' |
| | | import * as std from 'std'; |
| | | import * as os from "os" |
| | | |
| | | const commonObj = new commonClass(); |
| | | |
| | | const common = {} |
| | | /** |
| | | * è·åç³»ç»å¯å¨çè¿è¡æ¶é´(å使¯ç§) |
| | | * @returns |
| | | */ |
| | | common.getUptime = function () { |
| | | return commonObj.getUptime(); |
| | | } |
| | | |
| | | /** |
| | | * è·åç³»ç»çæ»å
å(å使¯åè) |
| | | * @returns |
| | | */ |
| | | common.getTotalmem = function () { |
| | | return commonObj.getTotalmem(); |
| | | } |
| | | |
| | | /** |
| | | * è·åç³»ç»å©ä½å
å(å使¯åè) |
| | | * @returns |
| | | */ |
| | | common.getFreemem = function () { |
| | | return commonObj.getFreemem(); |
| | | } |
| | | |
| | | /** |
| | | * Deprcated, Please use `common.logMemory` instead. |
| | | */ |
| | | common.logMem = function (logger, interval = 10) { |
| | | if (logger) { |
| | | logger.debug("Deprcated, Please use `common.logMemory` instead.") |
| | | } |
| | | } |
| | | /** |
| | | * Logs the current memory usage at regular intervals for debugging and monitoring purposes. |
| | | * @param {object} logger The dxLogger module object. |
| | | * @param {number} interval The logging interval in seconds, defaulting to 10 seconds. |
| | | */ |
| | | common.logMemory = function (logger, interval = 10) { |
| | | if (!logger) return; |
| | | |
| | | let first = new Date().getTime(); |
| | | let min = common.getFreemem() / 1024; |
| | | let max = min; |
| | | const _logmemory = () => { |
| | | try { |
| | | const now = new Date().getTime(); |
| | | const pass = (now - first) / 1000; |
| | | const free = common.getFreemem() / 1024; |
| | | |
| | | min = Math.min(min, free); |
| | | max = Math.max(max, free); |
| | | |
| | | // Format time |
| | | let passStr; |
| | | if (pass > 1700000000) { |
| | | first = now; |
| | | passStr = 'time synced, 0s'; |
| | | } else if (pass >= 3600) { |
| | | const hours = Math.floor(pass / 3600); |
| | | const minutes = Math.floor((pass % 3600) / 60); |
| | | const seconds = Math.floor(pass % 60); |
| | | passStr = `${hours}h ${minutes}m ${seconds}s`; |
| | | } else if (pass >= 60) { |
| | | const minutes = Math.floor(pass / 60); |
| | | const seconds = Math.floor(pass % 60); |
| | | passStr = `${minutes}m ${seconds}s`; |
| | | } else { |
| | | passStr = `${Math.floor(pass)}s`; |
| | | } |
| | | const log = `------ ${passStr} passed, free memory (k): ${free}, min free memory (k): ${min}, max free memory (k): ${max} ------`; |
| | | logger.info(log); |
| | | } catch (err) { |
| | | logger.error('Error in logMemory:', err); |
| | | } finally { |
| | | os.setTimeout(_logmemory, interval * 1000); |
| | | } |
| | | }; |
| | | |
| | | os.setTimeout(_logmemory, interval * 1000); |
| | | }; |
| | | |
| | | /** |
| | | * The principle of converting asynchronous to synchronous is as follows: |
| | | * the `request` function periodically checks a designated variable in memory for a value. |
| | | * If the value is found within the timeout period, the result is returned; otherwise, |
| | | * it is considered a timeout. The `response` function is responsible for storing the result |
| | | * in the designated variable once the asynchronous request is completed. |
| | | */ |
| | | common.sync = { |
| | | /** |
| | | * Block and wait for data |
| | | * Usage: |
| | | common.sync.request(topic, 200) |
| | | .then((data) => { |
| | | log.info("Received data:", data); |
| | | }) |
| | | .catch((err) => { |
| | | log.error("Request failed:", err.message); |
| | | }); |
| | | * @param {string} topic The unique identifier for each request |
| | | * @param {int} timeout waitting timeout(microsecond)ï¼default is 200 ms |
| | | * @returns |
| | | */ |
| | | request: function (topic, timeout = 200) { |
| | | return new Promise((resolve, reject) => { |
| | | let map = dxMap.get("SYNC"); |
| | | let startTime = Date.now(); |
| | | |
| | | const checkData = () => { |
| | | let data = map.get(topic); |
| | | if (data) { |
| | | map.del(topic); //del data in map |
| | | resolve(data); //return data |
| | | } else if (Date.now() - startTime >= timeout) { |
| | | map.del(topic); // del data in map with timeout |
| | | reject(new Error(`Timeout exceeded for topic: ${topic}`)); |
| | | } else { |
| | | os.setTimeout(checkData, 10); //every 10 ms to check |
| | | } |
| | | }; |
| | | |
| | | os.setTimeout(checkData, 10); // first check |
| | | }); |
| | | }, |
| | | |
| | | /** |
| | | * notify data to requester |
| | | * @param {string} topic The unique identifier for each request |
| | | * @param {*} data |
| | | * @returns |
| | | */ |
| | | response: function (topic, data) { |
| | | let map = dxMap.get("SYNC"); |
| | | map.put(topic, data); // save data in map |
| | | } |
| | | }; |
| | | |
| | | /** |
| | | * è·åç³»ç»å¯ç¨ç£çæ»é(å使¯åè) |
| | | * @param {string} path ä¸åçç£çååºåç§°ï¼ä¸æ¯ç®å½åï¼ï¼éå¿
å¡«ï¼ç¼ºçæ¯'/' |
| | | */ |
| | | common.getTotaldisk = function (path) { |
| | | return commonObj.getTotaldisk(!path ? "/" : path); |
| | | } |
| | | |
| | | /** |
| | | * è·åç³»ç»ç£çå©ä½å¯ç¨é(å使¯åè) |
| | | * @param {string} path ä¸åçç£çååºåç§°ï¼ä¸æ¯ç®å½åï¼ï¼éå¿
å¡«ï¼ç¼ºçæ¯'/' |
| | | * @returns |
| | | */ |
| | | common.getFreedisk = function (path) { |
| | | return commonObj.getFreedisk(!path ? "/" : path); |
| | | } |
| | | |
| | | /** |
| | | * è·åCPU ID |
| | | * @param {number} len éå¿
å¡«ï¼ç¼ºçé¿åº¦æ¯33ä½é¿ |
| | | * @returns |
| | | */ |
| | | common.getCpuid = function () { |
| | | return commonObj.getCpuid(33); |
| | | } |
| | | |
| | | /** |
| | | * è·å设å¤uuidï¼åç¬¦ä¸²ï¼ |
| | | * @returns |
| | | */ |
| | | common.getUuid = function () { |
| | | return commonObj.getUuid(19); |
| | | } |
| | | |
| | | /** |
| | | * è·å设å¤å¯ä¸æ è¯ |
| | | * @returns |
| | | */ |
| | | common.getSn = function () { |
| | | let sn = std.loadFile('/etc/.sn') |
| | | if (sn) { |
| | | return sn |
| | | } else { |
| | | return commonObj.getUuid(19); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è·åéè¿uuid计ç®çmacå°åï¼è¿ä¸ªå¯ä»¥ç¨æ¥åå§åç½å¡çæ¶åç¨ |
| | | * @returns æ ¼å¼ç±»ä¼¼ï¼b2:a1:63:3f:99:b6 |
| | | */ |
| | | common.getUuid2mac = function () { |
| | | return commonObj.getUuid2mac(19); |
| | | } |
| | | |
| | | /** |
| | | * è·åcpuå ç¨çï¼ä¸å¤§äº100çæ°åï¼ |
| | | * @returns |
| | | */ |
| | | common.getFreecpu = function () { |
| | | return commonObj.getFreecpu(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * RSA è§£å¯ ï¼ç§é¥å å¯å
¬é¥è§£å¯ï¼ |
| | | * æ¯å¦å
¬é¥æ¯ |
| | | * @param {ArrayBuffer} data è¦è§£å¯çæ°æ®ï¼å¿
å¡« |
| | | * @param {string} publicKey å
¬é¥ï¼å¿
å¡« |
| | | * @returns |
| | | */ |
| | | common.arrayBufferRsaDecrypt = function (data, publicKey) { |
| | | if (data === undefined || data === null) { |
| | | throw new Error("dxCommon.arrayBufferRsaDecrypt:'data' parameter should not be null or empty") |
| | | } |
| | | if (publicKey === undefined || publicKey === null || publicKey.length < 1) { |
| | | throw new Error("dxCommon.arrayBufferRsaDecrypt:'publicKey' parameter should not be null or empty") |
| | | } |
| | | return commonObj.arrayBufferRsaDecrypt(data, publicKey) |
| | | } |
| | | |
| | | /** |
| | | * @brief Stirng aes å å¯ |
| | | */ |
| | | common.aes128EcbEncrypt = function (input, key) { |
| | | return commonObj.aes128EcbEncrypt(input, key) |
| | | } |
| | | /** |
| | | * @brief Stirng aes è§£å¯ |
| | | */ |
| | | common.aes128EcbDecrypt = function (input, key) { |
| | | return commonObj.aes128EcbDecrypt(input, key) |
| | | } |
| | | |
| | | /** |
| | | * arraybuffer ecb 128bit Pkcs5Padding aes å å¯ |
| | | * @param {ArrayBuffer} input ææ |
| | | * @param {ArrayBuffer} key å¯é¥ |
| | | * @returns ArrayBuffer 坿 |
| | | */ |
| | | common.aes128EcbPkcs5PaddingEncode = function (input, key) { |
| | | return commonObj.aes128Pkcs7PaddingEncode(input, key) |
| | | } |
| | | |
| | | /** |
| | | * arraybuffer ecb 128bit Pkcs5Padding aes è§£å¯ |
| | | * |
| | | * @param {ArrayBuffer} input 坿 |
| | | * @param {ArrayBuffer} key å¯é¥ |
| | | * @returns ArrayBuffer ææ |
| | | */ |
| | | common.aesEcb128Pkcs5PaddingDecode = function (input, key) { |
| | | return commonObj.aes128Pkcs7PaddingDecode(input, key) |
| | | } |
| | | |
| | | /** |
| | | * aes ECB Pkcs5Padding 128 å å¯ |
| | | * 示ä¾ï¼common.aes128EcbPkcs5PaddingEncrypt("stamp=202008æ&tic", "1234567890123456") |
| | | * ç»æï¼ef7c3cff9df57b3bcb0951938c574f969e13ffdcc1eadad298ddbd1fb1a4d2f7 |
| | | * åè https://www.devglan.com/online-tools/aes-encryption-decryption |
| | | * @param {string} input æææ°æ® |
| | | * @param {string} key å¯é¥ 16åèå符串 |
| | | * @return 坿 16è¿å¶å符串 |
| | | */ |
| | | common.aes128EcbPkcs5PaddingEncrypt = function (input, key) { |
| | | let data = common.hexStringToArrayBuffer(common.strToUtf8Hex(input)) |
| | | key = common.hexStringToArrayBuffer(common.strToUtf8Hex(key)) |
| | | // å å¯ |
| | | let hex = common.arrayBufferToHexString(common.aes128EcbPkcs5PaddingEncode(data, key)) |
| | | return hex |
| | | } |
| | | /** |
| | | * aes ECB Pkcs5Padding 128 è§£å¯ |
| | | * @param {string} input 坿 16è¿å¶å符串 |
| | | * @param {string} key å¯é¥ 16åèå符串 |
| | | * @return ææ |
| | | */ |
| | | common.aes128EcbPkcs5PaddingDecrypt = function (input, key) { |
| | | key = common.hexStringToArrayBuffer(common.strToUtf8Hex(key)) |
| | | let res = common.aesEcb128Pkcs5PaddingDecode(common.hexStringToArrayBuffer(input), key) |
| | | return common.utf8HexToStr(common.arrayBufferToHexString(res)) |
| | | } |
| | | |
| | | /** |
| | | * æ§è¡æä½ç³»ç»çå½ä»¤ |
| | | * @param {*} cmd å½ä»¤ |
| | | * @returns |
| | | */ |
| | | common.system = function (cmd) { |
| | | return commonObj.system(cmd) |
| | | } |
| | | |
| | | /** |
| | | * æ§è¡æä½ç³»ç»çå½ä»¤ |
| | | * @param {*} cmd å½ä»¤ æä½ç³»ç»å¸¸ç¨æä»¤(linuxç»å¤§é¨åæä»¤é½æ¯æ)ï¼å¿
å¡« |
| | | * @returns |
| | | */ |
| | | common.systemBrief = function (cmd) { |
| | | return commonObj.systemBrief(cmd) |
| | | } |
| | | |
| | | /** |
| | | * æ§è¡æä½ç³»ç»çå½ä»¤å¹¶è¿åç»æ |
| | | * @param {*} cmd å½ä»¤ æä½ç³»ç»å¸¸ç¨æä»¤(linuxç»å¤§é¨åæä»¤é½æ¯æ)ï¼å¿
å¡« |
| | | * @param {*} resLen æ¥æ¶æ°æ®é¿åº¦ ææ¶åè¿åçæ°æ®å¾å¤§ï¼å¯ä»¥éè¿è¿ä¸ªå¼æ¥è¿ååºå®é¿åº¦çæ°æ®ï¼å¿
å¡« |
| | | * @returns |
| | | */ |
| | | common.systemWithRes = function (cmd, resLen) { |
| | | return commonObj.systemWithRes(cmd, resLen) |
| | | } |
| | | |
| | | /** |
| | | * æ§è¡æä½ç³»ç»çå½ä»¤é»å¡æ§è¡ |
| | | * @param {*} cmd å½ä»¤ æä½ç³»ç»å¸¸ç¨æä»¤(linuxç»å¤§é¨åæä»¤é½æ¯æ)ï¼å¿
å¡« |
| | | * @returns |
| | | */ |
| | | common.systemBlocked = function (cmd) { |
| | | return commonObj.systemBlocked(cmd) |
| | | } |
| | | |
| | | /** |
| | | * 弿¥å»¶è¿éå¯ |
| | | * @param {*} delay_s å»¶è¿æ¶é´ |
| | | * @returns |
| | | */ |
| | | common.asyncReboot = function (delay_s) { |
| | | return commonObj.asyncReboot(delay_s) |
| | | } |
| | | |
| | | /** |
| | | * bccæ ¡éª |
| | | * @param {array} data eg:[49,50,51,52,53,54]对åºç弿¯7 |
| | | * @returns æ ¡éªè®¡ç®ç»æ |
| | | */ |
| | | common.calculateBcc = function (data) { |
| | | return commonObj.calculateBcc(data) |
| | | } |
| | | |
| | | /** |
| | | * crcæ ¡éª æ¯å¦å符串'123456'æ ¡éªè®¡ç®çç»ææ¯æ°å 158520161 |
| | | * @param {string} content è¦æ ¡éªçåç¬¦ä¸²æ°æ®ï¼ |
| | | * @returns |
| | | */ |
| | | common.crc32 = function (content) { |
| | | if (content === undefined || content === null || typeof (content) != "string" || content.length < 1) { |
| | | throw new Error("dxCommon.crc32:'content' paramter should not be empty") |
| | | } |
| | | return commonObj.crc32(content) |
| | | } |
| | | |
| | | /** |
| | | * 计ç®MD5åå¸ï¼æ¯å¦'123456'对åºçæ°åæ°ç»æ¯[49,50,51,52,53,54] 对åºçmd5æ¯'e10adc3949ba59abbe56e057f20f883e'ï¼ |
| | | * 使¯è¿åç䏿¯16è¿å¶åç¬¦ä¸²ï¼æ¯æ°åæ°ç»ï¼å¯ä»¥ä½¿ç¨arrToHex彿°è½¬æ¢ |
| | | * @param {array} arr æ°åæ°ç» |
| | | * @returns æ°åæ°ç» |
| | | */ |
| | | common.md5Hash = function (arr) { |
| | | return commonObj.md5Hash(arr) |
| | | } |
| | | |
| | | /** |
| | | * æä»¶è®¡ç®MD5åå¸,æ¯å¦æä»¶éçå
容æ¯'123456'ï¼å¯¹åºçmd5æ¯'e10adc3949ba59abbe56e057f20f883e' |
| | | * 使¯è¿åç䏿¯16è¿å¶åç¬¦ä¸²ï¼æ¯æ°åæ°ç»ï¼å¯ä»¥ä½¿ç¨arrToHex彿°è½¬æ¢ |
| | | * @param {string} æä»¶è·¯å¾ï¼ç»å¯¹è·¯å¾ï¼å¿
å¡«ï¼é常æ¯ä»¥/app/codeå¼å¤´ |
| | | * @returns æ°åæ°ç» |
| | | */ |
| | | common.md5HashFile = function (filePath) { |
| | | if (filePath === undefined || filePath === null || typeof (filePath) != "string") { |
| | | return null |
| | | } |
| | | return commonObj.md5HashFile(filePath) |
| | | } |
| | | |
| | | /** |
| | | * 计ç®HMAC MD5å å¯,æ¯å¦å å¯çæ°æ®æ¯'123456',å¯é¥æ¯'654321'ï¼å¯¹åºçç»ææ¯'357cbe6d81a8ec770799879dc8629a53' |
| | | * 使¯åæ°åè¿åçå¼é½æ¯ArrayBuffer |
| | | * @param {ArrayBuffer} data éè¦å å¯çå
容,å¿
å¡« |
| | | * @param {ArrayBuffer} key å¯é¥ ,å¿
å¡« |
| | | * @returns ArrayBuffer |
| | | */ |
| | | common.hmacMd5Hash = function (data, key) { |
| | | return commonObj.hmacMd5Hash(data, key) |
| | | } |
| | | |
| | | /** |
| | | * 计ç®HMAC MD5å å¯,æ¯å¦å å¯çæ°æ®æ¯'123456',å¯é¥æ¯'654321'ï¼å¯¹åºçç»ææ¯'357cbe6d81a8ec770799879dc8629a53' |
| | | * @param {string} data éè¦å å¯çå
容,å¿
å¡« |
| | | * @param {string} key å¯é¥ ,å¿
å¡« |
| | | * @returns ArrayBuffer |
| | | */ |
| | | common.hmac = function (data, key) { |
| | | return commonObj.hmac(data, key) |
| | | } |
| | | |
| | | /** |
| | | * æä»¶è®¡ç®HMAC MD5å å¯ï¼æ¯å¦æä»¶éçå
容æ¯'123456'ï¼å¯é¥æ¯'654321'ï¼å¯¹åºçç»ææ¯'357cbe6d81a8ec770799879dc8629a53' |
| | | * @param {string} filePath éè¦å å¯çå
容åå¨çæä»¶è·¯å¾ï¼ç»å¯¹è·¯å¾ï¼å¿
å¡«ï¼é常æ¯ä»¥/app/codeå¼å¤´ |
| | | * @param {array} key å¯é¥ ,æ°åæ°ç»,å¿
å¡« |
| | | * @returns æ°åæ°ç» |
| | | */ |
| | | common.hmacMd5HashFile = function (filePath, key) { |
| | | return commonObj.hmacMd5HashFile(filePath, key) |
| | | } |
| | | |
| | | |
| | | /** |
| | | * base64转binæä»¶ |
| | | * @param {string} file_path æä»¶è·¯å¾ï¼å¿
å¡« |
| | | * @param {string} base64Data base64æ°æ®ï¼å¿
å¡« |
| | | * @returns |
| | | */ |
| | | common.base64_2binfile = function (file_path, base64Data) { |
| | | return commonObj.base64_2binfile(file_path, base64Data); |
| | | } |
| | | |
| | | /** |
| | | * binæä»¶è½¬base64 |
| | | * @param {string} file_path æä»¶è·¯å¾ï¼å¿
å¡« |
| | | * @returns base64Data base64æ°æ®ï¼å¿
å¡« |
| | | */ |
| | | common.binfile_2base64 = function (file_path) { |
| | | return commonObj.binfile_2base64(file_path); |
| | | } |
| | | |
| | | /** |
| | | * åæ¢è®¾å¤æ¨¡å¼ |
| | | * @description 模å¼åæ¢åä¼éå¯è®¾å¤ï¼è¿å
¥æå®æ¨¡å¼ï¼ä½¿ç¨æ¹æ³æ¶é宿´ç»´æ¤ç¸äºåæ¢çé»è¾ï¼åæ¢ä¸ºä¸å¡æ¨¡å¼åä¸è½ä½¿ç¨IDEåè½ |
| | | * @param {number} mode 注æï¼æ§çæ¬æ¨¡å¼åæ¢ä½¿ç¨ï¼1ã2ã3ï¼ï¼æ°çæ¬æ¨¡å¼åæ¢ä½¿ç¨ï¼devãtestãprodãsafeï¼ |
| | | * @returns true false |
| | | */ |
| | | common.setMode = function (mode) { |
| | | // 注æï¼æ§çæ¬æ¨¡å¼åæ¢ä½¿ç¨ï¼1ã2ã3ï¼ |
| | | if (mode == 1) { |
| | | //çäº§æ¨¡å¼ |
| | | commonObj.systemWithRes(`echo 'app' > /etc/.mode`, 2) |
| | | // 1.0çæ¬åæ¢ä¸ºå
¶ä»æ¨¡å¼åå é¤å·¥åæ£æµï¼åç»çæ¬å¯è½ä¼è°æ´ï¼ |
| | | commonObj.systemWithRes(`rm -rf /test`, 2) |
| | | } else if (mode == 2) { |
| | | //è°è¯æ¨¡å¼ |
| | | commonObj.systemWithRes(`echo 'debug' > /etc/.mode`, 2) |
| | | // 1.0çæ¬åæ¢ä¸ºå
¶ä»æ¨¡å¼åå é¤å·¥åæ£æµï¼åç»çæ¬å¯è½ä¼è°æ´ï¼ |
| | | commonObj.systemWithRes(`rm -rf /test`, 2) |
| | | } else if (mode == 3) { |
| | | //è¯äº§æ¨¡å¼ |
| | | commonObj.systemWithRes(`echo 'pp' > /etc/.mode`, 2) |
| | | } |
| | | |
| | | // 注æï¼æ°çæ¬æ¨¡å¼åæ¢ä½¿ç¨ï¼devãtestãprodãsafeï¼ |
| | | else if (mode == "dev") { |
| | | //å¼åæ¨¡å¼ |
| | | commonObj.systemWithRes(`echo 'dev' > /etc/.mode_v1`, 2) |
| | | } else if (mode == "test") { |
| | | //æµè¯æ¨¡å¼ï¼è¯äº§æ¨¡å¼ï¼ |
| | | commonObj.systemWithRes(`echo 'test' > /etc/.mode_v1`, 2) |
| | | } else if (mode == "prod") { |
| | | //çäº§æ¨¡å¼ |
| | | commonObj.systemWithRes(`echo 'prod' > /etc/.mode_v1`, 2) |
| | | } else if (mode == "safe") { |
| | | //å®å
¨æ¨¡å¼ |
| | | commonObj.systemWithRes(`echo 'safe' > /etc/.mode_v1`, 2) |
| | | } else { |
| | | return false |
| | | } |
| | | commonObj.systemWithRes(`sync`, 2) |
| | | commonObj.asyncReboot(2) |
| | | return true |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢è®¾å¤æ¨¡å¼ |
| | | * @description è·å设å¤å½åæ¨¡å¼ |
| | | * @returns ä¸å¡æ¨¡å¼ï¼1ï¼å¼å模å¼ï¼2ï¼å·¥å模å¼ï¼28ï¼ å¼å¸¸æ¨¡å¼ï¼-1 |
| | | */ |
| | | common.getMode = function () { |
| | | let ret = commonObj.systemWithRes(`test -e "/etc/.mode" && echo "OK" || echo "NO"`, 2) |
| | | if (ret.includes('NO')) { |
| | | return 28 |
| | | } |
| | | let mode = commonObj.systemWithRes(`cat "/etc/.mode"`, 10) |
| | | if (mode.includes('app')) { |
| | | return 1 |
| | | } else if (mode.includes('debug')) { |
| | | return 2 |
| | | } else { |
| | | return -1 |
| | | } |
| | | } |
| | | /** |
| | | * åå
è¿å¶è½¬åèæ°ç» eg:313233616263->[49,50,51,97,98,99] |
| | | * @param {string} str 16è¿å¶å符串 å°åä¸ä¸é´æ 空éçåå
è¿å¶å符串 |
| | | * @returns æ°åæ°å |
| | | */ |
| | | common.hexToArr = function (str) { |
| | | if (str === undefined || str === null || (typeof str) != 'string' || str.length < 1) { |
| | | throw new Error("dxCommon.hexToArr:'str' parameter should not be empty") |
| | | } |
| | | let regex = /.{2}/g; |
| | | let arr = str.match(regex); |
| | | return arr.map(item => parseInt(item, 16)); |
| | | } |
| | | /** |
| | | * åèæ°ç»è½¬åå
è¿å¶ eg:[49,50,51,97,98,99]->313233616263 |
| | | * @param {array}numbers æ°åæ°ç» |
| | | * @returns str 16è¿å¶å符串 å°åä¸ä¸é´æ 空éçåå
è¿å¶å符串 |
| | | */ |
| | | common.arrToHex = function (numbers) { |
| | | const hexArray = numbers.map(num => num.toString(16).padStart(2, '0').toLowerCase()); |
| | | const hexString = hexArray.join(''); |
| | | return hexString; |
| | | } |
| | | /** |
| | | * åå
è¿å¶è½¬å符串 eg:313233616263->123abc |
| | | * 注æå¦æ16è¿å¶å符串æ¯ç±ä¸æè½¬è¿å»çï¼å转å䏿åç¬¦ä¸²ä¼æä¹±ç ï¼å 为æ¯ä¸ä¸ªä¸ä¸ªåèçè½¬æ¢ |
| | | * @param {string} str è¦è½¬ç16è¿å¶å符串 |
| | | * @returns |
| | | */ |
| | | common.hexToString = function (str) { |
| | | let regex = /.{2}/g; |
| | | let arr = str.match(regex); |
| | | arr = arr.map(item => String.fromCharCode(parseInt(item, 16))); |
| | | return arr.join(""); |
| | | } |
| | | // å°å符串转æ¢ä¸º UTF-8 ç¼ç ç16è¿å¶å符串 |
| | | common.strToUtf8Hex = function (str) { |
| | | const bytes = []; |
| | | for (let i = 0; i < str.length; i++) { |
| | | let code = str.charCodeAt(i); |
| | | if (code < 0x80) { |
| | | bytes.push(code); |
| | | } else if (code < 0x800) { |
| | | bytes.push(0xc0 | (code >> 6), 0x80 | (code & 0x3f)); |
| | | } else if (code < 0xd800 || code >= 0xe000) { |
| | | bytes.push(0xe0 | (code >> 12), 0x80 | ((code >> 6) & 0x3f), 0x80 | (code & 0x3f)); |
| | | } else { |
| | | // å¤ç Unicode ç¼ç |
| | | i++; |
| | | code = 0x10000 + (((code & 0x3ff) << 10) | (str.charCodeAt(i) & 0x3ff)); |
| | | bytes.push( |
| | | 0xf0 | (code >> 18), |
| | | 0x80 | ((code >> 12) & 0x3f), |
| | | 0x80 | ((code >> 6) & 0x3f), |
| | | 0x80 | (code & 0x3f) |
| | | ); |
| | | } |
| | | } |
| | | return this.arrToHex(bytes); |
| | | } |
| | | /** |
| | | * ä¼ éè¿æ¥çutf-8ç16è¿å¶åç¬¦ä¸²è½¬æ¢æå符串 |
| | | * @param {string} hex |
| | | * @returns |
| | | */ |
| | | common.utf8HexToStr = function (hex) { |
| | | let array = this.hexToArr(hex) |
| | | var out, i, len, c; |
| | | var char2, char3; |
| | | |
| | | out = ""; |
| | | len = array.length; |
| | | i = 0; |
| | | while (i < len) { |
| | | c = array[i++]; |
| | | switch (c >> 4) { |
| | | case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: |
| | | // 0xxxxxxx |
| | | out += String.fromCharCode(c); |
| | | break; |
| | | case 12: case 13: |
| | | // 110x xxxx 10xx xxxx |
| | | char2 = array[i++]; |
| | | out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F)); |
| | | break; |
| | | case 14: |
| | | // 1110 xxxx 10xx xxxx 10xx xxxx |
| | | char2 = array[i++]; |
| | | char3 = array[i++]; |
| | | out += String.fromCharCode(((c & 0x0F) << 12) | |
| | | ((char2 & 0x3F) << 6) | |
| | | ((char3 & 0x3F) << 0)); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | return out; |
| | | } |
| | | /** |
| | | * å符串转åå
è¿å¶ eg:123abc->313233616263 |
| | | * @param {string} str è¦è½¬çå符串 |
| | | * @returns |
| | | */ |
| | | common.stringToHex = function (str) { |
| | | if (str === undefined || str === null || typeof (str) != "string") { |
| | | return null |
| | | } |
| | | let val = ""; |
| | | for (let i = 0; i < str.length; i++) { |
| | | val += str.charCodeAt(i).toString(16) |
| | | } |
| | | return val |
| | | } |
| | | |
| | | /** |
| | | * å°ç«¯æ ¼å¼è½¬åè¿å¶æ° eg:001001->69632 |
| | | * @param {string} hexString 16è¿å¶å符串 å°åä¸ä¸é´æ 空éçåå
è¿å¶å符串 |
| | | * @returns æ°å |
| | | */ |
| | | common.littleEndianToDecimal = function (hexString) { |
| | | // å°å°ç«¯æ ¼å¼çåå
è¿å¶å符串è¿è¡å转 |
| | | let reversedHexString = hexString |
| | | .match(/.{2}/g) // æ¯ä¸¤ä¸ªå符åé |
| | | .reverse() // å转æ°ç» |
| | | .join(""); // å并为å符串 |
| | | |
| | | // å°å转åçåå
è¿å¶å符串转æ¢ä¸ºåè¿å¶æ° |
| | | let decimal = parseInt(reversedHexString, 16); |
| | | return decimal; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * åè¿å¶æ°è½¬æ¢ä¸º16è¿å¶å°ç«¯æ ¼å¼å符串 |
| | | * eg:300->2c01 |
| | | * eg:230->e600 |
| | | * @param {number} decimalNumber åè¿å¶æ°å,å¿
å¡« |
| | | * @param {number} byteSize çæä½æ° åèç个æ°ï¼å¦æè¶
åºå®é
åè个æ°ï¼ä¼å¨å³è¾¹è¡¥0ï¼ä½äºä¼æªåï¼éå¿
å¡«ï¼ç¼ºçæ¯2 |
| | | * @returns |
| | | */ |
| | | common.decimalToLittleEndianHex = function (decimalNumber, byteSize) { |
| | | if (decimalNumber === undefined || decimalNumber === null || (typeof decimalNumber) != 'number') { |
| | | throw new Error("dxCommon.decimalToLittleEndianHex:'decimalNumber' parameter should be number") |
| | | } |
| | | if (byteSize === undefined || byteSize === null || (typeof byteSize) != 'number' || byteSize <= 0) { |
| | | byteSize = 2 |
| | | } |
| | | const littleEndianBytes = []; |
| | | for (let i = 0; i < byteSize; i++) { |
| | | littleEndianBytes.push(decimalNumber & 0xFF); |
| | | decimalNumber >>= 8;//ç¸å½äºé¤ä»¥256 |
| | | } |
| | | const littleEndianHex = littleEndianBytes |
| | | .map((byte) => byte.toString(16).padStart(2, '0')) |
| | | .join(''); |
| | | return littleEndianHex; |
| | | } |
| | | |
| | | /** |
| | | * å°16è¿å¶å符串转æ¢ä¸ºArrayBuffer |
| | | * @param {*} hexString è¦è½¬æ¢ç16è¿å¶å符串 |
| | | * @returns |
| | | */ |
| | | common.hexStringToArrayBuffer = function (hexString) { |
| | | return this.hexStringToUint8Array(hexString).buffer; |
| | | } |
| | | |
| | | /** |
| | | * å°16è¿å¶å符串转æ¢ä¸ºUint8Array |
| | | * @param {string} hexString è¦è½¬æ¢ç16è¿å¶å符串ï¼å°åä¸ä¸é´æ 空éçåå
è¿å¶å符串 |
| | | * @returns Uint8Array对象 |
| | | */ |
| | | common.hexStringToUint8Array = function (hexString) { |
| | | if (hexString === undefined || hexString === null || (typeof hexString) != 'string' || hexString.length <= 0) { |
| | | throw new Error("dxCommon.hexStringToUint8Array:'hexString' parameter should not be empty") |
| | | } |
| | | let byteString = hexString.match(/.{1,2}/g); |
| | | let byteArray = byteString.map(function (byte) { |
| | | return parseInt(byte, 16); |
| | | }); |
| | | let buffer = new Uint8Array(byteArray); |
| | | return buffer; |
| | | } |
| | | |
| | | /** |
| | | * å° ArrayBuffer 转æ¢ä¸ºåå
è¿å¶åç¬¦ä¸²æ ¼å¼ |
| | | * @param {ArrayBuffer} buffer |
| | | * @returns å°åä¸ä¸é´æ 空éçåå
è¿å¶å符串 |
| | | */ |
| | | common.arrayBufferToHexString = function (buffer) { |
| | | return this.uint8ArrayToHexString(new Uint8Array(buffer)) |
| | | } |
| | | /** |
| | | * å° Uint8Array 转æ¢ä¸ºåå
è¿å¶åç¬¦ä¸²æ ¼å¼ |
| | | * @param {Uint8Array} array |
| | | * @returns å°åä¸ä¸é´æ 空éçåå
è¿å¶å符串 |
| | | */ |
| | | common.uint8ArrayToHexString = function (array) { |
| | | let hexString = ''; |
| | | for (let i = 0; i < array.length; i++) { |
| | | const byte = array[i].toString(16).padStart(2, '0'); |
| | | hexString += byte; |
| | | } |
| | | return hexString |
| | | } |
| | | /** |
| | | * 设置/è·åç»ä»¶å¥æidéç¨æ¹æ³ |
| | | * @param {string} name ç»ä»¶åï¼å¿
å¡« |
| | | * @param {string} id 奿idï¼éå¿
å¡« |
| | | * @param {number} pointer 奿æéæ°åï¼éå¿
å¡« |
| | | * @returns |
| | | */ |
| | | common.handleId = function (name, id, pointer) { |
| | | // ç»ä»¶åä¸è½ä¸ºç©º |
| | | if (name === undefined || name === null || name === "" || typeof name !== 'string') { |
| | | return |
| | | } |
| | | let map = dxMap.get('handleIds') |
| | | // 奿id |
| | | if (id === undefined || id === null || id === "" || typeof id !== 'string') { |
| | | id = "__" + name + "_default" |
| | | } |
| | | if (pointer === undefined || pointer === null || typeof pointer !== 'number') { |
| | | // pointer为空å为è·å |
| | | return map.get(id) |
| | | } else { |
| | | // pointerä¸ä¸ºç©ºå为设置 |
| | | let isExist = map.get(id) |
| | | if (isExist) { |
| | | // 奿已åå¨ |
| | | return |
| | | } |
| | | map.put(id, pointer) |
| | | } |
| | | } |
| | | |
| | | |
| | | export default common |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | /** |
| | | * å®ç°å¯¹åºç¨ææé
置项ï¼key/value)ç管çï¼ |
| | | * 1. ç¨æ·éè¦æåå§çé
置项ä¿åå¨é¡¹ç®ç src/config.json ï¼é
ç½®æä»¶çæ ¼å¼è¯·ä¿çkey/valueæ ¼å¼ï¼æ¯ææ³¨é)ï¼valueåªè½æ¯åç¬¦ä¸²åæ°åç±»å,ä¾å¦ï¼ |
| | | * { |
| | | * //mqttç¸å
³é
ç½® |
| | | * "mqtt.ip":"192.168.2.3", |
| | | * "mqtt.port":6199, |
| | | * } |
| | | * 2. 乿¯æèªå®ä¹é
ç½®æä»¶ï¼åå§åå¯ä»¥ä¼ éèªå®ä¹é
ç½®æä»¶çè·¯å¾åæ è¯ï¼åç»è¯»åæ°æ®é½éè¦ä¼ éè¿ä¸ªæ è¯ |
| | | * 3. ç¨æ·å¨åºç¨ä¸ç¬¬ä¸æ¬¡ä½¿ç¨è¿ä¸ªç»ä»¶ï¼éè¦å
åå§å initï¼åå§å伿 config.json çæ°æ®ä¿åå°å
åéï¼ä»¥åæ¯æ¬¡è·å齿¯ä»å
åè·å |
| | | * 4. ç¨æ·å¯ä»¥å¨ä»»ä½å°æ¹é½å¯ä»¥éè¿ get å set æ¥è¯»åé
ç½® |
| | | * 5. å¦æä¿®æ¹é
置项ç value åæ¶éè¦ä¿åå°é
ç½®æä»¶ï¼ä¿è¯éå¯åæ°é
ç½®çæï¼ï¼ä½¿ç¨ setAndSave |
| | | * 6. 妿éè¦æ¢å¤ææé»è®¤é
ç½®ï¼ä½¿ç¨ reset |
| | | */ |
| | | import * as os from 'os'; |
| | | import dxMap from './dxMap.js' |
| | | import common from './dxCommon.js' |
| | | import logger from './dxLogger.js' |
| | | import std from './dxStd.js' |
| | | |
| | | const map = dxMap.get("default") |
| | | |
| | | const config = {} |
| | | const DEFALUT_OPTIONS = { path: '/app/code/src/config.json', savePath: '/app/data/config/config.json', flag: '___config.' } |
| | | |
| | | /** |
| | | * åå§å伿 config.json æèªå®ä¹çé
ç½®æä»¶çæ°æ®ä¿åå°å
åéï¼ä»¥åæ¯æ¬¡è·å齿¯ä»å
åè·å |
| | | * @param {object} custom éå¿
å¡«ï¼èªå®ä¹çé
ç½®æä»¶ |
| | | * @param {string} custom.path èªå®ä¹çé
ç½®æä»¶å®æ´è·¯å¾ |
| | | * @param {string} custom.flag èªå®ä¹é
ç½®æä»¶çæ è¯ï¼æ³¨æå¦ææå¤ä¸ªèªå®ä¹é
ç½®æä»¶ï¼è¿ä¸ªæ è¯ä¸è¦éå¤ |
| | | */ |
| | | config.init = function (custom) { |
| | | if (custom) { |
| | | if (!custom.path || !custom.flag) { |
| | | throw new Error('The path and flag for the custom configuration file cannot be empty.') |
| | | } |
| | | } |
| | | let flag = custom ? DEFALUT_OPTIONS.flag + custom.flag + '.' : DEFALUT_OPTIONS.flag; |
| | | const isInited = map.get('___inited' + flag) |
| | | if (isInited) {//åªåå§å䏿¬¡ |
| | | return |
| | | } |
| | | let path = custom ? custom.path : DEFALUT_OPTIONS.path |
| | | let savePath = custom ? '/app/data/config/config' + custom.flag + '.json' : DEFALUT_OPTIONS.savePath |
| | | if (!std.exist(path)) { |
| | | throw new Error('The config file not existed:' + path) |
| | | } |
| | | let existed = std.exist(savePath) |
| | | let content = existed ? std.parseExtJSON(std.loadFile(savePath)) : std.parseExtJSON(std.loadFile(path)) |
| | | if (!existed) { |
| | | std.saveFile(savePath, JSON.stringify(content)) |
| | | } |
| | | for (let [key, value] of Object.entries(content)) { |
| | | map.put(flag + key, value) |
| | | } |
| | | map.put('___inited' + flag, 'ok') |
| | | } |
| | | /** |
| | | * è·åææé
置项 |
| | | * @param {string} flag èªå®ä¹çé
ç½®æä»¶æ è¯ï¼å¯ä»¥ä¸ºç©ºï¼ä¸ºç©ºåè¿å缺çconfig.jsonéææå
容 |
| | | * @returns json对象 |
| | | */ |
| | | config.getAll = function (flag) { |
| | | let _flag = _getFlag(flag) |
| | | let configInfo = {} |
| | | let keys = map.keys().filter(k => k.startsWith(_flag)) |
| | | keys.forEach(k => { |
| | | let key = k.substring(_flag.length) |
| | | let val = map.get(k) |
| | | configInfo[key] = val |
| | | }) |
| | | return configInfo |
| | | } |
| | | /** |
| | | * è·åé
ç½®ï¼åªä»mapè·å |
| | | * 妿é
置项为空ï¼è¿åæææææ°æ®ï¼ |
| | | * @param {string} key é
置项 |
| | | * @param {string} flag èªå®ä¹çé
ç½®æä»¶æ è¯ï¼å¯ä»¥ä¸ºç©ºï¼ä¸ºç©ºåè¿å缺çconfig.jsonéçé
ç½®å¼ |
| | | * @returns |
| | | */ |
| | | config.get = function (key, flag) { |
| | | if (!key) { |
| | | return this.getAll(flag); |
| | | } |
| | | let _flag = _getFlag(flag) |
| | | return map.get(_flag + key) |
| | | } |
| | | |
| | | /** |
| | | * æ´æ°é
ç½®ï¼åªä¿®æ¹map |
| | | * @param {string} key é
置项 |
| | | * @param {string} value é
ç½®å¼ |
| | | * @param {string} flag èªå®ä¹çé
ç½®æä»¶æ è¯ï¼å¯ä»¥ä¸ºç©ºï¼ä¸ºç©ºåæå缺çconfig.jsonéçé
ç½®å¼ |
| | | */ |
| | | config.set = function (key, value, flag) { |
| | | if (!key || value == null || value == undefined) { |
| | | throw new Error("key or value should not be empty") |
| | | } |
| | | let _flag = _getFlag(flag) |
| | | map.put(_flag + key, value) |
| | | } |
| | | |
| | | /** |
| | | * å°mapä¸çæ°æ®æä¹
åå°æ¬å° |
| | | * @param {string} flag èªå®ä¹çé
ç½®æä»¶æ è¯ï¼å¯ä»¥ä¸ºç©ºï¼ä¸ºç©ºåæå缺çconfig.jsonéçé
ç½®å¼ |
| | | */ |
| | | config.save = function (flag) { |
| | | //ä¿å |
| | | std.saveFile(_getSavePath(flag), JSON.stringify(this.getAll(flag))) |
| | | } |
| | | |
| | | /** |
| | | * æ´æ°é
ç½®ï¼ä¿®æ¹map䏿ä¹
åæ¬å° |
| | | * @param {string} key é
置项 |
| | | * @param {string} value é
ç½®å¼ |
| | | * @param {string} flag èªå®ä¹çé
ç½®æä»¶æ è¯ï¼å¯ä»¥ä¸ºç©ºï¼ä¸ºç©ºåæå缺çconfig.jsonéçé
ç½®å¼ |
| | | */ |
| | | config.setAndSave = function (key, value, flag) { |
| | | this.set(key, value, flag) |
| | | //ä¿å |
| | | std.saveFile(_getSavePath(flag), JSON.stringify(this.getAll(flag))) |
| | | } |
| | | |
| | | /** |
| | | * éç½®ï¼éç½®å请éå¯å¨è®¾å¤ |
| | | * @param {string} flag èªå®ä¹çé
ç½®æä»¶æ è¯ï¼å¯ä»¥ä¸ºç©ºï¼ä¸ºç©ºåæå缺çconfig.jsonéçé
ç½®å¼ |
| | | */ |
| | | config.reset = function (flag) { |
| | | common.systemBrief('rm -rf ' + _getSavePath(flag)) |
| | | } |
| | | |
| | | //-------------------private------------------------------- |
| | | |
| | | function _getFlag(flag) { |
| | | return flag ? DEFALUT_OPTIONS.flag + flag + '.' : DEFALUT_OPTIONS.flag |
| | | } |
| | | function _getSavePath(flag) { |
| | | return flag ? '/app/data/config/config' + flag + '.json' : DEFALUT_OPTIONS.savePath |
| | | } |
| | | export default config; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | const dxDriver = {}
|
| | |
|
| | | /*************************************Device Resource Enumeration*************************************/
|
| | |
|
| | | /**
|
| | | * GPIO device pins
|
| | | */
|
| | | dxDriver.GPIO = {
|
| | |
|
| | | // Relay
|
| | | RELAY0: 44,
|
| | | }
|
| | |
|
| | | /**
|
| | | * Channel communication
|
| | | */
|
| | | dxDriver.CHANNEL = {
|
| | |
|
| | | // 485 |
| | | UART_PATH: "/dev/ttySLB2",
|
| | |
|
| | | // USBHID
|
| | | USBHID_PATH: "/dev/hidg1",
|
| | | }
|
| | |
|
| | | /**
|
| | | * Camera related parameters
|
| | | */
|
| | | dxDriver.CAPTURER = {
|
| | | // Camera image width
|
| | | RGB_WIDTH: 1280,
|
| | | // Camera image height
|
| | | RGB_HEIGHT: 800,
|
| | | // Camera device files
|
| | | RGB_PATH: "/dev/video3",
|
| | |
|
| | | // Camera image width
|
| | | NIR_WIDTH: 800,
|
| | | // Camera image height
|
| | | NIR_HEIGHT: 600,
|
| | | // Camera device files
|
| | | NIR_PATH: "/dev/video0"
|
| | | }
|
| | |
|
| | | /**
|
| | | * PWM channel
|
| | | */
|
| | | dxDriver.PWM = {
|
| | |
|
| | | // Fill light
|
| | | WHITE_SUPPLEMENT_CHANNEL: 4,
|
| | | WHITE_SUPPLEMENT_PERIOD_NS: 255000,
|
| | | WHITE_SUPPLEMENT_DUTY: 255000 * 255 / 255,
|
| | | |
| | | NIR_SUPPLEMENT_CHANNEL: 7,
|
| | | NIR_SUPPLEMENT_PERIOD_NS: 255000,
|
| | | NIR_SUPPLEMENT_DUTY: 255000 * 255 / 255,
|
| | | }
|
| | |
|
| | | /**
|
| | | * GPIO pin function enumeration
|
| | | */
|
| | | dxDriver.GPIO_FUNC = {
|
| | | GPIO_FUNC_3: 0x03, //0011, GPIO as function 3 / device 3
|
| | | GPIO_OUTPUT0: 0x04, //0100, GPIO output low level
|
| | | GPIO_OUTPUT1: 0x05 //0101, GPIO output high level
|
| | | };
|
| | |
|
| | | /**
|
| | | * Door opening button
|
| | | */
|
| | | dxDriver.GPIO_KEY_OPEN = 30
|
| | |
|
| | | /**
|
| | | * Door magnetic status
|
| | | */
|
| | | dxDriver.GPIO_KEY_SEN = 48
|
| | |
|
| | |
|
| | |
|
| | | export default dxDriver |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | import { eidClass } from './libvbar-m-dxeid.so' |
| | | const eidObj = new eidClass(); |
| | | |
| | | const eid = { |
| | | /** |
| | | * @brief äºè¯æ¿æ´» |
| | | * @param {string} sn 设å¤sn |
| | | * @param {string} version ä¸å¡èªå®ä¹çæ¬å· |
| | | * @param {string} mac 设å¤macå°å |
| | | * @param {string} codeMsg äºè¯æ¿æ´»ç æ°æ® |
| | | * @returns |
| | | */ |
| | | active: function(sn, version, mac, codeMsg){ |
| | | |
| | | if(!sn){ |
| | | throw("sn should not be null or empty") |
| | | } |
| | | if(!version){ |
| | | throw("version should not be null or empty") |
| | | } |
| | | if(!mac){ |
| | | throw("mac should not be null or empty") |
| | | } |
| | | if(!codeMsg){ |
| | | throw("codeMsg should not be null or empty") |
| | | } |
| | | return eidObj.active(sn, version, mac, codeMsg); |
| | | }, |
| | | /** |
| | | * @brief è·åä¿¡æ¯ |
| | | */ |
| | | getInfo: function(){ |
| | | if(data == null || data.length < 1){ |
| | | throw("data should not be null or empty") |
| | | } |
| | | return eidObj.getInfo(data) |
| | | }, |
| | | /** |
| | | * @brief è·åçæ¬å· |
| | | */ |
| | | getVersion: function(){ |
| | | return eidObj.getVersion() |
| | | }, |
| | | } |
| | | |
| | | export default eid; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //build:20240628 |
| | | //äºä»¶æ»çº¿ï¼å©ç¨quickjsçworkeré´æ°æ®éä¿¡æ¥å®ç°çº¿ç¨ä¹é´åéäºä»¶éç¥ã |
| | | //workeråworkerä¹é´ä¸è½ç´æ¥éä¿¡ï¼éè¦éè¿parent(主线ç¨)æ¥è½¬åï¼æä»¥éè¦å®ç°5ç§å¯è½æ§çäºä»¶éç¥ |
| | | //1. worker1--->parent--->worker2 |
| | | //2. worker3--->parent |
| | | //3. parent--->worker4 |
| | | //4. parent<-->parent |
| | | //5. worker5<--->worker5,ä¹ä¼éè¿parent转 |
| | | //ç»ä»¶ä¾èµ dxLogger,dxCommon |
| | | import std from './dxStd.js' |
| | | import logger from './dxLogger.js' |
| | | import * as os from "os"; |
| | | //-------------------------variable-------------------- |
| | | const bus = {} |
| | | const all = {} |
| | | const subs = {} |
| | | const isMain = (os.Worker.parent === undefined) |
| | | bus.id = isMain ? '__main' : null |
| | | /** |
| | | * 卿»çº¿ä¸å¯å¨ä¸ä¸ªworkerï¼ç»å®å®ä¹ä¸ä¸ªå¯ä¸çidæ è¯ |
| | | * å 为workeråªè½éè¿ä¸»çº¿ç¨åå»ºï¼æä»¥newWorker彿°ä¹åªè½å¨ä¸»çº¿ç¨éæ§è¡ |
| | | * 注æ: worker对åºçæä»¶éä¸è½å
å«while(true)è¿ç§æ»å¾ªç¯ï¼å¦åå°±æ¶ä¸å°messageï¼å¯ä»¥ç¨setIntevalæ¥å®ç°å¾ªç¯ |
| | | * @param {string} id workerçå¯ä¸æ è¯ï¼ä¸è½ä¸ºç©º |
| | | * @param {object} file worker对åºçæä»¶åï¼ç»å¯¹è·¯å¾ï¼é常以'/app/code/src'å¼å§ |
| | | */ |
| | | bus.newWorker = function (id, file) { |
| | | if (!id) { |
| | | throw new Error("eventbus newWorker:'id' should not be empty") |
| | | } if (!file) { |
| | | throw new Error("eventbus newWorker:'file' should not be empty") |
| | | } |
| | | if (!isMain) { |
| | | throw new Error("evnetbus newWorker should be invoke in main thread") |
| | | } |
| | | if (!std.exist(file)) { |
| | | throw new Error("eventbus newWorker: file not found:" + file) |
| | | } |
| | | let content = std.loadFile(file) + ` |
| | | import __bus from '/app/code/dxmodules/dxEventBus.js' |
| | | __bus.id='${id}' |
| | | Object.keys(__bus.handlers).forEach(key => { |
| | | __bus.os.Worker.parent.postMessage({ __sub: key, id: __bus.id }) |
| | | }) |
| | | __bus.os.Worker.parent.onmessage = function (e) { |
| | | if(!e.data){ |
| | | return |
| | | } |
| | | e = e.data |
| | | if (!e || !e.topic) { |
| | | return |
| | | } |
| | | let fun = __bus.handlers[e.topic] |
| | | if (fun) { |
| | | fun(e.data) |
| | | } |
| | | } |
| | | ` |
| | | let newfile = file + '_' + id + '.js' |
| | | std.saveFile(newfile, content) |
| | | let worker = new os.Worker(newfile) |
| | | all[id] = worker |
| | | worker.onmessage = function (data) { |
| | | if (data.data) { |
| | | if (data.data.__sub) { |
| | | sub(data.data.__sub, data.data.id) |
| | | return |
| | | } |
| | | //workeråéè¿æ¥çæ°æ®åè°ç¨ä¸æ¬¡ä¸»çº¿ç¨çfireï¼è¦ä¹ä¸»çº¿ç¨èªå·±æ¶è´¹ï¼è¦ä¹è½¬åå°å
¶å®worker |
| | | bus.fire(data.data.topic, data.data.data) |
| | | } |
| | | } |
| | | } |
| | | /** |
| | | * æ ¹æ®idå é¤å¯¹åºçworkerï¼è¿æ ·worker线ç¨å°±è½æ£å¸¸ç»æ |
| | | * @param {string} id |
| | | */ |
| | | bus.delWorker = function (id) { |
| | | delete all[id] |
| | | } |
| | | /** |
| | | * 触åä¸ä¸ªäºä»¶ï¼è¿ä¸ªäºä»¶ä¼ç«å»åéç»æï¼æ¥æ¶å°æ¶æ¯çå¤ç妿æ¯è¾èæ¶ä¸ä¼å½±åäºä»¶åéçé¡ºåºæåºç°äºä»¶ä¸¢å¤± |
| | | * åæ ·ä¸ä¸ªäºä»¶å¯ä»¥æå¤ä¸ªè®¢é
è
ï¼å¯ä»¥åæ¶éç¥å¤ä¸ªè®¢é
è
ï¼åä¸ä¸ªtopicå使¶é´å
åªå¤çä¸ä¸ªäºä»¶ï¼ |
| | | * åªæå½åtopic被ææç订é
è
å¤çå®ä¹åæå
许å¤çåä¸topicä¸ä¸ä¸ªäºä»¶ |
| | | * |
| | | * @param {string} topic äºä»¶çæ è¯ãä¸»é¢ |
| | | * @param {*} data äºä»¶éå¸¦çæ°æ® |
| | | */ |
| | | bus.fire = function (topic, data) { |
| | | if (!topic || (typeof topic) != 'string') { |
| | | throw new Error("eventbus :'topic' should not be null"); |
| | | } |
| | | if (isMain) { |
| | | if (subs[topic] && subs[topic].length > 0) { |
| | | for (let i = 0; i < subs[topic].length; i++) { |
| | | const id = subs[topic][i] |
| | | if (id === '__main' && bus.handlers[topic]) { |
| | | if (Array.isArray(bus.handlers[topic])) { |
| | | // æ§è¡æææ³¨åçå¤ç彿° |
| | | for (let j = 0; j < bus.handlers[topic].length; j++) { |
| | | try { |
| | | bus.handlers[topic][j](data) |
| | | } catch (error) { |
| | | logger.error('Error in event handler for topic ' + topic + ': ' + error.message) |
| | | } |
| | | } |
| | | } else { |
| | | // å
¼å®¹æ§çæ¬ï¼æ§è¡å个å¤ç彿° |
| | | try { |
| | | bus.handlers[topic](data) |
| | | } catch (error) { |
| | | logger.error('Error in event handler for topic ' + topic + ': ' + error.message) |
| | | } |
| | | } |
| | | } else { |
| | | const worker = all[id] |
| | | if (worker) { |
| | | worker.postMessage({ topic: topic, data: data }) |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | os.Worker.parent.postMessage({ topic: topic, data: data }) |
| | | } |
| | | } |
| | | |
| | | |
| | | bus.handlers = {} |
| | | /** |
| | | * 订é
ä¸ä¸ªäºä»¶ |
| | | * @param {string} topic äºä»¶çæ è¯ãä¸»é¢ ï¼å¿
å¡« |
| | | * @param {function} callback äºä»¶å¤ççåè°å½æ°ï¼å¿
å¡« |
| | | */ |
| | | bus.on = function (topic, callback) { |
| | | if (!topic || (typeof topic) != 'string') { |
| | | throw new Error("The 'topic' should not be null"); |
| | | } |
| | | if (!callback || (typeof callback) != 'function') { |
| | | throw new Error("The 'callback' should be a function"); |
| | | } |
| | | sub(topic, bus.id) |
| | | // æ¯æå¤ä¸ªäºä»¶å¤ç彿° |
| | | if (!this.handlers[topic]) { |
| | | this.handlers[topic] = [] |
| | | } |
| | | if (!Array.isArray(this.handlers[topic])) { |
| | | // å
¼å®¹æ§çæ¬ï¼å°åä¸ªå½æ°è½¬æ¢ä¸ºæ°ç» |
| | | this.handlers[topic] = [this.handlers[topic]] |
| | | } |
| | | this.handlers[topic].push(callback) |
| | | } |
| | | function sub(topic, id) { |
| | | if (isMain) { |
| | | if (!subs[topic]) { |
| | | subs[topic] = [] |
| | | } |
| | | if (!subs[topic].includes(id)) { |
| | | subs[topic].push(id) |
| | | } |
| | | } else { |
| | | if (id != null) { |
| | | os.Worker.parent.postMessage({ __sub: topic, id: id }) |
| | | } |
| | | } |
| | | } |
| | | bus.os = os |
| | | export default bus |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //build: 20250513 |
| | | //ä¾èµç»ä»¶:dxDriverï¼dxStdï¼dxLoggerï¼dxMapï¼dxEventBus,dxCommon |
| | | import { faceClass } from './libvbar-b-dxface.so' |
| | | import dxCommon from './dxCommon.js' |
| | | import bus from './dxEventBus.js' |
| | | const faceObj = new faceClass(); |
| | | const face = {} |
| | | |
| | | /** |
| | | * 人è¸å¤çåå§å |
| | | * @param {object} options é
ç½®åæ°ï¼å¤§é¨åå¯ä»¥ç¨é»è®¤å¼ |
| | | * @param {string} options.rgbPath å¿
å¡«ï¼rgbå¾åéé设å¤è·¯å¾ï¼æ¯ç§è®¾å¤æå·®å¼ï¼æ¯å¦DW200对åºç弿¯'/dev/video11', M500对åºç'/dev/video0' |
| | | * @param {string} options.nirPath å¿
å¡«ï¼çº¢å¤å¾åéé设å¤è·¯å¾ï¼æ¯ç§è®¾å¤æå·®å¼ |
| | | * @param {string} options.dbPath æ°æ®åºè·¯å¾ï¼å¿
å¡« |
| | | * @param {number} options.score ç¹å¾å¼å¯¹æ¯æåæéæä½å¯¹æ¯å¾å ï¼éå¿
å¡«ï¼ç¼ºç0.6ï¼ |
| | | * @param {number} options.dbMax å
åä¸å è½½çæå¤§ç¹å¾å表æ°éï¼éå¿
å¡«ï¼ç¼ºç5000ï¼ |
| | | * @param {string} options.mapPath æ å®ç»ææä»¶è·¯å¾ï¼éå¿
å¡« |
| | | * @param {string} options.picPath ä¿å宿´äººè¸ç
§çè·¯å¾ï¼éå¿
å¡« |
| | | * @param {string} capturerRgbId å¿
å¡«ï¼rgbåå¾å¥æid |
| | | * @param {string} capturerNirId å¿
å¡«ï¼niråå¾å¥æid |
| | | * @returns true/false |
| | | */ |
| | | face.init = function (options, capturerRgbId, capturerNirId) { |
| | | if (options.rgbPath === undefined || options.rgbPath === null || options.rgbPath.length < 1) { |
| | | throw new Error("dxFace.init: 'rgbPath' parameter should not be null or empty") |
| | | } |
| | | if (options.nirPath === undefined || options.nirPath === null || options.nirPath.length < 1) { |
| | | throw new Error("dxFace.init: 'nirPath' parameter should not be null or empty") |
| | | } |
| | | if (capturerRgbId === undefined || capturerRgbId === null || capturerRgbId.length < 1) { |
| | | throw new Error("dxFace.init: 'capturerRgbId' parameter should not be null or empty") |
| | | } |
| | | if (capturerNirId === undefined || capturerNirId === null || capturerNirId.length < 1) { |
| | | throw new Error("dxFace.init: 'capturerNirId' parameter should not be null or empty") |
| | | } |
| | | capturerRgbId = dxCommon.handleId("capturer", capturerRgbId) |
| | | capturerNirId = dxCommon.handleId("capturer", capturerNirId) |
| | | |
| | | return faceObj.init(options, capturerRgbId, capturerNirId); |
| | | } |
| | | /** |
| | | * 人è¸å¤çå»åå§å |
| | | * @returns true/false |
| | | */ |
| | | face.deinit = function () { |
| | | return faceObj.deinit(); |
| | | } |
| | | |
| | | /** |
| | | * 人è¸å·¥ä½æ¨¡å¼ |
| | | * @param {number} mode 工使¨¡å¼ï¼å¿
å¡«ï¼ 0 人è¸è¯å«æ¨¡å¼ï¼1 äººè¸æ³¨å模å¼ï¼ |
| | | * @returns true/false |
| | | */ |
| | | face.setRecgMode = function (mode) { |
| | | if (mode === undefined || mode === null) { |
| | | throw new Error("dxFace.setRecgMode: 'mode' parameter should not be null or empty") |
| | | } |
| | | return faceObj.setRecgMode(mode) |
| | | } |
| | | /** |
| | | * äººè¸æ³¨å |
| | | * @param {string} userId 人åIDï¼å¿
å¡« |
| | | * @param {string} feature ç¹å¾å¼ base64å符串ï¼å¿
å¡« |
| | | * @returns 0:æå/é0:失败 |
| | | */ |
| | | face.addFaceFeatures = function (userId, feature) { |
| | | if (userId === undefined || userId === null) { |
| | | throw new Error("dxFace.addFaceFeatures: 'userId' parameter should not be null or empty") |
| | | } |
| | | if (feature === undefined || feature === null) { |
| | | throw new Error("dxFace.addFaceFeatures: 'feature' parameter should not be null or empty") |
| | | } |
| | | |
| | | return faceObj.addFaceFeatures(userId, feature) |
| | | } |
| | | /** |
| | | * 人è¸ç¹å¾å¼å¯¹æ¯ |
| | | * @param {string} feature ç¹å¾å¼ base64å符串ï¼å¿
å¡« |
| | | * @param {string} score æ¯å¯¹éå¼ï¼éå¿
å¡«ï¼é»è®¤0.6 |
| | | * @returns string userId |
| | | */ |
| | | face.faceFeatureCompare = function (feature, score) { |
| | | if (feature === undefined || feature === null) { |
| | | throw new Error("dxFace.faceFeatureCompare: 'feature' parameter should not be null or empty") |
| | | } |
| | | return faceObj.faceFeatureCompare(feature, score) |
| | | } |
| | | /** |
| | | * æ´æ°é
ç½® |
| | | * @param {object} options 注ååæ°ï¼ç±æ³¨ååè°è·åï¼åèface.addFaceFeaturesæ¹æ³ |
| | | * @returns true/false |
| | | */ |
| | | face.faceUpdateConfig = function (options) { |
| | | if (options === null || options === undefined) { |
| | | throw new Error("dxFace.faceUpdateConfig: 'options' parameter should not be null or empty") |
| | | } |
| | | return faceObj.faceUpdateConfig(options) |
| | | } |
| | | /** |
| | | * 人è¸å é¤ |
| | | * @param {string} userId 人åIDï¼å¿
å¡« |
| | | * @returns true/false |
| | | */ |
| | | face.deleteFaceFeatures = function (userId) { |
| | | if (userId === null || userId === undefined) { |
| | | throw new Error("dxFace.deleteFaceFeatures: 'userId' parameter should not be null or empty") |
| | | } |
| | | return faceObj.deleteFaceFeatures(userId) |
| | | } |
| | | /** |
| | | * æ ¹æ®ç
§çè·¯å¾åuserId注åäººè¸ |
| | | * @param {string} userId ç¨æ·idï¼å¿
å¡« |
| | | * @param {string} picPath ç
§çè·¯å¾ï¼å¿
å¡« |
| | | * @returns true/false |
| | | */ |
| | | face.registerFaceByPicFile = function (userId, picPath) { |
| | | if (userId === undefined || userId === null || userId.length < 1) { |
| | | throw new Error("dxFace.registerFaceByPicFile: 'userId' parameter should not be null or empty") |
| | | } |
| | | if (picPath === undefined || picPath === null || picPath.length < 1) { |
| | | throw new Error("dxFace.registerFaceByPicFile: 'picPath' parameter should not be null or empty") |
| | | } |
| | | return faceObj.registerFaceByPicFile(userId, picPath) |
| | | } |
| | | /** |
| | | * 人è¸çº¿ç¨å¯ç¨/ç¦ç¨ï¼åè½å¼å
³ |
| | | * @param {bool} en å¯ç¨ãç¦ç¨ï¼å¿
å¡« |
| | | * @returns true/false |
| | | */ |
| | | face.faceSetEnable = function (en) { |
| | | if (en === undefined || en === null) { |
| | | throw new Error("dxFace.faceSetEnable: 'en' parameter should not be null or empty") |
| | | } |
| | | return faceObj.detectSetEnable(en ? 0 : -1) |
| | | } |
| | | |
| | | /** |
| | | * é置人è¸ç¶æ |
| | | * @returns |
| | | */ |
| | | face.resetFaceStatus = function () { |
| | | return faceObj.resetFaceStatus() |
| | | } |
| | | |
| | | /** |
| | | * æ¸
ç©ºäººè¸æ°æ® |
| | | * @returns true/false |
| | | */ |
| | | face.faceFeaturesClean = function () { |
| | | return faceObj.faceFeaturesClean() |
| | | } |
| | | |
| | | /** |
| | | * è·åå±å¹äº®åº¦ |
| | | * @returns number å±å¹äº®åº¦ |
| | | */ |
| | | face.getDisplayBacklight = function () { |
| | | return faceObj.getDisplayBacklight() |
| | | } |
| | | /** |
| | | * 设置å±å¹äº®åº¦ |
| | | * @param {number} light å±å¹äº®åº¦ï¼å¿
å¡« |
| | | * @returns true/false |
| | | */ |
| | | face.setDisplayBacklight = function (light) { |
| | | if (light === undefined || light === null) { |
| | | throw new Error("dxFace.setDisplayBacklight: 'light' parameter should not be null or empty") |
| | | } |
| | | return faceObj.setDisplayBacklight(light) |
| | | } |
| | | /** |
| | | * è·åå±å¹ç¶æ |
| | | * @returns number 0-ç¦ç¨ 1-å¯ç¨ |
| | | */ |
| | | face.getEnableStatus = function () { |
| | | return faceObj.getEnableStatus() |
| | | } |
| | | /** |
| | | * 设置å±å¹ç¶æ |
| | | * @param {number} enable 0-ç¦ç¨ 1-å¯ç¨ |
| | | * @returns true/false |
| | | */ |
| | | face.setEnableStatus = function (enable) { |
| | | if (enable === undefined || enable === null) { |
| | | throw new Error("dxFace.setEnableStatus: 'enable' parameter should not be null or empty") |
| | | } |
| | | return faceObj.setEnableStatus(enable) |
| | | } |
| | | /** |
| | | /** |
| | | * è·åå±å¹ç¶æ |
| | | * @returns number 0-NORMAL 1-STANDBY |
| | | */ |
| | | face.getPowerMode = function () { |
| | | return faceObj.getPowerMode() |
| | | } |
| | | /** |
| | | * 设置å±å¹ç¶æ |
| | | * @param {number} mode 0-NORMAL 1-STANDBY |
| | | * @returns true/false |
| | | */ |
| | | face.setPowerMode = function (mode) { |
| | | if (mode === undefined || mode === null) { |
| | | throw new Error("dxFace.setPowerMode: 'mode' parameter should not be null or empty") |
| | | } |
| | | return faceObj.setPowerMode(mode) |
| | | } |
| | | /** |
| | | * è·åç¯å¢å
|
| | | * @returns number ç¯å¢å
亮度 |
| | | */ |
| | | face.getEnvBrightness = function () { |
| | | return faceObj.getEnvBrightness() |
| | | } |
| | | /** |
| | | * è·å人è¸åæ |
| | | * @returns string 人è¸åæ JSON |
| | | */ |
| | | face.getTrackingBox = function () { |
| | | return faceObj.getTrackingBox() |
| | | } |
| | | /** |
| | | * æ¥è¯¢ç¨æ·æ»æ° |
| | | * @returns number |
| | | */ |
| | | face.selectCount = function () { |
| | | return faceObj.selectFaceFeatures(1) |
| | | } |
| | | /** |
| | | * æ¥è¯¢ææuserId |
| | | * @returns JSON |
| | | */ |
| | | face.selectAll = function () { |
| | | return faceObj.selectFaceFeatures(2) |
| | | } |
| | | /** |
| | | * å¤æç¨æ·æ¯å¦åå¨ |
| | | * @returns true/false |
| | | */ |
| | | face.userExist = function (userId) { |
| | | return faceObj.selectFaceFeatures(3, userId) |
| | | } |
| | | /** |
| | | * 夿faceæ¶æ¯é忝å¦ä¸ºç©º |
| | | * @returns true/false |
| | | */ |
| | | face.msgIsEmpty = function () { |
| | | return faceObj.msgIsEmpty() |
| | | } |
| | | /** |
| | | * ä»faceæ¶æ¯éåä¸è¯»åæ°æ® |
| | | * @returns json |
| | | */ |
| | | face.msgReceive = function () { |
| | | return JSON.parse(faceObj.msgReceive()); |
| | | } |
| | | |
| | | face.RECEIVE_MSG = '__face__MsgReceive' |
| | | |
| | | /** |
| | | * ç¨äºç®åfaceç»ä»¶å¾®å
éä¿¡åè®®ç使ç¨ï¼æfaceå°è£
å¨è¿ä¸ªworkeréï¼ä½¿ç¨è
åªéè¦è®¢é
eventbusçäºä»¶å°±å¯ä»¥çå¬face |
| | | */ |
| | | face.run = function () { |
| | | let workerFile = '/app/code/dxmodules/faceWorker.js' |
| | | bus.newWorker('__face', workerFile) |
| | | } |
| | | |
| | | /** |
| | | * 妿faceåç¬ä¸ä¸ªçº¿ç¨ï¼å¯ä»¥ç´æ¥ä½¿ç¨run彿°ï¼ä¼èªå¨å¯å¨ä¸ä¸ªçº¿ç¨ï¼ |
| | | * 妿æ³å å
¥å°å
¶ä»å·²æç线ç¨ï¼å¯ä»¥ä½¿ç¨ä»¥ä¸å°è£
ç彿° |
| | | */ |
| | | face.worker = { |
| | | //å¨while循ç¯å |
| | | beforeLoop: function (options) { |
| | | // 人è¸ç®æ³åå§å |
| | | face.init(options, options.capturerRgbId, options.capturerNirId) |
| | | }, |
| | | //å¨while循ç¯é |
| | | loop: function () { |
| | | if (!face.msgIsEmpty()) { |
| | | let res = face.msgReceive(); |
| | | bus.fire(face.RECEIVE_MSG, res) |
| | | } |
| | | } |
| | | } |
| | | |
| | | export default face; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | // build : 20240524 |
| | | // gpio è¾åº,åªè½è¾åº2ç§ç¶æï¼é«çµå¹³/ä½çµå¹³ï¼å¦ææ¥å
¥ç»§çµå¨ï¼åé«çµå¹³æ¯å¼ï¼ä½çµå¹³æ¯å
³ |
| | | import { gpioClass } from './libvbar-b-dxgpio.so' |
| | | const gpioObj = new gpioClass(); |
| | | const gpio = {} |
| | | |
| | | /** |
| | | * åå§å,åªéè¦æ§è¡ä¸æ¬¡å³å¯ |
| | | * @returns true/false |
| | | */ |
| | | gpio.init = function () { |
| | | return gpioObj.init(); |
| | | } |
| | | |
| | | /** |
| | | * éæ¾gpioèµæº |
| | | * @returns true/false |
| | | */ |
| | | gpio.deinit = function () { |
| | | return gpioObj.exit(); |
| | | } |
| | | |
| | | /** |
| | | * ç³è¯·gpio,æ¯ä¸ªgpioåªéè¦ç³è¯·ä¸æ¬¡ |
| | | * @param {number} gpioçæ è¯ï¼ä¸åç设å¤ä¸åçæ è¯ï¼å¿
å¡« |
| | | * @returns true/false |
| | | */ |
| | | gpio.request = function (gpio_) { |
| | | let res = gpioObj.request(gpio_) |
| | | if (!res) { |
| | | return res |
| | | } |
| | | gpioObj.setFunc(gpio_, 0x04); |
| | | return true |
| | | } |
| | | |
| | | /** |
| | | * éæ¾æå®gpio |
| | | * @param {number} gpioçæ è¯ï¼ä¸åç设å¤ä¸åçæ è¯ï¼å¿
å¡« |
| | | * @returns true/false |
| | | */ |
| | | gpio.free = function (gpio_) { |
| | | return gpioObj.free(gpio_); |
| | | } |
| | | |
| | | /** |
| | | * æå®gpioè¾åºé«/ä½çµå¹³ |
| | | * @param {number} gpioçæ è¯ï¼ä¸åç设å¤ä¸åçæ è¯ï¼å¿
å¡« |
| | | * @param {number} value åªè½æ¯1å0ï¼1表示é«çµå¹³ï¼0表示ä½çµå¹³ï¼ç¼ºçæ¯é«çµå¹³ï¼å¿
å¡« |
| | | * @returns true/false |
| | | */ |
| | | gpio.setValue = function (gpio_, value) { |
| | | return gpioObj.setValue(gpio_, value); |
| | | } |
| | | |
| | | /** |
| | | * è·åæå®gpioå½åçè¾åº ï¼é«/ä½çµå¹³ |
| | | * @param {number} gpioçæ è¯ï¼ä¸åç设å¤ä¸åçæ è¯ï¼å¿
å¡« |
| | | * @returns 1å0ï¼1表示é«çµå¹³ï¼0表示ä½çµå¹³ |
| | | */ |
| | | gpio.getValue = function (gpio_) { |
| | | return gpioObj.getValue(gpio_); |
| | | } |
| | | |
| | | /** |
| | | * ç³è¯·gpio,æ¯ä¸ªgpioåªéè¦ç³è¯·ä¸æ¬¡ |
| | | * @param {number} gpioçæ è¯ï¼ä¸åç设å¤ä¸åçæ è¯ï¼å¿
å¡« |
| | | * @returns true/false |
| | | */ |
| | | gpio.requestGpio = function (gpio_) { |
| | | let res = gpioObj.request(gpio_) |
| | | return res |
| | | } |
| | | |
| | | /** |
| | | * 设置gpioåè½ |
| | | * @param {number} gpioçæ è¯ï¼ä¸åç设å¤ä¸åçæ è¯ï¼å¿
å¡« |
| | | * @param {number} gpioåè½å±æ§ï¼ä¸åç设å¤ä¸åçåè½å±æ§ï¼å¿
å¡« |
| | | * @returns true/false |
| | | */ |
| | | gpio.setFuncGpio = function (gpio_, func) { |
| | | let res = gpioObj.setFunc(gpio_, func) |
| | | return res |
| | | } |
| | | |
| | | /** |
| | | * 设置æå®gpioä¸æç¶æ |
| | | * @param {number} gpioçæ è¯ï¼ä¸åç设å¤ä¸åçæ è¯ï¼å¿
å¡« |
| | | * @param {number} state ä¸æç¶æï¼å¿
å¡« |
| | | * @returns true/false |
| | | */ |
| | | gpio.setPullState = function (gpio_, state) { |
| | | return gpioObj.setPullState(gpio_, state); |
| | | } |
| | | |
| | | /** |
| | | * è·åæå®gpioä¸æç¶æ |
| | | * @param {number} gpioçæ è¯ï¼ä¸åç设å¤ä¸åçæ è¯ï¼å¿
å¡« |
| | | * @returns ä¸æç¶æ(int) |
| | | */ |
| | | gpio.getPullState = function (gpio_) { |
| | | return gpioObj.getPullState(gpio_); |
| | | } |
| | | /** |
| | | * 设置æå®gpioç驱å¨è½å |
| | | * @param {number} gpioçæ è¯ï¼ä¸åç设å¤ä¸åçæ è¯ï¼å¿
å¡« |
| | | * @param {number} strength è½åï¼å¿
å¡« |
| | | * @returns true/false |
| | | */ |
| | | gpio.setDriveStrength = function (gpio_, strength) { |
| | | return gpioObj.setDriveStrength(gpio_, strength); |
| | | } |
| | | |
| | | /** |
| | | * è·åæå®gpioç驱å¨è½å |
| | | * @param {number} gpioçæ è¯ï¼ä¸åç设å¤ä¸åçæ è¯ï¼å¿
å¡« |
| | | * @returns è½å(int) |
| | | */ |
| | | gpio.getDriveStrength = function (gpio_) { |
| | | return gpioObj.getDriveStrength(gpio_); |
| | | } |
| | | |
| | | export default gpio; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //build 20240524 |
| | | //æ¥å gpio çè¾å
¥ |
| | | //ä¾èµç»ä»¶: dxLogger,dxDriver,dxEventBus |
| | | import { gpioKeyClass } from './libvbar-m-dxkey.so' |
| | | import bus from './dxEventBus.js' |
| | | import * as os from "os"; |
| | | const gpioKeyObj = new gpioKeyClass(); |
| | | const gpioKey = {} |
| | | |
| | | /** |
| | | * gpioKey åå§å |
| | | * @returns true:æå,false:失败 |
| | | */ |
| | | gpioKey.init = function () { |
| | | const res = gpioKeyObj.init() |
| | | if (res) { |
| | | gpioKeyObj.registerCb("gpioKeyCb") |
| | | } |
| | | return res |
| | | } |
| | | |
| | | /** |
| | | * gpioKey åæ¶åå§å |
| | | * @returns true:æå,false:失败 |
| | | */ |
| | | gpioKey.deinit = function () { |
| | | gpioKeyObj.unRegisterCb("gpioKeyCb") |
| | | return gpioKeyObj.deinit() |
| | | } |
| | | |
| | | /** |
| | | * 夿gpioKeyæ¶æ¯é忝å¦ä¸ºç©º |
| | | * @returns true:æå,false:失败 |
| | | */ |
| | | gpioKey.msgIsEmpty = function () { |
| | | return gpioKeyObj.msgIsEmpty() |
| | | } |
| | | |
| | | /** |
| | | * ä»gpioKeyæ¶æ¯éåä¸è¯»åæ°æ® |
| | | * @returns jsonæ¶æ¯å¯¹è±¡ï¼æ ¼å¼ï¼{"code":30,"type":1,"value":1} |
| | | */ |
| | | gpioKey.msgReceive = function () { |
| | | let msg = gpioKeyObj.msgReceive() |
| | | return JSON.parse(msg); |
| | | } |
| | | |
| | | gpioKey.RECEIVE_MSG = '__gpioKey__MsgReceive' |
| | | |
| | | /** |
| | | * ç®ågpiokeyç»ä»¶ç使ç¨ï¼æ é轮询å»è·åæ°æ®ï¼æ°æ®ä¼éè¿eventbusåéåºå» |
| | | * run åªä¼æ§è¡ä¸æ¬¡ |
| | | * 妿éè¦å®æ¶è·åæ°æ®ï¼å¯ä»¥è®¢é
eventbusçäºä»¶ï¼äºä»¶çtopicæ¯GPIO_KEYï¼äºä»¶çå
容æ¯ç±»ä¼¼{"code":30,"type":1,"value":1} |
| | | * å
¶ä¸codeæ¯gpioçæ è¯ï¼è¡¨ç¤ºæ¯é£ä¸ªgpioæè¾å
¥ï¼valueå¼åªè½æ¯0ï¼1é常表示ä½çµå¹³åé«çµå¹³ |
| | | * typeæ¯äºä»¶ç±»åï¼éµå¾ªLinuxçæ åè¾å
¥è§å®,以ä¸ååºå¸¸ç¨å ä¸ªï¼ |
| | | (0x01):æé®äºä»¶ï¼å
æ¬ææçé®çåæé®äºä»¶ãä¾å¦ï¼å½æä¸æéæ¾é®çä¸çä¸ä¸ªé®æ¶ï¼å°æ¥åæ¤ç±»äºä»¶ã |
| | | (0x05):å¼å
³äºä»¶ï¼ä¾å¦ç¬è®°æ¬çµèççå¼å
³å¯ä»¥æ¥åå¼åç¶æã |
| | | (Ox11):LEDäºä»¶ï¼ç¨äºæ§å¶è®¾å¤ä¸çLEDæç¤ºç¯ï¼ |
| | | (Ox12):声é³äºä»¶ï¼ç¨äºæ§å¶è®¾å¤ä¸ç声é³è¾åºï¼ |
| | | (0x16):çµæºäºä»¶ï¼å¯ä»¥ç¨äºæ¥åçµæºæé®äºä»¶æçµæ± çµéä½ |
| | | * |
| | | */ |
| | | gpioKey.run = function () { |
| | | bus.newWorker("__gpiokey", '/app/code/dxmodules/gpioKeyWorker.js') |
| | | } |
| | | |
| | | /** |
| | | * 妿gpioKeyåç¬ä¸ä¸ªçº¿ç¨ï¼å¯ä»¥ç´æ¥ä½¿ç¨run彿°ï¼ä¼èªå¨å¯å¨ä¸ä¸ªçº¿ç¨ï¼ |
| | | * 妿æ³å å
¥å°å
¶ä»å·²æç线ç¨ï¼å¯ä»¥ä½¿ç¨ä»¥ä¸å°è£
ç彿° |
| | | */ |
| | | gpioKey.worker = { |
| | | //å¨while循ç¯å |
| | | beforeLoop: function () { |
| | | gpioKey.init() |
| | | }, |
| | | //å¨while循ç¯é |
| | | loop: function () { |
| | | if (!gpioKey.msgIsEmpty()) { |
| | | let res = gpioKey.msgReceive(); |
| | | bus.fire(gpioKey.RECEIVE_MSG, res) |
| | | } |
| | | } |
| | | } |
| | | export default gpioKey; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | // http客æ·ç«¯ç»ä»¶ |
| | | import { httpClass } from './libvbar-m-dxhttp.so' |
| | | |
| | | const httpObj = new httpClass(); |
| | | |
| | | const http = { |
| | | |
| | | HTTP_METHOD : { |
| | | GET: "GET", |
| | | POST: "POST", |
| | | PUT: "PUT", |
| | | DELETE: "DELETE", |
| | | HEAD: "HEAD", |
| | | OPTIONS: "OPTIONS", |
| | | PATCH: "PATCH" |
| | | }, |
| | | HTTP_FORMAT : { |
| | | JSON: "JSON", |
| | | FORM: "FORM", |
| | | URLENCODE: "URLENCODE" |
| | | }, |
| | | HTTP_FORM_TYPE : { |
| | | STRING: "STRING", |
| | | FILE: "FILE" |
| | | }, |
| | | /** |
| | | * getè¯·æ± |
| | | * @param {string} url |
| | | * @param {array} headers éå¿
å¡«ï¼ä¼æé»è®¤å¡«å
request headers |
| | | * @param {number} timeout éå¿
å¡«ï¼ è¶
æ¶æ¶é´ |
| | | * @returns |
| | | */ |
| | | get: function (url, headers, timeout) { |
| | | if (!url) { |
| | | throw new Error("url should not be null or empty") |
| | | } |
| | | return httpObj.request({ method: 0, url: url, headers: headers, timeout: timeout}) |
| | | }, |
| | | /** |
| | | * post请æ±,data为json/formè¡¨åæ°ç»æ ¼å¼ |
| | | * @param {string} url |
| | | * @param {array} data |
| | | * @param {array} headers éå¿
å¡«ï¼ä¼æé»è®¤å¡«å
request headers |
| | | * @param {number} timeout éå¿
å¡«ï¼ è¶
æ¶æ¶é´ |
| | | * @returns |
| | | */ |
| | | post: function (url, data, headers, timeout, format = "JSON") { |
| | | if (!url) { |
| | | throw new Error("url should not be null or empty") |
| | | } |
| | | if (!data) { |
| | | throw new Error("data should not be null or empty") |
| | | } |
| | | if (typeof data != 'string' && format != "FORM") { |
| | | data = JSON.stringify(data) |
| | | } |
| | | if(format == "JSON"){ |
| | | return httpObj.request({ method: 1, url: url, data: data, headers: headers, timeout: timeout}) |
| | | }else{ |
| | | return httpObj.request({ method: 1, url: url, formData: data, headers: headers, timeout: timeout}) |
| | | } |
| | | }, |
| | | /** |
| | | * put请æ±,data为json/formè¡¨åæ°ç»æ ¼å¼ |
| | | * @param {string} url |
| | | * @param {array} data |
| | | * @param {array} headers éå¿
å¡«ï¼ä¼æé»è®¤å¡«å
request headers |
| | | * @param {number} timeout éå¿
å¡«ï¼ è¶
æ¶æ¶é´ |
| | | * @returns |
| | | */ |
| | | put: function (url, data, headers, timeout, format = "JSON") { |
| | | if (!url) { |
| | | throw new Error("url should not be null or empty") |
| | | } |
| | | if (!data) { |
| | | throw new Error("data should not be null or empty") |
| | | } |
| | | if (typeof data != 'string' && format != "FORM") { |
| | | data = JSON.stringify(data) |
| | | } |
| | | if(format == "JSON"){ |
| | | return httpObj.request({ method: 2, url: url, data: data, headers: headers, timeout: timeout}) |
| | | }else{ |
| | | return httpObj.request({ method: 2, url: url, formData: data, headers: headers, timeout: timeout}) |
| | | } |
| | | }, |
| | | /** |
| | | * deleteè¯·æ± |
| | | * @param {string} url |
| | | * @param {array} headers éå¿
å¡«ï¼ä¼æé»è®¤å¡«å
request headers |
| | | * @param {number} timeout éå¿
å¡«ï¼ è¶
æ¶æ¶é´ |
| | | * @returns |
| | | */ |
| | | delete: function (url, headers, timeout) { |
| | | if (!url) { |
| | | throw new Error("url should not be null or empty") |
| | | } |
| | | return httpObj.request({ method: 3, url: url, headers: headers, timeout: timeout}) |
| | | }, |
| | | /** |
| | | * ä¸è½½æä»¶ï¼æ¬è´¨æ¯getè¯·æ± |
| | | * @param {string} url |
| | | * @param {string} path ç®æ è·¯å¾(ç»å¯¹è·¯å¾) |
| | | * @param {array} headers éå¿
å¡«ï¼ä¼æé»è®¤å¡«å
request headers |
| | | * @param {number} timeout éå¿
å¡«ï¼ è¶
æ¶æ¶é´ |
| | | * @returns ä¸è½½æä»¶æå¯è½è¿ånullï¼ä½æ¯ä¸è½½æ¯æåç |
| | | */ |
| | | download: function (url, path, headers, timeout) { |
| | | if (!url) { |
| | | throw new Error("url should not be null or empty") |
| | | } |
| | | if (!path) { |
| | | throw new Error("path should not be null or empty") |
| | | } |
| | | return httpObj.request({ method: 0, url: url, headers: headers, download: path, timeout: timeout }) |
| | | }, |
| | | |
| | | /** |
| | | * ä¸ä¼ æä»¶ï¼æ¬è´¨æ¯postè¯·æ± |
| | | * @param {string} url |
| | | * @param {string} path æºè·¯å¾(ç»å¯¹è·¯å¾) |
| | | * @returns |
| | | */ |
| | | upload: function (url, path) { |
| | | if (!url) { |
| | | throw new Error("url should not be null or empty") |
| | | } |
| | | if (!path) { |
| | | throw new Error("path should not be null or empty") |
| | | } |
| | | return httpObj.request({ |
| | | method: 1, |
| | | url: url, |
| | | headers: ["application/x-www-form-urlencoded; charset=UTF-8"], |
| | | upload: path |
| | | }) |
| | | }, |
| | | /** |
| | | * åçæ¹å¼ |
| | | * å¿
å¡«åæ°ï¼methodï¼0ï¼get请æ±ï¼1ï¼post请æ±ï¼ãurl |
| | | * å¯éåæ°ï¼headers(å符串æ°ç»ï¼è¦çé»è®¤header)ãdownloadï¼æä»¶ä¸è½½å°åï¼ãdata(è¯·æ±æ¥æï¼post请æ±å¿
å¡«)ãtimeout(è¶
æ¶æ¶é´/ms,缺ç:5000)ãdns(缺ç:"114.114.114.114,8.8.8.8")ãupload |
| | | * é»è®¤headerï¼Accept-Charset:utf-8ãContent-Type:application/json;charset=utf-8ãConnection:close |
| | | * @param {object} param json |
| | | * å¦ï¼let param={ |
| | | method:0, |
| | | url:"http://192.168.10.122:8000/DW200_1_0.zip", |
| | | download:"/testNet/aaa" |
| | | } |
| | | * @returns |
| | | */ |
| | | request: function (param) { |
| | | return httpObj.request(param) |
| | | } |
| | | } |
| | | export default http; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | /** |
| | | * dxLogger module |
| | | * To replace the `console.log` function, allowing logs to be viewed in the corresponding VSCode plugin during debugging, |
| | | * with support for three levels of logging: `debug`,`info`, and `error`. |
| | | * Supports printing various data types in JavaScript. |
| | | */ |
| | | import dxCommon from './dxCommon.js' |
| | | const logger = {} |
| | | |
| | | logger.config = { |
| | | level: 0, // default is all,if<0,no print |
| | | } |
| | | logger.debug = function (...data) { |
| | | if (this.config.level === 0) { |
| | | log("DEBUG ", data) |
| | | } |
| | | } |
| | | logger.info = function (...data) { |
| | | if ([0, 1].includes(this.config.level)) { |
| | | log("INFO ", data) |
| | | } |
| | | } |
| | | logger.error = function (...data) { |
| | | if ([0, 1, 2].includes(this.config.level)) { |
| | | log("ERROR ", data) |
| | | } |
| | | } |
| | | //-----------------------------------private---------------------- |
| | | function log(level, messages) { |
| | | let message = messages.map(msg => getContent(msg)).join(' '); |
| | | let content = `[${level}${getTime()}]: ${message}` |
| | | dxCommon.systemBrief(`echo '${content}'`) |
| | | } |
| | | function getContent(message) { |
| | | if (message === undefined) { |
| | | return 'undefined' |
| | | } else if (message === null) { |
| | | return 'null' |
| | | } |
| | | if ((typeof message) == 'object') { |
| | | if (Object.prototype.toString.call(message) === '[object Error]') { |
| | | return message.message + '\n' + message.stack |
| | | } |
| | | return JSON.stringify(message) |
| | | } |
| | | return message |
| | | } |
| | | function getTime() { |
| | | const now = new Date(); |
| | | const year = now.getFullYear(); |
| | | const month = ('0' + (now.getMonth() + 1)).slice(-2); |
| | | const day = ('0' + now.getDate()).slice(-2); |
| | | const hours = ('0' + now.getHours()).slice(-2); |
| | | const minutes = ('0' + now.getMinutes()).slice(-2); |
| | | const seconds = ('0' + now.getSeconds()).slice(-2); |
| | | const milliseconds = ('0' + now.getMilliseconds()).slice(-3); |
| | | return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds + '.' + milliseconds; |
| | | } |
| | | export default logger |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | import { mapClass } from './libvbar-m-dxmap.so' |
| | | /** |
| | | * build:20240407 |
| | | * map ç»ä»¶ï¼å¯ä»¥å¨å
åé读åkey/value |
| | | */ |
| | | const mapObj = new mapClass(); |
| | | |
| | | const map = { |
| | | get: function (name) { |
| | | if (!name || name.length == 0) { |
| | | throw new Error("dxMap.get:name should not be null or empty") |
| | | } |
| | | //ç¬¬ä¸æ¬¡putä¼èªå¨å建å®ä¾ |
| | | return { |
| | | /** |
| | | * @brief è·åMapä¸çææé®,è¿åä¸ä¸ªæ°ç» |
| | | */ |
| | | keys: function () { |
| | | let all = mapObj.keys(name) |
| | | return all == null ? [] : all |
| | | }, |
| | | /** |
| | | * @brief æ ¹æ®keyè·åvalue |
| | | */ |
| | | get: function (key) { |
| | | if (!key || key.length < 1) { |
| | | throw new Error("The 'key' parameter cannot be null or empty") |
| | | } |
| | | // put空å符串ï¼get伿¯null |
| | | let value = mapObj.get(name, key) |
| | | if (value === undefined || value === null) { |
| | | value = "" |
| | | } |
| | | return _parseString(value) |
| | | }, |
| | | /** |
| | | * @brief åMap䏿å
¥é®å¼å¯¹ |
| | | */ |
| | | put: function (key, value) { |
| | | if (!key || key.length < 1) { |
| | | throw new Error("The 'key' parameter cannot be null or empty") |
| | | } |
| | | if (value == null || value == undefined) { |
| | | throw new Error("The 'value' parameter cannot be null or empty") |
| | | } |
| | | return mapObj.insert(name, key, _stringifyValue(value)) |
| | | }, |
| | | /** |
| | | * @brief æ ¹æ®Keyå é¤é®å¼å¯¹ |
| | | */ |
| | | del: function (key) { |
| | | if (!key || key.length < 1) { |
| | | throw new Error("The 'key' parameter cannot be null or empty") |
| | | } |
| | | return mapObj.delete(name, key) |
| | | }, |
| | | /** |
| | | * ä¸å使ç¨äºï¼å°±éæ¯ |
| | | */ |
| | | destroy: function () { |
| | | return mapObj.destroy(name) |
| | | }, |
| | | } |
| | | } |
| | | |
| | | } |
| | | function _stringifyValue(value) { |
| | | const type = typeof value |
| | | if (type === 'string') { |
| | | return value |
| | | } |
| | | if (type === 'number') { |
| | | return '#n#' + value |
| | | } |
| | | if (type === 'boolean') { |
| | | return '#b#' + value |
| | | } |
| | | if (type === 'object') { |
| | | // 妿æ¯å¯¹è±¡ï¼è¿ä¸æ¥å¤ææ¯å¦ä¸ºæ°ç» |
| | | if (Array.isArray(value)) { |
| | | return '#a#' + JSON.stringify(value); |
| | | }// else if (value === null) { åé¢å·²ç»è§é¿äºnullçæ
åµ |
| | | return '#o#' + JSON.stringify(value) |
| | | } |
| | | if (type === 'function') { |
| | | throw new Error("The 'value' parameter should not be function") |
| | | } |
| | | } |
| | | function _parseString(str) { |
| | | if (str.startsWith('#n#')) { |
| | | // è§£ææ°å |
| | | const numberStr = str.substring(3); |
| | | return numberStr.includes('.') ? parseFloat(numberStr) : parseInt(numberStr, 10); |
| | | } else if (str.startsWith('#b#')) { |
| | | // è§£æå¸å°å¼ |
| | | return str.substring(3) === 'true'; |
| | | } else if (str.startsWith('#a#')) { |
| | | // è§£ææ°ç» |
| | | return JSON.parse(str.substring(3)); |
| | | } else if (str.startsWith('#o#')) { |
| | | // è§£æå¯¹è±¡ |
| | | return JSON.parse(str.substring(3)); |
| | | } else { |
| | | // é»è®¤æ
åµä¸ï¼å°å符串è¿å |
| | | return str; |
| | | } |
| | | } |
| | | export default map; |
| | | |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //build:20240411 |
| | | //å©ç¨mqttåè®®å®ç°åmqttæå¡ç«¯çéä¿¡æéè¿mqtt brokerå®ç°åå
¶å®mqtt客æ·ç«¯çéä¿¡ |
| | | //ä¾èµç»ä»¶ dxMap,dxLogger,dxDriver,dxCommon,dxEventBus,dxNet |
| | | import { mqttClass } from './libvbar-m-dxmqtt.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 map = dxMap.get("default") |
| | | const mqttObj = new mqttClass(); |
| | | const mqtt = {} |
| | | /** |
| | | * åå§åmqttç¸å
³å±æ§å¹¶åå»ºè¿æ¥,请å¨workeré使ç¨dxMqttç»ä»¶æä½¿ç¨ç®å彿°dxMqtt.run |
| | | * @param {string} mqttAddr mqttæå¡å°åï¼å¿
å¡«ï¼ä»¥tcp://å¼å¤´ï¼æ ¼å¼æ¯tcp://ip:port |
| | | * @param {string} clientId 客æ·ç«¯idï¼å¿
å¡«ï¼ä¸åç设å¤è¯·ä½¿ç¨ä¸åç客æ·ç«¯id |
| | | * @param {string} username éå¿
å¡«ï¼mqttç¨æ·å |
| | | * @param {string} password éå¿
å¡«ï¼mqttå¯ç |
| | | * @param {string} prefix éå¿
å¡«ï¼ç¼ºç为空å符串ï¼è¿ä¸ªè¡¨ç¤ºèªå¨å¨ä¸»é¢åå ä¸ä¸ä¸ªåç¼ |
| | | * @param {number} qos 0,1,2 éå¿
å¡«ï¼ç¼ºçæ¯1. å
¶ä¸0è¡¨ç¤ºæ¶æ¯æå¤åé䏿¬¡ï¼åéåæ¶æ¯å°±è¢«ä¸¢å¼;1è¡¨ç¤ºæ¶æ¯è³å°åé䏿¬¡ï¼å¯ä»¥ä¿è¯æ¶æ¯è¢«æ¥æ¶æ¹æ¶å°ï¼ä½æ¯ä¼å卿¥æ¶æ¹æ¶å°é夿¶æ¯çæ
åµ;2è¡¨ç¤ºæ¶æ¯åéæåä¸åªåé䏿¬¡,èµæºå¼é大 |
| | | * @param {string} willTopic éå¿
å¡«ï¼éå±ä¸»é¢ï¼éè¿brokeréä¿¡çæ¶åè®¾å¤æå¼ä¼èªå¨è§¦åä¸ä¸ªmqtté屿¶æ¯ï¼è¿ä¸ªæ¯é屿¶æ¯çä¸»é¢ |
| | | * @param {string} willMessage éå¿
å¡«ï¼éå±å
容ï¼éè¿brokeréä¿¡çæ¶åè®¾å¤æå¼ä¼èªå¨è§¦åä¸ä¸ªmqtté屿¶æ¯ï¼è¿ä¸ªæ¯é屿¶æ¯çå
容 |
| | | * @param {string} id 奿idï¼éå¿
å¡«ï¼è¥åå§åå¤ä¸ªå®ä¾éè¦ä¼ å
¥å¯ä¸idï¼ |
| | | */ |
| | | mqtt.init = function (mqttAddr, clientId, username, password, prefix = "", qos = 1, willTopic, willMessage, id) { |
| | | |
| | | if (mqttAddr === undefined || mqttAddr.length === 0) { |
| | | throw new Error("dxMqtt.init: 'mqttAddr' parameter should not be null or empty") |
| | | } |
| | | if (clientId === undefined || clientId.length === 0) { |
| | | throw new Error("dxMqtt.init: 'clientId' parameter should not be null or empty") |
| | | } |
| | | // 妿mqttAddrä¸ä»¥tcp://å¼å¤´ï¼èªå¨æ·»å åç¼ |
| | | if (!mqttAddr.startsWith('tcp://')) { |
| | | mqttAddr = 'tcp://' + mqttAddr |
| | | } |
| | | let pointer = mqttObj.init(mqttAddr, clientId, username, password, prefix, qos, willTopic, willMessage); |
| | | if (pointer === undefined || pointer === null) { |
| | | throw new Error("dxMqtt.init: mqtt init failed") |
| | | } |
| | | |
| | | dxCommon.handleId("mqtt", id, pointer) |
| | | } |
| | | |
| | | /** |
| | | * éæ°è¿æ¥,æ¯å¦è¿æ¥æååçªç¶ç½ç»æå¼ï¼æ ééæ°initï¼ç´æ¥éè¿å³å¯ |
| | | * @param {string} willTopic éå¿
å¡«ï¼éå±ä¸»é¢ï¼éè¿brokeréä¿¡çæ¶åè®¾å¤æå¼ä¼èªå¨è§¦åä¸ä¸ªmqtté屿¶æ¯ï¼è¿ä¸ªæ¯é屿¶æ¯çä¸»é¢ |
| | | * @param {string} willMessage éå¿
å¡«ï¼éå±å
容ï¼éè¿brokeréä¿¡çæ¶åè®¾å¤æå¼ä¼èªå¨è§¦åä¸ä¸ªmqtté屿¶æ¯ï¼è¿ä¸ªæ¯é屿¶æ¯çå
容 |
| | | * @param {string} id 奿idï¼éå¿
å¡«ï¼éä¿æåinitä¸çidä¸è´ï¼ |
| | | */ |
| | | mqtt.reconnect = function (willTopic, willMessage, id) { |
| | | let pointer = dxCommon.handleId("mqtt", id) |
| | | return mqttObj.recreate(pointer, willTopic, willMessage); |
| | | } |
| | | |
| | | /** |
| | | * 订é
å¤ä¸»é¢ |
| | | * @param {array} topics å¿
å¡«ï¼ è¦è®¢é
ç䏻颿°ç»ï¼å¯ä»¥åæ¶è®¢é
å¤ä¸ª |
| | | * @param {number} qos éå¿
å¡«ï¼ç¼ºçæ¯1. å
¶ä¸0è¡¨ç¤ºæ¶æ¯æå¤åé䏿¬¡ï¼åéåæ¶æ¯å°±è¢«ä¸¢å¼;1è¡¨ç¤ºæ¶æ¯è³å°åé䏿¬¡ï¼å¯ä»¥ä¿è¯æ¶æ¯è¢«æ¥æ¶æ¹æ¶å°ï¼ä½æ¯ä¼å卿¥æ¶æ¹æ¶å°é夿¶æ¯çæ
åµ;2è¡¨ç¤ºæ¶æ¯åéæåä¸åªåé䏿¬¡,èµæºå¼é大 |
| | | * @param {string} id 奿idï¼éå¿
å¡«ï¼éä¿æåinitä¸çidä¸è´ï¼ |
| | | * @returns |
| | | */ |
| | | mqtt.subscribes = function (topics, qos, id) { |
| | | if (topics === undefined || topics.length === 0) { |
| | | throw new Error("dxMqtt.subscribes: 'topics' parameter should not be null or empty") |
| | | } |
| | | |
| | | if (qos === undefined) { |
| | | qos = 1 |
| | | } |
| | | let pointer = dxCommon.handleId("mqtt", id) |
| | | return mqttObj.subscribes(pointer, topics, qos); |
| | | } |
| | | |
| | | /** |
| | | * 夿mqttæ¯å¦è¿æ¥ï¼è¿æ¥æåå妿ç½ç»æå¼ï¼è¿æ¥ä¹ä¼æå¼ |
| | | * @param {string} id 奿idï¼éå¿
å¡«ï¼éä¿æåinitä¸çidä¸è´ï¼ |
| | | * @returns falseå¤±è´¥ï¼ trueæå |
| | | */ |
| | | mqtt.isConnected = function (id) { |
| | | let pointer = dxCommon.handleId("mqtt", id) |
| | | return mqttObj.isConnected(pointer); |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢mqtté
ç½® |
| | | * @param {string} id 奿idï¼éå¿
å¡«ï¼éä¿æåinitä¸çidä¸è´ï¼ |
| | | * @returns mqtté
ç½® |
| | | */ |
| | | mqtt.getConfig = function (id) { |
| | | let pointer = dxCommon.handleId("mqtt", id) |
| | | return mqttObj.getConfig(pointer); |
| | | } |
| | | |
| | | /** |
| | | * mqtté
ç½®æ´æ° |
| | | * @param {object} options é
ç½®åæ°ï¼å¤§é¨åå¯ä»¥ç¨é»è®¤å¼ |
| | | * @param {string} options.mqttAddr mqttæå¡å°åï¼å¿
å¡«ï¼ä»¥tcp://å¼å¤´ï¼æ ¼å¼æ¯tcp://ip:port |
| | | * @param {string} options.clientId 客æ·ç«¯idï¼å¿
å¡«ï¼ä¸åç设å¤è¯·ä½¿ç¨ä¸åç客æ·ç«¯id |
| | | * @param {string} options.userName éå¿
å¡«ï¼mqttç¨æ·å |
| | | * @param {string} options.password éå¿
å¡«ï¼mqttå¯ç |
| | | * @param {string} options.prefix éå¿
å¡«ï¼ç¼ºç为空å符串ï¼è¿ä¸ªè¡¨ç¤ºèªå¨å¨ä¸»é¢åå ä¸ä¸ä¸ªåç¼ |
| | | * @param {number} options.qos 0,1,2 éå¿
å¡«ï¼ç¼ºçæ¯1. å
¶ä¸0è¡¨ç¤ºæ¶æ¯æå¤åé䏿¬¡ï¼åéåæ¶æ¯å°±è¢«ä¸¢å¼;1è¡¨ç¤ºæ¶æ¯è³å°åé䏿¬¡ï¼å¯ä»¥ä¿è¯æ¶æ¯è¢«æ¥æ¶æ¹æ¶å°ï¼ä½æ¯ä¼å卿¥æ¶æ¹æ¶å°é夿¶æ¯çæ
åµ;2è¡¨ç¤ºæ¶æ¯åéæåä¸åªåé䏿¬¡,èµæºå¼é大 |
| | | * @param {string} options.ssl éå¿
å¡«ï¼sslé
置类 |
| | | */ |
| | | mqtt.updateConfig = function (options, id) { |
| | | if (!options) { |
| | | throw new Error("dxMqtt.updateConfig: 'options' parameter should not be null or empty") |
| | | } |
| | | if (options.mqttAddr === undefined || options.mqttAddr.length === 0) { |
| | | throw new Error("dxMqtt.updateConfig: 'options.mqttAddr' parameter should not be null or empty") |
| | | } |
| | | if (options.clientId === undefined || options.clientId.length === 0) { |
| | | throw new Error("dxMqtt.updateConfig: 'options.clientId' parameter should not be null or empty") |
| | | } |
| | | if (options.qos === undefined || options.qos == null) { |
| | | throw new Error("dxMqtt.updateConfig: 'options.qos' parameter should not be null or empty") |
| | | } |
| | | // 妿mqttAddrä¸ä»¥tcp://å¼å¤´ï¼èªå¨æ·»å åç¼ |
| | | if (!options.mqttAddr.startsWith('tcp://')) { |
| | | options.mqttAddr = 'tcp://' + options.mqttAddr |
| | | } |
| | | let pointer = dxCommon.handleId("mqtt", id) |
| | | let res = mqttObj.setConfig(pointer, options); |
| | | return res; |
| | | } |
| | | |
| | | /** |
| | | * åémqttè¯·æ± |
| | | * @param {string} topic 主é¢ï¼å¿
å¡« |
| | | * @param {string} payload æ¶æ¯ä½å
容ï¼å¿
å¡« |
| | | * @param {string} id 奿idï¼éå¿
å¡«ï¼éä¿æåinitä¸çidä¸è´ï¼ |
| | | */ |
| | | mqtt.send = function (topic, payload, id) { |
| | | if (topic === undefined || topic.length === 0) { |
| | | throw new Error("dxMqtt.send:'topic' parameter should not be null or empty") |
| | | } |
| | | if (payload === undefined || payload.length === 0) { |
| | | throw new Error("dxMqtt.send:'payload' parameter should not be null or empty") |
| | | } |
| | | let pointer = dxCommon.handleId("mqtt", id) |
| | | return mqttObj.sendMsg(pointer, topic, payload); |
| | | } |
| | | |
| | | /** |
| | | * æ¥æ¶mqttæ°æ®,éè¦è½®è¯¢å»è·å |
| | | * @param {string} id 奿idï¼éå¿
å¡«ï¼éä¿æåinitä¸çidä¸è´ï¼ |
| | | * @return mqttè¯·æ±æ°æ®ï¼ç»ææ¯: {topic:'主é¢',payload:'å
容'} |
| | | */ |
| | | mqtt.receive = function (id) { |
| | | let msg = mqttObj.msgReceive(id); |
| | | return JSON.parse(msg); |
| | | } |
| | | |
| | | /** |
| | | * 夿æ¯å¦ææ°çæ°æ®ï¼ä¸è¬å
å¤æææ°æ®ååè°ç¨receiveå»è·åæ°æ® |
| | | * @param {string} id 奿idï¼éå¿
å¡«ï¼éä¿æåinitä¸çidä¸è´ï¼ |
| | | * @returns false ææ°æ®ï¼true æ²¡ææ°æ® |
| | | */ |
| | | mqtt.msgIsEmpty = function (id) { |
| | | return mqttObj.msgIsEmpty(id); |
| | | } |
| | | |
| | | /** |
| | | * 鿝mqttå®ä¾ |
| | | * @param {string} id 奿idï¼éå¿
å¡«ï¼éä¿æåinitä¸çidä¸è´ï¼ |
| | | */ |
| | | mqtt.destroy = function (id) { |
| | | let pointer = dxCommon.handleId("mqtt", id) |
| | | mqttObj.deinit(pointer); |
| | | } |
| | | |
| | | mqtt.RECEIVE_MSG = '__mqtt__MsgReceive' |
| | | mqtt.CONNECTED_CHANGED = '__mqtt__Connect_changed' |
| | | mqtt.RECONNECT = '__mqtt__Reconnect' |
| | | |
| | | /** |
| | | * ç¨ç®åçæ¹å¼å®ç°mqtt客æ·ç«¯ï¼åªéè¦è°ç¨è¿ä¸ä¸ªå½æ°å°±å¯ä»¥å®ç°mqtt客æ·ç«¯ï¼ |
| | | * æ¶å°æ¶æ¯ä¼è§¦åç» dxEventBusåéä¸ä¸ªäºä»¶ï¼äºä»¶ç䏻颿¯mqtt.RECEIVE_MQTT_MSGï¼å
容æ¯{topic:'',payload:''}æ ¼å¼ |
| | | * 妿éè¦åéæ¶æ¯ï¼ç´æ¥ä½¿ç¨ mqtt.sendæ¹æ³ mqttåéçæ°æ®æ ¼å¼ç±»ä¼¼ï¼ { topic: "sendtopic1", payload: JSON.stringify({ a: i, b: "ssss" }) } |
| | | * mqttçè¿æ¥ç¶æåçååä¼è§¦åç» dxEventBusåéä¸ä¸ªäºä»¶ï¼äºä»¶ç䏻颿¯mqtt.CONNECTED_CHANGEDï¼å
容æ¯'connected'æè
'disconnect' |
| | | * mqttéè¦æç½ç»ï¼æä»¥å¿
é¡»å¨ä½¿ç¨ä¹åç¡®ä¿dxNetç»ä»¶å®æåå§å |
| | | * @param {object} options mqttç¸å
³åæ°,å¿
å¡« |
| | | * @param {string} options.mqttAddr mqttæå¡å°åï¼å¿
å¡«ï¼ä»¥tcp://å¼å¤´ï¼æ ¼å¼æ¯tcp://ip:port |
| | | * @param {string} options.clientId 客æ·ç«¯idï¼å¿
å¡«ï¼ä¸åç设å¤è¯·ä½¿ç¨ä¸åç客æ·ç«¯id |
| | | * @param {string} options.username éå¿
å¡«ï¼mqttç¨æ·å |
| | | * @param {string} options.password éå¿
å¡«ï¼mqttå¯ç |
| | | * @param {string} options.prefix éå¿
å¡«ï¼ç¼ºç为空å符串ï¼è¿ä¸ªè¡¨ç¤ºèªå¨å¨ä¸»é¢åå ä¸ä¸ä¸ªåç¼ |
| | | * @param {number} options.qos 0,1,2 éå¿
å¡«ï¼ç¼ºçæ¯1. å
¶ä¸0è¡¨ç¤ºæ¶æ¯æå¤åé䏿¬¡ï¼åéåæ¶æ¯å°±è¢«ä¸¢å¼;1è¡¨ç¤ºæ¶æ¯è³å°åé䏿¬¡ï¼å¯ä»¥ä¿è¯æ¶æ¯è¢«æ¥æ¶æ¹æ¶å°ï¼ä½æ¯ä¼å卿¥æ¶æ¹æ¶å°é夿¶æ¯çæ
åµ;2è¡¨ç¤ºæ¶æ¯åéæåä¸åªåé䏿¬¡,èµæºå¼é大 |
| | | * @param {string} options.willTopic éå¿
å¡«ï¼éå±ä¸»é¢ï¼éè¿brokeréä¿¡çæ¶åè®¾å¤æå¼ä¼èªå¨è§¦åä¸ä¸ªmqtté屿¶æ¯ï¼è¿ä¸ªæ¯é屿¶æ¯çä¸»é¢ |
| | | * @param {string} options.willMessage éå¿
å¡«ï¼éå±å
容ï¼éè¿brokeréä¿¡çæ¶åè®¾å¤æå¼ä¼èªå¨è§¦åä¸ä¸ªmqtté屿¶æ¯ï¼è¿ä¸ªæ¯é屿¶æ¯çå
容 |
| | | * @param {array} options.subs éå¿
å¡«ï¼è¦è®¢é
ç主é¢ç» |
| | | * @param {string} options.id 奿idï¼éå¿
å¡«ï¼è¥åå§åå¤ä¸ªå®ä¾éè¦ä¼ å
¥å¯ä¸idï¼ |
| | | */ |
| | | mqtt.run = function (options) { |
| | | if (options === undefined || options.length === 0) { |
| | | throw new Error("dxmqtt.run:'options' parameter should not be null or empty") |
| | | } |
| | | if (options.id === undefined || options.id === null || typeof options.id !== 'string') { |
| | | // 奿id |
| | | options.id = "" |
| | | } |
| | | let oldfilepre = '/app/code/dxmodules/mqttWorker' |
| | | let content = std.loadFile(oldfilepre + '.js').replace("{{id}}", options.id) |
| | | let newfile = oldfilepre + options.id + '.js' |
| | | std.saveFile(newfile, content) |
| | | let init = map.get("__mqtt__run_init" + options.id) |
| | | if (!init) {//ç¡®ä¿åªåå§å䏿¬¡ |
| | | map.put("__mqtt__run_init" + options.id, options) |
| | | bus.newWorker(options.id || "__mqtt", newfile) |
| | | } |
| | | } |
| | | /** |
| | | * è·åå½åmqttè¿æ¥çç¶æ |
| | | * @param {string} id 奿idï¼éå¿
å¡«ï¼éä¿æåinitä¸çidä¸è´ï¼ |
| | | * @returns 'connected' æè
'disconnected' |
| | | */ |
| | | mqtt.getConnected = function (id) { |
| | | if (id == undefined || id == null) { |
| | | id = "" |
| | | } |
| | | return mqtt.isConnected(id) ? "connected" : "disconnected" |
| | | } |
| | | |
| | | export default mqtt; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //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ã使¯initåéè¦è½®è¯¢å»è·åç½ç»ç¶æï¼éè¿msgReceive) |
| | | * ä¹å¯ä»¥ç´æ¥ä½¿ç¨ç®åæ¹æ³dxNet.runï¼æ é轮询 |
| | | * @param {object} options åå§åç½ç»çåæ° |
| | | * @param {number} type å¿
å¡« ç½ç»ç±»åï¼åènet.TYPEæä¸¾ |
| | | * @param {number} dhcp å¿
å¡« DHCPï¼åènet.DHCPæä¸¾ |
| | | * @param {string} macAddr å¿
å¡« macå°å,缺ç使ç¨dxCommon.getUuid2mac()æ¹æ³æ¥è·åmacå°å |
| | | * @param {string} ip éå¿
å¡« ç½ç»ipå°å |
| | | * @param {string} gateway éå¿
å¡« ç½å
³å°å |
| | | * @param {string} netmask éå¿
å¡« åç½æ©ç |
| | | * @param {string} dns0 éå¿
å¡« DNSå°å |
| | | * @param {string} dns1 éå¿
å¡« å¤éDNSå°å |
| | | * @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 å¿
å¡« ç½ç»ç±»åï¼åènet.TYPEæä¸¾ |
| | | * @returns Macå°å |
| | | */ |
| | | net.getMacaddr = function (type) { |
| | | return netObj.getMacaddr(type) |
| | | } |
| | | /** |
| | | * 设置Macå°å |
| | | * @param {number} type å¿
å¡« ç½ç»ç±»åï¼åènet.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 å¿
å¡« ç½ç»ç±»åï¼åènet.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 å¿
å¡« ç½ç»ç±»åï¼åènet.TYPEæä¸¾ |
| | | * @param {number} mode å¿
å¡« DHCPï¼åènet.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 å¿
å¡« ç½ç»ç±»åï¼åènet.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 å¿
å¡« ç½ç»ç±»åï¼åènet.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, ç½çº¿å·²æå
¥æè
wifiå·²è¿æ¥ssid 使ªåé
ip |
| | | 4, å·²æååé
ip |
| | | 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) |
| | | } |
| | | /** |
| | | * è¿æ¥å°wifi |
| | | * @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() |
| | | } |
| | | /** |
| | | * æå¼å½åè¿æ¥çwifiçç¹ |
| | | * @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åènet.TYPEæä¸¾ |
| | | * å
¶ä¸statusçå¼è¯´æå¦ä¸ï¼ |
| | | * 0, æªåå§æ |
| | | 1, ç½å¡å¤äºå
³éç¶æ |
| | | 2, ç½å¡å¤äºæå¼ç¶æ |
| | | 3, ç½çº¿å·²æå
¥æè
wifiå·²è¿æ¥ssid 使ªåé
ip |
| | | 4, å·²æååé
ip |
| | | 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çäºä»¶ï¼äºä»¶çtopicæ¯net.STATUS_CHANGEï¼äºä»¶çå
容æ¯ç±»ä¼¼{"type":1,"status":4ï¼"connected":true} |
| | | * å
¶ä¸typeåènet.TYPEæä¸¾ |
| | | * å
¶ä¸statusçå¼è¯´æå¦ä¸ï¼ |
| | | * 0, æªåå§æ |
| | | 1, ç½å¡å¤äºå
³éç¶æ |
| | | 2, ç½å¡å¤äºæå¼ç¶æ |
| | | 3, ç½çº¿å·²æå
¥æè
wifiå·²è¿æ¥ssid 使ªåé
ip |
| | | 4, å·²æååé
ip |
| | | 5 å·²è¿æ¥æå®æå¡æè
éè¿æµè¯å¯ä»¥è¿æ¥å°å¹¿åç½ |
| | | * @param {object} options åèinitçoptionsæè¿° |
| | | */ |
| | | 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 = { |
| | | //å¨while循ç¯å |
| | | beforeLoop: function (options) { |
| | | net.init(options) |
| | | }, |
| | | //å¨while循ç¯é |
| | | 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; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //build:20240715 |
| | | //éè¿è¿ä¸ªç»ä»¶æ¥è¯»åå¡ï¼å
æ¬M1å¡ï¼psamå¡ä¹ç±»ç |
| | | //ä¾èµç»ä»¶: dxDriver,dxMap,dxLogger,dxDriver,dxCommon,dxEventBus |
| | | import { nfcClass } from './libvbar-p-dxnfc.so' |
| | | import dxCommon from './dxCommon.js' |
| | | import bus from './dxEventBus.js' |
| | | import dxMap from './dxMap.js' |
| | | const nfcObj = new nfcClass(); |
| | | const map = dxMap.get("default") |
| | | const nfc = {} |
| | | |
| | | /** |
| | | * NFC åå§å |
| | | * @param {number} useEid éå¿
å¡«ï¼æ¯å¦ä½¿ç¨äºè¯ 0ä¸ä½¿ç¨ 1ä½¿ç¨ |
| | | */ |
| | | nfc.init = function (useEid = 0) { |
| | | let pointer = nfcObj.init(useEid) |
| | | if (pointer === undefined || pointer === null) { |
| | | throw new Error("nfc.init: init failed") |
| | | } |
| | | dxCommon.handleId("nfc", 'nfcid', pointer) |
| | | } |
| | | |
| | | /** |
| | | * NFC æ®é塿³¨ååè° |
| | | */ |
| | | nfc.cbRegister = function (callback) { |
| | | let pointer = dxCommon.handleId("nfc", 'nfcid') |
| | | return nfcObj.cbRegister(pointer, "nfc_cb", 1, callback) |
| | | } |
| | | |
| | | /** |
| | | * NFC PSAM塿³¨ååè° |
| | | */ |
| | | nfc.psamCbRegister = function (callback) { |
| | | let pointer = dxCommon.handleId("nfc", 'nfcid') |
| | | return nfcObj.nfcPsamCheckVgcardCallback(pointer, callback) |
| | | } |
| | | |
| | | /** |
| | | * NFC åæ¶åå§å |
| | | */ |
| | | nfc.deinit = function () { |
| | | let pointer = dxCommon.handleId("nfc", 'nfcid') |
| | | let ret = nfcObj.cbUnregister(pointer, "nfc_cb") |
| | | if (ret === false) { |
| | | throw new Error("nfc.cbUnregister: cbUnregister failed") |
| | | } |
| | | return nfcObj.deinit(pointer) |
| | | } |
| | | |
| | | /** |
| | | * NFC å¡ä¿¡æ¯å建 |
| | | * @param {number} cardType å¡è¯çç±»å(ååå®ä¹) |
| | | * @param {ArrayBuffer} cardId å¡å· |
| | | * @param {number} type å¡ç±»å(æä»¬èªå·±å®ä¹ç) |
| | | * @returns cardInfo(pointer) |
| | | */ |
| | | nfc.cardInfoCreate = function (cardType, cardId, type) { |
| | | if (!cardType) { |
| | | throw new Error("cardInfoCreate:cardType should not be null or empty") |
| | | } |
| | | if (!cardId) { |
| | | throw new Error("cardInfoCreate:cardId should not be null or empty") |
| | | } |
| | | if (!type) { |
| | | throw new Error("cardInfoCreate:type should not be null or empty") |
| | | } |
| | | return nfcObj.cardInfoCreate(cardType, cardId, type); |
| | | } |
| | | |
| | | /** |
| | | * NFC å¡ä¿¡æ¯éæ¯ |
| | | * @param {pointer} cardInfo å¡ä¿¡æ¯ |
| | | * @returns |
| | | */ |
| | | nfc.cardInfoDestory = function (cardInfo) { |
| | | if (!cardInfo) { |
| | | throw new Error("cardInfoDestory:cardInfo should not be null or empty") |
| | | } |
| | | return nfcObj.cardInfoDestory(cardInfo); |
| | | } |
| | | |
| | | /** |
| | | * NFC å¡ä¿¡æ¯å¤å¶ |
| | | * @param {pointer} cardInfo å¡ä¿¡æ¯ |
| | | * @returns cardInfo(pointer) |
| | | */ |
| | | nfc.cardInfoCopy = function (cardInfo) { |
| | | if (cardInfo == null) { |
| | | throw new Error("cardInfoCopy:cardInfo should not be null or empty") |
| | | } |
| | | return nfcObj.cardInfoCopy(cardInfo); |
| | | } |
| | | |
| | | /** |
| | | * NFC 夿æ¯å¦æå¡ |
| | | * @returns bool |
| | | */ |
| | | nfc.isCardIn = function () { |
| | | let pointer = dxCommon.handleId("nfc", 'nfcid') |
| | | return nfcObj.isCardIn(pointer); |
| | | } |
| | | |
| | | /** |
| | | * NFC 读M1å¡æåº |
| | | * @param {number} taskFlg 任塿 å¿ï¼ |
| | | * 0x00->AUTO åç¥æ«ç å¨è¯¥æä»¤å¯åç¬æ§è¡ï¼æ æä»¤é´çä¾èµå
³ç³»ã |
| | | * 0x01->START åç¥æ«ç å¨å¼å§å¯¹å¡æä½æå¯¹å¡æä½å°æªç»æï¼ä¸æä»¤é´å¯è½åå¨ä¾èµå
³ç³»ã |
| | | * 0x02->FINISH åç¥æ«ç 卿¬æ¡æä»¤æ¯æä½å¡çæå䏿¡æä»¤ï¼å°å¡çæä½ç¯å¢æ¢å¤å°é»æã |
| | | * @param {number} secNum æåºå· |
| | | * @param {number} logicBlkNum åå·ï¼å¨æåºå
çé»è¾å·0~3) |
| | | * @param {number} blkNums åæ° |
| | | * @param {array} key å¯é¥, é¿åº¦6bytes |
| | | * @param {number} keyType å¯é¥ç±»å: A:0x60 B:0x61 |
| | | * @returns Array 读åç»æ undefined:失败 |
| | | */ |
| | | nfc.m1cardReadSector = function (taskFlg, secNum, logicBlkNum, blkNums, key, keyType) { |
| | | let pointer = dxCommon.handleId("nfc", 'nfcid') |
| | | _validate('m1cardReadSector', taskFlg, secNum, logicBlkNum, blkNums, key, keyType, ' ') |
| | | return nfcObj.m1cardReadSector(pointer, taskFlg, secNum, logicBlkNum, blkNums, key, keyType); |
| | | } |
| | | |
| | | /** |
| | | * NFC 读M1å¡æåº |
| | | * @param {number} taskFlg 任塿 å¿ï¼ |
| | | * 0x00->AUTO åç¥æ«ç å¨è¯¥æä»¤å¯åç¬æ§è¡ï¼æ æä»¤é´çä¾èµå
³ç³»ã |
| | | * 0x01->START åç¥æ«ç å¨å¼å§å¯¹å¡æä½æå¯¹å¡æä½å°æªç»æï¼ä¸æä»¤é´å¯è½åå¨ä¾èµå
³ç³»ã |
| | | * 0x02->FINISH åç¥æ«ç 卿¬æ¡æä»¤æ¯æä½å¡çæå䏿¡æä»¤ï¼å°å¡çæä½ç¯å¢æ¢å¤å°é»æã |
| | | * @param {number} secNum æåºå· |
| | | * @param {number} logicBlkNum åå·ï¼å¨æåºå
çé»è¾å·0~3) |
| | | * @param {number} blkNums åæ° |
| | | * @param {array} key å¯é¥, é¿åº¦6bytes |
| | | * @param {number} keyType å¯é¥ç±»å: A:0x60 B:0x61 |
| | | * @param {array} data åå
¥æ°æ® |
| | | * @returns int åå
¥é¿åº¦ -1:é误 |
| | | */ |
| | | nfc.m1cardWriteSector = function (taskFlg, secNum, logicBlkNum, blkNums, key, keyType, data) { |
| | | let pointer = dxCommon.handleId("nfc", 'nfcid') |
| | | _validate('m1cardWriteSector', taskFlg, secNum, logicBlkNum, blkNums, key, keyType, data) |
| | | return nfcObj.m1cardWriteSector(pointer, taskFlg, secNum, logicBlkNum, blkNums, key, keyType, data); |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @param {number} taskFlg 任塿 å¿ï¼ |
| | | * 0x00->AUTO åç¥æ«ç å¨è¯¥æä»¤å¯åç¬æ§è¡ï¼æ æä»¤é´çä¾èµå
³ç³»ã |
| | | * 0x01->START åç¥æ«ç å¨å¼å§å¯¹å¡æä½æå¯¹å¡æä½å°æªç»æï¼ä¸æä»¤é´å¯è½åå¨ä¾èµå
³ç³»ã |
| | | * 0x02->FINISH åç¥æ«ç 卿¬æ¡æä»¤æ¯æä½å¡çæå䏿¡æä»¤ï¼å°å¡çæä½ç¯å¢æ¢å¤å°é»æã |
| | | * @param {number} blkNums åå· |
| | | * @param {array} key å¯é¥, é¿åº¦6bytes |
| | | * @param {number} keyType å¯é¥ç±»å: A:0x60 B:0x61 |
| | | * @returns Array 读åç»æ undefined:失败 |
| | | */ |
| | | nfc.m1cardReadBlk = function (taskFlg, blkNum, key, keyType) { |
| | | let pointer = dxCommon.handleId("nfc", 'nfcid') |
| | | _validate('m1cardReadBlk', taskFlg, 1, 0, blkNum, key, keyType, ' ') |
| | | return nfcObj.m1cardReadBlk(pointer, taskFlg, blkNum, key, keyType); |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @param {number} taskFlg 任塿 å¿ï¼ |
| | | * 0x00->AUTO åç¥æ«ç å¨è¯¥æä»¤å¯åç¬æ§è¡ï¼æ æä»¤é´çä¾èµå
³ç³»ã |
| | | * 0x01->START åç¥æ«ç å¨å¼å§å¯¹å¡æä½æå¯¹å¡æä½å°æªç»æï¼ä¸æä»¤é´å¯è½åå¨ä¾èµå
³ç³»ã |
| | | * 0x02->FINISH åç¥æ«ç 卿¬æ¡æä»¤æ¯æä½å¡çæå䏿¡æä»¤ï¼å°å¡çæä½ç¯å¢æ¢å¤å°é»æã |
| | | * @param {number} blkNums åå· |
| | | * @param {array} key å¯é¥, é¿åº¦6bytes |
| | | * @param {number} keyType å¯é¥ç±»å: A:0x60 B:0x61 |
| | | * @param {array} data åå
¥æ°æ® |
| | | * @returns int åå
¥é¿åº¦ -1:é误 |
| | | */ |
| | | nfc.m1cardWriteBlk = function (taskFlg, blkNum, key, keyType, data) { |
| | | let pointer = dxCommon.handleId("nfc", 'nfcid') |
| | | _validate('m1cardWriteBlk', taskFlg, 1, 0, blkNum, key, keyType, data) |
| | | return nfcObj.m1cardWriteBlk(pointer, taskFlg, blkNum, key, keyType, data); |
| | | } |
| | | /** |
| | | * ATSæ£æµ |
| | | */ |
| | | nfc.nfc_iso14443_type_a_get_ats = function () { |
| | | let pointer = dxCommon.handleId("nfc", 'nfcid') |
| | | return nfcObj.nfc_iso14443_type_a_get_ats(pointer) |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @param {number} taskFlg 任塿 å¿ï¼ |
| | | * 0x00->AUTO åç¥æ«ç å¨è¯¥æä»¤å¯åç¬æ§è¡ï¼æ æä»¤é´çä¾èµå
³ç³»ã |
| | | * 0x01->START åç¥æ«ç å¨å¼å§å¯¹å¡æä½æå¯¹å¡æä½å°æªç»æï¼ä¸æä»¤é´å¯è½åå¨ä¾èµå
³ç³»ã |
| | | * 0x02->FINISH åç¥æ«ç 卿¬æ¡æä»¤æ¯æä½å¡çæå䏿¡æä»¤ï¼å°å¡çæä½ç¯å¢æ¢å¤å°é»æã |
| | | * @param {ArrayBuffer} buffer è¦åéçæ°æ® |
| | | * @param {number} bufferLen è¦åéçæ°æ®é¿åº¦ |
| | | * @returns buffer |
| | | */ |
| | | nfc.iso14443Apdu = function (taskFlg, buffer, bufferLen) { |
| | | let pointer = dxCommon.handleId("nfc", "nfcid") |
| | | return nfcObj.iso14443Apdu(pointer, taskFlg, buffer, bufferLen); |
| | | } |
| | | |
| | | /** |
| | | * PSAMå¡æçµ |
| | | */ |
| | | nfc.nfcPsamPowerDown = function () { |
| | | let pointer = dxCommon.handleId("nfc", "nfcid") |
| | | return nfcObj.nfcPsamPowerDown(pointer); |
| | | } |
| | | |
| | | /** |
| | | * NFC æ¹åç¶æ |
| | | */ |
| | | nfc.nfcPsamChangeBaud = function () { |
| | | let pointer = dxCommon.handleId("nfc", "nfcid") |
| | | return nfcObj.nfcPsamChangeBaud(pointer); |
| | | } |
| | | |
| | | /** |
| | | * PSAMå¡éç½® |
| | | */ |
| | | nfc.nfcPsamCardReset = function (force) { |
| | | let pointer = dxCommon.handleId("nfc", "nfcid") |
| | | return nfcObj.nfcPsamCardReset(pointer, force); |
| | | } |
| | | |
| | | /** |
| | | * åéPSAM APDUæä»¤ |
| | | */ |
| | | nfc.nfcPsamCardApdu = function (buffer) { |
| | | let pointer = dxCommon.handleId("nfc", "nfcid") |
| | | return nfcObj.nfcPsamCardApdu(pointer, buffer); |
| | | } |
| | | |
| | | /** |
| | | * EID æ´æ°äºè¯é
ç½® |
| | | * @param {object} eidConfig äºè¯é
ç½® |
| | | * @param {string} eidConfig.appid å¹³å°åé
ç»åºç¨çappid |
| | | * @param {number} eidConfig.read_len; // 忬¡è¯»å¡é¿åº¦ï¼é»è®¤0x80 |
| | | * @param {number} eidConfig.declevel; // æ¯å¦è¯»åç
§çï¼1为ä¸è¯»åï¼2为读å |
| | | * @param {number} eidConfig.loglevel; //æ¥å¿çº§å«ï¼æ¯æ0ï¼1ï¼2 |
| | | * @param {number} eidConfig.model; // æ¯å¦ç´æ¥æ¥åºä¿¡æ¯ 0æ¯ 1å¦ ï¼å³0æ¯åè·¯è¿åï¼è¿å身份信æ¯ï¼1æ¯è½¬åï¼è¿åreqidï¼ |
| | | * @param {number} eidConfig.type; // å¡çç±»åï¼0 èº«ä»½è¯ 1çµåè¯ç
§ |
| | | * @param {number} eidConfig.pic_type; // ç
§çè§£ç æ°æ®ç±»å 0 wlt 1 jpg |
| | | * @param {number} eidConfig.envCode; // ç¯å¢è¯å«ç |
| | | * @param {string} eidConfig.sn[128]; // 设å¤åºåå· |
| | | * @param {string} eidConfig.device_model[128]; // 设å¤åå· |
| | | * @param {number} eidConfig.info_type; // ä¿¡æ¯è¿åç±»åï¼0 身份信æ¯ç»æä½ ï¼1åå§æ°æ® char |
| | | */ |
| | | nfc.eidUpdateConfig = function (eidConfig) { |
| | | if (eidConfig == null) { |
| | | throw new Error("eidUpdateConfig:eidConfig should not be null or empty") |
| | | } |
| | | return nfcObj.eidUpdateConfig(eidConfig); |
| | | } |
| | | |
| | | /** |
| | | * 读NTAGçæ¬å· |
| | | * @param {number} hdl nfc奿 |
| | | * @returns {ArrayBuffer} buffer |
| | | */ |
| | | nfc.nfcNtagReadVersion = function () { |
| | | let pointer = dxCommon.handleId("nfc", 'nfcid') |
| | | return nfcObj.nfcNtagReadVersion(pointer); |
| | | } |
| | | |
| | | /** |
| | | * 读NTAG页å
容 åºå®è¯»å4页å
±16åè |
| | | * @param {number} hdl nfc奿 |
| | | * @param {number} pageNum èµ·å§é¡µå°åï¼ |
| | | * æ¯æ¬¡è¯»åå个页 |
| | | * 妿å°å(Addr)æ¯04hï¼åè¿å页04hã05hã06hã07hå
容 |
| | | * @returns {ArrayBuffer} buffer |
| | | */ |
| | | nfc.nfcNtagReadPage = function (pageNum) { |
| | | let pointer = dxCommon.handleId("nfc", 'nfcid') |
| | | if (pageNum == null) { |
| | | throw new Error("nfcNtagReadPage:pageNum should not be null or empty") |
| | | } |
| | | return nfcObj.nfcNtagReadPage(pointer, pageNum); |
| | | } |
| | | |
| | | /** |
| | | * 读NTAGå¤é¡µå
容 è¯»åæ°æ®çbuffer,æå°ä¸º 页æ°*4ï¼è¦è¯»åçæ°æ®é¿åº¦ 页æ°*4 |
| | | * @param {number} hdl nfc奿 |
| | | * @param {number} start_addr èµ·å§é¡µå°å |
| | | * @param {number} end_addr ç»æé¡µå°å |
| | | * @returns {ArrayBuffer} buffer |
| | | */ |
| | | nfc.nfcNtagFastReadPage = function (start_page, end_page) { |
| | | let pointer = dxCommon.handleId("nfc", 'nfcid') |
| | | if (start_page == null) { |
| | | throw new Error("nfcNtagFastReadPage:start_page should not be null or empty") |
| | | } |
| | | if (end_page == null) { |
| | | throw new Error("nfcNtagFastReadPage:end_page should not be null or empty") |
| | | } |
| | | return nfcObj.nfcNtagFastReadPage(pointer, start_page, end_page); |
| | | } |
| | | |
| | | /** |
| | | * åNTAG页å
容 |
| | | * @param {number} hdl nfc奿 |
| | | * @param {number} pageNum åå
¥çé¡µå· ï¼ææAddråæ° |
| | | * 对äºNTAG213ï¼é¡µå°å02hè³2Ch |
| | | * 对äºNTAG215ï¼é¡µå°å02hè³86h |
| | | * 对äºNTAG216ï¼é¡µå°å02hè³E6h |
| | | * @param {ArrayBuffer} pageData åå
¥é¡µçå
容ï¼ååè |
| | | * @returns {boolean} ture/false |
| | | */ |
| | | nfc.nfcNtagWritePage = function (pageNum, pageData) { |
| | | let pointer = dxCommon.handleId("nfc", 'nfcid') |
| | | if (pageNum == null) { |
| | | throw new Error("nfcNtagWritePage:pageNum should not be null or empty") |
| | | } |
| | | if (!pageData) { |
| | | throw new Error("nfcNtagWritePage:pageData should not be null or empty") |
| | | } |
| | | return nfcObj.nfcNtagWritePage(pointer, pageNum, pageData); |
| | | } |
| | | |
| | | /** |
| | | * 夿nfcæ¶æ¯é忝å¦ä¸ºç©º |
| | | * @returns bool |
| | | */ |
| | | nfc.msgIsEmpty = function () { |
| | | let pointer = dxCommon.handleId("nfc", 'nfcid') |
| | | return nfcObj.msgIsEmpty(pointer) |
| | | } |
| | | |
| | | /** |
| | | * ä»nfcæ¶æ¯éåä¸è¯»åæ°æ® |
| | | * @returns jsonæ¶æ¯å¯¹è±¡ |
| | | */ |
| | | nfc.msgReceive = function () { |
| | | let pointer = dxCommon.handleId("nfc", 'nfcid') |
| | | let msg = nfcObj.msgReceive(pointer) |
| | | return JSON.parse(msg); |
| | | } |
| | | |
| | | function _validate(fun, taskFlg, secNum, logicBlkNum, blkNums, key, keyType, data) { |
| | | if (![0x00, 0x01, 0x02].includes(taskFlg)) { |
| | | throw new Error(fun, ":taskFlg error") |
| | | } |
| | | if (!(secNum >= 0)) { |
| | | throw new Error(fun, ":secNum error") |
| | | } |
| | | if (logicBlkNum == null || logicBlkNum == undefined || logicBlkNum < 0 || logicBlkNum > 3) { |
| | | throw new Error(fun, ":logicBlkNum error") |
| | | } |
| | | if (blkNums == null || blkNums == undefined || blkNums < 0 || blkNums > 59) { |
| | | throw new Error(fun, ":blkNums error") |
| | | } |
| | | if (key == null || key === undefined || key.length < 0) { |
| | | throw new Error(fun, ":key error") |
| | | } |
| | | if (![0x60, 0x61].includes(keyType)) { |
| | | throw new Error(fun, ":keyType error") |
| | | } |
| | | if (data === null || data === undefined) { |
| | | throw new Error(fun, ":data error") |
| | | } |
| | | } |
| | | |
| | | nfc.RECEIVE_MSG = '__nfc__MsgReceive' |
| | | |
| | | /** |
| | | * ç®åNFCç»ä»¶ç使ç¨ï¼æ é轮询å»è·åç½ç»ç¶æï¼ç½ç»çç¶æä¼éè¿eventcenteråéåºå» |
| | | * run åªä¼æ§è¡ä¸æ¬¡ï¼æ§è¡ä¹åç½ç»åºæ¬é
ç½®ä¸è½ä¿®æ¹ |
| | | * 妿éè¦å®æ¶è·åå·å¡æ°æ®ï¼å¯ä»¥è®¢é
eventCenterçäºä»¶ï¼äºä»¶çtopicæ¯nfc.CARDï¼äºä»¶çå
容æ¯ç±»ä¼¼ |
| | | * {id:'å¡id',card_type:å¡è¯çç±»å,id_len:å¡å·é¿åº¦,typeï¼å¡ç±»å,timestamp:'å·å¡æ¶é´æ³',monotonic_timestamp:'ç¸å¯¹å¼æºçæ¶é´'} |
| | | * @param {*} options |
| | | * @param {boolean} options.m1 éå¿
å¡«ï¼æ®éå¡åè°å¼å
³ |
| | | * @param {boolean} options.psam éå¿
å¡«ï¼psamå¡åè°å¼å
³ |
| | | */ |
| | | nfc.run = function (options) { |
| | | if (options === undefined || options.length === 0) { |
| | | throw new Error("dxnfc.run:'options' parameter should not be null or empty") |
| | | } |
| | | let init = map.get("__nfc__run_init") |
| | | if (!init) {//ç¡®ä¿åªåå§å䏿¬¡ |
| | | map.put("__nfc__run_init", options) |
| | | bus.newWorker("__nfc", '/app/code/dxmodules/nfcWorker.js') |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 妿nfcåç¬ä¸ä¸ªçº¿ç¨ï¼å¯ä»¥ç´æ¥ä½¿ç¨run彿°ï¼ä¼èªå¨å¯å¨ä¸ä¸ªçº¿ç¨ï¼ |
| | | * 妿æ³å å
¥å°å
¶ä»å·²æç线ç¨ï¼å¯ä»¥ä½¿ç¨ä»¥ä¸å°è£
ç彿° |
| | | */ |
| | | nfc.worker = { |
| | | //å¨while循ç¯å |
| | | beforeLoop: function (options) { |
| | | nfc.init(options.useEid) |
| | | // PSAMåæ®éå¡åè° |
| | | if (options.m1) { |
| | | nfc.cbRegister() |
| | | } |
| | | if (options.psam) { |
| | | nfc.psamCbRegister() |
| | | } |
| | | }, |
| | | //å¨while循ç¯é |
| | | loop: function () { |
| | | if (!nfc.msgIsEmpty()) { |
| | | let res = nfc.msgReceive(); |
| | | bus.fire(nfc.RECEIVE_MSG, res) |
| | | } |
| | | } |
| | | } |
| | | export default nfc; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //build: 20240523 |
| | | //忥æ¶é´,è¿è¡æ¶éè¦æè¿ä¸ªç»ä»¶å è½½å°ä¸ä¸ªçº¿ç¨éçwhile循ç¯, |
| | | //ç¼ºçæ¯é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ï¼è¡¨ç¤ºGMT8å京æ¶é´ |
| | | * @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; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //build:20240724 |
| | | // è´è´£åºä»¶çå级 |
| | | import log from './dxLogger.js' |
| | | import com from './dxCommon.js' |
| | | import http from './dxHttp.js' |
| | | import * as os from 'os'; |
| | | |
| | | const ota = {} |
| | | //è·åå½åç£çå©ä½å¤§å°ï¼kï¼å¯è½ä¸åçæä½ç³»ç»æä»¤ä¸ä¸æ · |
| | | ota.DF_CMD = `df -k / | awk 'NR==2 {print $4}'` |
| | | ota.OTA_ROOT = '/ota' |
| | | ota.OTA_RUN = ota.OTA_ROOT + '/run.sh' |
| | | |
| | | |
| | | /** |
| | | * HTTPå级ï¼ç½ç»ä¸è½½å级å
å级 |
| | | * @param {string} url å¿
å¡«ï¼ä¸è½½å级å
çhttp urlå°å |
| | | * @param {string} md5 å¿
å¡«ï¼å级å
çmd5æ è¯ï¼ä¸è½½å®éè¿md5æ¥å¤ææ¯å¦å®æ´ã32é¿åº¦çå
¨å°å16è¿å¶å符串 |
| | | * @param {number} size éå¿
å¡«ï¼å级å
ç大æ¦å¤§å°ï¼å使¯kï¼å¦ææä»¶å¤ªå¤§èå©ä½ç£çä¸å¤ï¼ä¼æåæ¥é误ï¼ä¸ä¼å¼å§å¯å¨ä¸è½½ |
| | | * @param {number} timeout éå¿
å¡«ï¼å°è¯é¾æ¥ä¸è½½å°åçè¶
æ¶æ¶é´ï¼ä¸æ¯ä¸è½½å®æçæ¶é´ï¼ï¼ç¼ºçæ¯3ç§ |
| | | * @param {string} password éå¿
å¡«ï¼ä¸è½½å®è£
å
çå¯ç ï¼å¯éï¼å¦æè®¾ç½®ï¼ä¸è½½æ¶éè¦è¾å
¥å¯ç |
| | | */ |
| | | ota.updateHttp = function (url, md5, timeout = 3, password, size) { |
| | | if (!url || !md5) { |
| | | throw new Error("The 'url' and 'md5' param should not be null") |
| | | } |
| | | if (size && (typeof size != 'number')) { |
| | | throw new Error("The 'size' param should be a number") |
| | | } |
| | | //1. æ¥çç£çè¿å©ä½çå¤§å° |
| | | let df = parseInt(com.systemWithRes(ota.DF_CMD, 1000)) |
| | | if (size) { |
| | | if (df < (3 * size)) {//å¤§æ¦æ¬å°å¿
é¡»æå®è£
å
3å大å°çç©ºé´ |
| | | throw new Error('The upgrade package is too large, and not be enough space on the disk to download it') |
| | | } |
| | | } |
| | | //2. ä¸è½½æä»¶å°ä¸´æ¶ç®å½ |
| | | const firmware = '/upgrades.zip' |
| | | const temp = '/upgrades.temp' |
| | | com.systemBrief(`rm -rf ${firmware} && rm -rf ${temp} `) //å
å é¤otaæ ¹ç®å½ |
| | | |
| | | let downloadRet = http.download(url + (password ? "&password=" + password : '') , temp, null, timeout*1000) |
| | | let fileExist = (os.stat(temp)[1] === 0) |
| | | if (!fileExist) { |
| | | log.error("download result" + downloadRet) |
| | | com.systemBrief(`rm -rf ${firmware} && rm -rf ${temp} `) |
| | | throw new Error('Download failed, please check the url:' + url) |
| | | } |
| | | //3. 计ç®å¹¶æ¯è¾md5æ¯å¦ä¸æ · |
| | | let md5Hash = com.md5HashFile(temp) |
| | | md5Hash = md5Hash.map(v => v.toString(16).padStart(2, 0)).join('') |
| | | if (md5Hash != md5) { |
| | | com.systemBrief(`rm -rf ${firmware} && rm -rf ${temp} `) |
| | | throw new Error('Download failed with wrong md5 value') |
| | | } |
| | | //4. md5æ ¡éªéè¿ï¼å°å级å
æ¾å°å级ç®å½ä¸ï¼çå¾
éå¯å级 |
| | | com.systemBrief(`mv ${temp} ${firmware} `) |
| | | } |
| | | |
| | | |
| | | /** |
| | | * æä»¶å级ï¼éè¿å
¶ä»æ¹å¼å°å级å
æ¾å°ç¨æ·ç®å½ä¸ï¼è°ç¨æ¤æ¹æ³å级 |
| | | * @param {string} path å¿
å¡«ï¼ä¸è½½å级å
çhttp urlå°å |
| | | * @param {string} md5 å¿
å¡«ï¼å级å
çmd5æ è¯ï¼ä¸è½½å®éè¿md5æ¥å¤ææ¯å¦å®æ´ã32é¿åº¦çå
¨å°å16è¿å¶å符串 |
| | | * @param {number} size éå¿
å¡«ï¼å级å
ç大æ¦å¤§å°ï¼å使¯kï¼å¦ææä»¶å¤ªå¤§èå©ä½ç£çä¸å¤ï¼ä¼æåæ¥é误ï¼ä¸ä¼å¼å§å¯å¨ä¸è½½ |
| | | */ |
| | | ota.updateFile = function (path, md5, size) { |
| | | if (!path || !md5) { |
| | | throw new Error("The 'path' and 'md5' param should not be null") |
| | | } |
| | | if (size && (typeof size != 'number')) { |
| | | throw new Error("The 'size' param should be a number") |
| | | } |
| | | |
| | | //1. æ¥çç£çè¿å©ä½çå¤§å° |
| | | let df = parseInt(com.systemWithRes(ota.DF_CMD, 1000)) |
| | | if (size) { |
| | | if (df < (3 * size)) {//å¤§æ¦æ¬å°å¿
é¡»æå®è£
å
3å大å°çç©ºé´ |
| | | throw new Error('The upgrade package is too large, and not be enough space on the disk to download it') |
| | | } |
| | | } |
| | | |
| | | //2. 计ç®å¹¶æ¯è¾md5æ¯å¦ä¸æ · |
| | | let md5Hash = com.md5HashFile(path) |
| | | md5Hash = md5Hash.map(v => v.toString(16).padStart(2, 0)).join('') |
| | | if (md5Hash != md5) { |
| | | throw new Error('With wrong md5 value') |
| | | } |
| | | |
| | | //3. md5æ ¡éªéè¿ï¼å°å级å
æ¾å°å级ç®å½ä¸ï¼çå¾
éå¯å级 |
| | | const firmware = '/upgrades.zip' |
| | | com.systemBrief(`mv ${path} ${firmware} `) |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 注æï¼æ¤æ¹æ³å³å°è¿æï¼ç¨äºå
¼å®¹æ§çæ¬ï¼æ°çæ¬ä¸æ¨èä½¿ç¨ |
| | | * å级åäºå¤§æ¥éª¤ï¼ç¬¬ä¸æ¥æ¯å¨åºç¨ç«¯ä¸è½½å级å
ï¼zipï¼ï¼è§£åå级å
|
| | | * ç¬¬äºæ¥å
æ¬éå¯è®¾å¤ï¼å©ç¨èæ¬å¤å¶ç®å½åæä»¶æé¢å¤ä¸äºæä½ |
| | | * 妿å¨å级å
æ ¹ç®å½ä¸æ¾ä¸ä¸ªcustom_update.sh,å°±ä¼å
æ§è¡è¿ä¸ªshellæä»¶ï¼æä»¬å¯ä»¥å¨è¿ä¸ªæä»¶éæ¾ä¸äºèªå®ä¹çå级å¨ä½ |
| | | * @param {string} url å¿
å¡«ï¼ä¸è½½å级å
çhttp urlå°å |
| | | * @param {string} md5 å¿
å¡«ï¼å级å
çmd5æ è¯ï¼ä¸è½½å®éè¿md5æ¥å¤ææ¯å¦å®æ´ã32é¿åº¦çå
¨å°å16è¿å¶å符串 |
| | | * @param {number} size éå¿
å¡«ï¼å级å
ç大æ¦å¤§å°ï¼å使¯kï¼å¦ææä»¶å¤ªå¤§èå©ä½ç£çä¸å¤ï¼ä¼æåæ¥é误ï¼ä¸ä¼å¼å§å¯å¨ä¸è½½ |
| | | * @param {string} shell éå¿
å¡«ï¼éå¯è®¾å¤åçåçº§èæ¬å
容ï¼è§£ååçæä»¶å¤¹ç¼ºçæ¯ /ota/temp,å级ä¼ç¼ºçæ/ota/temp䏿ææä»¶æ·è´å¤å¶å°/app/code/ä¸ |
| | | * @param {number} timeout éå¿
å¡«ï¼å°è¯é¾æ¥ä¸è½½å°åçè¶
æ¶æ¶é´ï¼ä¸æ¯ä¸è½½å®æçæ¶é´ï¼ï¼ç¼ºçæ¯3ç§ |
| | | */ |
| | | ota.update = function (url, md5, size, shell, timeout = 3) { |
| | | if (!url || !md5) { |
| | | throw new Error("The 'url' and 'md5' param should not be null") |
| | | } |
| | | if (size && (typeof size != 'number')) { |
| | | throw new Error("The 'size' param should be a number") |
| | | } |
| | | //1. æ¥çç£çè¿å©ä½çå¤§å° |
| | | let df = parseInt(com.systemWithRes(ota.DF_CMD, 1000)) |
| | | if (size) { |
| | | if (df < (3 * size)) {//å¤§æ¦æ¬å°å¿
é¡»æå®è£
å
3å大å°çç©ºé´ |
| | | throw new Error('The upgrade package is too large, and not be enough space on the disk to download it') |
| | | } |
| | | } |
| | | //2. ä¸è½½æä»¶å°ç¹å®ç®å½ |
| | | const firmware = ota.OTA_ROOT + '/download.zip' |
| | | const temp = ota.OTA_ROOT + '/temp' |
| | | com.systemBrief(`rm -rf ${ota.OTA_ROOT} && mkdir ${ota.OTA_ROOT} `) //å
å é¤otaæ ¹ç®å½ |
| | | let download = `wget --no-check-certificate --timeout=${timeout} -c "${url}" -O ${firmware} 2>&1` |
| | | com.systemBrief(download, 1000) |
| | | let fileExist = (os.stat(firmware)[1] === 0) |
| | | let downloadRet |
| | | if (!fileExist) { |
| | | downloadRet = http.download(url, firmware, null, timeout*1000) |
| | | } |
| | | fileExist = (os.stat(firmware)[1] === 0) |
| | | if (!fileExist) { |
| | | log.error("download result" + downloadRet) |
| | | throw new Error('Download failed, please check the url:' + url) |
| | | } |
| | | //3. 计ç®å¹¶æ¯è¾md5æ¯å¦ä¸æ · |
| | | let md5Hash = com.md5HashFile(firmware) |
| | | md5Hash = md5Hash.map(v => v.toString(16).padStart(2, 0)).join('') |
| | | if (md5Hash != md5) { |
| | | log.error("download result" + downloadRet) |
| | | throw new Error('Download failed with wrong md5 value') |
| | | } |
| | | //4. è§£å |
| | | com.systemBrief(`mkdir ${temp} && unzip -o ${firmware} -d ${temp}`) |
| | | //5. æ§è¡èªå®ä¹çåçº§èæ¬ |
| | | const custom_update = temp+'/custom_update.sh' |
| | | if(os.stat(custom_update)[1] === 0){ |
| | | com.systemBrief(`chmod +x ${custom_update}`) |
| | | com.systemWithRes(`${custom_update}`) |
| | | } |
| | | //6. æå»ºèæ¬æä»¶ |
| | | if (!shell) { |
| | | //缺çåªæ¯æ·è´ç®å½å¹¶å é¤otaæ ¹ç®å½ |
| | | shell = `cp -r ${temp}/* /app/code \n rm -rf ${ota.OTA_ROOT}` |
| | | } |
| | | |
| | | com.systemBrief(`echo "${shell}" > ${ota.OTA_RUN} && chmod +x ${ota.OTA_RUN}`) |
| | | fileExist = (os.stat(ota.OTA_RUN)[1] === 0) |
| | | if (!fileExist) { |
| | | throw new Error('Build shell file failed') |
| | | } |
| | | com.systemWithRes(`${ota.OTA_RUN}`) |
| | | } |
| | | |
| | | /** |
| | | * 注æï¼æ¤æ¹æ³å³å°è¿æï¼ç¨äºå
¼å®¹æ§çæ¬ï¼æ°çæ¬ä¸æ¨èä½¿ç¨ |
| | | * ç¹æ®ï¼å
¼å®¹æ§çåçº§æ ¼å¼ï¼å¿
é¡»æ¯tar.xzæ ¼å¼ï¼ä¸åªç¨æ¥åçº§èµæºæä»¶ |
| | | * å级åäºå¤§æ¥éª¤ï¼ç¬¬ä¸æ¥æ¯å¨åºç¨ç«¯ä¸è½½å级å
ï¼zipï¼ï¼è§£åå级å
|
| | | * ç¬¬äºæ¥å
æ¬éå¯è®¾å¤ï¼å©ç¨èæ¬å¤å¶ç®å½åæä»¶æé¢å¤ä¸äºæä½ |
| | | * 妿å¨å级å
æ ¹ç®å½ä¸æ¾ä¸ä¸ªcustom_update.sh,å°±ä¼å
æ§è¡è¿ä¸ªshellæä»¶ï¼æä»¬å¯ä»¥å¨è¿ä¸ªæä»¶éæ¾ä¸äºèªå®ä¹çå级å¨ä½ |
| | | * @param {string} url å¿
å¡«ï¼ä¸è½½å级å
çhttp urlå°å |
| | | * @param {string} md5 å¿
å¡«ï¼å级å
çmd5æ è¯ï¼ä¸è½½å®éè¿md5æ¥å¤ææ¯å¦å®æ´ã32é¿åº¦çå
¨å°å16è¿å¶å符串 |
| | | * @param {number} size éå¿
å¡«ï¼å级å
ç大æ¦å¤§å°ï¼å使¯kï¼å¦ææä»¶å¤ªå¤§èå©ä½ç£çä¸å¤ï¼ä¼æåæ¥é误ï¼ä¸ä¼å¼å§å¯å¨ä¸è½½ |
| | | * @param {string} shell éå¿
å¡«ï¼éå¯è®¾å¤åçåçº§èæ¬å
容ï¼è§£ååçæä»¶å¤¹ç¼ºçæ¯ /ota/temp,å级ä¼ç¼ºçæ/ota/temp䏿ææä»¶æ·è´å¤å¶å°/app/code/ä¸ |
| | | * @param {number} timeout éå¿
å¡«ï¼å°è¯é¾æ¥ä¸è½½å°åçè¶
æ¶æ¶é´ï¼ä¸æ¯ä¸è½½å®æçæ¶é´ï¼ï¼ç¼ºçæ¯3ç§ |
| | | */ |
| | | ota.updateResource = function (url, md5, size, shell, timeout = 3) { |
| | | if (!url || !md5) { |
| | | throw new Error("The 'url' and 'md5' param should not be null") |
| | | } |
| | | if (size && (typeof size != 'number')) { |
| | | throw new Error("The 'size' param should be a number") |
| | | } |
| | | //1. æ¥çç£çè¿å©ä½çå¤§å° |
| | | let df = parseInt(com.systemWithRes(ota.DF_CMD, 1000)) |
| | | if (size) { |
| | | if (df < (3 * size)) {//å¤§æ¦æ¬å°å¿
é¡»æå®è£
å
3å大å°çç©ºé´ |
| | | throw new Error('The upgrade package is too large, and not be enough space on the disk to download it') |
| | | } |
| | | } |
| | | //2. ä¸è½½æä»¶å°ç¹å®ç®å½ |
| | | const firmware = ota.OTA_ROOT + '/download.tar.xz' |
| | | const temp = ota.OTA_ROOT + '/temp' |
| | | com.systemBrief(`rm -rf ${ota.OTA_ROOT} && mkdir ${ota.OTA_ROOT} `) //å
å é¤otaæ ¹ç®å½ |
| | | let download = `wget --no-check-certificate --timeout=${timeout} -c "${url}" -O ${firmware} 2>&1` |
| | | com.systemBrief(download, 1000) |
| | | let fileExist = (os.stat(firmware)[1] === 0) |
| | | if (!fileExist) { |
| | | http.download(url, firmware, null, timeout*1000) |
| | | } |
| | | fileExist = (os.stat(firmware)[1] === 0) |
| | | if (!fileExist) { |
| | | throw new Error('Download failed, please check the url:' + url) |
| | | } |
| | | |
| | | //3. 计ç®å¹¶æ¯è¾md5æ¯å¦ä¸æ · |
| | | let md5Hash = com.md5HashFile(firmware) |
| | | md5Hash = md5Hash.map(v => v.toString(16).padStart(2, 0)).join('') |
| | | if (md5Hash != md5) { |
| | | throw new Error('Download failed with wrong md5 value') |
| | | } |
| | | //4. è§£å |
| | | //tar -xJvf test.tar.xz -C /path/ |
| | | com.systemBrief(`mkdir ${temp} && tar -xJvf ${firmware} -C ${temp}`) |
| | | //5. æå»ºèæ¬æä»¶ |
| | | if (!shell) { |
| | | shell = ` |
| | | source=${temp}/vgapp/res/image/bk.png |
| | | target=/app/code/resource/image/bg.png |
| | | if test -e "\\$source"; then |
| | | cp "\\$source" "\\$target" |
| | | fi |
| | | source=${temp}/vgapp/res/image/bk_90.png |
| | | target=/app/code/resource/image/bg_90.png |
| | | if test -e "\\$source"; then |
| | | cp "\\$source" "\\$target" |
| | | fi |
| | | source=${temp}/vgapp/res/font/AlibabaPuHuiTi-2-65-Medium.ttf |
| | | target=/app/code/resource/font.ttf |
| | | if test -e "\\$source"; then |
| | | cp "\\$source" "\\$target" |
| | | fi |
| | | source=${temp}/vgapp/wav/*.wav |
| | | target=/app/code/resource/wav/ |
| | | cp "\\$source" "\\$target" |
| | | rm -rf ${ota.OTA_ROOT} |
| | | ` |
| | | } |
| | | |
| | | com.systemBrief(`echo "${shell}" > ${ota.OTA_RUN} && chmod +x ${ota.OTA_RUN}`) |
| | | fileExist = (os.stat(ota.OTA_RUN)[1] === 0) |
| | | if (!fileExist) { |
| | | throw new Error('Build shell file failed') |
| | | } |
| | | com.systemWithRes(`${ota.OTA_RUN}`) |
| | | } |
| | | /** |
| | | * ç±è°ç¨è
æ¥å¯å¨éå¯ï¼ä¸è¬æ¯update彿°æ²¡æé误ï¼è¿è¡å®æå¹¶åååæ±æ¥ç»æååè°ç¨éå¯ |
| | | */ |
| | | ota.reboot = function () { |
| | | com.asyncReboot(2) |
| | | } |
| | | //-------------------------private------------------- |
| | | |
| | | export default ota |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | // build : 20240419 |
| | | // PWM代表èå²å®½åº¦è°å¶ï¼Pulse Width Modulationï¼è¢«ç¨æ¥æ¨¡æè¾åºçµåæåçï¼ä»¥æ§å¶è鸣å¨ãçµæºçé度ãLEDçäº®åº¦ãæ¸©åº¦è°èå¨ç温度çç |
| | | import { pwmClass } from './libvbar-b-dxpwm.so' |
| | | import * as os from "os" |
| | | const pwmObj = new pwmClass(); |
| | | |
| | | const pwm = {} |
| | | |
| | | /** |
| | | * ç³è¯·pwméé,ç³è¯·ä¸æ¬¡å³å¯ |
| | | * @param {number} channel ç³è¯·çééå·ï¼æ¯æ0~7éé |
| | | * @returns true/false |
| | | */ |
| | | pwm.request = function (channel) { |
| | | return pwmObj.request(channel) |
| | | } |
| | | /** |
| | | * 设置PWMæ¨¡å¼ |
| | | * @param {number} mode |
| | | 0 --> CPU mode,è¿ç»æ³¢å½¢. |
| | | 1 --> DMA mode,æå®æ°éçæ³¢å½¢. |
| | | 2 --> DMA mode,è¿ç»æ³¢å½¢. |
| | | * @returns true/false |
| | | */ |
| | | pwm.setMode = function (mode) { |
| | | return pwmObj.setMode(mode) |
| | | } |
| | | /** |
| | | * 设置PWM卿 æ¯æä¸ä¸ªå®æ´çPWMä¿¡å·å¨ææè±è´¹çæ¶é´ |
| | | * @param {number} periodNs å¾
设置çPWM卿å¼(åä½: ns) |
| | | * @returns true/false |
| | | */ |
| | | pwm.setPeriod = function (periodNs) { |
| | | return pwmObj.setPeriod(periodNs) |
| | | } |
| | | /** |
| | | * 设置PWMå ç©ºæ¯ æ¯æé«çµå¹³ï¼èå²ï¼å¨ä¸ä¸ªå®æ´ç卿å
æå çæ¶é´ |
| | | * @param {number} dutyNs å¾
设置çPWMå 空æ¯(设置é«çµå¹³çæ¶é´, åä½: ns) |
| | | * @returns true/false |
| | | */ |
| | | pwm.setDuty = function (dutyNs) { |
| | | return pwmObj.setDuty(dutyNs) |
| | | } |
| | | /** |
| | | * 设置PWM mode 2ï¼æä»¤æ°éçæ³¢å½¢æ¨¡å¼çæ°é |
| | | * @param {number} dutyNs |
| | | * @returns true/false |
| | | */ |
| | | pwm.setDmaDuty = function (dutyNs) { |
| | | return pwmObj.setDmaDuty(dutyNs) |
| | | } |
| | | /** |
| | | * ä½¿è½æå®éé |
| | | * @param {number} channel ç³è¯·çééå·ï¼æ¯æ0~7éé |
| | | * @param {boolean} on |
| | | * @returns true/false |
| | | */ |
| | | pwm.enable = function (channel, on) { |
| | | return pwmObj.enable(channel, on) |
| | | } |
| | | /** |
| | | * å
³éæééé |
| | | * @param {number} channel è¾å
¥åæ°, ç³è¯·çééå·ï¼æ¯æ0~7éé |
| | | * @returns true/false |
| | | */ |
| | | pwm.free = function (channel) { |
| | | return pwmObj.free(channel) |
| | | } |
| | | /** |
| | | * 设置æå®ééçPWM卿 |
| | | * @param {number} channel ç³è¯·çééå·ï¼æ¯æ0~7éé |
| | | * @param {number} periodNs å¾
设置çPWM卿å¼(åä½: ns) |
| | | * @returns true/false |
| | | */ |
| | | pwm.setPeriodByChannel = function (channel, periodNs) { |
| | | return pwmObj.setPeriodByChannel(channel, periodNs) |
| | | } |
| | | /** |
| | | * 设置æå®ééçPWMå ç©ºæ¯ |
| | | * @param {number} channel ç³è¯·çééå·ï¼æ¯æ0~7éé |
| | | * @param {number} dutyNs å¾
设置çPWMå 空æ¯(设置é«çµå¹³çæ¶é´, åä½: ns) |
| | | * @returns true/false |
| | | */ |
| | | pwm.setDutyByChannel = function (channel, dutyNs) { |
| | | return pwmObj.setDutyByChannel(channel, dutyNs); |
| | | } |
| | | /** |
| | | * è鸣,éè¦å
requestï¼setPeriodByChannelåenableä¹åæå¯ä»¥ä½¿ç¨ |
| | | * @param {object} options è鸣çåæ° |
| | | * @param {number} options.channel ç³è¯·çééå·ï¼æ¯æ0~7ééï¼å¿
å¡« |
| | | * @param {number} options.period å¾
设置çPWM卿å¼(åä½: ns) ç¼ºçæ¯366166 |
| | | * @param {number} options.count èé¸£çæ¬¡æ°ï¼ç¼ºçæ¯1次 |
| | | * @param {number} options.time èé¸£çæ¶é´ï¼ç¼ºçæ¯50毫ç§ï¼å¦ææ³é¿é¸£ï¼ä¸è¬æ¯500æ¯«ç§ |
| | | * @param {number} options.interval 2次è鸣ä¹é´çé´éï¼ç¼ºçæ¯50æ¯«ç§ |
| | | * @param {number} options.volume è鸣çé³éï¼ç¼ºçæ¯50 |
| | | */ |
| | | pwm.beep = function (options) { |
| | | const { |
| | | count = 1, |
| | | time = 50, |
| | | interval = 50, |
| | | volume = 50, |
| | | period = 366166, |
| | | } = options; |
| | | for (let i = 0; i < count; i++) { |
| | | pwm.setDutyByChannel(options.channel, period * volume / 255) |
| | | os.sleep(time) |
| | | pwm.setDutyByChannel(options.channel, 0) |
| | | if (i < (count - 1)) { |
| | | // æå䏿¬¡è鸣æ é´é |
| | | os.sleep(interval) |
| | | } |
| | | } |
| | | } |
| | | |
| | | export default pwm; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //build: 20240301 |
| | | //å¾®å
äºç»´ç ç å¶è§åï¼å
æ¬101ï¼103 ç |
| | | //ä¾èµç»ä»¶: dxDriver,dxCommon,dxLogger |
| | | import common from './dxCommon.js' |
| | | import base64 from './dxBase64.js' |
| | | import logger from './dxLogger.js' |
| | | let sqliteObj |
| | | |
| | | // æ¯è¾ä¸¤ä¸ªå符串çåN个å符æ¯å¦ç¸ç |
| | | function comparePrefix(str1, str2, N) { |
| | | let substring1 = str1.substring(0, N); |
| | | let substring2 = str2.substring(0, N); |
| | | return substring1 === substring2; |
| | | } |
| | | |
| | | |
| | | |
| | | // 101ç å¼è§£ç |
| | | function decode101(str) { |
| | | if (str.length < 5) { |
| | | logger.info("æ æäºç»´ç ") |
| | | throw new Error("code invalid,length too short") |
| | | } |
| | | let decodeBuf = base64.decode(str.slice(0, -4)) |
| | | decodeBuf=decodeBuf.substring(4) |
| | | |
| | | return decodeBuf |
| | | } |
| | | function hexStringToArrayBuffer (hexString) { |
| | | var byteString = hexString.match(/.{1,2}/g); |
| | | var byteArray = byteString.map(function (byte) { |
| | | return parseInt(byte, 16); |
| | | }); |
| | | var buffer = new Uint8Array(byteArray).buffer; |
| | | return buffer; |
| | | } |
| | | |
| | | /** |
| | | * 103ç å¼è§£ç |
| | | * 1ãbase64è§£ç |
| | | * 2ãè§£æç»ç»ç¼å· |
| | | * 3ãRSAè§£å¯ |
| | | * 4ãè§£æèº«ä»½ç±»å |
| | | * 5ãè§£ææéæ è¯ |
| | | * 6ãè§£æçç æ¶é´ |
| | | * 7ãè§£æç è¿ææ¶é´ |
| | | * 8ãæ ¡éªéè¡ç æ¯å¦è¿æ |
| | | * @param {*} str |
| | | * @returns |
| | | */ |
| | | function decode103(str) { |
| | | // FIXME è¿ä¸ªpubKeyåæéè¦ä»é
ç½®ä¸æ¥è¯¢ |
| | | let TLV_T_SIZE = 2, TLV_L_SIZE = 2, offset = 0, code, decryptedData, generationCodeTime, expirationTime |
| | | |
| | | // 1ãbase64è§£ç |
| | | let decodeBuf = base64.toHexString(str) |
| | | decodeBuf= hexStringToArrayBuffer(decodeBuf) |
| | | let view = new Uint8Array(decodeBuf) |
| | | let organizationNumber; |
| | | // 2ãè§£æç»ç»ç¼å· |
| | | if (view[offset] == 0x01) { |
| | | offset += TLV_T_SIZE |
| | | let orgNumLen = view[offset] |
| | | offset += TLV_L_SIZE |
| | | let orgNumBuf = new Uint8Array(decodeBuf, offset, orgNumLen); |
| | | organizationNumber = String.fromCharCode.apply(null, new Uint8Array(orgNumBuf)); |
| | | logger.info("ç»ç»ç¼å·: " + organizationNumber) |
| | | offset += orgNumLen |
| | | } else { |
| | | throw new Error("code invalid,organization number error") |
| | | } |
| | | |
| | | // 3ãRSAè§£å¯ |
| | | if (view[offset] == 0x02) { |
| | | // ç»ç»ç¼å·æ°æ®é¿åº¦ |
| | | offset += TLV_T_SIZE |
| | | let cipherTextLen = view[offset] |
| | | offset += TLV_L_SIZE |
| | | // 坹坿è¿è¡RSAè§£å¯ |
| | | let encryptedData = decodeBuf.slice(offset, offset + cipherTextLen) |
| | | |
| | | |
| | | // TODO ç§é¥åæ»ï¼åç»éè¦æ´é²åºæ¥ |
| | | // RSA æ¥è¯¢å¯é¥(ä¹å¯ä»¥åºå®ï¼ä¹å¯ä»¥å卿æ¬ä¸)ï¼æ ¹æ®å¯é¥åæ¬¡è§£å¯ |
| | | // RSAè§£å¯åçæ°æ® |
| | | let arr = sqliteObj.securityFindAllByCodeAndTypeAndTimeAndkey(undefined, undefined, undefined, Math.floor(Date.parse(new Date()) / 1000), organizationNumber) |
| | | if (arr && arr.length > 0) { |
| | | for (let data of arr) { |
| | | decryptedData = common.arrayBufferRsaDecrypt(encryptedData, data.value) |
| | | if (decryptedData != null) { |
| | | break |
| | | } |
| | | } |
| | | } |
| | | if (!arr && arr.length <= 0 || decryptedData == null) { |
| | | return str |
| | | } |
| | | } |
| | | // ä¸ä¸ªè®¾å¤ä¸ä¸ªå¯é¥ï¼ç¸å½äºè®¾å¤å
ç¨äºè§£å¯çå
¬é¥æ¯åºå®çï¼å¯ä»¥æå
¬é¥æ¾å°é
ç½®ä¸ï¼è¿éå
é»è®¤åæ» |
| | | // "MTlBODExMDA2MTkwMzQ4Q0I5QUY3QTc4QzAzOTQzNUU5NzNFODAzMEU4QUU1QzBEMkZFOEYwRjEzRjU4M0M5MTU5QUU5MTdDMDIzRDU0RDgxRUY2NTI0NkUyQ0Y2MUMzMTQzNTNENjA2NDU5N0Y2OTY5RUE4QjA5MUY1RTYyODM="; |
| | | // let buf = common.arrayBufferRsaDecrypt(deData, deData.length) |
| | | // 0 3 0 3 0 31 30 33 4 0 a 0 31 30 35 34 33 32 33 33 32 33 5 0 4 0 af 8c fa 5a 6 0 1 0 35 7 0 0 0 |
| | | // 0 |
| | | // 3 0 3 0 31 30 33 |
| | | // 4 0 a 0 31 30 35 34 33 32 33 33 32 33 |
| | | // 5 0 4 0 af 8c fa 5a |
| | | // 6 0 1 0 35 |
| | | // 7 0 0 0 |
| | | |
| | | offset = 1; |
| | | view = new Uint8Array(decryptedData) |
| | | // 4ãè§£æèº«ä»½ç±»å(type:103) |
| | | if (view[offset] == 0x03) { |
| | | // èº«ä»½ç±»åæ°æ®é¿åº¦ |
| | | offset += TLV_T_SIZE |
| | | let identityTypeLength = view[offset] |
| | | // èº«ä»½ç±»åæ°æ® |
| | | offset += TLV_L_SIZE |
| | | let identityTypeBuf = new Uint8Array(decryptedData, offset, identityTypeLength); |
| | | let identityType = String.fromCharCode.apply(null, identityTypeBuf); |
| | | offset += identityTypeLength |
| | | logger.info("èº«ä»½ç±»åæ°æ®: " + identityType) |
| | | } |
| | | |
| | | |
| | | // 5ãè§£ææéæ è¯(code) |
| | | if (view[offset] == 0x04) { |
| | | // æéæ è¯æ°æ®é¿åº¦ |
| | | offset += TLV_T_SIZE |
| | | let identityCodeLength = view[offset] |
| | | // æéæ è¯æ°æ® |
| | | offset += TLV_L_SIZE |
| | | let identityCodeBuf = new Uint8Array(decryptedData, offset, identityCodeLength); |
| | | offset += identityCodeLength |
| | | code = String.fromCharCode.apply(null, identityCodeBuf); |
| | | } |
| | | |
| | | |
| | | // 6ãè§£æçç æ¶é´ |
| | | if (view[offset] == 0x05) { |
| | | // çç æ¶é´æ°æ®é¿åº¦ |
| | | offset += TLV_T_SIZE |
| | | let createTimeLength = view[offset] |
| | | // çç æ¶é´æ°æ® |
| | | offset += TLV_L_SIZE |
| | | let createTimeBuf = new Uint8Array(decryptedData, offset, createTimeLength); |
| | | offset += createTimeLength |
| | | generationCodeTime = parseInt(common.arrayBufferToHexString(createTimeBuf.reverse()), 16) |
| | | } |
| | | |
| | | |
| | | // 7ãè§£æç è¿ææ¶é´ |
| | | if (view[offset] == 0x06) { |
| | | // ç è¿ææ¶é´æ°æ®é¿åº¦ |
| | | offset += TLV_T_SIZE |
| | | let expireTimeLength = view[offset] |
| | | // ç è¿ææ¶é´æ°æ® |
| | | offset += TLV_L_SIZE |
| | | let expireTimeBuf = new Uint8Array(decryptedData, offset, expireTimeLength); |
| | | offset += expireTimeLength |
| | | expirationTime = parseInt(String.fromCharCode.apply(null, expireTimeBuf)) |
| | | } |
| | | |
| | | // 8ãæ ¡éªéè¡ç æ¯å¦è¿æ |
| | | let timestamp = Date.now(); |
| | | expirationTime = generationCodeTime + expirationTime |
| | | if (expirationTime * 1000 > timestamp) { |
| | | return code |
| | | } else { |
| | | return null |
| | | } |
| | | |
| | | } |
| | | |
| | | const code = { |
| | | formatCode: function (msg, sqlObj) { |
| | | if (!msg) { |
| | | throw new Error("msg should not be null or empty") |
| | | } |
| | | if (!sqlObj) { |
| | | throw new Error("sqlObj should not be null or empty") |
| | | } |
| | | if (!sqliteObj) { |
| | | sqliteObj = sqlObj |
| | | } |
| | | |
| | | let data = {} |
| | | // 夿ç å¼ |
| | | if (comparePrefix(msg, "&llgy", "&llgy".length) || comparePrefix(msg, "&v101", "&v101".length)) { |
| | | // 101ç å¼ |
| | | data.type = 101 |
| | | data.code = decode101(msg.substring(5)) |
| | | } |
| | | else if (comparePrefix(msg, "vg://v103", "vg://v103".length)) { |
| | | // 103ç å¼ |
| | | data.type = 103 |
| | | data.code = decode103(msg.substring(9)) ? decode103(msg.substring(9)) : msg.substring(9) |
| | | } else if (comparePrefix(msg, "___VBAR_CONFIG_V1.1.0___", "___VBAR_CONFIG_V1.1.0___".length) || comparePrefix(msg, "___VBAR_KZB_V1.1.0___", "___VBAR_KZB_V1.1.0___".length)) { |
| | | //TODO å
è¿æ ·åï¼è®¨è®ºå¥½åæ´æ¹æµè½¬é»è¾ |
| | | data.type = 'config' |
| | | data.code = msg |
| | | } else { |
| | | data.type = 100 |
| | | data.code = msg |
| | | } |
| | | if (data.code) { |
| | | return data |
| | | } else { |
| | | console.log("decode fail") |
| | | return |
| | | } |
| | | } |
| | | } |
| | | |
| | | export default code; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //build: 20240525 |
| | | //ä¾èµç»ä»¶:dxCommon |
| | | import { sqliteClass } from './libvbar-m-dxsqlite.so' |
| | | import dxCommon from './dxCommon.js' |
| | | const sqliteObj = new sqliteClass(); |
| | | const sqlite = {} |
| | | |
| | | /** |
| | | * åå§åæ°æ®åº |
| | | * @param {string} path dbæä»¶å
¨è·¯å¾ï¼å¿
å¡« |
| | | * @param {string} id 奿idï¼éå¿
å¡«ï¼è¥åå§åå¤ä¸ªå®ä¾éè¦ä¼ å
¥å¯ä¸idï¼ |
| | | */ |
| | | sqlite.init = function (path, id) { |
| | | if (path == undefined || path.length == 0) { |
| | | throw new Error("dxsqliteObj.initDb:path should not be null or empty") |
| | | } |
| | | let pointer = sqliteObj.open(path); |
| | | dxCommon.handleId("sqlite", id, pointer) |
| | | } |
| | | |
| | | /** |
| | | * æ§è¡è¯å¥ |
| | | * @param {string} sql èæ¬è¯å¥ï¼å¿
å¡« |
| | | * @param {string} id 奿idï¼éå¿
å¡«ï¼éä¿æåinitä¸çidä¸è´ï¼ |
| | | * @returns 0:æåï¼é0失败 |
| | | */ |
| | | sqlite.exec = function (sql, id) { |
| | | let pointer = dxCommon.handleId("sqlite", id) |
| | | return sqliteObj.sql_exec(pointer, sql) |
| | | } |
| | | |
| | | |
| | | /** |
| | | * æ§è¡æ¥è¯¢è¯å¥ |
| | | * @param {string} sql èæ¬è¯å¥ï¼å¿
å¡« |
| | | * @param {string} id 奿idï¼éå¿
å¡«ï¼éä¿æåinitä¸çidä¸è´ï¼ |
| | | * @returns æ¥è¯¢ç»æï¼å½¢å¦ï¼[{"id":"1","type":200,"code":"aad7485a","door":"大é¨","extra":"","tiemType":0,"beginTime":1716613766,"endTime":1716613766,"repeatBeginTime":1716613766,"repeatEndTime":1716613766,"period":"extra"}] |
| | | */ |
| | | sqlite.select = function (sql, id) { |
| | | let pointer = dxCommon.handleId("sqlite", id) |
| | | return sqliteObj.select(pointer, sql); |
| | | } |
| | | |
| | | /** |
| | | * å
³éæ°æ®åºè¿æ¥ |
| | | * @param {string} id 奿idï¼éå¿
å¡«ï¼éä¿æåinitä¸çidä¸è´ï¼ |
| | | * @returns 0:æåï¼é0失败 |
| | | */ |
| | | sqlite.close = function (id) { |
| | | let pointer = dxCommon.handleId("sqlite", id) |
| | | return sqliteObj.close(pointer) |
| | | } |
| | | |
| | | export default sqlite; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //build 20240222 |
| | | //quickjs æ ååºï¼æä¾åæä½ç³»ç»ç¸å
³å½æ°ï¼æä¾æ åIOç¸å
³å½æ° |
| | | import * as os from "os" |
| | | import * as std from "std" |
| | | import common from "./dxCommon.js" |
| | | |
| | | const dxstd = {} |
| | | /** |
| | | * éåºåºç¨ |
| | | * @param {number} n éåºç |
| | | */ |
| | | dxstd.exit = function (n) { |
| | | return std.exit(n); |
| | | } |
| | | /** |
| | | * å¯å¨è®¡æ¶å¨ï¼å»¶æ¶å¼æ¥æ§è¡å½æ° |
| | | * @param {function} func éè¦æ§è¡ç彿° |
| | | * @param {number} delay å»¶è¿çæ¶é´ï¼æ¯«ç§ï¼ |
| | | * @returns timerå¼ç¨ |
| | | */ |
| | | dxstd.setTimeout = function (func, delay) { |
| | | return os.setTimeout(func, delay) |
| | | } |
| | | /** |
| | | * æ¸
餿å®ç计æ¶å¨ |
| | | * @param {*} handle timerå¼ç¨ |
| | | */ |
| | | dxstd.clearTimeout = function (handle) { |
| | | os.clearTimeout(handle) |
| | | } |
| | | // è®°å½å®æ¶å¨idï¼ç¨äºclearï¼åªè½å¨åä¸çº¿ç¨ä¸clear |
| | | let allTimerIdsMap = {} |
| | | |
| | | /** |
| | | * interval宿¶å¨ |
| | | * @param {function} callback åè°å½æ°ï¼å¿
å¡« |
| | | * @param {number} interval é´éæ¶é´ï¼å¿
å¡« |
| | | * @param {boolean} once å建åç«å³æ§è¡ä¸æ¬¡ï¼éå¿
å¡« |
| | | * @param {number} timerId 宿¶å¨idï¼éå¿
å¡« |
| | | */ |
| | | dxstd.setInterval = function (callback, interval, once, timerId) { |
| | | if (timerId === null || timerId === undefined) { |
| | | timerId = new Date().getTime() + "_" + this.genRandomStr(5) |
| | | allTimerIdsMap[timerId] = "ready" |
| | | } |
| | | if (once === true) { |
| | | // å建åç«å³æ§è¡ä¸æ¬¡ |
| | | os.setTimeout(() => { |
| | | if (allTimerIdsMap[timerId]) { |
| | | callback() |
| | | } |
| | | }, 0); |
| | | } |
| | | if (!allTimerIdsMap[timerId]) { |
| | | return |
| | | } |
| | | allTimerIdsMap[timerId] = os.setTimeout(() => { |
| | | if (allTimerIdsMap[timerId]) { |
| | | callback() |
| | | this.setInterval(callback, interval, false, timerId) |
| | | } |
| | | }, interval); |
| | | return timerId |
| | | } |
| | | |
| | | /** |
| | | * æ¸
é¤interval宿¶å¨ |
| | | * @param {number} timerId 宿¶å¨idï¼å¿
å¡« |
| | | */ |
| | | dxstd.clearInterval = function (timerId) { |
| | | const timer = allTimerIdsMap[timerId]; |
| | | if (timer) { |
| | | os.clearTimeout(timer); |
| | | delete allTimerIdsMap[timerId]; |
| | | } |
| | | } |
| | | /** |
| | | * å é¤å½åçº¿ç¨ææinterval宿¶å¨ï¼æ³¨æï¼åªæ¯å é¤å½å线ç¨å建ç宿¶å¨ï¼è¥æå¤ä¸ªçº¿ç¨ï¼æ¯ä¸ªçº¿ç¨é½éè¦è°ç¨å é¤ |
| | | */ |
| | | dxstd.clearIntervalAll = function () { |
| | | for (let timerId in allTimerIdsMap) { |
| | | if (allTimerIdsMap.hasOwnProperty(timerId)) { |
| | | os.clearTimeout(allTimerIdsMap[timerId]); |
| | | delete allTimerIdsMap[timerId]; |
| | | } |
| | | } |
| | | } |
| | | /** |
| | | * çææå®é¿åº¦ç忝忰åç»åçéæºå符串 |
| | | * @param {number} length å符串é¿åº¦ï¼éå¿
å¡«ï¼ç¼ºçæ¯6 |
| | | * @returns |
| | | */ |
| | | dxstd.genRandomStr = function (length = 6) { |
| | | const charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' |
| | | let result = '' |
| | | for (let i = 0; i < length; i++) { |
| | | const randomIndex = Math.floor(Math.random() * charset.length) |
| | | result += charset.charAt(randomIndex) |
| | | } |
| | | return result |
| | | } |
| | | /** |
| | | * æä¸æ®µå符串ä½ä¸º javascript èæ¬æ§è¡ |
| | | * @param {string} str jsèæ¬å符串 |
| | | * @param {boolean} async é»è®¤ä¸ºfalseï¼å¦æä¸º trueï¼èæ¬ä¸å°æ¥å await å¹¶è¿åä¸ä¸ª Promise |
| | | */ |
| | | dxstd.eval = function (str, async) { |
| | | return std.evalScript(str, { async: async }); |
| | | } |
| | | /** |
| | | * å è½½ä¸ä¸ªæä»¶å
容ä½ä¸º javascript èæ¬æ§è¡ |
| | | * @param {string} filename jsèæ¬å
容çæä»¶å(ç»å¯¹è·¯å¾) |
| | | */ |
| | | dxstd.loadScript = function (filename) { |
| | | return std.loadScript(filename); |
| | | } |
| | | /** |
| | | * å è½½æä»¶ï¼è¯»åæä»¶éçå
容ï¼ä½¿ç¨utfï¼ |
| | | * @param {string} filename æä»¶å |
| | | */ |
| | | dxstd.loadFile = function (filename) { |
| | | return std.loadFile(filename) |
| | | } |
| | | /** |
| | | * ä¿ååç¬¦ä¸²å°æä»¶ |
| | | * @param {string} filename |
| | | * @param {string} content |
| | | */ |
| | | dxstd.saveFile = function (filename, content) { |
| | | if (!content || (typeof content) != 'string') { |
| | | throw new Error("The 'content' value should be string and not empty") |
| | | } |
| | | if (!filename) { |
| | | throw new Error("The 'filename' should not be empty") |
| | | } |
| | | if (!this.exist(filename)) { |
| | | this.ensurePathExists(filename) |
| | | let fd = os.open(filename, os.O_RDWR | os.O_CREAT | os.O_TRUNC); |
| | | if (fd < 0) { |
| | | throw new Error("Create file failed:" + filename) |
| | | } |
| | | os.close(fd) |
| | | } |
| | | let fd = std.open(filename, "w"); |
| | | fd.puts(content) |
| | | fd.flush(); |
| | | fd.close(); |
| | | common.systemBrief('sync') |
| | | return true |
| | | } |
| | | /** |
| | | * ç¡®ä¿æä»¶å¯¹åºçç®å½é½åå¨ï¼ä¸åå¨å°±ä¼å建 |
| | | * @param {string} filename |
| | | */ |
| | | dxstd.ensurePathExists = function (filename) { |
| | | const pathSegments = filename.split('/'); |
| | | let currentPath = ''; |
| | | for (let i = 0; i < pathSegments.length - 1; i++) { |
| | | currentPath += pathSegments[i] + '/'; |
| | | if (!this.exist(currentPath)) { |
| | | this.mkdir(currentPath); |
| | | } |
| | | } |
| | | } |
| | | /** |
| | | * 夿æä»¶æ¯å¦åå¨ |
| | | * @param {string} filename æä»¶å |
| | | * @returns true/false |
| | | */ |
| | | dxstd.exist = function (filename) { |
| | | return (os.stat(filename)[1] === 0) |
| | | } |
| | | /** |
| | | * è¿åä¸ä¸ªå
å«ç¯å¢åéçé®å¼å¯¹ç对象ã |
| | | */ |
| | | dxstd.getenviron = function () { |
| | | return std.getenviron(); |
| | | } |
| | | /** |
| | | * è¿åç¯å¢åéåç§°çå¼ï¼å¦ææªå®ä¹åè¿åundefined |
| | | * @param {string} name åéå |
| | | */ |
| | | dxstd.getenv = function (name) { |
| | | return std.getenv(name); |
| | | } |
| | | /** |
| | | * å°ç¯å¢åéåçå¼è®¾ç½®ä¸ºåç¬¦ä¸²å¼ |
| | | * @param {string} name åéå |
| | | * @param {string} value åéå¼ |
| | | */ |
| | | dxstd.setenv = function (name, value) { |
| | | return std.setenv(name, value); |
| | | } |
| | | /** |
| | | * å é¤ç¯å¢åé |
| | | * @param {string} name åéå |
| | | */ |
| | | dxstd.unsetenv = function (name) { |
| | | return std.unsetenv(name); |
| | | } |
| | | /** |
| | | * 使ç¨JSON.parseçè¶
éæ¥è§£æå符串ãå¯ä»¥è§£æéæ åç JSON åç¬¦ä¸²ãæ¥å以䏿©å±ï¼ |
| | | * - åè¡åå¤è¡æ³¨é |
| | | * - æªå å¼å·ç屿§ï¼ä»
ASCIIå符çJavaScriptæ è¯ç¬¦ï¼ |
| | | * - æ°ç»å对象æåå¯ä»¥å éå· |
| | | * - åå¼å·å符串 |
| | | * - \f å \v 被æ¥åä¸ºç©ºæ ¼å符 |
| | | * - æ°åä¸çåé¢å¯ä»¥æå å· |
| | | * - å
«è¿å¶ï¼0oåç¼ï¼ååå
è¿å¶ï¼0xåç¼ï¼æ°å |
| | | * @param {string} str jsonå符串 |
| | | */ |
| | | dxstd.parseExtJSON = function (str) { |
| | | return std.parseExtJSON(str); |
| | | } |
| | | /** |
| | | * ä¼ç delay_msæ¯«ç§ |
| | | */ |
| | | dxstd.sleep = function (delay_ms) { |
| | | return os.sleep(delay_ms); |
| | | } |
| | | /** |
| | | * è¿å表示平å°çå符串ï¼"linux"ã"darwin"ã"win32" æ "js"ã |
| | | */ |
| | | dxstd.platform = function () { |
| | | return os.platform; |
| | | } |
| | | /** |
| | | * å建ä¸ä¸ªæ°çº¿ç¨ï¼workerï¼çæé 彿°ï¼å
¶APIæ¥è¿äºWebWorkersã |
| | | * 对äºå¨æå¯¼å
¥ç模åï¼å®ç¸å¯¹äºå½åèæ¬ææ¨¡åè·¯å¾ã线ç¨é常ä¸å
±äº«ä»»ä½æ°æ®ï¼å¯ä»¥éè¿dxMap,dxQueue,dxWpcæ¥å
±äº«åä¼ éæ°æ®ã䏿¯æåµå¥ç workerã |
| | | * @param {string} module_filename æå®å¨æ°å建ç线ç¨ä¸æ§è¡ç模åæä»¶å |
| | | */ |
| | | dxstd.Worker = function (module_filename) { |
| | | return new os.Worker(module_filename) |
| | | } |
| | | |
| | | dxstd.O_RDONLY = os.O_RDONLY |
| | | dxstd.O_WRONLY = os.O_WRONLY |
| | | dxstd.O_RDWR = os.O_RDWR |
| | | dxstd.O_APPEND = os.O_APPEND |
| | | dxstd.O_CREAT = os.O_CREAT |
| | | dxstd.O_EXCL = os.O_EXCL |
| | | dxstd.O_TRUNC = os.O_TRUNC |
| | | /** |
| | | * æå¼ä¸ä¸ªæä»¶ãè¿åä¸ä¸ªå¥æï¼å¦æåºç°é误åè¿å < 0ã |
| | | * @param {string} filename æä»¶ç»å¯¹è·¯å¾ |
| | | * @param {number} flags O_RDONLY,O_WRONLY,O_RDWR,O_APPEND,O_CREAT,O_EXCL,O_TRUNC |
| | | * 1. O_RDONLY ï¼ä»¥åªè¯»æ¹å¼æå¼æä»¶ |
| | | * 2. O_WRONLY ï¼ä»¥åªåæ¹å¼æå¼æä»¶ |
| | | * 3. O_RDWR ï¼ä»¥å¯è¯»å¯åæ¹å¼æå¼æä»¶ |
| | | * 以ä¸ä¸ä¸ªæ¯æä»¶è®¿é®æéæ å¿ï¼ä¼ å
¥çflags åæ°ä¸å¿
é¡»è¦å
å«å
¶ä¸ä¸ç§æ å¿ï¼èä¸åªè½å
å«ä¸ç§ï¼æå¼çæä»¶åªè½æç
§è¿ç§æéæ¥æä½ï¼ |
| | | è¬å¦ä½¿ç¨äº O_RDONLY æ å¿ï¼å°±åªè½å¯¹æä»¶è¿è¡è¯»åæä½ï¼ä¸è½åæä½ã |
| | | |
| | | * 4. O_APPEND ï¼è°ç¨ open 彿°æå¼æä»¶ï¼å½æ¯æ¬¡ä½¿ç¨ write()彿°å¯¹æä»¶è¿è¡åæä½æ¶ï¼é½ä¼èªå¨ææä»¶å½åä½ç½®åç§»éç§»å¨å°æä»¶æ«å°¾ï¼ |
| | | 仿件æ«å°¾å¼å§åå
¥æ°æ®ï¼ä¹å°±æ¯æå³çæ¯æ¬¡åå
¥æ°æ®é½æ¯ä»æä»¶æ«å°¾å¼å§ã |
| | | O_APPENDæ å¿å¹¶ä¸ä¼å½±å读æä»¶ï¼å½è¯»åæä»¶æ¶ï¼ O_APPEND æ å¿å¹¶ä¸ä¼å½±å读ä½ç½®åç§»éï¼ |
| | | å³ä½¿ä½¿ç¨äº O_APPENDæ å¿ï¼è¯»æä»¶ä½ç½®åç§»éé»è®¤æ
åµä¸ä¾ç¶æ¯æä»¶å¤´ï¼ |
| | | ä½¿ç¨ lseek 彿°æ¥æ¹å write()æ¶çåä½ç½®åç§»éä¹ä¸ä¼æåï¼ |
| | | 彿§è¡ write()彿°æ¶ï¼æ£æµå° open 彿°æºå¸¦äº O_APPEND æ å¿ï¼æä»¥å¨ write 彿°å
é¨ä¼èªå¨å°åä½ç½®åç§»éç§»å¨å°æä»¶æ«å°¾ |
| | | |
| | | * 5. O_CREATï¼å¦æ filename åæ°æåçæä»¶ä¸åå¨ååå»ºæ¤æä»¶ |
| | | * 6. O_EXCL :æ¤æ å¿ä¸è¬ç»å O_CREAT æ å¿ä¸èµ·ä½¿ç¨ï¼ç¨äºä¸é¨å建æä»¶ã |
| | | å¨ flags åæ°åæ¶ä½¿ç¨å°äº O_CREAT åO_EXCL æ å¿çæ
åµä¸ï¼å¦æ filename åæ°æåçæä»¶å·²ç»åå¨ï¼ |
| | | å open 彿°è¿åé误ãå¯ä»¥ç¨äºæµè¯ä¸ä¸ªæä»¶æ¯å¦åå¨ï¼å¦æä¸åå¨ååå»ºæ¤æä»¶ï¼å¦æåå¨åè¿åé误ï¼è¿ä½¿å¾æµè¯åå建两è
æä¸ºä¸ä¸ªååæä½ã |
| | | * 7. O_TRUNC ï¼è°ç¨ open 彿°æå¼æä»¶çæ¶åä¼å°æä»¶åæ¬çå
容å
¨é¨ä¸¢å¼ï¼æä»¶å¤§å°å为 0ï¼ |
| | | */ |
| | | dxstd.open = function (filename, flags) { |
| | | return os.open(filename, flags); |
| | | } |
| | | /** |
| | | * 夿ç»å®è·¯å¾æ¯å¦æ¯ä¸ä¸ªæä»¶å¤¹ã |
| | | * @param {string} filename - è¦æ£æ¥çè·¯å¾ã |
| | | * @returns {boolean} å¦ææ¯æä»¶å¤¹åè¿å trueï¼å¦åè¿å false,妿ä¸åå¨ï¼æåºå¼å¸¸ã |
| | | */ |
| | | dxstd.isDir = function (filename) { |
| | | let stat = os.stat(filename) |
| | | if (stat[1] != 0) { |
| | | throw new Error("No such file:" + filename) |
| | | } |
| | | return ((stat[0].mode & this.S_IFMT) === this.S_IFDIR); |
| | | } |
| | | /** |
| | | * å
³éæä»¶ |
| | | * @param {*} fd æä»¶å¥æ |
| | | */ |
| | | dxstd.close = function (fd) { |
| | | return os.close(fd) |
| | | } |
| | | dxstd.SEEK_SET = std.SEEK_SET |
| | | dxstd.SEEK_CUR = std.SEEK_CUR |
| | | dxstd.SEEK_END = std.SEEK_END |
| | | /** |
| | | * 卿件ä¸è¿è¡å®ä½ã使ç¨SEEK_*æ¥è¡¨ç¤ºwhenceãoffsetå¯ä»¥æ¯æ°åæbigintã妿offsetæ¯bigintï¼åè¿åä¸ä¸ªbigintã |
| | | * @param {*} fd æä»¶å¥æ |
| | | * @param {number} offset 为åç§»éï¼æ´æ°è¡¨ç¤ºæ£ååç§»ï¼è´æ°è¡¨ç¤ºè´ååç§» |
| | | * @param {*} whence 设å®ä»æä»¶çåªéå¼å§åç§»: SEEK_SETï¼ æä»¶å¼å¤´;SEEK_CURï¼ å½åä½ç½®;SEEK_ENDï¼ æä»¶ç»å°¾ |
| | | */ |
| | | dxstd.seek = function (fd, offset, whence) { |
| | | return os.seek(fd, offset, whence) |
| | | } |
| | | /** |
| | | * 仿件奿fd读ålengthåèå°ä½äºåèä½ç½®offsetçArrayBufferç¼å²åºãè¿å读åçåèæ°ï¼å¦æåºç°é误åè¿å < 0ã |
| | | * @param {*} fd æä»¶å¥æ |
| | | * @param {*} buffer ArrayBuffer对象 |
| | | * @param {number} offset åç§»é |
| | | * @param {number} length 读åçåèé¿åº¦ |
| | | */ |
| | | dxstd.read = function (fd, buffer, offset, length) { |
| | | return os.read(fd, buffer, offset, length); |
| | | } |
| | | /** |
| | | * ä»ArrayBufferç¼å²åºçåèä½ç½®offsetåæä»¶å¥æfdåå
¥lengthåèãè¿åå·²åå
¥çåèæ°ï¼å¦æåºç°é误åè¿å < 0ã |
| | | * @param {*} fd æä»¶å¥æ |
| | | * @param {*} buffer ArrayBuffer对象 |
| | | * @param {*} offset åç§»é |
| | | * @param {*} length åçåèé¿åº¦ |
| | | */ |
| | | dxstd.write = function (fd, buffer, offset, length) { |
| | | return os.write(fd, buffer, offset, length); |
| | | } |
| | | /** |
| | | * å é¤æä»¶ï¼æåè¿å0å¦å-errno |
| | | * @param {string} filename æä»¶ç»å¯¹è·¯å¾ |
| | | */ |
| | | dxstd.remove = function (filename) { |
| | | return os.remove(filename) |
| | | } |
| | | /** |
| | | * ä¿®æ¹æä»¶åç§°ï¼æåè¿å0å¦å-errno |
| | | * @param {string} oldname æ§æä»¶ç»å¯¹è·¯å¾ |
| | | * @param {string} newname æ°æä»¶ç»å¯¹è·¯å¾ |
| | | */ |
| | | dxstd.rename = function (oldname, newname) { |
| | | return os.rename(oldname, newname) |
| | | } |
| | | /** |
| | | * è¿å [str, err]ï¼å
¶ä¸ str æ¯å½åå·¥ä½ç®å½ï¼err æ¯é误代ç |
| | | */ |
| | | dxstd.getcwd = function () { |
| | | return os.getcwd() |
| | | } |
| | | /** |
| | | * æ¹åå½åå·¥ä½ç®å½ |
| | | * @param {string} path ç®å½,æ¯æç»å¯¹åç¸å¯¹è·¯å¾ |
| | | */ |
| | | dxstd.chdir = function (path) { |
| | | return os.chdir(path) |
| | | } |
| | | /** |
| | | * å建ç®å½,æåè¿å0å¦å-errno |
| | | * @param {string} path ç®å½ç»å¯¹è·¯å¾ |
| | | */ |
| | | dxstd.mkdir = function (path) { |
| | | return os.mkdir(path) |
| | | } |
| | | dxstd.S_IFMT = os.S_IFMT |
| | | dxstd.S_IFIFO = os.S_IFIFO |
| | | dxstd.S_IFCHR = os.S_IFCHR |
| | | dxstd.S_IFDIR = os.S_IFDIR |
| | | dxstd.S_IFBLK = os.S_IFBLK |
| | | dxstd.S_IFREG = os.S_IFREG |
| | | dxstd.S_IFSOCK = os.S_IFSOCK |
| | | dxstd.S_IFLNK = os.S_IFLNK |
| | | dxstd.S_ISGID = os.S_ISGID |
| | | dxstd.S_ISUID = os.S_ISUID |
| | | /** |
| | | * è¿å [obj, err]ï¼å
¶ä¸ obj æ¯ä¸ä¸ªå
å«è·¯å¾pathçæä»¶ç¶æä¿¡æ¯ç对象ã |
| | | * err æ¯é误代ç ãobj ä¸å®ä¹äºä»¥ä¸å段ï¼devãinoãmodeãnlinkãuidãgidãrdevãsizeãblocksãatimeãmtimeãctimeã |
| | | * æ¶é´ä»¥èª1970年以æ¥ç毫ç§ä¸ºå使å®ã |
| | | * å
¶ä¸modeçå¼å¯¹åºä»¥ä¸æä¸¾,ä¾å¦ï¼æ£æ¥ä¸ä¸ªæä»¶æ¯å¦æ¯ç®å½å¯ä»¥ä½¿ç¨ (mode & S_IFMT) == S_IFDIR çæ¹å¼: |
| | | S_IFMTï¼ä½æ©ç ï¼ç¨äºæåæä»¶ç±»åé¨åçä½ãè¿æ¯ä¸ä¸ªç¨äºå±è½æä»¶ç±»åä½ç常éã |
| | | S_IFIFOï¼è¡¨ç¤ºFIFOï¼å½å管éï¼ã |
| | | S_IFCHRï¼è¡¨ç¤ºå符设å¤ã |
| | | S_IFDIRï¼è¡¨ç¤ºç®å½ã |
| | | S_IFBLKï¼è¡¨ç¤ºå设å¤ã |
| | | S_IFREGï¼è¡¨ç¤ºå¸¸è§æä»¶ã |
| | | S_IFSOCKï¼è¡¨ç¤ºå¥æ¥åã |
| | | S_IFLNKï¼è¡¨ç¤ºç¬¦å·é¾æ¥ã |
| | | S_ISGIDï¼è®¾ç½®ç»IDä½ã |
| | | S_ISUIDï¼è®¾ç½®ç¨æ·IDä½ã |
| | | * @param {string} path æä»¶æç®å½ç»å¯¹è·¯å¾ |
| | | */ |
| | | dxstd.stat = function (path) { |
| | | return os.stat(path) |
| | | } |
| | | /** |
| | | * lstat() ä¸ stat() ç¸åï¼åªæ¯å®è¿åå
³äºé¾æ¥æ¬èº«çä¿¡æ¯ã |
| | | * @param {*} path æä»¶æç®å½ç»å¯¹è·¯å¾ |
| | | */ |
| | | dxstd.lstat = function (path) { |
| | | return os.lstat(path) |
| | | } |
| | | /** |
| | | * è¿å [array, err]ï¼å
¶ä¸ array æ¯å
å«ç®å½è·¯å¾ä¸çæä»¶åçå符串æ°ç»ãerr æ¯é误代ç ã |
| | | * @param {string} path ç®å½ç»å¯¹è·¯å¾ |
| | | */ |
| | | dxstd.readdir = function (path) { |
| | | return os.readdir(path) |
| | | } |
| | | export default dxstd |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //build: 20240715 |
| | | //æ°æ®éä¿¡ééï¼å
æ¬ä¸²å£ï¼Serial portï¼ãUSBï¼Universal Serial Busï¼å馿 ¹ï¼Wiegandï¼ |
| | | //ä¾èµç»ä»¶:dxDriverï¼dxStdï¼dxLoggerï¼dxMapï¼dxEventBus,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äººä½æ¥å£è®¾å¤ï¼USB Human Interface Deviceï¼ééç±»å |
| | | UART: 3,//表示UARTééç±»åï¼å³ä¸²å£éé |
| | | WIEGAND: 4//馿 ¹ï¼Wiegandï¼ééç±»å |
| | | } |
| | | |
| | | /* åç±»éé 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, |
| | | /* è®¾ç½®é¦æ ¹ééçGPIOé
ç½® */ |
| | | 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 ä¸åçè®¾å¤æåä¸è®¾å¤çä¸åç±»åéé对åºçpathä¸ä¸æ ·ï¼æ¯å¦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ï¼éå¿
å¡«ï¼éä¿æåinitä¸ç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ï¼éå¿
å¡«ï¼éä¿æåinitä¸ç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é¿åº¦ï¼ä¼ç»§ç»çå¾
ç´å°æ¥æ¶å°sizeé¿åº¦ï¼ä½æ¯å¦ætimeoutå¾çï¼å°±ä¼æå¯è½æ²¡æ¶å®å°±ç»æè¿ä¸æ¬¡æä½ |
| | | * @param {number} size æ¥æ¶æ°æ®çåèæ°ï¼å¿
å¡« |
| | | * @param {number} timeout è¶
æ¶æ¶é´ï¼æ¯«ç§ï¼è¿ä¸ªå½æ°ä¼é»å¡çå¾
æå¤è¿ä¸ªæ¶é´å°±ç»æï¼å¦ææåæ¥æ¶å°äºsizeä¸ªæ°æ®ä¹ä¼ç»æï¼éå¿
å¡«ï¼ç¼ºçæ¯10ms |
| | | * @param {string} id 奿idï¼éå¿
å¡«ï¼éä¿æåinitä¸ç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ï¼éå¿
å¡«ï¼éä¿æåinitä¸ç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ï¼éå¿
å¡«ï¼éä¿æåinitä¸ç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ï¼éå¿
å¡«ï¼éä¿æåinitä¸ç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çäºè¿å¶çæ°æ®æ¥åå°åè§£ææå¯¹è±¡ï¼å¹¶ä»¥eventbusçeventåéåºå»(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. åéæ°æ®ï¼æå¯¹è±¡è½¬æTLVæ ¼å¼çäºè¿å¶æ°æ®ååéåºå»ï¼å¯ä»¥éè¿uart.sendVg('è¦åéçæ°æ®',id)ï¼æ°æ®æ ¼å¼å¦ä¸ |
| | | * åéçæ°æ®æ ¼å¼æäºç§ 1.å¯¹è±¡æ ¼å¼ ï¼{cmd:"2a",result:"01",length:7,data:"0a1acc320fee32"} 2. 宿´ç16è¿å¶å符串'55AA09000000F6' |
| | | * 3. åæ ·çidï¼å¤æ¬¡è°ç¨runvgä¹åªä¼æ§è¡ä¸æ¬¡ |
| | | * |
| | | * @param {object} options å¯å¨çåæ° |
| | | * @param {number} options.type ééç±»åï¼åèæä¸¾ TYPEï¼å¿
å¡« ï¼å
¼å®¹USBHIDåä¼ è¾ï¼é»è®¤1024æ¯åï¼ |
| | | * @param {string} options.path ä¸åçè®¾å¤æåä¸è®¾å¤çä¸åç±»åéé对åºçpathä¸ä¸æ ·ï¼æ¯å¦DW200ç485对åºç弿¯"/dev/ttyS2"ï¼å¿
å¡« |
| | | * @param {number} options.result 0å1(ç¼ºçæ¯0)ï¼æ è¯æ¯æ¥æ¶çæ°æ®è¿æ¯åéçæ°æ®å
嫿 è¯åèï¼0表示æ¥åçæ°æ®ä¸å
æ¬æ è¯åï¼åéçæ°æ®å
æ¬ï¼1æ¯åä¹ |
| | | * @param {number} options.passThrough passThrough为true忥æ¶çæ°æ®ä½¿ç¨éä¼ æ¨¡å¼ï¼éå¿
å¡« |
| | | * @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; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //build:20240724 |
| | | /** |
| | | * UI çåºç¡ç»ä»¶ï¼éè¦å
äºè§£ä¸äºæ¦å¿µ |
| | | * 1. å¾å±ï¼è®¾å¤å
·å¤2ä¸ªåºæ¬å¾å±ï¼ä¸»å¾å±ï¼mainï¼åé¡¶é¨å¾å±ï¼topï¼ |
| | | å
¶ä¸TOPå¾å±æ°¸è¿å¨ä¸»å¾å±ä¹ä¸ï¼ä¸»å¾å±åæ¢é¡µé¢ä¸ä¼æ¡ä½TOPå¾å±ï¼TOPå¾å±ç¨äºæ¾ç¤ºä¸äºç¶ææ æ¯æ¯è¾åéçã |
| | | å
¶ä¸ä¸»å¾å±å¯ä»¥é¢å
å¨å
å䏿é å¤ä¸ªé¡µé¢ï¼ç¶åéè¿loadMainæ¥å è½½åæ¢ä¸åç页é¢ãèTOPå¾å±ä¸è½åæ¢ï¼åªè½è®©ui对象éèæå é¤ |
| | | |
| | | * 2. UIå¯¹è±¡ï¼æå¾å¤ç§ç±»çUI对象ï¼å
¶ä¸æåºç¡çæ¯ 'view' 对象ï¼ä¸»å¾å±åé¡¶é¨å¾å±çæ ¹ui对象å¿
é¡»æ¯ 'view'对象ï¼å©ä¸ç ui å¯¹è±¡é½æ¯æä¸ª ui 对象çåuiã |
| | | ui对象å
æ¬å¸¸è§ç 'button'ã'label'ã'image'ççï¼ææå¯¹è±¡é½æä¸äºéç¨ç屿§ï¼ä¹æä¸äºç¬ç¹ç屿§ |
| | | ææ ui å¯¹è±¡é½æå
¨å±å¯ä¸ç id ï¼ä¸è½éå¤ãéç¨ç屿§è¿å
æ¬ |
| | | - typeï¼è·åui对象çç±»åï¼å符串 |
| | | - parentï¼è·åui对象çç¶èç¹ï¼å符串 |
| | | - childrenï¼è·åuiå¯¹è±¡çææå对象çidï¼å符串æ°ç» |
| | | |
| | | * 3. dxuiæä»¶ï¼ä»¥.dxui为æ©å±åçæä»¶æ¯å©ç¨å¯è§åææ½å·¥å
·çæç ui æ ,å·¥å
·ä¼èªå¨çæå¯¹åºçjsæä»¶ï¼å¯ä»¥import对åºçjsæä»¶æ¥æä½ |
| | | |
| | | */ |
| | | |
| | | import logger from './dxLogger.js' |
| | | import utils from './uiUtils.js' |
| | | import button from './uiButton.js' |
| | | import font from './uiFont.js' |
| | | import image from './uiImage.js' |
| | | import label from './uiLabel.js' |
| | | import line from './uiLine.js' |
| | | import list from './uiList.js' |
| | | import dropdown from './uiDropdown.js' |
| | | import checkbox from './uiCheckbox.js' |
| | | import slider from './uiSlider.js' |
| | | import _switch from './uiSwitch.js' |
| | | import textarea from './uiTextarea.js' |
| | | import keyboard from './uiKeyboard.js' |
| | | import style from './uiStyle.js' |
| | | import view from './uiView.js' |
| | | import buttons from './uiButtons.js' |
| | | |
| | | const dxui = {} |
| | | dxui.Button = button |
| | | dxui.Font = font |
| | | dxui.Image = image |
| | | dxui.Label = label |
| | | dxui.Line = line |
| | | dxui.List = list |
| | | dxui.Dropdown = dropdown |
| | | dxui.Checkbox = checkbox |
| | | dxui.Slider = slider |
| | | dxui.Switch = _switch |
| | | dxui.Textarea = textarea |
| | | dxui.Keyboard = keyboard |
| | | dxui.Style = style |
| | | dxui.View = view |
| | | dxui.Utils = utils |
| | | dxui.Buttons = buttons |
| | | let orientation = 1 //é»è®¤æ¨ªå± |
| | | /** |
| | | * åå§åï¼å¿
é¡»å¨ä»£ç æåé¢è°ç¨ |
| | | * @param {object} options åå§ååæ° |
| | | * @param {number} options.orientation å±å¹æ¹å å¯ä»¥ä¸º0ï¼1ï¼2ï¼3ï¼åå«è¡¨ç¤ºç«å±ï¼å±å¹å¨å·¦ï¼æ¨ªå±ï¼å±å¹å¨ä¸ï¼ç«å±ï¼å±å¹å¨å³ï¼æ¨ªæ¹ï¼å±å¹å¨ä¸ |
| | | * @param {object} context ä¸ä¸æï¼æ¯ä¸ªåºç¨é½æå¯ä¸çä¸ä¸ªä¸ä¸æåéï¼ä¸åçjså¯ä»¥é½å¼ç¨dxUi.jsï¼ä½æ¯contextå¿
é¡»ä¸è´ |
| | | */ |
| | | dxui.init = function (options, context = {}) { |
| | | this.initContext(context) |
| | | if (options && options.orientation != undefined && options.orientation != null && [0, 1, 2, 3].includes(options.orientation)) { |
| | | orientation = options.orientation |
| | | } |
| | | utils.GG.NativeDisp.lvDispSetRotation(orientation) |
| | | } |
| | | /** |
| | | * åå§åä¸ä¸æï¼æ¯ä¸ªåºç¨é½æå¯ä¸çä¸ä¸ªä¸ä¸æåéï¼ä¸åçjså¯ä»¥é½å¼ç¨dxUi.jsï¼ä½æ¯contextå¿
é¡»ä¸è´ |
| | | * å¨æå»ºuiåéè¦åå§å |
| | | * @param {object} context åå§æ¯ä¸ä¸ªç©ºå¯¹è±¡{} |
| | | */ |
| | | dxui.initContext = function (context) { |
| | | utils.validateObject(context) |
| | | dxui.all = context |
| | | dxui.Button.all = dxui.all |
| | | dxui.Image.all = dxui.all |
| | | dxui.Label.all = dxui.all |
| | | dxui.Line.all = dxui.all |
| | | dxui.List.all = dxui.all |
| | | dxui.Dropdown.all = dxui.all |
| | | dxui.Checkbox.all = dxui.all |
| | | dxui.Slider.all = dxui.all |
| | | dxui.Switch.all = dxui.all |
| | | dxui.Textarea.all = dxui.all |
| | | dxui.Keyboard.all = dxui.all |
| | | dxui.View.all = dxui.all |
| | | dxui.Buttons.all = dxui.all |
| | | } |
| | | /** |
| | | * æ ¹æ®idè·åå·²ç»æå»ºçui对象 |
| | | * @param {string} id |
| | | * @returns |
| | | */ |
| | | dxui.getUi = function (id) { |
| | | return dxui.all[id] |
| | | } |
| | | /** |
| | | * å¤é¨å¾ªç¯éè¦è°ç¨æ¤æ¹æ³ |
| | | */ |
| | | dxui.handler = function () { |
| | | return utils.GG.NativeTimer.lvTimerHandler() |
| | | } |
| | | /** |
| | | * è·åå±å¹æ¹åï¼ä¸åçå±å¹æ¹åå¯è½è¦å è½½ä¸åçuiæä¸åçå¤çé»è¾ |
| | | * @returns å¯ä»¥ä¸º0ï¼1ï¼2ï¼3ï¼åå«è¡¨ç¤ºç«å±ï¼å±å¹å¨å·¦ï¼æ¨ªå±ï¼å±å¹å¨ä¸ï¼ç«å±ï¼å±å¹å¨å³ï¼æ¨ªæ¹ï¼å±å¹å¨ä¸ |
| | | */ |
| | | dxui.getOrientation = function () { |
| | | return orientation; |
| | | } |
| | | /** |
| | | * å建ä¸ä¸ªå®æ¶å¨ï¼æ¯émsæ¯«ç§æ§è¡ä¸æ¬¡åè°å½æ°ï¼ä¸»è¦ç¨äºå®æ¶å·æ°æä¸ªui对象çå¼ |
| | | * å¯ä»¥å¨åè°å½æ°éå é¤å®æ¶å¨(clearInterval)æ¥å®ç°setTimeoutçææ |
| | | * @param {string} id 宿¶å¨çå¯ä¸æ è¯ å¿
å¡« |
| | | * @param {function} callback åè°å½æ°ï¼å¯ä»¥æ¯å¿å彿°ï¼ |
| | | * @param {number} ms æ¯«ç§æ° |
| | | * @param {object} user_data ç¨æ·æ°æ®ï¼ä¼ éç»åè°åæ° |
| | | * @returns 宿¶å¨å¥æ |
| | | */ |
| | | dxui.setInterval = function (id, callback, ms, user_data) { |
| | | if (utils.validateId(dxui.all, id)) |
| | | if (!callback || (typeof callback != 'function') || !callback.name || callback.name === '') { |
| | | throw new Error('The callback should not be null and should be named function') |
| | | } |
| | | if (!ms || (typeof ms != 'number')) { |
| | | throw new Error('The interval should not be empty, and should be number') |
| | | } |
| | | if (!this.all.__interval) { |
| | | this.all.__interval = {} |
| | | } |
| | | this.all.__interval[id] = utils.GG.NativeTimer.lvTimerCreate(callback, ms, user_data) |
| | | } |
| | | /** |
| | | * 宿¶å¨ä¸åéè¦åï¼å¯ä»¥å é¤è¿ä¸ªå®æ¶å¨ |
| | | * @param {string} id 宿¶å¨id |
| | | */ |
| | | dxui.clearInterval = function (id) { |
| | | if (!dxui.all[id]) { |
| | | return |
| | | } |
| | | utils.GG.NativeTimer.lvTimerDel(dxui.all[id]) |
| | | delete dxui.all.__interval[id] |
| | | } |
| | | /** |
| | | * è·åui对象çç¶å¯¹è±¡ |
| | | * @param {Object} ui |
| | | */ |
| | | dxui.getParent = function (ui) { |
| | | if (ui.parent) { |
| | | return dxui.getUi(ui.parent) |
| | | } |
| | | return null |
| | | } |
| | | /** |
| | | * å é¤å½åèªèº«ui对象 |
| | | */ |
| | | dxui.del = function (ui) { |
| | | function recursiveDelete(ui) { |
| | | // å¦æå¯¹è±¡ä¸åå¨ï¼ç´æ¥è¿å |
| | | if (!dxui.all[ui.id]) { |
| | | return; |
| | | } |
| | | |
| | | // å
éå½å 餿æå对象 |
| | | if (ui.children && Array.isArray(ui.children)) { |
| | | // ååºéååèç¹ |
| | | for (let i = ui.children.length - 1; i >= 0; i--) { |
| | | const childId = ui.children[i]; |
| | | if (dxui.all[childId]) { |
| | | recursiveDelete(dxui.all[childId]); |
| | | } |
| | | } |
| | | } |
| | | // ä»ç¶å¯¹è±¡ä¸ç§»é¤å½å对象 |
| | | if (ui.parent && dxui.all[ui.parent] && Array.isArray(dxui.all[ui.parent].children)) { |
| | | const children = dxui.all[ui.parent].children |
| | | let index = children.indexOf(ui.id); |
| | | if (index !== -1) { |
| | | children.splice(index, 1); |
| | | } |
| | | } |
| | | |
| | | // å é¤å½å对象 |
| | | ui.obj.lvObjDel(); |
| | | delete dxui.all[ui.id]; |
| | | } |
| | | |
| | | // å¼å§éå½å é¤ |
| | | recursiveDelete(ui); |
| | | } |
| | | /** |
| | | * å¨ä¸»å¾å±å è½½ï¼åæ¢ï¼å·²ç»æå»ºå¥½ç ui å¯¹è±¡ï¼ |
| | | * @param {object} ui 使ç¨build彿°æå»ºç ui 对象 |
| | | */ |
| | | dxui.loadMain = function (ui) { |
| | | if (!ui || !ui.obj) { |
| | | throw new Error("dxui.loadMain:'ui' paramter should not be null") |
| | | } |
| | | // å 载主å±å¹ |
| | | utils.GG.NativeDisp.lvScrLoad(ui.obj) |
| | | } |
| | | /** |
| | | * 仿åä¸ä¸ªç¨æ·æ´»å¨æ¾ç¤º(å¦ç¹å»)ç»è¿çæ¶é´ |
| | | * @returns è¿å仿åä¸ä¸ªæ´»å¨å¼å§çç»è¿æ¶é´(毫ç§) |
| | | */ |
| | | dxui.getIdleDuration = function () { |
| | | return utils.GG.NativeDisp.lvDispGetInactiveTime() |
| | | } |
| | | /** |
| | | * éç½®ç¨æ·æ´»å¨æ¾ç¤º(å¦ç¹å»)ç»è¿çæ¶é´ |
| | | */ |
| | | dxui.trigActivity = function () { |
| | | utils.GG.NativeDisp.lvDispTrigActivity() |
| | | } |
| | | |
| | | export default dxui; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //build 20240425 |
| | | //çé¨çç»ä»¶ï¼ç¨äºçæ§åºç¨æ¯å¦å¡æ»ï¼è®¾ç½®ä¸ä¸ªè¶
æ¶æ¶é´ï¼å¦æè¶
è¿è¿ä¸ªæ¶é´æ²¡æåçï¼ä¼èªå¨è§¦å设å¤éå¯ |
| | | //注æä½¿ç¨çé¨çä¹åå¯è½éè¦å
åå§ågpio |
| | | //ä¾èµç»ä»¶ dxDriver,dxLogger,dxCommon,dxMap,dxGpio |
| | | import { watchdogClass } from './libvbar-b-dxwatchdog.so' |
| | | import dxMap from './dxMap.js' |
| | | import logger from './dxLogger.js' |
| | | import dxCommon from './dxCommon.js' |
| | | |
| | | const map = dxMap.get("___watchdog") |
| | | const watchdogObj = new watchdogClass(); |
| | | |
| | | const watchdog = {} |
| | | watchdog.last = new Date().getTime() |
| | | /** |
| | | * æå¼çé¨çè®¾å¤ |
| | | * @param {number} type å¿
å¡« |
| | | * @param {string} id 奿idï¼éå¿
å¡«ï¼è¥åå§åå¤ä¸ªå®ä¾éè¦ä¼ å
¥å¯ä¸idï¼ |
| | | */ |
| | | watchdog.open = function (type, id) { |
| | | let pointer = watchdogObj.open(type) |
| | | if (pointer === undefined || pointer === null) { |
| | | throw new Error("watchdog.open: open failed") |
| | | } |
| | | dxCommon.handleId("watchdog", id, pointer) |
| | | } |
| | | /** |
| | | * æ§å¶æå®ééå¼å
³ |
| | | * @param {number} chan ééid,å¿
å¡« |
| | | * @param {string} id 奿idï¼éå¿
å¡«ï¼éä¿æåinitä¸çidä¸è´ï¼ |
| | | * @returns true/false |
| | | */ |
| | | watchdog.enable = function (chan, id) { |
| | | let pointer = dxCommon.handleId("watchdog", id) |
| | | return watchdogObj.enable(pointer, chan) |
| | | } |
| | | /** |
| | | * å¼å¯çé¨çæ»å®æ¶å¨ |
| | | * @param {*} timeout å¿
å¡« |
| | | * @param {string} id 奿idï¼éå¿
å¡«ï¼éä¿æåinitä¸çidä¸è´ï¼ |
| | | * @returns true/false |
| | | */ |
| | | watchdog.start = function (timeout, id) { |
| | | let pointer = dxCommon.handleId("watchdog", id) |
| | | return watchdogObj.start(pointer, timeout) |
| | | } |
| | | /** |
| | | * 夿æ¯å¦æ¯ä¸çµå¤ä½ï¼çé¨çæ¯å¦å·²ç»å¯å¨ |
| | | * @param {string} id 奿idï¼éå¿
å¡«ï¼éä¿æåinitä¸çidä¸è´ï¼ |
| | | * @returns true/false |
| | | */ |
| | | watchdog.isPoweron = function (id) { |
| | | let pointer = dxCommon.handleId("watchdog", id) |
| | | return watchdogObj.isPoweron(pointer) |
| | | } |
| | | /** |
| | | * åçæå®éé |
| | | * @param {*} chan ééidï¼å¿
å¡« |
| | | * @param {string} id 奿idï¼éå¿
å¡«ï¼éä¿æåinitä¸çidä¸è´ï¼ |
| | | * @returns true/false |
| | | */ |
| | | watchdog.restart = function (chan, id) { |
| | | let pointer = dxCommon.handleId("watchdog", id) |
| | | return watchdogObj.restart(pointer, chan) |
| | | } |
| | | /** |
| | | * å
³éçé¨çæ»å®æ¶å¨ |
| | | * @param {string} id 奿idï¼éå¿
å¡«ï¼éä¿æåinitä¸çidä¸è´ï¼ |
| | | * @returns true/false |
| | | */ |
| | | watchdog.stop = function (id) { |
| | | let pointer = dxCommon.handleId("watchdog", id) |
| | | return watchdogObj.stop(pointer) |
| | | } |
| | | /** |
| | | * å
³éçé¨çè®¾å¤ |
| | | * @param {string} id 奿idï¼éå¿
å¡«ï¼éä¿æåinitä¸çidä¸è´ï¼ |
| | | * @returns true/false |
| | | */ |
| | | watchdog.close = function (id) { |
| | | let pointer = dxCommon.handleId("watchdog", id) |
| | | return watchdogObj.close(pointer) |
| | | } |
| | | /** |
| | | * å¾ªç¯æ£æ¥æ¯ä¸ªçº¿ç¨çåçæ
åµï¼ä»»ä½ä¸ä¸ªçº¿ç¨æ²¡æåçï¼åä¸å¯å¨restart |
| | | * @param {number} chan ééidï¼å¿
å¡« |
| | | * @param {string} id 奿idï¼éå¿
å¡«ï¼éä¿æåinitä¸çidä¸è´ï¼ |
| | | */ |
| | | watchdog.loop = function (chan, id) { |
| | | const now = new Date().getTime() |
| | | const minus = now - watchdog.last |
| | | if (minus > 3000 || minus < 0) {//æ¯3ç§æ£æ¥ä¸æ¬¡æè
å°äº0代表æä½äºå¾åæ¹æ¶é´ |
| | | watchdog.last = now |
| | | let keys = map.keys() |
| | | let check = true |
| | | for (let i = 0; i < keys.length; i++) { |
| | | let key = keys[i] |
| | | let value = map.get(key) |
| | | const temp = now - value.now |
| | | if (temp > value.timeout * 1000 && temp < 1700000000) { |
| | | logger.error(`The worker ${key} did not feed the dog in time.`, temp) |
| | | check = false |
| | | break |
| | | } |
| | | } |
| | | if (check) { |
| | | this.restart(chan, id) |
| | | } |
| | | } |
| | | } |
| | | /** |
| | | * ä¸åç线ç¨åç |
| | | * @param {string} flag 线ç¨çæ è¯,å¿
å¡«ä¸è½ä¸ºç©º |
| | | * @param {number} timeout 线ç¨å¯ä»¥å¤é¿æ¶é´ä¸åçï¼ç§ï¼ï¼ç¼ºçæ¯10ç§ |
| | | */ |
| | | watchdog.feed = function (flag, timeout = 10) { |
| | | if (!flag || flag.length <= 0) { |
| | | return |
| | | } |
| | | map.put(flag, { now: new Date().getTime(), timeout: timeout }) |
| | | } |
| | | |
| | | export default watchdog; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //build:20240717 |
| | | //çº¿ç¨æ± ï¼éé¢å è½½å¤ä¸ªworkerï¼çº¿ç¨æ± æ¥æ¶ä»»å¡æäºå¡åç¶åæ´¾åç»çº¿ç¨æ± éé¢ç©ºé²çworkeræ¥æ§è¡ä»»å¡ï¼ç¨äºè§£å³å¤äºå¡å¤ççç¶é¢ |
| | | //设å¤èµæºæéï¼çº¿ç¨æ°éä¸å®å¤ªå¤ï¼å¦å¤ä¹ä¸èèå¤ä¸ªçº¿ç¨æ± çæ
åµï¼å
¨å±åªä¸ä¸ª |
| | | //ç»ä»¶ä¾èµ dxLogger,dxCommonï¼dxStd |
| | | import std from './dxStd.js' |
| | | import logger from './dxLogger.js' |
| | | import * as os from "os"; |
| | | //-------------------------variable-------------------- |
| | | const pool = {} |
| | | const isMain = (os.Worker.parent === undefined) |
| | | let queueSize = 100 |
| | | const queue = [] |
| | | const all = {} |
| | | pool.os = os |
| | | /** |
| | | * åå§åçº¿ç¨æ± ï¼è®¾ç½®worker个æ°åç¼åéå大å°ï¼æå¯è½å¤ä¸ªworker齿²¡æç©ºé²ï¼ç¼åéåå¯ä»¥ç¼åæ¥ä¸åå¤ççäºå¡ |
| | | * å 为workeråªè½éè¿ä¸»çº¿ç¨åå»ºï¼æä»¥init彿°ä¹åªè½å¨ä¸»çº¿ç¨éæ§è¡ |
| | | * 注æ: worker对åºçæä»¶éä¸è½å
å«while(true)è¿ç§æ»å¾ªç¯ï¼å¯ä»¥ç¨setIntevalæ¥å®ç°å¾ªç¯ |
| | | * @param {string} file worker对åºçæä»¶åï¼å¿
å¡«ï¼ç»å¯¹è·¯å¾ï¼é常以'/app/code/src'å¼å§ |
| | | * @param {Object} bus EventBus对象 å¿
å¡« |
| | | * @param {Array} topics è¦è®¢é
ç主é¢ç» å¿
å¡« |
| | | * @param {number} count 线ç¨ç个æ°ï¼éå¿
å¡«ï¼ä¸è½å°äº1ï¼ç¼ºç2, |
| | | * @param {number} maxsize äºå¡ç¼åç大å°ï¼éå¿
å¡«ï¼ç¼ºç100ï¼å¦æè¶
è¿100ï¼æèçäºå¡è¢«æå¼ |
| | | */ |
| | | pool.init = function (file, bus, topics, count = 2, maxsize = 100) { |
| | | if (!file) { |
| | | throw new Error("pool init:'file' should not be empty") |
| | | } |
| | | if (!bus) { |
| | | throw new Error("pool init:'bus' should not be empty") |
| | | } |
| | | if (!topics) { |
| | | throw new Error("pool init:'topics' should not be empty") |
| | | } |
| | | if (!isMain) { |
| | | throw new Error("pool init should be invoked in main thread") |
| | | } |
| | | if (!std.exist(file)) { |
| | | throw new Error("pool init: file not found:" + file) |
| | | } |
| | | queueSize = maxsize |
| | | if (count <= 1) { |
| | | count = 1 |
| | | } |
| | | for (let i = 0; i < count; i++) { |
| | | const id = 'pool__id' + i |
| | | let content = std.loadFile(file) + ` |
| | | import __pool from '/app/code/dxmodules/dxWorkerPool.js' |
| | | __pool.id = '${id}' |
| | | const __parent = __pool.os.Worker.parent |
| | | __parent.onmessage = function (e) { |
| | | if (!e.data) { |
| | | return |
| | | } |
| | | let fun = __pool.callbackFunc |
| | | if (fun) { |
| | | try { |
| | | fun(e.data) |
| | | __parent.postMessage({ id: __pool.id })//éç¥å¤çå®äºidle |
| | | } catch (err) { |
| | | __parent.postMessage({ id: __pool.id, error: err.stack })//éç¥å¤çå®äºidle,使¯å¤±è´¥äº |
| | | } |
| | | } |
| | | } |
| | | ` |
| | | let newfile = file + '_' + id + '.js' |
| | | std.saveFile(newfile, content) |
| | | let worker = new os.Worker(newfile) |
| | | all[id] = { isIdle: true, worker: worker } |
| | | worker.onmessage = function (data) { |
| | | if (!data.data) { |
| | | return |
| | | } |
| | | const id = data.data.id |
| | | if (id) {//éç¥å¤çå®æçæ¶æ¯ |
| | | all[id].isIdle = true |
| | | if (data.data.error) { |
| | | logger.error(`worker ${id} callback error:${data.data.error}`) |
| | | } |
| | | } else { |
| | | const topic = data.data.topic |
| | | if (topic) {//bus.fireåºæ¥çæ¶æ¯ |
| | | bus.fire(topic, data.data.data) |
| | | } |
| | | } |
| | | } |
| | | } |
| | | for (let topic of topics) { |
| | | bus.on(topic, function (d) { |
| | | push({ topic: topic, data: d }) |
| | | }) |
| | | } |
| | | |
| | | std.setInterval(function () { |
| | | Object.keys(all).forEach(key => { |
| | | const obj = all[key] |
| | | if (obj.isIdle) { |
| | | let event = take() |
| | | if (event) { |
| | | obj.isIdle = false |
| | | obj.worker.postMessage(event) |
| | | } |
| | | } |
| | | }); |
| | | }, 5) |
| | | } |
| | | /** |
| | | * è¿å线ç¨çå¯ä¸æ è¯id |
| | | * @returns workerå¯ä¸æ è¯ |
| | | */ |
| | | pool.getWorkerId = function () { |
| | | if (isMain) { |
| | | return 'main' |
| | | } else { |
| | | return pool.id |
| | | } |
| | | } |
| | | /** |
| | | * 订é
EventBus ä¸çäºå¡ä¸»é¢ï¼å¯ä»¥è®¢é
å¤ä¸ªä¸»é¢,è¿ä¸ªå½æ°ä¹åªè½å¨ä¸»çº¿ç¨éæ§è¡ |
| | | * @param {Object} bus EventBus对象 |
| | | * @param {Array} topics è¦è®¢é
ç主é¢ç» |
| | | */ |
| | | pool.on = function (bus, topics) { |
| | | if (!bus) { |
| | | throw new Error("pool onEventBus:'bus' should not be empty") |
| | | } |
| | | if (!topics) { |
| | | throw new Error("pool onEventBus:'topics' should not be empty") |
| | | } |
| | | if (!isMain) { |
| | | throw new Error("pool onEventBus should be invoked in main thread") |
| | | } |
| | | |
| | | } |
| | | |
| | | pool.callbackFunc = null |
| | | /** |
| | | * worker线ç¨è®¢é
çº¿ç¨æ± çäºä»¶ï¼ä¸ç¨éæ©ç¹å®ç主é¢ï¼çº¿ç¨æ± å
³æ³¨çææäºä»¶é½ä¼å¤ç, |
| | | * è¿ä¸ªå½æ°å¿
é¡»å¨worker线ç¨éæ§è¡ï¼ä¸è½å¨ä¸»çº¿ç¨æ§è¡ |
| | | * @param {function} cb äºä»¶å¤ççåè°å½æ°ï¼å¿
å¡« |
| | | */ |
| | | pool.callback = function (cb) { |
| | | if (!cb || (typeof cb) != 'function') { |
| | | throw new Error("pool on :The 'callback' should be a function"); |
| | | } |
| | | if (isMain) { |
| | | throw new Error("pool on should not be invoked in main thread") |
| | | } |
| | | pool.callbackFunc = cb |
| | | } |
| | | |
| | | function push(item) { |
| | | if (queue.length >= queueSize) { |
| | | const first = JSON.stringify(queue[0]) |
| | | logger.error(`pool queue is full,removing oldest element: ${first}`) |
| | | queue.shift(); // ç§»é¤æèçå
ç´ |
| | | } |
| | | queue.push(item); |
| | | } |
| | | |
| | | function take() { |
| | | if (queue.length === 0) { |
| | | return null; // éå为空æ¶è¿å null |
| | | } |
| | | return queue.shift(); // ç§»é¤å¹¶è¿åææ©æ·»å çå
ç´ |
| | | } |
| | | export default pool |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //build:20240606 |
| | | //ç¨äºç®åfaceç»ä»¶å¾®å
éä¿¡åè®®ç使ç¨ï¼æfaceå°è£
å¨è¿ä¸ªworkeréï¼ä½¿ç¨è
åªéè¦è®¢é
eventbusçäºä»¶å°±å¯ä»¥çå¬face |
| | | import log from './dxLogger.js' |
| | | import face from './dxFace.js' |
| | | import std from './dxStd.js' |
| | | |
| | | function run() { |
| | | face.worker.beforeLoop() |
| | | log.info('face start......') |
| | | std.setInterval (function() { |
| | | try { |
| | | face.worker.loop() |
| | | } catch (error) { |
| | | log.error(error) |
| | | } |
| | | },10) |
| | | } |
| | | |
| | | try { |
| | | run() |
| | | } catch (error) { |
| | | log.error(error) |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //build:20240524 |
| | | //ç¨äºç®ågpioKeyç»ä»¶å¾®å
éä¿¡åè®®ç使ç¨ï¼ægpioKeyå°è£
å¨è¿ä¸ªworkeréï¼ä½¿ç¨è
åªéè¦è®¢é
eventbusçäºä»¶å°±å¯ä»¥çå¬gpioKey |
| | | import log from './dxLogger.js' |
| | | import gpioKey from './dxGpioKey.js' |
| | | import * as os from "os"; |
| | | import std from './dxStd.js' |
| | | function run() { |
| | | gpioKey.worker.beforeLoop() |
| | | log.info('gpioKey start......') |
| | | std.setInterval(() => { |
| | | try { |
| | | gpioKey.worker.loop() |
| | | } catch (error) { |
| | | log.error(error) |
| | | } |
| | | },10) |
| | | } |
| | | |
| | | try { |
| | | run() |
| | | } catch (error) { |
| | | log.error(error) |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //build:20240524 |
| | | //ç¨äºç®åmqttç»ä»¶å¾®å
éä¿¡åè®®ç使ç¨ï¼æmqttå°è£
å¨è¿ä¸ªworkeréï¼ä½¿ç¨è
åªéè¦è®¢é
eventcenterçäºä»¶å°±å¯ä»¥çå¬mqtt |
| | | import log from './dxLogger.js' |
| | | import net from './dxNet.js' |
| | | import mqtt from './dxMqtt.js' |
| | | import dxMap from './dxMap.js' |
| | | import std from './dxStd.js' |
| | | import * as os from "os"; |
| | | const map = dxMap.get('default') |
| | | const id = "{{id}}" |
| | | const options = map.get("__mqtt__run_init" + id) |
| | | let connected = false |
| | | function run() { |
| | | mqtt.init(options.mqttAddr, options.clientId, options.username, options.password, options.prefix, options.qos, options.willTopic, options.willMessage, options.id) |
| | | log.info('mqtt start......,id =', id) |
| | | os.sleep(2000)//çå¾
2ç§ |
| | | |
| | | __bus.on(mqtt.RECONNECT, (options) => { |
| | | mqtt.destroy(options.id) |
| | | mqtt.init(options.mqttAddr, options.clientId, options.username, options.password, options.prefix, options.qos, options.willTopic, options.willMessage, options.id) |
| | | }) |
| | | |
| | | std.setInterval(() => { |
| | | try { |
| | | if (mqtt.isConnected(options.id) && net.getStatus().connected) { |
| | | if (!connected) { |
| | | _fireChange(true) |
| | | if (options.subs) { |
| | | mqtt.subscribes(options.subs, options.qos, options.id) |
| | | } |
| | | } |
| | | } else { |
| | | if (connected) { |
| | | _fireChange(false) |
| | | } |
| | | // éè¿ |
| | | mqtt.reconnect(options.willTopic, options.willMessage, options.id) |
| | | os.sleep(2000)//éè¿åçå¾
2ç§ |
| | | } |
| | | } catch (error) { |
| | | log.error(error) |
| | | } |
| | | }, 3000) |
| | | std.setInterval(() => { |
| | | // è¿æ¥æååè¿å
¥æ¶æ¯çå¬ |
| | | if (connected) { |
| | | if (!mqtt.msgIsEmpty(options.id)) { |
| | | let msg = mqtt.receive(options.id) |
| | | __bus.fire(mqtt.RECEIVE_MSG + options.id, msg)//bus.newworkerçæ¶åä¼import eventbus as __bus |
| | | } |
| | | } |
| | | }, 10); |
| | | } |
| | | |
| | | try { |
| | | run() |
| | | } catch (error) { |
| | | log.error(error) |
| | | } |
| | | |
| | | function _fireChange(status) { |
| | | __bus.fire(mqtt.CONNECTED_CHANGED + options.id, status ? 'connected' : 'disconnected')//bus.newworkerçæ¶åä¼import eventbus as __bus |
| | | connected = status |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //build:20240525 |
| | | //ç¨äºç®ånetç»ä»¶å¾®å
éä¿¡åè®®ç使ç¨ï¼ænetå°è£
å¨è¿ä¸ªworkeréï¼ä½¿ç¨è
åªéè¦è®¢é
eventcenterçäºä»¶å°±å¯ä»¥çå¬net |
| | | import log from './dxLogger.js' |
| | | import net from './dxNet.js' |
| | | import dxMap from './dxMap.js' |
| | | import std from './dxStd.js' |
| | | const map = dxMap.get('default') |
| | | const options = map.get("__net__run_init") |
| | | |
| | | function run() { |
| | | net.worker.beforeLoop(options) |
| | | log.info('net worker start......') |
| | | std.setInterval (function() { |
| | | try { |
| | | net.worker.loop() |
| | | } catch (error) { |
| | | log.error(error) |
| | | } |
| | | },100) |
| | | } |
| | | try { |
| | | run() |
| | | } catch (error) { |
| | | log.error(error) |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //build:20240524 |
| | | //ç¨äºç®ånfcç»ä»¶å¾®å
éä¿¡åè®®ç使ç¨ï¼ænfcå°è£
å¨è¿ä¸ªworkeréï¼ä½¿ç¨è
åªéè¦è®¢é
eventcenterçäºä»¶å°±å¯ä»¥çå¬nfc |
| | | import log from './dxLogger.js' |
| | | import nfc from './dxNfc.js' |
| | | import dxMap from './dxMap.js' |
| | | import std from './dxStd.js' |
| | | import * as os from "os"; |
| | | const map = dxMap.get('default') |
| | | const options = map.get("__nfc__run_init") |
| | | |
| | | function run() { |
| | | nfc.worker.beforeLoop(options) |
| | | log.info('nfc start......') |
| | | std.setInterval(() => { |
| | | try { |
| | | nfc.worker.loop(options) |
| | | } catch (error) { |
| | | log.error(error) |
| | | } |
| | | }, 10) |
| | | } |
| | | |
| | | try { |
| | | run() |
| | | } catch (error) { |
| | | log.error(error) |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //build:20240524 |
| | | /** |
| | | * UIçåºç±»ï¼å
¶å®æ§ä»¶é½ä¼ç»§æ¿ï¼åç±»ä¸å
许修æ¹å¯¹åºç彿°è¡ä¸º,è¿ä¸ªjsä¸éè¦ç´æ¥å¼ç¨åä½¿ç¨ |
| | | */ |
| | | import utils from "./uiUtils.js" |
| | | import logger from './dxLogger.js' |
| | | import * as os from "os" |
| | | const uibase = {} |
| | | /** |
| | | * ä¿®æ¹æè·åæ§ä»¶ç宽度 |
| | | * @param {number} w éå¿
å¡«ï¼å¦æä¸å¡«æ¯è·å宽度ï¼å¦åå°±æ¯ä¿®æ¹å®½åº¦ |
| | | */ |
| | | uibase.width = function (w) { |
| | | if (!utils.validateNumber(w)) { |
| | | return this.obj.getWidth() |
| | | } |
| | | this.obj.lvObjSetWidth(w) |
| | | } |
| | | /** |
| | | * ä¿®æ¹æè·åæ§ä»¶çé«åº¦ |
| | | * @param {number} h éå¿
å¡«ï¼å¦æä¸å¡«å°±æ¯è·åé«åº¦ï¼å¦åå°±æ¯ä¿®æ¹é«åº¦ |
| | | */ |
| | | uibase.height = function (h) { |
| | | if (!utils.validateNumber(h)) { |
| | | return this.obj.getHeight() |
| | | } |
| | | this.obj.lvObjSetHeight(h) |
| | | } |
| | | /** |
| | | * è·åå»é¤è¾¹æ¡ãå
è¾¹è·ç宽度 |
| | | * @returns |
| | | */ |
| | | uibase.contentWidth = function () { |
| | | return this.obj.lvObjGetContentWidth() |
| | | } |
| | | /** |
| | | * è·åå»é¤è¾¹æ¡ãå
è¾¹è·çé«åº¦ |
| | | * @returns |
| | | */ |
| | | uibase.contentHeight = function () { |
| | | return this.obj.lvObjGetContentHeight() |
| | | } |
| | | /** |
| | | * è·å䏿¹æ»å¨è·ç¦» |
| | | * @returns |
| | | */ |
| | | uibase.scrollTop = function () { |
| | | return this.obj.getScrollTop() |
| | | } |
| | | /** |
| | | * è·å䏿¹æ»å¨è·ç¦» |
| | | * @returns |
| | | */ |
| | | uibase.scrollBottom = function () { |
| | | return this.obj.getScrollBottom() |
| | | } |
| | | /** |
| | | * è·åå·¦æ¹æ»å¨è·ç¦» |
| | | * @returns |
| | | */ |
| | | uibase.scrollLeft = function () { |
| | | return this.obj.getScrollLeft() |
| | | } |
| | | /** |
| | | * è·å峿¹æ»å¨è·ç¦» |
| | | * @returns |
| | | */ |
| | | uibase.scrollRight = function () { |
| | | return this.obj.getScrollRight() |
| | | } |
| | | /** |
| | | * ä¿®æ¹æ§ä»¶ç宽度åé«åº¦ |
| | | * @param {number} w å¿
å¡« |
| | | * @param {number} h å¿
å¡« |
| | | */ |
| | | uibase.setSize = function (w, h) { |
| | | let err = 'dxui.setSize: width or height should not be empty' |
| | | utils.validateNumber(w, err) |
| | | utils.validateNumber(h, err) |
| | | this.obj.lvObjSetSize(w, h) |
| | | } |
| | | /** |
| | | * ä¿®æ¹æè·åæ§ä»¶ç¸å½äºç¶å¯¹è±¡çxåæ |
| | | * @param {number} x éå¿
å¡«ï¼å¦æä¸å¡«å°±æ¯è·åxåæ ï¼å¦åå°±æ¯ä¿®æ¹xåæ |
| | | */ |
| | | uibase.x = function (x) { |
| | | if (!utils.validateNumber(x)) { |
| | | return this.obj.getX() |
| | | } |
| | | this.obj.lvObjSetX(x) |
| | | } |
| | | /** |
| | | * ä¿®æ¹æè·åæ§ä»¶ç¸å½äºç¶å¯¹è±¡çxåæ |
| | | * @param {number} y éå¿
å¡«ï¼å¦æä¸å¡«å°±æ¯è·åyåæ ï¼å¦åå°±æ¯ä¿®æ¹yåæ |
| | | */ |
| | | uibase.y = function (y) { |
| | | if (!utils.validateNumber(y)) { |
| | | return this.obj.getY() |
| | | } |
| | | this.obj.lvObjSetY(y) |
| | | } |
| | | /** |
| | | * ä¿®æ¹æ§ä»¶ç¸å¯¹ç¶å¯¹è±¡çxåyåæ |
| | | * @param {number} x å¿
å¡« |
| | | * @param {number} y å¿
å¡« |
| | | */ |
| | | uibase.setPos = function (x, y) { |
| | | let err = 'dxui.setPos: x or y should not be empty' |
| | | utils.validateNumber(x, err) |
| | | utils.validateNumber(y, err) |
| | | this.obj.lvObjSetPos(x, y) |
| | | } |
| | | /** |
| | | * ææ§ä»¶ç§»å¨å°æä¸å±ï¼ç¸å½äºç¶å¯¹è±¡æåä¸ä¸ªå建çåæ§ä»¶ï¼ä¼è¦çå
¶å®ææåæ§ä»¶ |
| | | */ |
| | | uibase.moveForeground = function () { |
| | | this.obj.moveForeground() |
| | | } |
| | | /** |
| | | * ææ§ä»¶ç§»å¨å°æåºå±ï¼ç¸å½äºç¶å¯¹è±¡ç¬¬ä¸ä¸ªå建çåæ§ä»¶ï¼ä¼è¢«å
¶å®ææåæ§ä»¶è¦ç |
| | | */ |
| | | uibase.moveBackground = function () { |
| | | this.obj.moveBackground() |
| | | } |
| | | /** |
| | | * 订é
äºä»¶ï¼æ¯æçäºä»¶ç±»ååèutils.EVENT |
| | | * @param {number} type æä¸¾utils.EVENT,æ¯å¦ç¹å»ãé¿æç |
| | | * @param {function} cb äºä»¶è§¦åçåè°å½æ°ï¼ä¸è½æ¯å¿å彿°ï¼ |
| | | * @param {object} ud ç¨æ·æ°æ® |
| | | */ |
| | | uibase.on = function (type, cb, ud) { |
| | | this.obj.addEventCb(() => { |
| | | if (cb) { |
| | | cb({ target: this, ud: ud }) |
| | | } |
| | | }, type) |
| | | } |
| | | /** |
| | | * åéäºä»¶ï¼æ¯å¦æ¨¡æç¹å»æé®ï¼å¯ä»¥ç»æé®åéCLICKäºä»¶ |
| | | * @param {number} type æä¸¾utils.EVENT,æ¯å¦ç¹å»ãé¿æç |
| | | */ |
| | | uibase.send = function (type) { |
| | | NativeObject.APP.NativeComponents.NativeEvent.lvEventSend(this.obj, type) |
| | | } |
| | | /** |
| | | * éèui对象 |
| | | */ |
| | | uibase.hide = function () { |
| | | if (!this.obj.hasFlag(1)) { |
| | | this.obj.lvObjAddFlag(1); |
| | | } |
| | | } |
| | | /** |
| | | * 夿æ¯å¦éè |
| | | * @returns |
| | | */ |
| | | uibase.isHide = function () { |
| | | return this.obj.hasFlag(1); |
| | | } |
| | | /** |
| | | * æ¾ç¤ºå·²ç»éèçui对象 |
| | | */ |
| | | uibase.show = function () { |
| | | if (this.obj.hasFlag(1)) { |
| | | this.obj.lvObjClearFlag(1); |
| | | } |
| | | } |
| | | /** |
| | | * ç¦å¯ç¨å¯¹è±¡ |
| | | * @param {*} en false/trueï¼trueæ¯ç¦ç¨ï¼falseæ¯å¯ç¨ |
| | | */ |
| | | uibase.disable = function (en) { |
| | | if (en) { |
| | | this.obj.addState(utils.STATE.DISABLED) |
| | | } else { |
| | | this.obj.clearState(utils.STATE.DISABLED) |
| | | } |
| | | } |
| | | /** |
| | | * æ¯å¦å¯ç¹å»å¯¹è±¡ |
| | | * @param {*} en false/trueï¼trueæ¯å¯ç¹å»ï¼falseæ¯ä¸å¯ç¹å» |
| | | */ |
| | | uibase.clickable = function (en) { |
| | | if (en) { |
| | | this.obj.lvObjAddFlag(utils.OBJ_FLAG.CLICKABLE) |
| | | } else { |
| | | this.obj.lvObjClearFlag(utils.OBJ_FLAG.CLICKABLE) |
| | | } |
| | | } |
| | | /** |
| | | * 夿æ¯å¦ç¦å¯ç¨ |
| | | * @returns trueæ¯å·²ç¦ç¨ï¼falseæ¯å·²å¯ç¨ |
| | | */ |
| | | uibase.isDisable = function () { |
| | | return this.obj.hasState(utils.STATE.DISABLED) |
| | | } |
| | | /** |
| | | * èç¦å¯¹è±¡ |
| | | * @param {*} en false/trueï¼trueæ¯èç¦ï¼falseæ¯åæ¶èç¦ |
| | | */ |
| | | uibase.focus = function (en) { |
| | | if (en) { |
| | | this.obj.addState(utils.STATE.FOCUSED) |
| | | } else { |
| | | this.obj.clearState(utils.STATE.FOCUSED) |
| | | } |
| | | } |
| | | /** |
| | | * 夿æ¯å¦èç¦ |
| | | * @returns trueæ¯å·²èç¦ï¼falseæ¯æ²¡èç¦ |
| | | */ |
| | | uibase.isFocus = function () { |
| | | return this.obj.hasState(utils.STATE.FOCUSED) |
| | | } |
| | | |
| | | /** |
| | | * 设置uiçæ ·å¼ï¼å¯ä»¥éè¿ä¸ä¸ªä¸ªæ ·å¼åç¬è®¾ç½®ï¼ä¹å¯ä»¥å
å®ä¹æ ·å¼å¯¹è±¡ï¼ç¶ååui对象ç»å® |
| | | * ç»uiå¯¹è±¡åæ ·å¼å¯¹è±¡ç»å®ï¼å¯ä»¥ç»å®å°ä¸åçé¨åæä¸åçç¶æ |
| | | * @param {object} style style.js build彿°è¿åç对象 |
| | | * @param {number} type åèutils.STYLE éå¿
å¡«ï¼ç¼ºçæ¯å对象èªèº«ç»å® |
| | | */ |
| | | uibase.addStyle = function (style, type) { |
| | | if (!style || !style.obj) { |
| | | throw new Error('dxui.addStyle: style should not be null') |
| | | } |
| | | if (!utils.validateNumber(type)) { |
| | | type = 0 |
| | | } |
| | | this.obj.lvObjAddStyle(style.obj, type); |
| | | } |
| | | /** |
| | | * 设置左å³ä¸ä¸çå
è¾¹è·é½ä¸ºä¸ä¸ªå¼ |
| | | * @param {number} pad è¾¹è·å¼ |
| | | * @param {number} type åèutils.STYLE éå¿
å¡«ï¼ç¼ºçæ¯å对象èªèº«ç»å® |
| | | */ |
| | | uibase.padAll = function (pad, type) { |
| | | if (!utils.validateNumber(type)) { |
| | | type = 0 |
| | | } |
| | | this.obj.lvObjSetStylePadAll(pad, type) |
| | | } |
| | | /** |
| | | * 设置/è·åå³å
è¾¹è·é½ä¸ºä¸ä¸ªå¼ |
| | | * @param {number} pad è¾¹è·å¼ |
| | | * @param {number} type åèutils.STYLE éå¿
å¡«ï¼ç¼ºçæ¯å对象èªèº«ç»å® |
| | | */ |
| | | uibase.padRight = function (pad, type) { |
| | | if (!utils.validateNumber(type)) { |
| | | type = 0 |
| | | } |
| | | if (!utils.validateNumber(pad)) { |
| | | return this.obj.getStylePadRight(type) |
| | | } |
| | | this.obj.setStylePadRight(pad, type) |
| | | } |
| | | /** |
| | | * 设置/è·åå·¦å
è¾¹è·é½ä¸ºä¸ä¸ªå¼ |
| | | * @param {number} pad è¾¹è·å¼ |
| | | * @param {number} type åèutils.STYLE éå¿
å¡«ï¼ç¼ºçæ¯å对象èªèº«ç»å® |
| | | */ |
| | | uibase.padLeft = function (pad, type) { |
| | | if (!utils.validateNumber(type)) { |
| | | type = 0 |
| | | } |
| | | if (!utils.validateNumber(pad)) { |
| | | return this.obj.getStylePadLeft(type) |
| | | } |
| | | this.obj.setStylePadLeft(pad, type) |
| | | } |
| | | /** |
| | | * 设置/è·åä¸å
è¾¹è·é½ä¸ºä¸ä¸ªå¼ |
| | | * @param {number} pad è¾¹è·å¼ |
| | | * @param {number} type åèutils.STYLE éå¿
å¡«ï¼ç¼ºçæ¯å对象èªèº«ç»å® |
| | | */ |
| | | uibase.padTop = function (pad, type) { |
| | | if (!utils.validateNumber(type)) { |
| | | type = 0 |
| | | } |
| | | if (!utils.validateNumber(pad)) { |
| | | return this.obj.getStylePadTop(type) |
| | | } |
| | | this.obj.setStylePadTop(pad, type) |
| | | } |
| | | /** |
| | | * 设置/è·åä¸å
è¾¹è·é½ä¸ºä¸ä¸ªå¼ |
| | | * @param {number} pad è¾¹è·å¼ |
| | | * @param {number} type åèutils.STYLE éå¿
å¡«ï¼ç¼ºçæ¯å对象èªèº«ç»å® |
| | | */ |
| | | uibase.padBottom = function (pad, type) { |
| | | if (!utils.validateNumber(type)) { |
| | | type = 0 |
| | | } |
| | | if (!utils.validateNumber(pad)) { |
| | | return this.obj.getStylePadBottom(type) |
| | | } |
| | | this.obj.setStylePadBottom(pad, type) |
| | | } |
| | | /** |
| | | * 设置/è·åè¾¹æ¡å®½åº¦ |
| | | * @param {number} w |
| | | * @param {number} type åèutils.STYLE éå¿
å¡«ï¼ç¼ºçæ¯å对象èªèº«ç»å® |
| | | */ |
| | | uibase.borderWidth = function (w, type) { |
| | | if (!utils.validateNumber(type)) { |
| | | type = 0 |
| | | } |
| | | if (!utils.validateNumber(w)) { |
| | | return this.obj.lvObjGetStyleBorderWidth(type) |
| | | } |
| | | this.obj.lvObjSetStyleBorderWidth(w, type) |
| | | } |
| | | /** |
| | | * 设置边æ¡é¢è² |
| | | * @param {number} color æ¯ææ°åç±»åï¼æ¯å¦0x34ffaaï¼å符串类å(#å¼å¤´),æ¯å¦:'#34ffaa' |
| | | * @param {number} type åèutils.STYLE éå¿
å¡«ï¼ç¼ºçæ¯å对象èªèº«ç»å® |
| | | */ |
| | | uibase.setBorderColor = function (color, type) { |
| | | if (!utils.validateNumber(type)) { |
| | | type = 0 |
| | | } |
| | | this.obj.setStyleBorderColor(utils.colorParse(color), type) |
| | | } |
| | | /** |
| | | * 设置边åè§ |
| | | * @param {number} r |
| | | * @param {number} type åèutils.STYLE éå¿
å¡«ï¼ç¼ºçæ¯å对象èªèº«ç»å® |
| | | */ |
| | | uibase.radius = function (r, type) { |
| | | if (!utils.validateNumber(type)) { |
| | | type = 0 |
| | | } |
| | | this.obj.lvObjSetStyleRadius(r, type) |
| | | } |
| | | /** |
| | | * è®¾ç½®èæ¯éæåº¦ï¼å¼èå´æ¯0-100ï¼å¼è¶å°è¶å¥½ |
| | | * @param {number} opa å¿
é¡»æ¯0-100 |
| | | * @param {number} type åèutils.STYLE éå¿
å¡«ï¼ç¼ºçæ¯å对象èªèº«ç»å® |
| | | */ |
| | | uibase.bgOpa = function (opa, type) { |
| | | if (!utils.validateNumber(type)) { |
| | | type = 0 |
| | | } |
| | | this.obj.lvObjSetStyleBgOpa(utils.OPA_MAPPING(opa), type) |
| | | } |
| | | /** |
| | | * è®¾ç½®èæ¯é¢è² |
| | | * @param {any} color æ¯ææ°åç±»åï¼æ¯å¦0x34ffaaï¼å符串类å(#å¼å¤´),æ¯å¦:'#34ffaa' |
| | | * @param {number} type åèutils.STYLE éå¿
å¡«ï¼ç¼ºçæ¯å对象èªèº«ç»å® |
| | | */ |
| | | uibase.bgColor = function (color, type) { |
| | | if (!utils.validateNumber(type)) { |
| | | type = 0 |
| | | } |
| | | this.obj.lvObjSetStyleBgColor(utils.colorParse(color), type) |
| | | } |
| | | /** |
| | | * 设置é´å½± |
| | | * @param {number} width é´å½±å®½åº¦ |
| | | * @param {number} x æ°´å¹³åç§» |
| | | * @param {number} y åç´åç§» |
| | | * @param {number} spread æ©æ£è·ç¦» |
| | | * @param {number} color é¢è² |
| | | * @param {number} opa éæåº¦ï¼å¿
é¡»æ¯0-100 |
| | | * @param {number} type åèutils.STYLE éå¿
å¡«ï¼ç¼ºçæ¯å对象èªèº«ç»å® |
| | | */ |
| | | uibase.shadow = function (width, x, y, spread, color, opa, type) { |
| | | if (!utils.validateNumber(type)) { |
| | | type = 0 |
| | | } |
| | | this.obj.lvObjSetStyleShadowWidth(width, type) |
| | | this.obj.lvObjSetStyleShadowOfsX(x, type) |
| | | this.obj.lvObjSetStyleShadowOfsY(y, type) |
| | | this.obj.lvObjSetStyleShadowSpread(spread, type) |
| | | this.obj.setStyleShadowColor(color, type) |
| | | this.obj.setStyleShadowOpa(utils.OPA_MAPPING(opa), type) |
| | | } |
| | | /** |
| | | * è®¾ç½®ææ¬é¢è² |
| | | * @param {any} color æ¯ææ°åç±»åï¼æ¯å¦0x34ffaaï¼å符串类å(#å¼å¤´),æ¯å¦:'#34ffaa' |
| | | * @param {number} type åèutils.STYLE éå¿
å¡«ï¼ç¼ºçæ¯å对象èªèº«ç»å® |
| | | */ |
| | | uibase.textColor = function (color, type) { |
| | | if (!utils.validateNumber(type)) { |
| | | type = 0 |
| | | } |
| | | this.obj.lvObjSetStyleTextColor(utils.colorParse(color), type) |
| | | } |
| | | /** |
| | | * è®¾ç½®ææ¬å¯¹é½æ¹å¼ |
| | | * @param {number} align åèutils.TEXT_ALIGN |
| | | * @param {number} type åèutils.STYLE éå¿
å¡«ï¼ç¼ºçæ¯å对象èªèº«ç»å® |
| | | */ |
| | | uibase.textAlign = function (align, type) { |
| | | if (!utils.validateNumber(type)) { |
| | | type = 0 |
| | | } |
| | | this.obj.lvObjSetStyleTextAlign(align, type) |
| | | } |
| | | /** |
| | | * è®¾ç½®ææ¬åä½ |
| | | * @param {object} font font.jsébuildè¿åç对象 |
| | | * @param {number} type åèutils.STYLE éå¿
å¡«ï¼ç¼ºçæ¯å对象èªèº«ç»å® |
| | | */ |
| | | uibase.textFont = function (font, type) { |
| | | if (!utils.validateNumber(type)) { |
| | | type = 0 |
| | | } |
| | | if (!font || !font.obj) { |
| | | throw new Error("dxui.textFont: 'font' parameter should not be null") |
| | | } |
| | | this.obj.lvObjSetStyleTextFont(font.obj, type) |
| | | } |
| | | /** |
| | | * 设置线对象(line)é¢è² |
| | | * @param {any} color æ¯ææ°åç±»åï¼æ¯å¦0x34ffaaï¼å符串类å(#å¼å¤´),æ¯å¦:'#34ffaa' |
| | | * @param {number} type åèutils.STYLE éå¿
å¡«ï¼ç¼ºçæ¯å对象èªèº«ç»å® |
| | | */ |
| | | uibase.lineColor = function (color, type) { |
| | | if (!utils.validateNumber(type)) { |
| | | type = 0 |
| | | } |
| | | this.obj.lvObjSetStyleLineColor(utils.colorParse(color), type) |
| | | } |
| | | /** |
| | | * 设置线对象(line)宽度 |
| | | * @param {number} w |
| | | * @param {number} type åèutils.STYLE éå¿
å¡«ï¼ç¼ºçæ¯å对象èªèº«ç»å® |
| | | */ |
| | | uibase.lineWidth = function (w, type) { |
| | | if (!utils.validateNumber(type)) { |
| | | type = 0 |
| | | } |
| | | this.obj.lvObjSetStyleLineWidth(w, type) |
| | | } |
| | | /** |
| | | * 设置线对象(line)åè§ |
| | | * @param {boolean} enable true/false |
| | | */ |
| | | uibase.lineRound = function (enable) { |
| | | this.obj.lvObjSetStyleLineRounded(enable) |
| | | } |
| | | /** |
| | | * 设置uiå¯¹è±¡çæ»å¨æ¡æ¾ç¤ºæ¹å¼ |
| | | * @param {boolean} state ture/false |
| | | */ |
| | | uibase.scrollbarMode = function (state) { |
| | | this.obj.lvObjSetScrollbarMode(state) |
| | | } |
| | | /** |
| | | * 设置ui对象æ¯å¦æ¯ææ»å¨ |
| | | * @param {boolean} state |
| | | */ |
| | | uibase.scroll = function (state) { |
| | | if (state) { |
| | | this.obj.lvObjAddFlag(16) |
| | | } else { |
| | | this.obj.lvObjClearFlag(16) |
| | | } |
| | | } |
| | | /** |
| | | * å°å¯¹è±¡ä¸å
¶å®åç
§å¯¹è±¡å¯¹é½ |
| | | * @param {object} ref åç
§å¯¹è±¡ |
| | | * @param {number} type 对é½çæ¹åï¼åèdxui.Utils.ALIGNæä¸¾ |
| | | * @param {number} x åç§»çx |
| | | * @param {number} y åç§»çy |
| | | */ |
| | | uibase.alignTo = function (ref, type, x, y) { |
| | | if (!ref || !ref.obj) { |
| | | throw new Error("dxui.alignto: 'ref' parameter should not be null") |
| | | } |
| | | this.obj.lvObjAlignTo(ref.obj, type, x, y) |
| | | } |
| | | /** |
| | | * å°å¯¹è±¡ä¸ç¶å¯¹è±¡å¯¹é½ |
| | | * @param {number} type 对é½çæ¹åï¼åèdxui.Utils.ALIGNæä¸¾ |
| | | * @param {number} x åç§»çx |
| | | * @param {number} y åç§»çy |
| | | */ |
| | | uibase.align = function (type, x, y) { |
| | | this.obj.lvObjAlign(type, x, y) |
| | | } |
| | | /** |
| | | * 伸缩çå¸å±ï¼å¯ä»¥æ´å çµæ´»å¾å®ä½ãæåååå¸å
ç´ ï¼ä½¿å¾å建ååºå¼åå¯ä¼¸ç¼©çå¸å±å徿´å 容æã |
| | | * å®åºäºä¸ä¸ªå®¹å¨ï¼åå
é¨çä¸äºå¼¹æ§é¡¹ç®ï¼ä¸é¢æ¯ä½¿ç¨è¿ç§å¸å±çä¸äºæ¦å¿µï¼ |
| | | * 1ã容å¨ï¼å®¹å¨å
å«äºå
é¨çå¼¹æ§é¡¹ç®ï¼å¯ä»¥ä½¿éé¢é¡¹ç®ä»å·¦å峿ä»å³åå·¦çè§åæåã |
| | | * 2ã主轴åä¾§è½´ï¼ä¸»è½´ï¼æ¯å®¹å¨ä¸é¡¹ç®çä¸»è¦æåæ¹å¼ï¼éå¸¸æ¯æ°´å¹³æ¹åæåç´æ¹åï¼å¯ä»¥è®©é¡¹ç®ä»¬æ°´å¹³æåæçºµåæåã |
| | | * ä¾§è½´ï¼ä¸ä¸»è½´åç´çè½´åï¼å¯ä»¥è§å®é¡¹ç®ä»¬å¨ä¾§è½´ä¸çæåæ¹å¼ã |
| | | * 主轴åä¾§è½´ç±flexFlow()设置ï¼ä¸»è¦æROWï¼æ°´å¹³æ¹åï¼ãCOLUMNï¼åç´æ¹åï¼ä¸¤ç§ï¼å¸¦æWRAPåç¼çå¨é¡¹ç®ä»¬è¶
åºå®¹å¨æ¶èªå¨æ¢è¡ï¼å¸¦æREVERSEåç¼çä¸é»è®¤æåæ¹åç¸åï¼å³ä¸ºä»å³å°å·¦æåï¼è¥ä¸»è½´æ¯åç´æ¹åå为ä»ä¸å°ä¸æåï¼ã |
| | | * 3ãä¸»è½´å¯¹é½æ¹å¼ï¼STARTï¼é»è®¤ä¸»è½´é¡ºåºï¼ãENDï¼é»è®¤ä¸»è½´é¡ºåºç¸åï¼ãCENTERï¼å¨ä¸»è½´æ¹åä¸å±
ä¸ï¼ãSPACE_EVENLYï¼å¨ä¸»è½´ä¸åååå¸ï¼ä¸¤ä¸¤ä¹é´è·ç¦»ç¸çï¼ãSPACE_AROUNDï¼å¨ä¸»è½´ä¸åååå¸ï¼æ¯ä¸ªé¡¹ç®å¹³å主轴ä¸çè·ç¦»ï¼ãSPACE_BETWEENï¼ä¸¤ç«¯é¡¶æ ¼ï¼ä¸é´ååï¼ï¼ç±flexAlign()设置ã |
| | | * 4ãä¾§è½´å¯¹é½æ¹å¼ï¼å°æ¯ä¸è¡ææ¯ä¸åçä½ä¸ä¸ªé¡¹ç®ï¼å¨ä¾§è½´æ¹åä¸å¯¹é½ï¼å¯¹é½æ¹å¼å主轴ï¼ç±flexAlign()设置ã |
| | | * 5ãæ´ä½å¯¹é½æ¹å¼ï¼å°å®¹å¨å
ææé¡¹ç®çä½ä¸ä¸ªæ´ä½ï¼å¨å®¹å¨ä¸å¯¹é½ï¼å¯¹é½æ¹å¼å主轴ï¼ç±flexAlign()设置ã |
| | | * @param {number} type 主轴åä¾§è½´ç设置 |
| | | */ |
| | | uibase.flexFlow = function (type) { |
| | | this.obj.lvObjSetFlexFlow(type) |
| | | } |
| | | /** |
| | | * |
| | | * @param {number} main åå
ç´ æä¸»è½´æ¹åç坹齿¹å¼ |
| | | * @param {number} cross åå
ç´ æä¾§è½´æ¹åç坹齿¹å¼ |
| | | * @param {number} track ææåå
ç´ å¯¹äºå®¹å¨ç坹齿¹å¼ |
| | | */ |
| | | uibase.flexAlign = function (main, cross, track) { |
| | | this.obj.lvObjSetFlexAlign(main, cross, track) |
| | | } |
| | | /** |
| | | * æ´æ°ä¸ä¸ªæ§ä»¶ç尺寸ï¼å½è·åä¸ä¸ªæ§ä»¶ç尺寸为0æ¶å¯ä»¥å
è°ç¨ï¼ç¸å½äºæ´æ°æ¾ç¤ºç¼åã |
| | | */ |
| | | uibase.update = function () { |
| | | this.obj.lvObjUpdateLayout() |
| | | } |
| | | /** |
| | | * æ·»å ä¸ä¸ªæ§ä»¶çç¶æ |
| | | * @param {number} state ç¶ææä¸¾ |
| | | */ |
| | | uibase.addState = function (state) { |
| | | this.obj.addState(state) |
| | | } |
| | | /** |
| | | * å é¤ä¸ä¸ªæ§ä»¶çç¶æï¼å¦ææ³è®©ä¸ä¸ªèç¦è¾å
¥æ¡å¤±ç¦ï¼å¯ä»¥è°ç¨æ¤æ¹æ³å é¤FOCUSEDç¶æ |
| | | * @param {number} state ç¶ææä¸¾ |
| | | */ |
| | | uibase.clearState = function (state) { |
| | | this.obj.clearState(state) |
| | | } |
| | | /** |
| | | * 夿ä¸ä¸ªæ§ä»¶æ¯å¦æ¥æç¶æï¼æ³å¤æä¸ä¸ªè¾å
¥æ¡æ¯å¦è¢«èç¦äºï¼å¯ä»¥ä½¿ç¨æ¤æ¹æ³å¹¶ä¼ å
¥FOCUSEDåæ° |
| | | * @param {number} state ç¶ææä¸¾ |
| | | * @returns true/false |
| | | */ |
| | | uibase.hasState = function (state) { |
| | | return this.obj.hasState(state) |
| | | } |
| | | /** |
| | | * éç»ä¸ä¸ªæ§ä»¶ï¼å¼ºå¶å·æ°æ§ä»¶çç¼åï¼å¯ä»¥å¼ºå¶è§£å³è±å±çé®é¢ï¼ä½æ¯å¦ææ»å¾ªç¯ä¸è°ç¨ä¼é使§è½ |
| | | */ |
| | | uibase.invalidate = function () { |
| | | this.obj.invalidate() |
| | | } |
| | | /** |
| | | * æ»å¨æä¸ªåæ§ä»¶ç´è³æ¾ç¤ºåºæ¥ï¼å¦ææ³å°ä¸ä¸ªè¢«æ»å¨è³å®¹å¨å¤å¯¼è´çä¸è§çé¡¹ç®æ»å¨è³è½è¢«çè§çä½ç½®ï¼è°ç¨æ¤æ¹æ³ã |
| | | * @param {boolean} en æ¯å¦å¼å¯å¨ç»ï¼å¼å¯ä¼ç¼æ
¢æ»å¨åºæ¥ï¼å
³éåç´æ¥è·³åºã |
| | | * @param {boolean} notRecursive é»è®¤éå½ï¼éç¨äºä¸è¬æ»å¨åæ»å¨åµå¥æ§ä»¶ |
| | | */ |
| | | uibase.scrollToView = function (en, isRecursive) { |
| | | if (isRecursive) { |
| | | this.obj.scrollToView(en) |
| | | } else { |
| | | this.obj.scrollToViewRecursive(en) |
| | | } |
| | | } |
| | | /** |
| | | * æ»å¨ä¸ä¸ªæ§ä»¶çxæ¹å |
| | | * @param {number} x æ»å¨xè½´è·ç¦» |
| | | * @param {boolean} en æ¯å¦å¼å¯å¨ç» |
| | | */ |
| | | uibase.scrollToX = function (x, en) { |
| | | this.obj.scrollToX(x, en) |
| | | } |
| | | /** |
| | | * æ»å¨ä¸ä¸ªæ§ä»¶çyæ¹å |
| | | * @param {number} y æ»å¨yè½´è·ç¦» |
| | | * @param {boolean} en æ¯å¦å¼å¯å¨ç» |
| | | */ |
| | | uibase.scrollToY = function (y, en) { |
| | | this.obj.scrollToY(y, en) |
| | | } |
| | | /** |
| | | * å
ç´ å¿«ç
§ï¼å
¶å®å°±æ¯æªå¾ï¼å¦ææ³ä¿åå
¨å±æªå¾ï¼å¯ä»¥å¯¹å±å¹å¯¹è±¡ä½¿ç¨æ¤æ¹æ³ï¼ |
| | | * @param {string} fileName å¿
å¡«ï¼ä¿åå¿«ç
§çæä»¶åï¼æ³¨æåç¼åºä¸æ ¼å¼å¯¹åºï¼ |
| | | * @param {number} type éå¿
å¡«ï¼ç¼ºçpngï¼å¿«ç
§æ ¼å¼ 0:bmp/1:png/2:jpg(jpeg) |
| | | * @param {number} cf éå¿
å¡«ï¼ä¸ç§RGBé¢è²å卿 ¼å¼ |
| | | */ |
| | | uibase.snapshot = function (fileName, type = 1, cf = NativeObject.APP.NativeComponents.NativeEnum.LV_IMG_CF_TRUE_COLOR_ALPHA) { |
| | | if (!fileName) { |
| | | return |
| | | } |
| | | // é»è®¤åå¨å¨/app/data/snapshotä½ç½® |
| | | os.mkdir("/app/data/snapshot/") |
| | | this.obj.lvSnapshotTake(cf, "/app/data/snapshot/" + fileName, type) |
| | | } |
| | | export default uibase; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //buildï¼20240311 |
| | | //buttonæ§ä»¶ ç¸å¯¹åºç±»æ²¡ææ°åè½ |
| | | import utils from "./uiUtils.js" |
| | | import base from "./uiBase.js" |
| | | let button = {} |
| | | |
| | | button.build = function (id, parent) { |
| | | let temp = utils.validateBuild(button.all, id, parent, 'button') |
| | | let my = { type: 'button' } |
| | | my.obj = new utils.GG.NativeButton({ uid: id }, temp) |
| | | my.id = id |
| | | let comp = Object.assign(my, base); |
| | | utils.setParent(this.all, comp, parent) |
| | | return comp; |
| | | } |
| | | export default button; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //buildï¼20240314 |
| | | //æé®ç»æ§ä»¶ |
| | | import utils from "./uiUtils.js" |
| | | import base from "./uiBase.js" |
| | | let buttons = {} |
| | | |
| | | buttons.build = function (id, parent) { |
| | | let temp = utils.validateBuild(buttons.all, id, parent, 'buttons') |
| | | let my = {type: 'buttons'} |
| | | my.obj = new utils.GG.NativeBtnmatrix({ uid: id }, temp) |
| | | my.id = id |
| | | /** |
| | | * 设置buttonç»å¯¹åºçæ°æ®ï¼å¿
é¡»æ¯æ°ç»æ ¼å¼ï¼ç¤ºä¾å¦ä¸ï¼è¡¨ç¤ºä¸è¡æé®ï¼æ»å
±12个æé® |
| | | * ["1", "2", "3", "0", "\n", |
| | | * "4", "5", "6", "åæ¶", "\n", |
| | | * "7", "8", "9", "确认", ""] |
| | | * @param {array} d éå¿
å¡«ï¼å¦ææ²¡æå¡«æè
䏿¯objectç±»åå°±æ¯è·åæ°æ® |
| | | */ |
| | | my.data = function (d) { |
| | | if (utils.validateObject(d)) { |
| | | this.obj.lvBtnmatrixSetMap(d) |
| | | } else { |
| | | return this.obj.lvBtnmatrixGetMap() |
| | | } |
| | | } |
| | | /** |
| | | * ç¹å»æé®ç»éä»»ä½ä¸ä¸ªæé®ï¼è°ç¨selectedDataæ¥è·åç¹å»æé®çidåææ¬ |
| | | * è¿å示ä¾: {id:11,text:'åæ¶'} |
| | | */ |
| | | my.clickedButton = function () { |
| | | let id = this.obj.lvBtnmatrixGetSelectedBtn(); |
| | | if (id == 0xFFFF) { |
| | | // ç¹å»æé®ç»è¾¹çä¼åºç°0xFFFFéæ³å¼ï¼è¿å空 |
| | | return { id: null, text: null } |
| | | } |
| | | let txt = this.obj.lvBtnmatrixGetBtnText(id); |
| | | return { id: id, text: txt } |
| | | } |
| | | /** |
| | | * 设置æé®ç»éæä¸ä¸ªç¹å®æé®çç¶æï¼å¯ä»¥æ¹æéä¸ï¼ä¸å¯ç¨ä¹ç±»ç |
| | | * @param {number} id æé®çç´¢å¼ï¼ä»0å¼å§ä»å·¦å°å³ä»ä¸å°ä¸ï¼ä¹æ¯ç¹å»æé®clickedButtonè¿åçid |
| | | * @param {number} state åèdxui.Utils.BUTTONS_STATE |
| | | */ |
| | | my.setState = function (id, state) { |
| | | this.obj.lvBtnmatrixSetBtnCtrl(id, state) |
| | | } |
| | | /** |
| | | * æ¸
餿é®ç»éæä¸ä¸ªç¹å®æé®çå·²ç»è®¾ç½®å¥½çç¶æ |
| | | * @param {number} id æé®çç´¢å¼ï¼ä»0å¼å§ä»å·¦å°å³ä»ä¸å°ä¸ï¼ä¹æ¯ç¹å»æé®clickedButtonè¿åçid |
| | | * @param {number} state åèdxui.Utils.BUTTONS_STATE |
| | | */ |
| | | my.clearState = function (id, state) { |
| | | this.obj.lvBtnmatrixClearBtnCtrl(id, state) |
| | | } |
| | | /** |
| | | * 设置æé®ç»éæææé®çç¶æï¼å¯ä»¥æ¹æéä¸ï¼ä¸å¯ç¨ä¹ç±»ç |
| | | * @param {number} state åèdxui.Utils.BUTTONS_STATE |
| | | */ |
| | | my.setAllState = function (state) { |
| | | this.obj.lvBtnmatrixSetBtnCtrlAll(state) |
| | | } |
| | | /** |
| | | * æ¸
餿é®ç»éæææé®çå·²ç»è®¾ç½®å¥½çç¶æ |
| | | * @param {number} state åèdxui.Utils.BUTTONS_STATE |
| | | */ |
| | | my.clearAllState = function (state) { |
| | | this.obj.lvBtnmatrixClearBtnCtrlAll(state) |
| | | } |
| | | /** |
| | | * 设置æä¸ªidçæé®å®½åº¦å ç¨å æ ¼ |
| | | * @param {number} id æé®åºå·ï¼ä»0å¼å§ç¼å· |
| | | * @param {number} width å®½åº¦è·¨è¶æ ¼åæ°é |
| | | */ |
| | | my.setBtnWidth = function (id, width) { |
| | | this.obj.lvBtnmatrixSetBtnWidth(id, width) |
| | | } |
| | | /** |
| | | * 设置æä¸ªidçæé®å¾æ |
| | | * @param {number} id æé®åºå·ï¼ä»0å¼å§ç¼å· |
| | | * @param {string} src 徿 æä»¶è·¯å¾ |
| | | */ |
| | | my.setBtnIcon = function (id, src) { |
| | | this.obj.addEventCb((e) => { |
| | | // è·åç»å¶æ§ä»¶å¯¹è±¡ |
| | | let dsc = e.lvEventGetDrawPartDsc() |
| | | // 妿æ¯ç»å¶ç¬¬id个æé® |
| | | if (dsc.type == utils.ENUM.LV_BTNMATRIX_DRAW_PART_BTN && dsc.id == id) { |
| | | // è·åå¾çä¿¡æ¯ |
| | | let header = utils.GG.NativeDraw.lvImgDecoderGetInfo(src) |
| | | // å®ä¹ä¸ååºåï¼å±
䏿¾ç¤ºï¼æ³¨æï¼å°ºå¯¸è½¬areaéè¦-1ï¼area转尺寸éè¦+1 |
| | | let x1 = dsc.draw_area.x1 + (dsc.draw_area.x2 - dsc.draw_area.x1 + 1 - header.w) / 2; |
| | | let y1 = dsc.draw_area.y1 + (dsc.draw_area.y2 - dsc.draw_area.y1 + 1 - header.h) / 2; |
| | | let x2 = x1 + header.w - 1; |
| | | let y2 = y1 + header.h - 1; |
| | | let area = utils.GG.NativeArea.lvAreaSet(x1, y1, x2, y2) |
| | | // ç»å¶å¾çä¿¡æ¯ |
| | | let img_draw_dsc = utils.GG.NativeDraw.lvDrawImgDscInit() |
| | | // ç»å¶å¾ç |
| | | utils.GG.NativeDraw.lvDrawImg(dsc.dsc, img_draw_dsc, area, src) |
| | | } |
| | | }, utils.ENUM.LV_EVENT_DRAW_PART_END) |
| | | } |
| | | let comp = Object.assign(my, base); |
| | | utils.setParent(this.all,comp,parent) |
| | | return comp; |
| | | } |
| | | export default buttons; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //buildï¼20240329 |
| | | //checkboxæ§ä»¶ |
| | | import utils from "./uiUtils.js" |
| | | import base from "./uiBase.js" |
| | | let checkbox = {} |
| | | |
| | | checkbox.build = function (id, parent) { |
| | | let temp = utils.validateBuild(checkbox.all, id, parent, 'checkbox') |
| | | let my = { type: 'checkbox' } |
| | | my.obj = new utils.GG.NativeCheckbox({ uid: id }, temp) |
| | | my.id = id |
| | | /** |
| | | * è·å/设置æå |
| | | * @param {string} text 设置æå |
| | | * @returns è·åæå |
| | | */ |
| | | my.text = function (text) { |
| | | if (text == null || text == undefined) { |
| | | return this.obj.getText() |
| | | } else { |
| | | this.obj.setText(text) |
| | | } |
| | | } |
| | | /** |
| | | * é䏿ä¸éä¸ |
| | | * @param {boolean} en true/false |
| | | */ |
| | | my.select = function (en) { |
| | | if (en) { |
| | | if (!my.obj.hasState(utils.STATE.CHECKED)) { |
| | | my.obj.addState(utils.STATE.CHECKED) |
| | | } |
| | | } else { |
| | | my.obj.clearState(utils.STATE.CHECKED) |
| | | } |
| | | } |
| | | /** |
| | | * 夿æ¯å¦éä¸ |
| | | * @returns è¿åtrue/false |
| | | */ |
| | | my.isSelect = function () { |
| | | return my.obj.hasState(utils.STATE.CHECKED) |
| | | } |
| | | let comp = Object.assign(my, base); |
| | | utils.setParent(this.all, comp, parent) |
| | | return comp; |
| | | } |
| | | export default checkbox; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //buildï¼20240329 |
| | | //dropdownæ§ä»¶ |
| | | import utils from "./uiUtils.js" |
| | | import base from "./uiBase.js" |
| | | let dropdown = {} |
| | | |
| | | dropdown.build = function (id, parent) { |
| | | let temp = utils.validateBuild(dropdown.all, id, parent, 'dropdown') |
| | | let my = {type: 'dropdown'} |
| | | my.obj = new utils.GG.NativeDropdown({ uid: id }, temp) |
| | | my.id = id |
| | | /** |
| | | * è®¾ç½®ä¸æé项å
容 |
| | | * @param {array} arr é项å
å®¹ï¼æ¯ä¸ªå符串æ°ç»ï¼æ¯ä¸é¡¹ä¸ºä¸ä¸ªé项 |
| | | */ |
| | | my.setOptions = function (arr) { |
| | | this.obj.setOptions(arr.join('\n')) |
| | | } |
| | | /** |
| | | * è·å䏿é项å表 |
| | | * @returns è¿ååè¡¨å¯¹è±¡ï¼æ¯ä¸ä¸ªåºç±»å¯¹è±¡ï¼å¯ä»¥åç¬è®¾ç½®å®çåä½ |
| | | */ |
| | | my.getList = function () { |
| | | let res = {} |
| | | res.obj = this.obj.getList() |
| | | return Object.assign(res, base) |
| | | } |
| | | /** |
| | | * 设置éä¸é¡¹ï¼é»è®¤ä¼éä¸è¿ä¸ª |
| | | * @param {number} index éä¸é¡¹ç´¢å¼ |
| | | */ |
| | | my.setSelected = function (index) { |
| | | this.obj.setSelected(index) |
| | | } |
| | | /** |
| | | * è·åéä¸é¡¹ç´¢å¼ |
| | | * @returns è¿åå½åéä¸çç´¢å¼ |
| | | */ |
| | | my.getSelected = function () { |
| | | return this.obj.getSelected() |
| | | } |
| | | /** |
| | | * è®¾ç½®ä¸ææ¡éå±å¾æ ï¼é»è®¤æ¯ä¸ªæä¸çç®å¤´ |
| | | * @param {string} icon 徿 å°å |
| | | */ |
| | | my.setSymbol = function (icon) { |
| | | this.obj.setSymbol(icon) |
| | | } |
| | | let comp = Object.assign(my, base); |
| | | utils.setParent(this.all, comp, parent) |
| | | return comp; |
| | | } |
| | | export default dropdown; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //buildï¼20240311 |
| | | //åä½å¯¹è±¡(è¦æ¯æä¸æï¼éè¦ä½¿ç¨æ¯æä¸æçåä½ttfæä»¶) |
| | | import utils from "./uiUtils.js" |
| | | let font = {} |
| | | /** |
| | | * æå»ºåä½ |
| | | * @param {string} ttf åä½ttfæä»¶ç宿´è·¯å¾ |
| | | * @param {number} size åä½å¤§å° |
| | | * @param {number} style å使 ·å¼ï¼åèutils.FONT_STYLE |
| | | * @returns |
| | | */ |
| | | font.build = function (ttf, size, style) { |
| | | let comp = {} |
| | | comp.obj = utils.GG.NativeFont.lvFontInit(ttf, size, style) |
| | | return comp; |
| | | } |
| | | |
| | | export default font; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //buildï¼20240311 |
| | | //imageæ§ä»¶ |
| | | import utils from "./uiUtils.js" |
| | | import base from "./uiBase.js" |
| | | let image = {} |
| | | |
| | | image.build = function (id, parent) { |
| | | let temp = utils.validateBuild(image.all, id, parent, 'image') |
| | | let my = {type: 'image'} |
| | | my.obj = new utils.GG.NativeImage({ uid: id }, temp) |
| | | my.id = id |
| | | /** |
| | | * 设置imageçæ¥æºæè·åæ¥æº |
| | | * @param {string} path éå¿
å¡«ï¼å¾çæä»¶çç»å¯¹è·¯å¾ï¼å¦ææ²¡æå¡«æè
䏿¯stringç±»åå°±æ¯è·å |
| | | */ |
| | | my.source = function (path) { |
| | | if (utils.validateString(path)) { |
| | | this.obj.lvImgSetSrc(path) |
| | | } else { |
| | | return this.obj.lvImgGetSrc() |
| | | } |
| | | } |
| | | let comp = Object.assign(my, base); |
| | | utils.setParent(this.all, comp, parent) |
| | | return comp; |
| | | } |
| | | export default image; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //buildï¼20240329 |
| | | //keyboardæ§ä»¶ |
| | | import utils from "./uiUtils.js" |
| | | import base from "./uiBase.js" |
| | | let keyboard = {} |
| | | |
| | | keyboard.build = function (id, parent) { |
| | | let temp = utils.validateBuild(keyboard.all, id, parent, 'keyboard') |
| | | let my = {type: 'keyboard'} |
| | | my.obj = new utils.GG.NativeKeyboard({ uid: id }, temp) |
| | | |
| | | // æ¼é³è¾å
¥æ³ä¼è·å¾ä¸ä¸ªæ°å¯¹è±¡ï¼ä¸å½åé®çç»å®ï¼ä»¥å¢å¼ºé®çåè½ï¼å¦9é®çï¼ç¨æ·ä½¿ç¨æ¶ä¸ç¨å
³å¿ï¼åªè¦æä½æåå建çé£ä¸ªé®ç对象 |
| | | let pinyin = {} |
| | | pinyin.obj = my.obj.lvImePinyinCreate() |
| | | my.obj.lvImePinyinSetKeyboard(pinyin.obj) |
| | | my["__obj"] = Object.assign(pinyin, base) |
| | | my.__mode = "K26" |
| | | |
| | | my.id = id |
| | | /** |
| | | * 设置å
³èææ¬æ¡ï¼é®çè¾åºçå
容伿¾ç¤ºå¨è¿é |
| | | * @param {object} textarea ææ¬æ¡æ§ä»¶å¯¹è±¡ |
| | | */ |
| | | my.setTextarea = function (textarea) { |
| | | this.obj.lvKeyboardSetTextarea(textarea.obj) |
| | | my.textarea = textarea |
| | | } |
| | | /** |
| | | * 设置/è·å模å¼ï¼çº¯æ°åé®çæå
¶ä»æ¨¡å¼ |
| | | * @param {any} mode 模å¼ï¼åç
§æä¸¾ |
| | | * @returns è¿åå½åæ¨¡å¼ |
| | | */ |
| | | my.mode = function (mode) { |
| | | if (!mode) { |
| | | return my.__mode |
| | | } |
| | | if (mode == "K26" || mode == "K9") { |
| | | this.obj.lvImePinyinSetMode(my["__obj"].obj, mode == "K26" ? 0 : 1) |
| | | } else { |
| | | if (mode == utils.KEYBOARD.NUMBER) { |
| | | this.obj.lvImePinyinSetMode(my["__obj"].obj, 2) |
| | | } |
| | | this.obj.lvKeyboardSetMode(mode) |
| | | } |
| | | my.__mode = mode |
| | | } |
| | | /** |
| | | * 设置æ¼é³åä½ï¼åé®çä¸åï¼è¿éè®¾ç½®çæ¯åéååä½ |
| | | * @param {object} font font.jsébuildè¿åç对象 |
| | | * @param {number} type åèutils.STYLE éå¿
å¡«ï¼ç¼ºçæ¯å对象èªèº«ç»å® |
| | | */ |
| | | my.chFont = function (font, type) { |
| | | if (!utils.validateNumber(type)) { |
| | | type = 0 |
| | | } |
| | | if (!font || !font.obj) { |
| | | throw new Error("dxui.textFont: 'font' parameter should not be null") |
| | | } |
| | | my.obj.lvImePinyinGetCandPanel(my["__obj"].obj).lvObjSetStyleTextFont(font.obj, type) |
| | | } |
| | | /** |
| | | * æä¸æ¶å¨å¼¹åºçªå£ä¸æ¾ç¤ºæé®æ é¢ï¼å³è¾
婿¾ç¤ºçä¸ä½æ¡ã |
| | | * @param {boolean} en true/false |
| | | */ |
| | | my.setPopovers = function (en) { |
| | | this.obj.lvKeyboardSetPopovers(en) |
| | | } |
| | | /** |
| | | * 设置è¯åº |
| | | * @param {object} dict è¯åºï¼æ ¼å¼å¦ï¼{"a": "å", "ai": "ç±",...,"zu":"ç»"},26ä¸ªåæ¯é½è¦æï¼æ²¡æåéåå°±å"" |
| | | * @returns |
| | | */ |
| | | my.dict = function (dict) { |
| | | if (!dict) { |
| | | return my.obj.lvImePinyinGetDict(my["__obj"].obj) |
| | | } else { |
| | | my.obj.lvImePinyinSetDict(my["__obj"].obj, dict) |
| | | } |
| | | } |
| | | let comp = Object.assign(my, base); |
| | | // éåæ¹æ³ |
| | | // ä¿çåå§çæ¹æ³ |
| | | const super_hide = my.hide; |
| | | const super_show = my.show; |
| | | my.hide = function () { |
| | | super_hide.call(this) |
| | | my.obj.lvImePinyinGetCandPanel(my["__obj"].obj).lvObjAddFlag(1); |
| | | if (my.textarea.text() && my.textarea.text().length > 0) { |
| | | my.obj.lvImePinyinClearData(my["__obj"].obj) |
| | | } |
| | | } |
| | | my.show = function () { |
| | | super_show.call(this) |
| | | if (my.obj.lvImePinyinGetCandNum(my["__obj"].obj) > 0) { |
| | | my.obj.lvImePinyinGetCandPanel(my["__obj"].obj).lvObjClearFlag(1); |
| | | } |
| | | my.obj.lvImePinyinGetCandPanel(my["__obj"].obj).lvObjAlignTo(my.obj, utils.ALIGN.OUT_TOP_MID, 0, 0) |
| | | } |
| | | utils.setParent(this.all, comp, parent) |
| | | return comp; |
| | | } |
| | | export default keyboard; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //buildï¼20240311 |
| | | //labelæ§ä»¶ |
| | | import utils from "./uiUtils.js" |
| | | import base from "./uiBase.js" |
| | | let label = {} |
| | | |
| | | label.build = function (id, parent) { |
| | | let temp = utils.validateBuild(label.all, id, parent, 'label') |
| | | let my = {type: 'label'} |
| | | my.obj = new utils.GG.NativeLabel({ uid: id }, temp) |
| | | my.id = id |
| | | /** |
| | | * 设置labelçææ¬æè·åææ¬å
容 |
| | | * @param {string} t éå¿
å¡«ï¼å¦ææ²¡æå¡«æè
䏿¯stringç±»åå°±æ¯è·åææ¬ |
| | | */ |
| | | my.text = function (t) { |
| | | if (utils.validateString(t)) { |
| | | this.obj.lvLabelSetText(t) |
| | | } else { |
| | | return this.obj.lvLabelGetText() |
| | | } |
| | | } |
| | | /** |
| | | * è®¾ç½®ææ¬è¶
é¿åæ¾ç¤ºç模å¼ï¼æ¯å¦æ»å¨æ¾ç¤ºææªææ...ç |
| | | * @param {number} mode æä¸¾åèutils.LABEL_LONG_MODE |
| | | */ |
| | | my.longMode = function (mode) { |
| | | this.obj.lvLabelSetLongMode(mode) |
| | | } |
| | | let comp = Object.assign(my, base); |
| | | utils.setParent(this.all, comp, parent) |
| | | return comp; |
| | | } |
| | | export default label; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //buildï¼20240311 |
| | | //lineæ§ä»¶ |
| | | import utils from "./uiUtils.js" |
| | | import base from "./uiBase.js" |
| | | let line = {} |
| | | |
| | | line.build = function (id, parent) { |
| | | let temp = utils.validateBuild(line.all, id, parent, 'line') |
| | | let my = {type: 'line'} |
| | | my.obj = new utils.GG.NativeLine({ uid: id }, temp) |
| | | my.id = id |
| | | /** |
| | | * 设置lineçææç¹çåæ |
| | | * @param {Array} points å¿
å¡«ï¼ææçç¹ç»æçæ°ç»ï¼æ¯å¦[[x1,y1],[x2,y2]] |
| | | * @param {number} count å¿
å¡«ï¼è¦ç»å¶çç¹ç个æ°ï¼æ³¨æè¿ä¸ªå¼å¯ä»¥å°äºpointsçé¿åº¦ |
| | | */ |
| | | my.setPoints = function (points, count) { |
| | | this.obj.lvLineSetPoints(points, count) |
| | | } |
| | | let comp = Object.assign(my, base); |
| | | utils.setParent(this.all, comp, parent) |
| | | return comp; |
| | | } |
| | | export default line; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //buildï¼20240329 |
| | | //listæ§ä»¶ |
| | | import utils from "./uiUtils.js" |
| | | import base from "./uiBase.js" |
| | | let list = {} |
| | | |
| | | list.build = function (id, parent) { |
| | | let temp = utils.validateBuild(list.all, id, parent, 'list') |
| | | let my = {type: 'list'} |
| | | my.obj = new utils.GG.NativeList({ uid: id }, temp) |
| | | my.id = id |
| | | /** |
| | | * æ·»å åä¸ªææ¬é¡¹ |
| | | * @param {string} text é¡¹çææ¬å
容 |
| | | * @returns 项èªèº«çbase对象 |
| | | */ |
| | | my.addText = function (text) { |
| | | let res = {} |
| | | res.obj = this.obj.lvListAddText(text) |
| | | return Object.assign(res, base) |
| | | } |
| | | /** |
| | | * æ·»å å个æé®é¡¹ |
| | | * @param {string} src 项åé¢ç徿 è·¯å¾ |
| | | * @param {string} text é¡¹çææ¬å
容 |
| | | * @returns 项èªèº«çbase对象 |
| | | */ |
| | | my.addBtn = function (src, text) { |
| | | let res = {} |
| | | res.obj = this.obj.lvListAddBtn(src, text) |
| | | return Object.assign(res, base) |
| | | } |
| | | /** |
| | | * è·åæé®é¡¹çææ¬å
容 |
| | | * @param {string} btn æé®é¡¹ |
| | | * @returns æé®é¡¹çææ¬å
容 |
| | | */ |
| | | my.getBtnText = function (btn) { |
| | | return this.obj.lvListGetBtnText(btn.obj) |
| | | } |
| | | let comp = Object.assign(my, base); |
| | | utils.setParent(this.all, comp, parent) |
| | | return comp; |
| | | } |
| | | export default list; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //buildï¼20240329 |
| | | //slideræ§ä»¶ |
| | | import utils from "./uiUtils.js" |
| | | import base from "./uiBase.js" |
| | | let slider = {} |
| | | |
| | | slider.build = function (id, parent) { |
| | | let temp = utils.validateBuild(slider.all, id, parent, 'slider') |
| | | let my = {type: 'slider'} |
| | | my.obj = new utils.GG.NativeSlider({ uid: id }, temp) |
| | | my.id = id |
| | | |
| | | /** |
| | | * è·å/è®¾ç½®å¼ |
| | | * @param {number} v è®¾ç½®å¼ |
| | | * @param {boolean} en è®¾ç½®å¼æ¶æ¯å¦å¼å¯å¨ç»ï¼å³ç¼å¨ææ |
| | | * @returns è·åå¼ |
| | | */ |
| | | my.value = function (v, en) { |
| | | if (v == null || v == undefined) { |
| | | return this.obj.lvSliderGetValue() |
| | | } else { |
| | | if (!utils.validateNumber(en)) { |
| | | en = false |
| | | } |
| | | this.obj.lvSliderSetValue(v, en) |
| | | } |
| | | } |
| | | /** |
| | | * 设置èå´ |
| | | * @param {number} min æå°å¼ |
| | | * @param {number} max æå¤§å¼ |
| | | */ |
| | | my.range = function (min, max) { |
| | | this.obj.lvSliderSetRange(min, max) |
| | | } |
| | | |
| | | let comp = Object.assign(my, base); |
| | | utils.setParent(this.all, comp, parent) |
| | | return comp; |
| | | } |
| | | export default slider; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //buildï¼20240315 |
| | | //æ§ä»¶æ ·å¼ æ¯ä¸ªæ§ä»¶å¯ä»¥ç»å®æ ·å¼å¯¹è±¡ï¼è®¾ç½®å¤ç§æ ·å¼ |
| | | import utils from "./uiUtils.js" |
| | | |
| | | let style = {} |
| | | style.build = function () { |
| | | let comp = {} |
| | | comp.obj = new utils.GG.NativeStyle() |
| | | comp.obj.lvStyleInit() |
| | | /** |
| | | * 设置左å³ä¸ä¸çå
è¾¹è·é½ä¸ºä¸ä¸ªå¼ |
| | | * @param {number} pad è¾¹è·å¼ |
| | | */ |
| | | comp.padAll = function (pad) { |
| | | this.obj.lvStyleSetPadAll(pad) |
| | | } |
| | | /** |
| | | * 设置å³å
è¾¹è·é½ä¸ºä¸ä¸ªå¼ |
| | | * @param {number} pad è¾¹è·å¼ |
| | | */ |
| | | comp.padRight = function (pad) { |
| | | this.obj.lvStyleSetPadRight(pad) |
| | | } |
| | | /** |
| | | * 设置左å
è¾¹è·é½ä¸ºä¸ä¸ªå¼ |
| | | * @param {number} pad è¾¹è·å¼ |
| | | */ |
| | | comp.padLeft = function (pad) { |
| | | this.obj.lvStyleSetPadLeft(pad) |
| | | } |
| | | /** |
| | | * 设置ä¸å
è¾¹è·é½ä¸ºä¸ä¸ªå¼ |
| | | * @param {number} pad è¾¹è·å¼ |
| | | */ |
| | | comp.padTop = function (pad) { |
| | | this.obj.lvStyleSetPadTop(pad) |
| | | } |
| | | /** |
| | | * 设置ä¸å
è¾¹è·é½ä¸ºä¸ä¸ªå¼ |
| | | * @param {number} pad è¾¹è·å¼ |
| | | */ |
| | | comp.padBottom = function (pad) { |
| | | this.obj.lvStyleSetPadBottom(pad) |
| | | } |
| | | /** |
| | | * 设置åä¸åä¹é´çè¾¹è·é½ä¸ºä¸ä¸ªå¼ |
| | | * @param {number} pad è¾¹è·å¼ |
| | | */ |
| | | comp.padColumn = function (pad) { |
| | | this.obj.lvStyleSetPadColumn(pad) |
| | | } |
| | | /** |
| | | * 设置è¡ä¸è¡ä¹é´çè¾¹è·é½ä¸ºä¸ä¸ªå¼ |
| | | * @param {number} pad è¾¹è·å¼ |
| | | */ |
| | | comp.padRow = function (pad) { |
| | | this.obj.lvStyleSetPadRow(pad) |
| | | } |
| | | /** |
| | | * 设置边æ¡å®½åº¦ |
| | | * @param {number} w |
| | | */ |
| | | comp.borderWidth = function (w) { |
| | | this.obj.lvStyleSetBorderWidth(w) |
| | | } |
| | | /** |
| | | * 设置边åè§ |
| | | * @param {number} r |
| | | */ |
| | | comp.radius = function (r) { |
| | | this.obj.lvStyleSetRadius(r) |
| | | } |
| | | /** |
| | | * è®¾ç½®èæ¯éæåº¦ï¼å¼èå´æ¯0-100ï¼å¼è¶å°è¶å¥½ |
| | | * @param {number} opa å¿
é¡»æ¯0-100 |
| | | */ |
| | | comp.bgOpa = function (opa) { |
| | | this.obj.lvStyleSetBgOpa(utils.OPA_MAPPING(opa)) |
| | | } |
| | | /** |
| | | * 设置èªèº«éæåº¦ï¼å¼èå´æ¯0-100ï¼å¼è¶å°è¶å¥½ |
| | | * @param {number} opa å¿
é¡»æ¯0-100 |
| | | */ |
| | | comp.opa = function (opa) { |
| | | this.obj.lvStyleSetOpa(utils.OPA_MAPPING(opa)) |
| | | } |
| | | /** |
| | | * è®¾ç½®èæ¯é¢è² |
| | | * @param {any} color æ¯ææ°åç±»åï¼æ¯å¦0x34ffaaï¼å符串类å(#å¼å¤´),æ¯å¦:'#34ffaa' |
| | | */ |
| | | comp.bgColor = function (color) { |
| | | this.obj.lvStyleSetBgColor(utils.colorParse(color)) |
| | | } |
| | | /** |
| | | * è®¾ç½®ææ¬é¢è² |
| | | * @param {any} color æ¯ææ°åç±»åï¼æ¯å¦0x34ffaaï¼å符串类å(#å¼å¤´),æ¯å¦:'#34ffaa' |
| | | */ |
| | | comp.textColor = function (color) { |
| | | this.obj.lvStyleSetTextColor(utils.colorParse(color)) |
| | | } |
| | | /** |
| | | * è®¾ç½®ææ¬å¯¹é½æ¹å¼ |
| | | * @param {number} type åèutils.TEXT_ALIGN |
| | | */ |
| | | comp.textAlign = function (type) { |
| | | this.obj.lvStyleSetTextAlign(type) |
| | | } |
| | | /** |
| | | * è®¾ç½®ææ¬åä½ |
| | | * @param {object} font font.jsébuildè¿åç对象 |
| | | */ |
| | | comp.textFont = function (font) { |
| | | if (!font || !font.obj) { |
| | | throw new Error("style.textFont: 'font' parameter should not be null") |
| | | } |
| | | this.obj.lvStyleSetTextFont(font.obj) |
| | | } |
| | | /** |
| | | * 设置æ¸åè² |
| | | * @param {number} color æ¸åè²ï¼ä¾å¦:0xffffff |
| | | */ |
| | | comp.bgGradColor = function (color) { |
| | | this.obj.lvStyleSetBgGradColor(color) |
| | | } |
| | | /** |
| | | * 设置æ¸åè²æ¹å |
| | | * @param {number} dir æ¹åï¼ç®ååªæ¯ææ°´å¹³ååç´ |
| | | */ |
| | | comp.bgGradDir = function (dir) { |
| | | this.obj.lvStyleSetBgGradDir(dir) |
| | | } |
| | | /** |
| | | * èæ¯è²çç»æä½ç½®(0-255) |
| | | * @param {number} value è·ç¦»ï¼ä»å·¦ç«¯å¼å§è®¡ç® |
| | | */ |
| | | comp.bgMainStop = function (value) { |
| | | this.obj.lvStyleSetBgMainStop(value) |
| | | } |
| | | /** |
| | | * æ¸åè²çè·ç¦»(0-255) |
| | | * @param {number} value è·ç¦»ï¼ä»èæ¯è²çç»æä½ç½®å¼å§è®¡ç® |
| | | */ |
| | | comp.bgGradStop = function (value) { |
| | | this.obj.lvStyleSetBgGradStop(value) |
| | | } |
| | | return comp; |
| | | } |
| | | |
| | | export default style; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //buildï¼20240329 |
| | | //_switchæ§ä»¶ |
| | | import utils from "./uiUtils.js" |
| | | import base from "./uiBase.js" |
| | | let _switch = {} |
| | | |
| | | _switch.build = function (id, parent) { |
| | | let temp = utils.validateBuild(_switch.all, id, parent, '_switch') |
| | | let my = {type: 'switch'} |
| | | my.obj = new utils.GG.NativeSwitch({ uid: id }, temp) |
| | | my.id = id |
| | | |
| | | /** |
| | | * è·å/设置æå |
| | | * @param {string} text 设置æå |
| | | * @returns è·åæå |
| | | */ |
| | | my.text = function (text) { |
| | | if (text == null || text == undefined) { |
| | | return this.obj.getText() |
| | | } else { |
| | | this.obj.setText(text) |
| | | } |
| | | } |
| | | /** |
| | | * é䏿ä¸éä¸ |
| | | * @param {boolean} en true/false |
| | | */ |
| | | my.select = function (en) { |
| | | if (en) { |
| | | if (!my.obj.hasState(utils.STATE.CHECKED)) { |
| | | my.obj.addState(utils.STATE.CHECKED) |
| | | } |
| | | } else { |
| | | my.obj.clearState(utils.STATE.CHECKED) |
| | | } |
| | | } |
| | | /** |
| | | * 夿æ¯å¦éä¸ |
| | | * @returns è¿åtrue/false |
| | | */ |
| | | my.isSelect = function () { |
| | | return my.obj.hasState(utils.STATE.CHECKED) |
| | | } |
| | | let comp = Object.assign(my, base); |
| | | utils.setParent(this.all, comp, parent) |
| | | return comp; |
| | | } |
| | | export default _switch; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //buildï¼20240330 |
| | | //textareaæ§ä»¶ |
| | | import utils from "./uiUtils.js" |
| | | import base from "./uiBase.js" |
| | | let textarea = {} |
| | | |
| | | textarea.build = function (id, parent) { |
| | | let temp = utils.validateBuild(textarea.all, id, parent, 'textarea') |
| | | let my = {type: 'textarea'} |
| | | my.obj = new utils.GG.NativeTextarea({ uid: id }, temp) |
| | | my.id = id |
| | | /** |
| | | * 设置åè¡æ¨¡å¼ï¼ä¸è½æ¢è¡ |
| | | * @param {boolean} en true/false |
| | | */ |
| | | my.setOneLine = function (en) { |
| | | this.obj.lvTextareaSetOneLine(en) |
| | | } |
| | | /** |
| | | * 设置å¯ç 模å¼ï¼å
容æ¾ç¤ºä¸ºÂ·å· |
| | | * @param {boolean} en true/false |
| | | */ |
| | | my.setPasswordMode = function (en) { |
| | | this.obj.lvTextareaSetPasswordMode(en) |
| | | } |
| | | /** |
| | | * 设置å
容坹齿¹å¼ï¼å±
ä¸é å·¦é å³ç |
| | | * @param {number} align 坹齿¹å¼æä¸¾ |
| | | */ |
| | | my.setAlign = function (align) { |
| | | this.obj.lvTextareaSetAlign(align) |
| | | } |
| | | /** |
| | | * 设置å
容æå¤§é¿åº¦ï¼å符æ°éå¶ |
| | | * @param {number} length é¿åº¦ |
| | | */ |
| | | my.setMaxLength = function (length) { |
| | | this.obj.lvTextareaSetMaxLength(length) |
| | | } |
| | | /** |
| | | * 设置æ¯å¦å¯ç¨å
æ å®ä½ï¼æ¯å¦æ¾ç¤º| |
| | | * @param {boolean} en true/false |
| | | */ |
| | | my.setCursorClickPos = function (en) { |
| | | this.obj.lvTextareaSetCursorClickPos(en) |
| | | } |
| | | /** |
| | | * å¨å½åå
æ ä½ç½®æå
¥ææ¬ |
| | | * @param {string} txt ææ¬å
容 |
| | | */ |
| | | my.lvTextareaAddText = function (txt) { |
| | | this.obj.lvTextareaAddText(txt) |
| | | } |
| | | /** |
| | | * ä»å½åå
æ ä½ç½®å é¤å·¦è¾¹çå符 |
| | | */ |
| | | my.lvTextareaDelChar = function () { |
| | | this.obj.lvTextareaDelChar() |
| | | } |
| | | /** |
| | | * è·å/è®¾ç½®ææ¬å
容 |
| | | * @param {string} text è®¾ç½®ææ¬å
容 |
| | | * @returns è·åææ¬å
容 |
| | | */ |
| | | my.text = function (text) { |
| | | if (text == null || text == undefined) { |
| | | return this.obj.lvTextareaGetText() |
| | | } else { |
| | | this.obj.lvTextareaSetText(text) |
| | | } |
| | | } |
| | | let comp = Object.assign(my, base); |
| | | utils.setParent(this.all, comp, parent) |
| | | return comp; |
| | | } |
| | | export default textarea; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //buildï¼20240315 |
| | | //å
¬ç¨çä¸äºå½æ°ã常éãæä¸¾ç |
| | | import { uiClass } from '../dxmodules/libvbar-m-dxui.so' |
| | | import logger from './dxLogger.js' |
| | | const ui = new uiClass(); |
| | | // åå§åuiç»ä»¶ |
| | | ui.init() |
| | | |
| | | let utils = {} |
| | | utils.GG = NativeObject.APP.NativeComponents |
| | | utils.ENUM = utils.GG.NativeEnum |
| | | utils.LAYER = { |
| | | "MAIN": 0, |
| | | "SYS": 1, |
| | | "TOP": 2 |
| | | } |
| | | utils.EVENT = { |
| | | "CLICK": 7, |
| | | "LONG_PRESSED": 5, |
| | | "SHORT_PRESSED": 4, |
| | | "PRESSING": utils.ENUM.LV_EVENT_PRESSING, |
| | | "FOCUSED": utils.ENUM.LV_EVENT_FOCUSED, |
| | | "DEFOCUSED": utils.ENUM.LV_EVENT_DEFOCUSED, |
| | | "VALUE_CHANGED": utils.ENUM.LV_EVENT_VALUE_CHANGED, |
| | | "INSERT": utils.ENUM.LV_EVENT_INSERT, |
| | | "REFRESH": utils.ENUM.LV_EVENT_REFRESH, |
| | | "READY": utils.ENUM.LV_EVENT_READY, |
| | | "CANCEL": utils.ENUM.LV_EVENT_CANCEL, |
| | | } |
| | | utils.TEXT_ALIGN = { |
| | | "AUTO": 0, |
| | | "LEFT": 1, |
| | | "CENTER": 2, |
| | | "RIGHT": 3 |
| | | } |
| | | utils.STATE = { |
| | | "DEFAULT": utils.ENUM.LV_STATE_DEFAULT, |
| | | "CHECKED": utils.ENUM.LV_STATE_CHECKED, |
| | | "FOCUSED": utils.ENUM.LV_STATE_FOCUSED, |
| | | "FOCUS_KEY": utils.ENUM.LV_STATE_FOCUS_KEY, |
| | | "EDITED": utils.ENUM.LV_STATE_EDITED, |
| | | "HOVERED": utils.ENUM.LV_STATE_HOVERED, |
| | | "PRESSED": utils.ENUM.LV_STATE_PRESSED, |
| | | "SCROLLED": utils.ENUM.LV_STATE_SCROLLED, |
| | | "DISABLED": utils.ENUM.LV_STATE_DISABLED, |
| | | } |
| | | utils.OBJ_FLAG = { |
| | | "CLICKABLE": utils.ENUM.LV_OBJ_FLAG_CLICKABLE, |
| | | } |
| | | utils.ALIGN = {//ç¸å¯¹åç
§å¯¹è±¡çä½ç½®ï¼å¸¦ OUT çå¨åç
§å¯¹è±¡çè¾¹çå¤ |
| | | "OUT_TOP_LEFT": utils.ENUM.LV_ALIGN_OUT_TOP_LEFT, |
| | | "OUT_TOP_MID": utils.ENUM.LV_ALIGN_OUT_TOP_MID, |
| | | "OUT_TOP_RIGHT": utils.ENUM.LV_ALIGN_OUT_TOP_RIGHT, |
| | | "OUT_BOTTOM_LEFT": utils.ENUM.LV_ALIGN_OUT_BOTTOM_LEFT, |
| | | "OUT_BOTTOM_MID": utils.ENUM.LV_ALIGN_OUT_BOTTOM_MID, |
| | | "OUT_BOTTOM_RIGHT": utils.ENUM.LV_ALIGN_OUT_BOTTOM_RIGHT, |
| | | "OUT_LEFT_TOP": utils.ENUM.LV_ALIGN_OUT_LEFT_TOP, |
| | | "OUT_LEFT_MID": utils.ENUM.LV_ALIGN_OUT_LEFT_MID, |
| | | "OUT_LEFT_BOTTOM": utils.ENUM.LV_ALIGN_OUT_LEFT_BOTTOM, |
| | | "OUT_RIGHT_TOP": utils.ENUM.LV_ALIGN_OUT_RIGHT_TOP, |
| | | "OUT_RIGHT_MID": utils.ENUM.LV_ALIGN_OUT_RIGHT_MID, |
| | | "OUT_RIGHT_BOTTOM": utils.ENUM.LV_ALIGN_OUT_RIGHT_BOTTOM, |
| | | "TOP_LEFT": utils.ENUM.LV_ALIGN_TOP_LEFT, |
| | | "TOP_MID": utils.ENUM.LV_ALIGN_TOP_MID, |
| | | "TOP_RIGHT": utils.ENUM.LV_ALIGN_TOP_RIGHT, |
| | | "BOTTOM_LEFT": utils.ENUM.LV_ALIGN_BOTTOM_LEFT, |
| | | "BOTTOM_MID": utils.ENUM.LV_ALIGN_BOTTOM_MID, |
| | | "BOTTOM_RIGHT": utils.ENUM.LV_ALIGN_BOTTOM_RIGHT, |
| | | "LEFT_MID": utils.ENUM.LV_ALIGN_LEFT_MID, |
| | | "RIGHT_MID": utils.ENUM.LV_ALIGN_RIGHT_MID, |
| | | "CENTER": utils.ENUM.LV_ALIGN_CENTER, |
| | | "DEFAULT": utils.ENUM.LV_ALIGN_DEFAULT |
| | | } |
| | | utils.FLEX_ALIGN = {//flexå¸å±ï¼å¯¹é½æ¹å¼ |
| | | "START": utils.ENUM.LV_FLEX_ALIGN_START, |
| | | "END": utils.ENUM.LV_FLEX_ALIGN_END, |
| | | "CENTER": utils.ENUM.LV_FLEX_ALIGN_CENTER, |
| | | "SPACE_EVENLY": utils.ENUM.LV_FLEX_ALIGN_SPACE_EVENLY, |
| | | "SPACE_AROUND": utils.ENUM.LV_FLEX_ALIGN_SPACE_AROUND, |
| | | "SPACE_BETWEEN": utils.ENUM.LV_FLEX_ALIGN_SPACE_BETWEEN, |
| | | } |
| | | utils.FLEX_FLOW = {//flexå¸å±ï¼ä¸»ä¾§è½´ |
| | | "ROW": utils.ENUM.LV_FLEX_FLOW_ROW, |
| | | "COLUMN": utils.ENUM.LV_FLEX_FLOW_COLUMN, |
| | | "ROW_WRAP": utils.ENUM.LV_FLEX_FLOW_ROW_WRAP, |
| | | "ROW_REVERSE": utils.ENUM.LV_FLEX_FLOW_ROW_REVERSE, |
| | | "ROW_WRAP_REVERSE": utils.ENUM.LV_FLEX_FLOW_ROW_WRAP_REVERSE, |
| | | "COLUMN_WRAP": utils.ENUM.LV_FLEX_FLOW_COLUMN_WRAP, |
| | | "COLUMN_REVERSE": utils.ENUM.LV_FLEX_FLOW_COLUMN_REVERSE, |
| | | "COLUMN_WRAP_REVERSE": utils.ENUM.LV_FLEX_FLOW_COLUMN_WRAP_REVERSE, |
| | | } |
| | | utils.GRAD = {//æ¸åè²æ¹å |
| | | "NONE": utils.ENUM.LV_GRAD_DIR_NONE, |
| | | "VER": utils.ENUM.LV_GRAD_DIR_VER, |
| | | "HOR": utils.ENUM.LV_GRAD_DIR_HOR, |
| | | } |
| | | utils.KEYBOARD = {//é®çæ¨¡å¼ |
| | | "TEXT_LOWER": utils.ENUM.LV_KEYBOARD_MODE_TEXT_LOWER, |
| | | "TEXT_UPPER": utils.ENUM.LV_KEYBOARD_MODE_TEXT_UPPER, |
| | | "SPECIAL": utils.ENUM.LV_KEYBOARD_MODE_SPECIAL, |
| | | "NUMBER": utils.ENUM.LV_KEYBOARD_MODE_NUMBER, |
| | | "K26": "K26", |
| | | "K9": "K9", |
| | | } |
| | | utils.FONT_STYLE = { |
| | | "NORMAL": utils.ENUM.FT_FONT_STYLE_NORMAL, |
| | | "ITALIC": utils.ENUM.FT_FONT_STYLE_ITALIC, |
| | | "BOLD": utils.ENUM.FT_FONT_STYLE_BOLD, |
| | | } |
| | | utils.BUTTONS_STATE = { |
| | | "HIDDEN": utils.ENUM.LV_BTNMATRIX_CTRL_HIDDEN,//æé®ç©éµä¸çæä¸ªæé®æ¯å¦éè |
| | | "NO_REPEAT": utils.ENUM.LV_BTNMATRIX_CTRL_NO_REPEAT,//æé®ç©éµä¸çæé®æ¯å¦å¯ä»¥é夿ä¸,ä¸ä¼éå¤è§¦åæé®äºä»¶ |
| | | "DISABLED": utils.ENUM.LV_BTNMATRIX_CTRL_DISABLED,//æé®ç©éµä¸çæä¸ªæé®æ¯å¦ç¦ç¨ |
| | | "CHECKABLE": utils.ENUM.LV_BTNMATRIX_CTRL_CHECKABLE,//æé®ç©éµä¸çæé®æ¯å¦å¯éä¸ |
| | | "CHECKED": utils.ENUM.LV_BTNMATRIX_CTRL_CHECKED,//æé®ç©éµä¸çæä¸ªæé®æ¯å¦å·²è¢«éä¸,å¨çé¢ä¸åç°ä¸ºè¢«éä¸ç¶æ |
| | | "CLICK_TRIG": utils.ENUM.LV_BTNMATRIX_CTRL_CLICK_TRIG,//æé®ç©éµä¸çæé®æ¯å¦å¯ä»¥éè¿ç¹å»è§¦å |
| | | "POPOVER": utils.ENUM.LV_BTNMATRIX_CTRL_POPOVER,//ç©éµä¸çæä¸ªæé®æ¯å¦å¼¹åº,被ç¹å»å伿¾ç¤ºæ´å¤çé项æå
容 |
| | | "RECOLOR": utils.ENUM.LV_BTNMATRIX_CTRL_RECOLOR//ç©éµä¸çæé®æ¯å¦å¯éæ°çè² |
| | | } |
| | | //æ ·å¼èµ·ä½ç¨çé¨å |
| | | utils.STYLE_PART = { |
| | | "MAIN": 0, //对象å½åæ ·å¼èµ·ä½ç¨ |
| | | "ITEMS": 327680//对象å
é¨å项起ä½ç¨ï¼æ¯å¦buttonMatrixéçæé®ç» |
| | | } |
| | | //ææ¬è¶
åºæ§ä»¶æ¾ç¤ºçæ¨¡å¼ |
| | | utils.LABEL_LONG_MODE = { |
| | | "WRAP": utils.ENUM.LV_LABEL_LONG_WRAP,//ææ¬é¿çæ¶åæ¢è¡ |
| | | "DOT": utils.ENUM.LV_LABEL_LONG_DOT,//ææ¬é¿çæ¶åç¨...æ¿ä»£ |
| | | "SCROLL": utils.ENUM.LV_LABEL_LONG_SCROLL,//ææ¬é¿çæ¶åèªå¨æ»å¨ |
| | | "SCROLL_CIRCULAR": utils.ENUM.LV_LABEL_LONG_SCROLL_CIRCULAR,//ææ¬é¿çæ¶åå¾ªç¯æ»å¨ |
| | | "CLIP": utils.ENUM.LV_LABEL_LONG_CLIP,//ææ¬é¿çæ¶åèªå¨æªæ |
| | | } |
| | | // å®ç°0-100æ å°ä¸º0-255 |
| | | utils.OPA_MAPPING = function (value) { |
| | | return Math.round((value / 100) * 255); |
| | | } |
| | | /** |
| | | * æ ¡éªæ°åæ¯å¦ä¸ºç©ºï¼æ¯å¦ä¸ºnumber |
| | | * @param {number} n å¿
å¡« |
| | | * @param {err} é误信æ¯ï¼éå¿
å¡«ï¼å¡«äºä¼æåºError |
| | | */ |
| | | utils.validateNumber = function (n, err) { |
| | | return _valid(n, 'number', err) |
| | | } |
| | | /** |
| | | * æ ¡éªå¯¹è±¡æ¯å¦ä¸ºç©ºï¼æ¯å¦ä¸ºobject |
| | | * @param {object} o å¿
å¡« |
| | | * @param {err} é误信æ¯ï¼éå¿
å¡«ï¼å¡«äºä¼æåºError |
| | | */ |
| | | utils.validateObject = function (o, err) { |
| | | return _valid(o, 'object', err) |
| | | } |
| | | /** |
| | | * æ ¡éªui对象çæå»ºåæ° |
| | | * @param {array} all å¿
å¡«,ææå¯¹è±¡å¼ç¨ |
| | | * @param {string} id ä¸è½ä¸ºç©ºï¼å¿
å¡« |
| | | * @param {object} parent éå¿
å¡«ï¼ç¼ºçæ¯0 |
| | | */ |
| | | utils.validateBuild = function (all, id, parent, type) { |
| | | this.validateId(all, id) |
| | | if (parent === 0 || parent === 1 || parent === 2) { |
| | | return parent |
| | | } |
| | | if (!parent || !parent.obj) { |
| | | throw new Error(type + ".build: 'parent' paramter should not be null") |
| | | } |
| | | return parent.obj |
| | | } |
| | | /** |
| | | * æ ¡éªææuiæ§ä»¶çidï¼ä¸è½éå¤ |
| | | * @param {array} all |
| | | * @param {string} id |
| | | */ |
| | | utils.validateId = function (all, id) { |
| | | this.validateString(id, "The 'id' parameter should not be null.") |
| | | if (all[id]) { |
| | | throw new Error("The id(" + id + ") already exists. Please set a different id value.") |
| | | } |
| | | } |
| | | /** |
| | | * æ ¡éªå符串æ¯å¦ä¸ºç©º |
| | | * @param {string} s å¿
å¡« |
| | | * @param {err} é误信æ¯ï¼éå¿
å¡«ï¼å¡«äºä¼æåºError |
| | | */ |
| | | utils.validateString = function (s, err) { |
| | | let res = _valid(s, 'string', err) |
| | | if (!res) { |
| | | return false |
| | | } |
| | | if (s.length <= 0) { |
| | | if (err) { |
| | | throw new Error(err) |
| | | } |
| | | return false |
| | | } |
| | | return true |
| | | } |
| | | /** |
| | | * è§£æä¸åç±»åçé¢è²å¼ |
| | | * @param {any} value æ¯ææ°åç±»åï¼0x34ffaaï¼å符串类å:'0x34ffaa',å符串类å:'#34ffaa' |
| | | * @returns |
| | | */ |
| | | utils.colorParse = function (value) { |
| | | if (typeof value == 'string') { |
| | | value = value.replace('#', '0x') |
| | | value = parseInt(value, 16) |
| | | } |
| | | return value |
| | | } |
| | | /** |
| | | * è·å触æ¸ç¹çåæ |
| | | * @returns {x:æ¨ªåæ ,y:çºµåæ } |
| | | */ |
| | | utils.getTouchPoint = function () { |
| | | let point = NativeObject.APP.NativeComponents.NativeIndev.lvIndevGetPoint() |
| | | return point |
| | | } |
| | | /** |
| | | * æä¾å¨ç» |
| | | * @param {object} obj å¨ç»æä½å¯¹è±¡ï¼å¯ä»¥æ¯ä»»æå¯¹è±¡ï¼åè°åæ°è·å |
| | | * @param {number} start åºé´å¼å§å¼ï¼ä¸è¬åendæé
使ç¨ï¼åè°åæ°è·åï¼startå¨å¨ç»è¿ç¨ååå°end |
| | | * @param {number} end åºé´ç»æå¼ |
| | | * @param {function} cb åè°å½æ°(obj, v)=>{},objå³å¨ç»æä½å¯¹è±¡ï¼åºé´å¼ï¼start-endï¼ |
| | | * @param {number} duration å¨ç»æç»æ¶é´ï¼æ¯«ç§ |
| | | * @param {number} backDuration å¯éï¼å¨ç»åæ¾æ¶é´ï¼æ¯«ç§ï¼ç¼ºçä¸åæ¾ |
| | | * @param {number} repeat å¯éï¼å¨ç»é夿¬¡æ°ï¼ç¼ºç1次 |
| | | * @param {string} mode éçæ²çº¿ï¼å¯éï¼ç¼ºçlinearï¼å
ç½®åè½ï¼linear,ease_in,ease_out,ease_in_out,overshoot,bounce,step |
| | | * linear 线æ§å¨ç» |
| | | step 卿å䏿¥æ´æ¹ |
| | | ease_in å¼å§ç¼æ
¢ |
| | | ease_out æåç¼æ
¢ |
| | | ease_in_out å¨å¼å§åç»ææ¶é½å¾ç¼æ
¢ |
| | | overshoot è¶
åºæç»å¼ |
| | | bounce 仿ç»å¼åå¼¹ä¸ç¹ï¼æ¯å¦æå°å¢ï¼ |
| | | * @returns å¨ç»å®ä¾ï¼ä¸å®å¾ä¿åå°å
¨å± |
| | | */ |
| | | utils.anime = function (obj, start, end, cb, duration, backDuration, repeat, mode) { |
| | | // 1ãåå§åå¨ç» |
| | | let anim = NativeObject.APP.NativeComponents.NativeAnim.lvAnimInit() |
| | | // 2ã设置å¨ç»å¯¹è±¡ |
| | | anim.lvAnimSetVar(obj) |
| | | // 3ã设置起å§åç»æå¼ |
| | | anim.lvAnimSetValues(start, end) |
| | | //4ã设置å¨ç»åè°å½æ° |
| | | anim.lvAnimSetExecCb(cb) |
| | | // 5ã设置å¨ç»æ¶é´ |
| | | anim.lvAnimSetTime(duration) |
| | | // å¯éï¼è®¾ç½®å¨ç»åæ¾æ¶é´ï¼ä¸è®¾ç½®å°±ä¸åæ¾ |
| | | if (backDuration) { |
| | | anim.lvAnimSetPlaybackTime(backDuration) |
| | | } |
| | | // å¯éï¼è®¾ç½®å¨ç»é夿¬¡æ° |
| | | if (repeat) { |
| | | anim.lvAnimSetRepeatCount(repeat) |
| | | } |
| | | // å¯éï¼è®¾ç½®å¨ç»éçæ²çº¿ |
| | | if (mode) { |
| | | anim.lvAnimSetPathCb(mode) |
| | | } |
| | | // 6ãè¿è¡å¨ç» |
| | | anim.lvAnimStart() |
| | | return anim |
| | | } |
| | | //æ¯ä¸ªå¯¹è±¡è®¾ç½®parentåchildren |
| | | utils.setParent = function (all, child, parent) { |
| | | if (!all || parent == null || parent == undefined || !child) { |
| | | return |
| | | } |
| | | if((typeof parent)=='number'){ |
| | | |
| | | } |
| | | const parentId = ((typeof parent)=='number')?'' + parent:parent.id//æ0ï¼1ï¼2转æå符串 |
| | | if (!all[parentId]) { |
| | | all[parentId] = { id: parentId }//æ ¹èç¹0,1,2 |
| | | } |
| | | if (!all[parentId].children) { |
| | | all[parentId].children = [] |
| | | } |
| | | all[parentId].children.push(child.id) |
| | | child.parent = parentId |
| | | all[child.id] = child |
| | | } |
| | | function _valid(n, type, err) { |
| | | if (n === undefined || n === null || (typeof n) != type) { |
| | | if (err) { |
| | | throw new Error(err) |
| | | } |
| | | return false |
| | | } |
| | | return true |
| | | } |
| | | export default utils |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //buildï¼20240314 |
| | | //åºç¡ç©å½¢å¯¹è±¡ 类似divå¯ä»¥å 载任ä½å
¶å®æ§ä»¶ |
| | | import utils from "./uiUtils.js" |
| | | import base from "./uiBase.js" |
| | | let view = {} |
| | | /** |
| | | * å建ä¸ä¸ªviewå è½½å¨ç¶æ§ä»¶å¯¹è±¡ä¸ |
| | | * @param {string} id æ§ä»¶idï¼å¿
å¡« |
| | | * @param {object} parent ç¶å¯¹è±¡ |
| | | * @returns å建å®çview对象 |
| | | */ |
| | | view.build = function (id, parent) { |
| | | let temp = utils.validateBuild(view.all, id, parent, 'view') |
| | | let my = {type: 'view'} |
| | | if (temp === 0 || temp === 1 || temp === 2) { |
| | | my.obj = new utils.GG.NativeBasicComponent({ uid: id }, null, temp) |
| | | } |
| | | else { |
| | | my.obj = new utils.GG.NativeBasicComponent({ uid: id }, temp) |
| | | } |
| | | my.id = id |
| | | let comp = Object.assign(my, base); |
| | | utils.setParent(this.all,comp,parent) |
| | | return comp; |
| | | } |
| | | |
| | | export default view; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //build:20240715 |
| | | //ç¨äºç®åuartç»ä»¶å¾®å
éä¿¡åè®®ç使ç¨ï¼æuartå°è£
å¨è¿ä¸ªworkeréï¼ä½¿ç¨è
åªéè¦è®¢é
eventcenterçäºä»¶å°±å¯ä»¥çå¬uart |
| | | import log from './dxLogger.js' |
| | | import uart from './dxUart.js' |
| | | import common from './dxCommon.js'; |
| | | import dxMap from './dxMap.js' |
| | | import * as os from "os"; |
| | | import std from './dxStd.js' |
| | | const map = dxMap.get('default') |
| | | const id = "{{id}}" |
| | | const options = map.get("__vguart__run_init" + id) |
| | | const timeout = 100 |
| | | const longTimeout = 500 |
| | | |
| | | function run() { |
| | | uart.open(options.type, options.path, options.id) |
| | | log.info('vg uart start......,id =', id) |
| | | std.setInterval(() => { |
| | | try { |
| | | // æ¥æ¶æ°æ®æ¨¡å¼ |
| | | if (options.passThrough) { |
| | | // éä¼ æ¨¡å¼ï¼éé
馿 ¹ä¹ç±» |
| | | passThrough() |
| | | } |
| | | if(options.type == uart.TYPE.USBHID){ |
| | | receiveUsb() |
| | | } else { |
| | | // å¾®å
éä¿¡åè®®æ¨¡å¼ |
| | | receive() |
| | | } |
| | | } catch (error) { |
| | | log.error(error) |
| | | } |
| | | }, 10) |
| | | } |
| | | |
| | | // éä¼ æ¨¡å¼ |
| | | function passThrough() { |
| | | let pack = []; |
| | | let buffer = readOne() |
| | | while (buffer !== null) { |
| | | pack.push(buffer) |
| | | os.sleep(10) |
| | | buffer = readOne() |
| | | } |
| | | if (pack.length !== 0) { |
| | | __bus.fire(uart.VG.RECEIVE_MSG + options.id, pack)//bus.newworkerçæ¶åä¼import eventbus as __bus |
| | | } |
| | | } |
| | | |
| | | function receive() { |
| | | //å2个åèå¿
é¡»æ¯55aa |
| | | let buffer = readOne() |
| | | if (buffer === null) { |
| | | return; |
| | | } |
| | | if (buffer == 85) {//0x55 |
| | | buffer = readOne() |
| | | if (buffer != 170) {//0xaa |
| | | return; |
| | | } |
| | | } else { |
| | | return; |
| | | } |
| | | let pack = {}; |
| | | // 读åå½ä»¤åï¼å ç¨1Byteï¼ |
| | | buffer = readOne() |
| | | if (buffer === null) { |
| | | return; |
| | | } |
| | | pack.cmd = buffer |
| | | if (options.result) { |
| | | // 读åç»æåï¼å ç¨1Byteï¼ |
| | | buffer = readOne() |
| | | if (buffer === null) { |
| | | return; |
| | | } |
| | | pack.result = buffer; |
| | | } else { |
| | | pack.result = 0//0ä¸å½±åbccç计ç®ç»æ |
| | | } |
| | | // å½ä»¤å¤´å·²è§£æå®ï¼è¯»åé¿åº¦åï¼å ç¨2Byteï¼ |
| | | let len1 = readOne() |
| | | if (len1 === null) { |
| | | return; |
| | | } |
| | | let len2 = readOne() |
| | | if (len2 === null) { |
| | | return; |
| | | } |
| | | // è§£æé¿åº¦åï¼è·åæ°æ®åé¿åº¦ |
| | | let len = len1 + len2 * 256 |
| | | // æ ¹æ®é¿åº¦å读åæå®æ°æ®é¿åº¦ |
| | | pack.length = len |
| | | if (len > 0) { |
| | | buffer = uart.receive(len, longTimeout, options.id) |
| | | if (buffer === null) { |
| | | return; |
| | | } |
| | | pack.data = Array.from(buffer); |
| | | } else { |
| | | pack.data = 0 |
| | | } |
| | | // 读å1Byteçæ ¡éªä½ |
| | | buffer = readOne() |
| | | if (buffer === null) { |
| | | return; |
| | | } |
| | | let bcc = valid(pack, buffer) |
| | | let res = { cmd: int2hex(pack.cmd), length: pack.length, bcc: bcc } |
| | | if (pack.length > 0) { |
| | | res.data = common.arrToHex(pack.data) |
| | | } |
| | | if (options.result) { |
| | | res.result = int2hex(pack.result) |
| | | } |
| | | __bus.fire(uart.VG.RECEIVE_MSG + options.id, res)//bus.newworkerçæ¶åä¼import eventbus as __bus |
| | | } |
| | | |
| | | |
| | | function receiveUsb() { |
| | | let arr = uart.receive(1024, 100, options.id) |
| | | if (arr && arr[0] == 0x55 && arr[1] == 0xAA) { |
| | | let cmd = arr[2] |
| | | let dlen = arr[4] * 256 + arr[3] |
| | | if (dlen > (1024 - 6)) { |
| | | let tempLen = dlen - 1024 + 5 |
| | | while(tempLen >= 0){ |
| | | let tempArr = uart.receive(1024, 100, options.id) |
| | | tempLen = tempLen - tempArr.length |
| | | let newArr = new Uint8Array(arr.length + tempArr.length) |
| | | newArr.set(arr) |
| | | newArr.set(tempArr, arr.length) |
| | | arr = newArr |
| | | } |
| | | } |
| | | let data = (dlen == 0 ? [] : Object.values(arr.slice(5, 5 + dlen))) |
| | | let bcc = common.calculateBcc([0x55, 0xAA, arr[2], arr[3], arr[4]].concat(data)) |
| | | data = data.map(v => v.toString(16).padStart(2, '0')).join('') |
| | | if (bcc == arr[5 + dlen]) { |
| | | let res = { "cmd": cmd.toString(16).padStart(2, '0'), "length": dlen, "data": data, "bcc": true } |
| | | __bus.fire(uart.VG.RECEIVE_MSG + options.id, res)//bus.newworkerçæ¶åä¼import eventbus as __bus |
| | | } |
| | | } |
| | | } |
| | | |
| | | function valid(pack, bcc) { |
| | | let temp = common.calculateBcc([0x55, 0xaa, pack.cmd, pack.result, pack.length % 256, Math.floor(pack.length / 256)].concat(pack.data)) |
| | | return temp === bcc |
| | | } |
| | | function readOne() { |
| | | let buffer = uart.receive(1, timeout, options.id) |
| | | if (buffer) { |
| | | return parseInt(buffer); |
| | | } |
| | | return null |
| | | } |
| | | function int2hex(num) { |
| | | return num.toString(16).padStart(2, '0') |
| | | } |
| | | |
| | | try { |
| | | run() |
| | | } catch (error) { |
| | | log.error(error, error.stack) |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | // è¯è¨å
|
| | | const messages = { |
| | | CN: { |
| | | mainView: { |
| | | config: "é
ç½®", |
| | | pwd: "å¯ç ", |
| | | app: "å°ç¨åºç ", |
| | | success: "éè¡æå", |
| | | fail: "éè¡å¤±è´¥", |
| | | passwordDisabled: "å¯ç å·²ç¦ç¨", |
| | | }, |
| | | idleView: { |
| | | week: { |
| | | 0: "卿¥", |
| | | 1: "å¨ä¸", |
| | | 2: "å¨äº", |
| | | 3: "å¨ä¸", |
| | | 4: "å¨å", |
| | | 5: "å¨äº", |
| | | 6: "å¨å
", |
| | | }, |
| | | }, |
| | | appView: { |
| | | knowed: "æå·²ç¥æ", |
| | | appQrcodeLbl: "使ç¨å°ç¨åºä¾¿æ·ç®¡ç", |
| | | }, |
| | | pwdView: { |
| | | title: "å¯ç éè¡", |
| | | pwd: "请è¾å
¥å¯ç ", |
| | | pwdAccess: "确认", |
| | | success: "å¯ç éè¡æå", |
| | | fail: "å¯ç éè¡å¤±è´¥", |
| | | }, |
| | | newPwdView: { |
| | | title: "设置管çå¯ç ", |
| | | pwdAccess: "确认", |
| | | pwd: "请è¾å
¥å¯ç ", |
| | | confirmPwd: "è¯·åæ¬¡è¾å
¥å¯ç ", |
| | | pwdAccess: "确认", |
| | | tip: "注æï¼æ¨è®¾ç½®çå¯ç 使°åºå¤§äºæçäº 8 ä½ï¼å¦è·³è¿è®¾ç½®ï¼è®¾å¤å°éç¨é»è®¤å¯ç ã", |
| | | skip: "è·³è¿ï¼ä»¥å设置", |
| | | success: "å¯ç 设置æå", |
| | | fail: "å¯ç 设置失败", |
| | | pwdNotMatch: "两次è¾å
¥å¯ç ä¸ä¸è´", |
| | | }, |
| | | identityVerificationView: { |
| | | title: "身份éªè¯", |
| | | pwd: "请è¾å
¥ç®¡çå¯ç ", |
| | | pwdAccess: "确认", |
| | | success: "人è¸éªè¯æå", |
| | | fail: "人è¸éªè¯å¤±è´¥", |
| | | pwdLog: "å¯ç ç»å½", |
| | | faceLog: "人è¸ç»å½", |
| | | pwdFail: "å¯ç é误", |
| | | }, |
| | | configView: { |
| | | title: "设置èå", |
| | | localUser: "æ¬å°ç¨æ·", |
| | | networkSetting: "ç½ç»è®¾ç½®", |
| | | doorControl: "é¨ç¦ç®¡ç", |
| | | systemSetting: "ç³»ç»è®¾ç½®", |
| | | deviceInfo: "设å¤ä¿¡æ¯", |
| | | recordQuery: "è®°å½æ¥è¯¢", |
| | | voiceBroadcast: "è¯é³ææ¥", |
| | | cloudCert: "äºè¯åè½", |
| | | factoryTest: "工念è¯", |
| | | help: "使ç¨å¸®å©", |
| | | confirmExit: "确认éåº", |
| | | confirmExitContent: "æ¯å¦ç¡®è®¤éåºè®¾ç½®èåï¼", |
| | | }, |
| | | cloudCertView: { |
| | | title: "äºè¯åè½", |
| | | cloudCertActive: "äºè¯æ¿æ´»", |
| | | inputKey: "请è¾å
¥å¯é¥", |
| | | key: "å¯é¥", |
| | | tip: "注æï¼äºè¯å¯ä»¥éè¿æè¾å¯é¥ææ«æ\nä¸ç¨äºç»´ç æ¿æ´»ï¼è¯¦æ
请è系客æã", |
| | | save: "ä¿å", |
| | | }, |
| | | doorControlView: { |
| | | title: "é¨ç¦ç®¡ç", |
| | | save: "ä¿å", |
| | | openDoorRelayDelay: "å¼é¨ç»§çµå¨å»¶æ¶", |
| | | antiTamperAlarm: "鲿æ¥è¦", |
| | | input: "请è¾å
¥", |
| | | success: "ä¿åæå", |
| | | fail: "ä¿å失败", |
| | | mqttAddr: "MQTTå°å", |
| | | mqttUser: "MQTTè´¦å·", |
| | | mqttPwd: "MQTTå¯ç ", |
| | | onlineChecking: "å¨çº¿éªè¯", |
| | | onlineCheckingTimeout: "å¨çº¿éªè¯è¶
æ¶", |
| | | ms: "毫ç§" |
| | | }, |
| | | helpView: { |
| | | title: "使ç¨å¸®å©", |
| | | scanCode: "æ«ç 访é®å®æ¹æç¨", |
| | | }, |
| | | networkSettingView: { |
| | | title: "ç½ç»è®¾ç½®", |
| | | type: "ç½ç»ç±»å", |
| | | ip: "IP", |
| | | dhcp: "DHCP", |
| | | mask: "åç½æ©ç ", |
| | | gateway: "ç½å
³", |
| | | dns: "DNS1", |
| | | dns2: "DNS2", |
| | | mac: "MAC", |
| | | status: "ç½ç»ç¶æ", |
| | | save: "ä¿å", |
| | | input: "请è¾å
¥", |
| | | ethernet: "以太ç½", |
| | | wifi: "WiFi", |
| | | _4G: "4G", |
| | | networkUnconnected: "ç½ç»æªè¿æ¥", |
| | | networkConnected: "ç½ç»å·²è¿æ¥", |
| | | wifiName: "WiFiåç§°", |
| | | wifiPwd: "WiFiå¯ç ", |
| | | wifiList: "WiFiå表", |
| | | close: "å
³é", |
| | | confirm: "确认", |
| | | fail: "ä¿å失败", |
| | | success: "ä¿åæå", |
| | | }, |
| | | systemSettingView: { |
| | | title: "ç³»ç»è®¾ç½®", |
| | | displaySetting: "æ¾ç¤ºçé¢è®¾ç½®", |
| | | faceRecognitionSetting: "人è¸è¯å«è®¾ç½®", |
| | | swipeCardRecognitionSetting: "å·å¡è¯å«è®¾ç½®", |
| | | passLogSetting: "éè¡æ¥å¿è®¾ç½®", |
| | | passwordOpenDoorSetting: "å¯ç å¼é¨è®¾ç½®", |
| | | passwordManagement: "å¯ç 管ç", |
| | | timeSetting: "æ¶é´è®¾ç½®", |
| | | restartDevice: "éå¯è®¾å¤", |
| | | restoreDefaultConfig: "æ¢å¤é»è®¤é
ç½®", |
| | | resetDevice: "é置设å¤", |
| | | restart: "éå¯", |
| | | restoreDefault: "æ¢å¤", |
| | | reset: "éç½®", |
| | | autoAdjustScreenBrightness: "èªå¨è°èå±å¹äº®åº¦", |
| | | screenBrightness: "å±å¹äº®åº¦", |
| | | autoTurnOffScreen: "èªå¨çå±", |
| | | autoTurnOffScreenTime: "èªå¨ç屿¶é´", |
| | | autoScreenSaver: "èªå¨å±ä¿", |
| | | autoScreenSaverTime: "èªå¨å±ä¿æ¶é´", |
| | | displayIp: "æ¾ç¤ºIPå°å", |
| | | displayDeviceSn: "æ¾ç¤ºè®¾å¤SN", |
| | | language: "è¯è¨", |
| | | displayCode: "æ¾ç¤ºå°ç¨åºç ", |
| | | themeMode: "å·¥ä½ä¸»é¢", |
| | | save: "ä¿å", |
| | | input: "请è¾å
¥", |
| | | faceSimilarityThreshold: "人è¸ç¸ä¼¼åº¦éå¼", |
| | | livenessDetectionFunction: "æ´»ä½æ£æµåè½", |
| | | livenessDetectionThreshold: "æ´»ä½æ£æµéå¼", |
| | | infraredImageDisplay: "红å¤å¾åæ¾ç¤º", |
| | | maskRecognition: "å£ç½©è¯å«", |
| | | maskRecognitionThreshold: "å£ç½©è¯å«éå¼", |
| | | recognitionDistance: "è¯å«è·ç¦»", |
| | | imageSaveType: "å¾åä¿åç±»å", |
| | | saveStrangerImage: "ä¿åéç人å¾å", |
| | | fullView: "å
¨æ¯", |
| | | face: "人è¸", |
| | | swipeCardRecognition: "å·å¡æ ¸éª", |
| | | passwordOpenDoor: "å¯ç å¼é¨", |
| | | inputOriginalPassword: "请è¾å
¥å管çå¯ç ", |
| | | inputNewPassword: "请è¾å
¥æ°å¯ç ", |
| | | inputRepeatNewPassword: "请é夿°å¯ç ", |
| | | syncMode: "æ¶åº", |
| | | ntpAddress: "NTPå°å", |
| | | timeSyncSuccess: "æ¶é´ä¸æå¡å¨åæ¥æå", |
| | | success: "ä¿åæå", |
| | | fail: "ä¿å失败", |
| | | appMode: "APP模å¼", |
| | | confirmation: "确认", |
| | | confirmRestart: "确认éå¯åï¼", |
| | | confirmRecoveryConfiguration: "确认æ¢å¤é»è®¤é
ç½®åï¼", |
| | | confirmReset: "确认éç½®åï¼", |
| | | min: "åé" |
| | | }, |
| | | deviceInfoView: { |
| | | title: "设å¤ä¿¡æ¯", |
| | | systemInfo: "ç³»ç»ä¿¡æ¯", |
| | | dataCapacityInfo: "æ°æ®å®¹éä¿¡æ¯", |
| | | deviceQrCode: "设å¤äºç»´ç ", |
| | | miniProgramCode: "å°ç¨åºç ", |
| | | deviceSN: "设å¤SNå·", |
| | | firmwareVersion: "åºä»¶çæ¬å·", |
| | | firmwareReleaseDate: "åºä»¶å叿¥æ", |
| | | deviceTotalSpace: "è®¾å¤æ»ç©ºé´", |
| | | deviceUsedSpace: "å·²ç¨ç©ºé´", |
| | | deviceRemainingSpace: "å©ä½ç©ºé´", |
| | | registeredPersonNum: "注å人æ°", |
| | | localFaceWhiteListNum: "æ¬å°äººè¸ç½ååæ°é", |
| | | localPasswordWhiteListNum: "æ¬å°å¯ç ç½ååæ°é", |
| | | localSwipeCardWhiteListNum: "æ¬å°å·å¡ç½ååæ°é", |
| | | passLogTotalNum: "éè¡è®°å½æ»æ°", |
| | | updateDevice: "æ´æ°è®¾å¤", |
| | | currentVersion: "å½åå·²ç»æ¯ææ°çæ¬ï¼æ éæ´æ°åºä»¶", |
| | | deviceFreeSpace: "设å¤ç©ºé²ç©ºé´", |
| | | }, |
| | | factoryTestView: { |
| | | title: "工念è¯", |
| | | calibration: "æå头æ å®", |
| | | }, |
| | | localUserView: { |
| | | title: "æ¬å°ç¨æ·", |
| | | empty: "æ¬å°å°æªæ·»å 人åï¼", |
| | | add: "æ°å¢äººå", |
| | | sync: "忥æ¬å°äººåè³å°ç¨åº", |
| | | search: "å§åæID", |
| | | searchBtn: "æç´¢", |
| | | edit: "ç¼è¾", |
| | | attention: "注æ", |
| | | attentionContent: |
| | | "1ã设å¤å°åæ¥è®¾å¤æ¬å°ç人åä¿¡æ¯\nè³å°ç¨åºç审æ¹å表ä¸ï¼æ§è¡æå\nå设å¤ç«¯å°æ¸
é¤å·²ç»å½å
¥ç人åä¿¡\næ¯ã \n2ãä½ä¸ºç®¡çåï¼æ¨å¯ä»¥å¨å°ç¨åºä¸\n对æ¬å°åæ¥ç人åè¿è¡å®¡æ¹ã审æ¹\néè¿å¹¶è¡¥å
å®å¿
è¦çåæ®µåï¼ç»ç»\nå
çå
¨é¨è®¾å¤ï¼å°æ¥ææ¤æ¬¡åæ¥äºº\nåçéè¡æéã\næ¤æä½æ æ³æ¤éï¼è¯·é®æ¨ç¡®å®è¦å\næ¥åï¼", |
| | | tip: "æç¤º", |
| | | tipContent: "设å¤å°æªè¿æ¥ç½ç»ï¼è¯·å
é
ç½®ç½ç»ï¼", |
| | | }, |
| | | recordQueryView: { |
| | | title: "è®°å½æ¥è¯¢", |
| | | code: "人åç¼å·", |
| | | time: "éè¡æ¶é´", |
| | | result: "éè¡ç»æ", |
| | | stranger: "éç人", |
| | | face: "人è¸", |
| | | card: "å·å¡", |
| | | password: "å¯ç ", |
| | | qrcode: "æ«ç ", |
| | | success: "éè¡æå", |
| | | fail: "éè¡å¤±è´¥", |
| | | }, |
| | | recordQueryDetailView: { |
| | | title: "éè¡è®°å½è¯¦æ
", |
| | | id: "第ä¸ç¨æ·ç¼å·", |
| | | name: "第ä¸ç¨æ·å§å", |
| | | idCard: "第ä¸ç¨æ·èº«ä»½è¯å·", |
| | | face: "第ä¸ç¨æ·äººè¸ææ", |
| | | secondId: "第äºç¨æ·ç¼å·", |
| | | secondName: "第äºç¨æ·å§å", |
| | | secondIdCard: "第äºç¨æ·èº«ä»½è¯å·", |
| | | secondFace: "第äºç¨æ·äººè¸ææ", |
| | | time: "éè¡æ¶é´", |
| | | result: "éè¡ç»æ", |
| | | }, |
| | | voiceBroadcastView: { |
| | | title: "è¯é³ææ¥", |
| | | save: "ä¿å", |
| | | strangerVoice: "éç人è¯é³", |
| | | voiceMode: "è¯é³æ¨¡å¼", |
| | | volume: "é³é", |
| | | success: "ä¿åæå", |
| | | fail: "ä¿å失败", |
| | | }, |
| | | confirm: { |
| | | ok: "确认", |
| | | no: "åæ¶", |
| | | upgrade: "设å¤å级", |
| | | upgrading: "æ£å¨å级", |
| | | upgradeSuccess: "å级æå", |
| | | upgradeFail: "å级失败", |
| | | cloudCertActive: "äºè¯æ¿æ´»", |
| | | cloudCertActiveSuccess: "æ¿æ´»æå", |
| | | cloudCertActiveFail: "æ¿æ´»å¤±è´¥", |
| | | restartDevice: "éå¯è®¾å¤", |
| | | restartDeviceDis: "é
ç½®å·²æ´æ°ï¼è®¾å¤å³å°éå¯", |
| | | }, |
| | | localUserAddView: { |
| | | title: "ç¨æ·æ°å¢", |
| | | title2: "ç¨æ·ç¼è¾", |
| | | save: "ä¿å", |
| | | id: "ID", |
| | | name: "人åå§å", |
| | | idCard: "身份è¯å·", |
| | | face: "人è¸åè¯", |
| | | pwd: "å¯ç åè¯", |
| | | card: "å¡çåè¯", |
| | | type: "人åç±»å", |
| | | input: "请è¾å
¥", |
| | | enter: "å½å
¥", |
| | | generate: "çæ", |
| | | edit: "ä¿®æ¹", |
| | | reset: "é设", |
| | | confirm: "确认", |
| | | confirmDelete: "确认å é¤", |
| | | confirmDeleteContent: "æ¯å¦ç¡®è®¤å é¤", |
| | | confirmFace: "确认å é¤äººè¸åè¯åï¼", |
| | | confirmPwd: "确认å é¤å¯ç åè¯åï¼", |
| | | confirmCard: "确认å é¤å¡çåè¯åï¼", |
| | | pwdBoxLbl: "å¯ç çæä¸", |
| | | pwdBoxSaveBtnLbl: "æ¢ä¸ä¸ª", |
| | | pwdBoxConfirmBtnLbl: "ç¡®å®", |
| | | cardBoxResetBtnLbl: "éç½®", |
| | | cardBoxSaveBtnLbl: "ä¿å", |
| | | cardBoxLbl: "读åå¡çä¸", |
| | | cardBoxInput: "请填åç¨æ·å¡å·", |
| | | delete: "å é¤", |
| | | success: "æå", |
| | | fail: "失败", |
| | | requiredInfo: "请å
å¡«åå¿
å¡«ä¿¡æ¯", |
| | | preview: "é¢è§", |
| | | failRepeat: "失败ï¼ç¨æ·IDéå¤", |
| | | failSimilarity: "失败ï¼äººè¸ç¸ä¼¼åº¦è¿é«", |
| | | failCardRepeat: "失败ï¼å¡çéå¤", |
| | | failPwdRepeat: "失败ï¼å¯ç éå¤", |
| | | }, |
| | | faceEnterView: { |
| | | title: "人è¸å½å
¥", |
| | | faceAdd: "人è¸å½å
¥ä¸ï¼è¯·æ£è§æå头", |
| | | recogFace: "è¯å«å°äººè¸", |
| | | recogSuccess: "è¯å«æå", |
| | | faceError: "è¶
æ¶æªè·å", |
| | | }, |
| | | faceService: { |
| | | contrastFailure: "对æ¯å¤±è´¥", |
| | | scalingFailure: "缩æ¾å¤±è´¥", |
| | | failedToSavePicture: "åå¨å¾ç失败", |
| | | convertToBase64Failed: "ç¹å¾å¼è½¬base64失败", |
| | | base64DecodingFailed: "base64è§£ç 失败", |
| | | similarityOverheight: "ç¸ä¼¼åº¦è¿é«", |
| | | fileDoesNotExist: "æä»¶ä¸åå¨", |
| | | theImageFormatIsNotSupported: "å¾çæ ¼å¼ä¸æ¯æ", |
| | | pictureReadFailure: "å¾ç读å失败", |
| | | thePictureSizeDoesNotMatch: "å¾ç尺寸ä¸ç¬¦", |
| | | imageParsingFailure: "å¾çè§£æå¤±è´¥", |
| | | imageYUVProcessingFailed: "å¾çYUVå¤ç失败", |
| | | failedToConvertJpegToImage: "jpeg转image失败", |
| | | faceInformationExtractionFailed: "人è¸ä¿¡æ¯æå失败", |
| | | theFaceIsNotUnique: "å¾çä¸äººè¸ä¿¡æ¯ä¸å¯ä¸", |
| | | } |
| | | }, |
| | | EN: { |
| | | mainView: { |
| | | config: "Settings", |
| | | pwd: "Password", |
| | | app: "Mini Program Code",//å±è½å°ç¨åºç |
| | | success: "Access Granted", |
| | | fail: "Access Denied", |
| | | passwordDisabled: "Password Access Disabled", |
| | | }, |
| | | idleView: { |
| | | week: { |
| | | 0: "Sun", |
| | | 1: "Mon", |
| | | 2: "Tue", |
| | | 3: "Wed", |
| | | 4: "Thu", |
| | | 5: "Fri", |
| | | 6: "Sat", |
| | | }, |
| | | }, |
| | | appView: { |
| | | knowed: "Got it", |
| | | appQrcodeLbl: "Manage with Mini Program", |
| | | }, |
| | | pwdView: { |
| | | title: "Password Access", |
| | | pwd: "Enter Password", |
| | | pwdAccess: "Confirm", |
| | | success: "Access Granted", |
| | | fail: "Access Denied", |
| | | }, |
| | | newPwdView: { |
| | | title: "Set Admin Password", |
| | | pwdAccess: "Confirm", |
| | | pwd: "Enter Password", |
| | | confirmPwd: "Confirm Password", |
| | | pwdAccess: "Confirm", |
| | | tip: "Note: Password must be at least 8 characters long. Default password will be used if skipped.", |
| | | skip: "Skip for Now", |
| | | success: "Password Set Successfully", |
| | | fail: "Failed to Set Password", |
| | | pwdNotMatch: "Passwords Don't Match", |
| | | }, |
| | | identityVerificationView: { |
| | | title: "Identity Verification", |
| | | pwd: "Enter Admin Password", |
| | | pwdAccess: "Confirm", |
| | | success: "Face Verification Successful", |
| | | fail: "Face Verification Failed", |
| | | pwdLog: "Password Login", |
| | | faceLog: "Face Login", |
| | | pwdFail: "Wrong Password", |
| | | }, |
| | | configView: { |
| | | title: "Settings", |
| | | localUser: "Local Users", |
| | | networkSetting: "Network", |
| | | doorControl: "Access Control", |
| | | systemSetting: "System", |
| | | deviceInfo: "Device Info", |
| | | recordQuery: "Access Logs", |
| | | voiceBroadcast: "Voice Settings", |
| | | cloudCert: "Cloud Certificate", |
| | | factoryTest: "Factory Test", |
| | | help: "Help", |
| | | confirmExit: "Exit Settings", |
| | | confirmExitContent: "Are you sure you want to exit Settings?", |
| | | }, |
| | | cloudCertView: { |
| | | title: "Cloud Certificate", |
| | | cloudCertActive: "Activate Certificate", |
| | | inputKey: "Enter Key", |
| | | key: "Key", |
| | | tip: "Note: Activate using key or QR code scan. Contact support for details.", |
| | | save: "Save", |
| | | }, |
| | | doorControlView: { |
| | | title: "Access Control", |
| | | save: "Save", |
| | | openDoorRelayDelay: "Door Release Delay", |
| | | antiTamperAlarm: "Tamper Alarm", |
| | | input: "Enter", |
| | | success: "Saved", |
| | | fail: "Save Failed", |
| | | mqttAddr: "MQTT Server", |
| | | mqttUser: "MQTT Username", |
| | | mqttPwd: "MQTT Password", |
| | | onlineChecking: "Online Verification", |
| | | onlineCheckingTimeout: "Verification Timeout", |
| | | ms: "ms" |
| | | }, |
| | | helpView: { |
| | | title: "Help", |
| | | scanCode: "Scan for Tutorial", |
| | | }, |
| | | networkSettingView: { |
| | | title: "Network", |
| | | type: "Connection Type", |
| | | ip: "IP Address", |
| | | dhcp: "DHCP", |
| | | mask: "Subnet Mask", |
| | | gateway: "Gateway", |
| | | dns: "Primary DNS", |
| | | dns2: "Secondary DNS", |
| | | mac: "MAC Address", |
| | | status: "Status", |
| | | save: "Save", |
| | | input: "Enter", |
| | | ethernet: "Ethernet", |
| | | wifi: "Wi-Fi", |
| | | _4G: "4G", |
| | | networkUnconnected: "Disconnected", |
| | | networkConnected: "Connected", |
| | | wifiName: "Network Name", |
| | | wifiPwd: "Password", |
| | | wifiList: "Available Networks", |
| | | close: "Close", |
| | | confirm: "Confirm", |
| | | fail: "Save Failed", |
| | | success: "Saved", |
| | | }, |
| | | systemSettingView: { |
| | | title: "System Settings", |
| | | displaySetting: "Display", |
| | | faceRecognitionSetting: "Face Recognition", |
| | | swipeCardRecognitionSetting: "Card Access", |
| | | passLogSetting: "Access Logs", |
| | | passwordOpenDoorSetting: "Password Access", |
| | | passwordManagement: "Password Management", |
| | | timeSetting: "Date & Time", |
| | | restartDevice: "Restart", |
| | | restoreDefaultConfig: "Reset to Default", |
| | | resetDevice: "Factory Reset", |
| | | restart: "Restart", |
| | | restoreDefault: "Reset", |
| | | reset: "Reset", |
| | | autoAdjustScreenBrightness: "Auto Brightness", |
| | | screenBrightness: "Brightness", |
| | | autoTurnOffScreen: "Auto Screen Off", |
| | | autoTurnOffScreenTime: "Screen Off Timer", |
| | | autoScreenSaver: "Screen Saver", |
| | | autoScreenSaverTime: "Screen Saver Timer", |
| | | displayIp: "Show IP Address", |
| | | displayDeviceSn: "Show Device SN", |
| | | language: "Language", |
| | | displayCode: "Show Program Code", |
| | | themeMode: "Work Theme", |
| | | save: "Save", |
| | | input: "Enter", |
| | | faceSimilarityThreshold: "Face Match Threshold", |
| | | livenessDetectionFunction: "Liveness Detection", |
| | | livenessDetectionThreshold: "Liveness Threshold", |
| | | infraredImageDisplay: "IR Display", |
| | | maskRecognition: "Mask Detection", |
| | | maskRecognitionThreshold: "Mask Detection Threshold", |
| | | recognitionDistance: "Detection Range", |
| | | imageSaveType: "Image Storage Type", |
| | | saveStrangerImage: "Save Stranger Photos", |
| | | fullView: "Full View", |
| | | face: "Face Only", |
| | | swipeCardRecognition: "Card Verification", |
| | | passwordOpenDoor: "Password Access", |
| | | inputOriginalPassword: "Enter Current Password", |
| | | inputNewPassword: "Enter New Password", |
| | | inputRepeatNewPassword: "Confirm New Password", |
| | | syncMode: "Time Zone", |
| | | ntpAddress: "NTP Server", |
| | | timeSyncSuccess: "Time Synced Successfully", |
| | | success: "Saved", |
| | | fail: "Failed", |
| | | confirmation: "Confirm", |
| | | confirmRestart: "Confirm Restart?", |
| | | confirmRecoveryConfiguration: "Reset to Default Settings?", |
| | | confirmReset: "Confirm Factory Reset?", |
| | | min: "min" |
| | | }, |
| | | deviceInfoView: { |
| | | title: "Device Info", |
| | | systemInfo: "System Info", |
| | | dataCapacityInfo: "Storage Info", |
| | | deviceQrCode: "Device QR Code", |
| | | miniProgramCode: "Mini Program Code", |
| | | deviceSN: "Serial Number", |
| | | firmwareVersion: "Firmware Version", |
| | | firmwareReleaseDate: "Release Date", |
| | | deviceTotalSpace: "Total Storage", |
| | | deviceUsedSpace: "Used Storage", |
| | | deviceRemainingSpace: "Available Storage", |
| | | registeredPersonNum: "Registered Users", |
| | | localFaceWhiteListNum: "Face Whitelist Count", |
| | | localPasswordWhiteListNum: "Password Whitelist Count", |
| | | localSwipeCardWhiteListNum: "Card Whitelist Count", |
| | | passLogTotalNum: "Total Access Logs", |
| | | updateDevice: "Update Device", |
| | | currentVersion: "Device is up to date", |
| | | deviceFreeSpace: "Free Space", |
| | | }, |
| | | factoryTestView: { |
| | | title: "Factory Test", |
| | | calibration: "Camera Calibration", |
| | | appMode: "APP Mode", |
| | | }, |
| | | localUserView: { |
| | | title: "Local Users", |
| | | empty: "No Users Added", |
| | | add: "Add User", |
| | | sync: "Sync to Mini Program", |
| | | search: "Search by Name or ID", |
| | | searchBtn: "Search", |
| | | edit: "Edit", |
| | | attention: "Notice", |
| | | attentionContent: |
| | | "1. Local user data will be synced to the Mini Program approval list. After successful sync, local user data will be cleared.\n2. As an admin, you can approve synced users in the Mini Program. Once approved and required fields are completed, users will have access to all organization devices.\nThis action cannot be undone. Continue?", |
| | | tip: "Note", |
| | | tipContent: "Please connect to network first", |
| | | }, |
| | | recordQueryView: { |
| | | title: "Access Logs", |
| | | code: "User ID", |
| | | time: "Time", |
| | | result: "Result", |
| | | stranger: "Unknown", |
| | | face: "Face", |
| | | card: "Card", |
| | | password: "Password", |
| | | success: "Granted", |
| | | fail: "Denied", |
| | | }, |
| | | recordQueryDetailView: { |
| | | title: "Access Log Details", |
| | | id: "User ID", |
| | | name: "Name", |
| | | idCard: "ID Number", |
| | | face: "First Face Photo", |
| | | secondId: "Second User ID", |
| | | secondName: "Second Name", |
| | | secondIdCard: "Second ID Number", |
| | | secondFace: "Second Face Photo", |
| | | time: "Access Time", |
| | | result: "Result", |
| | | }, |
| | | voiceBroadcastView: { |
| | | title: "Voice Settings", |
| | | save: "Save", |
| | | strangerVoice: "Stranger Alert", |
| | | voiceMode: "Voice Mode", |
| | | volume: "Volume", |
| | | success: "Saved", |
| | | fail: "Save Failed", |
| | | }, |
| | | confirm: { |
| | | ok: "OK", |
| | | no: "Cancel", |
| | | upgrade: "Update Device", |
| | | upgrading: "Updating...", |
| | | upgradeSuccess: "Update Complete", |
| | | upgradeFail: "Update Failed", |
| | | cloudCertActive: "Activate Certificate", |
| | | cloudCertActiveSuccess: "Activate Success", |
| | | cloudCertActiveFail: "Activate Failed", |
| | | restartDevice: "Restart Device", |
| | | restartDeviceDis: "Configuration updated, device will restart", |
| | | }, |
| | | localUserAddView: { |
| | | title: "Add User", |
| | | title2: "Edit User", |
| | | save: "Save", |
| | | id: "ID", |
| | | name: "Name", |
| | | idCard: "ID Number", |
| | | face: "Face ID", |
| | | pwd: "Password", |
| | | card: "Access Card", |
| | | type: "User Type", |
| | | input: "Enter", |
| | | enter: "Add", |
| | | generate: "Generate", |
| | | edit: "Edit", |
| | | reset: "Reset", |
| | | confirm: "Confirm", |
| | | confirmDelete: "Confirm Delete", |
| | | confirmDeleteContent: "Delete this item?", |
| | | confirmFace: "Delete Face ID?", |
| | | confirmPwd: "Delete Password?", |
| | | confirmCard: "Delete Access Card?", |
| | | pwdBoxLbl: "Generating...", |
| | | pwdBoxSaveBtnLbl: "Generate New", |
| | | pwdBoxConfirmBtnLbl: "OK", |
| | | cardBoxResetBtnLbl: "Reset", |
| | | cardBoxSaveBtnLbl: "Save", |
| | | cardBoxLbl: "Reading Card...", |
| | | cardBoxInput: "Enter Card Number", |
| | | delete: "Delete", |
| | | success: "Success", |
| | | fail: "Failed", |
| | | requiredInfo: "Required Fields Missing", |
| | | preview: "Preview", |
| | | failRepeat: "ID Already Exists", |
| | | failSimilarity: "Face Too Similar", |
| | | failCardRepeat: "Card Already Exists", |
| | | failPwdRepeat: "Password Already Exists", |
| | | }, |
| | | faceEnterView: { |
| | | title: "Face Enrollment", |
| | | faceAdd: "Look at Camera", |
| | | recogFace: "Face Detected", |
| | | recogSuccess: "Enrollment Complete", |
| | | faceError: "No Face Detected", |
| | | }, |
| | | calibrationView: { |
| | | firstCalibration: "Initial Calibration", |
| | | secondCalibration: "Secondary Calibration" |
| | | }, |
| | | faceService: { |
| | | contrastFailure: "Comparison Failed", |
| | | scalingFailure: "Scaling Failed", |
| | | failedToSavePicture: "Failed to Save Image", |
| | | convertToBase64Failed: "Base64 Conversion Failed", |
| | | base64DecodingFailed: "Base64 Decode Failed", |
| | | similarityOverheight: "Face Too Similar", |
| | | fileDoesNotExist: "File Not Found", |
| | | theImageFormatIsNotSupported: "Unsupported Image Format", |
| | | pictureReadFailure: "Failed to Read Image", |
| | | thePictureSizeDoesNotMatch: "the picture size does not match", |
| | | imageParsingFailure: "image parsing failure", |
| | | imageYUVProcessingFailed: "image yuv processing failed", |
| | | failedToConvertJpegToImage: "failed to convert jpeg to image", |
| | | faceInformationExtractionFailed: "face information extraction failed", |
| | | theFaceIsNotUnique: "the face is not unique", |
| | | } |
| | | }, |
| | | }; |
| | | |
| | | export default messages; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | |
| | | /** |
| | | * é
置常éæä»¶ |
| | | * å®ä¹ç³»ç»ä¸ææé
置项çé®å¼æ å° |
| | | * ç¨äºç»ä¸ç®¡çé
置项çè·¯å¾ï¼æ¹ä¾¿å¨ç³»ç»ä¸å¼ç¨ |
| | | */ |
| | | const configConst = {} |
| | | |
| | | /** |
| | | * é
置项æ å°è¡¨ |
| | | * å
å«ç³»ç»ææå¯é
置项çé®å¼å¯¹ |
| | | * é®ä¸ºé
置项åç§°ï¼å¼ä¸ºé
置项å¨é
ç½®æä»¶ä¸çè·¯å¾ |
| | | */ |
| | | configConst.setConfig = { |
| | | // åºç¡é
ç½® |
| | | language: "base.language", // è¯è¨è®¾ç½®ï¼CN/EN |
| | | password: "base.password", // 管çåå¯ç |
| | | screenOff: "base.screenOff", // ç屿¶é´ï¼åä½åéï¼0表示ä»ä¸ |
| | | screensaver: "base.screensaver", // å±å¹ä¿æ¤ï¼åä½åéï¼0表示ä»ä¸ |
| | | brightness: "base.brightness", // å±å¹äº®åº¦ |
| | | brightnessAuto: "base.brightnessAuto", // èªå¨äº®åº¦å¼å
³ |
| | | volume: "base.volume", // é³é设置 |
| | | showIp: "base.showIp", // æ¯å¦æ¾ç¤ºIPå°å |
| | | showSn: "base.showSn", // æ¯å¦æ¾ç¤ºåºåå· |
| | | showProgramCode: "base.showProgramCode", // æ¯å¦æ¾ç¤ºç¨åºä»£ç |
| | | showIdentityCard: "base.showIdentityCard", // æ¯å¦æ¾ç¤ºèº«ä»½è¯ä¿¡æ¯ |
| | | appMode: "base.appMode", // åºç¨æ¨¡å¼ |
| | | luminanceWhite: "base.luminanceWhite", // ç½å
亮度 |
| | | luminanceNir: "base.luminanceNir", // 红å¤å
亮度 |
| | | |
| | | // 人è¸è¯å«é
ç½® |
| | | similarity: "face.similarity", // 人è¸è¯å«ç¸ä¼¼åº¦éå¼ |
| | | livenessOff: "face.livenessOff", // æ´»ä½æ£æµå¼å
³ |
| | | livenessVal: "face.livenessVal", // æ´»ä½æ£æµéå¼ |
| | | showNir: "face.showNir", // æ¯å¦æ¾ç¤ºçº¢å¤å¾å |
| | | detectMask: "face.detectMask", // æ¯å¦æ£æµå£ç½© |
| | | stranger: "face.stranger", // éç人è¯é³æç¤ºï¼["æ è¯é³", "ææ¾è¯·å
注å", "ææ¾éçäººä½ å¥½"] |
| | | voiceMode: "face.voiceMode", // è¯é³æ¨¡å¼ï¼["æ è¯é³", "ææ¾åå", "ææ¾é®åè¯"] |
| | | voiceModeDate: "face.voiceModeDate", // è¯é³æ¨¡å¼æ¥æè®¾ç½® |
| | | |
| | | // MQTTé
ç½® |
| | | addr: "mqtt.addr", // MQTTæå¡å¨å°å |
| | | mqttclientId: "mqtt.clientId", // MQTT客æ·ç«¯ID |
| | | mqttusername: "mqtt.username", // MQTTç¨æ·å |
| | | mqttpassword: "mqtt.password", // MQTTå¯ç |
| | | mqttqos: "mqtt.qos", // MQTT QoSçº§å« |
| | | mqttprefix: "mqtt.prefix", // MQTT主é¢åç¼ |
| | | onlinecheck: "mqtt.onlinecheck", // å¨çº¿æ£æ¥å¼å
³ |
| | | timeout: "mqtt.timeout", // MQTTè¿æ¥è¶
æ¶ |
| | | willTopic: "mqtt.willTopic", // MQTTéå±ä¸»é¢ |
| | | |
| | | // ç½ç»é
ç½® |
| | | type: "net.type", // ç½ç»ç±»å |
| | | ssid: "net.ssid", // WiFi SSID |
| | | psk: "net.psk", // WiFiå¯ç |
| | | dhcp: "net.dhcp", // DHCPå¼å
³ |
| | | ip: "net.ip", // IPå°å |
| | | gateway: "net.gateway", // ç½å
³å°å |
| | | mask: "net.mask", // åç½æ©ç |
| | | dns: "net.dns", // DNSæå¡å¨ |
| | | mac: "net.mac", // MACå°å |
| | | |
| | | // NTPæ¶é´åæ¥é
ç½® |
| | | ntp: "ntp.ntp", // NTPå¼å
³ |
| | | server: "ntp.server", // NTPæå¡å¨å°å |
| | | ntpInterval: "ntp.interval", // NTP忥é´é |
| | | gmt: "ntp.gmt", // GMTæ¶åºè®¾ç½® |
| | | |
| | | // ç³»ç»é
ç½® |
| | | version: "sys.version", // ç³»ç»çæ¬ |
| | | appVersion: "sys.appVersion", // åºç¨çæ¬ |
| | | releaseTime: "sys.releaseTime", // å叿¶é´ |
| | | heart_en: "sys.heart_en", // å¿è·³å¼å
³ï¼1å¼ 0å
³ |
| | | heart_time: "sys.heart_time", // å¿è·³é´é |
| | | nfc: "sys.nfc", // å·å¡å¼å
³ï¼1å¼ 0å
³ |
| | | pwd: "sys.pwd", // å¯ç å¼é¨å¼å
³ï¼1å¼ 0å
³ |
| | | emergencyPwd: "sys.emergencyPwd", // åºæ¥å¼ä»å¯ç |
| | | interval: "sys.interval", // ç³»ç»é´é设置 |
| | | strangerImage: "sys.strangerImage", // éç人ä¿åå¾çå¼å
³ï¼1å¼ 0å
³ |
| | | accessImageType: "sys.accessImageType", // éè¡å¾çç±»åï¼1äººè¸ 0å
¨æ¯ |
| | | com_passwd: "sys.com_passwd", // é
ç½®ç å¯ç æ ¡éª |
| | | nfcIdentityCardEnable: "sys.nfcIdentityCardEnable", // äºè¯å¼å
³ï¼3äºè¯è·å 1ç©çå¡å· |
| | | |
| | | // é¨ç¦é
ç½® |
| | | offlineAccessNum: "access.offlineAccessNum", // 离线å¼é¨æ¬¡æ° |
| | | relayTime: "access.relayTime", // ç»§çµå¨å¨ä½æ¶é´ |
| | | tamperAlarm: "access.tamperAlarm" // 鲿æ¥è¦å¼å
³ |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®é®è·åé
ç½®é¡¹è·¯å¾ |
| | | * @param {string} key - é
置项åç§° |
| | | * @returns {string|undefined} é
置项å¨é
ç½®æä»¶ä¸çè·¯å¾ï¼å¦æä¸åå¨åè¿åundefined |
| | | */ |
| | | configConst.getValueByKey = function (key) { |
| | | return this.setConfig[key] || undefined; |
| | | } |
| | | |
| | | export default configConst |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | /** |
| | | * å·¥å
·å½æ°æ¨¡å |
| | | * æä¾ç³»ç»å¸¸ç¨çå·¥å
·å½æ°ï¼å
æ¬æä»¶ä¸è½½ãå符串å¤çãç³»ç»æä½ç |
| | | */ |
| | | import * as os from "os" |
| | | import common from '../../../dxmodules/dxCommon.js' |
| | | import logger from "../../../dxmodules/dxLogger.js" |
| | | const utils = {} |
| | | |
| | | /** |
| | | * è·åURLæä»¶çä¸è½½å¤§å°ï¼åèæ°ï¼ |
| | | * @param {string} url - æä»¶çURLå°å |
| | | * @returns {number} æä»¶å¤§å°ï¼åèï¼ï¼å¦æè·å失败åè¿å0 |
| | | */ |
| | | utils.getUrlFileSize = function (url) { |
| | | // 使ç¨wgetå½ä»¤è·åæä»¶å¤§å°ä¿¡æ¯ |
| | | let actualSize = common.systemWithRes(`wget --spider -S ${url} 2>&1 | grep 'Length' | awk '{print $2}'`, 100).match(/\d+/g) |
| | | return actualSize ? parseInt(actualSize) : 0 |
| | | } |
| | | |
| | | /** |
| | | * 夿弿¯å¦ä¸ºç©ºï¼ç©ºå符串ãnullæundefinedï¼ |
| | | * @param {*} str - è¦å¤æçå¼ |
| | | * @returns {boolean} 妿å¼ä¸ºç©ºåè¿åtrueï¼å¦åè¿åfalse |
| | | */ |
| | | utils.isEmpty = function (str) { |
| | | return (str === "" || str === null || str === undefined) |
| | | } |
| | | |
| | | /** |
| | | * è§£æå符串为JSON对象 |
| | | * 注æï¼valueå
ä¸è½æ"å· |
| | | * @param {string} inputString - è¦è§£æçåç¬¦ä¸²ï¼æ ¼å¼ä¸º{key1=value1, key2=value2} |
| | | * @returns {Object} è§£æåçJSON对象 |
| | | */ |
| | | utils.parseString = function (inputString) { |
| | | // è·å{}åå
¶ä¹é´çå
容 |
| | | inputString = inputString.slice(inputString.indexOf("{"), inputString.lastIndexOf("}") + 1) |
| | | // key=valueæ£åï¼keyæ¯\w+ï¼åæ¯æ°åä¸å线ï¼åºå«å¤§å°åï¼ï¼=ä¸¤è¾¹å¯æç©ºæ ¼ï¼valueæ¯\w+æç¸é»ä¸¤ä¸ª"ä¹é´çå
容ï¼å
å«"ï¼ |
| | | const keyValueRegex = /(\w+)\s*=\s*("[^"]*"|\w+(\.\w+)?)/g; |
| | | let jsonObject = {}; |
| | | let match; |
| | | |
| | | // éåå¹é
ç»æï¼æå»ºJSON对象 |
| | | while ((match = keyValueRegex.exec(inputString)) !== null) { |
| | | let key = match[1]; |
| | | let value = match[2] |
| | | |
| | | // æ ¹æ®å¼çç±»åè¿è¡è½¬æ¢ |
| | | if (/^\d+$/.test(value)) { |
| | | // æ°åç±»å |
| | | value = parseInt(value) |
| | | } else if (/^\d+\.\d+$/.test(value)) { |
| | | // å°æ°ç±»å |
| | | value = parseFloat(value) |
| | | } else if (value == 'true') { |
| | | // å¸å°å¼true |
| | | value = true |
| | | } else if (value == 'false') { |
| | | // å¸å°å¼false |
| | | value = false |
| | | } else { |
| | | // å符串类åï¼å»é¤å¼å·åç©ºæ ¼ |
| | | value = value.replace(/"/g, '').trim() |
| | | } |
| | | |
| | | jsonObject[key] = value; |
| | | } |
| | | |
| | | return jsonObject; |
| | | } |
| | | |
| | | /** |
| | | * çå¾
æä»¶ä¸è½½å®æå¹¶è¿è¡MD5æ ¡éª |
| | | * 注æï¼è¶
æ¶æ¶é´ä¸å¾è¶
è¿åçæ¶é´ï¼å¦åä¸è½½æ
¢ä¼å¯¼è´ç³»ç»éå¯ |
| | | * @param {string} update_addr - ä¸è½½å°å |
| | | * @param {string} downloadPath - åå¨è·¯å¾ |
| | | * @param {number} timeout - è¶
æ¶æ¶é´ï¼æ¯«ç§ï¼ |
| | | * @param {string} update_md5 - MD5æ ¡éªå¼ |
| | | * @param {number} fileSize - æä»¶å¤§å°ï¼åèï¼ |
| | | * @returns {boolean} ä¸è½½ç»æï¼true表示æåï¼false表示失败 |
| | | */ |
| | | utils.waitDownload = function (update_addr, downloadPath, timeout, update_md5, fileSize) { |
| | | // å é¤åæä»¶ |
| | | common.systemBrief(`rm -rf "${downloadPath}"`) |
| | | |
| | | // 弿¥ä¸è½½æä»¶ |
| | | common.systemBrief(`wget -c "${update_addr}" -O "${downloadPath}" &`) |
| | | |
| | | let startTime = new Date().getTime() |
| | | |
| | | // å¾ªç¯æ£æ¥ä¸è½½è¿åº¦ |
| | | while (true) { |
| | | // 计ç®å·²ä¸è½½çæä»¶å¤§å° |
| | | let size = parseInt(common.systemWithRes(`file="${downloadPath}"; [ -e "$file" ] && wc -c "$file" | awk '{print $1}' || echo "0"`, 100).split(/\s/g)[0]) |
| | | |
| | | // 妿æä»¶å¤§å°è¾¾å°é¢æï¼è¿è¡MD5æ ¡éª |
| | | if (size == fileSize) { |
| | | let ret = common.md5HashFile(downloadPath) |
| | | if (ret) { |
| | | let md5 = ret.map(v => v.toString(16).padStart(2, '0')).join('') |
| | | if (md5 == update_md5) { |
| | | // MD5æ ¡éªæå |
| | | return true |
| | | } |
| | | } |
| | | // MD5æ ¡éªå¤±è´¥ï¼å 餿件 |
| | | common.systemBrief(`rm -rf "${downloadPath}"`) |
| | | return false |
| | | } |
| | | // 妿ä¸è½½è¶
æ¶ï¼å é¤ä¸è½½çæä»¶å¹¶ä¸éå¯ï¼åæ¢å¼æ¥ç»§ç»ä¸è½½ |
| | | if (new Date().getTime() - startTime > timeout) { |
| | | vf203.pwm.fail() |
| | | common.systemBrief(`rm -rf "${downloadPath}"`) |
| | | // ç«å³éå¯ |
| | | this.restart() |
| | | return false |
| | | } |
| | | |
| | | // æå100毫ç§åç»§ç»æ£æ¥ |
| | | os.sleep(100) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * ç«å³éå¯ |
| | | */ |
| | | utils.restart = function () { |
| | | common.systemBrief("reboot -f") |
| | | } |
| | | |
| | | export default utils |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | { |
| | | // CN/EN |
| | | "base.language": "CN", |
| | | // 管çåå¯ç |
| | | "base.password": "1", |
| | | //æ¯å¦ç¬¬ä¸æ¬¡ç»å½åå° 0 æªç»å½ 1 å·²ç»å½ |
| | | "base.firstLogin": 0, |
| | | // 人è¸è¯å«ç¸ä¼¼åº¦ |
| | | "face.similarity": 0.6, |
| | | // æ´»ä½æ£æµ |
| | | "face.livenessOff": 0, |
| | | // æ´»ä½æ£æµéå¼ï¼0-100ï¼ |
| | | "face.livenessVal": 0, |
| | | "face.showNir": 0, |
| | | "face.detectMask": 0, |
| | | // ["æ è¯é³", "ææ¾è¯·å
注å", "ææ¾éçäººä½ å¥½"] |
| | | "face.stranger": 1, |
| | | // ["æ è¯é³", "ææ¾åå", "ææ¾é®åè¯"] |
| | | "face.voiceMode": 1, |
| | | "face.voiceModeDate": "欢è¿å
临", |
| | | "mqtt.addr": "192.168.1.78:1883", |
| | | "mqtt.clientId": "", |
| | | "mqtt.username": "admin", |
| | | "mqtt.password": "123456", |
| | | "mqtt.qos": 1, |
| | | "mqtt.prefix": "", |
| | | "mqtt.onlinecheck": 0, |
| | | "mqtt.timeout": 5000, |
| | | "mqtt.willTopic": "access_device/v2/event/offline", |
| | | "net.type": 2, |
| | | "net.ssid": "", |
| | | "net.psk": "Fzzy@#$432..K", |
| | | "net.dhcp": 1, |
| | | "net.ip": "192.168.1.188", |
| | | "net.gateway": "192.168.1.1", |
| | | "net.mask": "255.255.255.0", |
| | | "net.dns": "218.4.4.4,218.2.2.2", |
| | | "net.mac": "", |
| | | // 0å
³éï¼1宿¶åæ¥ |
| | | "ntp.ntp": 2, |
| | | "ntp.server": "192.168.1.78", |
| | | // 宿¶åæ¥ï¼24å°æ¶å¶ |
| | | "ntp.hour": 3, |
| | | "ntp.gmt": 8, |
| | | // macå°å |
| | | "sys.mac": "", |
| | | "sys.uuid": "", |
| | | "sys.sn": "", |
| | | "sys.model": "vf105", |
| | | "sys.version": "", |
| | | "sys.appVersion": "vf105_v11_access_2.0.0", |
| | | "sys.releaseTime": "2024-09-13 09:52:00", |
| | | "sys.heart_en": 0, //å¿è·³1å¼ 0 å
³ |
| | | "sys.heart_time": 30, |
| | | "sys.nfc": 1, //1å¼ 0 å
³ å·å¡å¼å
³ |
| | | "sys.pwd": 1, //1å¼ 0 å
³ å¯ç å¼é¨å¼å
³ |
| | | "sys.strangerImage": 1, //1å¼ 0 å
³ éç人ä¿åå¾çå¼å
³ |
| | | "sys.accessImageType": 1, //1äººè¸ 0 å
¨æ¯ éè¡å¾çç±»å |
| | | "sys.com_passwd": "1234567887654321", // é
ç½®ç å¯ç æ ¡éª |
| | | //äºè¯å¼å
³ 3:äºè¯è·å 1:ç©çå¡å· |
| | | "sys.nfcIdentityCardEnable": 1, |
| | | "sys.interval": 1000, //æ«ç é´é模å¼é´éæ¶é´ |
| | | "access.offlineAccessNum": 2000, |
| | | "access.relayTime": 2000, |
| | | "access.tamperAlarm": 1, |
| | | // ç屿¶é´ï¼åä½åéï¼0ä»ä¸ |
| | | "base.screenOff": 5, |
| | | // å±å¹ä¿æ¤ï¼åä½åéï¼0ä»ä¸ |
| | | "base.screensaver": 5, |
| | | //å±å¹äº®åº¦ |
| | | "base.brightness": 70, |
| | | //èªå¨è°è亮度 1 èªå¨è°è |
| | | "base.brightnessAuto": 1, |
| | | //é³é |
| | | "base.volume": 80, |
| | | // ip æ¾ç¤º 1 æ¾ç¤º 0 éè |
| | | "base.showIp": 0, |
| | | // sn æ¾ç¤º 1 æ¾ç¤º 0 éè |
| | | "base.showSn": 0, |
| | | //å°ç¨åºç æ¾ç¤º 1 æ¾ç¤º 0 éè |
| | | "base.showProgramCode": 0, |
| | | //äºè¯åè½èå æ¾ç¤º 1 æ¾ç¤º 0 éè |
| | | "base.showIdentityCard": 0, |
| | | // 0: æ 忍¡å¼ 1: ç®çº¦æ¨¡å¼ |
| | | "base.appMode": 1, |
| | | // ç½è²è¡¥å
ç¯äº®åº¦ |
| | | "base.luminanceWhite": 80, |
| | | // 红å¤è¡¥å
ç¯äº®åº¦ |
| | | "base.luminanceNir": 80, |
| | | // 0:wifi çæ¬ 1:4Gçæ¬ 2:以太ç½çæ¬ é»è®¤ 3æªè¯»åç¶æ |
| | | "sys.devType": 0, |
| | | // ä¸å¡ç¼ç å®ä¹ï¼FunctionIdï¼ |
| | | "functionId": { |
| | | "gasDetection": "1000", |
| | | "safeInputControl": "2000", |
| | | "lightControl": "3000" |
| | | }, |
| | | // æ¥å£è¿åç¼ç ï¼respCodeï¼ |
| | | "respCode": { |
| | | "success": "200", |
| | | "badRequest": "400", |
| | | "unauthorized": "401", |
| | | "forbidden": "403", |
| | | "notFound": "404", |
| | | "serverError": "500" |
| | | }, |
| | | // ä»å»åç§° |
| | | "houseName": "01å·ä»", |
| | | // åºåºåç§° |
| | | "GranaryName": "ä¸å¤®å¨å¤ç²®ææç´å±åº", |
| | | // HTTPæ¥å£è·¯å¾ |
| | | "http": { |
| | | "safeInputAccess": "http://192.168.1.119:80/cgi-bin/safeInputAccess" |
| | | } |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | /** |
| | | * æ§å¶å¨æä»¶ |
| | | * è´è´£å®ææ§è¡ç³»ç»å驱å¨çå¾ªç¯æä½ï¼ç¡®ä¿ç³»ç»æ£å¸¸è¿è¡ |
| | | */ |
| | | import log from '../dxmodules/dxLogger.js' |
| | | import std from '../dxmodules/dxStd.js' |
| | | import face from '../dxmodules/dxFace.js' |
| | | import bus from '../dxmodules/dxEventBus.js' |
| | | import driver from './driver.js' |
| | | |
| | | /** |
| | | * è¿è¡æ§å¶å¨ |
| | | * 设置å¤ä¸ªå®æ¶å¨ï¼å®ææ§è¡ä¸åç循ç¯ä»»å¡ |
| | | */ |
| | | function run() { |
| | | // æ¯5msæ§è¡ä¸æ¬¡ä¸»å¾ªç¯ |
| | | std.setInterval(() => { |
| | | try { |
| | | driver.watchdog.feed("controller", 30) // åçï¼è®¾ç½®30ç§è¶
æ¶ |
| | | loop() // æ§è¡ä¸»å¾ªç¯ |
| | | } catch (error) { |
| | | log.error(error) // è®°å½é误 |
| | | } |
| | | }, 5) |
| | | |
| | | // æ¯500msæ§è¡ä¸æ¬¡ç½ç»å¾ªç¯ |
| | | std.setInterval(() => { |
| | | try { |
| | | driver.watchdog.feed("controller1", 30) // åçï¼è®¾ç½®30ç§è¶
æ¶ |
| | | driver.net.loop() // æ§è¡ç½ç»å¾ªç¯ |
| | | } catch (error) { |
| | | log.error(error) // è®°å½é误 |
| | | } |
| | | }, 500) |
| | | |
| | | // æ¯1000msæ§è¡ä¸æ¬¡NTPå¾ªç¯ |
| | | std.setInterval(() => { |
| | | try { |
| | | driver.watchdog.feed("controller2", 30) // åçï¼è®¾ç½®30ç§è¶
æ¶ |
| | | driver.ntp.loop() // æ§è¡NTPå¾ªç¯ |
| | | } catch (error) { |
| | | log.error(error) // è®°å½é误 |
| | | } |
| | | }, 1000) |
| | | } |
| | | |
| | | /** |
| | | * å¯å¨æ§å¶å¨ |
| | | */ |
| | | try { |
| | | run() |
| | | } catch (error) { |
| | | log.error(error) |
| | | } |
| | | |
| | | /** |
| | | * 主循ç¯å½æ° |
| | | * æ§è¡å驱å¨çå¾ªç¯æä½ |
| | | */ |
| | | function loop() { |
| | | driver.capturer.loop() // æ§è¡æåå¤´å¾ªç¯ |
| | | driver.face.loop() // æ§è¡äººè¸è¯å«å¾ªç¯ |
| | | driver.nfc.loop() // æ§è¡NFCå¾ªç¯ |
| | | driver.mqtt.heartbeat() // æ§è¡MQTTå¿è·³ |
| | | driver.gpiokey.loop() // æ§è¡GPIOæé®å¾ªç¯ |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | /** |
| | | * 驱卿¨¡åæä»¶ |
| | | * å
å«ç³»ç»ææç¡¬ä»¶é©±å¨çåå§ååæä½æ¹æ³ï¼æ¯ç³»ç»ä¸ç¡¬ä»¶äº¤äºçæ ¸å¿æ¨¡å |
| | | */ |
| | | import * as os from "os" |
| | | import capturer from '../dxmodules/dxCapturer.js' |
| | | import cameraCalibration from '../dxmodules/dxCameraCalibration.js' |
| | | import face from '../dxmodules/dxFace.js' |
| | | import std from '../dxmodules/dxStd.js' |
| | | import common from '../dxmodules/dxCommon.js' |
| | | import utils from './common/utils/utils.js' |
| | | import alsa from '../dxmodules/dxAlsa.js' |
| | | import config from '../dxmodules/dxConfig.js' |
| | | import pwm from '../dxmodules/dxPwm.js' |
| | | import net from '../dxmodules/dxNet.js' |
| | | import ntp from '../dxmodules/dxNtp.js' |
| | | import mqtt from '../dxmodules/dxMqtt.js' |
| | | import dxMap from '../dxmodules/dxMap.js' |
| | | import logger from '../dxmodules/dxLogger.js' |
| | | import sqliteService from "./service/sqliteService.js" |
| | | import mqttService from "./service/mqttService.js" |
| | | import gpio from "../dxmodules/dxGpio.js" |
| | | import map from "../dxmodules/dxMap.js" |
| | | import eid from "../dxmodules/dxEid.js" |
| | | import nfc from "../dxmodules/dxNfc.js" |
| | | import bus from "../dxmodules/dxEventBus.js" |
| | | import dxUart from "../dxmodules/dxUart.js" |
| | | import watchdog from "../dxmodules/dxWatchdog.js" |
| | | import base64 from "../dxmodules/dxBase64.js" |
| | | import dxGpioKey from "../dxmodules/dxGpioKey.js" |
| | | import dxDriver from "../dxmodules/dxDriver.js" |
| | | const driver = {} |
| | | |
| | | /** |
| | | * é³é¢é©±å¨æ¨¡å |
| | | * è´è´£é³é¢ææ¾åè¯é³åæ |
| | | */ |
| | | driver.alsa = alsa |
| | | |
| | | /** |
| | | * é
ç½®é©±å¨æ¨¡å |
| | | * è´è´£åå§åç³»ç»é
ç½®ï¼è®¾ç½®ç³»ç»åºæ¬ä¿¡æ¯ |
| | | */ |
| | | driver.config = { |
| | | /** |
| | | * åå§åé
ç½® |
| | | * åå§åé
置模åï¼è®¾ç½®ç³»ç»MACãUUIDãSNçåºæ¬ä¿¡æ¯ |
| | | */ |
| | | init: function () { |
| | | config.init() |
| | | let mac = common.getUuid2mac(19) |
| | | let uuid = common.getSn(19) |
| | | if (!config.get('sys.mac') && mac) { |
| | | config.set('sys.mac', mac) |
| | | } |
| | | if (!config.get('sys.uuid') && uuid) { |
| | | config.set('sys.uuid', uuid) |
| | | } |
| | | //妿 sn 为空å
ç¨è®¾å¤ uuid |
| | | if (!config.get('sys.sn') && uuid) { |
| | | config.set('sys.sn', uuid) |
| | | } |
| | | if (!config.get('mqtt.clientId') && uuid) { |
| | | config.set('mqtt.clientId', uuid) |
| | | } |
| | | config.save() |
| | | } |
| | | } |
| | | /** |
| | | * å±å¹é©±å¨æ¨¡å |
| | | * è´è´£å±å¹ç¸å
³çäºä»¶è§¦ååæä½ |
| | | */ |
| | | driver.screen = { |
| | | /** |
| | | * éè¡å¤±è´¥ |
| | | * 触åéè¡å¤±è´¥äºä»¶ |
| | | */ |
| | | accessFail: function () { |
| | | bus.fire('accessRes', false) |
| | | }, |
| | | |
| | | /** |
| | | * éè¡æå |
| | | * 触åéè¡æåäºä»¶ |
| | | */ |
| | | accessSuccess: function () { |
| | | bus.fire('accessRes', true) |
| | | }, |
| | | |
| | | /** |
| | | * å级 |
| | | * 触åå级äºä»¶ |
| | | * @param {object} data - åçº§æ°æ® |
| | | */ |
| | | upgrade: function (data) { |
| | | bus.fire('upgrade', data) |
| | | }, |
| | | |
| | | /** |
| | | * è·åå¡ç |
| | | * ææ¾è¯»å¡å£°é³å¹¶è§¦åè·åå¡çäºä»¶ |
| | | * @param {string} card - å¡çä¿¡æ¯ |
| | | */ |
| | | getCard: function (card) { |
| | | driver.alsa.play(`/app/code/resource/${config.get("base.language") == "CN" ? "CN" : "EN"}/wav/read.wav`) |
| | | bus.fire('getCard', card) |
| | | }, |
| | | |
| | | /** |
| | | * éèSN |
| | | * 触åéèSNäºä»¶ |
| | | * @param {object} data - äºä»¶æ°æ® |
| | | */ |
| | | hideSn: function (data) { |
| | | bus.fire('hideSn', data) |
| | | }, |
| | | |
| | | /** |
| | | * åºç¨æ¨¡å¼ |
| | | * 触ååºç¨æ¨¡å¼äºä»¶ |
| | | * @param {object} data - æ¨¡å¼æ°æ® |
| | | */ |
| | | appMode: function (data) { |
| | | bus.fire('appMode', data) |
| | | }, |
| | | |
| | | /** |
| | | * éèIP |
| | | * 触åéèIPäºä»¶ |
| | | * @param {object} data - äºä»¶æ°æ® |
| | | */ |
| | | hideIp: function (data) { |
| | | bus.fire('hideIp', data) |
| | | }, |
| | | |
| | | /** |
| | | * 忢è¯è¨ |
| | | * 触åè¯è¨åæ¢äºä»¶ |
| | | */ |
| | | changeLanguage: function () { |
| | | bus.fire('changeLanguage') |
| | | } |
| | | } |
| | | /** |
| | | * SQLite驱卿¨¡å |
| | | * è´è´£æ°æ®åºåå§åå管ç |
| | | */ |
| | | driver.sqlite = { |
| | | /** |
| | | * åå§åæ°æ®åº |
| | | * ç¡®ä¿æ°æ®åºè·¯å¾åå¨å¹¶åå§åSQLiteæå¡ |
| | | */ |
| | | init: function () { |
| | | std.ensurePathExists('/app/data/db/app.db') |
| | | sqliteService.init('/app/data/db/app.db') |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * PWM驱卿¨¡å |
| | | * è´è´£æ§å¶è¡¥å
ç¯ç亮度 |
| | | */ |
| | | driver.pwm = { |
| | | /** |
| | | * åå§åPWM |
| | | * åå§åç½è²è¡¥å
ç¯å红å¤è¡¥å
ç¯çPWMéé |
| | | */ |
| | | init: function () { |
| | | // ç½ç¯ |
| | | let luminanceWhite = config.get('base.luminanceWhite') ?? 80 |
| | | pwm.request(dxDriver.PWM.WHITE_SUPPLEMENT_CHANNEL); |
| | | pwm.setPeriodByChannel(dxDriver.PWM.WHITE_SUPPLEMENT_CHANNEL, dxDriver.PWM.WHITE_SUPPLEMENT_PERIOD_NS) |
| | | pwm.enable(dxDriver.PWM.WHITE_SUPPLEMENT_CHANNEL, true); |
| | | pwm.setDutyByChannel(dxDriver.PWM.WHITE_SUPPLEMENT_CHANNEL, dxDriver.PWM.WHITE_SUPPLEMENT_PERIOD_NS - (dxDriver.PWM.WHITE_SUPPLEMENT_PERIOD_NS * (luminanceWhite / 100))) |
| | | // çº¢å¤ |
| | | let luminanceNir = config.get('base.luminanceNir') ?? 80 |
| | | pwm.request(dxDriver.PWM.NIR_SUPPLEMENT_CHANNEL); |
| | | pwm.setPeriodByChannel(dxDriver.PWM.NIR_SUPPLEMENT_CHANNEL, dxDriver.PWM.NIR_SUPPLEMENT_PERIOD_NS) |
| | | pwm.enable(dxDriver.PWM.NIR_SUPPLEMENT_CHANNEL, true); |
| | | pwm.setDutyByChannel(dxDriver.PWM.NIR_SUPPLEMENT_CHANNEL, dxDriver.PWM.NIR_SUPPLEMENT_PERIOD_NS - (dxDriver.PWM.NIR_SUPPLEMENT_PERIOD_NS * (luminanceNir / 100))) |
| | | }, |
| | | |
| | | /** |
| | | * è°èç½è²è¡¥å
ç¯äº®åº¦ |
| | | * @param {number} value - 亮度å¼ï¼èå´0-100 |
| | | */ |
| | | luminanceWhite: function (value) { |
| | | if (value < 0 || value > 100) { |
| | | logger.error("[driver.pwm]: value should be between 0 and 100") |
| | | return |
| | | } |
| | | pwm.setDutyByChannel(dxDriver.PWM.WHITE_SUPPLEMENT_CHANNEL, dxDriver.PWM.WHITE_SUPPLEMENT_PERIOD_NS - (dxDriver.PWM.WHITE_SUPPLEMENT_PERIOD_NS * (value / 100))) |
| | | }, |
| | | |
| | | /** |
| | | * è°è红å¤è¡¥å
ç¯äº®åº¦ |
| | | * @param {number} value - 亮度å¼ï¼èå´0-100 |
| | | */ |
| | | luminanceNir: function (value) { |
| | | if (value < 0 || value > 100) { |
| | | logger.error("[driver.pwm]: value should be between 0 and 100") |
| | | return |
| | | } |
| | | pwm.setDutyByChannel(dxDriver.PWM.NIR_SUPPLEMENT_CHANNEL, dxDriver.PWM.NIR_SUPPLEMENT_PERIOD_NS - (dxDriver.PWM.NIR_SUPPLEMENT_PERIOD_NS * (value / 100))) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * ALSA驱卿¨¡å |
| | | * è´è´£é³é¢ææ¾åé³éæ§å¶ |
| | | */ |
| | | driver.alsa = { |
| | | /** |
| | | * åå§åé³é¢ |
| | | * åå§åALSAé³é¢æ¨¡å并设置é³é |
| | | */ |
| | | init: function () { |
| | | alsa.init() |
| | | this.volume(config.get("base.volume")) |
| | | }, |
| | | |
| | | /** |
| | | * ææ¾é³é¢æä»¶ |
| | | * @param {string} src - é³é¢æä»¶è·¯å¾ |
| | | */ |
| | | play: function (src) { |
| | | alsa.play(src) |
| | | }, |
| | | |
| | | /** |
| | | * ææ¬è½¬è¯é³ææ¾ |
| | | * @param {string} text - è¦ææ¾çææ¬ |
| | | */ |
| | | ttsPlay: function (text) { |
| | | alsa.ttsPlay(text) |
| | | }, |
| | | |
| | | /** |
| | | * è·åæè®¾ç½®é³é |
| | | * @param {number} [volume] - é³éå¼ï¼èå´1-100 |
| | | * @returns {number} å½åé³éå¼ï¼å½æªæä¾åæ°æ¶ï¼ |
| | | */ |
| | | volume: function (volume) { |
| | | if (volume === undefined || volume === null) { |
| | | return alsa.getVolume() |
| | | } else { |
| | | function mapScore(input) { |
| | | // ç¡®ä¿è¾å
¥å¼å¨1-100ä¹é´ |
| | | if (input < 1 || input > 100) { |
| | | throw new Error('è¾å
¥å¼å¿
é¡»å¨1å°100ä¹é´'); |
| | | } |
| | | if (input < 60 && input > 30) { |
| | | input = input * 1.2 |
| | | } |
| | | if (input < 30 && input > 1) { |
| | | input = input * 2 |
| | | } |
| | | return input |
| | | } |
| | | alsa.setVolume(mapScore(volume)) |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æå头驱卿¨¡å |
| | | * è´è´£æå头çåå§ååæä½ï¼å
æ¬å½©è²æå头åçº¢å¤æå头 |
| | | */ |
| | | driver.capturer = { |
| | | /** |
| | | * å½©è²æå头é
ç½® |
| | | */ |
| | | options1: { |
| | | id: "rgb", |
| | | path: dxDriver.CAPTURER.RGB_PATH, |
| | | width: dxDriver.CAPTURER.RGB_WIDTH, |
| | | height: dxDriver.CAPTURER.RGB_HEIGHT, |
| | | preview_width: dxDriver.CAPTURER.RGB_HEIGHT, |
| | | preview_height: dxDriver.CAPTURER.RGB_WIDTH, |
| | | preview_mode: 2, |
| | | preview_screen_index: 0 // å
å顺åºï¼æ°åè¶å¤§è¶å¨åé¢ |
| | | }, |
| | | |
| | | /** |
| | | * çº¢å¤æå头é
ç½® |
| | | */ |
| | | options2: { |
| | | id: "nir", |
| | | path: dxDriver.CAPTURER.NIR_PATH, |
| | | width: dxDriver.CAPTURER.NIR_WIDTH, |
| | | height: dxDriver.CAPTURER.NIR_HEIGHT, |
| | | preview_width: 150, |
| | | preview_height: 200, |
| | | preview_mode: 1, |
| | | preview_left: 605, |
| | | preview_top: 80, |
| | | preview_screen_index: 1 // å
å顺åºï¼æ°åè¶å¤§è¶å¨åé¢ |
| | | }, |
| | | |
| | | /** |
| | | * åå§åæå头 |
| | | * åå§åå½©è²æå头åçº¢å¤æå头 |
| | | */ |
| | | init: function () { |
| | | capturer.worker.beforeLoop(this.options1) |
| | | capturer.worker.beforeLoop(this.options2) |
| | | |
| | | this.showNir(config.get("face.showNir")) |
| | | }, |
| | | |
| | | /** |
| | | * æ¾ç¤ºæéèçº¢å¤æå头é¢è§ |
| | | * @param {boolean} enable - æ¯å¦å¯ç¨çº¢å¤æå头é¢è§ |
| | | */ |
| | | showNir: function (enable) { |
| | | capturer.capturerEnable(enable, this.options2.id) |
| | | }, |
| | | |
| | | /** |
| | | * å°å¾çæ°æ®è½¬æ¢ä¸ºå¾å |
| | | * @param {string} base64Data - Base64ç¼ç çå¾çæ°æ® |
| | | * @returns {number} å¾åID |
| | | */ |
| | | pictureDataToImage: function (base64Data) { |
| | | return capturer.pictureDataToImage(base64Data, base64Data.length, 1) |
| | | }, |
| | | |
| | | /** |
| | | * å°å¾åä¿å为æä»¶ |
| | | * @param {number} imageId - å¾åID |
| | | * @param {string} savePath - ä¿åè·¯å¾ |
| | | * @returns {boolean} æ¯å¦ä¿åæå |
| | | */ |
| | | imageToPictureFile: function (imageId, savePath) { |
| | | return capturer.imageToPictureFile(imageId, 1, 0, 24, savePath) |
| | | }, |
| | | |
| | | /** |
| | | * å°å¾åä¿å为æä»¶ï¼é«è´¨éï¼ |
| | | * @param {number} imageId - å¾åID |
| | | * @param {string} savePath - ä¿åè·¯å¾ |
| | | * @returns {boolean} æ¯å¦ä¿åæå |
| | | */ |
| | | imageToPictureFile2: function (imageId, savePath) { |
| | | return capturer.imageToPictureFile(imageId, 1, 0, 100, savePath) |
| | | }, |
| | | |
| | | /** |
| | | * è°æ´å¾åå辨ç |
| | | * @param {number} imageId - å¾åID |
| | | * @param {number} width - ç®æ 宽度 |
| | | * @param {number} height - ç®æ é«åº¦ |
| | | * @returns {number} è°æ´åçå¾åID |
| | | */ |
| | | imageResizeResolution: function (imageId, width, height) { |
| | | return capturer.imageResizeResolution(imageId, width, height, 0) |
| | | }, |
| | | |
| | | /** |
| | | * æåå¤´å¾ªç¯ |
| | | * æ§è¡æå头çå¾ªç¯æä½ |
| | | */ |
| | | loop: function () { |
| | | capturer.worker.loop(this.options1) |
| | | capturer.worker.loop(this.options2) |
| | | } |
| | | } |
| | | /** |
| | | * NFC驱卿¨¡å |
| | | * è´è´£NFCå¡çç读ååå¤ç |
| | | */ |
| | | driver.nfc = { |
| | | /** |
| | | * NFCé
ç½®é项 |
| | | */ |
| | | options: { m1: true, psam: false }, |
| | | |
| | | /** |
| | | * åå§åNFC |
| | | * åå§åNFC模åï¼æ ¹æ®é
ç½®å³å®æ¯å¦å¯ç¨ |
| | | */ |
| | | init: function () { |
| | | if (!config.get('sys.nfc')) { |
| | | logger.debug("å·å¡å·²å
³é") |
| | | return |
| | | } |
| | | this.options.useEid = config.get("sys.nfcIdentityCardEnable") == 3 ? 1 : 0 |
| | | nfc.worker.beforeLoop(this.options) |
| | | }, |
| | | |
| | | /** |
| | | * åå§åEIDï¼çµå身份è¯ï¼ |
| | | * æ´æ°EIDé
ç½® |
| | | */ |
| | | eidInit: function () { |
| | | if (!config.get('sys.nfc')) { |
| | | return |
| | | } |
| | | if (config.get("sys.nfcIdentityCardEnable") == 3) { |
| | | nfc.eidUpdateConfig({ appid: "1621503", sn: config.get("sys.sn"), device_model: config.get("sys.appVersion") }) |
| | | } |
| | | }, |
| | | |
| | | /** |
| | | * NFCå¾ªç¯ |
| | | * æ§è¡NFCçå¾ªç¯æä½ï¼æ ¹æ®é
ç½®å³å®æ¯å¦å¯ç¨ |
| | | */ |
| | | loop: function () { |
| | | if (!config.get('sys.nfc')) { |
| | | this.loop = () => { } |
| | | } else { |
| | | this.loop = () => nfc.worker.loop(this.options) |
| | | } |
| | | } |
| | | } |
| | | /** |
| | | * 人è¸è¯å«é©±å¨æ¨¡å |
| | | * è´è´£äººè¸è¯å«ã注ååç¸å
³åè½ç管ç |
| | | */ |
| | | driver.face = { |
| | | /** |
| | | * åå§å人è¸è¯å« |
| | | * åå§åäººè¸æ¨¡åï¼è®¾ç½®ç¸å
³åæ°åé
ç½® |
| | | */ |
| | | init: function () { |
| | | common.systemBrief('mkdir -p /app/data/user/temp/') |
| | | let options = { |
| | | dbPath: "/app/data/db/face.db", |
| | | rgbPath: "/dev/video3", |
| | | nirPath: "/dev/video0", |
| | | capturerRgbId: "rgb", |
| | | capturerNirId: "nir", |
| | | dbMax: 5000, //äººè¸æ³¨åä¸é |
| | | score: config.get("face.similarity"), |
| | | picPath: "/app/data/user/temp", |
| | | gThumbnailHeight: 1280 / 6, |
| | | gThumbnailWidth: 800 / 6, |
| | | // æ¯å¦å¼å¯éæ£ |
| | | recgFaceattrEnable: 1, |
| | | // æ´»ä½å¼å
³ |
| | | livingCheckEnable: config.get("face.livenessOff"), |
| | | // æ´»ä½æ£æµéå¼ |
| | | livingScore: config.get("face.livenessVal"), |
| | | // å£ç½©æ£æµå¼å
³ |
| | | detectMaskEnable: config.get("face.detectMask"), |
| | | // 鿣é´é |
| | | recheckIntervalTime: 5000, |
| | | // æ£æµè¶
æ¶ |
| | | detectTimeoutTime: 1000 |
| | | } |
| | | face.worker.beforeLoop(options) |
| | | |
| | | // é»è®¤ä¸ºäººè¸è¯å«æ¨¡å¼ |
| | | this.mode(0) |
| | | // å
³éææäººè¸åè½ |
| | | this.status(false) |
| | | |
| | | // å±å¹äº®åº¦ |
| | | this.setDisplayBacklight(config.get("base.brightness")) |
| | | |
| | | this.screenStatus(1) |
| | | |
| | | // è¡¥å
ç¯ç¶æè·è¸ª |
| | | let isLightOn = true |
| | | |
| | | // å±å¹äº®åº¦èªå¨è°è |
| | | std.setInterval(() => { |
| | | // çå±å¤æ |
| | | let screenOff = map.get("screenOff") |
| | | if (screenOff.get("status") == 1) { |
| | | this.setDisplayBacklight(0) |
| | | this.screenStatus(0) |
| | | // å
³éè¡¥å
ç¯ï¼ä»
å½è¡¥å
ç¯å½åæ¯å¼å¯ç¶ææ¶ï¼ |
| | | if (isLightOn) { |
| | | driver.pwm.luminanceWhite(0) |
| | | driver.pwm.luminanceNir(0) |
| | | logger.info("[driver.face]: çå±ï¼å
³éè¡¥å
ç¯") |
| | | isLightOn = false |
| | | } |
| | | } |
| | | |
| | | // 忢çå± |
| | | if (screenOff.get("status") != 1) { |
| | | if (config.get("base.brightnessAuto") == 1) { |
| | | // èªå¨è°èå±å¹äº®åº¦ |
| | | let brightness = Math.floor(face.getEnvBrightness() / 10) |
| | | brightness = brightness > 100 ? 100 : brightness |
| | | this.setDisplayBacklight(brightness) |
| | | } else { |
| | | this.setDisplayBacklight(config.get("base.brightness")) |
| | | } |
| | | // å¼å¯è¡¥å
ç¯ï¼ä»
å½è¡¥å
ç¯å½åæ¯å
³éç¶ææ¶ï¼ |
| | | if (!isLightOn) { |
| | | let luminanceWhite = config.get('base.luminanceWhite') ?? 80 |
| | | let luminanceNir = config.get('base.luminanceNir') ?? 80 |
| | | driver.pwm.luminanceWhite(luminanceWhite) |
| | | driver.pwm.luminanceNir(luminanceNir) |
| | | logger.info(`[driver.face]: éåºçå±ï¼å¼å¯è¡¥å
ç¯ï¼ç½ç¯: ${luminanceWhite}%, 红å¤: ${luminanceNir}%ï¼`) |
| | | isLightOn = true |
| | | } |
| | | } |
| | | }, 1000) |
| | | }, |
| | | |
| | | /** |
| | | * è·å人è¸è·è¸ªæ¡ |
| | | * @returns {object} è·è¸ªæ¡ä¿¡æ¯ |
| | | */ |
| | | getTrackingBox: function () { |
| | | return face.getTrackingBox() |
| | | }, |
| | | |
| | | /** |
| | | * 人è¸è¯å«å¾ªç¯ |
| | | * æ§è¡äººè¸è¯å«çå¾ªç¯æä½ |
| | | */ |
| | | loop: function () { |
| | | // æ£æ¥å±å¹æ¯å¦å¤äºçå±ç¶æ |
| | | let screenOff = map.get("screenOff") |
| | | if (screenOff && screenOff.get("status") == 1) { |
| | | // çå±ç¶æä¸ä¸è¿è¡äººè¸è¯å« |
| | | return |
| | | } |
| | | face.worker.loop() |
| | | }, |
| | | |
| | | /** |
| | | * 人è¸çº¿ç¨å¯ç¨å¼å
³ |
| | | * @param {boolean} flag - æ¯å¦å¯ç¨äººè¸æ£æµ |
| | | */ |
| | | status: function (flag) { |
| | | console.log('---äººè¸æ£æµ' + (flag ? 'å¼å¯' : 'æå') + '---'); |
| | | face.faceSetEnable(flag) |
| | | }, |
| | | |
| | | /** |
| | | * 设置人è¸è¯å«æ¨¡å¼ |
| | | * @param {number} value - 模å¼å¼ï¼0为è¯å«æ¨¡å¼ï¼1ä¸ºæ³¨åæ¨¡å¼ |
| | | */ |
| | | mode: function (value) { |
| | | console.log('---人è¸' + (value ? '注å' : 'è¯å«') + '模å¼---'); |
| | | face.setRecgMode(value) |
| | | }, |
| | | |
| | | /** |
| | | * äººè¸æ³¨å |
| | | * @param {string} id - ç¨æ·ID |
| | | * @param {string} feature - 人è¸ç¹å¾ |
| | | * @returns {boolean} æ¯å¦æ³¨åæå |
| | | */ |
| | | reg: function (id, feature) { |
| | | return face.addFaceFeatures(id, feature); |
| | | }, |
| | | |
| | | /** |
| | | * æ´æ°äººè¸é
ç½® |
| | | * @param {object} options - é
ç½®é项 |
| | | */ |
| | | faceUpdateConfig: function (options) { |
| | | console.log("æ´æ°äººè¸é
ç½®", JSON.stringify(options)); |
| | | face.faceUpdateConfig(options) |
| | | }, |
| | | |
| | | /** |
| | | * 设置å±å¹äº®åº¦ |
| | | * @param {number} brightness - äº®åº¦å¼ |
| | | */ |
| | | setDisplayBacklight: function (brightness) { |
| | | brightness = brightness < 2 ? 2 : brightness |
| | | face.setDisplayBacklight(brightness) |
| | | }, |
| | | |
| | | /** |
| | | * éè¿å¾çæä»¶æ³¨åäººè¸ |
| | | * @param {string} userId - ç¨æ·ID |
| | | * @param {string} picPath - å¾çè·¯å¾ |
| | | * @returns {boolean} æ¯å¦æ³¨åæå |
| | | */ |
| | | registerFaceByPicFile: function (userId, picPath) { |
| | | return face.registerFaceByPicFile(userId, picPath) |
| | | }, |
| | | |
| | | /** |
| | | * æ¸
ç©ºäººè¸æ°æ® |
| | | * @returns {boolean} æ¯å¦æ¸
空æå |
| | | */ |
| | | clean: function () { |
| | | // æ¸
空人è¸ï¼éè¦å¨åå§å人è¸ç»ä»¶ä¹åæè½æ§è¡ï¼å¦åæ¥é |
| | | face.faceFeaturesClean() |
| | | common.systemBrief("rm -rf /app/data/db/face.db") |
| | | return !std.exist("/app/data/db/face.db") |
| | | }, |
| | | |
| | | /** |
| | | * å 餿å®ç¨æ·çäººè¸æ°æ® |
| | | * @param {string} userId - ç¨æ·ID |
| | | * @returns {boolean} æ¯å¦å 餿å |
| | | */ |
| | | delete: function (userId) { |
| | | return face.deleteFaceFeatures(userId) |
| | | }, |
| | | |
| | | /** |
| | | * 设置å±å¹ç¶æ |
| | | * @param {boolean} status - æ¯å¦å¯ç¨å±å¹ |
| | | */ |
| | | screenStatus: function (status) { |
| | | if (status) { |
| | | face.setPowerMode(0) |
| | | } else { |
| | | face.setPowerMode(1) |
| | | } |
| | | face.setEnableStatus(status) |
| | | }, |
| | | |
| | | /** |
| | | * å°æä»¶è½¬æ¢ä¸ºbase64ç¼ç |
| | | * @param {string} filePath - æä»¶è·¯å¾ |
| | | * @returns {string} Base64ç¼ç çæä»¶å
容 |
| | | */ |
| | | fileToBase64: function (filePath) { |
| | | function fileToUint8Array(filename) { |
| | | // 读åæä»¶ |
| | | const file = std.open(filename, "rb"); |
| | | if (!file) { |
| | | throw new Error("æ æ³æå¼æä»¶"); |
| | | } |
| | | |
| | | // è·åæä»¶å¤§å° |
| | | const size = std.seek(file, 0, std.SEEK_END) |
| | | std.seek(file, 0, std.SEEK_SET) |
| | | |
| | | // æ£æ¥æä»¶å¤§å°æ¯å¦ææ |
| | | if (size <= 0) { |
| | | std.close(file); |
| | | throw new Error("æä»¶å¤§å°æ æ"); |
| | | } |
| | | |
| | | // å建 ArrayBuffer 并读åæä»¶å
容 |
| | | const buffer = new ArrayBuffer(size); |
| | | const array = new Uint8Array(buffer); |
| | | std.read(file, array.buffer, 0, size); |
| | | |
| | | std.close(file); |
| | | |
| | | return array; |
| | | } |
| | | |
| | | try { |
| | | // æ£æ¥æä»¶è·¯å¾æ¯å¦åå¨ |
| | | if (!filePath) { |
| | | throw new Error("æä»¶è·¯å¾ä¸ºç©º"); |
| | | } |
| | | const data = fileToUint8Array(filePath); |
| | | return base64.fromUint8Array(data); |
| | | } catch (error) { |
| | | logger.info("æä»¶è½¬Base64失败: " + error.message); |
| | | return ""; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * ç½ç»é©±å¨æ¨¡å |
| | | * è´è´£ç½ç»è¿æ¥å管ç |
| | | */ |
| | | driver.net = { |
| | | /** |
| | | * åå§åç½ç» |
| | | * åå§åç½ç»æ¨¡åï¼è®¾ç½®ç½ç»é
ç½® |
| | | */ |
| | | init: function () { |
| | | let dns = config.get("net.dns").split(",") |
| | | let option = { |
| | | type: config.get("net.type"), |
| | | dhcp: config.get("net.dhcp"), |
| | | ip: config.get("net.ip"), |
| | | gateway: config.get("net.gateway"), |
| | | netmask: config.get("net.mask"), |
| | | dns0: dns[0], |
| | | dns1: dns[1], |
| | | macAddr: common.getUuid2mac() |
| | | } |
| | | logger.info("æ´æ°èç½é
ç½®ï¼", JSON.stringify(option)); |
| | | net.worker.beforeLoop(option) |
| | | config.set("net.mac", common.getUuid2mac()) |
| | | if (config.get("net.type") == 2) { |
| | | //wifiåé
ç½®æä»¶å»è¿æ¥ |
| | | let ssid = utils.isEmpty(config.get('net.ssid')) ? "ssid" : config.get('net.ssid') |
| | | let psk = utils.isEmpty(config.get('net.psk')) ? "psk" : config.get('net.psk') |
| | | driver.net.netConnectWifiSsid(ssid, psk) |
| | | } |
| | | // è§£å³ç½ç»åæ¢ç¶æä¸å¯¹ |
| | | std.setInterval(() => { |
| | | let status = net.getStatus() |
| | | if (status.status != map.get("NET").get("status")) { |
| | | status.type = config.get("net.type") |
| | | bus.fire(net.STATUS_CHANGE, status) |
| | | } |
| | | }, 1000) |
| | | }, |
| | | |
| | | /** |
| | | * 忢ç½ç»ç±»å |
| | | * 忢ç½ç»ç±»åå¹¶é
ç½®ç¸åºçç½ç»åæ° |
| | | */ |
| | | changeNetType: function () { |
| | | // å é |
| | | if (map.get("NET").get("changeType") == "Y") { |
| | | return |
| | | } |
| | | map.get("NET").put("changeType", "Y") |
| | | let type = config.get("net.type") |
| | | logger.info("忢ç½ç»", type); |
| | | [1, 2, 4].filter(v => v != type).forEach(v => { |
| | | logger.info("å
³éç½å¡", v, net.cardEnable(v, false)); |
| | | }) |
| | | logger.info("设置主ç½å¡", type, net.setMasterCard(type)); |
| | | logger.info("å¼å¯ç½å¡", type, net.cardEnable(type, true)); |
| | | if (type == 2) { |
| | | //wifiåé
ç½®æä»¶å»è¿æ¥ |
| | | let ssid = utils.isEmpty(config.get('net.ssid')) ? "ssid" : config.get('net.ssid') |
| | | let psk = utils.isEmpty(config.get('net.psk')) ? "psk" : config.get('net.psk') |
| | | logger.info("è¿æ¥wifi", ssid, psk); |
| | | net.netConnectWifiSsid(ssid, psk) |
| | | |
| | | // çå¾
WiFiè¿æ¥æååå设置ç½ç»æ¨¡å¼ |
| | | std.setTimeout(() => { |
| | | let dns = config.get("net.dns").split(",") |
| | | net.setModeByCard(type, config.get("net.dhcp"), config.get("net.dhcp") == 1 ? { |
| | | ip: config.get("net.ip"), |
| | | gateway: config.get("net.gateway"), |
| | | netmask: config.get("net.mask"), |
| | | dns0: dns[0], |
| | | dns1: dns[1], |
| | | } : undefined) |
| | | }, 3000); // çå¾
3ç§è®©WiFiè¿æ¥æå |
| | | } else if (type == 1) { |
| | | // 以太ç½ç´æ¥è®¾ç½®ç½ç»æ¨¡å¼ |
| | | let dns = config.get("net.dns").split(",") |
| | | net.setModeByCard(type, config.get("net.dhcp"), config.get("net.dhcp") == 1 ? { |
| | | ip: config.get("net.ip"), |
| | | gateway: config.get("net.gateway"), |
| | | netmask: config.get("net.mask"), |
| | | dns0: dns[0], |
| | | dns1: dns[1], |
| | | } : undefined) |
| | | } |
| | | map.get("NET").del("changeType") |
| | | }, |
| | | |
| | | /** |
| | | * åå§åEIDç½ç» |
| | | * éåºç½ç»å¹¶éå¯ç¸å
³æå¡ |
| | | */ |
| | | eidInit: function () { |
| | | net.exit(); |
| | | common.systemWithRes(`pkill -9 -f 'wpa_supplicant|udhcpc'`, 5) |
| | | }, |
| | | |
| | | /** |
| | | * è·åç½ç»ç¶æ |
| | | * @returns {boolean} æ¯å¦è¿æ¥æå |
| | | */ |
| | | getStatus: function () { |
| | | let status = net.getStatus() |
| | | if (status.connected == true && status.status == 4) { |
| | | return true |
| | | } else { |
| | | return false |
| | | } |
| | | |
| | | }, |
| | | |
| | | /** |
| | | * è¿æ¥WiFi |
| | | * @param {string} ssid - WiFiåç§° |
| | | * @param {string} psk - WiFiå¯ç |
| | | */ |
| | | netConnectWifiSsid: function (ssid, psk) { |
| | | net.netConnectWifiSsid(ssid, psk, "") |
| | | }, |
| | | |
| | | /** |
| | | * è·åWiFiå表 |
| | | * @returns {array} WiFiå表 |
| | | */ |
| | | netGetWifiSsidList: function () { |
| | | if (!driver.net.getStatus()) { |
| | | //妿 wifi è¿æ¥å¤±è´¥ è·åå表ä¼å¤±è´¥éè¦å
鿝 |
| | | net.netDisconnetWifi() |
| | | } |
| | | let result = net.netGetWifiSsidList(1000, 5) |
| | | if (!result || !result.results || result.results.length === 0) { |
| | | return []; |
| | | } |
| | | let wifiList = []; // åå§åwifiList为æ°ç» |
| | | result.results.forEach(element => wifiList.push(element.ssid)); // 使ç¨pushæ¹æ³æ·»å ssidå°æ°ç» |
| | | return wifiList; |
| | | }, |
| | | |
| | | /** |
| | | * éç½®ç½å¡ |
| | | */ |
| | | cardReset: function () { |
| | | // net.netCardReset(2,1) |
| | | }, |
| | | |
| | | /** |
| | | * ç½ç»å¾ªç¯ |
| | | * æ§è¡ç½ç»çå¾ªç¯æä½ |
| | | */ |
| | | loop: function () { |
| | | net.worker.loop() |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * NTP驱卿¨¡å |
| | | * è´è´£ç½ç»æ¶é´åæ¥ |
| | | */ |
| | | driver.ntp = { |
| | | /** |
| | | * NTPå¾ªç¯ |
| | | * åå§åNTP模åå¹¶æ§è¡æ¶é´åæ¥æä½ |
| | | */ |
| | | loop: function () { |
| | | // æ¯ç§é夿æ¶é´ï¼å¦ææ¶å·®å¤§äº2ç§åè¿è¡äºå¯¹æ¶ |
| | | let last = new Date().getTime() |
| | | dxMap.get("NTP_SYNC").put("syncTime", last) |
| | | std.setInterval(() => { |
| | | let now = new Date().getTime() |
| | | let diff = now - last |
| | | if (diff > 2000) { |
| | | dxMap.get("NTP_SYNC").put("syncTime", now) |
| | | last = now |
| | | } |
| | | }, 1000) |
| | | |
| | | ntp.beforeLoop(config.get("ntp.server"), 9999999999999) |
| | | this.ntpHour = config.get('ntp.hour') |
| | | this.flag = true |
| | | driver.ntp.loop = () => { |
| | | if (config.get("ntp.ntp")) { |
| | | ntp.loop() |
| | | if (new Date().getHours() == this.ntpHour && this.flag) { |
| | | // 宿¶åæ¥ï¼ç«å³åæ¥ä¸æ¬¡æ¶é´ |
| | | ntp.syncnow = true |
| | | this.flag = false |
| | | } |
| | | if (new Date().getHours() != this.ntpHour) { |
| | | // çè¿äºè¿ä¸ªå°æ¶å次å
è®¸å¯¹æ¶ |
| | | this.flag = true |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | /** |
| | | * 忥驱卿¨¡å |
| | | * æä¾å¼æ¥è½¬åæ¥çå®ç° |
| | | */ |
| | | driver.sync = { |
| | | /** |
| | | * 弿¥è½¬åæ¥è¯·æ± |
| | | * @param {string} topic - ä¸»é¢ |
| | | * @param {number} timeout - è¶
æ¶æ¶é´ï¼æ¯«ç§ï¼ |
| | | * @returns {any} ååºæ°æ® |
| | | */ |
| | | request: function (topic, timeout) { |
| | | let map = dxMap.get("SYNC") |
| | | let count = 0 |
| | | let data = map.get(topic) |
| | | while (utils.isEmpty(data) && count * 10 < timeout) { |
| | | data = map.get(topic) |
| | | std.sleep(10) |
| | | count += 1 |
| | | } |
| | | let res = map.get(topic) |
| | | map.del(topic) |
| | | return res |
| | | }, |
| | | |
| | | /** |
| | | * 忥ååº |
| | | * @param {string} topic - ä¸»é¢ |
| | | * @param {any} data - ååºæ°æ® |
| | | */ |
| | | response: function (topic, data) { |
| | | let map = dxMap.get("SYNC") |
| | | map.put(topic, data) |
| | | } |
| | | } |
| | | /** |
| | | * MQTT驱卿¨¡å |
| | | * è´è´£MQTTéä¿¡åæ¶æ¯å¤ç |
| | | */ |
| | | driver.mqtt = { |
| | | /** |
| | | * åå§åMQTT |
| | | * åå§åMQTT模åï¼è®¾ç½®è¿æ¥åæ° |
| | | */ |
| | | init: function () { |
| | | mqtt.run({ mqttAddr: config.get("mqtt.addr"), clientId: config.get('mqtt.clientId'), subs: mqttService.getTopics(), username: config.get("mqtt.username"), password: config.get("mqtt.password"), qos: config.get("mqtt.qos"), willTopic: config.get("mqtt.willTopic"), willMessage: JSON.stringify({ "uuid": config.get("sys.uuid") }) }) |
| | | }, |
| | | |
| | | /** |
| | | * åå§åEIDçMQTT |
| | | * 鿝MQTTè¿æ¥ |
| | | */ |
| | | eidInit: function () { |
| | | mqtt.destroy() |
| | | }, |
| | | |
| | | /** |
| | | * åéMQTTæ¶æ¯ |
| | | * @param {string} topic - æ¶æ¯ä¸»é¢ |
| | | * @param {any} payload - æ¶æ¯è½½è· |
| | | */ |
| | | send: function (topic, payload,) { |
| | | logger.info("[driver.mqtt] send :", topic) |
| | | mqtt.send(topic, payload) |
| | | }, |
| | | |
| | | /** |
| | | * è·åå¨çº¿æ£æ¥ |
| | | * @returns {any} å¨çº¿æ£æ¥ç»æ |
| | | */ |
| | | getOnlinecheck: function () { |
| | | let timeout = config.get("mqtt.timeout") |
| | | timeout = utils.isEmpty(timeout) ? 2000 : timeout |
| | | return driver.sync.request("mqtt.getOnlinecheck", timeout) |
| | | }, |
| | | |
| | | /** |
| | | * å¨çº¿æ£æ¥åå¤ |
| | | * @param {any} data - å夿°æ® |
| | | */ |
| | | getOnlinecheckReply: function (data) { |
| | | driver.sync.response("mqtt.getOnlinecheck", data) |
| | | }, |
| | | |
| | | /** |
| | | * è·åMQTTè¿æ¥ç¶æ |
| | | * @returns {boolean} æ¯å¦è¿æ¥æå |
| | | */ |
| | | getStatus: function () { |
| | | return mqtt.isConnected() |
| | | }, |
| | | |
| | | /** |
| | | * MQTTå¿è·³ |
| | | * åéå¿è·³æ¶æ¯ï¼ä¿æè¿æ¥ |
| | | */ |
| | | heartbeat: function () { |
| | | if (utils.isEmpty(this.heart_en)) { |
| | | let heart_en = config.get('sys.heart_en') |
| | | this.heart_en = utils.isEmpty(heart_en) ? 0 : heart_en |
| | | let heart_time = config.get('sys.heart_time') |
| | | this.heart_time = utils.isEmpty(heart_time) ? 30 : heart_time < 30 ? 30 : heart_time |
| | | } |
| | | if (utils.isEmpty(this.lastHeartbeat)) { |
| | | this.lastHeartbeat = 0 |
| | | } |
| | | if (this.heart_en === 1 && (new Date().getTime() - this.lastHeartbeat >= (this.heart_time * 1000))) { |
| | | this.lastHeartbeat = new Date().getTime() |
| | | driver.mqtt.send("access_device/v2/event/heartbeat", JSON.stringify(mqttService.mqttReply(std.genRandomStr(10), undefined, mqttService.CODE.S_000))) |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * GPIO驱卿¨¡å |
| | | * è´è´£GPIO设å¤çæ§å¶ï¼ä¸»è¦æ¯ç»§çµå¨æ§å¶ |
| | | */ |
| | | driver.gpio = { |
| | | /** |
| | | * åå§åGPIO |
| | | * åå§åGPIO模å并请æ±ç»§çµå¨å¼è |
| | | */ |
| | | init: function () { |
| | | gpio.init() |
| | | gpio.request(dxDriver.GPIO.RELAY0) |
| | | }, |
| | | |
| | | /** |
| | | * æå¼ç»§çµå¨ |
| | | * æå¼ç»§çµå¨å¹¶å¨æå®æ¶é´åèªå¨å
³é |
| | | */ |
| | | open: function () { |
| | | logger.info("[GPIO]: æå¼ç»§çµå¨") |
| | | let result = gpio.setValue(dxDriver.GPIO.RELAY0, 1); |
| | | logger.info("[GPIO]: æå¼ç»§çµå¨ç»æ: " + result) |
| | | |
| | | let relayTime = config.get("access.relayTime") |
| | | |
| | | std.setTimeout(() => { |
| | | logger.info("[GPIO]: å
³éç»§çµå¨") |
| | | let closeResult = gpio.setValue(dxDriver.GPIO.RELAY0, 0); |
| | | logger.info("[GPIO]: å
³éç»§çµå¨ç»æ: " + closeResult) |
| | | }, relayTime) |
| | | }, |
| | | |
| | | /** |
| | | * å
³éç»§çµå¨ |
| | | * ç«å³å
³éç»§çµå¨ |
| | | */ |
| | | close: function () { |
| | | gpio.setValue(dxDriver.GPIO.RELAY0, 0) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * UART485驱卿¨¡å |
| | | * è´è´£UART485éä¿¡ |
| | | */ |
| | | driver.uart485 = { |
| | | /** |
| | | * UART485 ID |
| | | */ |
| | | id: 'uart485', |
| | | |
| | | /** |
| | | * åå§åUART485 |
| | | * åå§åUART485模å并设置éä¿¡åæ° |
| | | */ |
| | | init: function () { |
| | | dxUart.runvg({ id: this.id, type: dxUart.TYPE.UART, path: '/dev/ttySLB2', result: 0, passThrough: false }) |
| | | std.sleep(2000) |
| | | dxUart.ioctl(6, '115200-8-N-1', this.id) |
| | | }, |
| | | |
| | | /** |
| | | * æ§å¶UART485 |
| | | * @param {string} data - æ§å¶æ°æ® |
| | | */ |
| | | ioctl: function (data) { |
| | | dxUart.ioctl(6, data, this.id) |
| | | }, |
| | | |
| | | /** |
| | | * åéæ°æ® |
| | | * @param {string} data - è¦åéçæ°æ® |
| | | */ |
| | | send: function (data) { |
| | | dxUart.send(data, this.id) |
| | | }, |
| | | |
| | | /** |
| | | * åéVGæ°æ® |
| | | * @param {object|string} data - è¦åéçæ°æ® |
| | | */ |
| | | sendVg: function (data) { |
| | | if (typeof data == 'object') { |
| | | data.length = data.length ? data.length : (data.data ? data.data.length / 2 : 0) |
| | | } |
| | | dxUart.sendVg(data, this.id) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * UARTCode驱卿¨¡å |
| | | * è´è´£UARTæ¡ç æ«æéä¿¡ |
| | | */ |
| | | driver.uartCode = { |
| | | /** |
| | | * UARTCode ID |
| | | */ |
| | | id: 'uartCode', |
| | | |
| | | /** |
| | | * åå§åUARTCode |
| | | * åå§åUARTCode模å并设置éä¿¡åæ° |
| | | */ |
| | | init: function () { |
| | | dxUart.runvg({ id: this.id, type: dxUart.TYPE.UART, path: '/dev/ttySLB1', result: 0, passThrough: false }) |
| | | std.sleep(500) |
| | | dxUart.ioctl(6, '115200-8-N-1', this.id) |
| | | }, |
| | | |
| | | /** |
| | | * æ§å¶UARTCode |
| | | * @param {string} data - æ§å¶æ°æ® |
| | | */ |
| | | ioctl: function (data) { |
| | | dxUart.ioctl(6, data, this.id) |
| | | }, |
| | | |
| | | /** |
| | | * åéæ°æ® |
| | | * @param {string} data - è¦åéçæ°æ® |
| | | */ |
| | | send: function (data) { |
| | | dxUart.send(data, this.id) |
| | | }, |
| | | |
| | | /** |
| | | * åéVGæ°æ® |
| | | * @param {object|string} data - è¦åéçæ°æ® |
| | | */ |
| | | sendVg: function (data) { |
| | | if (typeof data == 'object') { |
| | | data.length = data.length ? data.length : (data.data ? data.data.length / 2 : 0) |
| | | } |
| | | dxUart.sendVg(data, this.id) |
| | | }, |
| | | } |
| | | |
| | | /** |
| | | * EID驱卿¨¡å |
| | | * è´è´£çµå身份è¯ç¸å
³æä½ |
| | | */ |
| | | driver.eid = { |
| | | /** |
| | | * EID ID |
| | | */ |
| | | id: "eid", |
| | | |
| | | /** |
| | | * æ¿æ´»EID |
| | | * @param {string} sn - 设å¤SN |
| | | * @param {string} version - çæ¬å· |
| | | * @param {string} mac - MACå°å |
| | | * @param {string} codeMsg - æ¿æ´»ç |
| | | * @returns {boolean} æ¯å¦æ¿æ´»æå |
| | | */ |
| | | active: function (sn, version, mac, codeMsg) { |
| | | return eid.active(sn, version, mac, codeMsg) |
| | | }, |
| | | |
| | | /** |
| | | * è·åEIDçæ¬ |
| | | * @returns {string} EIDçæ¬ |
| | | */ |
| | | getVerion: function () { |
| | | return eid.getVersion() |
| | | } |
| | | } |
| | | /** |
| | | * GPIOæé®é©±å¨æ¨¡å |
| | | * è´è´£GPIOæé®çåå§åå循ç¯å¤ç |
| | | */ |
| | | driver.gpiokey = { |
| | | /** |
| | | * åå§åGPIOæé® |
| | | * åå§åGPIOæé®æ¨¡å |
| | | */ |
| | | init: function () { |
| | | dxGpioKey.worker.beforeLoop() |
| | | }, |
| | | |
| | | /** |
| | | * GPIOæé®å¾ªç¯ |
| | | * æ§è¡GPIOæé®çå¾ªç¯æä½ |
| | | */ |
| | | loop: function () { |
| | | dxGpioKey.worker.loop() |
| | | }, |
| | | } |
| | | /** |
| | | * çé¨ç驱卿¨¡å |
| | | * è´è´£ç³»ç»çé¨ççåå§åååçæä½ |
| | | */ |
| | | driver.watchdog = { |
| | | /** |
| | | * åå§åçé¨ç |
| | | * åå§åçé¨ç模å |
| | | */ |
| | | init: function () { |
| | | // watchdog.open(1) |
| | | // watchdog.enable(1) |
| | | // watchdog.start(20000) |
| | | }, |
| | | |
| | | /** |
| | | * çé¨çå¾ªç¯ |
| | | * æ§è¡çé¨ççå¾ªç¯æä½ |
| | | */ |
| | | loop: function () { |
| | | // watchdog.loop(1) |
| | | }, |
| | | |
| | | /** |
| | | * åç |
| | | * åçé¨çåéåçä¿¡å·ï¼é²æ¢ç³»ç»éå¯ |
| | | * @param {string} flag - åçæ å¿ |
| | | * @param {number} timeout - è¶
æ¶æ¶é´ |
| | | */ |
| | | feed: function (flag, timeout) { |
| | | // if (utils.isEmpty(this["feedTime" + flag]) || new Date().getTime() - this["feedTime" + flag] > 2000) { |
| | | // // éä½åçé¢çï¼é´é2ç§å䏿¬¡ |
| | | // this["feedTime" + flag] = new Date().getTime() |
| | | // watchdog.feed(flag, timeout) |
| | | // } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * èªå¨éå¯é©±å¨æ¨¡å |
| | | * è´è´£ç³»ç»çèªå¨éå¯åè½ |
| | | */ |
| | | driver.autoRestart = { |
| | | /** |
| | | * 䏿¬¡é坿£æ¥çå°æ¶æ° |
| | | */ |
| | | lastRestartCheck: new Date().getHours(), // åå§å为å½åå°æ¶æ°ï¼è䏿¯0 |
| | | |
| | | /** |
| | | * åå§åèªå¨éå¯ |
| | | * åå§åèªå¨é坿¨¡åï¼è®¾ç½®å®æ¶éå¯åè½ |
| | | */ |
| | | init: function () { |
| | | // std.setInterval(() => { // æ£æ¥æ¯å¦éè¦æ´ç¹éå¯ |
| | | // const now = new Date() |
| | | // const currentHour = now.getHours() |
| | | // // åªæå½å°æ¶æ°çäºè®¾å®å¼ï¼ä¸ä¸æ¯ä¸æ¬¡æ£æ¥è¿çå°æ¶æ¶ææ§è¡ |
| | | // if (currentHour === 3 && currentHour !== this.lastRestartCheck && now.getMinutes() === 0) { |
| | | // common.systemBrief('reboot') |
| | | // } |
| | | // // æ´æ°ä¸æ¬¡æ£æ¥çå°æ¶æ° |
| | | // this.lastRestartCheck = currentHour |
| | | // }, 60000) |
| | | } |
| | | } |
| | | |
| | | export default driver |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | /** |
| | | * åºç¨ä¸»å
¥å£æä»¶ |
| | | * è´è´£åå§åç³»ç»åç»ä»¶ã驱å¨åæå¡ï¼å¯å¨åºç¨ç¨åº |
| | | */ |
| | | import log from '../dxmodules/dxLogger.js' |
| | | import std from '../dxmodules/dxStd.js' |
| | | import bus from '../dxmodules/dxEventBus.js' |
| | | import screen from './screen.js' |
| | | import driver from './driver.js' |
| | | import pool from '../dxmodules/dxWorkerPool.js' |
| | | import config from '../dxmodules/dxConfig.js' |
| | | import face from '../dxmodules/dxFace.js' |
| | | import net from '../dxmodules/dxNet.js' |
| | | import mqtt from '../dxmodules/dxMqtt.js' |
| | | import dxNfc from '../dxmodules/dxNfc.js' |
| | | import dxUart from '../dxmodules/dxUart.js' |
| | | import dxGpioKey from '../dxmodules/dxGpioKey.js' |
| | | |
| | | /** |
| | | * äºä»¶æ»çº¿ä¸»é¢å表 |
| | | * å
å«ç³»ç»ä¸ææéè¦çå¬çäºä»¶ä¸»é¢ |
| | | */ |
| | | let topics = ["getCode", face.RECEIVE_MSG, dxGpioKey.RECEIVE_MSG, "netGetWifiSsidList", "switchNetworkType", "access", "setConfig", dxNfc.RECEIVE_MSG, net.STATUS_CHANGE, mqtt.CONNECTED_CHANGED, mqtt.RECEIVE_MSG, dxUart.VG.RECEIVE_MSG + driver.uart485.id, dxUart.VG.RECEIVE_MSG + driver.uartCode.id, "trackResult"] |
| | | |
| | | /** |
| | | * åå§åæ§å¶å¨ |
| | | * åå§åç³»ç»ææé©±å¨æ¨¡å |
| | | */ |
| | | function initController() { |
| | | driver.gpio.init() // åå§åGPIO |
| | | driver.watchdog.init() // åå§åçé¨ç |
| | | driver.config.init() // åå§åé
ç½® |
| | | driver.gpiokey.init() // åå§åGPIOæé® |
| | | driver.net.init() // åå§åç½ç» |
| | | driver.sqlite.init() // åå§åæ°æ®åº |
| | | driver.alsa.init() // åå§åé³é¢ |
| | | driver.nfc.init() // åå§åNFC |
| | | driver.nfc.eidInit() // åå§åEIDï¼çµå身份è¯ï¼ |
| | | driver.uart485.init() // åå§åUART485 |
| | | driver.uartCode.init() // åå§åUARTç |
| | | driver.capturer.init() // åå§åæå头 |
| | | std.sleep(100) // çå¾
100ms |
| | | driver.face.init() // åå§å人è¸è¯å« |
| | | std.sleep(100) // çå¾
100ms |
| | | driver.pwm.init() // åå§åPWM |
| | | std.sleep(100) // çå¾
100ms |
| | | driver.mqtt.init() // åå§åMQTT |
| | | driver.autoRestart.init() // åå§åèªå¨éå¯ |
| | | } |
| | | |
| | | /** |
| | | * åºç¨ç¨åºå¯å¨å½æ° |
| | | * åå§åæ§å¶å¨ãå±å¹ãå建工ä½çº¿ç¨åæå¡æ± |
| | | */ |
| | | (function () { |
| | | initController() // åå§åæ§å¶å¨ |
| | | screen.init() // åå§åå±å¹ |
| | | bus.newWorker('controller', '/app/code/src/controller.js') // å建æ§å¶å¨å·¥ä½çº¿ç¨ |
| | | pool.init('/app/code/src/services.js', bus, topics, 5, 100) // åå§åæå¡æ± |
| | | const appVersion = 'vf105_v12_access_2.0.1.1' // åºç¨çæ¬å· |
| | | config.setAndSave('sys.version', appVersion) // ä¿åçæ¬å·å°é
ç½® |
| | | config.setAndSave('sys.appVersion', appVersion) // ä¿ååºç¨çæ¬å·å°é
ç½® |
| | | log.info("=================== version:" + appVersion + " ====================") |
| | | })(); |
| | | |
| | | /** |
| | | * ä¸»å¾ªç¯ |
| | | * 宿åçãæ§è¡çé¨ç循ç¯åå±å¹å¾ªç¯ |
| | | */ |
| | | std.setInterval(() => { |
| | | try { |
| | | driver.watchdog.feed("main", 30) // åçï¼è®¾ç½®30ç§è¶
æ¶ |
| | | driver.watchdog.loop() // æ§è¡çé¨çå¾ªç¯ |
| | | screen.loop() // æ§è¡å±å¹å¾ªç¯ |
| | | } catch (error) { |
| | | log.error(error) // è®°å½é误 |
| | | } |
| | | }, 5) // æ¯5msæ§è¡ä¸æ¬¡ |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | /** |
| | | * å±å¹ç®¡ç模å |
| | | * è´è´£å±å¹æ¾ç¤ºãUIæ§å¶ãç¨æ·çé¢ç®¡ççåè½ |
| | | */ |
| | | import dxui from '../dxmodules/dxUi.js' |
| | | import dxMap from '../dxmodules/dxMap.js' |
| | | import log from '../dxmodules/dxLogger.js' |
| | | import net from '../dxmodules/dxNet.js' |
| | | import viewUtils from './view/viewUtils.js' |
| | | import i18n from './view/i18n.js' |
| | | import grainService from './service/grainService.js' |
| | | import sqliteService from './service/sqliteService.js' |
| | | import pinyin from './view/pinyin/pinyin.js' |
| | | import mainView from './view/mainView.js' |
| | | import idleView from './view/idleView.js' |
| | | import topView from './view/topView.js' |
| | | import appView from './view/appView.js' |
| | | import pwdView from './view/pwdView.js' |
| | | import emergencyPwdView from './view/emergencyPwdView.js' |
| | | import newPwdView from './view/config/newPwdView.js' |
| | | import identityVerificationView from './view/config/identityVerificationView.js' |
| | | import configView from './view/config/configView.js' |
| | | import cloudCertView from './view/config/menu/cloudCertView.js' |
| | | import doorControlView from './view/config/menu/doorControlView.js' |
| | | import helpView from './view/config/menu/helpView.js' |
| | | import networkSettingView from './view/config/menu/networkSettingView.js' |
| | | import systemSettingView from './view/config/menu/systemSettingView.js' |
| | | import deviceInfoView from './view/config/menu/deviceInfoView.js' |
| | | import factoryTestView from './view/config/menu/factoryTestView.js' |
| | | import localUserView from './view/config/menu/localUserView.js' |
| | | import recordQueryView from './view/config/menu/recordQueryView.js' |
| | | import voiceBroadcastView from './view/config/menu/voiceBroadcastView.js' |
| | | import dockingSettingView from './view/config/menu/dockingSetting.js' |
| | | import localUserAddView from './view/config/menu/localUser/localUserAddView.js' |
| | | import faceEnterView from './view/config/menu/localUser/faceEnterView.js' |
| | | import displaySettingView from './view/config/menu/systemSetting/displaySettingView.js' |
| | | import faceRecognitionSettingView from './view/config/menu/systemSetting/faceRecognitionSettingView.js' |
| | | import swipeCardRecognitionSettingView from './view/config/menu/systemSetting/swipeCardRecognitionSettingView.js' |
| | | import passLogSettingView from './view/config/menu/systemSetting/passLogSettingView.js' |
| | | import passwordOpenDoorSettingView from './view/config/menu/systemSetting/passwordOpenDoorSettingView.js' |
| | | import passwordManagementView from './view/config/menu/systemSetting/passwordManagementView.js' |
| | | import timeSettingView from './view/config/menu/systemSetting/timeSettingView.js' |
| | | import systemInfoView from './view/config/menu/deviceInfo/systemInfoView.js' |
| | | import dataCapacityInfoView from './view/config/menu/deviceInfo/dataCapacityInfoView.js' |
| | | import recordQueryDetailView from './view/config/menu/recordQuery/recordQueryDetailView.js' |
| | | import std from '../dxmodules/dxStd.js' |
| | | import bus from '../dxmodules/dxEventBus.js' |
| | | import driver from './driver.js' |
| | | import config from '../dxmodules/dxConfig.js' |
| | | import common from '../dxmodules/dxCommon.js' |
| | | import configService from './service/configService.js' |
| | | import codeService from './service/codeService.js' |
| | | import face from '../dxmodules/dxFace.js' |
| | | import faceService from './service/faceService.js' |
| | | |
| | | /** |
| | | * å±å¹ç®¡ç对象 |
| | | */ |
| | | const screen = {} |
| | | |
| | | /** |
| | | * å±å¹å°ºå¯¸é
ç½® |
| | | */ |
| | | screen.screenSize = { |
| | | width: 800, |
| | | height: 1280 |
| | | } |
| | | |
| | | /** |
| | | * UIä¸ä¸æ |
| | | */ |
| | | const context = {} |
| | | |
| | | /** |
| | | * åå§åå±å¹ç®¡ç模å |
| | | * åå§åææUIç»ä»¶ã设置è¯è¨ãå¯å¨å±ä¿è®¡æ¶å¨ç |
| | | * 注æï¼å¨main.jsä¸è°ç¨ï¼åªå
许è°ç¨ä¸æ¬¡ |
| | | */ |
| | | screen.init = function () { |
| | | const loadMethod = dxui.loadMain |
| | | dxui.loadMain = function (view) { |
| | | if (screen.screenNow && screen.screenNow.id == view.id) { |
| | | return |
| | | } |
| | | screen.screenNow = view |
| | | pinyin.hide(true) |
| | | loadMethod.call(dxui, view) |
| | | } |
| | | |
| | | dxui.init({ orientation: 0 }, context); |
| | | // åå§åææç»ä»¶ |
| | | pinyin.init(800, 400) |
| | | |
| | | viewUtils.confirmInit() |
| | | |
| | | mainView.init() |
| | | idleView.init() |
| | | topView.init() |
| | | appView.init() |
| | | pwdView.init() |
| | | emergencyPwdView.init() |
| | | newPwdView.init() |
| | | identityVerificationView.init() |
| | | configView.init() |
| | | |
| | | cloudCertView.init() |
| | | doorControlView.init() |
| | | helpView.init() |
| | | networkSettingView.init() |
| | | systemSettingView.init() |
| | | deviceInfoView.init() |
| | | factoryTestView.init() |
| | | localUserView.init() |
| | | recordQueryView.init() |
| | | voiceBroadcastView.init() |
| | | dockingSettingView.init() |
| | | |
| | | localUserAddView.init() |
| | | faceEnterView.init() |
| | | |
| | | displaySettingView.init() |
| | | faceRecognitionSettingView.init() |
| | | swipeCardRecognitionSettingView.init() |
| | | passLogSettingView.init() |
| | | |
| | | |
| | | passwordOpenDoorSettingView.init() |
| | | passwordManagementView.init() |
| | | timeSettingView.init() |
| | | |
| | | systemInfoView.init() |
| | | dataCapacityInfoView.init() |
| | | recordQueryDetailView.init() |
| | | |
| | | // 设置è¯è¨ |
| | | // i18n.setLanguage("en-US") |
| | | i18n.setLanguage(config.get("base.language")) |
| | | |
| | | dxui.loadMain(mainView.screenMain) |
| | | // dxui.loadMain(networkSettingView.screenMain) |
| | | |
| | | // å¯å¨å±ä¿è®¡æ¶å¨ |
| | | idleTimerStart() |
| | | |
| | | // busäºä»¶ |
| | | busEvents() |
| | | |
| | | // 宿¶è·åç¹å»åæ |
| | | getClickPoint() |
| | | |
| | | // éèé®ç |
| | | hidePinyin() |
| | | |
| | | // 人è¸è·è¸ªæ¡ |
| | | faceTrackingBox() |
| | | } |
| | | |
| | | /** |
| | | * 人è¸è·è¸ªæ¡å¤ç |
| | | * 宿è·å人è¸è·è¸ªæ°æ®å¹¶æ´æ°è·è¸ªæ¡æ¾ç¤º |
| | | */ |
| | | function faceTrackingBox() { |
| | | std.setInterval(() => { |
| | | let data = driver.face.getTrackingBox() |
| | | try { |
| | | if (data && typeof data === 'string') { |
| | | // æ£æ¥æ°æ®æ¯å¦æ¯ææçJSONå符串 |
| | | try { |
| | | data = JSON.parse(data) |
| | | // æå¤§10个人 |
| | | if (data.type == "track" && data.faces && data.faces.length <= 10) { |
| | | for (let i = 0; i < data.faces.length; i++) { |
| | | let item = data.faces[i] |
| | | if (item && item.rect_render && item.rect_render.length === 4) { |
| | | screen.trackUpdate({ w: item.rect_render[2] - item.rect_render[0], h: item.rect_render[3] - item.rect_render[1], x: item.rect_render[0], y: item.rect_render[1] }, item.id, item.is_living) |
| | | } |
| | | } |
| | | } |
| | | } catch (parseError) { |
| | | log.info('screen.faceTrackingBox: æ æçJSONæ°æ®:', data); |
| | | log.error("screen.faceTrackingBox: JSONè§£æé误:", parseError) |
| | | } |
| | | } |
| | | } catch (error) { |
| | | log.info('screen.faceTrackingBox:', data); |
| | | log.error("screen.faceTrackingBox:", error) |
| | | } |
| | | }, 110) |
| | | } |
| | | |
| | | /** |
| | | * ç¹å»åæ ååæ è®° |
| | | */ |
| | | let changedClickPoint |
| | | |
| | | /** |
| | | * 䏿¬¡ç¹å»åæ |
| | | */ |
| | | let lastClickPoint = { x: 0, y: 0 } |
| | | |
| | | /** |
| | | * å½åç¹å»åæ |
| | | */ |
| | | let clickPoint |
| | | |
| | | /** |
| | | * 宿¶è·åç¹å»åæ |
| | | * 宿è·åç¨æ·è§¦æ¸å±å¹çåæ ä½ç½® |
| | | */ |
| | | function getClickPoint() { |
| | | const indev = NativeObject.APP.NativeComponents.NativeIndev |
| | | std.setInterval(() => { |
| | | clickPoint = { |
| | | x: Math.abs(800 - indev.lvIndevGetPointVg().x), |
| | | y: indev.lvIndevGetPointVg().y |
| | | } |
| | | |
| | | if (lastClickPoint.x != clickPoint.x || lastClickPoint.y != clickPoint.y) { |
| | | changedClickPoint = clickPoint |
| | | } else { |
| | | changedClickPoint = null |
| | | } |
| | | |
| | | lastClickPoint = clickPoint |
| | | }, 5) |
| | | } |
| | | |
| | | /** |
| | | * éèæ¼é³é®ç |
| | | * å¤çæ¼é³é®ççæ¾ç¤ºåéèé»è¾ï¼å½ç¨æ·ç¹å»å±å¹å
¶ä»åºåæ¶èªå¨éèé®ç |
| | | */ |
| | | function hidePinyin() { |
| | | /** |
| | | * é®çæ¾ç¤ºæ¶çç¹å»åæ |
| | | */ |
| | | let showPoint |
| | | |
| | | /** |
| | | * åå§çéèæ¹æ³ |
| | | */ |
| | | const hideMethod = pinyin.hide |
| | | |
| | | /** |
| | | * åå§çæ¾ç¤ºæ¹æ³ |
| | | */ |
| | | const showMethod = pinyin.show |
| | | |
| | | /** |
| | | * é宿 å¿ï¼é²æ¢éå¤æä½ |
| | | */ |
| | | let lock = false |
| | | |
| | | // éåéèæ¹æ³ |
| | | pinyin.hide = function (isForce) { |
| | | if (isForce) { |
| | | hideMethod.call(pinyin) |
| | | lock = false |
| | | return |
| | | } |
| | | if (lock) { |
| | | return |
| | | } |
| | | lock = true |
| | | hideMethod.call(pinyin) |
| | | lock = false |
| | | } |
| | | |
| | | // éåæ¾ç¤ºæ¹æ³ |
| | | pinyin.show = function (...args) { |
| | | if (lock) { |
| | | return |
| | | } |
| | | lock = true |
| | | showMethod.call(pinyin, ...args) |
| | | showPoint = clickPoint |
| | | lock = false |
| | | } |
| | | |
| | | // å®ææ£æ¥æ¯å¦éè¦éèé®ç |
| | | std.setInterval(() => { |
| | | if (showPoint && (Math.abs(showPoint.x - clickPoint.x) > 5 && Math.abs(showPoint.y - clickPoint.y) > 5)) { |
| | | if (clickPoint.y < (1280 - (pinyin.getMode() == 1 ? 400 + 70 : 400))) { |
| | | let defocus = dxMap.get("INPUT_KEYBOARD").get("defocus") |
| | | if (defocus == "defocus") { |
| | | dxMap.get("INPUT_KEYBOARD").del("defocus") |
| | | showPoint = null |
| | | pinyin.hide() |
| | | } |
| | | } |
| | | } |
| | | }, 5) |
| | | } |
| | | |
| | | /** |
| | | * å±å¹ç®¡çå¨ç±» |
| | | * è´è´£å±å¹ç¶æç®¡çï¼å
æ¬å±ä¿åçå±åè½ |
| | | */ |
| | | class ScreenManager { |
| | | /** |
| | | * æé 彿° |
| | | * @param {object} callbacks - åè°å½æ°å¯¹è±¡ |
| | | */ |
| | | constructor(callbacks = {}) { |
| | | /** |
| | | * 宿¶å¨å¯¹è±¡ |
| | | */ |
| | | this.timers = { |
| | | screenSaver: null, // å±ä¿å®æ¶å¨ |
| | | screenOff: null // çå±å®æ¶å¨ |
| | | }; |
| | | |
| | | /** |
| | | * é
置对象 |
| | | */ |
| | | this.config = { |
| | | screenSaverDelay: 0, // å±ä¿å»¶è¿ï¼æ¯«ç§ï¼ |
| | | screenOffDelay: 0 // çå±å»¶è¿ï¼æ¯«ç§ï¼ |
| | | }; |
| | | |
| | | /** |
| | | * åè°å½æ° |
| | | */ |
| | | this.callbacks = { |
| | | onScreenSaverStart: callbacks.onScreenSaverStart || (() => { }), |
| | | onScreenSaverEnd: callbacks.onScreenSaverEnd || (() => { }), |
| | | onScreenOff: callbacks.onScreenOff || (() => { }), |
| | | onScreenOn: callbacks.onScreenOn || (() => { }) |
| | | }; |
| | | |
| | | this.resetTimers = this.resetTimers.bind(this); |
| | | } |
| | | |
| | | /** |
| | | * é
ç½®æ¶é´ |
| | | * @param {number} screenSaverDelay - å±ä¿å»¶è¿ï¼æ¯«ç§ï¼ |
| | | * @param {number} screenOffDelay - çå±å»¶è¿ï¼æ¯«ç§ï¼ |
| | | */ |
| | | configure({ screenSaverDelay = 0, screenOffDelay = 0 }) { |
| | | this.config.screenSaverDelay = screenSaverDelay; |
| | | this.config.screenOffDelay = screenOffDelay; |
| | | this.resetTimers(); |
| | | } |
| | | |
| | | /** |
| | | * éç½®å®æ¶å¨ |
| | | * æ¸
é¤ç°æå®æ¶å¨å¹¶è®¾ç½®æ°ç宿¶å¨ |
| | | */ |
| | | resetTimers() { |
| | | // æ¸
é¤ç°æå®æ¶å¨ |
| | | if (this.timers.screenSaver) { |
| | | std.clearTimeout(this.timers.screenSaver); |
| | | } |
| | | if (this.timers.screenOff) { |
| | | std.clearTimeout(this.timers.screenOff); |
| | | } |
| | | |
| | | // éåºå½åç¶æ |
| | | this.exitScreenStates(); |
| | | |
| | | // 设置æ°ç宿¶å¨ |
| | | if (this.config.screenOffDelay > 0) { |
| | | this.timers.screenOff = std.setTimeout(() => { |
| | | this.enterScreenOff(); |
| | | }, this.config.screenOffDelay); |
| | | } |
| | | |
| | | // åªæå½ç屿¶é´å¤§äºå±ä¿æ¶é´æ¶æè®¾ç½®å±ä¿å®æ¶å¨ |
| | | if (this.config.screenSaverDelay > 0 && |
| | | (this.config.screenSaverDelay < this.config.screenOffDelay || this.config.screenOffDelay == 0)) { |
| | | this.timers.screenSaver = std.setTimeout(() => { |
| | | this.enterScreenSaver(); |
| | | }, this.config.screenSaverDelay); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è¿å
¥å±ä¿ç¶æ |
| | | */ |
| | | enterScreenSaver() { |
| | | const mapUI = dxMap.get("UI") |
| | | if (!mapUI.get("isScreenOff")) { |
| | | mapUI.put("isScreenSaver", true) |
| | | this.callbacks.onScreenSaverStart(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è¿å
¥çå±ç¶æ |
| | | */ |
| | | enterScreenOff() { |
| | | const mapUI = dxMap.get("UI") |
| | | mapUI.put("isScreenOff", true) |
| | | mapUI.put("isScreenSaver", false) |
| | | this.callbacks.onScreenOff(); |
| | | } |
| | | |
| | | /** |
| | | * éåºææå±å¹ç¶æ |
| | | */ |
| | | exitScreenStates() { |
| | | const mapUI = dxMap.get("UI") |
| | | const previousState = { isScreenOff: mapUI.get("isScreenOff"), isScreenSaver: mapUI.get("isScreenSaver") }; |
| | | mapUI.put("isScreenOff", false) |
| | | mapUI.put("isScreenSaver", false) |
| | | // å¦æç¶æåçæ¹åï¼è§¦åç¸åºåè° |
| | | if (previousState.isScreenSaver) { |
| | | this.callbacks.onScreenSaverEnd(); |
| | | } |
| | | if (previousState.isScreenOff) { |
| | | this.callbacks.onScreenOn(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è·åå½åç¶æ |
| | | * @returns {object} å½åå±å¹ç¶æ |
| | | */ |
| | | getState() { |
| | | const mapUI = dxMap.get("UI") |
| | | return { isScreenOff: mapUI.get("isScreenOff"), isScreenSaver: mapUI.get("isScreenSaver") }; |
| | | } |
| | | |
| | | /** |
| | | * æ¸
çèµæº |
| | | * æ¸
餿æå®æ¶å¨ |
| | | */ |
| | | destroy() { |
| | | if (this.timers.screenSaver) { |
| | | std.clearTimeout(this.timers.screenSaver); |
| | | } |
| | | if (this.timers.screenOff) { |
| | | std.clearTimeout(this.timers.screenOff); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å±å¹ç®¡çå¨å®ä¾ |
| | | */ |
| | | let screenManager |
| | | |
| | | /** |
| | | * å¯å¨å±ä¿è®¡æ¶å¨ |
| | | * åå§åå±å¹ç®¡çå¨ï¼è®¾ç½®å±ä¿åç屿¶é´ï¼æ£æµç¨æ·è§¦æ¸ |
| | | */ |
| | | function idleTimerStart() { |
| | | // å建å®ä¾ï¼ä¼ å
¥åè°å½æ° |
| | | screenManager = new ScreenManager({ |
| | | /** |
| | | * å±ä¿å¼å§åè° |
| | | */ |
| | | onScreenSaverStart: () => { |
| | | screen.enterIdle() |
| | | }, |
| | | |
| | | /** |
| | | * å±ä¿ç»æåè° |
| | | */ |
| | | onScreenSaverEnd: () => { |
| | | screen.exitIdle(true) |
| | | }, |
| | | |
| | | /** |
| | | * çå±åè° |
| | | */ |
| | | onScreenOff: () => { |
| | | dxMap.get("screenOff").put("status", 1) |
| | | // åæ¢äººè¸è¯å« |
| | | driver.face.status(false) |
| | | screen.screenNow.hide() |
| | | topView.screenMain.hide() |
| | | }, |
| | | |
| | | /** |
| | | * 亮å±åè° |
| | | */ |
| | | onScreenOn: () => { |
| | | screen.exitIdle(true) |
| | | dxMap.get("screenOff").put("status", 0) |
| | | // æ¢å¤äººè¸è¯å« |
| | | driver.face.status(true) |
| | | screen.screenNow.show() |
| | | topView.screenMain.show() |
| | | |
| | | // éåºç屿¶è·åå¹¶æ´æ°æ°ä½æµåº¦åç¶æä¿¡æ¯ |
| | | try { |
| | | log.info('[screen]: éåºçå±ï¼è·åæ°ä½æµåº¦åç¶æä¿¡æ¯') |
| | | grainService.checkGasConcentration() |
| | | grainService.checkDevConcentration() |
| | | } catch (error) { |
| | | log.error(`[screen]: è·åæ°ä½æµåº¦åç¶æä¿¡æ¯é误: ${error.message}`) |
| | | } |
| | | } |
| | | }); |
| | | |
| | | // é
ç½®æ¶é´ï¼æ¯«ç§ï¼ |
| | | screenManager.configure({ |
| | | // screenSaverDelay: 10000, // å±ä¿ |
| | | // screenOffDelay: 5000 // çå± |
| | | screenSaverDelay: config.get("base.screensaver") * 60 * 1000, // å±ä¿ |
| | | screenOffDelay: config.get("base.screenOff") * 60 * 1000 // çå± |
| | | }); |
| | | |
| | | // æ£æµç¨æ·è§¦æ¸ |
| | | let touchCount = 0 |
| | | std.setInterval(() => { |
| | | let count = dxui.Utils.GG.NativeDisp.lvDispGetInactiveTime() |
| | | if (count < touchCount) { |
| | | screenManager.resetTimers(); |
| | | } |
| | | touchCount = count |
| | | }, 100); |
| | | } |
| | | |
| | | /** |
| | | * å·æ°å±å¹ç®¡çå¨é
ç½® |
| | | * æ´æ°å±ä¿åç屿¶é´é
ç½® |
| | | */ |
| | | screen.screenManagerRefresh = function () { |
| | | screenManager.configure({ |
| | | screenSaverDelay: config.get("base.screensaver") * 60 * 1000, // å±ä¿ |
| | | screenOffDelay: config.get("base.screenOff") * 60 * 1000 // çå± |
| | | }); |
| | | screenManager.resetTimers(); |
| | | } |
| | | |
| | | /** |
| | | * è¿å
¥å±ä¿å®æ¶å¨ |
| | | */ |
| | | let enterIdleTimer |
| | | |
| | | /** |
| | | * è¿å
¥å±ä¿ |
| | | * æ¾ç¤ºå±ä¿çé¢ |
| | | */ |
| | | screen.enterIdle = function () { |
| | | // å»¶è¿1ç§ï¼é²æ¢è¿å
¥å±ä¿åéåºå±ä¿åæ¶è§¦åï¼1ç§å
没æè§¦åéåºå±ä¿ï¼å认为è¿å
¥å±ä¿ |
| | | enterIdleTimer = std.setTimeout(() => { |
| | | if (idleView.screenMain.isHide()) { |
| | | viewUtils.confirmClose() |
| | | dxui.loadMain(mainView.screenMain) |
| | | idleView.screenMain.show() |
| | | topView.changeTheme(false) |
| | | } |
| | | }, 1000) |
| | | } |
| | | |
| | | /** |
| | | * éåºå±ä¿ |
| | | * éèå±ä¿çé¢ |
| | | * @param {boolean} isSelf - æ¯å¦ç±ç³»ç»èªèº«è§¦å |
| | | */ |
| | | screen.exitIdle = function (isSelf) { |
| | | if (enterIdleTimer) { |
| | | std.clearTimeout(enterIdleTimer) |
| | | enterIdleTimer = null |
| | | } |
| | | if (!isSelf) { |
| | | screenManager.resetTimers(); |
| | | } |
| | | if (!idleView.screenMain.isHide()) { |
| | | idleView.screenMain.hide() |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å±å¹å¾ªç¯å¤ç |
| | | * å¤çUIäºä»¶ |
| | | * @returns {boolean} å¤çç»æ |
| | | */ |
| | | screen.loop = function () { |
| | | return dxui.handler() |
| | | } |
| | | |
| | | /** |
| | | * äºè¯æ¿æ´» |
| | | * æ¿æ´»çµåèº«ä»½è¯ |
| | | * @param {string} code - æ¿æ´»ç |
| | | * @returns {number} æ¿æ´»ç»æï¼0表示æåï¼é0表示失败 |
| | | */ |
| | | screen.nfcIdentityCardActivation = function (code) { |
| | | return driver.eid.active(config.get("sys.sn"), config.get("sys.appVersion"), config.get("sys.mac"), code); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * å é¤äººå |
| | | * å é¤ç¨æ·ä¿¡æ¯ãæéãåè¯åäººè¸æ°æ® |
| | | * @param {object} user - ç¨æ·å¯¹è±¡ |
| | | * @returns {boolean} å é¤ç»æ |
| | | */ |
| | | screen.deleteUser = function (user) { |
| | | // å é¤äººåä¿¡æ¯ |
| | | sqliteService.d1_person.deleteByUserId(user.userId) |
| | | // å 餿éä¿¡æ¯ |
| | | sqliteService.d1_permission.deleteByUserId(user.userId) |
| | | // å é¤åè¯ä¿¡æ¯ |
| | | sqliteService.d1_voucher.deleteByUserId(user.userId) |
| | | // å é¤äººè¸æ°æ® |
| | | let res = driver.face.delete(user.userId) |
| | | |
| | | return true |
| | | } |
| | | |
| | | /** |
| | | * æ´æ°äººåä¿¡æ¯ |
| | | * æ´æ°ç¨æ·ä¿¡æ¯ãå¯ç ãå¡çåäººè¸æ°æ® |
| | | * @param {object} user - ç¨æ·å¯¹è±¡ |
| | | * @returns {boolean|string} æ´æ°ç»æï¼æåè¿åtrueï¼å¤±è´¥è¿åéè¯¯ä¿¡æ¯ |
| | | */ |
| | | screen.updateUser = function (user) { |
| | | //ä¿®æ¹äººåä¿¡æ¯ |
| | | let res = sqliteService.d1_person.updatenameAndExtraByUserId(user.userId, user.name, JSON.stringify({ type: user.type, idCard: user.idCard })) |
| | | if (res != 0) { |
| | | return false |
| | | } |
| | | |
| | | //å¤çåè¯ |
| | | let ret |
| | | |
| | | //å¤çå¯ç åè¯ |
| | | if (user.pwd) { |
| | | //夿åºè¡¨æ¯å¦åå¨è¿ä¸ªåè¯ |
| | | let pwdData = sqliteService.d1_voucher.findByCodeAndType(user.pwd, "400"); |
| | | if (pwdData.length > 0 && pwdData[0].userId != user.userId) { |
| | | //åå¨ä¸è½æ·»å è¿å失败 |
| | | log.info("å¯ç éå¤"); |
| | | return "localUserAddView.failPwdRepeat" |
| | | } |
| | | //æ¥è¯¢æ¯å¦æå¯ç åè¯ææ´æ°æ²¡ææ°å¢ |
| | | let countByuserIdAndType = sqliteService.d1_voucher.findByuserIdAndType(user.userId, "400"); |
| | | if (countByuserIdAndType.length > 0) { |
| | | ret = sqliteService.d1_voucher.updatecodeByuserIdAndtype(user.userId, "400", user.pwd) |
| | | if (ret != 0) { |
| | | return false |
| | | } |
| | | } else { |
| | | //æ°å¢ä¸ä¸ª |
| | | ret = sqliteService.d1_voucher.save({ keyId: std.genRandomStr(32), type: "400", code: user.pwd, userId: user.userId }) |
| | | if (ret != 0) { |
| | | return false |
| | | } |
| | | } |
| | | } else { |
| | | //没æå
容廿°æ®åºè¡¨å é¤ä¸ä¸ |
| | | sqliteService.d1_voucher.deleteByuserIdAndtype(user.userId, "400") |
| | | } |
| | | |
| | | //å¤çå¡çåè¯ |
| | | if (user.card) { |
| | | //夿åºè¡¨æ¯å¦åå¨è¿ä¸ªåè¯ |
| | | let cardData = sqliteService.d1_voucher.findByCodeAndType(user.card, "200"); |
| | | if (cardData.length > 0 && cardData[0].userId != user.userId) { |
| | | //åå¨ä¸è½æ·»å è¿å失败 |
| | | log.info("å¡éå¤"); |
| | | return "localUserAddView.failCardRepeat" |
| | | } |
| | | //æ¥è¯¢æ¯å¦æå¯ç åè¯ææ´æ°æ²¡ææ°å¢ |
| | | let countByuserIdAndType = sqliteService.d1_voucher.countByuserIdAndType(user.userId, "200"); |
| | | if (countByuserIdAndType > 0) { |
| | | ret = sqliteService.d1_voucher.updatecodeByuserIdAndtype(user.userId, "200", user.card) |
| | | if (ret != 0) { |
| | | return false |
| | | } |
| | | } else { |
| | | //æ°å¢ä¸ä¸ª |
| | | ret = sqliteService.d1_voucher.save({ keyId: std.genRandomStr(32), type: "200", code: user.card, userId: user.userId }) |
| | | |
| | | if (ret != 0) { |
| | | return false |
| | | } |
| | | } |
| | | } else { |
| | | //没æå
容廿°æ®åºè¡¨å é¤ä¸ä¸ |
| | | sqliteService.d1_voucher.deleteByuserIdAndtype(user.userId, "200") |
| | | } |
| | | |
| | | //å¤ç人è¸åè¯ |
| | | if (user.face) { |
| | | let findByuserIdAndType = sqliteService.d1_voucher.findByuserIdAndType(user.userId, "300"); |
| | | if (findByuserIdAndType.length <= 0) { |
| | | let ret = driver.face.registerFaceByPicFile(user.userId, user.face) |
| | | log.info("2注å人è¸,ret:", ret) |
| | | if (ret != 0) { |
| | | return faceService.regErrorEnum.picture[ret + ''] |
| | | } |
| | | //注åæååéè¦å§åæ¥å¾çç§»å¨å° user 对åºç®å½ä¸ |
| | | let src = "/app/data/user/" + user.userId + "/register.jpg" |
| | | std.ensurePathExists(src) |
| | | common.systemBrief('mv ' + user.face + " " + src) |
| | | |
| | | //æ°å¢ä¸ä¸ª |
| | | ret = sqliteService.d1_voucher.save({ keyId: std.genRandomStr(32), type: "300", code: src, userId: user.userId }) |
| | | if (ret != 0) { |
| | | return false |
| | | } |
| | | } else { |
| | | //忥æåä¼ å
¥ å
å é¤åæ°å¢ |
| | | if (findByuserIdAndType[0].code != user.face) { |
| | | //å é¤èäººè¸ |
| | | driver.face.delete(user.userId) |
| | | //æ³¨åæ°äººè¸ |
| | | let res = driver.face.registerFaceByPicFile(user.userId, user.face) |
| | | log.info("3注å人è¸,res:", res) |
| | | if (res != 0) { |
| | | return faceService.regErrorEnum.picture[res + ''] |
| | | } |
| | | let src = "/app/data/user/" + user.userId + "/register.jpg" |
| | | std.ensurePathExists(src) |
| | | //æä¸´æ¶ç®å½äººè¸ç§»å¨å° user 对åºçæä»¶å¤¹ä¸ |
| | | common.systemBrief('mv ' + user.face + " " + src) |
| | | ret = sqliteService.d1_voucher.updatecodeAndExtraByuserIdAndtype(user.userId, "300", src, JSON.stringify({ faceType: 0 })) |
| | | |
| | | } |
| | | } |
| | | } else { |
| | | //没æå
容廿°æ®åºè¡¨å é¤ä¸ä¸ |
| | | sqliteService.d1_voucher.deleteByuserIdAndtype(user.userId, "300") |
| | | driver.face.delete(user.userId) |
| | | common.systemBrief("rm -rf /app/data/user/" + user.userId) |
| | | } |
| | | |
| | | return true |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢äººå |
| | | * æ·»å æ°ç¨æ·ä¿¡æ¯ãå¯ç ãå¡çåäººè¸æ°æ® |
| | | * @param {object} user - ç¨æ·å¯¹è±¡ |
| | | * @returns {boolean|string} æ·»å ç»æï¼æåè¿åtrueï¼å¤±è´¥è¿åéè¯¯ä¿¡æ¯ |
| | | */ |
| | | screen.insertUser = async function (user) { |
| | | /** |
| | | * ä¿ååè¯ |
| | | * @param {string} type - åè¯ç±»å |
| | | * @param {string} code - åè¯ä»£ç |
| | | * @returns {boolean|string} ä¿åç»æ |
| | | */ |
| | | const saveVoucher = async (type, code) => { |
| | | // æ£æ¥å¡çåè¯æ¯å¦éå¤ |
| | | if (type == "200") { |
| | | let cardData = sqliteService.d1_voucher.findByCodeAndType(code, "200"); |
| | | if (cardData.length > 0 && cardData[0].userId != user.userId) { |
| | | //åå¨ä¸è½æ·»å è¿å失败 |
| | | log.info("å¡éå¤"); |
| | | return "localUserAddView.failCardRepeat" |
| | | } |
| | | } |
| | | |
| | | // å½ type 为 "300" æ¶ï¼é¦å
è°ç¨ç¹å®æ¹æ³æ£æ¥æ¯å¦å¯ä»¥ç»§ç»ä¿ååè¯ |
| | | if (type === "300") { |
| | | let preCheckResult = await preSaveCheck(code); // åè®¾è¿æ¯æ¨æå°çéè¦è°ç¨çæ¹æ³ |
| | | if (preCheckResult !== true) { // 妿颿£æ¥ä¸éè¿ï¼åç´æ¥è¿å false |
| | | return preCheckResult; |
| | | } |
| | | code = "/app/data/user/" + user.userId + "/register.jpg" |
| | | } |
| | | |
| | | // æ£æ¥å¯ç åè¯æ¯å¦éå¤ |
| | | if (type == "400") { |
| | | let pwdData = sqliteService.d1_voucher.findByCodeAndType(code, "400"); |
| | | if (pwdData.length > 0 && pwdData[0].userId != user.userId) { |
| | | //åå¨ä¸è½æ·»å è¿å失败 |
| | | log.info("å¯ç éå¤"); |
| | | return "localUserAddView.failPwdRepeat" |
| | | } |
| | | } |
| | | |
| | | let keyId = std.genRandomStr(32); |
| | | |
| | | let extra = type == 300 ? JSON.stringify({ faceType: 0 }) : JSON.stringify({}) |
| | | let voucherRet = await sqliteService.d1_voucher.save({ |
| | | keyId: keyId, |
| | | type: type, |
| | | code: code, |
| | | userId: user.userId, |
| | | extra: extra |
| | | }); |
| | | |
| | | if (voucherRet != 0) { |
| | | // 妿åè¯ä¿å失败ï¼åå é¤å·²ä¿åçç¨æ·ä¿¡æ¯åå¯è½å·²ä¿åçå
¶ä»åè¯ |
| | | await sqliteService.d1_person.deleteByUserId(user.userId); |
| | | await sqliteService.d1_voucher.deleteByUserId(user.userId); |
| | | return false; |
| | | } |
| | | return true; |
| | | }; |
| | | |
| | | /** |
| | | * ä¿ååæ£æ¥ |
| | | * @param {string} code - 人è¸å¾çè·¯å¾ |
| | | * @returns {boolean|string} æ£æ¥ç»æ |
| | | */ |
| | | async function preSaveCheck(code) { |
| | | let ret = driver.face.registerFaceByPicFile(user.userId, code) |
| | | log.info("1注å人è¸,ret:", ret) |
| | | if (ret != 0) { |
| | | return faceService.regErrorEnum.picture[ret + ''] |
| | | } |
| | | //注åæååéè¦å§åæ¥å¾çç§»å¨å° user 对åºç®å½ä¸ |
| | | let src = "/app/data/user/" + user.userId + "/register.jpg" |
| | | std.ensurePathExists(src) |
| | | common.systemBrief('mv ' + code + " " + src) |
| | | return true; |
| | | } |
| | | |
| | | let success = true; |
| | | // ä¿å人è¸åè¯ |
| | | if (success === true && user.face && !(success = await saveVoucher("300", user.face))); |
| | | // ä¿åå¯ç åè¯ |
| | | if (success === true && user.pwd && !(success = await saveVoucher("400", user.pwd))); |
| | | // ä¿åå¡çåè¯ |
| | | if (success === true && user.card && !(success = await saveVoucher("200", user.card))); |
| | | |
| | | if (success === true) { |
| | | //{"id":"423","userId":"423","name":"å¾®å
äºè","idCard":"123","pwd":"251574","card":"123"} |
| | | //ä¿å人åä¿¡æ¯ |
| | | let personRet = await sqliteService.d1_person.save({ |
| | | userId: user.userId, |
| | | name: user.name, |
| | | extra: JSON.stringify({ type: user.type == 1 ? 1 : 0, idCard: user.idCard }) |
| | | }); |
| | | if (personRet != 0) { |
| | | sqliteService.d1_voucher.deleteByUserId(user.userId); |
| | | return "localUserAddView.failRepeat" |
| | | } |
| | | //æ°å¢ä¸æ¡æ°¸ä¹
æé |
| | | sqliteService.d1_permission.save({ permissionId: user.userId, userId: user.userId, timeType: 0 }) |
| | | } else { |
| | | await sqliteService.d1_voucher.deleteByUserId(user.userId); |
| | | } |
| | | |
| | | return success; |
| | | |
| | | } |
| | | |
| | | /** |
| | | * è·åæ¬å°äººåä¿¡æ¯ |
| | | * è·åç¨æ·çåè¯ä¿¡æ¯ï¼å
æ¬èº«ä»½è¯ãå¡çãå¯ç åäººè¸æ°æ® |
| | | * @param {string} userId - ç¨æ·ID |
| | | * @returns {object} ç¨æ·åè¯ä¿¡æ¯ |
| | | */ |
| | | screen.getVoucher = function (userId) { |
| | | // è·åç¨æ·ä¿¡æ¯ |
| | | let person = sqliteService.d1_person.find({ userId: userId }); |
| | | |
| | | if (person.length < 0) { |
| | | return |
| | | } |
| | | |
| | | // è·åå¯ç åè¯ |
| | | let pwd_voucher = sqliteService.d1_voucher.find({ userId: userId, type: "400" })[0] || undefined |
| | | |
| | | // è·åå¡çåè¯ |
| | | let card_voucher = sqliteService.d1_voucher.find({ userId: userId, type: "200" })[0] || undefined |
| | | |
| | | // è·å人è¸åè¯ |
| | | let face_voucher = sqliteService.d1_voucher.find({ userId: userId, type: "300" })[0] || undefined |
| | | |
| | | // è·å身份è¯ä¿¡æ¯ |
| | | let idCard_voucher |
| | | try { |
| | | idCard_voucher = JSON.parse(person[0].extra).idCard |
| | | } catch (error) { |
| | | } |
| | | |
| | | return { |
| | | id: userId, |
| | | idCard: idCard_voucher ? idCard_voucher : undefined, |
| | | card: card_voucher ? card_voucher.code : undefined, |
| | | pwd: pwd_voucher ? pwd_voucher.code : undefined, |
| | | face: face_voucher ? face_voucher.code : undefined, |
| | | type: JSON.parse(person[0].extra).type || 0 |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * è·åç¨æ·å表 |
| | | * æ ¹æ®æ¡ä»¶æ¥è¯¢ç¨æ·åè¡¨ï¼æ¯æå页åæç´¢ |
| | | * @param {number} page - 页ç ï¼é»è®¤0 |
| | | * @param {number} size - æ¯é¡µå¤§å°ï¼é»è®¤6 |
| | | * @param {string} userId - ç¨æ·IDï¼ç¨äºç²¾ç¡®æç´¢ |
| | | * @param {string} name - ç¨æ·å§åï¼ç¨äºæ¨¡ç³æç´¢ |
| | | * @returns {object} ç¨æ·åè¡¨æ°æ®ï¼å
å«åé¡µä¿¡æ¯ |
| | | */ |
| | | screen.getUsers = function (page = 0, size = 6, userId, name) { |
| | | // æç¨æ·IDæå§åæç´¢ |
| | | if (userId || name) { |
| | | // æç¨æ·IDæç´¢ |
| | | let user = sqliteService.d1_person.findByUserId(userId)[0] |
| | | if (user) { |
| | | user.id = user.userId |
| | | return { data: [user], totalPage: 1, totalSize: 1, currentPage: 1 } |
| | | } |
| | | // æç¨æ·å§åæç´¢ |
| | | let users = sqliteService.d1_person.findByName(name) |
| | | if (users && users.length > 0) { |
| | | users.map(v => { |
| | | v.id = v.userId |
| | | }) |
| | | |
| | | /** |
| | | * æ°ç»åå |
| | | * @param {array} arr - æºæ°ç» |
| | | * @param {number} size - åå¤§å° |
| | | * @returns {array} åååçæ°ç» |
| | | */ |
| | | function chunkArray(arr, size) { |
| | | // 妿æ°ç»ä¸ºç©ºæè
大å°ä¸ºé¶ï¼è¿å空æ°ç» |
| | | if (arr.length === 0 || size <= 0) { |
| | | return []; |
| | | } |
| | | const result = []; |
| | | // 使ç¨å¾ªç¯éåæ°ç»ï¼å¹¶æç
§å¤§å°åå² |
| | | for (let i = 0; i < arr.length; i += size) { |
| | | result.push(arr.slice(i, i + size)); // slice æªåæå®èå´çå
ç´ |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | const chunkedArray = chunkArray(users, size); |
| | | return { data: chunkedArray[page], totalPage: Math.ceil(users.length / size), totalSize: users.length, currentPage: page + 1 } |
| | | } |
| | | return { data: [], totalPage: 0, totalSize: 0, currentPage: 1 } |
| | | } |
| | | |
| | | // è·åææç¨æ· |
| | | let userCount = sqliteService.d1_person.count() |
| | | let users = sqliteService.d1_person.findOrderByUserIdAsc({ page, size }) |
| | | if (users.length > 0) { |
| | | users.forEach(element => { element.id = element.userId }); |
| | | } |
| | | // æ»é¡µæ° |
| | | let totalPage = Math.ceil(userCount / size) |
| | | return { data: users, totalPage: totalPage, totalSize: userCount, currentPage: page + 1 } |
| | | } |
| | | |
| | | /** |
| | | * è·åéè¡è®°å½ |
| | | * è·åç¨æ·éè¡è®°å½ï¼æ¯æå页 |
| | | * @param {number} page - 页ç ï¼é»è®¤0 |
| | | * @param {number} size - æ¯é¡µå¤§å°ï¼é»è®¤6 |
| | | * @returns {object} éè¡è®°å½æ°æ®ï¼å
å«åé¡µä¿¡æ¯ |
| | | */ |
| | | screen.getPassRecord = function (page = 0, size = 6) { |
| | | let passCount = sqliteService.d1_pass_record.count() |
| | | let datas = sqliteService.d1_pass_record.findOrderByTimeDesc({ page, size }) |
| | | // æ»é¡µæ° |
| | | let totalPage = Math.ceil(passCount / size) |
| | | return { data: datas, totalPage: totalPage, totalSize: passCount, currentPage: page + 1 } |
| | | } |
| | | |
| | | /** |
| | | * 人è¸å½å
¥å¼å§ |
| | | * å¼å§äººè¸å½å
¥ï¼UIæ§å¶ |
| | | * @param {string} userId - ç¨æ·ID |
| | | */ |
| | | screen.faceEnterStart = function (userId) { |
| | | dxMap.get("UI").put("faceEnterStart", userId) |
| | | driver.face.status(1) |
| | | driver.face.mode(1) |
| | | } |
| | | |
| | | /** |
| | | * 人è¸å½å
¥ç»æ |
| | | * ç»æäººè¸å½å
¥ï¼UIæ§å¶ |
| | | */ |
| | | screen.faceEnterEnd = function () { |
| | | dxMap.get("UI").del("faceEnterStart") |
| | | driver.face.status(0) |
| | | // driver.face.mode(0) |
| | | } |
| | | |
| | | /** |
| | | * è·åå¡å·å¼å§ |
| | | * å¼å§è·åå¡å·ï¼UIæ§å¶ |
| | | */ |
| | | screen.getCardStart = function () { |
| | | dxMap.get("UI").put("getCardStart", true) |
| | | } |
| | | |
| | | /** |
| | | * è·åå¡å·ç»æ |
| | | * ç»æè·åå¡å·ï¼UIæ§å¶ |
| | | */ |
| | | screen.endCardEnd = function () { |
| | | dxMap.get("UI").del("getCardStart") |
| | | } |
| | | |
| | | /** |
| | | * å¼å¯äººè¸è¯å« |
| | | * å¼å§äººè¸è¯å«åè½ |
| | | */ |
| | | screen.faceRecgStart = function () { |
| | | driver.face.status(1) |
| | | driver.face.mode(0) |
| | | } |
| | | |
| | | /** |
| | | * 人è¸è¯å«æå |
| | | * æå人è¸è¯å«åè½ |
| | | */ |
| | | screen.faceRecgPause = function () { |
| | | driver.face.status(0) |
| | | } |
| | | |
| | | /** |
| | | * 人è¸å½å
¥ç»æ |
| | | * å¤ç人è¸å½å
¥ç»æ |
| | | * @param {string} facePic - 人è¸å¾çè·¯å¾ |
| | | */ |
| | | screen.faceEnterResult = function (facePic) { |
| | | if (facePic) { |
| | | faceEnterView.successFlag = true |
| | | // æåï¼æ¾ç¤ºäººè¸ç
§ç |
| | | localUserAddView.addFace(facePic) |
| | | dxui.loadMain(localUserAddView.screenMain) |
| | | faceEnterView.backCb() |
| | | } else { |
| | | // å¤±è´¥ï¼æ¥é |
| | | faceEnterView.timeout() |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * éè¯å«é¡µé¢äººè¸è®¤è¯å¼å§ |
| | | * å¼å§äººè¸è®¤è¯ï¼UIæ§å¶ |
| | | */ |
| | | screen.faceAuthStart = function () { |
| | | dxMap.get("UI").put("faceAuthStart", "Y") |
| | | driver.face.status(1) |
| | | driver.face.mode(0) |
| | | } |
| | | |
| | | /** |
| | | * éè¯å«é¡µé¢äººè¸è®¤è¯ç»æ |
| | | * ç»æäººè¸è®¤è¯ï¼UIæ§å¶ |
| | | */ |
| | | screen.faceAuthEnd = function () { |
| | | dxMap.get("UI").del("faceAuthStart") |
| | | driver.face.status(0) |
| | | } |
| | | |
| | | /** |
| | | * éè¯å«é¡µé¢äººè¸è®¤è¯ç»æ |
| | | * å¤ç人è¸è®¤è¯ç»æ |
| | | * @param {boolean} bool - 认è¯ç»æï¼true表示æåï¼false表示失败 |
| | | */ |
| | | screen.faceAuthResult = function (bool) { |
| | | if (bool) { |
| | | // æåï¼è¿å
¥è®¾ç½®èå |
| | | driver.alsa.play(`/app/code/resource/${config.get("base.language") == "CN" ? "CN" : "EN"}/wav/recg_s.wav`) |
| | | dxui.loadMain(configView.screenMain) |
| | | } else { |
| | | // å¤±è´¥ï¼æ¥é |
| | | driver.alsa.play(`/app/code/resource/${config.get("base.language") == "CN" ? "CN" : "EN"}/wav/recg_f.wav`) |
| | | identityVerificationView.statusPanel.fail() |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * ä¿åé
ç½® |
| | | * ä¿åç³»ç»é
ç½® |
| | | * @param {object} configAll - é
置对象 |
| | | * @returns {boolean} ä¿åç»æ |
| | | */ |
| | | screen.saveConfig = function (configAll) { |
| | | // ç´æ¥è°ç¨é
ç½®éªè¯åä¿å彿° |
| | | return configService.configVerifyAndSave(configAll) |
| | | } |
| | | |
| | | /** |
| | | * è·åé
ç½® |
| | | * è·åç³»ç»é
ç½® |
| | | * @returns {object} é
置对象 |
| | | */ |
| | | screen.getConfig = function () { |
| | | let config1 = config.getAll() |
| | | return config1 |
| | | } |
| | | |
| | | /** |
| | | * å¯ç éè¡ |
| | | * 使ç¨å¯ç è¿è¡éè¡éªè¯ |
| | | * @param {string} pwd - å¯ç |
| | | * @returns {boolean} éªè¯ç»æï¼true表示æåï¼false表示失败 |
| | | */ |
| | | screen.pwdAccess = function (pwd) { |
| | | // æ£æ¥æ°æ®åºä¸çåºæ¥å¼ä»å¯ç |
| | | try { |
| | | const passwords = sqliteService.d1_emergency_password.findAll({ status: 1 }) |
| | | for (let i = 0; i < passwords.length; i++) { |
| | | if (passwords[i].password === pwd) { |
| | | return true |
| | | } |
| | | } |
| | | } catch (error) { |
| | | logger.error('æ£æ¥åºæ¥å¼ä»å¯ç 失败:', error) |
| | | } |
| | | |
| | | // å
¶ä»å¯ç éªè¯é»è¾ |
| | | bus.fire("access", { data: { type: "400", code: pwd } }) |
| | | return false |
| | | } |
| | | |
| | | /** |
| | | * 忢ç½ç»ç±»å |
| | | * 忢ç½ç»è¿æ¥ç±»å |
| | | * @param {object} data - ç½ç»ç±»åæ°æ® |
| | | */ |
| | | screen.switchNetworkType = function (data) { |
| | | bus.fire("switchNetworkType", data) |
| | | } |
| | | |
| | | /** |
| | | * è·åWiFiå表 |
| | | * è·åå¯ç¨çWiFiç½ç»å表 |
| | | */ |
| | | screen.netGetWifiSsidList = function () { |
| | | bus.fire("netGetWifiSsidList") |
| | | } |
| | | |
| | | /** |
| | | * WiFiåè¡¨æ°æ® |
| | | * å¤çWiFiåè¡¨æ°æ® |
| | | * @param {array} data - WiFiåè¡¨æ°æ® |
| | | */ |
| | | screen.netWifiSsidList = function (data) { |
| | | if (data.length == 0 && config.get("net.type") == 2) { |
| | | //æ çº¿ç½ |
| | | std.setTimeout(() => { |
| | | screen.netGetWifiSsidList() |
| | | }, 1000) |
| | | return |
| | | } |
| | | networkSettingView.wifiListData = data |
| | | networkSettingView.wifiList.refresh() |
| | | } |
| | | |
| | | /** |
| | | * è¿æ¥WiFi |
| | | * è¿æ¥å°æå®çWiFiç½ç» |
| | | * @param {string} ssid - WiFiåç§° |
| | | * @param {string} psk - WiFiå¯ç |
| | | * @returns {boolean} è¿æ¥ç»æ |
| | | */ |
| | | screen.netConnectWifiSsid = function (ssid, psk) { |
| | | return driver.net.netConnectWifiSsid(ssid, psk) |
| | | } |
| | | |
| | | /** |
| | | * è·åå¡å· |
| | | * å¤çè·åå°çå¡å· |
| | | * @param {string} card - å¡å· |
| | | */ |
| | | screen.getCard = function (card) { |
| | | localUserAddView.cardBoxInput.text(card) |
| | | } |
| | | |
| | | /** |
| | | * äºä»¶æ»çº¿äºä»¶å¤ç |
| | | * 注ååå¤çç³»ç»äºä»¶ |
| | | */ |
| | | function busEvents() { |
| | | // ç½ç»ç¶æ |
| | | bus.on('netStatus', (data) => { |
| | | console.log(JSON.stringify(data)); |
| | | let type = config.get("net.type") |
| | | if (data.connected) { |
| | | let ip = net.getModeByCard(type).param.ip |
| | | mainView.overlayIpLbl.text("IP:" + ip) |
| | | config.setAndSave("net.ip", ip) |
| | | config.setAndSave("net.mac", net.getMacaddr(type)) |
| | | topView.ethConnectState(true, type) |
| | | networkSettingView.netInfo[10].label.dataI18n = "networkSettingView.networkConnected" |
| | | } else { |
| | | topView.ethConnectState(false, type) |
| | | networkSettingView.netInfo[10].label.dataI18n = "networkSettingView.networkUnconnected" |
| | | } |
| | | i18n.refreshObj(networkSettingView.netInfo[10].label) |
| | | }) |
| | | |
| | | // mqttè¿æ¥ç¶æ |
| | | bus.on('mqttStatus', (data) => { |
| | | if (data == "connected") { |
| | | topView.mqttConnectState(true) |
| | | } else { |
| | | topView.mqttConnectState(false) |
| | | } |
| | | }) |
| | | |
| | | // 人è¸å½å
¥å¼å§ |
| | | bus.on("beginAddFace", screen.beginAddFace) |
| | | |
| | | // 人è¸å½å
¥ç»æ |
| | | bus.on("faceEnterResult", screen.faceEnterResult) |
| | | |
| | | // éåºå±ä¿ |
| | | bus.on("exitIdle", screen.exitIdle) |
| | | |
| | | // è·åWiFiå表 - ç§»é¤äºä»¶çå¬å¨ï¼é¿å
æ éå¾ªç¯ |
| | | |
| | | // è·åå¡å· |
| | | bus.on("getCard", screen.getCard) |
| | | |
| | | // 人è¸è®¤è¯ç»æ |
| | | bus.on("faceAuthResult", screen.faceAuthResult) |
| | | |
| | | // éè¡ç»æ |
| | | bus.on("accessRes", screen.accessRes) |
| | | |
| | | // è·è¸ªæ´æ° |
| | | // bus.on("trackUpdate", screen.trackUpdate) |
| | | |
| | | // éèSN |
| | | bus.on("hideSn", screen.hideSn) |
| | | |
| | | // 忢è¯è¨ |
| | | bus.on("changeLanguage", screen.changeLanguage) |
| | | |
| | | // éèIP |
| | | bus.on("hideIp", screen.hideIp) |
| | | |
| | | // å·æ°å±å¹ç®¡çå¨ |
| | | bus.on("screenManagerRefresh", screen.screenManagerRefresh) |
| | | |
| | | // WiFiåè¡¨æ°æ® |
| | | bus.on("netWifiSsidList", screen.netWifiSsidList) |
| | | |
| | | // APPæ¨¡å¼ |
| | | bus.on("appMode", screen.appMode) |
| | | |
| | | // å级 |
| | | bus.on("upgrade", screen.upgrade) |
| | | |
| | | // å¡çéç½® |
| | | // bus.on("cardReset", screen.cardReset) |
| | | |
| | | // è·è¸ªç»æ |
| | | bus.on("trackResult", screen.trackResult) |
| | | bus.on("showAccessResult", screen.showAccessResult) |
| | | } |
| | | |
| | | /** |
| | | * å¡çéç½®å®æ¶å¨ |
| | | */ |
| | | let setTimeout |
| | | |
| | | /** |
| | | * å¡çéç½® |
| | | * å¤çå¡çéç½®é»è¾ |
| | | * @param {object} msg - æ¶æ¯å¯¹è±¡ |
| | | */ |
| | | screen.cardReset = function (msg) { |
| | | if (msg.type == 2 && msg.status == 3) { |
| | | setTimeout = std.setTimeout(() => { |
| | | driver.net.cardReset() |
| | | }, 30 * 1000); |
| | | } else { |
| | | if (setTimeout) { |
| | | std.clearTimeout(setTimeout) |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å¼å§æ³¨åäººè¸ |
| | | * å¤çäººè¸æ³¨åå¼å§é»è¾ |
| | | * @param {object} data - äººè¸æ°æ®å¯¹è±¡ |
| | | */ |
| | | screen.beginAddFace = function (data) { |
| | | log.info('screen.beginAddFace', JSON.stringify(data)); |
| | | |
| | | if (!data.fileName) { |
| | | return screen.faceEnterResult() |
| | | } |
| | | |
| | | driver.alsa.play(`/app/code/resource/${config.get("base.language") == "CN" ? "CN" : "EN"}/wav/recognition_s.wav`) |
| | | faceEnterView.statusPanel.success("faceEnterView.recogSuccess") |
| | | // ä¿åå¾çå°æ¬å° |
| | | let src = `/app/data/user/register.jpg` |
| | | common.systemBrief(`mv ${data.fileName} ${src}`) |
| | | common.systemBrief(`rm -rf /app/data/user/temp/*`) |
| | | |
| | | screen.faceEnterResult(src) |
| | | } |
| | | |
| | | /** |
| | | * éè¡ç»æ |
| | | * å¤çéè¡æåæå¤±è´¥çç»æ |
| | | * @param {boolean} bool - éè¡ç»æï¼true表示æåï¼false表示失败 |
| | | */ |
| | | screen.accessRes = function (bool) { |
| | | if (bool) { |
| | | if (mainView.smallStatusPanel && mainView.smallStatusPanel.success) { |
| | | mainView.smallStatusPanel.success() |
| | | } |
| | | } else { |
| | | if (mainView.smallStatusPanel && mainView.smallStatusPanel.fail) { |
| | | mainView.smallStatusPanel.fail() |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 忢APPæ¨¡å¼ |
| | | * 忢åºç¨ç¨åºæ¾ç¤ºæ¨¡å¼ï¼æ 忍¡å¼æç®æ´æ¨¡å¼ï¼ |
| | | * @param {number} mode - 模å¼å¼ï¼0表示æ 忍¡å¼ï¼1è¡¨ç¤ºç®æ´æ¨¡å¼ |
| | | */ |
| | | screen.appMode = function (mode) { |
| | | if (mode == 0) { |
| | | // 忢尿 忍¡å¼ |
| | | } else if (mode == 1) { |
| | | // 忢å°ç®æ´æ¨¡å¼ |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ´æ°äººè¸è·è¸ªæ¡ |
| | | * æ´æ°äººè¸è·è¸ªæ¡çä½ç½®åç¶æ |
| | | * @param {object} data - åæ ä¿¡æ¯ |
| | | * @param {number} id - face_idï¼ç¨äºå
³èè¯å«å§åç¨ |
| | | * @param {boolean} isLiving - æ¯å¦æ´»ä½ |
| | | */ |
| | | screen.trackUpdate = function (data, id, isLiving) { |
| | | let item = mainView.trackFaces[0] |
| | | for (let i = 0; i < 10; i++) { |
| | | let ele = mainView.trackFaces[i] |
| | | if (ele.face_id == id) { |
| | | item = ele |
| | | break |
| | | } |
| | | } |
| | | item.face_id = id |
| | | |
| | | if (item && item.timer) { |
| | | std.clearTimeout(item.timer) |
| | | item.timer = null |
| | | } |
| | | |
| | | item.timer = std.setTimeout(() => { |
| | | item.trackFace.hide() |
| | | // item.trackFaceName.hide() |
| | | if (item.timer) { |
| | | std.clearTimeout(item.timer) |
| | | item.timer = null |
| | | } |
| | | }, 300) |
| | | |
| | | let edge = data.w > data.h ? data.w : data.h |
| | | let offset = Math.abs(data.w - data.h) / 2 |
| | | item.trackFace.show() |
| | | item.trackFace.setSize(edge, edge) |
| | | item.trackFace.radius(edge / 2) |
| | | if (data.w > data.h) { |
| | | item.trackFace.setPos(data.x, data.y - offset) |
| | | } else { |
| | | item.trackFace.setPos(data.x - offset, data.y) |
| | | } |
| | | |
| | | item.trackFaceName.text(" ") |
| | | |
| | | if (item.result && item.result.result === true && item.result.id == id) { |
| | | item.trackFace.setBorderColor(viewUtils.color.success) |
| | | let user = sqliteService.d1_person.findByUserId(item.result.userId)[0] |
| | | item.trackFaceName.text(user ? user.name : "") |
| | | } else if (item.result && item.result.result === false && item.result.id == id) { |
| | | item.trackFace.setBorderColor(viewUtils.color.fail) |
| | | } else if (isLiving) { |
| | | item.trackFace.setBorderColor(0xf3e139) |
| | | } else { |
| | | item.trackFace.setBorderColor(0xffffff) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 认è¯ç»æ |
| | | * å¤ç人è¸è¯å«è®¤è¯ç»æ |
| | | * @param {object} data - 认è¯ç»ææ°æ® |
| | | */ |
| | | screen.trackResult = function (data) { |
| | | for (let i = 0; i < 10; i++) { |
| | | let ele = mainView.trackFaces[i] |
| | | if (ele.face_id == data.id) { |
| | | ele.result = data |
| | | return |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * éèSNæé® |
| | | * æ§å¶SNæé®çæ¾ç¤ºåéè |
| | | * @param {boolean} bool - æ¯å¦æ¾ç¤ºï¼true表示æ¾ç¤ºï¼false表示éè |
| | | */ |
| | | screen.hideSn = function (bool) { |
| | | if (bool) { |
| | | mainView.bottomSnBtn.show() |
| | | } else { |
| | | mainView.bottomSnBtn.hide() |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * éèIPæ ç¾ |
| | | * æ§å¶IPæ ç¾çæ¾ç¤ºåéè |
| | | * @param {boolean} bool - æ¯å¦æ¾ç¤ºï¼true表示æ¾ç¤ºï¼false表示éè |
| | | */ |
| | | screen.hideIp = function (bool) { |
| | | // ä¸åéè¦æ¤å½æ°ï¼å 为IPä¿¡æ¯ç°å¨æ¾ç¤ºå¨åéæè¦çå¾å±ä¸ |
| | | } |
| | | |
| | | /** |
| | | * éèåºé¨æ¡ |
| | | * æ§å¶åºé¨æ¡çæ¾ç¤ºåéè |
| | | * @param {boolean} bool - æ¯å¦æ¾ç¤ºï¼true表示æ¾ç¤ºï¼false表示éè |
| | | */ |
| | | screen.hideBottomBox = function (bool) { |
| | | if (bool) { |
| | | mainView.bottomBox.hide() |
| | | } else { |
| | | mainView.bottomBox.show() |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 忢è¯è¨ |
| | | * åæ¢ç³»ç»è¯è¨è®¾ç½® |
| | | */ |
| | | screen.changeLanguage = function () { |
| | | i18n.setLanguage(screen.getConfig()['base.language']) |
| | | } |
| | | |
| | | /** |
| | | * å级æç¤º |
| | | * æ¾ç¤ºç³»ç»å级æç¤ºä¿¡æ¯ |
| | | * @param {object} data - å级信æ¯å¯¹è±¡ï¼å
å«titleåcontent |
| | | */ |
| | | screen.upgrade = function (data) { |
| | | const { title, content } = data |
| | | viewUtils.confirmOpen(title, content) |
| | | } |
| | | |
| | | /** |
| | | * æ¾ç¤ºéè¡ç»æå¼¹çª |
| | | * @param {object} data - éè¡ç»ææ°æ® |
| | | * @param {boolean} data.faceAuth - 人è¸è¯å«æ¯å¦éè¿ |
| | | * @param {boolean} data.gasConcentration - æ°ä½æµåº¦æ¯å¦åæ ¼ |
| | | * @param {boolean} data.accessAllowed - æ¯å¦å
许éè¡ |
| | | * @param {string} data.message - å¼¹çªæ¶æ¯ |
| | | */ |
| | | screen.showAccessResult = function (data) { |
| | | // // æ¾ç¤ºç¶æé¢æ¿ï¼3ç§åèªå¨å
³é |
| | | // if (data.accessAllowed) { |
| | | // mainView.statusPanel.success(data.message) |
| | | // } else { |
| | | // mainView.statusPanel.fail(data.message) |
| | | // } |
| | | |
| | | |
| | | // æ¾ç¤ºå°åç¶æé¢æ¿ï¼3ç§åèªå¨å
³é |
| | | if (data.accessAllowed) { |
| | | mainView.smallStatusPanel.success(data.message) |
| | | } else { |
| | | mainView.smallStatusPanel.fail(data.message) |
| | | } |
| | | } |
| | | |
| | | export default screen |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | /** |
| | | * é¨ç¦éè¡æå¡æ¨¡å |
| | | * å¤çé¨ç¦éè¡ç¸å
³çä¸å¡é»è¾ï¼å
æ¬äººè¸/å¯ç ç½ååæ ¡éªãæé夿ãéè¡è®°å½ä¿åç |
| | | */ |
| | | import logger from "../../dxmodules/dxLogger.js" |
| | | import std from "../../dxmodules/dxStd.js" |
| | | import config from "../../dxmodules/dxConfig.js" |
| | | import common from "../../dxmodules/dxCommon.js" |
| | | import map from '../../dxmodules/dxMap.js' |
| | | import bus from '../../dxmodules/dxEventBus.js' |
| | | import driver from "../driver.js" |
| | | import mqttService from "./mqttService.js" |
| | | import sqliteService from "./sqliteService.js" |
| | | import utils from '../common/utils/utils.js' |
| | | import http from "../../dxmodules/dxHttp.js" |
| | | import grainService from './grainService.js' |
| | | const accessService = {} |
| | | |
| | | /** |
| | | * å°åè¿å¶æ°è½¬æ¢ä¸ºå°ç«¯åºåå
è¿å¶å符串 |
| | | * @param {number} decimalNumber - åè¿å¶æ° |
| | | * @param {number} byteSize - åèå¤§å° |
| | | * @returns {string} å°ç«¯åºåå
è¿å¶å符串 |
| | | */ |
| | | function decimalToLittleEndianHex(decimalNumber, byteSize) { |
| | | const littleEndianBytes = []; |
| | | for (let i = 0; i < byteSize; i++) { |
| | | littleEndianBytes.push(decimalNumber & 0xFF); |
| | | decimalNumber >>= 8; // ç¸å½äºé¤ä»¥256 |
| | | } |
| | | const littleEndianHex = littleEndianBytes |
| | | .map((byte) => byte.toString(16).padStart(2, '0')) |
| | | .join(''); |
| | | return littleEndianHex; |
| | | } |
| | | |
| | | /** |
| | | * å°æ°æ®å
转æ¢ä¸ºåç¬¦ä¸²æ ¼å¼ |
| | | * @param {object} pack - æ°æ®å
对象 |
| | | * @returns {string} 转æ¢åçå符串 |
| | | */ |
| | | function pack2str(pack) { |
| | | pack.data = (!pack.data) ? [] : pack.data.match(/.{2}/g) |
| | | let len = decimalToLittleEndianHex(pack.data.length, 2) |
| | | let str = "55aa" + pack.cmd + pack.result + len + pack.data.join('') |
| | | let crc = common.calculateBcc([0x55, 0xaa, parseInt(pack.cmd, 16), parseInt(pack.result, 16), pack.data.length % 256, pack.data.length / 256].concat(pack.data.map(v => parseInt(v, 16)))) |
| | | return str + crc.toString(16).padStart(2, '0') |
| | | } |
| | | |
| | | /** |
| | | * 人è¸/å¯ç ç½ååæ ¡éª |
| | | * @param {object} data - éè¡æ°æ®ï¼å
å«typeï¼ç å¶ï¼åcodeï¼ç å
å®¹ï¼ |
| | | * @param {string} fileName - éè¡å¾çæä»¶è·¯å¾ |
| | | * @param {boolean|undefined} similarity - ç¸ä¼¼åº¦éªè¯ç»æï¼false表示éªè¯å¤±è´¥ |
| | | * @returns {number|string|boolean} -1ï¼åæ°é误ï¼ï¼0ï¼éè¡æåï¼ï¼1ï¼å¨çº¿éªè¯ï¼ï¼stringï¼æ ¡éªå¤±è´¥çåå ï¼ï¼falseï¼éè¡å éï¼ |
| | | */ |
| | | accessService.access = function (data, fileName, similarity) { |
| | | // éè¡å éï¼é²æ¢éå¤éªè¯ |
| | | let lockMap = map.get("access_lock") |
| | | if (lockMap.get("access_lock")) { |
| | | logger.error("[access]: éè¡å éï¼è¯·ç¨ååè¯") |
| | | return false |
| | | } |
| | | lockMap.put("access_lock", true) |
| | | |
| | | try { |
| | | // è®°å½éè¡æ¶é´æ³ |
| | | data.time = Math.floor(Date.parse(new Date()) / 1000) |
| | | |
| | | // æ ¹æ®codeæ¥è¯¢åè¯ |
| | | let res |
| | | if (data.type == "300") { |
| | | // 人è¸ç±»åï¼ä½¿ç¨userIdæ¥è¯¢ |
| | | res = sqliteService.d1_voucher.findByUserIdAndType(data.code, data.type) |
| | | } else { |
| | | // å
¶ä»ç±»åï¼ä½¿ç¨codeæ¥è¯¢ |
| | | res = sqliteService.d1_voucher.findByCodeAndType(data.code, data.type) |
| | | } |
| | | |
| | | // æé认è¯ç»æ |
| | | let ret = true |
| | | // æ¯å¦æ¯éç人 |
| | | let isStranger = false |
| | | |
| | | if (similarity === false) { |
| | | // 妿ç¸ä¼¼åº¦éªè¯å¤±è´¥ï¼åä¸è¿è¡è®¤è¯ |
| | | ret = false |
| | | isStranger = true |
| | | } else { |
| | | // éªè¯åè¯æ¯å¦åå¨ |
| | | if (res.length == 0) { |
| | | logger.error("[access]: éè¡å¤±è´¥ï¼æ²¡æ¥è¯¢å°åè¯ï¼") |
| | | ret = false |
| | | isStranger = true |
| | | } else { |
| | | // åè¯åå¨ï¼è·åç¨æ·ä¿¡æ¯ |
| | | data.userId = res[0].userId |
| | | data.keyId = res[0].id |
| | | |
| | | // æ ¹æ®userIdæ¥è¯¢äººåä¿¡æ¯ |
| | | res = sqliteService.d1_person.findByUserId(data.userId) |
| | | if (res.length == 0) { |
| | | logger.error("[access]: éè¡å¤±è´¥ï¼æ²¡æ¥è¯¢å°äººåï¼") |
| | | ret = false |
| | | isStranger = true |
| | | } else { |
| | | // è·å人åå§åã身份è¯å·å身份类å |
| | | let idCard |
| | | let userType = 0 |
| | | try { |
| | | idCard = JSON.parse(res[0].extra).idCard |
| | | userType = JSON.parse(res[0].extra).type || 0 |
| | | } catch (error) { |
| | | logger.error("æ 身份è¯å·æç±»å") |
| | | } |
| | | data.extra = { name: res[0].name, idCard: idCard, type: userType } |
| | | } |
| | | |
| | | // å¤çå人认è¯ä¿¡æ¯ |
| | | if (data.dualAuthInfo) { |
| | | logger.info("[access]: å¤çå人认è¯ä¿¡æ¯: " + JSON.stringify(data.dualAuthInfo)) |
| | | // åå¨ç¬¬ä¸ç¨æ·ä¿¡æ¯ |
| | | let firstUserId = data.dualAuthInfo.firstUserId |
| | | // æ¥è¯¢ç¬¬ä¸ç¨æ·ç详ç»ä¿¡æ¯ |
| | | let res1 = sqliteService.d1_person.findByUserId(firstUserId) |
| | | if (res1.length > 0) { |
| | | // è·å第ä¸ç¨æ·çå§åã身份è¯å·å身份类å |
| | | let idCard1 |
| | | let firstUserType = 0 |
| | | try { |
| | | idCard1 = JSON.parse(res1[0].extra).idCard |
| | | firstUserType = JSON.parse(res1[0].extra).type || 0 |
| | | } catch (error) { |
| | | logger.error("æ 第ä¸ç¨æ·èº«ä»½è¯å·æç±»å") |
| | | } |
| | | data.userId = firstUserId |
| | | data.extra = { name: res1[0].name, idCard: idCard1, type: firstUserType } |
| | | } else { |
| | | // å¦ææ²¡ææ¥è¯¢å°ç¬¬ä¸ç¨æ·ä¿¡æ¯ï¼ä½¿ç¨é»è®¤å¼ |
| | | data.userId = firstUserId |
| | | data.extra = { name: data.dualAuthInfo.firstUserName, idCard: "", type: 0 } |
| | | } |
| | | // åå¨ç¬¬äºç¨æ·ä¿¡æ¯ |
| | | data.userId2 = data.dualAuthInfo.secondUserId |
| | | // æ¥è¯¢ç¬¬äºç¨æ·ç详ç»ä¿¡æ¯ |
| | | let res2 = sqliteService.d1_person.findByUserId(data.dualAuthInfo.secondUserId) |
| | | if (res2.length > 0) { |
| | | // è·å第äºç¨æ·çå§åå身份è¯å· |
| | | let idCard2 |
| | | let secondUserType = 0 |
| | | try { |
| | | idCard2 = JSON.parse(res2[0].extra).idCard |
| | | secondUserType = JSON.parse(res2[0].extra).type || 0 |
| | | } catch (error) { |
| | | logger.error("æ 第äºç¨æ·èº«ä»½è¯å·æç±»å") |
| | | } |
| | | data.extra2 = { name: res2[0].name, idCard: idCard2 } |
| | | // åå¨ç¬¬äºç¨æ·çæéIDï¼èº«ä»½ç±»åï¼ |
| | | data.permissionId2 = secondUserType.toString() |
| | | } else { |
| | | // å¦ææ²¡ææ¥è¯¢å°ç¬¬äºç¨æ·ä¿¡æ¯ï¼ä½¿ç¨é»è®¤å¼ |
| | | data.extra2 = { name: data.dualAuthInfo.secondUserName, idCard: "" } |
| | | data.permissionId2 = "" |
| | | } |
| | | // å¤ç第ä¸ç¨æ·ç人è¸å¾ç |
| | | if (data.firstUserFileName) { |
| | | let firstUserSrc = `/app/data/passRecord/${firstUserId}_${data.time}_1.jpg` |
| | | std.ensurePathExists(firstUserSrc) // ç¡®ä¿ç®å½åå¨ |
| | | if (std.exist(data.firstUserFileName)) { |
| | | // ç§»å¨å¾çå°æå®ç®å½ |
| | | common.systemBrief(`mv ${data.firstUserFileName} ${firstUserSrc}`) |
| | | // æ´æ°dataä¸çcode为第ä¸ç¨æ·çå¾çè·¯å¾ |
| | | data.code = firstUserSrc |
| | | } |
| | | } |
| | | // å¤ç第äºç¨æ·ç人è¸å¾ç |
| | | if (fileName) { |
| | | let secondUserSrc = `/app/data/passRecord/${data.userId2}_${data.time}_2.jpg` |
| | | std.ensurePathExists(secondUserSrc) // ç¡®ä¿ç®å½åå¨ |
| | | if (std.exist(fileName)) { |
| | | // ç§»å¨å¾çå°æå®ç®å½ |
| | | common.systemBrief(`mv ${fileName} ${secondUserSrc}`) |
| | | // æ´æ°dataä¸çcode2为第äºç¨æ·çå¾çè·¯å¾ |
| | | data.code2 = secondUserSrc |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // éªè¯æé |
| | | if (ret) { |
| | | // æ ¹æ®userIdæ¥è¯¢æé |
| | | res = sqliteService.d1_permission.findByUserId(data.userId) |
| | | if (res && res.length > 0 && judgmentPermission(res)) { |
| | | logger.info("[access]: æé认è¯éè¿") |
| | | ret = true |
| | | // åå¨ç¨æ·èº«ä»½ç±»åä½ä¸ºæéIDï¼æ¬ç³»ç»ä¸èº«ä»½å³æéï¼ |
| | | let userType = 0 |
| | | try { |
| | | if (data.extra) { |
| | | userType = data.extra.type || 0 |
| | | } else { |
| | | // 仿°æ®åºæ¥è¯¢ç¨æ·ä¿¡æ¯è·å身份类å |
| | | let userRes = sqliteService.d1_person.findByUserId(data.userId) |
| | | if (userRes && userRes.length > 0) { |
| | | userType = JSON.parse(userRes[0].extra).type || 0 |
| | | } |
| | | } |
| | | } catch (error) { |
| | | logger.error("è§£æç¨æ·ç±»å失败") |
| | | } |
| | | data.permissionId = userType.toString() |
| | | // æå人è¸è®¤è¯åè½ |
| | | driver.face.status(false) |
| | | logger.info("[access]: æå人è¸è®¤è¯åè½") |
| | | } else { |
| | | logger.info("[access]: æ æé") |
| | | ret = false |
| | | } |
| | | } |
| | | |
| | | // æ æéæ¶ï¼å°è¯å¨çº¿éªè¯ |
| | | if (!ret && config.get('mqtt.onlinecheck') == 1 && driver.mqtt.getStatus()) { |
| | | logger.info("[access]: æ æéï¼èµ°å¨çº¿éªè¯") |
| | | let serialNo = std.genRandomStr(10) |
| | | driver.mqtt.send("access_device/v2/event/access_online", JSON.stringify(mqttService.mqttReply(serialNo, data, mqttService.CODE.S_000))) |
| | | driver.alsa.play(`/app/code/resource/${config.get("base.language") == "CN" ? "CN" : "EN"}/wav/verify.wav`) |
| | | |
| | | // çå¾
å¨çº¿éªè¯ç»æ |
| | | let payload = driver.mqtt.getOnlinecheck() |
| | | if (payload && payload.serialNo == serialNo && payload.code == '000000') { |
| | | ret = true |
| | | // æå人è¸è®¤è¯åè½ |
| | | driver.face.status(false) |
| | | logger.info("[access]: æå人è¸è®¤è¯åè½") |
| | | } else { |
| | | logger.info("[access]: å¨çº¿éªè¯å¤±è´¥") |
| | | ret = false |
| | | } |
| | | } |
| | | } |
| | | |
| | | // ç¡®å®è¯é³æä»¶åç§° |
| | | let alsaFile = (data.type).toString().startsWith("10") ? '10x' : data.type |
| | | |
| | | //æå人è¸è®¤è¯åè½ |
| | | |
| | | |
| | | if (ret == true) { |
| | | // éªè¯æ°ä½æµåº¦ |
| | | grainService.checkGasConcentration(function() { |
| | | // ä»åå¨çæ°ä½æ°æ®ä¸è·åéªè¯ç»æ |
| | | const gasData = grainService.getGasData() |
| | | |
| | | if(gasData && gasData.data && gasData.data.status === "0") { |
| | | logger.info("[access]: æ°ä½æµåº¦éªè¯åæ ¼") |
| | | // éè¡æåå¤ç |
| | | driver.screen.accessSuccess() |
| | | logger.info("[access]: éè¡æå") |
| | | |
| | | // æ¾ç¤ºéè¡æåç»æ |
| | | bus.fire("showAccessResult", { |
| | | faceAuth: true, |
| | | gasConcentration: true, |
| | | accessAllowed: true, |
| | | message: "*ä»å
æ°ä½æµåº¦åæ ¼ï¼å
许éè¡*" |
| | | }) |
| | | |
| | | // 触åéè¡æåäºä»¶ï¼éç¥UIæ´æ° |
| | | bus.fire("accessSuccess", { data: data, fileName: fileName }) |
| | | driver.alsa.play(`/app/code/resource/${config.get("base.language") == "CN" ? "CN" : "EN"}/wav/access_s.wav`) |
| | | driver.gpio.open() // å¼é¨ |
| | | savePassPic(data, fileName) // ä¿åéè¡å¾ç |
| | | reply(data, true) // 䏿¥éè¡è®°å½ |
| | | } else { |
| | | logger.info("[access]: æ°ä½æµåº¦éªè¯ä¸åæ ¼") |
| | | // éè¡å¤±è´¥å¤ç |
| | | driver.screen.accessFail() |
| | | logger.error("[access]: éè¡å¤±è´¥") |
| | | // 触åå¤±è´¥å¼¹çª |
| | | bus.fire("showAccessResult", { |
| | | faceAuth: true, |
| | | gasConcentration: false, |
| | | accessAllowed: false, |
| | | message: "*ä»å
æ°ä½æµåº¦ä¸åæ ¼ï¼ç¦æ¢éè¡*" |
| | | }) |
| | | if (utils.isEmpty(similarity)) { |
| | | driver.alsa.play(`/app/code/resource/${config.get("base.language") == "CN" ? "CN" : "EN"}/wav/access_f.wav`) |
| | | } |
| | | // if (isStranger && !config.get("sys.strangerImage")) { |
| | | // // éç人ä¸ä¿åç
§ç |
| | | // } else { |
| | | // savePassPic(data, fileName) |
| | | // } |
| | | savePassPic(data, fileName) |
| | | // æ·»å æ°ä½æµåº¦å¤±è´¥ä¿¡æ¯ |
| | | data.message = "æ°ä½æµåº¦ä¸åæ ¼" |
| | | reply(data, false) // 䏿¥éè¡è®°å½ |
| | | } |
| | | }) |
| | | |
| | | } else { |
| | | // éè¡å¤±è´¥å¤ç |
| | | driver.screen.accessFail() |
| | | logger.error("[access]: éè¡å¤±è´¥") |
| | | // 触åå¤±è´¥å¼¹çª |
| | | bus.fire("showAccessResult", { |
| | | faceAuth: true, |
| | | gasConcentration: false, |
| | | accessAllowed: false, |
| | | message: "*æé认è¯å¤±è´¥ï¼ç¦æ¢éè¡*" |
| | | }) |
| | | if (utils.isEmpty(similarity)) { |
| | | driver.alsa.play(`/app/code/resource/${config.get("base.language") == "CN" ? "CN" : "EN"}/wav/recg_f.wav`) |
| | | } |
| | | // if (isStranger && !config.get("sys.strangerImage")) { |
| | | // // éç人ä¸ä¿åç
§ç |
| | | // } else { |
| | | // savePassPic(data, fileName) |
| | | // } |
| | | savePassPic(data, fileName) |
| | | |
| | | reply(data, false) // 䏿¥éè¡è®°å½ |
| | | } |
| | | } catch (error) { |
| | | logger.error(error) |
| | | } |
| | | |
| | | // è¯é³ææ¥éè¦æ¶é´ï¼æä»¥å»¶è¿1ç§è§£é |
| | | std.sleep(1000) |
| | | lockMap.put("access_lock", false) |
| | | logger.error("[access]: è§£éæå") |
| | | // 触åéè¡è§£é宿äºä»¶ï¼éç¥UIéç½® |
| | | // bus.fire("accessUnlockComplete") |
| | | } |
| | | |
| | | /** |
| | | * ä¿åéè¡å¾ç |
| | | * @param {object} data - éè¡æ°æ® |
| | | * @param {string} fileName - å¾çæä»¶è·¯å¾ |
| | | */ |
| | | function savePassPic(data, fileName) { |
| | | if (data.type == "300") { // ä»
å¤ç人è¸ç±»å |
| | | // 妿æ¯å人认è¯ï¼å·²ç»å¨å¤çå人认è¯ä¿¡æ¯æ¶ä¿åäºå¾çï¼è¿éè·³è¿ |
| | | if (data.dualAuthInfo) { |
| | | return |
| | | } |
| | | let src = `/app/data/passRecord/${data.userId}_${data.time}.jpg` |
| | | std.ensurePathExists(src) // ç¡®ä¿ç®å½åå¨ |
| | | if (std.exist(fileName)) { |
| | | // ç§»å¨å¾çå°æå®ç®å½ |
| | | common.systemBrief(`mv ${fileName} ${src}`) |
| | | // åªæ¸
çåå§ä¸´æ¶å¾çæä»¶ï¼ä»¥æ¶é´æ³å½åçæä»¶ï¼ï¼ä¿çè°æ´åçå¾çæä»¶ |
| | | common.systemBrief(`rm -rf /app/data/user/temp/[0-9]*.jpg`) |
| | | // æ´æ°dataä¸çcode为å¾çè·¯å¾ |
| | | data.code = src |
| | | } else { |
| | | logger.error("[access]: éè¡å¤±è´¥ï¼å¾çä¸åå¨ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼" + fileName) |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªæéæ¶é´æ¯å¦å¯ä»¥éè¡ |
| | | * @param {array} permissions - æéè®°å½æ°ç» |
| | | * @returns {boolean} true表示ææéï¼falseè¡¨ç¤ºæ æé |
| | | */ |
| | | function judgmentPermission(permissions) { |
| | | let currentTime = Math.floor(Date.now() / 1000) |
| | | for (let permission of permissions) { |
| | | if (permission.timeType == 0) { |
| | | // æ°¸ä¹
æé |
| | | return true |
| | | } else if (permission.beginTime <= currentTime && currentTime <= permission.endTime) { |
| | | if (permission.timeType == 1) { |
| | | // æ¶é´æ®µæé |
| | | return true |
| | | } |
| | | if (permission.timeType == 2) { |
| | | // æ¯æ¥æé |
| | | let seconds = Math.floor((new Date() - new Date().setHours(0, 0, 0, 0)) / 1000); |
| | | if (permission.repeatBeginTime <= seconds && seconds <= permission.repeatEndTime) { |
| | | return true |
| | | } |
| | | } |
| | | if (permission.timeType == 3 && permission.period) { |
| | | // å¨é夿é |
| | | let dayTimes = JSON.parse(permission.period)[new Date().getDay() + 1] |
| | | if (dayTimes && dayTimes.split("|").some((dayTime) => isCurrentTimeInTimeRange(dayTime))) { |
| | | return true |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return false |
| | | } |
| | | |
| | | /** |
| | | * 夿å½åæ¶é´æ¯å¦å¨æ¶é´æ®µå
|
| | | * @param {string} time - æ¶é´æ®µåç¬¦ä¸²ï¼æ ¼å¼å¦"15:00-19:00" |
| | | * @returns {boolean} true表示å½åæ¶é´å¨æ¶é´æ®µå
ï¼false表示ä¸å¨ |
| | | */ |
| | | function isCurrentTimeInTimeRange(time) { |
| | | // åå²å¼å§æ¶é´åç»ææ¶é´ |
| | | let [startTime, endTime] = time.split('-'); |
| | | // è§£æå¼å§æ¶é´çå°æ¶ååé |
| | | let [startHour, startMinute] = startTime.split(':'); |
| | | // è§£æç»ææ¶é´çå°æ¶ååé |
| | | let [endHour, endMinute] = endTime.split(':'); |
| | | |
| | | // è·åå½åæ¶é´ |
| | | let currentTime = new Date(); |
| | | |
| | | // å建å¼å§æ¶é´çæ¥æå¯¹è±¡ |
| | | let startDate = new Date(); |
| | | startDate.setHours(parseInt(startHour, 10)); |
| | | startDate.setMinutes(parseInt(startMinute, 10)); |
| | | // åå»ºç»ææ¶é´çæ¥æå¯¹è±¡ |
| | | let endDate = new Date(); |
| | | endDate.setHours(parseInt(endHour, 10)); |
| | | endDate.setMinutes(parseInt(endMinute, 10)); |
| | | |
| | | // æ£æ¥å½åæ¶é´æ¯å¦å¨æ¶é´èå´å
|
| | | return currentTime >= startDate && currentTime <= endDate; |
| | | } |
| | | |
| | | /** |
| | | * éè¡è®°å½ä¸æ¥ |
| | | * @param {object} data - éè¡æ°æ® |
| | | * @param {boolean} result - éè¡ç»æï¼true表示æåï¼false表示失败 |
| | | */ |
| | | function reply(data, result) { |
| | | // 使ç¨çº¿ç¨å¤çæ´ä¸ªreply彿°ï¼é¿å
å µå¡ä¸»è¿ç¨ |
| | | std.setTimeout(() => { |
| | | try { |
| | | // æå»ºéè¡è®°å½ |
| | | let record = { |
| | | id: std.genRandomStr(16), |
| | | result: result ? 0 : 1, // 0表示æåï¼1表示失败 |
| | | } |
| | | |
| | | // å¤å¶dataä¸çåæ®µï¼æé¤extraåextra2 |
| | | for (const key in data) { |
| | | if (key !== 'extra' && key !== 'extra2' && !(key in record)) { |
| | | record[key] = data[key] |
| | | } |
| | | } |
| | | |
| | | // å¤çextraåæ®µ |
| | | if (data.extra) { |
| | | record.extra = JSON.stringify(data.extra) |
| | | } |
| | | |
| | | // å¤çextra2åæ®µ |
| | | if (data.extra2) { |
| | | record.extra2 = JSON.stringify(data.extra2) |
| | | } |
| | | |
| | | // åå¨éè¡è®°å½ï¼å¤æä¸é |
| | | let count = sqliteService.d1_pass_record.count() |
| | | let configNum = config.get("access.offlineAccessNum"); |
| | | configNum = configNum ? configNum : 2000; |
| | | |
| | | if (configNum > 0) { |
| | | if (count >= configNum) { |
| | | // è¾¾å°æå¤§å卿°éï¼å 餿æ§çè®°å½ |
| | | let lastRecord = sqliteService.d1_pass_record.findAllOrderBytimeDesc({ page: 0, size: 1 }) |
| | | if (lastRecord && lastRecord.length == 1) { |
| | | // 妿æ¯äººè¸è®°å½ï¼å é¤å¯¹åºçå¾çæä»¶ |
| | | if (lastRecord[0].type == 300) { |
| | | common.systemBrief(`rm -rf ${lastRecord[0].code}`) |
| | | } |
| | | sqliteService.d1_pass_record.deleteByid(lastRecord[0].id) |
| | | } |
| | | } |
| | | // ä¿åæ°è®°å½ |
| | | sqliteService.d1_pass_record.save(record) |
| | | } |
| | | |
| | | // // çæåºåå· |
| | | // let serialNo = std.genRandomStr(10) |
| | | |
| | | // // å¤ç人è¸å¾ç |
| | | // if (record.type == 300) { |
| | | // let m = map.get("faceAccesss") |
| | | // m.del(serialNo) |
| | | // m.put(serialNo, record.code ? record.code : "") |
| | | // // å°å¾ç转æ¢ä¸ºbase64æ ¼å¼ |
| | | // record.code = driver.face.fileToBase64(record.code) |
| | | // } |
| | | |
| | | // // æå»ºMQTTæ¶æ¯å¹¶åé |
| | | // let payload = mqttService.mqttReply(serialNo, [record], mqttService.CODE.S_000) |
| | | // driver.mqtt.send("access_device/v2/event/access", JSON.stringify(payload)) |
| | | } catch (error) { |
| | | logger.error(`[accessService]: å¤çéè¡è®°å½å¤±è´¥: ${error.message}`) |
| | | } |
| | | }, 0) |
| | | } |
| | | |
| | | export default accessService |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | /** |
| | | * äºç»´ç /æ¡å½¢ç å¤çæå¡æ¨¡å |
| | | * å¤çåç±»äºç»´ç /æ¡å½¢ç çè§£æåå¤çï¼å
æ¬é
ç½®ç ãäºè¯æ¿æ´»ç åéè¡ç |
| | | */ |
| | | import common from '../../dxmodules/dxCommon.js'; |
| | | import log from '../../dxmodules/dxLogger.js' |
| | | import qrRule from '../../dxmodules/dxQrRule.js' |
| | | import std from '../../dxmodules/dxStd.js' |
| | | import config from '../../dxmodules/dxConfig.js' |
| | | import base64 from '../../dxmodules/dxBase64.js' |
| | | import dxMap from '../../dxmodules/dxMap.js' |
| | | import ota from "../../dxmodules/dxOta.js"; |
| | | import bus from "../../dxmodules/dxEventBus.js" |
| | | import sqliteService from "./sqliteService.js"; |
| | | import driver from '../driver.js'; |
| | | import utils from '../common/utils/utils.js'; |
| | | import configConst from '../common/consts/configConst.js'; |
| | | import configService from './configService.js'; |
| | | import accessService from './accessService.js'; |
| | | import logger from '../../dxmodules/dxLogger.js'; |
| | | const codeService = {} |
| | | |
| | | /** |
| | | * æ¥æ¶æ¶æ¯å¹¶å¤ç |
| | | * @param {ArrayBuffer} data - æ¥æ¶å°çåå§æ°æ® |
| | | */ |
| | | codeService.receiveMsg = function (data) { |
| | | log.info('[codeService] receiveMsg :' + JSON.stringify(data)) |
| | | // å°ArrayBuffer转æ¢ä¸ºåå
è¿å¶å符串ï¼å转æ¢ä¸ºUTF8å符串 |
| | | let str = common.utf8HexToStr(common.arrayBufferToHexString(data)) |
| | | // è°ç¨codeæ¹æ³å¤çå符串 |
| | | this.code(str) |
| | | } |
| | | |
| | | /** |
| | | * æ¯è¾ä¸¤ä¸ªå符串çåN个å符æ¯å¦ç¸ç |
| | | * @param {string} str1 - 第ä¸ä¸ªå符串 |
| | | * @param {string} str2 - 第äºä¸ªå符串 |
| | | * @param {number} N - æ¯è¾çåç¬¦æ° |
| | | * @returns {boolean} åN个å符æ¯å¦ç¸ç |
| | | */ |
| | | function comparePrefix (str1, str2, N) { |
| | | let substring1 = str1.substring(0, N); |
| | | let substring2 = str2.substring(0, N); |
| | | return substring1 === substring2; |
| | | } |
| | | |
| | | /** |
| | | * å¤çäºç»´ç /æ¡å½¢ç æ°æ® |
| | | * @param {string} data - äºç»´ç /æ¡å½¢ç çåå§æ°æ® |
| | | */ |
| | | codeService.code = function (data) { |
| | | log.info('[codeService] code :' + data) |
| | | // æ ¼å¼åäºç»´ç æ°æ® |
| | | data = qrRule.formatCode(data, sqliteService) |
| | | |
| | | // 夿äºç»´ç ç±»å |
| | | if (data.type == 'config' || comparePrefix(data.code, "___VF102_CONFIG_V1.1.0___", "___VF102_CONFIG_V1.1.0___".length)) { |
| | | // é
ç½®ç å¤ç |
| | | configCode(data.code) |
| | | } else if (comparePrefix(data.code, "___VBAR_ID_ACTIVE_V", "___VBAR_ID_ACTIVE_V".length)) { |
| | | // äºè¯æ¿æ´»ç å¤ç |
| | | let activeResute = driver.eid.active(config.get("sys.sn"), config.get("sys.appVersion"), config.get("sys.mac"), data.code); |
| | | log.info("[codeService] code: activeResute " + activeResute) |
| | | if (activeResute === 0) { |
| | | log.info("[codeService] code: äºè¯æ¿æ´»æå") |
| | | driver.screen.upgrade({ title: "confirm.cloudCertActive", content: "confirm.cloudCertActiveSuccess" }) |
| | | } else { |
| | | log.info("[codeService] code: äºè¯æ¿æ´»å¤±è´¥") |
| | | driver.screen.upgrade({ title: "confirm.cloudCertActive", content: "confirm.cloudCertActiveFail" }) |
| | | } |
| | | } else { |
| | | // éè¡ç å¤ç |
| | | log.info("è§£æéè¡ç ï¼", JSON.stringify(data)) |
| | | bus.fire("access", { data }) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * é
ç½®ç å¤ç |
| | | * @param {string} code - é
ç½®ç æ°æ® |
| | | * @param {boolean} configType - é
ç½®ç±»åæ å¿ |
| | | */ |
| | | function configCode (code, configType) { |
| | | // é
ç½®ç æ ¡éªææ¶æ³¨é |
| | | // if (!checkConfigCode(code)) { |
| | | // log.error("é
ç½®ç æ ¡éªå¤±è´¥") |
| | | // return |
| | | // } |
| | | |
| | | // è§£æé
ç½®ç 为JSON对象 |
| | | let json = utils.parseString(code) |
| | | if (Object.keys(json).length <= 0) { |
| | | try { |
| | | json = JSON.parse(code.slice(code.indexOf("{"), code.lastIndexOf("}") + 1)) |
| | | } catch (error) { |
| | | log.error(error) |
| | | } |
| | | } |
| | | log.info("è§£æé
ç½®ç ï¼", JSON.stringify(json)) |
| | | |
| | | // 模å¼åæ¢å¤ç |
| | | if (!utils.isEmpty(json.w_model)) { |
| | | try { |
| | | common.setMode(json.w_model) |
| | | common.asyncReboot(1) |
| | | } catch (error) { |
| | | log.error(error, error.stack) |
| | | log.info('åæ¢å¤±è´¥ä¸åä»»ä½å¤ç'); |
| | | } |
| | | return |
| | | } |
| | | |
| | | let map = dxMap.get("UPDATE") |
| | | // æ«ç å级å¤ç |
| | | if (json.update_flag === 1) { |
| | | if (!driver.net.getStatus()) { |
| | | driver.alsa.play(`/app/code/resource/${config.get("base.language") == "CN" ? "CN" : "EN"}/wav/network.wav`) |
| | | return |
| | | } |
| | | if (map.get("updateFlag")) { |
| | | return |
| | | } |
| | | map.put("updateFlag", true) |
| | | try { |
| | | driver.screen.upgrade({ title: "confirm.upgrade", content: "confirm.upgrading" }) |
| | | ota.updateHttp(json.update_addr, json.update_md5, 300) |
| | | driver.screen.upgrade({ title: "confirm.upgrade", content: "confirm.upgradeSuccess" }) |
| | | } catch (error) { |
| | | logger.info(error.message) |
| | | driver.screen.upgrade({ title: "confirm.upgrade", content: "confirm.upgradeFail" }) |
| | | } finally { |
| | | map.del("updateFlag") |
| | | } |
| | | common.asyncReboot(3) |
| | | return |
| | | } |
| | | |
| | | // 设å¤é
ç½®å¤ç |
| | | let configData = {} |
| | | for (let key in json) { |
| | | let transKey |
| | | if (configType == true) { |
| | | transKey = key |
| | | } else { |
| | | transKey = configConst.getValueByKey(key) |
| | | } |
| | | if (transKey == undefined) { |
| | | continue |
| | | } |
| | | let keys = transKey.split(".") |
| | | if (utils.isEmpty(configData[keys[0]])) { |
| | | configData[keys[0]] = {} |
| | | } |
| | | configData[keys[0]][keys[1]] = json[key] |
| | | } |
| | | |
| | | let res = false |
| | | if (Object.keys(configData).length > 0) { |
| | | res = configService.configVerifyAndSave(configData) |
| | | } |
| | | |
| | | if (typeof res != 'boolean') { |
| | | log.error(res) |
| | | return |
| | | } |
| | | |
| | | if (res) { |
| | | log.info("é
ç½®æå") |
| | | } else { |
| | | log.error("é
置失败") |
| | | } |
| | | |
| | | // é
ç½®åéå¯ |
| | | if (json.reboot === 1) { |
| | | driver.screen.warning({ msg: config.get("sysInfo.language") == 1 ? "Rebooting" : "éå¯ä¸", beep: false }) |
| | | common.asyncReboot(1) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªé
ç½®ç |
| | | * @param {string} code - é
ç½®ç æ°æ® |
| | | * @returns {boolean} æ ¡éªæ¯å¦æå |
| | | */ |
| | | function checkConfigCode (code) { |
| | | let password = config.get('sysInfo.com_passwd') || '1234567887654321' |
| | | let lastIndex = code.lastIndexOf("--"); |
| | | if (lastIndex < 0) { |
| | | lastIndex = code.lastIndexOf("__"); |
| | | } |
| | | let firstPart = code.substring(0, lastIndex); |
| | | let secondPart = code.substring(lastIndex + 2); |
| | | let res |
| | | try { |
| | | res = base64.fromHexString(common.arrayBufferToHexString(common.hmac(firstPart, password))) |
| | | } catch (error) { |
| | | log.error(error) |
| | | return false |
| | | } |
| | | |
| | | return res == secondPart; |
| | | } |
| | | |
| | | export default codeService |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | /** |
| | | * é
ç½®æå¡æ¨¡å |
| | | * è´è´£é
ç½®çæ ¡éªãä¿åååºç¨ï¼å
æ¬åç§é
置项çè§åéªè¯ååè°å¤ç |
| | | */ |
| | | import utils from '../common/utils/utils.js' |
| | | import config from '../../dxmodules/dxConfig.js' |
| | | import mqtt from '../../dxmodules/dxMqtt.js' |
| | | import std from '../../dxmodules/dxStd.js' |
| | | import ntp from '../../dxmodules/dxNtp.js' |
| | | import common from '../../dxmodules/dxCommon.js' |
| | | import driver from '../driver.js' |
| | | import bus from '../../dxmodules/dxEventBus.js' |
| | | import mqttService from './mqttService.js' |
| | | import logger from '../../dxmodules/dxLogger.js' |
| | | const configService = {} |
| | | |
| | | /** |
| | | * IPå°åæ ¡éªæ£å |
| | | * å¹é
以ç¹ååè¿å¶å½¢å¼è¡¨ç¤ºç IP å°åï¼ä¾å¦ï¼192.168.0.1 |
| | | */ |
| | | const ipCheck = v => /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(v) |
| | | |
| | | /** |
| | | * IPå°åæååæ ¡éªæ£åï¼å¸¦ç«¯å£ï¼ |
| | | * å¹é
IPå°åæååï¼å¯éæ©å¸¦æç«¯å£å· |
| | | */ |
| | | const ipOrDomainCheckWithPort = v => /^(?:(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,})(:\d{1,5})?$/.test(v); |
| | | |
| | | /** |
| | | * æ£æ´æ°æ ¡éªæ£å |
| | | */ |
| | | const regpCheck = v => /^[1-9]\d*$/.test(v) |
| | | |
| | | /** |
| | | * éè´æ´æ°æ ¡éªæ£å |
| | | */ |
| | | const regnCheck = v => /^([1-9]\d*|0{1})$/.test(v) |
| | | |
| | | /** |
| | | * æææ¯æçé
ç½®é¡¹çæ£éªè§å以å设置æååçåè° |
| | | * ruleï¼æ ¡éªè§åï¼è¿åtrueæ ¡éªæåï¼falseæ ¡éªå¤±è´¥ |
| | | * callbackï¼é
置修æ¹è§¦ååè° |
| | | */ |
| | | const supported = { |
| | | // 人è¸é
ç½® |
| | | face: { |
| | | similarity: { rule: v => typeof v == 'number' && v >= 0 && v <= 1, callback: v => driver.face.faceUpdateConfig({ score: v }) }, |
| | | livenessOff: { rule: v => [0, 1].includes(v), callback: v => driver.face.faceUpdateConfig({ livingCheckEnable: v }) }, |
| | | livenessVal: { rule: v => typeof v == 'number' && v >= 0 && v <= 1, callback: v => driver.face.faceUpdateConfig({ livingScore: v }) }, |
| | | showNir: { rule: v => [0, 1].includes(v), callback: v => driver.capturer.showNir(v) }, |
| | | detectMask: { rule: v => [0, 1].includes(v), callback: v => driver.face.faceUpdateConfig({ detectMaskEnable: v }) }, |
| | | stranger: { rule: v => [0, 1, 2].includes(v) }, |
| | | voiceMode: { rule: v => [0, 1, 2].includes(v) }, |
| | | voiceModeDate: { rule: v => typeof v == 'string' }, |
| | | }, |
| | | // MQTTé
ç½® |
| | | mqtt: { |
| | | addr: { rule: ipOrDomainCheckWithPort }, |
| | | clientId: { rule: v => typeof v == 'string' }, |
| | | username: { rule: v => typeof v == 'string' }, |
| | | password: { rule: v => typeof v == 'string' }, |
| | | qos: { rule: v => [0, 1, 2].includes(v) }, |
| | | prefix: { rule: v => typeof v == 'string' }, |
| | | willtopic: { rule: v => typeof v == 'string' }, |
| | | onlinecheck: { rule: v => [0, 1, 2].includes(v) }, |
| | | timeout: { rule: regpCheck }, |
| | | }, |
| | | // ç½ç»é
ç½® |
| | | net: { |
| | | type: { rule: v => [0, 1, 2, 4].includes(v) }, // ç½ç»ç±»å |
| | | dhcp: { rule: v => [1, 2, 3].includes(v) }, // DHCP设置 |
| | | ip: { rule: ipCheck }, // IPå°å |
| | | gateway: { rule: ipCheck }, // ç½å
³å°å |
| | | dns: { rule: v => !v.split(",").some(ip => !ipCheck(ip)) }, // DNSæå¡å¨ |
| | | mask: { rule: ipCheck }, // åç½æ©ç |
| | | mac: { rule: v => typeof v == 'string' }, // MACå°å |
| | | ssid: { rule: v => typeof v == 'string' }, // WiFi SSID |
| | | psk: { rule: v => typeof v == 'string' }, // WiFiå¯ç |
| | | }, |
| | | // NTPæ¶é´åæ¥é
ç½® |
| | | ntp: { |
| | | ntp: { rule: v => [0, 1].includes(v) }, // NTPå¼å
³ |
| | | server: { rule: ipCheck }, // NTPæå¡å¨ |
| | | gmt: { rule: v => typeof v == 'number' && v >= 0 && v <= 24, callback: v => ntp.updateGmt(v) }, // æ¶åºè®¾ç½® |
| | | }, |
| | | // ç³»ç»é
ç½® |
| | | sys: { |
| | | uuid: { rule: v => typeof v == 'string' }, // 设å¤UUID |
| | | model: { rule: v => typeof v == 'string' }, // 设å¤åå· |
| | | mode: { rule: v => typeof v == 'string', callback: v => setMode(v) }, // è®¾å¤æ¨¡å¼ |
| | | sn: { rule: v => typeof v == 'string' }, // 设å¤åºåå· |
| | | version: { rule: v => typeof v == 'string' }, // ç³»ç»çæ¬ |
| | | releaseDate: { rule: v => typeof v == 'string' }, // å叿¥æ |
| | | nfc: { rule: v => [0, 1].includes(v) }, // NFCå¼å
³ |
| | | nfcIdentityCardEnable: { rule: v => [1, 3].includes(v) }, // äºè¯å¼å
³ |
| | | pwd: { rule: v => [0, 1].includes(v) }, // å¯ç å¼é¨å¼å
³ |
| | | strangerImage: { rule: v => [0, 1].includes(v) }, // éç人ä¿åå¾çå¼å
³ |
| | | accessImageType: { rule: v => [0, 1].includes(v) }, // éè¡å¾çç±»å |
| | | interval: { rule: regnCheck }, // ç³»ç»é´é设置 |
| | | }, |
| | | // é¨ç¦é
ç½® |
| | | access: { |
| | | relayTime: { rule: regpCheck }, // ç»§çµå¨å¨ä½æ¶é´ |
| | | offlineAccessNum: { rule: regpCheck }, // 离线å¼é¨æ¬¡æ° |
| | | tamperAlarm: { rule: v => [0, 1].includes(v) }, // 鲿æ¥è¦å¼å
³ |
| | | }, |
| | | // åºç¡é
ç½® |
| | | base: { |
| | | firstLogin: { rule: v => [0, 1].includes(v) }, // 馿¬¡ç»å½æ å¿ |
| | | brightness: { rule: regnCheck, callback: v => driver.face.setDisplayBacklight(v) }, // å±å¹äº®åº¦ |
| | | brightnessAuto: { rule: v => [0, 1].includes(v) }, // èªå¨äº®åº¦å¼å
³ |
| | | showIp: { rule: v => [0, 1].includes(v), callback: v => driver.screen.hideIp(v) }, // æ¯å¦æ¾ç¤ºIPå°å |
| | | showSn: { rule: v => [0, 1].includes(v), callback: v => driver.screen.hideSn(v) }, // æ¯å¦æ¾ç¤ºåºåå· |
| | | appMode: { rule: v => [0, 1].includes(v), callback: v => driver.screen.appMode(v) }, // åºç¨æ¨¡å¼ |
| | | screenOff: { rule: regnCheck, callback: v => bus.fire("screenManagerRefresh") }, // ç屿¶é´ |
| | | screensaver: { rule: regnCheck, callback: v => bus.fire("screenManagerRefresh") }, // å±å¹ä¿æ¤ |
| | | volume: { rule: regnCheck, callback: v => driver.alsa.volume(v) }, // é³é设置 |
| | | password: { rule: v => typeof v == 'string' && v.length >= 8 }, // 管çåå¯ç |
| | | language: { rule: v => ["EN", "CN"].includes(v), callback: v => driver.screen.changeLanguage() }, // è¯è¨è®¾ç½® |
| | | showProgramCode: { rule: v => [0, 1].includes(v) }, // æ¯å¦æ¾ç¤ºç¨åºä»£ç |
| | | showIdentityCard: { rule: v => [0, 1].includes(v) }, // æ¯å¦æ¾ç¤ºèº«ä»½è¯ä¿¡æ¯ |
| | | luminanceWhite: { rule: v => typeof v == 'number' && v >= 0 && v <= 100, callback: v => driver.pwm.luminanceWhite(v) }, // ç½å
亮度 |
| | | luminanceNir: { rule: v => typeof v == 'number' && v >= 0 && v <= 100, callback: v => driver.pwm.luminanceNir(v) }, // 红å¤å
亮度 |
| | | }, |
| | | // å¯ç éè¡é
ç½® |
| | | passwordAccess: { |
| | | passwordAccess: { rule: v => [0, 1].includes(v) }, // å¯ç éè¡å¼å
³ |
| | | emergencyPassword: { rule: v => typeof v == 'string' && v.length >= 8 }, // åºæ¥å¼ä»å¯ç |
| | | }, |
| | | // HTTPé
ç½® |
| | | http: { |
| | | gas: { rule: v => typeof v == 'string' }, // HTTP_æ°ä½ |
| | | status: { rule: v => typeof v == 'string' }, // HTTP_ç¶æ |
| | | safeInputAccess: { rule: v => typeof v == 'string' } // HTTPæ¥å£è·¯å¾ |
| | | }, |
| | | // ä»å»åç§° |
| | | houseName: {}, |
| | | // åºåºåç§° |
| | | GranaryName: {}, |
| | | // æ´æ°é
ç½® |
| | | update: { |
| | | gasTime: { rule: regpCheck }, // æ°ä½æµåº¦æ´æ°æ¶é´ï¼ç§ï¼ |
| | | statusTime: { rule: regpCheck } // ç¶æä¿¡æ¯æ´æ°æ¶é´ï¼ç§ï¼ |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * éè¦éå¯çé
置项 |
| | | */ |
| | | const needReboot = ["sys.nfc", "sys.nfcIdentityCardEnable", "ntp"] |
| | | configService.needReboot = needReboot |
| | | |
| | | /** |
| | | * ä¿®æ¹è®¾å¤æ¨¡å¼ |
| | | * @param {string} params - 模å¼åæ° |
| | | */ |
| | | function setMode(params) { |
| | | common.systemWithRes(`echo 'app' > /etc/.app_v1`, 2) |
| | | common.setMode(params) |
| | | } |
| | | |
| | | /** |
| | | * é
ç½®jsonæ ¡éªå¹¶ä¿å |
| | | * @param {object} data - é
置json对象 |
| | | * @returns {boolean|string} trueè¡¨ç¤ºæ ¡éªå¹¶ä¿åæåï¼string表示éè¯¯ä¿¡æ¯ |
| | | */ |
| | | configService.configVerifyAndSave = function (data) { |
| | | let netFlag = false // ç½ç»é
ç½®æ å¿ |
| | | let mqttFlag = false // MQTTé
ç½®æ å¿ |
| | | let isReboot = false // æ¯å¦éè¦éå¯ |
| | | |
| | | for (const key in data) { |
| | | if (key == 'net') { |
| | | netFlag = true |
| | | } |
| | | if (key == 'mqtt') { |
| | | mqttFlag = true |
| | | } |
| | | |
| | | // æ£æ¥é
ç½®ç»æ¯å¦æ¯æ |
| | | if (!supported[key]) { |
| | | return key + " not supported" |
| | | } |
| | | |
| | | const item = data[key]; |
| | | if (typeof item != 'object') { |
| | | // é¡¶å±é
置项ï¼ç´æ¥ä¿å |
| | | config.set(key, item) |
| | | continue |
| | | } |
| | | |
| | | // æ£æ¥æ¯å¦éè¦éå¯ |
| | | if (needReboot.includes(key)) { |
| | | isReboot = true |
| | | } |
| | | |
| | | for (const subKey in item) { |
| | | let option = supported[key][subKey] |
| | | if (isEmpty(option)) { |
| | | return subKey + " not supported" |
| | | } |
| | | |
| | | const value = item[subKey]; |
| | | |
| | | // æ£æ¥æ¯å¦éè¦éå¯ |
| | | if (needReboot.includes(key + "." + subKey)) { |
| | | isReboot = true |
| | | } |
| | | |
| | | // æ ¡éªé
ç½®å¼ |
| | | if (!option.rule || option.rule(value)) { |
| | | // æ²¡ææ ¡éªè§åé»è®¤æ ¡éªéè¿ |
| | | config.set(key + "." + subKey, value) |
| | | if (option.callback) { |
| | | // æ§è¡é
置设置åè° |
| | | option.callback(value) |
| | | } |
| | | } else { |
| | | return value + " check failure" |
| | | } |
| | | } |
| | | } |
| | | |
| | | // ä¿åé
ç½® |
| | | config.save() |
| | | |
| | | // æ£æ¥éè¦éå¯çé
ç½®ï¼3ç§åéå¯ |
| | | if (isReboot) { |
| | | driver.screen.upgrade({ title: "confirm.restartDevice", content: "confirm.restartDeviceDis" }) |
| | | common.asyncReboot(3) |
| | | } |
| | | |
| | | // å¤çç½ç»é
ç½®åæ´ |
| | | if (netFlag) { |
| | | // çå¾
1 ç§ å 为éè¦è¿å mqtt |
| | | std.setTimeout(() => { |
| | | bus.fire("switchNetworkType", config.get("net.type")) |
| | | }, 1000); |
| | | } |
| | | |
| | | // å¤çMQTTé
ç½®åæ´ |
| | | if (mqttFlag) { |
| | | let option = { |
| | | mqttAddr: config.get("mqtt.addr"), |
| | | clientId: config.get('mqtt.clientId') + std.genRandomStr(3), |
| | | subs: mqttService.getTopics(), |
| | | username: config.get("mqtt.username"), |
| | | password: config.get("mqtt.password"), |
| | | qos: config.get("mqtt.qos"), |
| | | willTopic: config.get("mqtt.willTopic"), |
| | | willMessage: JSON.stringify({ "uuid": config.get("sys.uuid") }) |
| | | } |
| | | logger.info("éå¯mqtt", JSON.stringify(option)) |
| | | // 鿝 mqtt 鿰 init |
| | | bus.fire(mqtt.RECONNECT, option) |
| | | } |
| | | |
| | | // 触åé
ç½®æ´æ°äºä»¶ï¼éç¥å
¶ä»æ¨¡åé
ç½®å·²æ´æ° |
| | | bus.fire('configUpdated') |
| | | |
| | | return true |
| | | } |
| | | |
| | | /** |
| | | * å¤ç©ºå½æ° |
| | | * @param {*} value - è¦å¤æçå¼ |
| | | * @returns {boolean} true表示å¼ä¸ºç©ºï¼false表示å¼ä¸ä¸ºç©º |
| | | */ |
| | | function isEmpty(value) { |
| | | return value === undefined || value === null |
| | | } |
| | | |
| | | export default configService |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | /** |
| | | * 人è¸è¯å«æå¡æ¨¡å |
| | | * å¤ç人è¸è¯å«ç¸å
³çä¸å¡é»è¾ï¼å
æ¬äººè¸æ³¨ååäººè¸æ¯å¯¹ |
| | | */ |
| | | import logger from "../../dxmodules/dxLogger.js"; |
| | | import dxCommon from "../../dxmodules/dxCommon.js"; |
| | | import bus from "../../dxmodules/dxEventBus.js"; |
| | | import dxMap from "../../dxmodules/dxMap.js"; |
| | | import driver from "../driver.js"; |
| | | import config from "../../dxmodules/dxConfig.js"; |
| | | import sqliteService from "./sqliteService.js"; |
| | | import std from "../../dxmodules/dxStd.js"; |
| | | import pool from "../../dxmodules/dxWorkerPool.js"; |
| | | |
| | | let map = dxMap.get("LOGIN") |
| | | const faceService = {} |
| | | |
| | | // è¯é³ææ¾é²ææ§å¶ |
| | | let lastPlayTime = 0 |
| | | const PLAY_DELAY = 2000 // 2ç§å
ä¸é夿æ¾ç¸åè¯é³ |
| | | |
| | | /** |
| | | * è¯é³ææ¾é²æå½æ° |
| | | * @param {function} playFunction - ææ¾å½æ° |
| | | * @returns {boolean} æ¯å¦æ§è¡äºææ¾ |
| | | */ |
| | | function debouncePlay(playFunction) { |
| | | const now = Date.now() |
| | | if (now - lastPlayTime > PLAY_DELAY) { |
| | | lastPlayTime = now |
| | | playFunction() |
| | | return true |
| | | } |
| | | return false |
| | | } |
| | | |
| | | // å人认è¯ç¶æç®¡ç |
| | | let dualAuthState = { |
| | | firstUserId: null, // 第ä¸ä¸ªç¨æ·ID |
| | | firstUserName: null, // 第ä¸ä¸ªç¨æ·å§å |
| | | firstUserFileName: null, // 第ä¸ä¸ªç¨æ·äººè¸å¾çæä»¶è·¯å¾ |
| | | firstUserIdCard: null, // 第ä¸ä¸ªç¨æ·èº«ä»½è¯å· |
| | | firstUserType: null, // 第ä¸ä¸ªç¨æ·èº«ä»½ç±»å |
| | | secondUserId: null, // 第äºä¸ªç¨æ·ID |
| | | secondUserName: null, // 第äºä¸ªç¨æ·å§å |
| | | secondUserIdCard: null, // 第äºä¸ªç¨æ·èº«ä»½è¯å· |
| | | secondUserType: null, // 第äºä¸ªç¨æ·èº«ä»½ç±»å |
| | | startTime: 0, // å¼å§æ¶é´ |
| | | timeout: null, // 宿¶å¨ |
| | | authComplete: false // è®¤è¯æ¯å¦å®æ |
| | | } |
| | | |
| | | /** |
| | | * æ¥æ¶äººè¸è¯å«æ¶æ¯å¹¶å¤ç |
| | | * @param {object} data - 人è¸è¯å«æ°æ® |
| | | */ |
| | | faceService.receiveMsg = function (data) { |
| | | logger.info('[faceService] receiveMsg :' + JSON.stringify(data)) |
| | | // 触åéåºç©ºé²ç¶æäºä»¶ï¼éå±åæ¯å±ï¼ |
| | | bus.fire("exitIdle") |
| | | |
| | | switch (data.type) { |
| | | case "register": |
| | | // 注å人è¸å¤ç |
| | | for (let i = 0; i < data.faces.length; i++) { |
| | | const element = data.faces[i]; |
| | | bus.fire("beginAddFace", element) |
| | | } |
| | | break; |
| | | case "compare": |
| | | // äººè¸æ¯å¯¹å¤ç |
| | | // æ¾ç¤ºå§åï¼ä»£è¡¨ææ³¨åè¿äººè¸ï¼ä½æ¯æéä¸ä¸å®ææï¼éè¦è¿ä¸æ¥è®¤è¯ |
| | | for (let i = 0; i < data.faces.length; i++) { |
| | | const element = data.faces[i]; |
| | | |
| | | // åªæå¨è®¤è¯æªå®ææ¶æè§¦åtrackResultäºä»¶ |
| | | if (!dualAuthState.authComplete) { |
| | | // 夿å½åæ¯ç¬¬å ä¸ªç¨æ·ï¼ç¨äºå人认è¯ï¼ |
| | | let userIndex = 1 // 0表示æªç¥ï¼1表示第ä¸ä¸ªç¨æ·ï¼2表示第äºä¸ªç¨æ· |
| | | if (!dualAuthState.firstUserId) { |
| | | // 第ä¸ä¸ªç¨æ·è¿æªè®¾ç½®ï¼å½åç¨æ·å°±æ¯ç¬¬ä¸ä¸ªç¨æ· |
| | | userIndex = 1 |
| | | } else if (element.userId === dualAuthState.firstUserId) { |
| | | userIndex = 1 |
| | | } else if (element.userId !== dualAuthState.firstUserId) { |
| | | userIndex = 2 |
| | | } |
| | | |
| | | logger.info('[faceService]: åå¤è§¦åtrackResultäºä»¶, userIndex=' + userIndex + ', result=' + element.result + ', userId=' + element.userId + ', authComplete=' + dualAuthState.authComplete + ', fileName=' + element.fileName) |
| | | |
| | | // ç´æ¥ä½¿ç¨bus.fire触åtrackResultäºä»¶ |
| | | bus.fire("trackResult", { id: element.id, result: element.result, userId: element.userId, userIndex: userIndex, fileName: element.fileName }) |
| | | } |
| | | |
| | | if (element.result) { |
| | | // 人è¸ç¸ä¼¼åº¦éªè¯éè¿ |
| | | let ret = sqliteService.d1_person.find({ userId: element.userId }) |
| | | |
| | | if (dxMap.get("UI").get("faceAuthStart") == "Y") { |
| | | // æ£å¨äººè¸ç»å½ |
| | | if (JSON.parse(ret[0].extra).type != 0) { |
| | | bus.fire("faceAuthResult", true) |
| | | } else { |
| | | bus.fire("faceAuthResult", false) |
| | | } |
| | | return |
| | | } |
| | | |
| | | // æ£æ¥ç¨æ·ç±»åï¼ç®¡çå级å«ï¼ |
| | | let userType = 0 |
| | | try { |
| | | userType = JSON.parse(ret[0].extra).type || 0 |
| | | } catch (error) { |
| | | logger.error("è§£æç¨æ·ç±»å失败") |
| | | } |
| | | |
| | | // 管çå级å«ç¨æ·ï¼type != 0ï¼ç´æ¥è®¤è¯éè¿ |
| | | if (userType != 0) { |
| | | // æ¸
é¤å人认è¯ç¶æ |
| | | clearDualAuthState() |
| | | |
| | | // æ ¹æ®è¯é³æ¨¡å¼ææ¾ç¸åºçè¯é³ |
| | | switch (config.get("face.voiceMode")) { |
| | | case 0: |
| | | // æ è¯é³ |
| | | break; |
| | | case 1: |
| | | // ææ¾åå |
| | | driver.alsa.ttsPlay(ret[0].name) |
| | | break; |
| | | case 2: |
| | | // ææ¾é®åè¯ |
| | | driver.alsa.ttsPlay(config.get("face.voiceModeDate") ? config.get("face.voiceModeDate") : "欢è¿å
临") |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | |
| | | // éè¡è®¤è¯å¤ç |
| | | bus.fire("access", { data: { type: "300", code: element.userId }, fileName: element.fileName }) |
| | | } else { |
| | | // é管çå级å«ç¨æ·ï¼éè¦åäººè®¤è¯ |
| | | handleDualAuth(element.userId, ret[0].name, element.fileName) |
| | | } |
| | | } else { |
| | | // 人è¸ç¸ä¼¼åº¦éªè¯å¤±è´¥ |
| | | if (dxMap.get("UI").get("faceAuthStart") == "Y") { |
| | | // 人è¸ç»å½å¤±è´¥ |
| | | bus.fire("faceAuthResult", false) |
| | | } else { |
| | | // éç人å¤ç |
| | | switch (config.get("face.stranger")) { |
| | | case 0: |
| | | // æ è¯é³ |
| | | break; |
| | | case 1: |
| | | // ææ¾è¯·å
注åï¼é²ææ§å¶ï¼ |
| | | debouncePlay(() => { |
| | | driver.alsa.play(`/app/code/resource/${config.get("base.language") == "CN" ? "CN" : "EN"}/wav/register.wav`) |
| | | }) |
| | | break; |
| | | case 2: |
| | | // ææ¾éçäººä½ å¥½ï¼é²ææ§å¶ï¼ |
| | | debouncePlay(() => { |
| | | driver.alsa.play(`/app/code/resource/${config.get("base.language") == "CN" ? "CN" : "EN"}/wav/stranger.wav`) |
| | | }) |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | // éè¡è®¤è¯å¤çï¼ç¸ä¼¼åº¦éªè¯å¤±è´¥ï¼ |
| | | bus.fire("access", { data: { type: "300", code: element.userId }, fileName: element.fileName, similarity: false }) |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | |
| | | // çå¬éè¡è§£é宿äºä»¶ï¼éç½®å人认è¯ç¶æ |
| | | bus.on('accessUnlockComplete', () => { |
| | | logger.info('[faceService]: accessUnlockCompleteäºä»¶è§¦åï¼éç½®å人认è¯ç¶æ') |
| | | clearDualAuthState() |
| | | }) |
| | | |
| | | /** |
| | | * æ¸
é¤å人认è¯ç¶æ |
| | | */ |
| | | function clearDualAuthState() { |
| | | dualAuthState.firstUserId = null |
| | | dualAuthState.firstUserName = null |
| | | dualAuthState.firstUserFileName = null |
| | | dualAuthState.firstUserIdCard = null |
| | | dualAuthState.firstUserType = null |
| | | dualAuthState.secondUserId = null |
| | | dualAuthState.secondUserName = null |
| | | dualAuthState.secondUserIdCard = null |
| | | dualAuthState.secondUserType = null |
| | | dualAuthState.startTime = 0 |
| | | dualAuthState.authComplete = false // é置认è¯å®ææ å¿ |
| | | if (dualAuthState.timeout) { |
| | | std.clearTimeout(dualAuthState.timeout) |
| | | dualAuthState.timeout = null |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å¤çå人认è¯è¶
æ¶ |
| | | */ |
| | | function handleDualAuthTimeout() { |
| | | try { |
| | | // ä¿å认è¯è®°å½ |
| | | if (dualAuthState.firstUserId && !dualAuthState.authComplete) { |
| | | // æ¥è¯¢ç¬¬ä¸ç¨æ·ç详ç»ä¿¡æ¯ï¼è·å身份类å |
| | | let firstUserType = dualAuthState.firstUserType || 0 |
| | | if (!firstUserType) { |
| | | let res = sqliteService.d1_person.findByUserId(dualAuthState.firstUserId) |
| | | if (res.length > 0) { |
| | | try { |
| | | firstUserType = JSON.parse(res[0].extra).type || 0 |
| | | } catch (error) { |
| | | logger.error("æ 第ä¸ç¨æ·ç±»å") |
| | | } |
| | | } |
| | | } |
| | | |
| | | // æ¥è¯¢ç¬¬äºç¨æ·ç详ç»ä¿¡æ¯ï¼è·å身份类å |
| | | let secondUserType = dualAuthState.secondUserType || 0 |
| | | if (dualAuthState.secondUserId && !secondUserType) { |
| | | let res = sqliteService.d1_person.findByUserId(dualAuthState.secondUserId) |
| | | if (res.length > 0) { |
| | | try { |
| | | secondUserType = JSON.parse(res[0].extra).type || 0 |
| | | } catch (error) { |
| | | logger.error("æ 第äºç¨æ·ç±»å") |
| | | } |
| | | } |
| | | } |
| | | |
| | | // å建认è¯è®°å½ |
| | | const record = { |
| | | id: std.genRandomStr(16), |
| | | userId: dualAuthState.firstUserId, |
| | | userId2: dualAuthState.secondUserId || "", |
| | | type: "300", // 人è¸è®¤è¯ï¼åç¬¦ä¸²æ ¼å¼ï¼ |
| | | code: dualAuthState.firstUserFileName, // äººè¸ææå¾çè·¯å¾ |
| | | result: 1, // 认è¯å¤±è´¥ï¼0æåï¼1å¤±è´¥ï¼ |
| | | time: Math.floor(Date.now() / 1000), // æ¶é´æ³ï¼ç§ï¼ |
| | | message: "å人认è¯è¶
æ¶", |
| | | extra: JSON.stringify({ name: dualAuthState.firstUserName, idCard: dualAuthState.firstUserIdCard, type: firstUserType }), |
| | | extra2: dualAuthState.secondUserId ? JSON.stringify({ name: dualAuthState.secondUserName || "", idCard: dualAuthState.secondUserIdCard || "", type: secondUserType }) : "", |
| | | permissionId: firstUserType.toString(), |
| | | permissionId2: dualAuthState.secondUserId ? secondUserType.toString() : "" |
| | | } |
| | | |
| | | // ä¿åå°æ°æ®åº |
| | | sqliteService.d1_pass_record.save(record) |
| | | logger.info(`[faceService]: ä¿åå人认è¯è¶
æ¶è®°å½: ${JSON.stringify(record)}`) |
| | | } |
| | | |
| | | // æ¸
é¤è®¤è¯ç¶æ |
| | | clearDualAuthState() |
| | | |
| | | // ææ¾å¤±è´¥æç¤ºé³ |
| | | driver.alsa.play(`/app/code/resource/${config.get("base.language") == "CN" ? "CN" : "EN"}/wav/verify_300_f.wav`) |
| | | |
| | | // è¯é³æç¤ºè®¤è¯å¤±è´¥ |
| | | // driver.alsa.ttsPlay("å人认è¯è¶
æ¶ï¼è®¤è¯å¤±è´¥") |
| | | |
| | | // 触å认è¯å¤±è´¥äºä»¶ |
| | | bus.fire("showAccessResult", { |
| | | faceAuth: false, |
| | | gasConcentration: true, |
| | | accessAllowed: false, |
| | | message: "*å人认è¯è¶
æ¶ï¼è®¤è¯å¤±è´¥*" |
| | | }) |
| | | |
| | | // 触åéè¡å¤±è´¥äºä»¶ï¼éç¥UIéç½® |
| | | bus.fire("accessRes", false) |
| | | |
| | | |
| | | } catch (error) { |
| | | logger.error(`[faceService]: å¤çå人认è¯è¶
æ¶é误: ${error.message}`) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å¤çå人认è¯é»è¾ |
| | | * @param {string} userId - å½åç¨æ·ID |
| | | * @param {string} userName - å½åç¨æ·å§å |
| | | * @param {string} fileName - 人è¸å¾çæä»¶è·¯å¾ |
| | | */ |
| | | function handleDualAuth(userId, userName, fileName) { |
| | | try { |
| | | if (!dualAuthState.firstUserId) { |
| | | // ç¬¬ä¸æ¬¡è®¤è¯ |
| | | dualAuthState.firstUserId = userId |
| | | dualAuthState.firstUserName = userName |
| | | dualAuthState.firstUserFileName = fileName |
| | | |
| | | // æ¥è¯¢ç¬¬ä¸ç¨æ·ç详ç»ä¿¡æ¯ï¼è·å身份è¯å·å身份类å |
| | | let res = sqliteService.d1_person.findByUserId(userId) |
| | | if (res.length > 0) { |
| | | let idCard |
| | | let userType = 0 |
| | | try { |
| | | idCard = JSON.parse(res[0].extra).idCard |
| | | userType = JSON.parse(res[0].extra).type || 0 |
| | | } catch (error) { |
| | | logger.error("æ 第ä¸ç¨æ·èº«ä»½è¯å·æç±»å") |
| | | } |
| | | dualAuthState.firstUserIdCard = idCard |
| | | dualAuthState.firstUserType = userType |
| | | } |
| | | |
| | | dualAuthState.startTime = Date.now() |
| | | |
| | | // æ¸
é¤ä¹åç宿¶å¨ |
| | | if (dualAuthState.timeout) { |
| | | std.clearTimeout(dualAuthState.timeout) |
| | | } |
| | | |
| | | // 设置1åéè¶
æ¶ |
| | | dualAuthState.timeout = std.setTimeout(() => { |
| | | // è¶
æ¶å¤çï¼è§ä¸ºè®¤è¯å¤±è´¥ |
| | | handleDualAuthTimeout() |
| | | }, 60000) |
| | | |
| | | // è¯é³æç¤º-请第äºç¨æ·è¿è¡è®¤è¯ |
| | | driver.alsa.play(`/app/code/resource/${config.get("base.language") == "CN" ? "CN" : "EN"}/wav/user2.wav`) |
| | | } else { |
| | | // ç¬¬äºæ¬¡è®¤è¯ |
| | | if (userId !== dualAuthState.firstUserId) { |
| | | // ä¸åç¨æ·ï¼è®¤è¯éè¿ |
| | | // æ¥è¯¢ç¬¬äºç¨æ·ç详ç»ä¿¡æ¯ï¼è·å身份è¯å·å身份类å |
| | | let secondUserIdCard = "" |
| | | let secondUserType = 0 |
| | | let res = sqliteService.d1_person.findByUserId(userId) |
| | | if (res.length > 0) { |
| | | try { |
| | | secondUserIdCard = JSON.parse(res[0].extra).idCard |
| | | secondUserType = JSON.parse(res[0].extra).type || 0 |
| | | } catch (error) { |
| | | logger.error("æ 第äºç¨æ·èº«ä»½è¯å·æç±»å") |
| | | } |
| | | } |
| | | |
| | | // ä¿åå人认è¯ç¶æä¿¡æ¯ï¼ç¨äºUIæ´æ° |
| | | let dualAuthInfo = { |
| | | firstUserId: dualAuthState.firstUserId, |
| | | firstUserName: dualAuthState.firstUserName, |
| | | secondUserId: userId, |
| | | secondUserName: userName, |
| | | secondUserIdCard: secondUserIdCard, |
| | | secondUserType: secondUserType |
| | | } |
| | | // ä¿å第ä¸ç¨æ·ç人è¸å¾çè·¯å¾ |
| | | let firstUserFileName = dualAuthState.firstUserFileName |
| | | // 设置认è¯å®ææ å¿ |
| | | dualAuthState.authComplete = true |
| | | clearDualAuthState() |
| | | |
| | | // è¯é³æç¤º-å人认è¯éè¿ |
| | | driver.alsa.play(`/app/code/resource/${config.get("base.language") == "CN" ? "CN" : "EN"}/wav/user2_s.wav`) |
| | | |
| | | // éè¡è®¤è¯å¤çï¼ä¼ éå人认è¯ä¿¡æ¯ |
| | | bus.fire("access", { data: { type: "300", code: userId, dualAuthInfo: dualAuthInfo, authComplete: true, firstUserFileName: firstUserFileName }, fileName: fileName }) |
| | | } else { |
| | | // åä¸ç¨æ·ï¼éæ°å¼å§ |
| | | dualAuthState.firstUserId = userId |
| | | dualAuthState.firstUserName = userName |
| | | |
| | | // æ¥è¯¢ç¨æ·ç详ç»ä¿¡æ¯ï¼è·å身份è¯å·å身份类å |
| | | let idCard |
| | | let userType = 0 |
| | | let res = sqliteService.d1_person.findByUserId(userId) |
| | | if (res.length > 0) { |
| | | try { |
| | | idCard = JSON.parse(res[0].extra).idCard |
| | | userType = JSON.parse(res[0].extra).type || 0 |
| | | } catch (error) { |
| | | logger.error("æ ç¨æ·èº«ä»½è¯å·æç±»å") |
| | | } |
| | | dualAuthState.firstUserIdCard = idCard |
| | | dualAuthState.firstUserType = userType |
| | | } |
| | | |
| | | dualAuthState.startTime = Date.now() |
| | | |
| | | // æ¸
é¤ä¹åç宿¶å¨ |
| | | if (dualAuthState.timeout) { |
| | | std.clearTimeout(dualAuthState.timeout) |
| | | } |
| | | |
| | | // éæ°è®¾ç½®1åéè¶
æ¶ |
| | | dualAuthState.timeout = std.setTimeout(() => { |
| | | // è¶
æ¶å¤çï¼è§ä¸ºè®¤è¯å¤±è´¥ |
| | | handleDualAuthTimeout() |
| | | }, 60000) |
| | | |
| | | // è¯é³æç¤º-请第äºç¨æ·è¿è¡è®¤è¯ |
| | | driver.alsa.play(`/app/code/resource/${config.get("base.language") == "CN" ? "CN" : "EN"}/wav/user2.wav`) |
| | | } |
| | | } |
| | | } catch (error) { |
| | | logger.error(`[faceService]: å¤çå人认è¯é误: ${error.message}`) |
| | | // æ¸
é¤è®¤è¯ç¶æ |
| | | clearDualAuthState() |
| | | } |
| | | } |
| | | /** |
| | | * äººè¸æ³¨åé误æä¸¾ |
| | | * å
å«åç§æ³¨å失败çé误ç å对åºçéè¯¯ä¿¡æ¯ |
| | | */ |
| | | faceService.regErrorEnum = { |
| | | "callback": { |
| | | title: "注ååè°ç¶ææä¸¾", |
| | | "-1": "faceService.contrastFailure", // 对æ¯å¤±è´¥ |
| | | "-2": "faceService.scalingFailure", // 缩æ¾å¤±è´¥ |
| | | "-3": "faceService.failedToSavePicture", // ä¿åå¾ç失败 |
| | | "-4": "faceService.convertToBase64Fail", // 转æ¢ä¸ºbase64失败 |
| | | }, |
| | | "feature": { |
| | | title: "ç¹å¾å¼æ³¨åç¶ææä¸¾", |
| | | "-1": "faceService.base64DecodingFail", // base64è§£ç 失败 |
| | | "-10": "faceService.contrastFailure", // 对æ¯å¤±è´¥ |
| | | "-11": "faceService.similarityOverheight", // ç¸ä¼¼åº¦è¿é« |
| | | }, |
| | | "picture": { |
| | | title: "å¾ç注åç¶ææä¸¾", |
| | | "-1": "faceService.fileDoesNotExist", // æä»¶ä¸åå¨ |
| | | "-2": "faceService.theImageFormatIsNotSupported", // å¾çæ ¼å¼ä¸æ¯æ |
| | | "-3": "faceService.pictureReadFailure", // å¾ç读å失败 |
| | | "-4": "faceService.thePictureSizeDoesNotMatch", // å¾ç尺寸ä¸å¹é
|
| | | "-5": "faceService.imageParsingFailure", // å¾çè§£æå¤±è´¥ |
| | | "-6": "faceService.imageYUVProcessingFailed", // å¾çYUVå¤ç失败 |
| | | "-7": "faceService.failedToConvertJpegToImage", // JPEG转æ¢ä¸ºå¾ç失败 |
| | | "-8": "faceService.faceInformationExtractionFailed", // 人è¸ä¿¡æ¯æå失败 |
| | | "-9": "faceService.theFaceIsNotUnique", // 人è¸ä¸å¯ä¸ |
| | | "-10": "faceService.contrastFailure", // 对æ¯å¤±è´¥ |
| | | "-11": "faceService.similarityOverheight", // ç¸ä¼¼åº¦è¿é« |
| | | } |
| | | } |
| | | |
| | | export default faceService |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | /** |
| | | * GPIOæé®æå¡æ¨¡å |
| | | * å¤çGPIOæé®ç¸å
³çä¸å¡é»è¾ï¼ä¸»è¦å
æ¬é²ææ¥è¦åè½ |
| | | */ |
| | | import logger from "../../dxmodules/dxLogger.js"; |
| | | import config from "../../dxmodules/dxConfig.js"; |
| | | import driver from "../driver.js"; |
| | | import bus from "../../dxmodules/dxEventBus.js"; |
| | | |
| | | const gpiokeyService = {} |
| | | |
| | | /** |
| | | * æ¥æ¶GPIOæé®æ¶æ¯å¹¶å¤ç |
| | | * @param {object} data - GPIOæé®æ°æ® |
| | | * @param {number} data.code - GPIOçæ è¯ï¼è¡¨ç¤ºæ¯åªä¸ªGPIOæè¾å
¥ 256-鲿ï¼257-é¨ç£ |
| | | * @param {number} data.type - æé®ç±»åï¼1è¡¨ç¤ºé²æ/é¨ç£ç¶æåå |
| | | * @param {number} data.value - æé®å¼ï¼1表示触å/é¨å¼ï¼0表示æªè§¦å/é¨å
³ |
| | | */ |
| | | gpiokeyService.receiveMsg = function (data) { |
| | | logger.info('[gpiokeyService] æ¥æ¶å°GPIOæ¶æ¯:', JSON.stringify(data)) |
| | | |
| | | // 鲿æ¥è¦å¤ç |
| | | if (data.code === 256) { |
| | | if (config.get("access.tamperAlarm") && data.type == 1 && data.value == 1) { |
| | | logger.info('[gpiokeyService] 鲿æ¥è¦è§¦å') |
| | | driver.alsa.play("/app/code/resource/wav/alarm.wav") |
| | | } |
| | | } |
| | | |
| | | // é¨ç£ç¶æååå¤ç |
| | | if (data.code === 257) { |
| | | const doorStatus = data.value == 1 ? "é¨å¼" : "é¨å
³" |
| | | logger.info(`[gpiokeyService] é¨ç£ç¶æåå: ${doorStatus}`) |
| | | |
| | | if (data.value === 1) { |
| | | // é¨å¼ |
| | | driver.alsa.play("/app/code/resource/CN/wav/door_open.wav") |
| | | } else { |
| | | // é¨å
³ |
| | | driver.alsa.play("/app/code/resource/CN/wav/door_close.wav") |
| | | } |
| | | |
| | | // åéé¨ç£ç¶æååéç¥äºä»¶ |
| | | bus.fire('doorStatusChanged', { |
| | | status: data.value, |
| | | statusText: doorStatus, |
| | | time: Math.floor(Date.now() / 1000) |
| | | }) |
| | | } |
| | | } |
| | | |
| | | export default gpiokeyService |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | /** |
| | | * ç²®æ
æå¡æ¨¡å |
| | | * è´è´£æ°ä½æµåº¦æ°æ®è·ååç¶æä¿¡æ¯æ°æ®è·å |
| | | */ |
| | | import logger from "../../dxmodules/dxLogger.js" |
| | | import config from "../../dxmodules/dxConfig.js" |
| | | import http from "../../dxmodules/dxHttp.js" |
| | | import bus from '../../dxmodules/dxEventBus.js' |
| | | import std from "../../dxmodules/dxStd.js" |
| | | import driver from "../driver.js" |
| | | const grainService = {} |
| | | |
| | | // ä»é
ç½®ä¸è·åä¸å¡ç¼ç å®ä¹ |
| | | const functionId = { |
| | | gasDetection: config.get('functionId.gasDetection') || "1000", |
| | | safeInputControl: config.get('functionId.safeInputControl') || "2000", |
| | | lightControl: config.get('functionId.lightControl') || "3000", |
| | | doorStatus: config.get('functionId.doorStatus') || "4000" |
| | | } |
| | | |
| | | // ä»é
ç½®ä¸è·åæ¥å£è¿åç¼ç |
| | | const respCode = { |
| | | success: config.get('respCode.success') || "200", |
| | | badRequest: config.get('respCode.badRequest') || "400", |
| | | unauthorized: config.get('respCode.unauthorized') || "401", |
| | | forbidden: config.get('respCode.forbidden') || "403", |
| | | notFound: config.get('respCode.notFound') || "404", |
| | | serverError: config.get('respCode.serverError') || "500" |
| | | } |
| | | |
| | | // é误ç 对åºçéè¯¯ä¿¡æ¯ |
| | | const errorMessages = { |
| | | "400": "请æ±åæ°æè¯¯", |
| | | "401": "æªç»å½ï¼ç¨æ·ä¸åå¨", |
| | | "403": "ç¨æ·æ æé", |
| | | "404": "请æ±åè½ä¸åå¨", |
| | | "500": "è¯·æ±æ§è¡å¼å¸¸ï¼è¯·è系管çå" |
| | | } |
| | | |
| | | // æä½æé®å¯¹åºçè¯é³æä»¶ |
| | | const voiceFiles = { |
| | | // å
许è¿ä»æ¨¡å¼ |
| | | "11": "btn11.wav", // å
许è¿ä»æ¨¡å¼ |
| | | "12": "btn12.wav", // å
¥ä» |
| | | "13": "btn13.wav", // åºä» |
| | | // å¬å£é飿¨¡å¼ |
| | | "21": "btn21.wav", // å¬å£é飿¨¡å¼ |
| | | "22": "btn22.wav", // å¯å¨ |
| | | "23": "btn23.wav", // å
³é |
| | | // ç¦æ¢è¿ä»æ¨¡å¼ |
| | | "31": "btn31.wav", // ç¦æ¢è¿ä»æ¨¡å¼ |
| | | "32": "btn32.wav", // ç´§æ¥å
¥ä» |
| | | "33": "btn33.wav", // åºä» |
| | | // ç
§ææ§å¶ |
| | | "light_open": "light_open.wav", // å¼ç¯ |
| | | "light_close": "light_close.wav" // å
³ç¯ |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®é误ç è·åéè¯¯ä¿¡æ¯ |
| | | * @param {string} code - é误ç |
| | | * @returns {string} éè¯¯ä¿¡æ¯ |
| | | */ |
| | | function getErrorMessage(code) { |
| | | return errorMessages[code] || "æä½å¤±è´¥" |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®æä½æé®ååè½ç è·åè¯é³æä»¶ |
| | | * @param {string} functionId - åè½ç |
| | | * @param {object} params - 请æ±åæ°ï¼å
å«modeåbtn |
| | | * @returns {string} è¯é³æä»¶è·¯å¾ |
| | | */ |
| | | function getVoiceFile(functionId, params) { |
| | | // ç
§ææ§å¶åè½ |
| | | if (functionId === "3000") { |
| | | // å¼ç¯ |
| | | if (String(params.btn) === "1") return voiceFiles["light_open"] |
| | | // å
³ç¯ |
| | | if (String(params.btn) === "2") return voiceFiles["light_close"] |
| | | } |
| | | // å®å
¨å
¥ä»æ§å¶åè½ |
| | | if (functionId === "2000" && params) { |
| | | const { mode, btn } = params |
| | | // 模å¼1: å
许è¿ä»æ¨¡å¼ |
| | | if (mode === 1) { |
| | | if (!btn) return voiceFiles["11"] // å
许è¿ä»æ¨¡å¼æé® |
| | | if (String(btn) === "1") return voiceFiles["12"] // å
¥ä»æé® |
| | | if (String(btn) === "2") return voiceFiles["13"] // åºä»æé® |
| | | } |
| | | // 模å¼2: å¬å£é飿¨¡å¼ |
| | | if (mode === 2) { |
| | | if (!btn) return voiceFiles["21"] // å¬å£é飿¨¡å¼æé® |
| | | if (String(btn) === "1") return voiceFiles["22"] // å¯å¨æé® |
| | | if (String(btn) === "2") return voiceFiles["23"] // å
³éæé® |
| | | } |
| | | // 模å¼3: ç¦æ¢è¿ä»æ¨¡å¼ |
| | | if (mode === 3) { |
| | | if (!btn) return voiceFiles["31"] // ç¦æ¢è¿ä»æ¨¡å¼æé® |
| | | if (String(btn) === "1") return voiceFiles["32"] // ç´§æ¥å
¥ä»æé® |
| | | if (String(btn) === "2") return voiceFiles["33"] // åºä»æé® |
| | | } |
| | | } |
| | | return null |
| | | } |
| | | |
| | | // ä»é
ç½®ä¸è·åHTTPæ¥å£è·¯å¾ |
| | | function getHttpUrl() { |
| | | return config.get('http.safeInputAccess') || "http://192.168.1.199:80/cgi-bin/safeInputAccess" |
| | | } |
| | | |
| | | // å卿°ä½æµåº¦æ°æ® |
| | | let gasDataStorage = null |
| | | |
| | | /** |
| | | * æ£æ¥æ°ä½æµåº¦ |
| | | * @param {function} callback - åè°å½æ°ï¼å¨æ°ä½æµåº¦æ£æµå®æåè°ç¨ |
| | | * @returns {boolean} true表示æ°ä½æµåº¦åæ ¼ï¼false表示æ°ä½æµåº¦ä¸åæ ¼ |
| | | */ |
| | | grainService.checkGasConcentration = function(callback) { |
| | | // 使ç¨setTimeoutå°HTTPè¯·æ±æ¾å
¥åå°æ§è¡ï¼é¿å
é»å¡ä¸»çº¿ç¨ |
| | | std.setTimeout(() => { |
| | | try { |
| | | // ç¡®ä¿URLæ ¼å¼æ£ç¡®ï¼æ·»å http://åç¼ |
| | | let url = getHttpUrl() |
| | | if (!url.startsWith('http://') && !url.startsWith('https://')) { |
| | | url = 'http://' + url |
| | | } |
| | | |
| | | const timeout = 3000 // 3ç§è¶
æ¶ |
| | | |
| | | logger.info(`[grain]: æ£å¨è·åæ°ä½æµåº¦æ°æ®: ${url}`) |
| | | |
| | | // æå»ºPOSTè¯·æ±æ°æ® |
| | | const postData = { |
| | | sn: config.get("sys.sn") || " ", // 设å¤åºåå·ï¼ä»é
ç½®ä¸è·å |
| | | houseId: "0000", // ä»å»ç¼ç ï¼é»è®¤å¡«å
"0000" |
| | | outId: "0000", // èªå®ä¹ç¼ç ï¼é»è®¤å¡«å
"0000" |
| | | functionId: functionId.gasDetection, // æ°ä½æµåº¦æ£æµåè½ç |
| | | timestamp: Date.now().toString() // æ¶é´æ³ |
| | | } |
| | | |
| | | logger.info(`[grain]: åéPOSTè¯·æ±æ°æ®: ${JSON.stringify(postData)}`) |
| | | |
| | | // åéHTTP POSTè¯·æ± |
| | | let response = http.post(url, postData, timeout) |
| | | |
| | | // logger.info(`[grain]: æ°ä½æµåº¦æ°æ®ååº: ${JSON.stringify(response)}`) |
| | | |
| | | // è§£æååºæ°æ® |
| | | // æ£æ¥responseæ¯å¦ä¸ºå符串ï¼å¦ææ¯åè§£æä¸ºå¯¹è±¡ |
| | | if (typeof response === 'string') { |
| | | response = JSON.parse(response) |
| | | } |
| | | |
| | | if (response && response.body) { |
| | | // è§£æååºä½ |
| | | let gasData |
| | | try { |
| | | gasData = JSON.parse(response.body) |
| | | logger.info(`[grain]: è§£æåçæ°ä½æµåº¦æ°æ®: ${JSON.stringify(gasData)}`) |
| | | |
| | | // æ ¹æ®æ¥å£è¿åç¼ç è¿è¡æ¥å¿è¾åº |
| | | if (gasData.respCode === respCode.success) { |
| | | logger.info(`[grain]: æ°ä½æµåº¦æ£æµæ¥å£è°ç¨æå`) |
| | | } else { |
| | | logger.error(`[grain]: æ°ä½æµåº¦æ£æµæ¥å£è°ç¨å¤±è´¥ï¼è¿åç¼ç : ${gasData.respCode}, è¿åä¿¡æ¯: ${gasData.respMsg}`) |
| | | } |
| | | } catch (parseError) { |
| | | logger.error(`[grain]: è§£ææ°ä½æµåº¦æ°æ®å¤±è´¥: ${parseError.message}`) |
| | | // å°è¯æ¸
çååºä½ä¸ç转ä¹å符 |
| | | try { |
| | | // ç§»é¤å¤ä½ç转ä¹å符 |
| | | const cleanedBody = response.body.replace(/\\r\\n/g, '').replace(/\\t/g, '').replace(/\"/g, '"') |
| | | gasData = JSON.parse(cleanedBody) |
| | | logger.info(`[grain]: æ¸
çåè§£æçæ°ä½æµåº¦æ°æ®: ${JSON.stringify(gasData)}`) |
| | | |
| | | // æ ¹æ®æ¥å£è¿åç¼ç è¿è¡æ¥å¿è¾åº |
| | | if (gasData.respCode === respCode.success) { |
| | | logger.info(`[grain]: æ°ä½æµåº¦æ£æµæ¥å£è°ç¨æå`) |
| | | } else { |
| | | logger.error(`[grain]: æ°ä½æµåº¦æ£æµæ¥å£è°ç¨å¤±è´¥ï¼è¿åç¼ç : ${gasData.respCode}, è¿åä¿¡æ¯: ${gasData.respMsg}`) |
| | | } |
| | | } catch (cleanError) { |
| | | logger.error(`[grain]: æ¸
çåè§£ææ°ä½æµåº¦æ°æ®ä»å¤±è´¥: ${cleanError.message}`) |
| | | // è°ç¨åè°å½æ° |
| | | if (callback) { |
| | | callback() |
| | | } |
| | | return |
| | | } |
| | | } |
| | | |
| | | // å卿°ä½æ°æ® |
| | | gasDataStorage = gasData |
| | | |
| | | // æ£æ¥æ°ä½æµåº¦æ¯å¦åæ ¼ |
| | | // æ°æ ¼å¼: {"value":[{"o2":"20.5","statusO2":"0","co2":"401","statusCo2":"0","ph3":"0","statusPh3":"0"}],"status":"1"} |
| | | // statusO2/statusCo2/statusPh3: "0"è¡¨ç¤ºåæ ¼ï¼"1"表示ä¸åæ ¼ï¼ä»
ç¨äºUIæ¾ç¤ºï¼ |
| | | // data.status: "0"表示æç»åæ ¼ï¼"1"表示æç»ä¸åæ ¼ |
| | | const gasValue = gasData.data && gasData.data.value ? gasData.data.value[0] : null |
| | | const isO2Qualified = gasValue && gasValue.statusO2 === "0" |
| | | const isCo2Qualified = gasValue && gasValue.statusCo2 === "0" |
| | | const isPh3Qualified = gasValue && gasValue.statusPh3 === "0" |
| | | |
| | | // 触åäºä»¶æ´æ°UI |
| | | bus.fire('gasConcentrationUpdated', gasData) |
| | | |
| | | // æç»åæ ¼å¤æåªä¾èµstatusåæ®µå¼ |
| | | const isAllQualified = gasData.data && gasData.data.status === "0" |
| | | |
| | | if (isAllQualified) { |
| | | logger.info("[grain]: æ°ä½æµåº¦æ£æµåæ ¼") |
| | | } else { |
| | | logger.info("[grain]: æ°ä½æµåº¦æ£æµä¸åæ ¼") |
| | | } |
| | | |
| | | // è°ç¨åè°å½æ° |
| | | if (callback) { |
| | | callback() |
| | | } |
| | | } else { |
| | | logger.error(`[grain]: æ°ä½æµåº¦æ°æ®è·å失败: ${response ? "æ ååºä½" : "æ ååº"}`) |
| | | // è°ç¨åè°å½æ° |
| | | if (callback) { |
| | | callback() |
| | | } |
| | | } |
| | | } catch (error) { |
| | | logger.error(`[grain]: æ°ä½æµåº¦æ£æµé误: ${error.message}`) |
| | | // è°ç¨åè°å½æ° |
| | | if (callback) { |
| | | callback() |
| | | } |
| | | } |
| | | }, 0) |
| | | |
| | | // ç«å³è¿åï¼é¿å
é»å¡ä¸»çº¿ç¨ |
| | | return true |
| | | } |
| | | |
| | | /** |
| | | * è·ååå¨çæ°ä½æµåº¦æ°æ® |
| | | * @returns {object|null} åå¨çæ°ä½æµåº¦æ°æ®ï¼å¦ææ²¡æåè¿ånull |
| | | */ |
| | | grainService.getGasData = function() { |
| | | return gasDataStorage |
| | | } |
| | | |
| | | /** |
| | | * æ£æ¥è®¾å¤ç¶æä¿¡æ¯ |
| | | * @param {object} params - 请æ±åæ° |
| | | * @param {string} params.user1 - 人è¸è¯å«ç¨æ·1 |
| | | * @param {string} params.user2 - 人è¸è¯å«ç¨æ·2 |
| | | * @param {string} params.mode - éæ©æ¨¡å¼ï¼1-å
许å
¥ä»ï¼2-å¬å£éé£ï¼3-ç¦æ¢å
¥ä»ï¼ |
| | | * @param {string} params.btn - æä½æé®ï¼1-å
¥ä»/å¼å¯ï¼2-åºä»/å
³éï¼ |
| | | * @returns {boolean} trueè¡¨ç¤ºç¶æä¿¡æ¯è·åæåï¼false表示失败 |
| | | */ |
| | | grainService.checkDevConcentration = function(params) { |
| | | // 使ç¨setTimeoutå°HTTPè¯·æ±æ¾å
¥åå°æ§è¡ï¼é¿å
é»å¡ä¸»çº¿ç¨ |
| | | std.setTimeout(() => { |
| | | try { |
| | | // ç¡®ä¿URLæ ¼å¼æ£ç¡®ï¼æ·»å http://åç¼ |
| | | let url = getHttpUrl() |
| | | if (!url.startsWith('http://') && !url.startsWith('https://')) { |
| | | url = 'http://' + url |
| | | } |
| | | |
| | | const timeout = 3000 // 3ç§è¶
æ¶ |
| | | |
| | | // logger.info(`[grain]: æ£å¨è·åç¶æä¿¡æ¯æ°æ®: ${url}`) |
| | | |
| | | // æå»ºPOSTè¯·æ±æ°æ® |
| | | const postData = { |
| | | sn: config.get("sys.sn") || " ", // 设å¤åºåå·ï¼ä»é
ç½®ä¸è·å |
| | | houseId: "0000", // ä»å»ç¼ç ï¼é»è®¤å¡«å
"0000" |
| | | outId: "0000", // èªå®ä¹ç¼ç ï¼é»è®¤å¡«å
"0000" |
| | | functionId: params && params.functionId ? params.functionId : functionId.safeInputControl, // åè½ç ï¼é»è®¤ä¸ºå®å
¨å
¥ä»è卿§å¶ |
| | | timestamp: Date.now().toString(), // æ¶é´æ³ |
| | | data: {} |
| | | } |
| | | |
| | | // æ·»å å¯éåæ° |
| | | if (params) { |
| | | if (params.user1) postData.data.user1 = params.user1 |
| | | if (params.user2) postData.data.user2 = params.user2 |
| | | if (params.mode) postData.data.mode = params.mode |
| | | if (params.btn) postData.data.btn = params.btn |
| | | } |
| | | |
| | | logger.info(`[grain]: åéPOSTè¯·æ±æ°æ®: ${JSON.stringify(postData)}`) |
| | | |
| | | // åéHTTP POSTè¯·æ± |
| | | let response = http.post(url, postData, timeout) |
| | | |
| | | // logger.info(`[grain]: ç¶æä¿¡æ¯æ°æ®ååº: ${JSON.stringify(response)}`) |
| | | |
| | | // è§£æååºæ°æ® |
| | | // æ£æ¥responseæ¯å¦ä¸ºå符串ï¼å¦ææ¯åè§£æä¸ºå¯¹è±¡ |
| | | if (typeof response === 'string') { |
| | | response = JSON.parse(response) |
| | | } |
| | | |
| | | if (response && response.body) { |
| | | // è§£æååºä½ |
| | | let statusData |
| | | try { |
| | | statusData = JSON.parse(response.body) |
| | | logger.info(`[grain]: è§£æåçç¶æä¿¡æ¯æ°æ®: ${JSON.stringify(statusData)}`) |
| | | |
| | | // æ ¹æ®æ¥å£è¿åç¼ç è¿è¡æ¥å¿è¾åº |
| | | if (statusData.respCode === respCode.success) { |
| | | logger.info(`[grain]: ç¶æä¿¡æ¯æ¥å£è°ç¨æå`) |
| | | // æ£æ¥dataæ¯å¦ä¸ºç©ºï¼ä¸ä¸ºç©ºæè§¦åéç¥ |
| | | if (Object.keys(postData.data).length > 0) { |
| | | // 触åæåå¼¹çª |
| | | bus.fire('showAccessResult', { |
| | | faceAuth: true, |
| | | gasConcentration: true, |
| | | accessAllowed: true, |
| | | message: '*æ§è¡æå*' |
| | | }) |
| | | |
| | | // ææ¾æåè¯é³æç¤º |
| | | try { |
| | | const voiceFile = getVoiceFile(postData.functionId, postData.data) |
| | | if (voiceFile) { |
| | | driver.alsa.play(`/app/code/resource/${config.get("base.language") == "CN" ? "CN" : "EN"}/wav/${voiceFile}`) |
| | | logger.info(`[grain]: ææ¾æåè¯é³æç¤º: ${voiceFile}`) |
| | | } |
| | | } catch (error) { |
| | | logger.error(`[grain]: ææ¾è¯é³æç¤ºå¤±è´¥: ${error.message}`) |
| | | } |
| | | } |
| | | } else { |
| | | logger.error(`[grain]: ç¶æä¿¡æ¯æ¥å£è°ç¨å¤±è´¥ï¼è¿åç¼ç : ${statusData.respCode}, è¿åä¿¡æ¯: ${statusData.respMsg}`) |
| | | // æ£æ¥dataæ¯å¦ä¸ºç©ºï¼ä¸ä¸ºç©ºæè§¦åéç¥ |
| | | if (Object.keys(postData.data).length > 0) { |
| | | // 触åå¤±è´¥å¼¹çª |
| | | bus.fire('showAccessResult', { |
| | | faceAuth: true, |
| | | gasConcentration: true, |
| | | accessAllowed: false, |
| | | message: statusData.respMsg || getErrorMessage(statusData.respCode) |
| | | }) |
| | | // ææ¾å¤±è´¥è¯é³æç¤º |
| | | try { |
| | | driver.alsa.play(`/app/code/resource/${config.get("base.language") == "CN" ? "CN" : "EN"}/wav/failed.wav`) |
| | | logger.info(`[grain]: ææ¾å¤±è´¥è¯é³æç¤º: failed.wav`) |
| | | } catch (error) { |
| | | logger.error(`[grain]: ææ¾è¯é³æç¤ºå¤±è´¥: ${error.message}`) |
| | | } |
| | | } |
| | | } |
| | | } catch (parseError) { |
| | | logger.error(`[grain]: è§£æç¶æä¿¡æ¯æ°æ®å¤±è´¥: ${parseError.message}`) |
| | | // å°è¯æ¸
çååºä½ä¸ç转ä¹å符 |
| | | try { |
| | | // ç§»é¤å¤ä½ç转ä¹å符 |
| | | const cleanedBody = response.body.replace(/\\r\\n/g, '').replace(/\\t/g, '').replace(/\"/g, '"') |
| | | statusData = JSON.parse(cleanedBody) |
| | | logger.info(`[grain]: æ¸
çåè§£æçç¶æä¿¡æ¯æ°æ®: ${JSON.stringify(statusData)}`) |
| | | |
| | | // æ ¹æ®æ¥å£è¿åç¼ç è¿è¡æ¥å¿è¾åº |
| | | if (statusData.respCode === respCode.success) { |
| | | logger.info(`[grain]: ç¶æä¿¡æ¯æ¥å£è°ç¨æå`) |
| | | // æ£æ¥dataæ¯å¦ä¸ºç©ºï¼ä¸ä¸ºç©ºæè§¦åéç¥ |
| | | if (Object.keys(postData.data).length > 0) { |
| | | // 触åæåå¼¹çª |
| | | bus.fire('showAccessResult', { |
| | | faceAuth: true, |
| | | gasConcentration: true, |
| | | accessAllowed: true, |
| | | message: '*æ§è¡æå*' |
| | | }) |
| | | |
| | | // ææ¾æåè¯é³æç¤º |
| | | try { |
| | | const voiceFile = getVoiceFile(postData.functionId, postData.data) |
| | | if (voiceFile) { |
| | | driver.alsa.play(`/app/code/resource/${config.get("base.language") == "CN" ? "CN" : "EN"}/wav/${voiceFile}`) |
| | | logger.info(`[grain]: ææ¾æåè¯é³æç¤º: ${voiceFile}`) |
| | | } |
| | | } catch (error) { |
| | | logger.error(`[grain]: ææ¾è¯é³æç¤ºå¤±è´¥: ${error.message}`) |
| | | } |
| | | } |
| | | } else { |
| | | logger.error(`[grain]: ç¶æä¿¡æ¯æ¥å£è°ç¨å¤±è´¥ï¼è¿åç¼ç : ${statusData.respCode}, è¿åä¿¡æ¯: ${statusData.respMsg}`) |
| | | // æ£æ¥dataæ¯å¦ä¸ºç©ºï¼ä¸ä¸ºç©ºæè§¦åéç¥ |
| | | if (Object.keys(postData.data).length > 0) { |
| | | // 触åå¤±è´¥å¼¹çª |
| | | bus.fire('showAccessResult', { |
| | | faceAuth: true, |
| | | gasConcentration: true, |
| | | accessAllowed: false, |
| | | message: statusData.respMsg || getErrorMessage(statusData.respCode) |
| | | }) |
| | | // ææ¾å¤±è´¥è¯é³æç¤º |
| | | try { |
| | | driver.alsa.play(`/app/code/resource/${config.get("base.language") == "CN" ? "CN" : "EN"}/wav/failed.wav`) |
| | | logger.info(`[grain]: ææ¾å¤±è´¥è¯é³æç¤º: failed.wav`) |
| | | } catch (error) { |
| | | logger.error(`[grain]: ææ¾è¯é³æç¤ºå¤±è´¥: ${error.message}`) |
| | | } |
| | | } |
| | | } |
| | | } catch (cleanError) { |
| | | logger.error(`[grain]: æ¸
çåè§£æç¶æä¿¡æ¯æ°æ®ä»å¤±è´¥: ${cleanError.message}`) |
| | | return false |
| | | } |
| | | } |
| | | |
| | | // 触åäºä»¶æ´æ°UI |
| | | bus.fire('statusInfoUpdated', statusData) |
| | | |
| | | return true |
| | | } else { |
| | | logger.error(`[grain]: ç¶æä¿¡æ¯æ°æ®è·å失败: ${response ? "æ ååºä½" : "æ ååº"}`) |
| | | // ç½ç»è¯·æ±å¤±è´¥æ¶ï¼é»è®¤è¿åfalseï¼å®å
¨èµ·è§ï¼ |
| | | return false |
| | | } |
| | | } catch (error) { |
| | | logger.error(`[grain]: ç¶æä¿¡æ¯æ£æµé误: ${error.message}`) |
| | | // åçé误æ¶ï¼é»è®¤è¿åfalseï¼å®å
¨èµ·è§ï¼ |
| | | return false |
| | | } |
| | | }, 0) |
| | | |
| | | // ç«å³è¿åï¼é¿å
é»å¡ä¸»çº¿ç¨ |
| | | return true |
| | | } |
| | | |
| | | /** |
| | | * ä»å
ç
§æè卿§å¶ |
| | | * @param {object} params - 请æ±åæ° |
| | | * @param {string} params.user1 - 人è¸è¯å«ç¨æ·1 |
| | | * @param {string} params.user2 - 人è¸è¯å«ç¨æ·2 |
| | | * @param {string} params.btn - æä½æé®ï¼1-å¼ç¯ï¼2-å
³ç¯ï¼ |
| | | * @returns {boolean} true表示æ§å¶æåï¼false表示æ§å¶å¤±è´¥ |
| | | */ |
| | | grainService.controlLight = function(params) { |
| | | // 使ç¨setTimeoutå°HTTPè¯·æ±æ¾å
¥åå°æ§è¡ï¼é¿å
é»å¡ä¸»çº¿ç¨ |
| | | std.setTimeout(() => { |
| | | try { |
| | | // ç¡®ä¿URLæ ¼å¼æ£ç¡®ï¼æ·»å http://åç¼ |
| | | let url = getHttpUrl() |
| | | if (!url.startsWith('http://') && !url.startsWith('https://')) { |
| | | url = 'http://' + url |
| | | } |
| | | |
| | | const timeout = 3000 // 3ç§è¶
æ¶ |
| | | |
| | | // æå»ºPOSTè¯·æ±æ°æ® |
| | | const postData = { |
| | | sn: config.get("sys.sn") || " ", // 设å¤åºåå·ï¼ä»é
ç½®ä¸è·å |
| | | houseId: "0000", // ä»å»ç¼ç ï¼é»è®¤å¡«å
"0000" |
| | | outId: "0000", // èªå®ä¹ç¼ç ï¼é»è®¤å¡«å
"0000" |
| | | functionId: functionId.lightControl, // ä»å
ç
§æè卿§å¶åè½ç |
| | | timestamp: Date.now().toString(), // æ¶é´æ³ |
| | | data: {} |
| | | } |
| | | |
| | | // æ·»å å¯éåæ° |
| | | if (params) { |
| | | if (params.user1) postData.data.user1 = params.user1 |
| | | if (params.user2) postData.data.user2 = params.user2 |
| | | if (params.btn) postData.data.btn = params.btn |
| | | } |
| | | |
| | | logger.info(`[grain]: åéä»å
ç
§æè卿§å¶è¯·æ±æ°æ®: ${JSON.stringify(postData)}`) |
| | | |
| | | // åéHTTP POSTè¯·æ± |
| | | let response = http.post(url, postData, timeout) |
| | | |
| | | // è§£æååºæ°æ® |
| | | // æ£æ¥responseæ¯å¦ä¸ºå符串ï¼å¦ææ¯åè§£æä¸ºå¯¹è±¡ |
| | | if (typeof response === 'string') { |
| | | response = JSON.parse(response) |
| | | } |
| | | |
| | | if (response && response.body) { |
| | | // è§£æååºä½ |
| | | let statusData |
| | | try { |
| | | statusData = JSON.parse(response.body) |
| | | logger.info(`[grain]: è§£æåçä»å
ç
§æè卿§å¶ååºæ°æ®: ${JSON.stringify(statusData)}`) |
| | | |
| | | // æ ¹æ®æ¥å£è¿åç¼ç è¿è¡æ¥å¿è¾åº |
| | | if (statusData.respCode === respCode.success) { |
| | | logger.info(`[grain]: ä»å
ç
§æè卿§å¶æ¥å£è°ç¨æå`) |
| | | // 触åæåå¼¹çª |
| | | bus.fire('showAccessResult', { |
| | | faceAuth: true, |
| | | gasConcentration: true, |
| | | accessAllowed: true, |
| | | message: '*æ§è¡æå*' |
| | | }) |
| | | |
| | | // ææ¾æåè¯é³æç¤º |
| | | try { |
| | | const voiceFile = getVoiceFile(postData.functionId, postData.data) |
| | | if (voiceFile) { |
| | | driver.alsa.play(`/app/code/resource/${config.get("base.language") == "CN" ? "CN" : "EN"}/wav/${voiceFile}`) |
| | | logger.info(`[grain]: ææ¾æåè¯é³æç¤º: ${voiceFile}`) |
| | | } |
| | | } catch (error) { |
| | | logger.error(`[grain]: ææ¾è¯é³æç¤ºå¤±è´¥: ${error.message}`) |
| | | } |
| | | } else { |
| | | logger.error(`[grain]: ä»å
ç
§æè卿§å¶æ¥å£è°ç¨å¤±è´¥ï¼è¿åç¼ç : ${statusData.respCode}, è¿åä¿¡æ¯: ${statusData.respMsg}`) |
| | | // 触åå¤±è´¥å¼¹çª |
| | | bus.fire('showAccessResult', { |
| | | faceAuth: true, |
| | | gasConcentration: true, |
| | | accessAllowed: false, |
| | | message: statusData.respMsg || getErrorMessage(statusData.respCode) |
| | | }) |
| | | // ææ¾å¤±è´¥è¯é³æç¤º |
| | | try { |
| | | driver.alsa.play(`/app/code/resource/${config.get("base.language") == "CN" ? "CN" : "EN"}/wav/failed.wav`) |
| | | logger.info(`[grain]: ææ¾å¤±è´¥è¯é³æç¤º: failed.wav`) |
| | | } catch (error) { |
| | | logger.error(`[grain]: ææ¾è¯é³æç¤ºå¤±è´¥: ${error.message}`) |
| | | } |
| | | } |
| | | } catch (parseError) { |
| | | logger.error(`[grain]: è§£æä»å
ç
§æè卿§å¶ååºæ°æ®å¤±è´¥: ${parseError.message}`) |
| | | // å°è¯æ¸
çååºä½ä¸ç转ä¹å符 |
| | | try { |
| | | // ç§»é¤å¤ä½ç转ä¹å符 |
| | | const cleanedBody = response.body.replace(/\\r\\n/g, '').replace(/\\t/g, '').replace(/\"/g, '"') |
| | | statusData = JSON.parse(cleanedBody) |
| | | logger.info(`[grain]: æ¸
çåè§£æçä»å
ç
§æè卿§å¶ååºæ°æ®: ${JSON.stringify(statusData)}`) |
| | | |
| | | // æ ¹æ®æ¥å£è¿åç¼ç è¿è¡æ¥å¿è¾åº |
| | | if (statusData.respCode === respCode.success) { |
| | | logger.info(`[grain]: ä»å
ç
§æè卿§å¶æ¥å£è°ç¨æå`) |
| | | // 触åæåå¼¹çª |
| | | bus.fire('showAccessResult', { |
| | | faceAuth: true, |
| | | gasConcentration: true, |
| | | accessAllowed: true, |
| | | message: '*æ§è¡æå*' |
| | | }) |
| | | |
| | | // ææ¾æåè¯é³æç¤º |
| | | try { |
| | | const voiceFile = getVoiceFile(postData.functionId, postData.data) |
| | | if (voiceFile) { |
| | | driver.alsa.play(`/app/code/resource/${config.get("base.language") == "CN" ? "CN" : "EN"}/wav/${voiceFile}`) |
| | | logger.info(`[grain]: ææ¾æåè¯é³æç¤º: ${voiceFile}`) |
| | | } |
| | | } catch (error) { |
| | | logger.error(`[grain]: ææ¾è¯é³æç¤ºå¤±è´¥: ${error.message}`) |
| | | } |
| | | } else { |
| | | logger.error(`[grain]: ä»å
ç
§æè卿§å¶æ¥å£è°ç¨å¤±è´¥ï¼è¿åç¼ç : ${statusData.respCode}, è¿åä¿¡æ¯: ${statusData.respMsg}`) |
| | | // 触åå¤±è´¥å¼¹çª |
| | | bus.fire('showAccessResult', { |
| | | faceAuth: true, |
| | | gasConcentration: true, |
| | | accessAllowed: false, |
| | | message: statusData.respMsg || getErrorMessage(statusData.respCode) |
| | | }) |
| | | // ææ¾å¤±è´¥è¯é³æç¤º |
| | | try { |
| | | driver.alsa.play(`/app/code/resource/${config.get("base.language") == "CN" ? "CN" : "EN"}/wav/failed.wav`) |
| | | logger.info(`[grain]: ææ¾å¤±è´¥è¯é³æç¤º: failed.wav`) |
| | | } catch (error) { |
| | | logger.error(`[grain]: ææ¾è¯é³æç¤ºå¤±è´¥: ${error.message}`) |
| | | } |
| | | } |
| | | } catch (cleanError) { |
| | | logger.error(`[grain]: æ¸
çåè§£æä»å
ç
§æè卿§å¶ååºæ°æ®ä»å¤±è´¥: ${cleanError.message}`) |
| | | return false |
| | | } |
| | | } |
| | | |
| | | // 触åäºä»¶æ´æ°UI |
| | | bus.fire('statusInfoUpdated', statusData) |
| | | |
| | | return true |
| | | } else { |
| | | logger.error(`[grain]: ä»å
ç
§æè卿§å¶è¯·æ±å¤±è´¥: ${response ? "æ ååºä½" : "æ ååº"}`) |
| | | // ç½ç»è¯·æ±å¤±è´¥æ¶ï¼é»è®¤è¿åfalseï¼å®å
¨èµ·è§ï¼ |
| | | return false |
| | | } |
| | | } catch (error) { |
| | | logger.error(`[grain]: ä»å
ç
§æè卿§å¶é误: ${error.message}`) |
| | | // åçé误æ¶ï¼é»è®¤è¿åfalseï¼å®å
¨èµ·è§ï¼ |
| | | return false |
| | | } |
| | | }, 0) |
| | | |
| | | // ç«å³è¿åï¼é¿å
é»å¡ä¸»çº¿ç¨ |
| | | return true |
| | | } |
| | | |
| | | /** |
| | | * åéé¨ç£ç¶ææ¶æ¯ |
| | | * @param {object} doorStatusData - é¨ç£ç¶ææ°æ® |
| | | * @param {number} doorStatusData.status - é¨ç£ç¶æï¼0表示é¨å
³ï¼1表示é¨å¼ |
| | | * @param {string} doorStatusData.statusText - é¨ç£ç¶æææ¬ |
| | | * @param {number} doorStatusData.time - æ¶é´æ³ |
| | | */ |
| | | grainService.sendDoorStatusMessage = function(doorStatusData) { |
| | | // 使ç¨setTimeoutå°HTTPè¯·æ±æ¾å
¥åå°æ§è¡ï¼é¿å
é»å¡ä¸»çº¿ç¨ |
| | | std.setTimeout(() => { |
| | | try { |
| | | // ç¡®ä¿URLæ ¼å¼æ£ç¡®ï¼æ·»å http://åç¼ |
| | | let url = getHttpUrl() |
| | | if (!url.startsWith('http://') && !url.startsWith('https://')) { |
| | | url = 'http://' + url |
| | | } |
| | | |
| | | const timeout = 3000 // 3ç§è¶
æ¶ |
| | | |
| | | logger.info(`[grain]: æ£å¨åéé¨ç£ç¶ææ¶æ¯: ${url}`) |
| | | |
| | | // æå»ºPOSTè¯·æ±æ°æ® |
| | | const postData = { |
| | | sn: config.get("sys.sn") || " ", // 设å¤åºåå·ï¼ä»é
ç½®ä¸è·å |
| | | houseId: "0000", // ä»å»ç¼ç ï¼é»è®¤å¡«å
"0000" |
| | | outId: "0000", // èªå®ä¹ç¼ç ï¼é»è®¤å¡«å
"0000" |
| | | functionId: functionId.doorStatus, // é¨ç£ç¶æåè½ç |
| | | timestamp: Date.now().toString(), // æ¶é´æ³ |
| | | data: { |
| | | doorStatus: doorStatusData.status // é¨ç£ç¶æ |
| | | } |
| | | } |
| | | |
| | | logger.info(`[grain]: åéé¨ç£ç¶ææ¶æ¯æ°æ®: ${JSON.stringify(postData)}`) |
| | | |
| | | // åéHTTP POSTè¯·æ± |
| | | let response = http.post(url, postData, timeout) |
| | | |
| | | // è§£æååºæ°æ® |
| | | if (typeof response === 'string') { |
| | | response = JSON.parse(response) |
| | | } |
| | | |
| | | if (response && response.body) { |
| | | let respData |
| | | try { |
| | | respData = JSON.parse(response.body) |
| | | logger.info(`[grain]: é¨ç£ç¶ææ¶æ¯ååº: ${JSON.stringify(respData)}`) |
| | | } catch (error) { |
| | | logger.error(`[grain]: è§£æé¨ç£ç¶ææ¶æ¯ååºå¤±è´¥: ${error.message}`) |
| | | } |
| | | } else { |
| | | logger.info(`[grain]: é¨ç£ç¶ææ¶æ¯ååºä¸ºç©º`) |
| | | } |
| | | } catch (error) { |
| | | logger.error(`[grain]: åéé¨ç£ç¶ææ¶æ¯å¤±è´¥: ${error.message}`) |
| | | } |
| | | }, 0) |
| | | } |
| | | |
| | | // çå¬é¨ç£ç¶æååäºä»¶ |
| | | bus.on('doorStatusChanged', (doorStatusData) => { |
| | | logger.info(`[grain]: æ¥æ¶å°é¨ç£ç¶æååäºä»¶: ${JSON.stringify(doorStatusData)}`) |
| | | // è°ç¨åéé¨ç£ç¶ææ¶æ¯ç彿° |
| | | try { |
| | | if (typeof grainService.sendDoorStatusMessage === 'function') { |
| | | grainService.sendDoorStatusMessage(doorStatusData) |
| | | } else { |
| | | logger.error('[grain]: sendDoorStatusMessage 䏿¯ä¸ä¸ªå½æ°') |
| | | logger.error('[grain]: grainService.sendDoorStatusMessage =', grainService.sendDoorStatusMessage) |
| | | } |
| | | } catch (error) { |
| | | logger.error('[grain]: è°ç¨sendDoorStatusMessageåºé:', error.message) |
| | | } |
| | | }) |
| | | |
| | | export default grainService |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | /** |
| | | * MQTTæå¡æ¨¡å |
| | | * å¤çMQTTæ¶æ¯çæ¥æ¶ååéï¼å
æ¬è®¾å¤ç®¡çã人å管çãæé管ççåè½ |
| | | */ |
| | | import common from "../../dxmodules/dxCommon.js"; |
| | | import config from "../../dxmodules/dxConfig.js"; |
| | | import logger from "../../dxmodules/dxLogger.js"; |
| | | import ota from "../../dxmodules/dxOta.js"; |
| | | import std from "../../dxmodules/dxStd.js"; |
| | | import dxMap from '../../dxmodules/dxMap.js' |
| | | import driver from "../driver.js"; |
| | | import configService from "./configService.js"; |
| | | import sqliteService from "./sqliteService.js"; |
| | | import sqlite from "../../dxmodules/dxSqlite.js"; |
| | | import utils from '../common/utils/utils.js' |
| | | |
| | | const mqttService = {} |
| | | let map = dxMap.get("faceAccesss") |
| | | |
| | | /** |
| | | * æ¥æ¶MQTTæ¶æ¯å¹¶å¤ç |
| | | * @param {object} data - MQTTæ¶æ¯æ°æ® |
| | | * @param {string} data.topic - æ¶æ¯ä¸»é¢ |
| | | * @param {string} data.payload - æ¶æ¯è½½è· |
| | | */ |
| | | mqttService.receiveMsg = function (data) { |
| | | // {"topic":"ddddd","payload":"{\n \"msg\": \"world\"\n}"} |
| | | logger.info('[mqttService] receiveMsg :' + JSON.stringify(data.topic)) |
| | | // æå主é¢çæåé¨åä½ä¸ºå½æ°å |
| | | if (typeof mqttService[data.topic.match(/[^/]+$/)[0]] == 'function') { |
| | | mqttService[data.topic.match(/[^/]+$/)[0]](data) |
| | | } else { |
| | | logger.error("æªå®ç°çtopic", data.topic) |
| | | } |
| | | } |
| | | |
| | | // =================================æéå¢å æ¹æ¥================================= |
| | | /** |
| | | * æ·»å æé |
| | | * @param {object} event - MQTTäºä»¶å¯¹è±¡ |
| | | */ |
| | | mqttService.insertPermission = function (event) { |
| | | try { |
| | | logger.info('[mqttService] æ¥æ¶å°insertPermissionå½ä»¤:', JSON.stringify(event.topic)) |
| | | logger.info('[mqttService] å½ä»¤payload:', event.payload) |
| | | let payload = JSON.parse(event.payload) |
| | | let data = payload.payload && payload.payload.data ? payload.payload.data : {} |
| | | logger.info('[mqttService] è§£æåçåæ°:', JSON.stringify(data)) |
| | | let res = this.insertPermissionAgreement(data) |
| | | if (typeof res == 'string') { |
| | | logger.error('[mqttService] insertPermission失败:', res) |
| | | return reply(event, res, CODE.E_100) |
| | | } |
| | | logger.info('[mqttService] insertPermissionæå') |
| | | return reply(event) |
| | | } catch (error) { |
| | | logger.error('[mqttService] insertPermission error:', error) |
| | | return reply(event, { error: error.message }, CODE.E_100) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ·»å æééç¨åè®®æ ¼å¼ |
| | | * @param {array} data - æéæ°æ®æ°ç» |
| | | * @returns {boolean|string} true表示æåï¼string表示éè¯¯ä¿¡æ¯ |
| | | */ |
| | | mqttService.insertPermissionAgreement = function (data) { |
| | | let permissions = [] |
| | | for (let i = 0; i < data.length; i++) { |
| | | const permission = data[i]; |
| | | if (!permission.permissionId || !permission.userId) { |
| | | return "id or userId cannot be empty" |
| | | } |
| | | if (!permission.extra) { |
| | | permission.extra = "" |
| | | } |
| | | if (!permission.time) { |
| | | return "time and type cannot be empty" |
| | | } |
| | | if (permission.time.type != 0 && permission.time.type != 1 && permission.time.type != 2 && permission.time.type != 3) { |
| | | return "time type is not supported" |
| | | } |
| | | let record = {} |
| | | record.permissionId = permission.permissionId |
| | | record.userId = permission.userId |
| | | record.door = isEmpty(permission.index) ? 0 : permission.index |
| | | record.extra = isEmpty(permission.extra) ? JSON.stringify({}) : JSON.stringify(permission.extra) |
| | | record.timeType = permission.time.type |
| | | record.beginTime = permission.time.type == 0 ? 0 : permission.time.range.beginTime |
| | | record.endTime = permission.time.type == 0 ? 0 : permission.time.range.endTime |
| | | record.repeatBeginTime = permission.time.type != 2 ? 0 : permission.time.beginTime |
| | | record.repeatEndTime = permission.time.type != 2 ? 0 : permission.time.endTime |
| | | record.period = permission.time.type != 3 ? 0 : JSON.stringify(permission.time.weekPeriodTime) |
| | | let ret = sqliteService.d1_permission.save(record) |
| | | if (ret != 0) { |
| | | // 妿ä¿å失败ï¼å°è¯å é¤åéæ°ä¿å |
| | | sqliteService.d1_permission.deleteByPermissionId(record.permissionId) |
| | | ret = sqliteService.d1_permission.save(record) |
| | | if (ret != 0) { |
| | | return "sql error ret:" + ret |
| | | } else { |
| | | continue |
| | | } |
| | | } |
| | | } |
| | | return true |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢æé |
| | | * @param {object} event - MQTTäºä»¶å¯¹è±¡ |
| | | */ |
| | | mqttService.getPermission = function (event) { |
| | | try { |
| | | logger.info('[mqttService] æ¥æ¶å°getPermissionå½ä»¤:', JSON.stringify(event.topic)) |
| | | logger.info('[mqttService] å½ä»¤payload:', event.payload) |
| | | let payload = JSON.parse(event.payload) |
| | | let data = payload.payload && payload.payload.data ? payload.payload.data : {} |
| | | logger.info('[mqttService] è§£æåçæ¥è¯¢åæ°:', JSON.stringify(data)) |
| | | let res = this.getPermissionAgreement(data) |
| | | logger.info('[mqttService] æ¥è¯¢ç»æ:', JSON.stringify(res)) |
| | | return reply(event, res) |
| | | } catch (error) { |
| | | logger.error('[mqttService] getPermission error:', error) |
| | | return reply(event, { error: error.message }, CODE.E_100) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢æééç¨åè®®æ ¼å¼ |
| | | * @param {object} data - æ¥è¯¢åæ° |
| | | * @returns {object} æ¥è¯¢ç»æ |
| | | */ |
| | | mqttService.getPermissionAgreement = function (data) { |
| | | try { |
| | | // ç¡®ä¿dataåæ°ä¸ä¸ºundefined |
| | | data = data || {} |
| | | data.page = isEmpty(data.page) ? 0 : data.page |
| | | data.size = isEmpty(data.size) ? 10 : data.size |
| | | let totalCount = sqliteService.d1_permission.count(data) |
| | | let permissions = sqliteService.d1_permission.findAll(data) |
| | | // æå»ºè¿åç»æ |
| | | let content = permissions.map(permission => ({ |
| | | permissionId: permission.permissionId, |
| | | userId: permission.userId, |
| | | extra: JSON.parse(permission.extra ? permission.extra : "{}"), |
| | | time: { |
| | | type: permission.timeType, |
| | | beginTime: permission.timeType != 2 ? undefined : permission.repeatBeginTime, |
| | | endTime: permission.timeType != 2 ? undefined : permission.repeatEndTime, |
| | | range: permission.timeType === 0 ? undefined : { beginTime: permission.beginTime, endTime: permission.endTime }, |
| | | weekPeriodTime: permission.timeType != 3 ? undefined : JSON.parse(permission.period) |
| | | } |
| | | })) |
| | | return { |
| | | content: content, |
| | | page: data.page, |
| | | size: data.size, |
| | | total: totalCount, |
| | | totalPage: Math.ceil(totalCount / data.size), |
| | | count: content.length |
| | | } |
| | | } catch (error) { |
| | | logger.error('[mqttService] getPermissionAgreement error:', error) |
| | | throw error |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å 餿é |
| | | * @param {object} event - MQTTäºä»¶å¯¹è±¡ |
| | | */ |
| | | mqttService.delPermission = function (event) { |
| | | try { |
| | | logger.info('[mqttService] æ¥æ¶å°delPermissionå½ä»¤:', JSON.stringify(event.topic)) |
| | | logger.info('[mqttService] å½ä»¤payload:', event.payload) |
| | | let payload = JSON.parse(event.payload) |
| | | let data = payload.payload && payload.payload.data ? payload.payload.data : {} |
| | | logger.info('[mqttService] è§£æåçåæ°:', JSON.stringify(data)) |
| | | let res = this.delPermissionAgreement(data) |
| | | if (typeof res == 'string') { |
| | | logger.error('[mqttService] delPermission失败:', res) |
| | | return reply(event, res, CODE.E_100) |
| | | } |
| | | logger.info('[mqttService] delPermissionæå') |
| | | return reply(event) |
| | | } catch (error) { |
| | | logger.error('[mqttService] delPermission error:', error) |
| | | return reply(event, { error: error.message }, CODE.E_100) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å 餿ééç¨åè®®æ ¼å¼ |
| | | * @param {object} data - å é¤åæ° |
| | | * @returns {boolean|string} true表示æåï¼string表示éè¯¯ä¿¡æ¯ |
| | | */ |
| | | mqttService.delPermissionAgreement = function (data) { |
| | | if (data.permissionIds && data.permissionIds.length > 0) { |
| | | let ret = sqliteService.d1_permission.deleteByPermissionIdInBatch(data.permissionIds) |
| | | if (ret != 0) { |
| | | return "sql error ret:" + ret |
| | | } |
| | | } |
| | | if (data.userIds && data.userIds.length > 0) { |
| | | let ret = sqliteService.d1_permission.deleteByUserIdInBatch(data.userIds) |
| | | if (ret != 0) { |
| | | return "sql error ret:" + ret |
| | | } |
| | | } |
| | | return true |
| | | } |
| | | |
| | | /** |
| | | * æ¸
空æé |
| | | * @param {object} event - MQTTäºä»¶å¯¹è±¡ |
| | | */ |
| | | mqttService.clearPermission = function (event) { |
| | | try { |
| | | logger.info('[mqttService] æ¥æ¶å°clearPermissionå½ä»¤:', JSON.stringify(event.topic)) |
| | | logger.info('[mqttService] å½ä»¤payload:', event.payload) |
| | | let ret = sqliteService.d1_permission.deleteAll() |
| | | if (ret == 0) { |
| | | logger.info('[mqttService] clearPermissionæå') |
| | | return reply(event) |
| | | } else { |
| | | logger.error('[mqttService] clearPermission失败:', "sql error ret:" + ret) |
| | | return reply(event, "sql error ret:" + ret, CODE.E_100) |
| | | } |
| | | } catch (error) { |
| | | logger.error('[mqttService] clearPermission error:', error) |
| | | return reply(event, { error: error.message }, CODE.E_100) |
| | | } |
| | | } |
| | | |
| | | |
| | | // =================================人åå¢å æ¹æ¥================================= |
| | | /** |
| | | * æ·»å 人å |
| | | * @param {object} event - MQTTäºä»¶å¯¹è±¡ |
| | | */ |
| | | mqttService.insertUser = function (event) { |
| | | try { |
| | | logger.info('[mqttService] æ¥æ¶å°insertUserå½ä»¤:', JSON.stringify(event.topic)) |
| | | logger.info('[mqttService] å½ä»¤payload:', event.payload) |
| | | let payload = JSON.parse(event.payload) |
| | | let data = payload.payload && payload.payload.data ? payload.payload.data : [] |
| | | logger.info('[mqttService] è§£æåçåæ°:', JSON.stringify(data)) |
| | | let res = this.insertUserAgreement(data) |
| | | if (typeof res == 'string') { |
| | | logger.error('[mqttService] insertUser失败:', res) |
| | | return reply(event, res, CODE.E_100) |
| | | } |
| | | logger.info('[mqttService] insertUseræå') |
| | | return reply(event) |
| | | } catch (error) { |
| | | logger.error('[mqttService] insertUser error:', error) |
| | | return reply(event, { error: error.message }, CODE.E_100) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ·»å 人åéç¨åè®®æ ¼å¼ |
| | | * @param {array} data - äººåæ°æ®æ°ç» |
| | | * @returns {boolean|string} true表示æåï¼string表示éè¯¯ä¿¡æ¯ |
| | | */ |
| | | mqttService.insertUserAgreement = function (data) { |
| | | let persons = [] |
| | | for (let i = 0; i < data.length; i++) { |
| | | const person = data[i]; |
| | | // ä¸¥æ ¼æ£æ¥æ°æ®æ ¼å¼ |
| | | if (!person.userId || !person.name || person.type === undefined || !person.idCard) { |
| | | return "æ°æ®æ ¼å¼é误ï¼ç¼ºå°å¿
è¦å段ï¼userIdãnameãtypeãidCardï¼" |
| | | } |
| | | // æ£æ¥typeåæ®µç±»å |
| | | if (typeof person.type !== 'number') { |
| | | return "æ°æ®æ ¼å¼é误ï¼typeåæ®µå¿
é¡»æ¯æ°å" |
| | | } |
| | | // æ£æ¥typeåæ®µå¼èå´ |
| | | if (person.type < 0 || person.type > 1) { |
| | | return "æ°æ®æ ¼å¼é误ï¼typeåæ®µå¼å¿
é¡»å¨0-1ä¹é´" |
| | | } |
| | | let record = {} |
| | | record.userId = person.userId |
| | | record.name = person.name |
| | | // å¤ç人åç±»ååæ®µå身份è¯å· |
| | | let extra = {} |
| | | extra.type = person.type |
| | | extra.idCard = person.idCard |
| | | record.extra = JSON.stringify(extra) |
| | | persons.push(record) |
| | | |
| | | // å¤ç人è¸ä¿¡æ¯ |
| | | if (person.face) { |
| | | try { |
| | | logger.info('[mqttService] å¼å§å¤ç人è¸ä¿¡æ¯:', person.userId) |
| | | |
| | | let faceFilePath = person.face |
| | | |
| | | // æ£æ¥æ¯å¦æ¯base64ç¼ç çå¾çæ°æ® |
| | | if (person.face.startsWith('data:image/')) { |
| | | logger.info('[mqttService] æ£æµå°base64ç¼ç çå¾çæ°æ®') |
| | | // æåbase64æ°æ® |
| | | let base64Data = person.face.split(',')[1] |
| | | // åå»ºä¸´æ¶æä»¶ |
| | | faceFilePath = '/app/data/user/temp_face_' + person.userId + '.jpg' |
| | | std.ensurePathExists(faceFilePath) |
| | | // å°base64æ°æ®è½¬æ¢ä¸ºæä»¶ |
| | | common.base64_2binfile(faceFilePath, base64Data) |
| | | logger.info('[mqttService] å·²å°base64æ°æ®ä¿å为æä»¶:', faceFilePath) |
| | | } else { |
| | | return "æ°æ®æ ¼å¼é误ï¼faceåæ®µå¿
é¡»æ¯base64ç¼ç çå¾çæ°æ®" |
| | | } |
| | | |
| | | // æ£æ¥æä»¶æ¯å¦åå¨ |
| | | let fileExists = common.systemWithRes(`test -e "${faceFilePath}" && echo "OK" || echo "NO"`, 2) |
| | | logger.info('[mqttService] 人è¸å¾çæä»¶åå¨:', fileExists.includes('OK')) |
| | | |
| | | if (fileExists.includes('OK')) { |
| | | // 注åäººè¸ |
| | | logger.info('[mqttService] å¼å§æ³¨å人è¸:', person.userId) |
| | | let ret = driver.face.registerFaceByPicFile(person.userId, faceFilePath) |
| | | logger.info('[mqttService] 注å人è¸ç»æ:', ret) |
| | | |
| | | if (ret == 0) { |
| | | // 注åæååç§»å¨å¾çå°ç¨æ·ç®å½ |
| | | let src = "/app/data/user/" + person.userId + "/register.jpg" |
| | | std.ensurePathExists(src) |
| | | logger.info('[mqttService] ç§»å¨äººè¸å¾çå°ç¨æ·ç®å½:', faceFilePath, '->', src) |
| | | common.systemBrief('mv ' + faceFilePath + " " + src) |
| | | |
| | | // ä¿å人è¸åè¯ |
| | | logger.info('[mqttService] ä¿å人è¸åè¯:', person.userId) |
| | | let voucherRet = sqliteService.d1_voucher.save({ |
| | | keyId: std.genRandomStr(32), |
| | | type: "300", |
| | | code: src, |
| | | userId: person.userId, |
| | | extra: JSON.stringify({ faceType: 0 }) |
| | | }); |
| | | logger.info('[mqttService] ä¿å人è¸åè¯ç»æ:', voucherRet) |
| | | } else { |
| | | logger.error('[mqttService] 注å人è¸å¤±è´¥ï¼è¿åç :', ret) |
| | | } |
| | | } else { |
| | | logger.error('[mqttService] 人è¸å¾çæä»¶ä¸åå¨:', faceFilePath) |
| | | } |
| | | } catch (error) { |
| | | logger.error('[mqttService] å¤ç人è¸ä¿¡æ¯é误:', error) |
| | | return "å¤ç人è¸ä¿¡æ¯é误: " + error.message |
| | | } finally { |
| | | logger.info('[mqttService] 人è¸ä¿¡æ¯å¤ç宿:', person.userId) |
| | | } |
| | | } |
| | | } |
| | | let ret = sqliteService.d1_person.saveAll(persons) |
| | | if (ret != 0) { |
| | | //å¤±è´¥äº æè¿äºäººå
¨é½å é¤å卿°å¢ä¸ä¸ |
| | | let userIds = persons.map(obj => obj.userId); |
| | | sqliteService.d1_person.deleteByUserIdInBatch(userIds) |
| | | //éæ°æ°å¢ |
| | | let ret = sqliteService.d1_person.saveAll(persons) |
| | | if (ret != 0) { |
| | | return "sql error ret:" + ret |
| | | } |
| | | } |
| | | |
| | | // ä¸ºç¨æ·æ·»å å¯¹åºæé |
| | | for (let i = 0; i < data.length; i++) { |
| | | const person = data[i]; |
| | | let userId = person.userId |
| | | let userType = person.type |
| | | |
| | | // åªæä¿ç®¡åï¼0ï¼åç§é¿ï¼1ï¼éè¦æ·»å æé |
| | | if (userType == 0 || userType == 1) { |
| | | try { |
| | | // æ£æ¥æ¯å¦å·²å卿éè®°å½ |
| | | let existingPermissions = sqliteService.d1_permission.findByUserId(userId) |
| | | if (existingPermissions && existingPermissions.length == 0) { |
| | | // æ·»å æ°¸ä¹
æé |
| | | let permissionRet = sqliteService.d1_permission.save({ |
| | | permissionId: std.genRandomStr(32), |
| | | userId: userId, |
| | | timeType: 0, // æ°¸ä¹
æé |
| | | beginTime: 0, |
| | | endTime: 0, |
| | | repeatBeginTime: 0, |
| | | repeatEndTime: 0, |
| | | period: "" |
| | | }); |
| | | logger.info('[mqttService] ä¸ºç¨æ·æ·»å æéç»æ:', permissionRet) |
| | | } else { |
| | | logger.info('[mqttService] ç¨æ·å·²å卿éè®°å½ï¼è·³è¿æéæ·»å :', userId) |
| | | } |
| | | } catch (error) { |
| | | logger.error('[mqttService] æ·»å æéæ¶åºé:', error) |
| | | } |
| | | } |
| | | } |
| | | |
| | | return true |
| | | |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢äººå |
| | | * @param {object} event - MQTTäºä»¶å¯¹è±¡ |
| | | */ |
| | | mqttService.getUser = function (event) { |
| | | try { |
| | | logger.info('[mqttService] æ¥æ¶å°getUserå½ä»¤:', JSON.stringify(event.topic)) |
| | | logger.info('[mqttService] å½ä»¤payload:', event.payload) |
| | | let payload = JSON.parse(event.payload) |
| | | let data = payload.payload && payload.payload.data ? payload.payload.data : {} |
| | | let res = this.getUserAgreement(data) |
| | | logger.info('[mqttService] æ¥è¯¢ç»æ:', JSON.stringify(res)) |
| | | return reply(event, res) |
| | | } catch (error) { |
| | | logger.error('[mqttService] getUser error:', error) |
| | | return reply(event, { error: error.message }, CODE.E_100) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢äººåéç¨åè®®æ ¼å¼ |
| | | * @param {object} data - æ¥è¯¢åæ° |
| | | * @returns {object} æ¥è¯¢ç»æ |
| | | */ |
| | | mqttService.getUserAgreement = function (data) { |
| | | try { |
| | | data.page = isEmpty(data.page) ? 0 : data.page |
| | | data.size = isEmpty(data.size) ? 10 : data.size |
| | | let totalCount = sqliteService.d1_person.count(data) |
| | | let persons = sqliteService.d1_person.findAll(data) |
| | | // è§£æ extra åæ®µï¼JSONå符串转å为JSONå¯¹è±¡ï¼æ¶é¤è½¬ä¹å符 |
| | | persons.forEach(person => { |
| | | try { |
| | | if (person.extra) { |
| | | person.extra = JSON.parse(person.extra) |
| | | } |
| | | } catch (error) { |
| | | logger.error('[mqttService] è§£æ extra åæ®µé误:', error) |
| | | } |
| | | }) |
| | | |
| | | let result = { |
| | | content: persons, |
| | | page: data.page, |
| | | size: data.size, |
| | | total: totalCount, |
| | | totalPage: Math.ceil(totalCount / data.size), |
| | | count: persons.length |
| | | } |
| | | |
| | | return result |
| | | } catch (error) { |
| | | logger.error('[mqttService] getUserAgreement error:', error) |
| | | throw error |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å é¤äººå |
| | | * @param {object} event - MQTTäºä»¶å¯¹è±¡ |
| | | */ |
| | | mqttService.delUser = function (event) { |
| | | try { |
| | | logger.info('[mqttService] æ¥æ¶å°delUserå½ä»¤:', JSON.stringify(event.topic)) |
| | | logger.info('[mqttService] å½ä»¤payload:', event.payload) |
| | | let payload = JSON.parse(event.payload) |
| | | let data = payload.payload && payload.payload.data ? payload.payload.data : [] |
| | | logger.info('[mqttService] è§£æåçåæ°:', JSON.stringify(data)) |
| | | let res = this.delUserAgreement(data) |
| | | if (typeof res == 'string') { |
| | | logger.error('[mqttService] delUser失败:', res) |
| | | return reply(event, res, CODE.E_100) |
| | | } |
| | | logger.info('[mqttService] delUseræå') |
| | | return reply(event) |
| | | } catch (error) { |
| | | logger.error('[mqttService] delUser error:', error) |
| | | return reply(event, { error: error.message }, CODE.E_100) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å é¤äººåéç¨åè®®æ ¼å¼ |
| | | * @param {array} data - 人åIDæ°ç» |
| | | * @returns {boolean|string} true表示æåï¼string表示éè¯¯ä¿¡æ¯ |
| | | */ |
| | | mqttService.delUserAgreement = function (data) { |
| | | if (data && data.length > 0) { |
| | | sqliteService.transaction() |
| | | let ret1 = sqliteService.d1_person.deleteByUserIdInBatch(data) |
| | | let ret2 = sqliteService.d1_permission.deleteByUserIdInBatch(data) |
| | | let ret3 = sqliteService.d1_voucher.deleteByUserIdInBatch(data) |
| | | if (ret1 != 0 || ret2 != 0 || ret3 != 0) { |
| | | sqliteService.rollback() |
| | | return "sql error" |
| | | } |
| | | sqliteService.commit() |
| | | // å é¤äººåçäººè¸æ°æ® |
| | | data.forEach(element => { |
| | | driver.face.delete(element) |
| | | }); |
| | | } |
| | | return true |
| | | } |
| | | |
| | | |
| | | /** |
| | | * æ¸
空人å |
| | | * @param {object} event - MQTTäºä»¶å¯¹è±¡ |
| | | */ |
| | | mqttService.clearUser = function (event) { |
| | | try { |
| | | logger.info('[mqttService] æ¥æ¶å°clearUserå½ä»¤:', JSON.stringify(event.topic)) |
| | | logger.info('[mqttService] å½ä»¤payload:', event.payload) |
| | | let persons = sqliteService.d1_person.findAll() |
| | | // å 餿æäººåçäººè¸æ°æ® |
| | | logger.info('[mqttService] å¼å§å é¤äººè¸æ°æ®ï¼å
±', persons.length, 'æ¡') |
| | | persons.forEach(element => { |
| | | driver.face.delete(element.userId) |
| | | }); |
| | | let ret1 = sqliteService.d1_person.deleteAll() |
| | | let ret2 = sqliteService.d1_permission.deleteAll() |
| | | let ret3 = sqliteService.d1_voucher.deleteAll() |
| | | if (ret1 == 0 && ret2 == 0 && ret3 == 0) { |
| | | logger.info('[mqttService] clearUseræå') |
| | | return reply(event) |
| | | } else { |
| | | let errorMsg = "sql error ret: " + ret1 + ", " + ret2 + ", " + ret3 |
| | | logger.error('[mqttService] clearUser失败:', errorMsg) |
| | | return reply(event, errorMsg, CODE.E_100) |
| | | } |
| | | } catch (error) { |
| | | logger.error('[mqttService] clearUser error:', error) |
| | | return reply(event, { error: error.message }, CODE.E_100) |
| | | } |
| | | } |
| | | |
| | | // =================================åè¯å¢å æ¹æ¥================================= |
| | | /** |
| | | * æ·»å åè¯ |
| | | * @param {object} event - MQTTäºä»¶å¯¹è±¡ |
| | | */ |
| | | mqttService.insertKey = function (event) { |
| | | try { |
| | | logger.info('[mqttService] æ¥æ¶å°insertKeyå½ä»¤:', JSON.stringify(event.topic)) |
| | | logger.info('[mqttService] å½ä»¤payload:', event.payload) |
| | | let payload = JSON.parse(event.payload) |
| | | let data = payload.payload && payload.payload.data ? payload.payload.data : {} |
| | | logger.info('[mqttService] è§£æåçåæ°:', JSON.stringify(data)) |
| | | let res = this.insertKeyAgreement(data) |
| | | if (typeof res == 'string') { |
| | | logger.error('[mqttService] insertKey失败:', res) |
| | | return reply(event, res, CODE.E_100) |
| | | } |
| | | logger.info('[mqttService] insertKeyæå') |
| | | return reply(event) |
| | | } catch (error) { |
| | | logger.error('[mqttService] insertKey error:', error) |
| | | return reply(event, { error: error.message }, CODE.E_100) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ·»å åè¯éç¨åè®®æ ¼å¼ |
| | | * @param {array} data - åè¯æ°æ®æ°ç» |
| | | * @returns {boolean|string} true表示æåï¼string表示éè¯¯ä¿¡æ¯ |
| | | */ |
| | | mqttService.insertKeyAgreement = function (data) { |
| | | let vouchers = [] |
| | | for (let i = 0; i < data.length; i++) { |
| | | const voucher = data[i]; |
| | | if (!voucher.keyId || !voucher.type || !voucher.code || !voucher.userId) { |
| | | return "keyId or type or code or userId cannot be empty" |
| | | } |
| | | |
| | | // åè¯éå¤ |
| | | let ret = sqliteService.d1_voucher.findAllBycode(voucher.code) |
| | | if (ret.length != 0) { |
| | | return "Duplicate vouchers" |
| | | } |
| | | |
| | | if (voucher.type == 300) { |
| | | if (voucher.extra) { |
| | | if (voucher.extra.faceType != 0 && voucher.extra.faceType != 1) { |
| | | return "faceType Incorrect format" |
| | | } |
| | | } else { |
| | | return "faceType is required" |
| | | } |
| | | } |
| | | let record = {} |
| | | record.keyId = voucher.keyId |
| | | record.type = voucher.type |
| | | if (voucher.type == "400") { |
| | | if (voucher.code.length > 6) { |
| | | return "Password length cannot exceed 6 digits" |
| | | } |
| | | } |
| | | if (voucher.type == "300") { |
| | | if (voucher.extra.faceType == 0) { |
| | | record.code = `/app/data/user/${voucher.userId}/register.jpg` |
| | | // ä¿åbase64å¾ç |
| | | std.ensurePathExists(record.code) |
| | | common.base64_2binfile(record.code, voucher.code) |
| | | // 注åäººè¸ |
| | | let weq = driver.face.registerFaceByPicFile(voucher.userId, record.code) |
| | | if (weq == 0) { |
| | | logger.info("注åäººè¸æå") |
| | | } else { |
| | | logger.info("ç¬¬ä¸æ¬¡äººè¸æ³¨å失败") |
| | | //å é¤éæ°æ³¨å |
| | | driver.face.delete(voucher.userId) |
| | | let res = driver.face.registerFaceByPicFile(voucher.userId, record.code) |
| | | if (res == 0) { |
| | | logger.info("ç¬¬äºæ¬¡æ³¨åäººè¸æå") |
| | | sqliteService.d1_voucher.deleteByKeyId(record.keyId) |
| | | } else { |
| | | return "Face registration failed" |
| | | } |
| | | } |
| | | } else { |
| | | record.code = voucher.code |
| | | //ç¹å¾å¼æ³¨å |
| | | let res = driver.face.reg(voucher.userId, voucher.code) |
| | | if (res != 0) { |
| | | return "Face registration failed" |
| | | } |
| | | } |
| | | } else { |
| | | record.code = voucher.code |
| | | let ret = sqliteService.d1_voucher.findAllByCodeAndType(voucher.code, voucher.type) |
| | | if (ret.length != 0) { |
| | | return "Duplicate vouchers" |
| | | } |
| | | } |
| | | |
| | | record.userId = voucher.userId |
| | | record.extra = isEmpty(voucher.extra) ? JSON.stringify({ type: 0 }) : JSON.stringify(voucher.extra) |
| | | vouchers.push(record) |
| | | } |
| | | let ret = sqliteService.d1_voucher.saveAll(vouchers) |
| | | if (ret == 0) { |
| | | return true |
| | | } else { |
| | | return "sql error ret:" + ret |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢åè¯ |
| | | * @param {object} event - MQTTäºä»¶å¯¹è±¡ |
| | | */ |
| | | mqttService.getKey = function (event) { |
| | | try { |
| | | logger.info('[mqttService] æ¥æ¶å°getKeyå½ä»¤:', JSON.stringify(event.topic)) |
| | | logger.info('[mqttService] å½ä»¤payload:', event.payload) |
| | | let payload = JSON.parse(event.payload) |
| | | let data = payload.payload && payload.payload.data ? payload.payload.data : {} |
| | | logger.info('[mqttService] è§£æåçæ¥è¯¢åæ°:', JSON.stringify(data)) |
| | | let res = this.getKeyAgreement(data) |
| | | if (typeof res == 'string') { |
| | | logger.error('[mqttService] getKey失败:', res) |
| | | return reply(event, res, CODE.E_100) |
| | | } |
| | | logger.info('[mqttService] æ¥è¯¢ç»æ:', JSON.stringify(res)) |
| | | return reply(event, res) |
| | | } catch (error) { |
| | | logger.error('[mqttService] getKey error:', error) |
| | | return reply(event, { error: error.message }, CODE.E_100) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢åè¯éç¨åè®®æ ¼å¼ |
| | | * @param {object} data - æ¥è¯¢åæ° |
| | | * @returns {object|string} æ¥è¯¢ç»ææéè¯¯ä¿¡æ¯ |
| | | */ |
| | | mqttService.getKeyAgreement = function (data) { |
| | | if (!data.type) { |
| | | return "type is required" |
| | | } |
| | | if (data.type == 300) { |
| | | data.size = 1 |
| | | } else { |
| | | data.page = isEmpty(data.page) ? 0 : data.page |
| | | data.size = isEmpty(data.size) ? 10 : data.size |
| | | } |
| | | let totalCount = sqliteService.d1_voucher.count(data) |
| | | let vouchers = sqliteService.d1_voucher.findAll(data) |
| | | vouchers.forEach(element => { |
| | | if (element.type == 300 && element.extra && JSON.parse(element.extra).faceType == 0) { |
| | | //人è¸ç¹æ®å¤çä¸ä¸ |
| | | element.code = driver.face.fileToBase64(element.code) |
| | | } |
| | | }); |
| | | return { |
| | | content: vouchers, |
| | | page: data.page, |
| | | size: data.size, |
| | | total: totalCount, |
| | | totalPage: Math.ceil(totalCount / data.size), |
| | | count: vouchers.length |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å é¤åè¯ |
| | | * @param {object} event - MQTTäºä»¶å¯¹è±¡ |
| | | */ |
| | | mqttService.delKey = function (event) { |
| | | try { |
| | | logger.info('[mqttService] æ¥æ¶å°delKeyå½ä»¤:', JSON.stringify(event.topic)) |
| | | logger.info('[mqttService] å½ä»¤payload:', event.payload) |
| | | let payload = JSON.parse(event.payload) |
| | | let data = payload.payload && payload.payload.data ? payload.payload.data : {} |
| | | logger.info('[mqttService] è§£æåçåæ°:', JSON.stringify(data)) |
| | | let res = this.delKeyAgreement(data) |
| | | if (typeof res == 'string') { |
| | | logger.error('[mqttService] delKey失败:', res) |
| | | return reply(event, res, CODE.E_100) |
| | | } |
| | | logger.info('[mqttService] delKeyæå') |
| | | return reply(event) |
| | | } catch (error) { |
| | | logger.error('[mqttService] delKey error:', error) |
| | | return reply(event, { error: error.message }, CODE.E_100) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å é¤åè¯éç¨åè®®æ ¼å¼ |
| | | * @param {object} data - å é¤åæ° |
| | | * @returns {boolean|string} true表示æåï¼string表示éè¯¯ä¿¡æ¯ |
| | | */ |
| | | mqttService.delKeyAgreement = function (data) { |
| | | if (data.keyIds && data.keyIds.length > 0) { |
| | | let userIds = [] |
| | | for (let i = 0; i < data.keyIds.length; i++) { |
| | | const element = data.keyIds[i]; |
| | | let res = sqliteService.d1_voucher.findAllByKeyId(element) |
| | | if (res.length <= 0) { |
| | | continue |
| | | } |
| | | if (res[0].type == 300) { |
| | | userIds.push(res[0].userId) |
| | | } |
| | | } |
| | | let ret = sqliteService.d1_voucher.deleteByKeyIdInBatch(data.keyIds) |
| | | if (ret != 0) { |
| | | return "sql error ret:" + ret |
| | | } |
| | | // å é¤äººè¸æ°æ® |
| | | userIds.forEach(element => { |
| | | driver.face.delete(element) |
| | | }); |
| | | } |
| | | if (data.userIds && data.userIds.length > 0) { |
| | | let ret = sqliteService.d1_voucher.deleteByUserIdInBatch(data.userIds) |
| | | if (ret != 0) { |
| | | return "sql error ret:" + ret |
| | | } |
| | | // å é¤äººè¸æ°æ® |
| | | data.userIds.forEach(element => { |
| | | driver.face.delete(element) |
| | | }); |
| | | } |
| | | return true |
| | | } |
| | | |
| | | /** |
| | | * æ¸
空åè¯ |
| | | * @param {object} event - MQTTäºä»¶å¯¹è±¡ |
| | | */ |
| | | mqttService.clearKey = function (event) { |
| | | try { |
| | | logger.info('[mqttService] æ¥æ¶å°clearKeyå½ä»¤:', JSON.stringify(event.topic)) |
| | | logger.info('[mqttService] å½ä»¤payload:', event.payload) |
| | | let res = sqliteService.d1_voucher.findAll() |
| | | let userIds = [] |
| | | res.forEach(element => { |
| | | if (element.type == 300) { |
| | | userIds.push(element.userId) |
| | | } |
| | | }); |
| | | logger.info('[mqttService] æ¾å°éè¦å é¤çäººè¸æ°æ®ï¼å
±', userIds.length, 'æ¡') |
| | | let ret = sqliteService.d1_voucher.deleteAll() |
| | | if (ret == 0) { |
| | | // å é¤äººè¸æ°æ® |
| | | logger.info('[mqttService] å¼å§å é¤äººè¸æ°æ®') |
| | | userIds.forEach((element, index) => { |
| | | driver.face.delete(element) |
| | | }); |
| | | logger.info('[mqttService] clearKeyæå') |
| | | reply(event) |
| | | } else { |
| | | logger.error('[mqttService] clearKey失败:', "sql error ret:" + ret) |
| | | reply(event, "sql error ret:" + ret, CODE.E_100) |
| | | } |
| | | } catch (error) { |
| | | logger.error('[mqttService] clearKey error:', error) |
| | | return reply(event, { error: error.message }, CODE.E_100) |
| | | } |
| | | } |
| | | |
| | | // =================================åºæ¥å¼ä»å¯ç å¢å æ¹æ¥================================= |
| | | /** |
| | | * æ·»å åºæ¥å¼ä»å¯ç |
| | | * @param {object} event - MQTTäºä»¶å¯¹è±¡ |
| | | */ |
| | | mqttService.insertEmergencyPassword = function (event) { |
| | | try { |
| | | logger.info('[mqttService] æ¥æ¶å°insertEmergencyPasswordå½ä»¤:', JSON.stringify(event.topic)) |
| | | logger.info('[mqttService] å½ä»¤payload:', event.payload) |
| | | let payload = JSON.parse(event.payload) |
| | | let data = payload.payload && payload.payload.data ? payload.payload.data : {} |
| | | logger.info('[mqttService] è§£æåçåæ°:', JSON.stringify(data)) |
| | | let res = this.insertEmergencyPasswordAgreement(data) |
| | | if (typeof res == 'string') { |
| | | logger.error('[mqttService] insertEmergencyPassword失败:', res) |
| | | return reply(event, res, CODE.E_100) |
| | | } |
| | | logger.info('[mqttService] insertEmergencyPasswordæå') |
| | | return reply(event) |
| | | } catch (error) { |
| | | logger.error('[mqttService] insertEmergencyPassword error:', error) |
| | | return reply(event, { error: error.message }, CODE.E_100) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ·»å åºæ¥å¼ä»å¯ç éç¨åè®®æ ¼å¼ |
| | | * @param {object} data - åºæ¥å¼ä»å¯ç æ°æ®å¯¹è±¡ |
| | | * @returns {boolean|string} true表示æåï¼string表示éè¯¯ä¿¡æ¯ |
| | | */ |
| | | mqttService.insertEmergencyPasswordAgreement = function (data) { |
| | | // åºæ¥å¼ä»å¯ç å¨è®¾å¤ä¸ä»
æå¯ä¸ç1ä¸ªï¼æä»¥å
æ¸
空表 |
| | | let deleteRet = sqliteService.d1_emergency_password.deleteAll() |
| | | if (deleteRet != 0) { |
| | | return "æ¸
空æ§å¯ç 失败: " + deleteRet |
| | | } |
| | | |
| | | // æ£æ¥å¯ç æ¯å¦ææ |
| | | if (!data.password) { |
| | | return "password cannot be empty" |
| | | } |
| | | |
| | | // æ£æ¥å¯ç é¿åº¦æ¯å¦å¤§äºçäº8ä½ |
| | | if (data.password.length < 8) { |
| | | return "Password length must be at least 8 digits" |
| | | } |
| | | |
| | | // æå»ºå¯ç è®°å½ |
| | | let record = {} |
| | | record.id = data.id || 'emergency_' + Date.now() // å¦ææ²¡æidï¼èªå¨çæ |
| | | record.password = data.password |
| | | record.description = data.description || "" |
| | | record.createTime = Date.now() |
| | | record.updateTime = Date.now() |
| | | record.status = data.status || 1 |
| | | |
| | | // ä¿åå¯ç |
| | | let ret = sqliteService.d1_emergency_password.save(record) |
| | | if (ret == 0) { |
| | | return true |
| | | } else { |
| | | return "sql error ret:" + ret |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢åºæ¥å¼ä»å¯ç |
| | | * @param {object} event - MQTTäºä»¶å¯¹è±¡ |
| | | */ |
| | | mqttService.getEmergencyPassword = function (event) { |
| | | try { |
| | | logger.info('[mqttService] æ¥æ¶å°getEmergencyPasswordå½ä»¤:', JSON.stringify(event.topic)) |
| | | logger.info('[mqttService] å½ä»¤payload:', event.payload) |
| | | let payload = JSON.parse(event.payload) |
| | | let res = this.getEmergencyPasswordAgreement() |
| | | logger.info('[mqttService] æ¥è¯¢ç»æ:', JSON.stringify(res)) |
| | | return reply(event, res) |
| | | } catch (error) { |
| | | logger.error('[mqttService] getEmergencyPassword error:', error) |
| | | return reply(event, { error: error.message }, CODE.E_100) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ¶é´æ³è½¬æ¥æå符串 |
| | | * @param {number} timestamp - æ¶é´æ³ |
| | | * @returns {string} æ¥æåç¬¦ä¸²ï¼æ ¼å¼ï¼YYYY-MM-DD HH:MM:SS |
| | | */ |
| | | function timestampToDateString(timestamp) { |
| | | const date = new Date(timestamp); |
| | | const year = date.getFullYear(); |
| | | const month = String(date.getMonth() + 1).padStart(2, '0'); |
| | | const day = String(date.getDate()).padStart(2, '0'); |
| | | const hours = String(date.getHours()).padStart(2, '0'); |
| | | const minutes = String(date.getMinutes()).padStart(2, '0'); |
| | | const seconds = String(date.getSeconds()).padStart(2, '0'); |
| | | return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢åºæ¥å¼ä»å¯ç éç¨åè®®æ ¼å¼ |
| | | * @returns {object} æ¥è¯¢ç»æ |
| | | */ |
| | | mqttService.getEmergencyPasswordAgreement = function () { |
| | | let passwords = sqliteService.d1_emergency_password.findAll() |
| | | if (passwords && passwords.length > 0) { |
| | | let password = passwords[0]; |
| | | // è½¬æ¢æ¶é´æ³ä¸ºåç¬¦ä¸²æ ¼å¼ |
| | | password.createTime = timestampToDateString(password.createTime); |
| | | password.updateTime = timestampToDateString(password.updateTime); |
| | | return password; |
| | | } |
| | | return {}; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * æ¸
ç©ºåºæ¥å¼ä»å¯ç |
| | | * @param {object} event - MQTTäºä»¶å¯¹è±¡ |
| | | */ |
| | | mqttService.clearEmergencyPassword = function (event) { |
| | | try { |
| | | logger.info('[mqttService] æ¥æ¶å°clearEmergencyPasswordå½ä»¤:', JSON.stringify(event.topic)) |
| | | logger.info('[mqttService] å½ä»¤payload:', event.payload) |
| | | let ret = sqliteService.d1_emergency_password.deleteAll() |
| | | if (ret == 0) { |
| | | logger.info('[mqttService] clearEmergencyPasswordæå') |
| | | return reply(event) |
| | | } else { |
| | | logger.error('[mqttService] clearEmergencyPassword失败:', "sql error ret:" + ret) |
| | | return reply(event, "sql error ret:" + ret, CODE.E_100) |
| | | } |
| | | } catch (error) { |
| | | logger.error('[mqttService] clearEmergencyPassword error:', error) |
| | | return reply(event, { error: error.message }, CODE.E_100) |
| | | } |
| | | } |
| | | |
| | | // =================================å¯é¥å¢å æ¹æ¥================================= |
| | | /** |
| | | * æ·»å å¯é¥ |
| | | * @param {object} event - MQTTäºä»¶å¯¹è±¡ |
| | | */ |
| | | mqttService.insertSecurity = function (event) { |
| | | try { |
| | | logger.info('[mqttService] æ¥æ¶å°insertSecurityå½ä»¤:', JSON.stringify(event.topic)) |
| | | logger.info('[mqttService] å½ä»¤payload:', event.payload) |
| | | let payload = JSON.parse(event.payload) |
| | | let data = payload.payload && payload.payload.data ? payload.payload.data : {} |
| | | logger.info('[mqttService] è§£æåçåæ°:', JSON.stringify(data)) |
| | | let res = this.insertSecurityAgreement(data) |
| | | if (typeof res == 'string') { |
| | | logger.error('[mqttService] insertSecurity失败:', res) |
| | | return reply(event, res, CODE.E_100) |
| | | } |
| | | logger.info('[mqttService] insertSecurityæå') |
| | | return reply(event) |
| | | } catch (error) { |
| | | logger.error('[mqttService] insertSecurity error:', error) |
| | | return reply(event, { error: error.message }, CODE.E_100) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ·»å å¯é¥éç¨åè®®æ ¼å¼ |
| | | * @param {array} data - å¯é¥æ°æ®æ°ç» |
| | | * @returns {boolean|string} true表示æåï¼string表示éè¯¯ä¿¡æ¯ |
| | | */ |
| | | mqttService.insertSecurityAgreement = function (data) { |
| | | let securities = [] |
| | | for (let i = 0; i < data.length; i++) { |
| | | const security = data[i]; |
| | | let record = [] |
| | | record.securityId = security.securityId |
| | | record.type = security.type |
| | | record.key = security.key |
| | | record.value = security.value |
| | | record.startTime = security.startTime |
| | | record.endTime = security.endTime |
| | | securities.push(record) |
| | | } |
| | | let ret = sqliteService.d1_security.saveAll(securities) |
| | | if (ret == 0) { |
| | | return true |
| | | } else { |
| | | return "sql error ret:" + ret |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢å¯é¥ |
| | | * @param {object} event - MQTTäºä»¶å¯¹è±¡ |
| | | */ |
| | | mqttService.getKey = function (event) { |
| | | try { |
| | | logger.info('[mqttService] æ¥æ¶å°getKeyå½ä»¤:', JSON.stringify(event.topic)) |
| | | logger.info('[mqttService] å½ä»¤payload:', event.payload) |
| | | let payload = JSON.parse(event.payload) |
| | | let data = payload.payload && payload.payload.data ? payload.payload.data : {} |
| | | logger.info('[mqttService] è§£æåçæ¥è¯¢åæ°:', JSON.stringify(data)) |
| | | let res = this.getKeyAgreement(data) |
| | | logger.info('[mqttService] æ¥è¯¢ç»æ:', JSON.stringify(res)) |
| | | return reply(event, res) |
| | | } catch (error) { |
| | | logger.error('[mqttService] getKey error:', error) |
| | | return reply(event, { error: error.message }, CODE.E_100) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢å¯é¥éç¨åè®®æ ¼å¼ |
| | | * @param {object} data - æ¥è¯¢åæ° |
| | | * @returns {object} æ¥è¯¢ç»æ |
| | | */ |
| | | mqttService.getSecurityAgreement = function (data) { |
| | | data.page = isEmpty(data.page) ? 0 : data.page |
| | | data.size = isEmpty(data.size) ? 10 : data.size |
| | | let totalCount = sqliteService.d1_security.count(data) |
| | | let securities = sqliteService.d1_security.findAll(data) |
| | | return { |
| | | content: securities, |
| | | page: data.page, |
| | | size: data.size, |
| | | total: totalCount, |
| | | totalPage: Math.ceil(totalCount / data.size), |
| | | count: securities.length |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å é¤å¯é¥ |
| | | * @param {object} event - MQTTäºä»¶å¯¹è±¡ |
| | | */ |
| | | mqttService.delSecurity = function (event) { |
| | | try { |
| | | logger.info('[mqttService] æ¥æ¶å°delSecurityå½ä»¤:', JSON.stringify(event.topic)) |
| | | logger.info('[mqttService] å½ä»¤payload:', event.payload) |
| | | let payload = JSON.parse(event.payload) |
| | | let data = payload.payload && payload.payload.data ? payload.payload.data : {} |
| | | logger.info('[mqttService] è§£æåçåæ°:', JSON.stringify(data)) |
| | | let res = this.delSecurityAgreement(data) |
| | | if (typeof res == 'string') { |
| | | logger.error('[mqttService] delSecurity失败:', res) |
| | | return reply(event, res, CODE.E_100) |
| | | } |
| | | logger.info('[mqttService] delSecurityæå') |
| | | return reply(event) |
| | | } catch (error) { |
| | | logger.error('[mqttService] delSecurity error:', error) |
| | | return reply(event, { error: error.message }, CODE.E_100) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å é¤å¯é¥éç¨åè®®æ ¼å¼ |
| | | * @param {array} data - å¯é¥IDæ°ç» |
| | | * @returns {boolean|string} true表示æåï¼string表示éè¯¯ä¿¡æ¯ |
| | | */ |
| | | mqttService.delSecurityAgreement = function (data) { |
| | | if (data.length > 0) { |
| | | let ret = sqliteService.d1_security.deleteBySecurityIdInBatch(data) |
| | | if (ret != 0) { |
| | | return "sql error ret:" + ret |
| | | } |
| | | } |
| | | return true |
| | | } |
| | | |
| | | /** |
| | | * æ¸
空å¯é¥ |
| | | * @param {object} event - MQTTäºä»¶å¯¹è±¡ |
| | | */ |
| | | mqttService.clearSecurity = function (event) { |
| | | try { |
| | | logger.info('[mqttService] æ¥æ¶å°clearSecurityå½ä»¤:', JSON.stringify(event.topic)) |
| | | logger.info('[mqttService] å½ä»¤payload:', event.payload) |
| | | let ret = sqliteService.d1_key.deleteAll() |
| | | if (ret == 0) { |
| | | logger.info('[mqttService] clearSecurityæå') |
| | | return reply(event) |
| | | } else { |
| | | logger.error('[mqttService] clearSecurity失败:', "sql error ret:" + ret) |
| | | return reply(event, "sql error ret:" + ret, CODE.E_100) |
| | | } |
| | | } catch (error) { |
| | | logger.error('[mqttService] clearSecurity error:', error) |
| | | return reply(event, { error: error.message }, CODE.E_100) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è¿ç¨æ§å¶ |
| | | * @param {object} event - MQTTäºä»¶å¯¹è±¡ |
| | | */ |
| | | mqttService.control = function (event) { |
| | | try { |
| | | logger.info('[mqttService] æ¥æ¶å°controlå½ä»¤:', JSON.stringify(event.topic)) |
| | | logger.info('[mqttService] å½ä»¤payload:', event.payload) |
| | | let payload = JSON.parse(event.payload) |
| | | let data = payload.payload.data || {} |
| | | switch (data.command) { |
| | | case 0: |
| | | //éå¯ |
| | | logger.info('[mqttService] æ§è¡éå¯å½ä»¤') |
| | | reply(event) |
| | | common.asyncReboot(2) |
| | | return |
| | | case 1: |
| | | //è¿ç¨å¼é¨ |
| | | logger.info('[mqttService] æ§è¡è¿ç¨å¼é¨å½ä»¤') |
| | | driver.gpio.open() |
| | | break |
| | | case 4: |
| | | //éç½® |
| | | logger.info('[mqttService] æ§è¡éç½®å½ä»¤') |
| | | common.systemBrief("rm -rf /app/data/config/*") |
| | | common.systemBrief("rm -rf /app/data/db/*") |
| | | common.systemBrief("rm -rf /app/data/user/*") |
| | | common.systemBrief("rm -rf /app/data/user/*") |
| | | common.systemBrief("rm -rf /vgmj.db") |
| | | reply(event) |
| | | common.asyncReboot(2) |
| | | return |
| | | case 5: |
| | | //ææ¾è¯é³ |
| | | logger.info('[mqttService] æ§è¡ææ¾è¯é³å½ä»¤') |
| | | if (data.extra) { |
| | | let res = common.systemWithRes(`test -e "/app/code/resource/wav/${data.extra.wav}.wav" && echo "OK" || echo "NO"`, 2) |
| | | if (res.includes('OK')) { |
| | | driver.alsa.play(`/app/code/resource/wav/${data.extra.wav}.wav`) |
| | | } |
| | | } |
| | | break |
| | | case 6: |
| | | // 6ï¼å±å¹å±ç¤ºå¾ç |
| | | // TODO |
| | | logger.info('[mqttService] æ§è¡å±å¹å±ç¤ºå¾çå½ä»¤') |
| | | break |
| | | case 7: |
| | | // 7ï¼å±å¹å±ç¤ºæå |
| | | // TODO |
| | | logger.info('[mqttService] æ§è¡å±å¹å±ç¤ºæåå½ä»¤') |
| | | break |
| | | case 10: |
| | | logger.info('[mqttService] æ§è¡äºç»´ç å±ç¤ºå½ä»¤') |
| | | if (!isEmpty(data.extra.qrCodeBase64) && typeof data.extra.qrCodeBase64 == 'string') { |
| | | //base64转å¾çä¿å |
| | | let src = `/app/code/resource/image/app_qrcode.png` |
| | | std.ensurePathExists(src) |
| | | common.base64_2binfile(src, data.extra.qrCodeBase64) |
| | | logger.info('[mqttService] äºç»´ç ä¿åæå') |
| | | return reply(event) |
| | | } |
| | | break |
| | | default: |
| | | logger.info('[mqttService] æªç¥å½ä»¤:', data.command) |
| | | break |
| | | } |
| | | logger.info('[mqttService] controlå½ä»¤æ§è¡å®æ') |
| | | return reply(event) |
| | | } catch (error) { |
| | | logger.error('[mqttService] control error:', error) |
| | | return reply(event, { error: error.message }, CODE.E_100) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢é
ç½® |
| | | * @param {object} event - MQTTäºä»¶å¯¹è±¡ |
| | | */ |
| | | mqttService.getConfig = function (event) { |
| | | try { |
| | | logger.info('[mqttService] æ¥æ¶å°getConfigå½ä»¤:', JSON.stringify(event.topic)) |
| | | logger.info('[mqttService] å½ä»¤payload:', event.payload) |
| | | let payload = JSON.parse(event.payload) |
| | | let data = payload.payload && payload.payload.data ? payload.payload.data : {} |
| | | logger.info('[mqttService] è§£æåçåæ°:', JSON.stringify(data)) |
| | | let configAll = config.getAll() |
| | | let res = {} |
| | | // é
ç½®åç» |
| | | for (const key in configAll) { |
| | | const value = configAll[key]; |
| | | const keys = key.split(".") |
| | | if (keys.length == 2) { |
| | | if (!res[keys[0]]) { |
| | | res[keys[0]] = {} |
| | | } |
| | | res[keys[0]][keys[1]] = value |
| | | } else { |
| | | res[keys[0]] = value |
| | | } |
| | | } |
| | | res.sys = { |
| | | // ä¿çåæç sysInfo ä¸çå
¶ä»å¼ |
| | | ...res.sys, |
| | | totalmem: common.getTotalmem(), |
| | | freemem: common.getFreemem(), |
| | | totaldisk: common.getTotaldisk(), |
| | | freedisk: common.getFreedisk(), |
| | | freecpu: common.getFreecpu() |
| | | }; |
| | | if (isEmpty(data) || typeof data != "string" || data == "") { |
| | | // æ¥è¯¢å
¨é¨ |
| | | logger.info('[mqttService] getConfigæåï¼è¿åå
¨é¨é
ç½®ï¼é
ç½®æ°é:', Object.keys(res).length) |
| | | return reply(event, res) |
| | | } |
| | | // 忡件æ¥è¯¢"data": "mqttInfo.clientId" |
| | | let keys = data.split(".") |
| | | let search = {} |
| | | if (keys.length == 2) { |
| | | if (res[keys[0]]) { |
| | | search[keys[0]] = {} |
| | | search[keys[0]][keys[1]] = res[keys[0]][keys[1]] |
| | | } |
| | | } else { |
| | | search[keys[0]] = res[keys[0]] |
| | | } |
| | | logger.info('[mqttService] getConfigæåï¼è¿åæå®é
ç½®:', JSON.stringify(search)) |
| | | return reply(event, search) |
| | | } catch (error) { |
| | | logger.error('[mqttService] getConfig error:', error) |
| | | return reply(event, { error: error.message }, CODE.E_100) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹é
ç½® |
| | | * @param {object} event - MQTTäºä»¶å¯¹è±¡ |
| | | */ |
| | | mqttService.setConfig = function (event) { |
| | | try { |
| | | logger.info('[mqttService] æ¥æ¶å°setConfigå½ä»¤:', JSON.stringify(event.topic)) |
| | | logger.info('[mqttService] å½ä»¤payload:', event.payload) |
| | | let payload = JSON.parse(event.payload) |
| | | let data = payload.payload && payload.payload.data ? payload.payload.data : {} |
| | | logger.info('[mqttService] è§£æåçåæ°:', JSON.stringify(data)) |
| | | if (!data || typeof data != 'object') { |
| | | logger.error('[mqttService] setConfig失败: data should not be empty') |
| | | return reply(event, "data should not be empty", CODE.E_100) |
| | | } |
| | | let res = configService.configVerifyAndSave(data) |
| | | if (typeof res != 'boolean') { |
| | | // è¿åéè¯¯ä¿¡æ¯ |
| | | logger.error('[mqttService] setConfig失败:', res) |
| | | return reply(event, res, CODE.E_100) |
| | | } |
| | | if (res) { |
| | | logger.info('[mqttService] setConfigæå') |
| | | return reply(event) |
| | | } else { |
| | | logger.error('[mqttService] setConfig失败: unknown failure') |
| | | return reply(event, "unknown failure", CODE.E_100) |
| | | } |
| | | } catch (error) { |
| | | logger.error('[mqttService] setConfig error:', error) |
| | | return reply(event, { error: error.message }, CODE.E_100) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å级åºä»¶ |
| | | * @param {object} event - MQTTäºä»¶å¯¹è±¡ |
| | | */ |
| | | mqttService.upgradeFirmware = function (event) { |
| | | try { |
| | | logger.info('[mqttService] æ¥æ¶å°upgradeFirmwareå½ä»¤:', JSON.stringify(event.topic)) |
| | | logger.info('[mqttService] å½ä»¤payload:', event.payload) |
| | | let payload = JSON.parse(event.payload) |
| | | let data = payload.payload && payload.payload.data ? payload.payload.data : {} |
| | | logger.info('[mqttService] è§£æåçåæ°:', JSON.stringify(data)) |
| | | if (!data || typeof data != 'object' || typeof data.type != 'number' || typeof data.url != 'string' || typeof data.md5 != 'string') { |
| | | logger.error('[mqttService] upgradeFirmware失败: data\'s params error') |
| | | return reply(event, "data's params error", CODE.E_100) |
| | | } |
| | | |
| | | if (data.type == 0) { |
| | | try { |
| | | logger.info('[mqttService] å¼å§åºä»¶å级ï¼url:', data.url, 'md5:', data.md5) |
| | | driver.screen.upgrade({ title: "confirm.upgrade", content: "confirm.upgrading" }) |
| | | ota.updateHttp(data.url, data.md5, 300) |
| | | driver.screen.upgrade({ title: "confirm.upgrade", content: "confirm.upgradeSuccess" }) |
| | | logger.info('[mqttService] åºä»¶å级æå') |
| | | reply(event) |
| | | common.asyncReboot(3) |
| | | return |
| | | } catch (error) { |
| | | logger.error('[mqttService] åºä»¶å级失败:', error) |
| | | driver.screen.upgrade({ title: "confirm.upgrade", content: "confirm.upgradeFail" }) |
| | | return reply(event, "upgrade failure", CODE.E_100) |
| | | } |
| | | } |
| | | |
| | | logger.error('[mqttService] upgradeFirmware失败: 䏿¯æçå级类å') |
| | | return reply(event, "upgrade failure", CODE.E_100) |
| | | } catch (error) { |
| | | logger.error('[mqttService] upgradeFirmware error:', error) |
| | | return reply(event, { error: error.message }, CODE.E_100) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢è¯å«è®°å½ |
| | | * @param {object} event - MQTTäºä»¶å¯¹è±¡ |
| | | */ |
| | | mqttService.getRecords = function (event) { |
| | | try { |
| | | logger.info('[mqttService] æ¥æ¶å°getRecordså½ä»¤:', JSON.stringify(event.topic)) |
| | | logger.info('[mqttService] å½ä»¤payload:', event.payload) |
| | | let payload = JSON.parse(event.payload) |
| | | let data = payload.payload && payload.payload.data ? payload.payload.data : {} |
| | | logger.info('[mqttService] è§£æåçæ¥è¯¢åæ°:', JSON.stringify(data)) |
| | | let res = this.getRecordsAgreement(data) |
| | | logger.info('[mqttService] æ¥è¯¢ç»æ:', JSON.stringify(res)) |
| | | return reply(event, res) |
| | | } catch (error) { |
| | | logger.error('[mqttService] getRecords error:', error) |
| | | return reply(event, { error: error.message }, CODE.E_100) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å°æ¥æå符串转æ¢ä¸ºæ¶é´æ³ï¼ç§ï¼ |
| | | * @param {string} dateString - æ¥æåç¬¦ä¸²ï¼æ ¼å¼ï¼YYYY-MM-DD HH:MM:SS |
| | | * @returns {number} æ¶é´æ³ï¼ç§ï¼ |
| | | */ |
| | | function dateStringToTimestamp(dateString) { |
| | | if (!dateString) return null |
| | | // å°YYYY-MM-DD HH:MM:SSæ ¼å¼è½¬æ¢ä¸ºYYYY-MM-DDTHH:MM:SSæ ¼å¼ï¼ä»¥ä¾¿new Date()æ£ç¡®è§£æ |
| | | const formattedDateString = dateString.replace(' ', 'T') |
| | | const date = new Date(formattedDateString) |
| | | return Math.floor(date.getTime() / 1000) |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢è¯å«è®°å½éç¨åè®®æ ¼å¼ |
| | | * @param {object} data - æ¥è¯¢åæ° |
| | | * @returns {object} æ¥è¯¢ç»æ |
| | | */ |
| | | mqttService.getRecordsAgreement = function (data) { |
| | | data.page = isEmpty(data.page) ? 0 : data.page |
| | | data.size = isEmpty(data.size) ? 10 : data.size |
| | | |
| | | // å¤çæ¶é´åæ°ï¼å°åç¬¦ä¸²æ ¼å¼è½¬æ¢ä¸ºæ¶é´æ³ |
| | | let startTime = null |
| | | let endTime = null |
| | | if (data.startTime) { |
| | | if (typeof data.startTime === 'string') { |
| | | startTime = dateStringToTimestamp(data.startTime) |
| | | } else { |
| | | startTime = Math.floor(data.startTime / 1000) // 转æ¢ä¸ºç§çº§æ¶é´æ³ |
| | | } |
| | | } |
| | | if (data.endTime) { |
| | | if (typeof data.endTime === 'string') { |
| | | endTime = dateStringToTimestamp(data.endTime) |
| | | } else { |
| | | endTime = Math.floor(data.endTime / 1000) // 转æ¢ä¸ºç§çº§æ¶é´æ³ |
| | | } |
| | | } |
| | | |
| | | // æå»ºæ¥è¯¢æ¡ä»¶ |
| | | let queryData = {} |
| | | let nameFilter = null |
| | | // å¤å¶å
¶ä»æ¥è¯¢åæ° |
| | | for (const key in data) { |
| | | if (key !== 'startTime' && key !== 'endTime' && key !== 'name') { |
| | | queryData[key] = data[key] |
| | | } else if (key === 'name') { |
| | | nameFilter = data[key] |
| | | } |
| | | } |
| | | |
| | | // æå»ºSQLæ¡ä»¶ |
| | | let whereClause = '' |
| | | if (startTime) { |
| | | whereClause += `time >= ${startTime} ` |
| | | } |
| | | if (endTime) { |
| | | if (whereClause) { |
| | | whereClause += `AND ` |
| | | } |
| | | whereClause += `time <= ${endTime} ` |
| | | } |
| | | |
| | | // å¤å¶å
¶ä»æ¡ä»¶ |
| | | for (const key in queryData) { |
| | | if (key !== 'page' && key !== 'size') { |
| | | if (whereClause) { |
| | | whereClause += `AND ` |
| | | } |
| | | if (typeof queryData[key] === 'string') { |
| | | whereClause += `${key} = '${queryData[key]}' ` |
| | | } else { |
| | | whereClause += `${key} = ${queryData[key]} ` |
| | | } |
| | | } |
| | | } |
| | | |
| | | // æ§è¡æ¥è¯¢ |
| | | let totalCount = 0 |
| | | let securities = [] |
| | | try { |
| | | // æå»ºcount SQL |
| | | let countSql = `SELECT COUNT(*) FROM d1_pass_record ` |
| | | if (whereClause) { |
| | | countSql += `WHERE ${whereClause} ` |
| | | } |
| | | countSql += `;` |
| | | let countResult = sqlite.select(countSql) |
| | | if (countResult && countResult[0] && countResult[0]['COUNT(*)']) { |
| | | totalCount = countResult[0]['COUNT(*)'] |
| | | } |
| | | |
| | | // æå»ºfindAll SQL |
| | | let findSql = `SELECT * FROM d1_pass_record ` |
| | | if (whereClause) { |
| | | findSql += `WHERE ${whereClause} ` |
| | | } |
| | | findSql += `ORDER BY time DESC ` |
| | | if (queryData.page !== undefined && queryData.size !== undefined) { |
| | | findSql += `LIMIT ${queryData.size} OFFSET ${queryData.page * queryData.size} ` |
| | | } |
| | | findSql += `;` |
| | | securities = sqlite.select(findSql) |
| | | } catch (error) { |
| | | logger.error('[mqttService] æ¥è¯¢è®°å½å¤±è´¥:', error) |
| | | } |
| | | |
| | | // å¤çæ¯æ¡è®°å½ |
| | | let processedSecurities = securities.map(record => { |
| | | // è§£æextraåæ®µ |
| | | let extraData = {} |
| | | try { |
| | | if (record.extra && record.extra !== '') { |
| | | extraData = JSON.parse(record.extra) |
| | | } |
| | | } catch (error) { |
| | | logger.error('[mqttService] è§£æextra失败:', error) |
| | | } |
| | | |
| | | // è§£æextra2åæ®µ |
| | | let extra2Data = {} |
| | | try { |
| | | if (record.extra2 && record.extra2 !== '') { |
| | | extra2Data = JSON.parse(record.extra2) |
| | | } |
| | | } catch (error) { |
| | | logger.error('[mqttService] è§£æextra2失败:', error) |
| | | } |
| | | |
| | | // æå»ºæ°è®°å½ |
| | | return { |
| | | id: record.id, |
| | | keyId: record.keyId, |
| | | permissionId: record.permissionId, |
| | | permissionId2: record.permissionId2, |
| | | userId: record.userId, |
| | | userId2: record.userId2, |
| | | type: record.type, |
| | | code: record.code, |
| | | door: record.door, |
| | | time: timestampToDateString(record.time * 1000), // å°ç§çº§æ¶é´æ³è½¬æ¢ä¸ºæ¯«ç§çº§ï¼å转æ¢ä¸ºæ¥æå符串 |
| | | result: record.result, |
| | | name: extraData.name || '', |
| | | idCard: extraData.idCard || '', |
| | | name2: extra2Data.name || '', |
| | | idCard2: extra2Data.idCard || '', |
| | | message: record.message |
| | | } |
| | | }) |
| | | |
| | | // åºç¨nameè¿æ»¤ |
| | | if (nameFilter) { |
| | | processedSecurities = processedSecurities.filter(record => |
| | | record.name.toLowerCase().includes(nameFilter.toLowerCase()) |
| | | ) |
| | | // æ´æ°æ»æ°åæ»é¡µæ° |
| | | totalCount = processedSecurities.length |
| | | } |
| | | |
| | | return { |
| | | content: processedSecurities, |
| | | page: data.page, |
| | | size: data.size, |
| | | total: totalCount, |
| | | totalPage: Math.ceil(totalCount / data.size), |
| | | count: processedSecurities.length |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å é¤è®°å½ |
| | | * @param {object} event - MQTTäºä»¶å¯¹è±¡ |
| | | */ |
| | | mqttService.delRecords = function (event) { |
| | | try { |
| | | logger.info('[mqttService] æ¥æ¶å°delRecordså½ä»¤:', JSON.stringify(event.topic)) |
| | | logger.info('[mqttService] å½ä»¤payload:', event.payload) |
| | | let payload = JSON.parse(event.payload) |
| | | let data = payload.payload && payload.payload.data ? payload.payload.data : {} |
| | | logger.info('[mqttService] è§£æåçåæ°:', JSON.stringify(data)) |
| | | let res = this.delRecordsAgreement(data) |
| | | if (typeof res == 'string') { |
| | | logger.error('[mqttService] delRecords失败:', res) |
| | | return reply(event, res, CODE.E_100) |
| | | } |
| | | logger.info('[mqttService] delRecordsæå') |
| | | return reply(event) |
| | | } catch (error) { |
| | | logger.error('[mqttService] delRecords error:', error) |
| | | return reply(event, { error: error.message }, CODE.E_100) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å é¤è®°å½éç¨åè®®æ ¼å¼ |
| | | * @param {object} data - å é¤åæ° |
| | | * @returns {boolean|string} true表示æåï¼string表示éè¯¯ä¿¡æ¯ |
| | | */ |
| | | mqttService.delRecordsAgreement = function (data) { |
| | | |
| | | // æ ¹æ®æ¶é´èå´å é¤è®°å½ |
| | | if (data.startTime || data.endTime) { |
| | | logger.info('[mqttService] æ¶é´èå´: startTime=' + data.startTime + ', endTime=' + data.endTime) |
| | | |
| | | try { |
| | | // æå»ºæ¥è¯¢æ¡ä»¶ |
| | | let query = {}; |
| | | if (data.startTime) { |
| | | query.startTime = data.startTime; |
| | | } |
| | | if (data.endTime) { |
| | | query.endTime = data.endTime; |
| | | } |
| | | |
| | | // 使ç¨getRecordsAgreement彿°çæ¥è¯¢é»è¾æ¥è·åç¬¦åæ¡ä»¶çè®°å½ |
| | | let result = mqttService.getRecordsAgreement(query); |
| | | let records = result.content || []; |
| | | |
| | | // é个å é¤è®°å½ |
| | | let deletedCount = 0; |
| | | for (let record of records) { |
| | | // 妿æ¯äººè¸è®°å½ï¼å é¤å¯¹åºçå¾çæä»¶ |
| | | if (record.type == 300 && record.code) { |
| | | try { |
| | | common.systemBrief(`rm -rf ${record.code}`); |
| | | } catch (error) { |
| | | logger.error('[mqttService] å é¤å¾çæä»¶åºé: ' + error.message); |
| | | } |
| | | } |
| | | // å é¤è®°å½ |
| | | sqliteService.d1_pass_record.delete({ id: record.id }); |
| | | deletedCount++; |
| | | } |
| | | |
| | | logger.info('[mqttService] æåå é¤ ' + deletedCount + ' æ¡è®°å½'); |
| | | } catch (error) { |
| | | logger.error('[mqttService] å é¤è®°å½åºé: ' + error.message); |
| | | // 忽ç¥é误ï¼è¿åæå |
| | | } |
| | | } |
| | | |
| | | return true |
| | | } |
| | | /** |
| | | * éè¡ä¸æ¥åå¤ |
| | | * @param {object} event - MQTTäºä»¶å¯¹è±¡ |
| | | */ |
| | | mqttService.access_reply = function (event) { |
| | | try { |
| | | logger.info('[mqttService] æ¥æ¶å°access_replyå½ä»¤:', JSON.stringify(event.topic)) |
| | | logger.info('[mqttService] å½ä»¤payload:', event.payload) |
| | | let payload = JSON.parse(event.payload) |
| | | logger.info('[mqttService] è§£æåçåæ°:', JSON.stringify(payload)) |
| | | let serialNo = map.get(payload.serialNo) |
| | | if (serialNo) { |
| | | logger.info('[mqttService] æ¸
çä¸´æ¶æä»¶:', serialNo) |
| | | common.systemBrief(`rm -rf ${serialNo}`) |
| | | map.del(payload.serialNo) |
| | | } |
| | | logger.info('[mqttService] æ¸
空éè¡è®°å½') |
| | | sqliteService.d1_pass_record.deleteAll() |
| | | logger.info('[mqttService] access_replyå¤ç宿') |
| | | } catch (error) { |
| | | logger.error('[mqttService] access_reply error:', error) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å¨çº¿éªè¯åå¤ |
| | | * @param {object} raw - MQTTäºä»¶å¯¹è±¡ |
| | | */ |
| | | mqttService.access_online_reply = function (raw) { |
| | | try { |
| | | logger.info('[mqttService] æ¥æ¶å°access_online_replyå½ä»¤:', JSON.stringify(raw.topic)) |
| | | logger.info('[mqttService] å½ä»¤payload:', raw.payload) |
| | | let payload = JSON.parse(raw.payload) |
| | | logger.info('[mqttService] è§£æåçåæ°:', JSON.stringify(payload)) |
| | | let map = dxMap.get("VERIFY") |
| | | let data = map.get(payload.serialNo) |
| | | if (data) { |
| | | logger.info('[mqttService] å¤çå¨çº¿éªè¯åå¤ï¼serialNo:', payload.serialNo) |
| | | map.del(payload.serialNo) |
| | | driver.mqtt.getOnlinecheckReply(payload) |
| | | } |
| | | logger.info('[mqttService] access_online_replyå¤ç宿') |
| | | } catch (error) { |
| | | logger.error('[mqttService] access_online_reply error:', error) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * é误代ç å®ä¹ |
| | | */ |
| | | const CODE = { |
| | | // æå |
| | | S_000: "000000", |
| | | // æªç¥é误 |
| | | E_100: "100000", |
| | | // 设å¤å·²è¢«ç¦ç¨ |
| | | E_101: "100001", |
| | | // è®¾å¤æ£å¿ï¼è¯·ç¨ååè¯ |
| | | E_102: "100002", |
| | | // ç¾åæ£éªå¤±è´¥ |
| | | E_103: "100003", |
| | | // è¶
æ¶é误 |
| | | E_104: "100004", |
| | | // 设å¤ç¦»çº¿ |
| | | E_105: "100005", |
| | | } |
| | | mqttService.CODE = CODE |
| | | |
| | | /** |
| | | * 䏿¥è®¾å¤ä¿¡æ¯åéè¡è®°å½ |
| | | */ |
| | | mqttService.report = function () { |
| | | // å¨çº¿ä¸æ¥ |
| | | let payloadReply = mqttReply(std.genRandomStr(10), { |
| | | mac: config.get("sys.mac") || '', |
| | | version: config.get("sys.version"), |
| | | appVersion: config.get("sys.version"), |
| | | releaseTime: config.get("sys.createTime"), |
| | | type: config.get("net.type"), |
| | | }, CODE.S_000) |
| | | driver.mqtt.send("access_device/v2/event/connect", JSON.stringify(payloadReply)) |
| | | |
| | | //éè¡è®°å½ä¸æ¥ - å·²å
³é |
| | | // let res = sqliteService.d1_pass_record.findAll() |
| | | // if (res.length <= 0) { |
| | | // return |
| | | // } |
| | | // // çéåº type === 300 ç对象ï¼äººè¸è®°å½ï¼ |
| | | // let faceArray = res.filter(item => item.type == 300); |
| | | // // çéåº type !== 300 ç对象ï¼å
¶ä»è®°å½ï¼ |
| | | // let recordArray = res.filter(item => item.type != 300); |
| | | // if (recordArray.length > 0) { |
| | | // driver.mqtt.send("access_device/v2/event/access", JSON.stringify(mqttReply(std.genRandomStr(10), recordArray, CODE.S_000))) |
| | | // } |
| | | // if (faceArray.length > 0) { |
| | | // let index = 0 |
| | | // let timer = std.setInterval(() => { |
| | | // let serialNo = std.genRandomStr(10) |
| | | // //ç¼åæ¾å
¥è¦å é¤ç人è¸ç
§ç src |
| | | // map.del(serialNo) |
| | | // map.put(serialNo, faceArray[index].code) |
| | | // |
| | | // // æ£æ¥faceArray[index].codeæ¯å¦ææ |
| | | // if (faceArray[index].code) { |
| | | // faceArray[index].code = driver.face.fileToBase64(faceArray[index].code) |
| | | // } else { |
| | | // faceArray[index].code = "" |
| | | // logger.info("人è¸è®°å½ä¸codeåæ®µä¸ºç©ºï¼è·³è¿Base64转æ¢") |
| | | // } |
| | | // |
| | | // driver.mqtt.send("access_device/v2/event/access", JSON.stringify(mqttReply(serialNo, [faceArray[index]], CODE.S_000))) |
| | | // index++ |
| | | // if (!faceArray[index]) { |
| | | // std.clearInterval(saveTimer) |
| | | // std.clearInterval(timer) |
| | | // } |
| | | // }, 1000) |
| | | // // æ¯é500msæ£æ¥ä¸æ¬¡mqttè¿æ¥ç¶æï¼å¦ææå¼ï¼å忢䏿¥ |
| | | // let saveTimer = std.setInterval(() => { |
| | | // if (!driver.mqtt.getStatus()) { |
| | | // std.clearInterval(saveTimer) |
| | | // std.clearInterval(timer) |
| | | // } |
| | | // }, 500) |
| | | // } |
| | | } |
| | | |
| | | /** |
| | | * mqtt请æ±ç»ä¸åå¤ |
| | | * @param {object} event - MQTTäºä»¶å¯¹è±¡ |
| | | * @param {any} data - å夿°æ® |
| | | * @param {string} code - é误代ç |
| | | */ |
| | | function reply(event, data, code) { |
| | | try { |
| | | let topic = getReplyTopic(event) |
| | | let payload = JSON.parse(event.payload) |
| | | let serialNo = payload.serialNo || std.genRandomStr(10) |
| | | let reply = JSON.stringify(mqttReply(serialNo, data, isEmpty(code) ? CODE.S_000 : code)) |
| | | driver.mqtt.send(topic, reply) |
| | | } catch (error) { |
| | | logger.error('[mqttService] reply error:', error) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è·ååå¤ä¸»é¢ |
| | | * @param {object} data - MQTTäºä»¶å¯¹è±¡ |
| | | * @returns {string} åå¤ä¸»é¢ |
| | | */ |
| | | function getReplyTopic(data) { |
| | | // return data.topic.replace("/" + config.get("sys.sn"), '') + "_reply"; |
| | | try { |
| | | let sn = config.get("mqtt.clientId") |
| | | return data.topic.replace("/" + sn, '') + "_reply"; |
| | | } catch (error) { |
| | | logger.error('[mqttService] getReplyTopic error:', error) |
| | | // åéå°ä½¿ç¨åºå®æ ¼å¼ |
| | | return data.topic + "_reply" |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * mqttå夿 ¼å¼æå»º |
| | | * @param {string} serialNo - åºåå· |
| | | * @param {any} data - å夿°æ® |
| | | * @param {string} code - é误代ç |
| | | * @returns {object} å夿 ¼å¼å¯¹è±¡ |
| | | */ |
| | | function mqttReply(serialNo, data, code) { |
| | | // çæå½åæ¶é´çåç¬¦ä¸²æ ¼å¼ |
| | | const now = new Date(); |
| | | const year = now.getFullYear(); |
| | | const month = String(now.getMonth() + 1).padStart(2, '0'); |
| | | const day = String(now.getDate()).padStart(2, '0'); |
| | | const hours = String(now.getHours()).padStart(2, '0'); |
| | | const minutes = String(now.getMinutes()).padStart(2, '0'); |
| | | const seconds = String(now.getSeconds()).padStart(2, '0'); |
| | | const timeString = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; |
| | | |
| | | return { |
| | | serialNo: serialNo, |
| | | uuid: config.get("sys.uuid"), |
| | | sign: '', |
| | | code: code, |
| | | data: data, |
| | | time: timeString |
| | | } |
| | | } |
| | | mqttService.mqttReply = mqttReply |
| | | |
| | | /** |
| | | * è·åææè®¢é
çtopic |
| | | * @returns {array} 订é
çtopicå表 |
| | | */ |
| | | mqttService.getTopics = function () { |
| | | // è·åææè®¢é
çtopic |
| | | let sn = config.get("mqtt.clientId") |
| | | const topics = [ |
| | | "control", "getConfig", "setConfig", "upgradeFirmware", "test", |
| | | "getPermission", "insertPermission", "delPermission", "clearPermission", |
| | | "getKey", "insertKey", "delKey", "clearKey", |
| | | "getUser", "insertUser", "delUser", "clearUser", |
| | | "getSecurity", "insertSecurity", "delSecurity", "clearSecurity", "getRecords", "delRecords", |
| | | "insertEmergencyPassword", "delEmergencyPassword", "clearEmergencyPassword", "getEmergencyPassword" |
| | | ] |
| | | const eventReplies = ["connect_reply", "alarm_reply", "access_reply", "access_online_reply"] |
| | | |
| | | let flag = 'access_device/v2/cmd/' + sn + "/" |
| | | let eventFlag = 'access_device/v2/event/' + sn + "/" |
| | | return topics.map(item => flag + item).concat(eventReplies.map(item => eventFlag + item)); |
| | | } |
| | | |
| | | /** |
| | | * å¤ç©ºå½æ° |
| | | * @param {any} value - è¦å¤æçå¼ |
| | | * @returns {boolean} æ¯å¦ä¸ºç©º |
| | | */ |
| | | function isEmpty(value) { |
| | | return value === undefined || value === null || value === "" |
| | | } |
| | | |
| | | export default mqttService |
| | | |
| | | /* |
| | | `mqttService.getTopics()` 彿°è¿åçææ topic å¦ä¸ï¼ |
| | | |
| | | ### å½ä»¤ topicï¼ç¨äºæ¥æ¶æå¡å¨ä¸åçå½ä»¤ï¼ï¼ |
| | | - `access_device/v2/cmd/{sn}/control` - æ§å¶å½ä»¤ |
| | | - `access_device/v2/cmd/{sn}/getConfig` - è·åé
ç½® |
| | | - `access_device/v2/cmd/{sn}/setConfig` - 设置é
ç½® |
| | | - `access_device/v2/cmd/{sn}/upgradeFirmware` - åºä»¶å级 |
| | | - `access_device/v2/cmd/{sn}/test` - æµè¯å½ä»¤ |
| | | - `access_device/v2/cmd/{sn}/getPermission` - è·åæé |
| | | - `access_device/v2/cmd/{sn}/insertPermission` - æå
¥æé |
| | | - `access_device/v2/cmd/{sn}/delPermission` - å 餿é |
| | | - `access_device/v2/cmd/{sn}/clearPermission` - æ¸
餿é |
| | | - `access_device/v2/cmd/{sn}/getKey` - è·åå¯é¥ |
| | | - `access_device/v2/cmd/{sn}/insertKey` - æå
¥å¯é¥ |
| | | - `access_device/v2/cmd/{sn}/delKey` - å é¤å¯é¥ |
| | | - `access_device/v2/cmd/{sn}/clearKey` - æ¸
é¤å¯é¥ |
| | | - `access_device/v2/cmd/{sn}/getUser` - è·åç¨æ· |
| | | - `access_device/v2/cmd/{sn}/insertUser` - æå
¥ç¨æ· |
| | | - `access_device/v2/cmd/{sn}/delUser` - å é¤ç¨æ· |
| | | - `access_device/v2/cmd/{sn}/clearUser` - æ¸
é¤ç¨æ· |
| | | - `access_device/v2/cmd/{sn}/getSecurity` - è·åå®å
¨ä¿¡æ¯ |
| | | - `access_device/v2/cmd/{sn}/insertSecurity` - æå
¥å®å
¨ä¿¡æ¯ |
| | | - `access_device/v2/cmd/{sn}/delSecurity` - å é¤å®å
¨ä¿¡æ¯ |
| | | - `access_device/v2/cmd/{sn}/clearSecurity` - æ¸
é¤å®å
¨ä¿¡æ¯ |
| | | - `access_device/v2/cmd/{sn}/getRecords` - è·åè®°å½ |
| | | - `access_device/v2/cmd/{sn}/delRecords` - å é¤è®°å½ |
| | | |
| | | ### äºä»¶åå¤ topicï¼ç¨äºæ¥æ¶æå¡å¨å¯¹äºä»¶çåå¤ï¼ï¼ |
| | | - `access_device/v2/event/{sn}/connect_reply` - è¿æ¥åå¤ |
| | | - `access_device/v2/event/{sn}/alarm_reply` - åè¦åå¤ |
| | | - `access_device/v2/event/{sn}/access_reply` - éè¡åå¤ |
| | | - `access_device/v2/event/{sn}/access_online_reply` - å¨çº¿éªè¯åå¤ |
| | | |
| | | å
¶ä¸ `{sn}` æ¯è®¾å¤çåºåå·ï¼ä¼è¢«æ¿æ¢ä¸ºå®é
ç设å¤åºåå·ã |
| | | */ |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | /** |
| | | * NFCæå¡æ¨¡å |
| | | * å¤çNFCå¡çç¸å
³çä¸å¡é»è¾ï¼å
æ¬èº«ä»½è¯å¡åäºè¯çå¤ç |
| | | */ |
| | | import log from '../../dxmodules/dxLogger.js' |
| | | import dxMap from '../../dxmodules/dxMap.js' |
| | | import accessService from '../service/accessService.js' |
| | | import config from '../../dxmodules/dxConfig.js' |
| | | import driver from '../driver.js'; |
| | | |
| | | const nfcService = {} |
| | | |
| | | /** |
| | | * æ¥æ¶NFCå¡çæ¶æ¯å¹¶å¤ç |
| | | * @param {object} data - NFCå¡çæ°æ® |
| | | * @param {string} [data.card_type] - å¡çç±»å |
| | | * @param {string} [data.id] - 身份è¯ç©çå¡å· |
| | | * @param {string} [data.name] - å§åï¼äºè¯ï¼ |
| | | * @param {string} [data.sex] - æ§å«ï¼äºè¯ï¼ |
| | | * @param {string} [data.idCardNo] - 身份è¯å·ç ï¼äºè¯ï¼ |
| | | */ |
| | | nfcService.receiveMsg = function (data) { |
| | | // log.info('[nfcService] receiveMsg :' + JSON.stringify(data)) |
| | | |
| | | // é¦å
夿æ¯å¦æ¯èº«ä»½è¯å¡ |
| | | if (data.card_type && data.id) { |
| | | if (dxMap.get("UI").get("getCardStart")) { |
| | | driver.screen.getCard(data.id) |
| | | return |
| | | } |
| | | // 身份è¯ç©çå¡å·/æ®éå¡ |
| | | accessService.access({ type: "200", code: data.id }) |
| | | } else if (data.name && data.sex && data.idCardNo) { |
| | | if (dxMap.get("UI").get("getCardStart")) { |
| | | driver.screen.getCard(data.idCardNo) |
| | | return |
| | | } |
| | | // äºè¯ |
| | | accessService.access({ type: "200", code: data.idCardNo }); |
| | | } |
| | | |
| | | } |
| | | |
| | | export default nfcService |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | /**
|
| | | * 平尿å¡é信模å
|
| | | * å¤ç平尿å¡ç¸å
³çä¸å¡é»è¾ï¼å
æ¬åè¯ä¸ååäºè¯çå¤ç
|
| | | */ |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | /** |
| | | * SQLiteæå¡æ¨¡å |
| | | * æä¾æ°æ®åºåå§åãè¡¨ç»æç®¡çãJPA飿 ¼çå¢å æ¹æ¥æ¹æ³åäºå¡ç®¡ç |
| | | */ |
| | | import log from '../../dxmodules/dxLogger.js' |
| | | import sqlite from '../../dxmodules/dxSqlite.js' |
| | | |
| | | //-------------------------variable------------------------- |
| | | const sqliteService = {} |
| | | //-------------------------public------------------------- |
| | | |
| | | /** |
| | | * åå§åæ°æ®åº |
| | | * @param {string} path - æ°æ®åºæä»¶è·¯å¾ |
| | | * @throws {Error} å¦æè·¯å¾ä¸ºç©ºåæåºé误 |
| | | */ |
| | | sqliteService.init = function (path) { |
| | | if (!path) { |
| | | throw new Error("path should not be null or empty") |
| | | } |
| | | // åå»ºæ°æ®åº |
| | | sqlite.init(path) |
| | | // å建表 |
| | | createTables() |
| | | } |
| | | |
| | | /** |
| | | * æ°æ®åºè¡¨ç»æå®ä¹ |
| | | */ |
| | | let entities = { |
| | | d1_pass_record: { |
| | | id: "VARCHAR(128) PRIMARY KEY", |
| | | keyId: "VARCHAR(128)", |
| | | permissionId: "VARCHAR(128)", |
| | | permissionId2: "VARCHAR(128)", |
| | | userId: "VARCHAR(128)", |
| | | userId2: "VARCHAR(128)", |
| | | type: "VARCHAR(128)", |
| | | code: "VARCHAR(128)", |
| | | door: "VARCHAR(128)", |
| | | time: "INTEGER", |
| | | result: "INTEGER", |
| | | extra: "TEXT", |
| | | extra2: "TEXT", |
| | | message: "TEXT", |
| | | }, |
| | | d1_permission: { |
| | | permissionId: "VARCHAR(128) PRIMARY KEY", |
| | | userId: "VARCHAR(128)", |
| | | door: "VARCHAR(128)", |
| | | extra: "TEXT", |
| | | timeType: "INTEGER", |
| | | beginTime: "INTEGER", |
| | | endTime: "INTEGER", |
| | | repeatBeginTime: "INTEGER", |
| | | repeatEndTime: "INTEGER", |
| | | period: "TEXT", |
| | | }, |
| | | d1_security: { |
| | | securityId: "VARCHAR(128) PRIMARY KEY", |
| | | type: "VARCHAR(128)", |
| | | key: "VARCHAR(128)", |
| | | value: "TEXT", |
| | | startTime: "INTEGER", |
| | | endTime: "INTEGER", |
| | | }, |
| | | d1_voucher: { |
| | | keyId: "VARCHAR(128) PRIMARY KEY", |
| | | type: "VARCHAR(128)", |
| | | code: "TEXT", |
| | | userId: "VARCHAR(128)", |
| | | extra: "TEXT", |
| | | }, |
| | | d1_person: { |
| | | userId: "VARCHAR(128) PRIMARY KEY", |
| | | name: "VARCHAR(128)", |
| | | extra: "TEXT", |
| | | }, |
| | | d1_emergency_password: { |
| | | id: "VARCHAR(128) PRIMARY KEY", |
| | | password: "VARCHAR(128)", |
| | | description: "VARCHAR(256)", |
| | | createTime: "INTEGER", |
| | | updateTime: "INTEGER", |
| | | status: "INTEGER" |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * SQLç±»å转JSç±»å |
| | | * @param {string} sqlType - SQLæ°æ®ç±»å |
| | | * @returns {string} JavaScriptæ°æ®ç±»å |
| | | */ |
| | | let sqlType2jsType = (sqlType) => { |
| | | if (sqlType.indexOf("INTEGER") > -1) { |
| | | return 'number' |
| | | } else { |
| | | return 'string' |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * åå»ºè¡¨ç»æ |
| | | * @throws {Error} å¦æè¡¨å建失败åæåºé误 |
| | | */ |
| | | function createTables() { |
| | | for (const tableName in entities) { |
| | | const table = entities[tableName]; |
| | | let sql = `CREATE TABLE IF NOT EXISTS ${tableName} (` |
| | | for (const column in table) { |
| | | const type = table[column]; |
| | | sql += ` ${column} ${type},` |
| | | } |
| | | sql = sql.slice(0, -1); |
| | | sql += ")" |
| | | let ret = sqlite.exec(sql) |
| | | if (ret != 0) { |
| | | throw new Error(`table ${tableName} create exception: ${ret}`) |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å建JPA飿 ¼ç代çå¤çå¨ |
| | | */ |
| | | let handler = { |
| | | get: function (target, prop, receiver) { |
| | | return (...args) => { |
| | | return createJPA(prop, target.tableName, ...args) |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 为æ¯ä¸ªè¡¨å建JPA飿 ¼çå¢å æ¹æ¥æ¹æ³ |
| | | sqliteService.d1_pass_record = new Proxy({ tableName: "d1_pass_record" }, handler); |
| | | |
| | | // æ·»å æ ¹æ®æ¶é´èå´å é¤è®°å½çæ¹æ³ |
| | | sqliteService.d1_pass_record.deleteByTimeRange = function (startTime, endTime) { |
| | | try { |
| | | // æå»ºæ¥è¯¢æ¡ä»¶ |
| | | let conditions = {}; |
| | | if (startTime) { |
| | | conditions.time = { |
| | | $gte: startTime |
| | | }; |
| | | } |
| | | if (endTime) { |
| | | if (!conditions.time) { |
| | | conditions.time = {}; |
| | | } |
| | | conditions.time.$lte = endTime; |
| | | } |
| | | |
| | | // 使ç¨JPA飿 ¼çdeleteæ¹æ³ |
| | | let ret = sqliteService.d1_pass_record.delete(conditions); |
| | | log.info('[sqliteService] deleteByTimeRangeè¿åå¼: ' + ret); |
| | | return ret; |
| | | } catch (error) { |
| | | log.error('deleteByTimeRange error:', error); |
| | | return -1; |
| | | } |
| | | }; |
| | | sqliteService.d1_permission = new Proxy({ tableName: "d1_permission" }, handler); |
| | | sqliteService.d1_security = new Proxy({ tableName: "d1_security" }, handler); |
| | | sqliteService.d1_voucher = new Proxy({ tableName: "d1_voucher" }, handler); |
| | | sqliteService.d1_person = new Proxy({ tableName: "d1_person" }, handler); |
| | | sqliteService.d1_emergency_password = new Proxy({ tableName: "d1_emergency_password" }, handler); |
| | | |
| | | /** |
| | | * å¼å§äºå¡ |
| | | * äºå¡ä¸æäº¤æ°æ®åºéå¯åï¼æ°æ®ä¼è¿åï¼æä»¥transactionåä¸å®è¦commit |
| | | * 妿å¨ä¸ä¸ªäºå¡å°æªæäº¤æåæ»çæ
åµä¸æ§è¡å¦ä¸ä¸ª BEGIN TRANSACTIONï¼SQLite ä¼èªå¨å°æ°çäºå¡åµå¥å¨ä¹åçäºå¡å
é¨ï¼è䏿¯è¦çä¹åçäºå¡ã |
| | | */ |
| | | sqliteService.transaction = function () { |
| | | sqlite.exec("BEGIN TRANSACTION;") |
| | | } |
| | | |
| | | /** |
| | | * åæ»äºå¡ |
| | | */ |
| | | sqliteService.rollback = function () { |
| | | sqlite.exec("ROLLBACK;") |
| | | } |
| | | |
| | | /** |
| | | * æäº¤äºå¡ |
| | | * æäº¤åæ æ³åæ»ï¼æ°æ®æ æ³è¿å |
| | | */ |
| | | sqliteService.commit = function () { |
| | | sqlite.exec("COMMIT;") |
| | | } |
| | | |
| | | /** |
| | | * èªå¨å建jpa常ç¨å¢å æ¹æ¥sqlæ¹æ³ï¼ |
| | | * æ¯æçè§åï¼findByAAndBAndC,findAll,findAllOrderByADescBAsc,deleteByAAndBAndC,deleteAll,deleteInBatch,deleteByIdInBatch,updateAByBAndCAndD,save,saveAll,count,countBy |
| | | * æ¡ä»¶å页æ¥è¯¢ï¼egï¼findByAAndBAndC(x,x,x,{ page: 0, size: 200, å
¶ä»æ¡ä»¶, id:"123456" }) |
| | | * æ¹éå é¤ï¼egï¼deleteInBatch([{ a: 1, b: 2, c: "3" }, { a: 2 }]) |
| | | * æ¡ä»¶å é¤ï¼egï¼deleteAll({ a: 1, b: 2, c: "3" }) |
| | | * 忡件æ¹éå é¤ï¼egï¼deleteByIdInBatch([1,2,3,4,5,6]) |
| | | * æ´å¤ç¤ºä¾å¯åèä¸é¢æµè¯æ¹æ³ |
| | | * @param {string} methodName æ¹æ³å |
| | | * @param {string} tableName 表å |
| | | * @param {...any} nums æ¹æ³åæ° |
| | | * @returns {any} sqliteæ§è¡ç»æ |
| | | */ |
| | | function createJPA(methodName, tableName, ...nums) { |
| | | let sql |
| | | let isFind = false |
| | | let isCount = false |
| | | let noPageable = false |
| | | let hasOrderBy = false |
| | | if (methodName.startsWith("save")) { |
| | | // å¢ |
| | | if (methodName.startsWith("saveAll")) { |
| | | // æ¹é |
| | | nums = nums[0] |
| | | sql = `INSERT INTO ${tableName} VALUES ` |
| | | for (let i = 0; i < nums.length; i++) { |
| | | const record = nums[i]; |
| | | sql += `(` |
| | | for (const column in entities[tableName]) { |
| | | const item = record[column]; |
| | | if (sqlType2jsType(entities[tableName][column]) == 'string') { |
| | | sql += `'${isEmpty(item) ? "" : item}',` |
| | | } else { |
| | | sql += `${isEmpty(item) ? 0 : item},` |
| | | } |
| | | } |
| | | sql = sql.slice(0, -1); |
| | | sql += `)` |
| | | if (i != nums.length - 1) { |
| | | sql += `, ` |
| | | } |
| | | } |
| | | } else { |
| | | // åæ¡ |
| | | let record = nums[0] |
| | | sql = `INSERT INTO ${tableName} VALUES (` |
| | | for (const column in entities[tableName]) { |
| | | const item = record[column]; |
| | | if (sqlType2jsType(entities[tableName][column]) == 'string') { |
| | | sql += `'${isEmpty(item) ? "" : item}',` |
| | | } else { |
| | | sql += `${isEmpty(item) ? 0 : item},` |
| | | } |
| | | } |
| | | sql = sql.slice(0, -1); |
| | | sql += `)` |
| | | } |
| | | methodName = "" |
| | | noPageable = true |
| | | } else if (methodName.startsWith("delete")) { |
| | | // å |
| | | if (methodName.startsWith("deleteAll")) { |
| | | // æ¸
空表 |
| | | sql = `DELETE FROM ${tableName} ` |
| | | methodName = "" |
| | | } else if (methodName.endsWith("InBatch")) { |
| | | if (nums.length != 1) { |
| | | log.error("[JPA]:", "缺å°åæ°") |
| | | return |
| | | } |
| | | sql = `DELETE FROM ${tableName} WHERE ` |
| | | if (methodName.indexOf("By") > -1) { |
| | | methodName = methodName.split("By")[1].split("InBatch")[0] |
| | | sql += `${firstLower(methodName)} IN ` |
| | | let whereClauses = "" |
| | | for (let i = 0; i < nums[0].length; i++) { |
| | | const value = nums[0][i]; |
| | | if (typeof value == 'string') { |
| | | whereClauses += `'${value}'` |
| | | } else { |
| | | whereClauses += `${value} ` |
| | | } |
| | | if (i != nums[0].length - 1) { |
| | | whereClauses += "," |
| | | } |
| | | } |
| | | sql += `(${whereClauses})` |
| | | } else { |
| | | for (let i = 0; i < nums[0].length; i++) { |
| | | let whereClauses = "" |
| | | const record = nums[0][i]; |
| | | for (const column in record) { |
| | | const value = record[column]; |
| | | if (typeof value == 'string') { |
| | | whereClauses += `${column} = '${value}'` |
| | | } else { |
| | | whereClauses += `${column} = ${value}` |
| | | } |
| | | whereClauses += ` AND ` |
| | | } |
| | | whereClauses = whereClauses.slice(0, " AND ".length * (-1)) |
| | | sql += `(${whereClauses})` |
| | | if (i != nums[0].length - 1) { |
| | | sql += ` OR ` |
| | | } |
| | | } |
| | | } |
| | | methodName = "" |
| | | noPageable = true |
| | | } else { |
| | | sql = `DELETE FROM ${tableName} ` |
| | | methodName = methodName.substring("delete".length) |
| | | } |
| | | } else if (methodName.startsWith("update")) { |
| | | // æ¹ |
| | | sql = `UPDATE ${tableName} SET` |
| | | methodName = methodName.substring("update".length) |
| | | } else if (methodName.startsWith("find")) { |
| | | // æ¥ |
| | | isFind = true |
| | | sql = `SELECT * FROM ${tableName} ` |
| | | if (methodName.startsWith("findAll")) { |
| | | methodName = methodName.substring("findAll".length) |
| | | } else { |
| | | methodName = methodName.substring("find".length) |
| | | } |
| | | let index = methodName.indexOf("OrderBy") |
| | | if (index > -1) { |
| | | hasOrderBy = methodName.substring(index + "OrderBy".length).match(/\w+?(Desc|Asc)/g) |
| | | methodName = methodName.substring(0, index) |
| | | } |
| | | } else if (methodName.startsWith("count")) { |
| | | // ç»è®¡ |
| | | isFind = true |
| | | isCount = true |
| | | sql = `SELECT COUNT(*) FROM ${tableName} ` |
| | | methodName = methodName.substring("count".length) |
| | | } else { |
| | | log.error("[JPA]:", "䏿¯æçæ¹æ³") |
| | | return |
| | | } |
| | | // whereæ¡ä»¶æå»º |
| | | let index = methodName.indexOf("By") |
| | | let whereClauses = "" |
| | | if (index > -1) { |
| | | let count = 0 |
| | | let conditionsPart = methodName.substring(index + 2) |
| | | if (conditionsPart.indexOf("And") > -1) { |
| | | conditionsPart = conditionsPart.split("And") |
| | | if (nums.length < conditionsPart.length) { |
| | | log.error("[JPA]:", "缺å°åæ°") |
| | | return |
| | | } |
| | | for (let i = 0; i < conditionsPart.length; i++) { |
| | | const field = conditionsPart[i]; |
| | | if (typeof nums[i] == 'string') { |
| | | whereClauses += `${firstLower(field)} = '${nums[i]}'` |
| | | } else { |
| | | whereClauses += `${firstLower(field)} = ${nums[i]}` |
| | | } |
| | | if (i != conditionsPart.length - 1) { |
| | | whereClauses += ` AND ` |
| | | } |
| | | count = i |
| | | } |
| | | } else if (conditionsPart.indexOf("Or") > -1) { |
| | | conditionsPart = conditionsPart.split("Or") |
| | | if (nums.length < conditionsPart.length) { |
| | | log.error("[JPA]:", "缺å°åæ°") |
| | | return |
| | | } |
| | | for (let i = 0; i < conditionsPart.length; i++) { |
| | | const field = conditionsPart[i]; |
| | | if (typeof nums[i] == 'string') { |
| | | whereClauses += `${firstLower(field)} = '${nums[i]}'` |
| | | } else { |
| | | whereClauses += `${firstLower(field)} = ${nums[i]}` |
| | | } |
| | | if (i != conditionsPart.length - 1) { |
| | | whereClauses += ` OR ` |
| | | } |
| | | count = i |
| | | } |
| | | } else { |
| | | if (nums.length < 1) { |
| | | log.error("[JPA]:", "缺å°åæ°") |
| | | return |
| | | } |
| | | if (typeof nums[0] == 'string') { |
| | | whereClauses = `${firstLower(conditionsPart)} = '${nums[0]}' ` |
| | | } else { |
| | | whereClauses = `${firstLower(conditionsPart)} = ${nums[0]} ` |
| | | } |
| | | } |
| | | count++ |
| | | // updateçset项æå»º |
| | | let setClauses = "" |
| | | let prefix = methodName.substring(0, index); |
| | | if (prefix.length > 0) { |
| | | prefix = prefix.split("And") |
| | | if ((nums.length - count) < prefix.length) { |
| | | log.error("[JPA]:", "缺å°åæ°") |
| | | return |
| | | } |
| | | for (let i = 0; i < prefix.length; i++) { |
| | | const field = prefix[i]; |
| | | if (typeof nums[i + count] == 'string') { |
| | | setClauses += `${firstLower(field)} = '${nums[i + count]}',` |
| | | } else { |
| | | setClauses += `${firstLower(field)} = ${nums[i + count]},` |
| | | } |
| | | } |
| | | setClauses = setClauses.slice(0, -1) |
| | | sql += ` ${setClauses} ` |
| | | } |
| | | sql += `WHERE ${whereClauses} ` |
| | | } |
| | | // orderæåº |
| | | let orderByClauses = "" |
| | | if (hasOrderBy) { |
| | | orderByClauses = "ORDER BY " |
| | | let conditionsPart = hasOrderBy |
| | | for (let i = 0; i < conditionsPart.length; i++) { |
| | | const orderItem = conditionsPart[i]; |
| | | let isDesc = orderItem.indexOf("Desc") |
| | | let isAsc = orderItem.indexOf("Asc") |
| | | if (isDesc > -1) { |
| | | orderByClauses += `${firstLower(orderItem.substring(0, isDesc))} DESC,` |
| | | } |
| | | if (isAsc > -1) { |
| | | orderByClauses += `${firstLower(orderItem.substring(0, isAsc))} ASC,` |
| | | } |
| | | } |
| | | orderByClauses = orderByClauses.slice(0, -1) |
| | | } |
| | | // 夿å页æ¡ä»¶æ¥è¯¢ |
| | | let pageable = nums[nums.length - 1] |
| | | if (typeof pageable == 'object' && !noPageable) { |
| | | let clauses = "" |
| | | for (const key in pageable) { |
| | | const condition = pageable[key]; |
| | | if (key == "page" || key == "size") { |
| | | continue |
| | | } |
| | | if (typeof condition == 'string') { |
| | | clauses += `${firstLower(key)} = '${condition}'` |
| | | } else { |
| | | clauses += `${firstLower(key)} = ${condition}` |
| | | } |
| | | clauses += ` AND ` |
| | | } |
| | | if (clauses.length > 0) { |
| | | clauses = clauses.slice(0, " AND ".length * (-1)) |
| | | if (sql.indexOf("WHERE") > -1) { |
| | | sql += `AND ${clauses} ` |
| | | } else { |
| | | sql += `WHERE ${clauses} ` |
| | | } |
| | | } |
| | | sql += `${orderByClauses} ` |
| | | if (isFind && !isCount && !isEmpty(pageable.page) && !isEmpty(pageable.size)) { |
| | | sql += `LIMIT ${pageable.size} OFFSET ${pageable.page * pageable.size} ` |
| | | } |
| | | } else { |
| | | sql += `${orderByClauses} ` |
| | | } |
| | | sql += `;`; |
| | | // log.info("[JPA]:", sql) |
| | | let ret |
| | | if (isFind) { |
| | | ret = sqlite.select(sql) |
| | | if (isCount) { |
| | | if (ret[0] && ret[0]["COUNT(*)"]) { |
| | | return ret[0]["COUNT(*)"] |
| | | } else { |
| | | return 0 |
| | | } |
| | | } |
| | | } else { |
| | | ret = sqlite.exec(sql) |
| | | } |
| | | return ret |
| | | } |
| | | |
| | | /** |
| | | * å¤ç©ºå½æ° |
| | | * @param {any} value - è¦å¤æçå¼ |
| | | * @returns {boolean} æ¯å¦ä¸ºç©º |
| | | */ |
| | | function isEmpty(value) { |
| | | return value === undefined || value === null |
| | | } |
| | | |
| | | /** |
| | | * é¦åæ¯å°å |
| | | * @param {string} str - å符串 |
| | | * @returns {string} é¦åæ¯å°åçå符串 |
| | | */ |
| | | function firstLower(str) { |
| | | return str.charAt(0).toLowerCase() + str.slice(1); |
| | | } |
| | | |
| | | /** |
| | | * JPAæµè¯æ¹æ³ |
| | | * æä¾åç§JPAæ¹æ³ç使ç¨ç¤ºä¾ |
| | | */ |
| | | sqliteService.testJPA = function () { |
| | | // æ¥è¯¢ |
| | | // SELECT * FROM d1_pass_record ; |
| | | sqliteService.d1_pass_record.find() |
| | | // SELECT * FROM d1_pass_record WHERE a = 1 AND b = 2 ; |
| | | sqliteService.d1_pass_record.find({ a: 1, b: 2 }) |
| | | // SELECT * FROM d1_pass_record WHERE a = 1 AND b = 2 ; |
| | | sqliteService.d1_pass_record.find({ a: 1, b: 2, page: 1 }) |
| | | // SELECT * FROM d1_pass_record WHERE a = 1 AND b = 2 LIMIT 1 OFFSET 1 ; |
| | | sqliteService.d1_pass_record.find({ a: 1, b: 2, page: 1, size: 1 }) |
| | | // SELECT * FROM d1_pass_record WHERE a = 1 AND b = 2 AND c = 3 ; |
| | | sqliteService.d1_pass_record.findByAAndBAndC(1, 2, 3) |
| | | // SELECT * FROM d1_pass_record WHERE a = 1 AND b = 2 AND c = 3 AND a = 1 AND b = 2 ; |
| | | sqliteService.d1_pass_record.findByAAndBAndC(1, 2, 3, { a: 1, b: 2 }) |
| | | // SELECT * FROM d1_pass_record WHERE a = 1 AND b = 2 AND c = 3 AND a = 1 AND b = 2 LIMIT 1 OFFSET 1 ; |
| | | sqliteService.d1_pass_record.findByAAndBAndC(1, 2, 3, { a: 1, b: 2, page: 1, size: 1 }) |
| | | // SELECT * FROM d1_pass_record ; |
| | | sqliteService.d1_pass_record.findAll() |
| | | // SELECT * FROM d1_pass_record WHERE a = 1 AND b = 2 ; |
| | | sqliteService.d1_pass_record.findAll({ a: 1, b: 2 }) |
| | | // SELECT * FROM d1_pass_record WHERE a = 1 AND b = 2 ; |
| | | sqliteService.d1_pass_record.findAll({ a: 1, b: 2, page: 1 }) |
| | | // SELECT * FROM d1_pass_record WHERE a = 1 AND b = 2 LIMIT 1 OFFSET 1 ; |
| | | sqliteService.d1_pass_record.findAll({ a: 1, b: 2, page: 1, size: 1 }) |
| | | // SELECT * FROM d1_pass_record WHERE a = 1 AND b = 2 AND c = 3 ; |
| | | sqliteService.d1_pass_record.findAllByAAndBAndC(1, 2, 3) |
| | | // SELECT * FROM d1_pass_record WHERE a = 1 AND b = 2 AND c = 3 AND a = 1 AND b = 2 ; |
| | | sqliteService.d1_pass_record.findAllByAAndBAndC(1, 2, 3, { a: 1, b: 2 }) |
| | | // SELECT * FROM d1_pass_record WHERE a = 1 AND b = 2 AND c = 3 AND a = 1 AND b = 2 LIMIT 1 OFFSET 1 ; |
| | | sqliteService.d1_pass_record.findAllByAAndBAndC(1, 2, 3, { a: 1, b: 2, page: 1, size: 1 }) |
| | | // SELECT * FROM d1_pass_record WHERE a = 1 AND b = 2 AND c = 3 AND a = 1 AND b = 2 ORDER BY a DESC,b ASC,c ASC LIMIT 1 OFFSET 1 ; |
| | | sqliteService.d1_pass_record.findAllByAAndBAndCOrderByADescBAscCAsc(1, 2, 3, { a: 1, b: 2, page: 1, size: 1 }) |
| | | // å é¤ |
| | | // DELETE FROM d1_pass_record ; |
| | | sqliteService.d1_pass_record.delete() |
| | | // DELETE FROM d1_pass_record WHERE a = 1 AND b = 2 ; |
| | | sqliteService.d1_pass_record.delete({ a: 1, b: 2 }) |
| | | // DELETE FROM d1_pass_record WHERE a = 1 AND b = 2 ; |
| | | sqliteService.d1_pass_record.delete({ a: 1, b: 2, page: 1 }) |
| | | // DELETE FROM d1_pass_record WHERE a = 1 AND b = 2 ; |
| | | sqliteService.d1_pass_record.delete({ a: 1, b: 2, page: 1, size: 1 }) |
| | | // DELETE FROM d1_pass_record WHERE a = 1 AND b = 2 AND c = 3 ; |
| | | sqliteService.d1_pass_record.deleteByAAndBAndC(1, 2, 3) |
| | | // DELETE FROM d1_pass_record WHERE a = 1 AND b = 2 AND c = 3 AND a = 1 AND b = 2 ; |
| | | sqliteService.d1_pass_record.deleteByAAndBAndC(1, 2, 3, { a: 1, b: 2 }) |
| | | // DELETE FROM d1_pass_record WHERE a = 1 AND b = 2 AND c = 3 AND a = 1 AND b = 2 ; |
| | | sqliteService.d1_pass_record.deleteByAAndBAndC(1, 2, 3, { a: 1, b: 2, page: 1, size: 1 }) |
| | | // DELETE FROM d1_pass_record ; |
| | | sqliteService.d1_pass_record.deleteAll() |
| | | // DELETE FROM d1_pass_record WHERE a = 1 AND b = 2 ; |
| | | sqliteService.d1_pass_record.deleteAll({ a: 1, b: 2 }) |
| | | // DELETE FROM d1_pass_record WHERE a = 1 AND b = 2 ; |
| | | sqliteService.d1_pass_record.deleteAll({ a: 1, b: 2, page: 1 }) |
| | | // DELETE FROM d1_pass_record WHERE a = 1 AND b = 2 ; |
| | | sqliteService.d1_pass_record.deleteAll({ a: 1, b: 2, page: 1, size: 1 }) |
| | | // DELETE FROM d1_pass_record ; |
| | | sqliteService.d1_pass_record.deleteAllByAAndBAndC(1, 2, 3) |
| | | // DELETE FROM d1_pass_record WHERE a = 1 AND b = 2 ; |
| | | sqliteService.d1_pass_record.deleteAllByAAndBAndC(1, 2, 3, { a: 1, b: 2 }) |
| | | // DELETE FROM d1_pass_record WHERE a = 1 AND b = 2 ; |
| | | sqliteService.d1_pass_record.deleteAllByAAndBAndC(1, 2, 3, { a: 1, b: 2, page: 1, size: 1 }) |
| | | // DELETE FROM d1_pass_record WHERE (a = 1 AND b = 2) OR (a = 1 AND b = 2 AND page = 1) OR (a = 1 AND b = 2 AND page = 1 AND size = 1); |
| | | sqliteService.d1_pass_record.deleteInBatch([{ a: 1, b: 2 }, { a: 1, b: 2, page: 1 }, { a: 1, b: 2, page: 1, size: 1 }]) |
| | | // DELETE FROM d1_pass_record WHERE id IN (1 ,2 ,3 ); |
| | | sqliteService.d1_pass_record.deleteByIdInBatch([1, 2, 3]) |
| | | // æ´æ° |
| | | // UPDATE d1_pass_record SET a = 4 WHERE b = 1 AND c = 2 AND d = 3 ; |
| | | sqliteService.d1_pass_record.updateAByBAndCAndD(1, 2, 3, 4) |
| | | // UPDATE d1_pass_record SET a = 4,b = 5,c = 6 WHERE d = 1 AND e = 2 AND f = 3 ; |
| | | sqliteService.d1_pass_record.updateAAndBAndCByDAndEAndF(1, 2, 3, 4, 5, 6) |
| | | // æ·»å |
| | | // INSERT INTO d1_pass_record VALUES (,,,,,,,0,0,,); |
| | | sqliteService.d1_pass_record.save({ a: 1, b: 2 }) |
| | | // INSERT INTO d1_pass_record VALUES (,,,,,,,0,0,,), (,,,,,,,0,0,,); |
| | | sqliteService.d1_pass_record.saveAll([{ a: 1, b: 2 }, { a: 1, b: 2 }]) |
| | | // èå |
| | | // SELECT COUNT(*) FROM d1_pass_record ; |
| | | sqliteService.d1_pass_record.count(); |
| | | // SELECT COUNT(*) FROM d1_pass_record WHERE a = 1 AND b = 2 AND c = 3 ; |
| | | sqliteService.d1_pass_record.countByAAndBAndC(1, 2, 3); |
| | | } |
| | | |
| | | /** |
| | | * å®å
¨å¯é¥æ¥è¯¢ |
| | | * @param {string} code - 代ç |
| | | * @param {string} type - ç±»å |
| | | * @param {string} id - å®å
¨ID |
| | | * @param {number} time - æ¶é´ |
| | | * @param {string} key - å¯é¥ |
| | | * @param {string} index - ç´¢å¼ |
| | | * @returns {array} æ¥è¯¢ç»æ |
| | | */ |
| | | sqliteService.securityFindAllByCodeAndTypeAndTimeAndkey = function (code, type, id, time, key, index) { |
| | | var query = `SELECT * FROM d1_security WHERE 1=1` |
| | | if (code) { |
| | | query += ` AND code = '${code}'` |
| | | } |
| | | if (type) { |
| | | query += ` AND type = '${type}'` |
| | | } |
| | | if (id) { |
| | | query += ` AND securityId = '${id}'` |
| | | } |
| | | if (index) { |
| | | query += ` AND door = '${index}'` |
| | | } |
| | | if (key) { |
| | | query += ` AND key = '${key}'` |
| | | } |
| | | if (time) { |
| | | query += ` AND endTime >= '${time}'` |
| | | } |
| | | return sqlite.select(query) |
| | | } |
| | | |
| | | export default sqliteService |
| | | |
| | | |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | /** |
| | | * UART485æå¡æ¨¡å |
| | | * å¤çUART485éä¿¡ç¸å
³çä¸å¡é»è¾ï¼å
æ¬æ¡ç æ°æ®æ¥æ¶ã设å¤é
置管ççåè½ |
| | | */ |
| | | import bus from "../../dxmodules/dxEventBus.js" |
| | | import common from "../../dxmodules/dxCommon.js" |
| | | import log from "../../dxmodules/dxLogger.js" |
| | | import std from '../../dxmodules/dxStd.js' |
| | | import driver from '../driver.js' |
| | | import utils from '../common/utils/utils.js' |
| | | import dxMap from '../../dxmodules/dxMap.js' |
| | | import config from '../../dxmodules/dxConfig.js' |
| | | const uart485Service = {} |
| | | |
| | | /** |
| | | * å°åè¿å¶æ°è½¬æ¢ä¸ºå°ç«¯åºåå
è¿å¶å符串 |
| | | * @param {number} decimalNumber - åè¿å¶æ°å |
| | | * @param {number} byteSize - åèå¤§å° |
| | | * @returns {string} å°ç«¯åºåå
è¿å¶å符串 |
| | | */ |
| | | function decimalToLittleEndianHex (decimalNumber, byteSize) { |
| | | const littleEndianBytes = []; |
| | | for (let i = 0; i < byteSize; i++) { |
| | | littleEndianBytes.push(decimalNumber & 0xFF); |
| | | decimalNumber >>= 8; // ç¸å½äºé¤ä»¥256 |
| | | } |
| | | const littleEndianHex = littleEndianBytes |
| | | .map((byte) => byte.toString(16).padStart(2, '0')) |
| | | .join(''); |
| | | return littleEndianHex; |
| | | } |
| | | |
| | | /** |
| | | * å°æ°æ®å
转æ¢ä¸ºåç¬¦ä¸²æ ¼å¼ |
| | | * @param {object} pack - æ°æ®å
对象 |
| | | * @param {string} pack.cmd - å½ä»¤ç |
| | | * @param {string} pack.result - ç»æç |
| | | * @param {string} [pack.data] - æ°æ® |
| | | * @returns {string} 转æ¢åçå符串 |
| | | */ |
| | | function pack2str (pack) { |
| | | pack.data = (!pack.data) ? [] : pack.data.match(/.{2}/g) |
| | | let len = decimalToLittleEndianHex(pack.data.length, 2) |
| | | let str = "55aa" + pack.cmd + pack.result + len + pack.data.join('') |
| | | let crc = common.calculateBcc([0x55, 0xaa, parseInt(pack.cmd, 16), parseInt(pack.result, 16), pack.data.length % 256, pack.data.length / 256].concat(pack.data.map(v => parseInt(v, 16)))) |
| | | return str + crc.toString(16).padStart(2, '0') |
| | | } |
| | | |
| | | /** |
| | | * æ¥æ¶UART485æ°æ®å¹¶å¤ç |
| | | * @param {object} data - æ¥æ¶å°çæ°æ® |
| | | * @param {string} type - æ°æ®ç±»åï¼'code'表示æ¡ç æ°æ®ï¼'instruction'表示æä»¤ |
| | | */ |
| | | uart485Service.receive = function (data, type) { |
| | | log.info("code:",JSON.stringify(data)) |
| | | if (type == 'code') { |
| | | if(data.cmd == "30") { |
| | | if(data.length > 0) { |
| | | let code = common.hexToString(data.data) |
| | | const now = new Date().getTime() |
| | | let map = dxMap.get("CODETIME") |
| | | let time = map.get("time") || 0 |
| | | let interval = Math.max(1000, config.get("sys.interval")) |
| | | if(now - time > interval) { |
| | | bus.fire("getCode", code) |
| | | map.put("time", new Date().getTime()) |
| | | } |
| | | } |
| | | } |
| | | } |
| | | if (type == 'instruction') { |
| | | if (data.cmd == "0a") { |
| | | // è·å设å¤SN |
| | | if (data.length > 0) { |
| | | console.log('---0Aåå
¥--'); |
| | | |
| | | let newSn = common.hexToString(data.data) |
| | | //ä¿®æ¹ sn å·æ¹æä¼ å
¥åæ° |
| | | try { |
| | | let wgetApp = common.systemWithRes(`test -e "/etc/.sn" && echo "OK" || echo "NO"`, 2) |
| | | if (!wgetApp.includes('OK')) { |
| | | //没æå建ä¸ä¸ |
| | | common.systemBrief("touch /etc/.sn") |
| | | } |
| | | std.saveFile('/etc/.sn', newSn) |
| | | common.systemWithRes(`rm -rf /app/data/config/config.json`, 2) |
| | | } catch (error) { |
| | | log.info('0Aåå
¥ sn 失败åå :', error.stack) |
| | | let pack1 = { "cmd": '0A', "result": '90', 'data': '' } |
| | | driver.uart485.sendVg(pack2str(pack1)) |
| | | return |
| | | } |
| | | //è¿åä¸²å£ |
| | | let pack1 = { "cmd": '0A', "result": '00', 'data': common.stringToHex(newSn) } |
| | | driver.uart485.sendVg(pack2str(pack1)) |
| | | common.asyncReboot(2) |
| | | } else { |
| | | log.info('-----0Aæ¥è¯¢-----', common.getSn()); |
| | | let pack1 = { "cmd": '0A', "result": '00', "data": common.stringToHex(common.getSn()) } |
| | | // log.info(pack2str(pack1)); |
| | | driver.uart485.sendVg(pack2str(pack1)) |
| | | } |
| | | } else if (data.cmd == "b0") { |
| | | log.info("----b0---") |
| | | // æ¥è¯¢/ä¿®æ¹è®¾å¤é
ç½® |
| | | let str = data.data |
| | | if (!str) { |
| | | return |
| | | } |
| | | //æ°æ®å第ä¸ä¸ªåè表示修æ¹è¿æ¯æ¥è¯¢ 00 æ¥è¯¢ 01 ä¿®æ¹ |
| | | if (parseInt(str.substring(0, 2)) == 0) { |
| | | //æ¥è¯¢é
ç½® |
| | | let pack1 = { "cmd": 'B0', "result": '00', "data": common.stringToHex(common.getSn()) } |
| | | driver.uart485.sendVg(pack2str(pack1)) |
| | | } else { |
| | | //ä¿®æ¹é
ç½® |
| | | if (data.dlen <= 1) { |
| | | return |
| | | } |
| | | // ___VBAR_CONFIG_V1.1.0___{ble_name="11127S"}--lLqHBRnE2bU8D2HJ5RTioQ== |
| | | let toString = common.hexToString(str.substring(2)) |
| | | let content = parseString(toString) |
| | | if (content.sn) { |
| | | //ä¿®æ¹ sn å·æ¹æä¼ å
¥åæ° |
| | | try { |
| | | let wgetApp = common.systemWithRes(`test -e "/etc/.sn" && echo "OK" || echo "NO"`, 2) |
| | | if (!wgetApp.includes('OK')) { |
| | | //没æå建ä¸ä¸ |
| | | common.systemBrief("touch /etc/.sn") |
| | | } |
| | | std.saveFile('/etc/.sn', content.sn) |
| | | common.systemWithRes(`rm -rf /app/data/config/config.json`, 2) |
| | | } catch (error) { |
| | | log.info('åå
¥/etc/.snæä»¶å¤±è´¥,åå :', error.stack) |
| | | let pack1 = { "cmd": 'B0', "result": '90', "data": common.stringToHex(common.getSn()) } |
| | | driver.uart485.sendVg(pack2str(pack1)) |
| | | return |
| | | } |
| | | //è¿åä¸²å£ |
| | | let pack1 = { "cmd": 'B0', "result": '00', "data": common.stringToHex(content.sn) } |
| | | driver.uart485.sendVg(pack2str(pack1)) |
| | | common.asyncReboot(2) |
| | | } |
| | | |
| | | } |
| | | } else if (data.cmd == "0c") { |
| | | log.info("----0c--") |
| | | // è·å主æ§chipID |
| | | let pack = { "cmd": '0C', "result": '00', "data": common.stringToHex(common.getUuid()) } |
| | | driver.uart485.sendVg(pack2str(pack)) |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è§£æå符串为JSONå¯¹è±¡ï¼æ³¨ævalueå
ä¸è½æ"å· |
| | | * @param {string} inputString - è¾å
¥å符串 |
| | | * @returns {object} è§£æåçJSON对象 |
| | | */ |
| | | utils.parseString = function (inputString) { |
| | | // è·å{}åå
¶ä¹é´çå
容 |
| | | inputString = inputString.slice(inputString.indexOf("{"), inputString.lastIndexOf("}") + 1) |
| | | // key=valueæ£åï¼keyæ¯\w+ï¼åæ¯æ°åä¸å线ï¼åºå«å¤§å°åï¼ï¼=ä¸¤è¾¹å¯æç©ºæ ¼ï¼valueæ¯\w+æç¸é»ä¸¤ä¸ª"ä¹é´çå
容ï¼å
å«"ï¼ |
| | | const keyValueRegex = /(\w+)\s*=\s*("[^"]*"|\w+)/g; |
| | | let jsonObject = {}; |
| | | let match; |
| | | while ((match = keyValueRegex.exec(inputString)) !== null) { |
| | | let key = match[1]; |
| | | let value = match[2] |
| | | |
| | | if (/^\d+$/.test(value)) { |
| | | // æ°å |
| | | value = parseInt(value) |
| | | } else if (/^\d+\.\d+$/.test(value)) { |
| | | // å°æ° |
| | | value = parseFloat(value) |
| | | } else if (value == 'true') { |
| | | value = true |
| | | } else if (value == 'false') { |
| | | value = false |
| | | } else { |
| | | // å符串 |
| | | value = value.replace(/"/g, '').trim() |
| | | } |
| | | jsonObject[key] = value; |
| | | } |
| | | return jsonObject; |
| | | } |
| | | |
| | | export default uart485Service |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | /** |
| | | * æå¡æ± é
ç½®æä»¶ |
| | | * 注åç³»ç»ä¸æææå¡çäºä»¶å¤çåè°ï¼å¤çæ¥èªå模åçäºä»¶ |
| | | */ |
| | | import pool from '../dxmodules/dxWorkerPool.js' |
| | | import face from '../dxmodules/dxFace.js' |
| | | import driver from './driver.js' |
| | | import bus from '../dxmodules/dxEventBus.js' |
| | | import faceService from './service/faceService.js' |
| | | import net from '../dxmodules/dxNet.js' |
| | | import config from '../dxmodules/dxConfig.js' |
| | | import nfc from '../dxmodules/dxNfc.js' |
| | | import mqtt from '../dxmodules/dxMqtt.js' |
| | | import map from '../dxmodules/dxMap.js' |
| | | import mqttService from './service/mqttService.js' |
| | | import accessService from './service/accessService.js' |
| | | import nfcService from './service/nfcService.js' |
| | | import common from '../dxmodules/dxCommon.js' |
| | | import log from '../dxmodules/dxLogger.js' |
| | | import dxGpioKey from '../dxmodules/dxGpioKey.js' |
| | | import uart from '../dxmodules/dxUart.js' |
| | | import uart485Service from './service/uart485Service.js' |
| | | import configService from './service/configService.js' |
| | | import grainService from './service/grainService.js' |
| | | import gpiokeyService from './service/gpiokeyService.js' |
| | | import codeService from './service/codeService.js' |
| | | |
| | | /** |
| | | * æå¡æ± åè°å½æ° |
| | | * å¤çæ¥èªå模åçäºä»¶æ¶æ¯ï¼æ ¹æ®äºä»¶ä¸»é¢ååå°ç¸åºçæå¡å¤ç |
| | | * @param {object} data - äºä»¶æ°æ® |
| | | * @param {string} data.topic - äºä»¶ä¸»é¢ |
| | | * @param {any} data.data - äºä»¶æ°æ® |
| | | */ |
| | | pool.callback((data) => { |
| | | let topic = data.topic |
| | | let msg = data.data |
| | | switch (topic) { |
| | | case face.RECEIVE_MSG: |
| | | // å¤ç人è¸è¯å«æ¶æ¯ |
| | | faceService.receiveMsg(msg) |
| | | break; |
| | | case dxGpioKey.RECEIVE_MSG: |
| | | // å¤çGPIOæé®æ¶æ¯ |
| | | gpiokeyService.receiveMsg(msg) |
| | | break; |
| | | case "netGetWifiSsidList": |
| | | // è·åWiFiå表 |
| | | let wifiList = driver.net.netGetWifiSsidList() |
| | | bus.fire("netWifiSsidList", wifiList) |
| | | break; |
| | | case "switchNetworkType": |
| | | // 忢ç½ç»ç±»å |
| | | config.setAndSave("net.type", msg) |
| | | console.log("忢ç½ç»", msg); |
| | | driver.net.changeNetType() |
| | | break; |
| | | case "setConfig": |
| | | // é
ç½®éªè¯åä¿å |
| | | configService.configVerifyAndSave(msg) |
| | | break; |
| | | case "access": |
| | | // å¤çéè¡éªè¯ |
| | | accessService.access(msg.data, msg.fileName, msg.similarity) |
| | | break; |
| | | case nfc.RECEIVE_MSG: |
| | | // å¤çNFCå¡çæ¶æ¯ |
| | | nfcService.receiveMsg(msg) |
| | | break; |
| | | case net.STATUS_CHANGE: |
| | | // ç½ç»ç¶æåå |
| | | map.get("NET").put("status", msg.status) |
| | | bus.fire("netStatus", msg) |
| | | break; |
| | | case mqtt.CONNECTED_CHANGED: |
| | | // MQTTè¿æ¥ç¶æåå |
| | | bus.fire("mqttStatus", msg) |
| | | // mqttè¿æ¥ä¸æ¥ |
| | | if (msg == "connected") { |
| | | mqttService.report() |
| | | } |
| | | break; |
| | | case mqtt.RECEIVE_MSG: |
| | | // å¤çMQTTæ¶æ¯ |
| | | mqttService.receiveMsg(msg) |
| | | break; |
| | | case uart.VG.RECEIVE_MSG + driver.uart485.id: |
| | | // å¤çUART485æä»¤æ¶æ¯ |
| | | uart485Service.receive(msg, 'instruction') |
| | | break; |
| | | case uart.VG.RECEIVE_MSG + driver.uartCode.id: |
| | | // å¤çUARTç æ¶æ¯ |
| | | uart485Service.receive(msg, 'code') |
| | | break; |
| | | case "getCode": |
| | | // å¤çæ¡ç æ°æ® |
| | | codeService.code(msg) |
| | | break; |
| | | case "trackResult": |
| | | // å¤ç人è¸è¯å«ç»æäºä»¶ï¼ç±mainView.jså¤çï¼ |
| | | break; |
| | | |
| | | default: |
| | | // æªç¥ä¸»é¢ |
| | | log.error("No such topic ", topic) |
| | | break; |
| | | } |
| | | }) |
| | | |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | import ui from "../dxmodules/dxUi.js"; |
| | | import std from "../dxmodules/dxStd.js" |
| | | |
| | | // uiä¸ä¸æ |
| | | let context = {} |
| | | |
| | | // uiåå§å |
| | | ui.init({ orientation: 0 }, context); |
| | | |
| | | const screenMain = ui.View.build('mainView', ui.Utils.LAYER.MAIN) |
| | | |
| | | const bottomSnBtn = ui.Button.build('bottomSnBtn', screenMain) |
| | | bottomSnBtn.bgColor(0xff0000) |
| | | bottomSnBtn.bgOpa(20) |
| | | bottomSnBtn.setSize(200, 100) |
| | | bottomSnBtn.setPos(100, 700) |
| | | |
| | | |
| | | bottomSnBtn.on(ui.Utils.EVENT.CLICK, () => { |
| | | print("passwordView") |
| | | }) |
| | | |
| | | // å è½½å±å¹ |
| | | ui.loadMain(screenMain) |
| | | |
| | | // å·æ°ui |
| | | let timer = std.setInterval(() => { |
| | | if (ui.handler() < 0) { |
| | | std.clearInterval(timer) |
| | | } |
| | | }, 1) |
| | | |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | import dxui from '../../dxmodules/dxUi.js' |
| | | import std from '../../dxmodules/dxStd.js' |
| | | import viewUtils from "./viewUtils.js" |
| | | import topView from './topView.js' |
| | | import mainView from './mainView.js' |
| | | import i18n from './i18n.js' |
| | | const appView = {} |
| | | appView.init = function () { |
| | | /**************************************************å建å±å¹*****************************************************/ |
| | | const screenMain = dxui.View.build('appView', dxui.Utils.LAYER.MAIN) |
| | | appView.screenMain = screenMain |
| | | screenMain.scroll(false) |
| | | screenMain.bgColor(0xffffff) |
| | | screenMain.on(dxui.Utils.ENUM.LV_EVENT_SCREEN_LOADED, () => { |
| | | topView.changeTheme(true) |
| | | appQrcode.source('/app/code/resource/image/app_qrcode.png') |
| | | // æ æä½10ç§èªå¨è¿å |
| | | if (appView.timer) { |
| | | std.clearInterval(appView.timer) |
| | | } |
| | | appView.timer = std.setInterval(() => { |
| | | let count = dxui.Utils.GG.NativeDisp.lvDispGetInactiveTime() |
| | | if (count > 10 * 1000) { |
| | | std.clearInterval(appView.timer) |
| | | appView.timer = null |
| | | dxui.loadMain(mainView.screenMain) |
| | | } |
| | | }, 1000) |
| | | }) |
| | | |
| | | const appQrcode = dxui.Image.build('appQrcode', screenMain) |
| | | appQrcode.source('/app/code/resource/image/app_qrcode.png') |
| | | appQrcode.align(dxui.Utils.ALIGN.TOP_MID, 0, 206) |
| | | |
| | | const knowedBtn = viewUtils.bottomBtn(screenMain, 'knowedBtn', 'appView.knowed', () => { |
| | | dxui.loadMain(mainView.screenMain) |
| | | }) |
| | | knowedBtn.align(dxui.Utils.ALIGN.BOTTOM_MID, 0, -124) |
| | | |
| | | const appQrcodeLbl = dxui.Label.build('appQrcodeLbl', screenMain) |
| | | appQrcodeLbl.text('使ç¨å°ç¨åºä¾¿æ·ç®¡ç') |
| | | appQrcodeLbl.textFont(viewUtils.font(30)) |
| | | appQrcodeLbl.align(dxui.Utils.ALIGN.BOTTOM_MID, 0, -403) |
| | | appQrcodeLbl.dataI18n = 'appView.appQrcodeLbl' |
| | | } |
| | | |
| | | export default appView |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | import dxui from "../../../dxmodules/dxUi.js" |
| | | import config from "../../../dxmodules/dxConfig.js" |
| | | import viewUtils from "../viewUtils.js" |
| | | import topView from "../topView.js" |
| | | import mainView from "../mainView.js" |
| | | import cloudCertView from "./menu/cloudCertView.js" |
| | | import doorControlView from "./menu/doorControlView.js" |
| | | import helpView from "./menu/helpView.js" |
| | | import networkSettingView from "./menu/networkSettingView.js" |
| | | import systemSettingView from "./menu/systemSettingView.js" |
| | | import deviceInfoView from "./menu/deviceInfoView.js" |
| | | import factoryTestView from "./menu/factoryTestView.js" |
| | | import localUserView from "./menu/localUserView.js" |
| | | import recordQueryView from "./menu/recordQueryView.js" |
| | | import voiceBroadcastView from "./menu/voiceBroadcastView.js" |
| | | |
| | | import screen from '../../screen.js' |
| | | const configView = {} |
| | | configView.init = function () { |
| | | /**************************************************å建å±å¹*****************************************************/ |
| | | const screenMain = dxui.View.build('configView', dxui.Utils.LAYER.MAIN) |
| | | configView.screenMain = screenMain |
| | | screenMain.scroll(false) |
| | | screenMain.bgColor(0xffffff) |
| | | screenMain.on(dxui.Utils.ENUM.LV_EVENT_SCREEN_LOADED, () => { |
| | | topView.changeTheme(true) |
| | | }) |
| | | |
| | | // const confirm = viewUtils.confirmWin('configViewConfirm', 'configView.confirmExit', () => { |
| | | // dxui.loadMain(mainView.screenMain) |
| | | // }) |
| | | |
| | | const titleBox = viewUtils.title(screenMain, undefined, 'configViewTitle', 'configView.title', () => { |
| | | viewUtils.confirmOpen('configView.confirmExit', 'configView.confirmExitContent', () => { |
| | | dxui.loadMain(mainView.screenMain) |
| | | }, () => { }) |
| | | }) |
| | | titleBox.align(dxui.Utils.ALIGN.TOP_MID, 0, 70) |
| | | |
| | | |
| | | const menuBox = dxui.View.build('menuBox', screenMain) |
| | | viewUtils._clearStyle(menuBox) |
| | | menuBox.setSize(screen.screenSize.width, 800) |
| | | menuBox.bgOpa(0) |
| | | menuBox.align(dxui.Utils.ALIGN.TOP_MID, 0, 178) |
| | | menuBox.flexFlow(dxui.Utils.FLEX_FLOW.ROW_WRAP) |
| | | menuBox.flexAlign(dxui.Utils.FLEX_ALIGN.START, dxui.Utils.FLEX_ALIGN.START, dxui.Utils.FLEX_ALIGN.START) |
| | | menuBox.obj.lvObjSetStylePadGap(0, dxui.Utils.ENUM._LV_STYLE_STATE_CMP_SAME) |
| | | |
| | | configView.menuBtn('localUser', menuBox, screen.screenSize.width / 4, screen.screenSize.width / 4, '/app/code/resource/image/localUser.png', 'configView.localUser', () => { |
| | | dxui.loadMain(localUserView.screenMain) |
| | | }) |
| | | |
| | | configView.menuBtn('networkSetting', menuBox, screen.screenSize.width / 4, screen.screenSize.width / 4, '/app/code/resource/image/networkSetting.png', 'configView.networkSetting', () => { |
| | | dxui.loadMain(networkSettingView.screenMain) |
| | | }) |
| | | |
| | | configView.menuBtn('doorControl', menuBox, screen.screenSize.width / 4, screen.screenSize.width / 4, '/app/code/resource/image/doorControl.png', 'configView.doorControl', () => { |
| | | dxui.loadMain(doorControlView.screenMain) |
| | | }) |
| | | |
| | | configView.menuBtn('systemSetting', menuBox, screen.screenSize.width / 4, screen.screenSize.width / 4, '/app/code/resource/image/systemSetting.png', 'configView.systemSetting', () => { |
| | | dxui.loadMain(systemSettingView.screenMain) |
| | | }) |
| | | |
| | | configView.menuBtn('deviceInfo', menuBox, screen.screenSize.width / 4, screen.screenSize.width / 4, '/app/code/resource/image/deviceInfo.png', 'configView.deviceInfo', () => { |
| | | dxui.loadMain(deviceInfoView.screenMain) |
| | | }) |
| | | |
| | | configView.menuBtn('recordQuery', menuBox, screen.screenSize.width / 4, screen.screenSize.width / 4, '/app/code/resource/image/recordQuery.png', 'configView.recordQuery', () => { |
| | | dxui.loadMain(recordQueryView.screenMain) |
| | | }) |
| | | |
| | | configView.menuBtn('voiceBroadcast', menuBox, screen.screenSize.width / 4, screen.screenSize.width / 4, '/app/code/resource/image/voiceBroadcast.png', 'configView.voiceBroadcast', () => { |
| | | dxui.loadMain(voiceBroadcastView.screenMain) |
| | | }) |
| | | |
| | | if (config.get("base.showIdentityCard") == 1) { |
| | | configView.menuBtn('cloudCert', menuBox, screen.screenSize.width / 4, screen.screenSize.width / 4, '/app/code/resource/image/cloudCert.png', 'configView.cloudCert', () => { |
| | | dxui.loadMain(cloudCertView.screenMain) |
| | | }) |
| | | } |
| | | |
| | | |
| | | |
| | | configView.menuBtn('help', menuBox, screen.screenSize.width / 4, screen.screenSize.width / 4, '/app/code/resource/image/help.png', 'configView.help', () => { |
| | | dxui.loadMain(helpView.screenMain) |
| | | }) |
| | | } |
| | | |
| | | configView.menuBtn = function (id, parent, width, height, src, dataI18n, callback = () => { }) { |
| | | const box = dxui.View.build(id, parent) |
| | | viewUtils._clearStyle(box) |
| | | box.setSize(width, height) |
| | | box.bgOpa(0) |
| | | |
| | | const zoom = 1.02 |
| | | |
| | | const bg = dxui.View.build(id + 'bg', box) |
| | | viewUtils._clearStyle(bg) |
| | | bg.setSize(140, 140) |
| | | bg.bgColor(0xf6f6f6) |
| | | bg.radius(30) |
| | | bg.align(dxui.Utils.ALIGN.TOP_MID, 0, 10) |
| | | |
| | | const image = dxui.Image.build(id + 'image', bg) |
| | | image.source(src) |
| | | image.align(dxui.Utils.ALIGN.CENTER, 0, 0) |
| | | |
| | | bg.on(dxui.Utils.ENUM.LV_EVENT_PRESSED, () => { |
| | | bg.setSize(140 * zoom, 140 * zoom) |
| | | image.obj.lvImgSetZoom(256 * zoom) |
| | | }) |
| | | bg.on(dxui.Utils.ENUM.LV_EVENT_RELEASED, () => { |
| | | bg.setSize(140, 140) |
| | | image.obj.lvImgSetZoom(256) |
| | | }) |
| | | |
| | | bg.on(dxui.Utils.EVENT.CLICK, () => { |
| | | callback() |
| | | }) |
| | | |
| | | const textLbl = dxui.Label.build(id + 'text', box) |
| | | textLbl.textFont(viewUtils.font(22)) |
| | | textLbl.textColor(0x767676) |
| | | textLbl.dataI18n = dataI18n |
| | | textLbl.align(dxui.Utils.ALIGN.BOTTOM_MID, 0, -10) |
| | | textLbl.width(width) |
| | | textLbl.textAlign(dxui.Utils.TEXT_ALIGN.CENTER) |
| | | textLbl.longMode(dxui.Utils.LABEL_LONG_MODE.SCROLL_CIRCULAR) |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | export default configView |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | import dxui from '../../../dxmodules/dxUi.js' |
| | | import std from '../../../dxmodules/dxStd.js' |
| | | import viewUtils from "../viewUtils.js" |
| | | import topView from '../topView.js' |
| | | import mainView from '../mainView.js' |
| | | import configView from './configView.js' |
| | | import i18n from '../i18n.js' |
| | | import screen from '../../screen.js' |
| | | const identityVerificationView = {} |
| | | identityVerificationView.init = function () { |
| | | /**************************************************å建å±å¹*****************************************************/ |
| | | const screenMain = dxui.View.build('identityVerificationView', dxui.Utils.LAYER.MAIN) |
| | | identityVerificationView.screenMain = screenMain |
| | | screenMain.scroll(false) |
| | | screenMain.bgColor(0xffffff) |
| | | screenMain.on(dxui.Utils.ENUM.LV_EVENT_SCREEN_LOADED, () => { |
| | | topView.changeTheme(true) |
| | | toggleTab(0) |
| | | |
| | | // æ æä½15ç§èªå¨è¿å |
| | | if (identityVerificationView.timer) { |
| | | std.clearInterval(identityVerificationView.timer) |
| | | } |
| | | identityVerificationView.timer = std.setInterval(() => { |
| | | let count = dxui.Utils.GG.NativeDisp.lvDispGetInactiveTime() |
| | | if (count > 15 * 1000) { |
| | | std.clearInterval(identityVerificationView.timer) |
| | | identityVerificationView.timer = null |
| | | dxui.loadMain(mainView.screenMain) |
| | | } |
| | | }, 1000) |
| | | }) |
| | | |
| | | screenMain.on(dxui.Utils.ENUM.LV_EVENT_SCREEN_UNLOADED, () => { |
| | | // 人è¸è®¤è¯ç»æ |
| | | if (identityVerificationView.timer) { |
| | | std.clearInterval(identityVerificationView.timer) |
| | | } |
| | | if (!faceRec.isHide()) { |
| | | screen.faceAuthEnd() |
| | | } |
| | | }) |
| | | |
| | | const titleBoxBg = dxui.View.build('titleBoxBg', screenMain) |
| | | viewUtils._clearStyle(titleBoxBg) |
| | | titleBoxBg.setSize(screen.screenSize.width, 70) |
| | | titleBoxBg.align(dxui.Utils.ALIGN.TOP_MID, 0, 0) |
| | | titleBoxBg.bgColor(0xffffff) |
| | | |
| | | const titleBox = viewUtils.title(screenMain, mainView.screenMain, 'identityVerificationViewTitle', 'identityVerificationView.title') |
| | | titleBox.align(dxui.Utils.ALIGN.TOP_MID, 0, 70) |
| | | |
| | | const tab = dxui.View.build('tab', screenMain) |
| | | viewUtils._clearStyle(tab) |
| | | tab.setSize(screen.screenSize.width, 80) |
| | | tab.alignTo(titleBox, dxui.Utils.ALIGN.OUT_BOTTOM_MID, 0, 0) |
| | | tab.flexFlow(dxui.Utils.FLEX_FLOW.ROW) |
| | | tab.flexAlign(dxui.Utils.FLEX_ALIGN.SPACE_AROUND, dxui.Utils.FLEX_ALIGN.CENTER, dxui.Utils.FLEX_ALIGN.CENTER) |
| | | |
| | | const pwdLogBox = dxui.View.build('pwdLogBox', tab) |
| | | viewUtils._clearStyle(pwdLogBox) |
| | | const pwdLogLbl = dxui.Label.build('pwdLogLbl', pwdLogBox) |
| | | pwdLogLbl.textFont(viewUtils.font(28)) |
| | | pwdLogLbl.textColor(0x888888) |
| | | pwdLogLbl.text('å¯ç ç»å½') |
| | | pwdLogLbl.dataI18n = 'identityVerificationView.pwdLog' |
| | | const pwdLogText = pwdLogLbl.text |
| | | pwdLogLbl.text = (data) => { |
| | | pwdLogText.call(pwdLogLbl, data) |
| | | pwdLogLbl.update() |
| | | pwdLogBox.setSize(pwdLogLbl.width() + 8, 80) |
| | | } |
| | | pwdLogLbl.align(dxui.Utils.ALIGN.CENTER, 0, 0) |
| | | pwdLogLbl.update() |
| | | pwdLogBox.setSize(pwdLogLbl.width() + 8, 80) |
| | | pwdLogBox.borderWidth(4) |
| | | pwdLogBox.obj.setStyleBorderSide(dxui.Utils.ENUM.LV_BORDER_SIDE_BOTTOM, 0) |
| | | pwdLogBox.setBorderColor(0x0836C) |
| | | pwdLogBox.on(dxui.Utils.EVENT.CLICK, () => { |
| | | toggleTab(0) |
| | | }) |
| | | |
| | | const faceLogBox = dxui.View.build('faceLogBox', tab) |
| | | viewUtils._clearStyle(faceLogBox) |
| | | const faceLogLbl = dxui.Label.build('faceLogLbl', faceLogBox) |
| | | faceLogLbl.textFont(viewUtils.font(28)) |
| | | faceLogLbl.textColor(0x888888) |
| | | faceLogLbl.text('人è¸ç»å½') |
| | | faceLogLbl.dataI18n = 'identityVerificationView.faceLog' |
| | | const faceLogText = faceLogLbl.text |
| | | faceLogLbl.text = (data) => { |
| | | faceLogText.call(faceLogLbl, data) |
| | | faceLogLbl.update() |
| | | faceLogBox.setSize(faceLogLbl.width() + 8, 80) |
| | | } |
| | | faceLogLbl.align(dxui.Utils.ALIGN.CENTER, 0, 0) |
| | | faceLogLbl.update() |
| | | faceLogBox.setSize(faceLogLbl.width() + 8, 80) |
| | | faceLogBox.borderWidth(4) |
| | | faceLogBox.obj.setStyleBorderSide(dxui.Utils.ENUM.LV_BORDER_SIDE_BOTTOM, 0) |
| | | faceLogBox.setBorderColor(0x0836C) |
| | | faceLogBox.on(dxui.Utils.EVENT.CLICK, () => { |
| | | toggleTab(1) |
| | | }) |
| | | |
| | | const pwdInput = viewUtils.input(screenMain, screenMain.id + 'pwdInput', undefined, undefined, 'identityVerificationView.pwd') |
| | | pwdInput.align(dxui.Utils.ALIGN.TOP_MID, 0, 263) |
| | | pwdInput.setPasswordMode(true) |
| | | |
| | | const eyeFill = viewUtils.imageBtn(screenMain, screenMain.id + 'eye_fill', '/app/code/resource/image/eye-fill.png') |
| | | eyeFill.alignTo(pwdInput, dxui.Utils.ALIGN.RIGHT_MID, 0, 0) |
| | | eyeFill.on(dxui.Utils.EVENT.CLICK, () => { |
| | | pwdInput.setPasswordMode(true) |
| | | eyeFill.hide() |
| | | eyeOff.show() |
| | | }) |
| | | eyeFill.hide() |
| | | |
| | | const eyeOff = viewUtils.imageBtn(screenMain, screenMain.id + 'eye_off', '/app/code/resource/image/eye-off.png') |
| | | eyeOff.alignTo(pwdInput, dxui.Utils.ALIGN.RIGHT_MID, 0, 0) |
| | | eyeOff.on(dxui.Utils.EVENT.CLICK, () => { |
| | | pwdInput.setPasswordMode(false) |
| | | eyeFill.show() |
| | | eyeOff.hide() |
| | | }) |
| | | |
| | | const pwdAccessBtn = viewUtils.bottomBtn(screenMain, screenMain.id + 'pwdAccessBtn', 'identityVerificationView.pwdAccess', () => { |
| | | if (screen.getConfig()['base.password'] === pwdInput.text()) { |
| | | // è¿å
¥è®¾ç½®èå |
| | | std.clearInterval(identityVerificationView.timer) |
| | | dxui.loadMain(configView.screenMain) |
| | | } else { |
| | | if (faceRec.isHide()) { |
| | | // å¯ç é误 |
| | | identityVerificationView.statusPanel.fail('identityVerificationView.pwdFail') |
| | | } else { |
| | | // 人è¸è®¤è¯å¤±è´¥ |
| | | identityVerificationView.statusPanel.fail('identityVerificationView.fail') |
| | | } |
| | | } |
| | | }) |
| | | pwdAccessBtn.align(dxui.Utils.ALIGN.BOTTOM_MID, 0, -83) |
| | | |
| | | const faceRec = dxui.Image.build('faceRec', screenMain) |
| | | faceRec.source('/app/code/resource/image/faceRec.png') |
| | | faceRec.alignTo(tab, dxui.Utils.ALIGN.OUT_BOTTOM_MID, 0, 70) |
| | | |
| | | identityVerificationView.statusPanel = viewUtils.statusPanel(screenMain, 'identityVerificationView.success', 'identityVerificationView.fail') |
| | | |
| | | function toggleTab(index) { |
| | | screenMain.send(dxui.Utils.EVENT.CLICK) |
| | | if (index == 0) { |
| | | pwdLogLbl.textColor(0x0836C) |
| | | faceLogLbl.textColor(0x888888) |
| | | pwdLogBox.setBorderColor(0x0836C) |
| | | faceLogBox.setBorderColor(0xffffff) |
| | | pwdInput.show() |
| | | eyeFill.show() |
| | | eyeOff.show() |
| | | pwdAccessBtn.show() |
| | | screenMain.bgOpa(100) |
| | | faceRec.hide() |
| | | |
| | | // 人è¸è®¤è¯ç»æ |
| | | screen.faceAuthEnd() |
| | | } else { |
| | | pwdLogLbl.textColor(0x888888) |
| | | faceLogLbl.textColor(0x0836C) |
| | | pwdLogBox.setBorderColor(0xffffff) |
| | | faceLogBox.setBorderColor(0x0836C) |
| | | pwdInput.hide() |
| | | eyeFill.hide() |
| | | eyeOff.hide() |
| | | pwdAccessBtn.hide() |
| | | screenMain.bgOpa(0) |
| | | faceRec.show() |
| | | |
| | | // 人è¸è®¤è¯å¼å§ |
| | | screen.faceAuthStart() |
| | | } |
| | | } |
| | | toggleTab(0) |
| | | } |
| | | |
| | | export default identityVerificationView |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | import dxui from '../../../../dxmodules/dxUi.js' |
| | | import viewUtils from "../../viewUtils.js" |
| | | import topView from "../../topView.js" |
| | | import configView from '../configView.js' |
| | | const cloudCertView = {} |
| | | cloudCertView.init = function () { |
| | | /**************************************************å建å±å¹*****************************************************/ |
| | | const screenMain = dxui.View.build('cloudCertView', dxui.Utils.LAYER.MAIN) |
| | | cloudCertView.screenMain = screenMain |
| | | screenMain.scroll(false) |
| | | screenMain.bgColor(0xffffff) |
| | | screenMain.on(dxui.Utils.ENUM.LV_EVENT_SCREEN_LOADED, () => { |
| | | topView.changeTheme(true) |
| | | }) |
| | | |
| | | const titleBox = viewUtils.title(screenMain, configView.screenMain, 'cloudCertViewTitle', 'cloudCertView.cloudCertActive') |
| | | titleBox.align(dxui.Utils.ALIGN.TOP_MID, 0, 70) |
| | | |
| | | const inputBox = viewUtils.input(screenMain, 'cloudCertViewInput', undefined, () => { |
| | | console.log('cloudCertViewInput') |
| | | }, 'cloudCertView.inputKey') |
| | | inputBox.align(dxui.Utils.ALIGN.TOP_LEFT, 109, 179) |
| | | inputBox.width(654) |
| | | |
| | | const keyLbl = dxui.Label.build('cloudCertViewKey', screenMain) |
| | | keyLbl.dataI18n = 'cloudCertView.key' |
| | | keyLbl.textFont(viewUtils.font(26)) |
| | | keyLbl.align(dxui.Utils.ALIGN.TOP_LEFT, 43, 201) |
| | | |
| | | const tipLbl = dxui.Label.build('cloudCertViewTip', screenMain) |
| | | tipLbl.dataI18n = 'cloudCertView.tip' |
| | | tipLbl.textFont(viewUtils.font(22)) |
| | | tipLbl.textColor(0x888888) |
| | | tipLbl.align(dxui.Utils.ALIGN.TOP_MID, 0, 650) |
| | | |
| | | |
| | | const saveBtn = viewUtils.bottomBtn(screenMain, screenMain.id + 'saveBtn', 'cloudCertView.save', () => { |
| | | }) |
| | | saveBtn.align(dxui.Utils.ALIGN.BOTTOM_MID, 0, -83) |
| | | } |
| | | |
| | | export default cloudCertView |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | import dxui from '../../../../../dxmodules/dxUi.js' |
| | | import dxCommon from '../../../../../dxmodules/dxCommon.js' |
| | | import viewUtils from "../../../viewUtils.js" |
| | | import topView from "../../../topView.js" |
| | | import deviceInfoView from '../deviceInfoView.js' |
| | | import i18n from "../../../i18n.js" |
| | | import sqliteService from '../../../../service/sqliteService.js' |
| | | import screen from '../../../../screen.js' |
| | | const dataCapacityInfoView = {} |
| | | dataCapacityInfoView.init = function () { |
| | | /**************************************************å建å±å¹*****************************************************/ |
| | | const screenMain = dxui.View.build('dataCapacityInfoView', dxui.Utils.LAYER.MAIN) |
| | | dataCapacityInfoView.screenMain = screenMain |
| | | screenMain.scroll(false) |
| | | screenMain.bgColor(0xffffff) |
| | | screenMain.on(dxui.Utils.ENUM.LV_EVENT_SCREEN_LOADED, () => { |
| | | topView.changeTheme(true) |
| | | |
| | | dataCapacityInfoView.info[0].label.text(Math.floor(dxCommon.getTotaldisk() / 1024 / 1024) + ' M') |
| | | dataCapacityInfoView.info[1].label.text(Math.floor((dxCommon.getTotaldisk() - dxCommon.getFreedisk()) / 1024 / 1024) + ' M') |
| | | dataCapacityInfoView.info[2].label.text(Math.floor(dxCommon.getFreedisk() / 1024 / 1024) + ' M') |
| | | dataCapacityInfoView.info[3].label.text(sqliteService.d1_person.count() + '') |
| | | dataCapacityInfoView.info[4].label.text(sqliteService.d1_voucher.countByType(300) + '') |
| | | dataCapacityInfoView.info[5].label.text(sqliteService.d1_voucher.countByType(400) + '') |
| | | dataCapacityInfoView.info[6].label.text(sqliteService.d1_voucher.countByType(200) + '') |
| | | dataCapacityInfoView.info[7].label.text(sqliteService.d1_pass_record.count() + '') |
| | | }) |
| | | |
| | | const titleBox = viewUtils.title(screenMain, deviceInfoView.screenMain, 'dataCapacityInfoViewTitle', 'deviceInfoView.dataCapacityInfo') |
| | | titleBox.align(dxui.Utils.ALIGN.TOP_MID, 0, 70) |
| | | |
| | | dataCapacityInfoView.info = [ |
| | | { |
| | | title: "deviceInfoView.deviceTotalSpace", |
| | | type: 'label', |
| | | value: '5918 M', |
| | | }, |
| | | { |
| | | title: "deviceInfoView.deviceUsedSpace", |
| | | type: 'label', |
| | | value: '344 M', |
| | | }, |
| | | // { |
| | | // title: "deviceInfoView.deviceFreeSpace", |
| | | // type: 'label', |
| | | // value: '5574 M', |
| | | // }, |
| | | { |
| | | title: "deviceInfoView.deviceRemainingSpace", |
| | | type: 'label', |
| | | value: '3', |
| | | }, |
| | | { |
| | | title: "deviceInfoView.registeredPersonNum", |
| | | type: 'label', |
| | | value: '3', |
| | | }, |
| | | { |
| | | title: "deviceInfoView.localFaceWhiteListNum", |
| | | type: 'label', |
| | | value: '3', |
| | | }, |
| | | { |
| | | title: "deviceInfoView.localPasswordWhiteListNum", |
| | | type: 'label', |
| | | value: '3', |
| | | }, |
| | | { |
| | | title: "deviceInfoView.localSwipeCardWhiteListNum", |
| | | type: 'label', |
| | | value: '3', |
| | | }, |
| | | { |
| | | title: "deviceInfoView.passLogTotalNum", |
| | | type: 'label', |
| | | value: '3', |
| | | } |
| | | ] |
| | | |
| | | const dataCapacityInfoBox = dxui.View.build('dataCapacityInfoBox', screenMain) |
| | | viewUtils._clearStyle(dataCapacityInfoBox) |
| | | dataCapacityInfoBox.align(dxui.Utils.ALIGN.TOP_MID, 0, 140) |
| | | dataCapacityInfoBox.setSize(screen.screenSize.width, 700) |
| | | dataCapacityInfoBox.bgOpa(0) |
| | | dataCapacityInfoBox.flexFlow(dxui.Utils.FLEX_FLOW.ROW_WRAP) |
| | | dataCapacityInfoBox.flexAlign(dxui.Utils.FLEX_ALIGN.CENTER, dxui.Utils.FLEX_ALIGN.START, dxui.Utils.FLEX_ALIGN.START) |
| | | dataCapacityInfoBox.obj.lvObjSetStylePadGap(0, dxui.Utils.ENUM._LV_STYLE_STATE_CMP_SAME) |
| | | dataCapacityInfoBox.borderWidth(1) |
| | | dataCapacityInfoBox.setBorderColor(0xDEDEDE) |
| | | dataCapacityInfoBox.obj.setStyleBorderSide(dxui.Utils.ENUM.LV_BORDER_SIDE_TOP, 0) |
| | | |
| | | dataCapacityInfoView.info.forEach(item => { |
| | | const itemBox = dxui.View.build(item.title, dataCapacityInfoBox) |
| | | viewUtils._clearStyle(itemBox) |
| | | itemBox.setSize(760, 76) |
| | | itemBox.borderWidth(1) |
| | | itemBox.setBorderColor(0xDEDEDE) |
| | | itemBox.obj.setStyleBorderSide(dxui.Utils.ENUM.LV_BORDER_SIDE_BOTTOM, 0) |
| | | |
| | | const itemLabel = dxui.Label.build(item.title + 'Label', itemBox) |
| | | itemLabel.dataI18n = item.title |
| | | itemLabel.align(dxui.Utils.ALIGN.LEFT_MID, 0, 0) |
| | | itemLabel.textFont(viewUtils.font(26)) |
| | | |
| | | switch (item.type) { |
| | | case 'label': |
| | | const label = dxui.Label.build(item.title + 'label', itemBox) |
| | | label.textFont(viewUtils.font(24)) |
| | | label.align(dxui.Utils.ALIGN.RIGHT_MID, 0, 0) |
| | | label.text(item.value) |
| | | label.textColor(0x767676) |
| | | item.label = label |
| | | break; |
| | | } |
| | | }) |
| | | } |
| | | |
| | | export default dataCapacityInfoView |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | import dxui from '../../../../../dxmodules/dxUi.js' |
| | | import viewUtils from "../../../viewUtils.js" |
| | | import topView from "../../../topView.js" |
| | | import deviceInfoView from '../deviceInfoView.js' |
| | | import i18n from "../../../i18n.js" |
| | | import screen from '../../../../screen.js' |
| | | const systemInfoView = {} |
| | | systemInfoView.init = function () { |
| | | /**************************************************å建å±å¹*****************************************************/ |
| | | const screenMain = dxui.View.build('systemInfoView', dxui.Utils.LAYER.MAIN) |
| | | systemInfoView.screenMain = screenMain |
| | | screenMain.scroll(false) |
| | | screenMain.bgColor(0xffffff) |
| | | screenMain.on(dxui.Utils.ENUM.LV_EVENT_SCREEN_LOADED, () => { |
| | | topView.changeTheme(true) |
| | | const config = screen.getConfig() |
| | | systemInfoView.info[0].label.text(config["sys.sn"]) |
| | | systemInfoView.info[1].label.text(config["sys.appVersion"]) |
| | | systemInfoView.info[2].label.text(config["sys.releaseTime"]) |
| | | }) |
| | | |
| | | const titleBox = viewUtils.title(screenMain, deviceInfoView.screenMain, 'systemInfoViewTitle', 'deviceInfoView.systemInfo') |
| | | titleBox.align(dxui.Utils.ALIGN.TOP_MID, 0, 70) |
| | | |
| | | systemInfoView.info = [ |
| | | { |
| | | title: "deviceInfoView.deviceSN", |
| | | type: 'label', |
| | | value: 'G2440288881', |
| | | }, |
| | | { |
| | | title: "deviceInfoView.firmwareVersion", |
| | | type: 'label', |
| | | value: 'VF203-v1.1.36.3a885-240611', |
| | | }, |
| | | { |
| | | title: "deviceInfoView.firmwareReleaseDate", |
| | | type: 'label', |
| | | value: '2024-06-11 18:00:00', |
| | | }, |
| | | ] |
| | | |
| | | const settingInfoBox = dxui.View.build('settingInfoBox', screenMain) |
| | | viewUtils._clearStyle(settingInfoBox) |
| | | settingInfoBox.align(dxui.Utils.ALIGN.TOP_MID, 0, 140) |
| | | settingInfoBox.setSize(screen.screenSize.width, 700) |
| | | settingInfoBox.bgOpa(0) |
| | | settingInfoBox.flexFlow(dxui.Utils.FLEX_FLOW.ROW_WRAP) |
| | | settingInfoBox.flexAlign(dxui.Utils.FLEX_ALIGN.CENTER, dxui.Utils.FLEX_ALIGN.START, dxui.Utils.FLEX_ALIGN.START) |
| | | settingInfoBox.obj.lvObjSetStylePadGap(0, dxui.Utils.ENUM._LV_STYLE_STATE_CMP_SAME) |
| | | settingInfoBox.borderWidth(1) |
| | | settingInfoBox.setBorderColor(0xDEDEDE) |
| | | settingInfoBox.obj.setStyleBorderSide(dxui.Utils.ENUM.LV_BORDER_SIDE_TOP, 0) |
| | | |
| | | systemInfoView.info.forEach(item => { |
| | | const itemBox = dxui.View.build(item.title, settingInfoBox) |
| | | viewUtils._clearStyle(itemBox) |
| | | itemBox.setSize(760, 76) |
| | | itemBox.borderWidth(1) |
| | | itemBox.setBorderColor(0xDEDEDE) |
| | | itemBox.obj.setStyleBorderSide(dxui.Utils.ENUM.LV_BORDER_SIDE_BOTTOM, 0) |
| | | |
| | | const itemLabel = dxui.Label.build(item.title + 'Label', itemBox) |
| | | itemLabel.dataI18n = item.title |
| | | itemLabel.align(dxui.Utils.ALIGN.LEFT_MID, 0, 0) |
| | | itemLabel.textFont(viewUtils.font(26)) |
| | | |
| | | switch (item.type) { |
| | | case 'label': |
| | | const label = dxui.Label.build(item.title + 'label', itemBox) |
| | | label.textFont(viewUtils.font(24)) |
| | | label.align(dxui.Utils.ALIGN.RIGHT_MID, 0, 0) |
| | | label.text(item.value) |
| | | label.textColor(0x767676) |
| | | item.label = label |
| | | break; |
| | | } |
| | | }) |
| | | |
| | | const currentVersion = dxui.Label.build('deviceInfoView.currentVersion', screenMain) |
| | | currentVersion.align(dxui.Utils.ALIGN.BOTTOM_MID, 0, -213) |
| | | currentVersion.textFont(viewUtils.font(22)) |
| | | currentVersion.textColor(0x888888) |
| | | currentVersion.dataI18n = 'deviceInfoView.currentVersion' |
| | | currentVersion.textAlign(dxui.Utils.TEXT_ALIGN.CENTER, 0, 0) |
| | | currentVersion.hide() |
| | | |
| | | const saveBtn = viewUtils.bottomBtn(screenMain, screenMain.id + 'saveBtn', 'deviceInfoView.updateDevice', () => { |
| | | }) |
| | | saveBtn.align(dxui.Utils.ALIGN.BOTTOM_MID, 0, -83) |
| | | saveBtn.hide() |
| | | } |
| | | |
| | | export default systemInfoView |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | import dxui from '../../../../dxmodules/dxUi.js' |
| | | import viewUtils from "../../viewUtils.js" |
| | | import topView from "../../topView.js" |
| | | import configView from '../configView.js' |
| | | import systemInfoView from './deviceInfo/systemInfoView.js' |
| | | import dataCapacityInfoView from './deviceInfo/dataCapacityInfoView.js' |
| | | import i18n from "../../i18n.js" |
| | | import screen from '../../../screen.js' |
| | | |
| | | const deviceInfoView = {} |
| | | deviceInfoView.init = function () { |
| | | /**************************************************å建å±å¹*****************************************************/ |
| | | const screenMain = dxui.View.build('deviceInfoView', dxui.Utils.LAYER.MAIN) |
| | | deviceInfoView.screenMain = screenMain |
| | | screenMain.scroll(false) |
| | | screenMain.bgColor(0xffffff) |
| | | screenMain.on(dxui.Utils.ENUM.LV_EVENT_SCREEN_LOADED, () => { |
| | | topView.changeTheme(true) |
| | | let config = screen.getConfig() |
| | | dxui.Utils.GG.NativeBasicComponent.lvQrcodeUpdate(deviceInfoView.sysInfo[2].qrcodeObj, config["sys.sn"]) |
| | | }) |
| | | |
| | | const titleBox = viewUtils.title(screenMain, configView.screenMain, 'deviceInfoViewTitle', 'deviceInfoView.title') |
| | | titleBox.align(dxui.Utils.ALIGN.TOP_MID, 0, 70) |
| | | |
| | | deviceInfoView.sysInfo = [ |
| | | { |
| | | title: 'deviceInfoView.systemInfo', |
| | | type: 'menu', |
| | | view: systemInfoView, |
| | | obj: null, |
| | | }, |
| | | { |
| | | title: 'deviceInfoView.dataCapacityInfo', |
| | | type: 'menu', |
| | | view: dataCapacityInfoView, |
| | | obj: null, |
| | | }, |
| | | { |
| | | title: 'deviceInfoView.deviceQrCode', |
| | | value: '123', |
| | | type: 'qrcode', |
| | | obj: null, |
| | | }, |
| | | ] |
| | | |
| | | |
| | | const deviceInfoBox = dxui.View.build('deviceInfoBox', screenMain) |
| | | viewUtils._clearStyle(deviceInfoBox) |
| | | deviceInfoBox.setSize(screen.screenSize.width, screen.screenSize.height - 140) |
| | | deviceInfoBox.align(dxui.Utils.ALIGN.TOP_MID, 0, 140) |
| | | deviceInfoBox.bgColor(0xf7f7f7) |
| | | deviceInfoBox.flexFlow(dxui.Utils.FLEX_FLOW.ROW_WRAP) |
| | | deviceInfoBox.flexAlign(dxui.Utils.FLEX_ALIGN.CENTER, dxui.Utils.FLEX_ALIGN.START, dxui.Utils.FLEX_ALIGN.START) |
| | | deviceInfoBox.obj.lvObjSetStylePadGap(10, dxui.Utils.ENUM._LV_STYLE_STATE_CMP_SAME) |
| | | deviceInfoBox.padTop(10) |
| | | deviceInfoBox.padBottom(10) |
| | | |
| | | deviceInfoView.sysInfo.forEach(item => { |
| | | item.obj = dxui.View.build(item.title, deviceInfoBox) |
| | | viewUtils._clearStyle(item.obj) |
| | | item.obj.setSize(760, 76) |
| | | item.obj.bgColor(0xffffff) |
| | | item.obj.radius(10) |
| | | item.obj.on(dxui.Utils.ENUM.LV_EVENT_PRESSED, () => { |
| | | item.obj.bgColor(0xEAEAEA) |
| | | }) |
| | | item.obj.on(dxui.Utils.ENUM.LV_EVENT_RELEASED, () => { |
| | | item.obj.bgColor(0xffffff) |
| | | }) |
| | | |
| | | const titleLbl = dxui.Label.build(item.title + 'Label', item.obj) |
| | | titleLbl.dataI18n = item.title |
| | | titleLbl.align(dxui.Utils.ALIGN.LEFT_MID, 20, 0) |
| | | titleLbl.textFont(viewUtils.font(26)) |
| | | |
| | | switch (item.type) { |
| | | case 'menu': |
| | | const image = dxui.Image.build(item.title + 'Image', item.obj) |
| | | image.align(dxui.Utils.ALIGN.RIGHT_MID, -15, 0) |
| | | image.source('/app/code/resource/image/right.png') |
| | | item.obj.on(dxui.Utils.EVENT.CLICK, () => { |
| | | dxui.loadMain(item.view.screenMain) |
| | | }) |
| | | break |
| | | case 'qrcode': |
| | | item.obj.height(350) |
| | | if (item.title == "deviceInfoView.miniProgramCode") { |
| | | const qrcodeImage = dxui.Image.build(item.title + 'qrcodeImage', item.obj) |
| | | deviceInfoView.qrcodeImage = qrcodeImage |
| | | qrcodeImage.source('/app/code/resource/image/app_qrcode.png') |
| | | qrcodeImage.obj.lvImgSetZoom(256 * 0.6) |
| | | qrcodeImage.obj.lvImgSetSizeMode(dxui.Utils.ENUM.LV_IMG_SIZE_MODE_REAL) |
| | | qrcodeImage.align(dxui.Utils.ALIGN.RIGHT_MID, -20, 0) |
| | | } else { |
| | | const qrcodeBox = dxui.View.build(item.title + 'QrCode', item.obj) |
| | | viewUtils._clearStyle(qrcodeBox) |
| | | qrcodeBox.setSize(220, 220) |
| | | qrcodeBox.align(dxui.Utils.ALIGN.RIGHT_MID, -20, 0) |
| | | const qrcodeObj = dxui.Utils.GG.NativeBasicComponent.lvQrcodeCreate(qrcodeBox.obj, 220, 0x000000, 0xffffff) |
| | | dxui.Utils.GG.NativeBasicComponent.lvQrcodeUpdate(qrcodeObj, item.value) |
| | | item.qrcodeObj = qrcodeObj |
| | | } |
| | | break |
| | | } |
| | | }) |
| | | |
| | | } |
| | | |
| | | export default deviceInfoView |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | import dxui from '../../../../dxmodules/dxUi.js' |
| | | import std from '../../../../dxmodules/dxStd.js' |
| | | import viewUtils from '../../viewUtils.js' |
| | | import topView from '../../topView.js' |
| | | import configView from '../configView.js' |
| | | import i18n from '../../i18n.js' |
| | | import screen from '../../../screen.js' |
| | | const dockingSettingView = {} |
| | | dockingSettingView.init = function () { |
| | | /**************************************************å建å±å¹*****************************************************/ |
| | | const screenMain = dxui.View.build('dockingSettingView', dxui.Utils.LAYER.MAIN) |
| | | dockingSettingView.screenMain = screenMain |
| | | screenMain.scroll(false) |
| | | screenMain.bgColor(0xffffff) |
| | | screenMain.on(dxui.Utils.ENUM.LV_EVENT_SCREEN_LOADED, () => { |
| | | topView.changeTheme(true) |
| | | |
| | | const configAll = screen.getConfig() |
| | | httpGasSettingInput.text(configAll['http.gas'] || '') |
| | | httpStatusSettingInput.text(configAll['http.status'] || '') |
| | | gasUpdateTimeSettingInput.text((configAll['update.gasTime'] || 5) + '') |
| | | statusUpdateTimeSettingInput.text((configAll['update.statusTime'] || 5) + '') |
| | | }) |
| | | |
| | | const titleBox = viewUtils.title(screenMain, configView.screenMain, 'dockingSettingViewTitle', 'dockingSettingView.title') |
| | | titleBox.align(dxui.Utils.ALIGN.TOP_MID, 0, 70) |
| | | |
| | | const httpGasSettingBox = dxui.View.build('httpGasSettingBox', screenMain) |
| | | viewUtils._clearStyle(httpGasSettingBox) |
| | | httpGasSettingBox.align(dxui.Utils.ALIGN.TOP_MID, 0, 140) |
| | | httpGasSettingBox.setSize(750, 76) |
| | | httpGasSettingBox.borderWidth(1) |
| | | httpGasSettingBox.setBorderColor(0xDEDEDE) |
| | | httpGasSettingBox.obj.setStyleBorderSide(dxui.Utils.ENUM.LV_BORDER_SIDE_BOTTOM, 0) |
| | | |
| | | const httpGasSettingLbl = dxui.Label.build('httpGasSettingLbl', httpGasSettingBox) |
| | | httpGasSettingLbl.text('HTTP_æ°ä½') |
| | | httpGasSettingLbl.align(dxui.Utils.ALIGN.LEFT_MID, 0, 0) |
| | | httpGasSettingLbl.textFont(viewUtils.font(26)) |
| | | |
| | | const httpGasSettingInput = viewUtils.input(httpGasSettingBox, 'httpGasSettingInput', undefined, undefined, 'dockingSettingView.input') |
| | | httpGasSettingInput.align(dxui.Utils.ALIGN.RIGHT_MID, 0, 0) |
| | | httpGasSettingInput.setSize(320, 60) |
| | | |
| | | const httpStatusSettingBox = dxui.View.build('httpStatusSettingBox', screenMain) |
| | | viewUtils._clearStyle(httpStatusSettingBox) |
| | | httpStatusSettingBox.align(dxui.Utils.ALIGN.TOP_MID, 0, 216) |
| | | httpStatusSettingBox.setSize(750, 76) |
| | | httpStatusSettingBox.borderWidth(1) |
| | | httpStatusSettingBox.setBorderColor(0xDEDEDE) |
| | | httpStatusSettingBox.obj.setStyleBorderSide(dxui.Utils.ENUM.LV_BORDER_SIDE_BOTTOM, 0) |
| | | |
| | | const httpStatusSettingLbl = dxui.Label.build('httpStatusSettingLbl', httpStatusSettingBox) |
| | | httpStatusSettingLbl.text('HTTP_ç¶æ') |
| | | httpStatusSettingLbl.align(dxui.Utils.ALIGN.LEFT_MID, 0, 0) |
| | | httpStatusSettingLbl.textFont(viewUtils.font(26)) |
| | | |
| | | const httpStatusSettingInput = viewUtils.input(httpStatusSettingBox, 'httpStatusSettingInput', undefined, undefined, 'dockingSettingView.input') |
| | | httpStatusSettingInput.align(dxui.Utils.ALIGN.RIGHT_MID, 0, 0) |
| | | httpStatusSettingInput.setSize(320, 60) |
| | | |
| | | // æ°ä½æµåº¦æ´æ°æ¶é´è®¾ç½® |
| | | const gasUpdateTimeSettingBox = dxui.View.build('gasUpdateTimeSettingBox', screenMain) |
| | | viewUtils._clearStyle(gasUpdateTimeSettingBox) |
| | | gasUpdateTimeSettingBox.align(dxui.Utils.ALIGN.TOP_MID, 0, 292) |
| | | gasUpdateTimeSettingBox.setSize(750, 76) |
| | | gasUpdateTimeSettingBox.borderWidth(1) |
| | | gasUpdateTimeSettingBox.setBorderColor(0xDEDEDE) |
| | | gasUpdateTimeSettingBox.obj.setStyleBorderSide(dxui.Utils.ENUM.LV_BORDER_SIDE_BOTTOM, 0) |
| | | |
| | | const gasUpdateTimeSettingLbl = dxui.Label.build('gasUpdateTimeSettingLbl', gasUpdateTimeSettingBox) |
| | | gasUpdateTimeSettingLbl.text('æ°ä½æµåº¦æ´æ°æ¶é´') |
| | | gasUpdateTimeSettingLbl.align(dxui.Utils.ALIGN.LEFT_MID, 0, 0) |
| | | gasUpdateTimeSettingLbl.textFont(viewUtils.font(26)) |
| | | |
| | | const gasUpdateTimeSettingUnitLbl = dxui.Label.build('gasUpdateTimeSettingUnitLbl', gasUpdateTimeSettingBox) |
| | | gasUpdateTimeSettingUnitLbl.text('ç§') |
| | | gasUpdateTimeSettingUnitLbl.align(dxui.Utils.ALIGN.RIGHT_MID, 0, 0) |
| | | gasUpdateTimeSettingUnitLbl.textFont(viewUtils.font(26)) |
| | | |
| | | const gasUpdateTimeSettingInput = viewUtils.input(gasUpdateTimeSettingBox, 'gasUpdateTimeSettingInput', 2, undefined, 'dockingSettingView.input') |
| | | gasUpdateTimeSettingInput.align(dxui.Utils.ALIGN.RIGHT_MID, -45, 0) |
| | | gasUpdateTimeSettingInput.setSize(150, 60) |
| | | |
| | | // ç¶æä¿¡æ¯æ´æ°æ¶é´è®¾ç½® |
| | | const statusUpdateTimeSettingBox = dxui.View.build('statusUpdateTimeSettingBox', screenMain) |
| | | viewUtils._clearStyle(statusUpdateTimeSettingBox) |
| | | statusUpdateTimeSettingBox.align(dxui.Utils.ALIGN.TOP_MID, 0, 368) |
| | | statusUpdateTimeSettingBox.setSize(750, 76) |
| | | statusUpdateTimeSettingBox.borderWidth(1) |
| | | statusUpdateTimeSettingBox.setBorderColor(0xDEDEDE) |
| | | statusUpdateTimeSettingBox.obj.setStyleBorderSide(dxui.Utils.ENUM.LV_BORDER_SIDE_BOTTOM, 0) |
| | | |
| | | const statusUpdateTimeSettingLbl = dxui.Label.build('statusUpdateTimeSettingLbl', statusUpdateTimeSettingBox) |
| | | statusUpdateTimeSettingLbl.text('ç¶æä¿¡æ¯æ´æ°æ¶é´') |
| | | statusUpdateTimeSettingLbl.align(dxui.Utils.ALIGN.LEFT_MID, 0, 0) |
| | | statusUpdateTimeSettingLbl.textFont(viewUtils.font(26)) |
| | | |
| | | const statusUpdateTimeSettingUnitLbl = dxui.Label.build('statusUpdateTimeSettingUnitLbl', statusUpdateTimeSettingBox) |
| | | statusUpdateTimeSettingUnitLbl.text('ç§') |
| | | statusUpdateTimeSettingUnitLbl.align(dxui.Utils.ALIGN.RIGHT_MID, 0, 0) |
| | | statusUpdateTimeSettingUnitLbl.textFont(viewUtils.font(26)) |
| | | |
| | | const statusUpdateTimeSettingInput = viewUtils.input(statusUpdateTimeSettingBox, 'statusUpdateTimeSettingInput', 2, undefined, 'dockingSettingView.input') |
| | | statusUpdateTimeSettingInput.align(dxui.Utils.ALIGN.RIGHT_MID, -45, 0) |
| | | statusUpdateTimeSettingInput.setSize(150, 60) |
| | | |
| | | const saveBtn = viewUtils.bottomBtn(screenMain, screenMain.id + 'saveBtn', 'dockingSettingView.save', () => { |
| | | const saveConfigData = { |
| | | http: { |
| | | gas: httpGasSettingInput.text(), |
| | | status: httpStatusSettingInput.text() |
| | | }, |
| | | update: { |
| | | gasTime: parseInt(gasUpdateTimeSettingInput.text()) || 5, |
| | | statusTime: parseInt(statusUpdateTimeSettingInput.text()) || 5 |
| | | } |
| | | } |
| | | const res = screen.saveConfig(saveConfigData) |
| | | if (res === true) { |
| | | dockingSettingView.statusPanel.success() |
| | | std.setTimeout(() => { |
| | | // æåè¿åä¸ä¸å±çé¢ |
| | | dxui.loadMain(configView.screenMain) |
| | | }, 500) |
| | | } else { |
| | | dockingSettingView.statusPanel.fail() |
| | | } |
| | | }) |
| | | saveBtn.align(dxui.Utils.ALIGN.BOTTOM_MID, 0, -83) |
| | | |
| | | dockingSettingView.statusPanel = viewUtils.statusPanel(screenMain, 'dockingSettingView.success', 'dockingSettingView.fail') |
| | | } |
| | | |
| | | export default dockingSettingView |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | import dxui from '../../../../dxmodules/dxUi.js' |
| | | import std from '../../../../dxmodules/dxStd.js' |
| | | import viewUtils from "../../viewUtils.js" |
| | | import topView from "../../topView.js" |
| | | import configView from '../configView.js' |
| | | import i18n from "../../i18n.js" |
| | | import screen from '../../../screen.js' |
| | | import bus from '../../../../dxmodules/dxEventBus.js' |
| | | const doorControlView = {} |
| | | doorControlView.init = function () { |
| | | /**************************************************å建å±å¹*****************************************************/ |
| | | const screenMain = dxui.View.build('doorControlView', dxui.Utils.LAYER.MAIN) |
| | | doorControlView.screenMain = screenMain |
| | | screenMain.scroll(false) |
| | | screenMain.bgColor(0xffffff) |
| | | screenMain.on(dxui.Utils.ENUM.LV_EVENT_SCREEN_LOADED, () => { |
| | | topView.changeTheme(true) |
| | | |
| | | const configAll = screen.getConfig() |
| | | delaySettingInput.text(configAll['access.relayTime'] + '') |
| | | alarmSettingSwitch.select(configAll['access.tamperAlarm'] == 1) |
| | | mqttSettingInput.text(configAll['mqtt.addr']) |
| | | mqttUserSettingInput.text(configAll['mqtt.username']) |
| | | mqttPwdSettingInput.text(configAll['mqtt.password']) |
| | | onlineCheckingSettingSwitch.select(configAll['mqtt.onlinecheck'] == 1) |
| | | onlineCheckingTimeoutSettingInput.text(configAll['mqtt.timeout'] + '') |
| | | GranarySettingInput.text(configAll['GranaryName'] || 'ä¸å¤®å¨å¤ç²®ææç´å±åº') |
| | | houseNameSettingInput.text(configAll['houseName'] || '01å·ä»') |
| | | doorHttpGasSettingInput.text(configAll['http.safeInputAccess'] || "http://192.168.1.199:80/cgi-bin/safeInputAccess") |
| | | }) |
| | | |
| | | const titleBox = viewUtils.title(screenMain, configView.screenMain, 'doorControlViewTitle', 'doorControlView.title') |
| | | titleBox.align(dxui.Utils.ALIGN.TOP_MID, 0, 70) |
| | | |
| | | const delaySettingBox = dxui.View.build('delaySettingBox', screenMain) |
| | | viewUtils._clearStyle(delaySettingBox) |
| | | delaySettingBox.align(dxui.Utils.ALIGN.TOP_MID, 0, 140) |
| | | delaySettingBox.setSize(750, 76) |
| | | delaySettingBox.borderWidth(1) |
| | | delaySettingBox.setBorderColor(0xDEDEDE) |
| | | delaySettingBox.obj.setStyleBorderSide(dxui.Utils.ENUM.LV_BORDER_SIDE_BOTTOM, 0) |
| | | |
| | | const delaySettingLbl = dxui.Label.build('delaySettingLbl', delaySettingBox) |
| | | delaySettingLbl.dataI18n = 'doorControlView.openDoorRelayDelay' |
| | | delaySettingLbl.align(dxui.Utils.ALIGN.LEFT_MID, 0, 0) |
| | | delaySettingLbl.textFont(viewUtils.font(26)) |
| | | |
| | | const delaySettingUnitLbl = dxui.Label.build('delaySettingUnitLbl', delaySettingBox) |
| | | delaySettingUnitLbl.dataI18n = "doorControlView.ms" |
| | | delaySettingUnitLbl.align(dxui.Utils.ALIGN.RIGHT_MID, 0, 0) |
| | | delaySettingUnitLbl.textFont(viewUtils.font(26)) |
| | | |
| | | const delaySettingInput = viewUtils.input(delaySettingBox, 'delaySettingInput', 2, undefined, 'doorControlView.input') |
| | | delaySettingInput.align(dxui.Utils.ALIGN.RIGHT_MID, -60, 0) |
| | | delaySettingInput.setSize(150, 60) |
| | | |
| | | const alarmSettingBox = dxui.View.build('alarmSettingBox', screenMain) |
| | | viewUtils._clearStyle(alarmSettingBox) |
| | | alarmSettingBox.align(dxui.Utils.ALIGN.TOP_MID, 0, 216) |
| | | alarmSettingBox.setSize(750, 76) |
| | | alarmSettingBox.borderWidth(1) |
| | | alarmSettingBox.setBorderColor(0xDEDEDE) |
| | | alarmSettingBox.obj.setStyleBorderSide(dxui.Utils.ENUM.LV_BORDER_SIDE_BOTTOM, 0) |
| | | |
| | | const alarmSettingLbl = dxui.Label.build('alarmSettingLbl', alarmSettingBox) |
| | | alarmSettingLbl.dataI18n = 'doorControlView.antiTamperAlarm' |
| | | alarmSettingLbl.align(dxui.Utils.ALIGN.LEFT_MID, 0, 0) |
| | | alarmSettingLbl.textFont(viewUtils.font(26)) |
| | | |
| | | const alarmSettingSwitch = dxui.Switch.build('alarmSettingSwitch', alarmSettingBox) |
| | | alarmSettingSwitch.align(dxui.Utils.ALIGN.RIGHT_MID, 0, 0) |
| | | alarmSettingSwitch.setSize(70, 35) |
| | | |
| | | |
| | | const mqttSettingBox = dxui.View.build('mqttSettingBox', screenMain) |
| | | viewUtils._clearStyle(mqttSettingBox) |
| | | mqttSettingBox.align(dxui.Utils.ALIGN.TOP_MID, 0, 292) |
| | | mqttSettingBox.setSize(750, 76) |
| | | mqttSettingBox.borderWidth(1) |
| | | mqttSettingBox.setBorderColor(0xDEDEDE) |
| | | mqttSettingBox.obj.setStyleBorderSide(dxui.Utils.ENUM.LV_BORDER_SIDE_BOTTOM, 0) |
| | | |
| | | const mqttSettingLbl = dxui.Label.build('mqttSettingLbl', mqttSettingBox) |
| | | mqttSettingLbl.dataI18n = 'doorControlView.mqttAddr' |
| | | mqttSettingLbl.align(dxui.Utils.ALIGN.LEFT_MID, 0, 0) |
| | | mqttSettingLbl.textFont(viewUtils.font(26)) |
| | | |
| | | const mqttSettingInput = viewUtils.input(mqttSettingBox, 'mqttSettingInput', undefined, undefined, 'doorControlView.input') |
| | | mqttSettingInput.align(dxui.Utils.ALIGN.RIGHT_MID, 0, 0) |
| | | mqttSettingInput.setSize(320, 60) |
| | | |
| | | const mqttUserSettingBox = dxui.View.build('mqttUserSettingBox', screenMain) |
| | | viewUtils._clearStyle(mqttUserSettingBox) |
| | | mqttUserSettingBox.align(dxui.Utils.ALIGN.TOP_MID, 0, 368) |
| | | mqttUserSettingBox.setSize(750, 76) |
| | | mqttUserSettingBox.borderWidth(1) |
| | | mqttUserSettingBox.setBorderColor(0xDEDEDE) |
| | | mqttUserSettingBox.obj.setStyleBorderSide(dxui.Utils.ENUM.LV_BORDER_SIDE_BOTTOM, 0) |
| | | |
| | | const mqttUserSettingLbl = dxui.Label.build('mqttUserSettingLbl', mqttUserSettingBox) |
| | | mqttUserSettingLbl.dataI18n = 'doorControlView.mqttUser' |
| | | mqttUserSettingLbl.align(dxui.Utils.ALIGN.LEFT_MID, 0, 0) |
| | | mqttUserSettingLbl.textFont(viewUtils.font(26)) |
| | | |
| | | const mqttUserSettingInput = viewUtils.input(mqttUserSettingBox, 'mqttUserSettingInput', undefined, undefined, 'doorControlView.input') |
| | | mqttUserSettingInput.align(dxui.Utils.ALIGN.RIGHT_MID, 0, 0) |
| | | mqttUserSettingInput.setSize(320, 60) |
| | | |
| | | const mqttPwdSettingBox = dxui.View.build('mqttPwdSettingBox', screenMain) |
| | | viewUtils._clearStyle(mqttPwdSettingBox) |
| | | mqttPwdSettingBox.align(dxui.Utils.ALIGN.TOP_MID, 0, 444) |
| | | mqttPwdSettingBox.setSize(750, 76) |
| | | mqttPwdSettingBox.borderWidth(1) |
| | | mqttPwdSettingBox.setBorderColor(0xDEDEDE) |
| | | mqttPwdSettingBox.obj.setStyleBorderSide(dxui.Utils.ENUM.LV_BORDER_SIDE_BOTTOM, 0) |
| | | |
| | | const mqttPwdSettingLbl = dxui.Label.build('mqttPwdSettingLbl', mqttPwdSettingBox) |
| | | mqttPwdSettingLbl.dataI18n = 'doorControlView.mqttPwd' |
| | | mqttPwdSettingLbl.align(dxui.Utils.ALIGN.LEFT_MID, 0, 0) |
| | | mqttPwdSettingLbl.textFont(viewUtils.font(26)) |
| | | |
| | | const mqttPwdSettingInput = viewUtils.input(mqttPwdSettingBox, 'mqttPwdSettingInput', undefined, undefined, 'doorControlView.input') |
| | | mqttPwdSettingInput.align(dxui.Utils.ALIGN.RIGHT_MID, 0, 0) |
| | | mqttPwdSettingInput.setSize(320, 60) |
| | | |
| | | |
| | | const onlineCheckingSettingBox = dxui.View.build('onlineCheckingSettingBox', screenMain) |
| | | viewUtils._clearStyle(onlineCheckingSettingBox) |
| | | onlineCheckingSettingBox.align(dxui.Utils.ALIGN.TOP_MID, 0, 540) |
| | | onlineCheckingSettingBox.setSize(750, 76) |
| | | onlineCheckingSettingBox.borderWidth(1) |
| | | onlineCheckingSettingBox.setBorderColor(0xDEDEDE) |
| | | onlineCheckingSettingBox.obj.setStyleBorderSide(dxui.Utils.ENUM.LV_BORDER_SIDE_BOTTOM, 0) |
| | | |
| | | const onlineCheckingSettingLbl = dxui.Label.build('onlineCheckingSettingLbl', onlineCheckingSettingBox) |
| | | onlineCheckingSettingLbl.dataI18n = 'doorControlView.onlineChecking' |
| | | onlineCheckingSettingLbl.align(dxui.Utils.ALIGN.LEFT_MID, 0, 0) |
| | | onlineCheckingSettingLbl.textFont(viewUtils.font(26)) |
| | | |
| | | const onlineCheckingSettingSwitch = dxui.Switch.build('onlineCheckingSettingSwitch', onlineCheckingSettingBox) |
| | | onlineCheckingSettingSwitch.align(dxui.Utils.ALIGN.RIGHT_MID, 0, 0) |
| | | onlineCheckingSettingSwitch.setSize(70, 35) |
| | | |
| | | const onlineCheckingTimeoutSettingBox = dxui.View.build('onlineCheckingTimeoutSettingBox', screenMain) |
| | | viewUtils._clearStyle(onlineCheckingTimeoutSettingBox) |
| | | onlineCheckingTimeoutSettingBox.align(dxui.Utils.ALIGN.TOP_MID, 0, 616) |
| | | onlineCheckingTimeoutSettingBox.setSize(750, 76) |
| | | onlineCheckingTimeoutSettingBox.borderWidth(1) |
| | | onlineCheckingTimeoutSettingBox.setBorderColor(0xDEDEDE) |
| | | onlineCheckingTimeoutSettingBox.obj.setStyleBorderSide(dxui.Utils.ENUM.LV_BORDER_SIDE_BOTTOM, 0) |
| | | |
| | | const onlineCheckingTimeoutSettingLbl = dxui.Label.build('onlineCheckingTimeoutSettingLbl', onlineCheckingTimeoutSettingBox) |
| | | onlineCheckingTimeoutSettingLbl.dataI18n = 'doorControlView.onlineCheckingTimeout' |
| | | onlineCheckingTimeoutSettingLbl.align(dxui.Utils.ALIGN.LEFT_MID, 0, 0) |
| | | onlineCheckingTimeoutSettingLbl.textFont(viewUtils.font(26)) |
| | | |
| | | const onlineCheckingTimeoutSettingUnitLbl = dxui.Label.build('onlineCheckingTimeoutSettingUnitLbl', onlineCheckingTimeoutSettingBox) |
| | | onlineCheckingTimeoutSettingUnitLbl.text('ms') |
| | | onlineCheckingTimeoutSettingUnitLbl.align(dxui.Utils.ALIGN.RIGHT_MID, 0, 0) |
| | | onlineCheckingTimeoutSettingUnitLbl.textFont(viewUtils.font(26)) |
| | | |
| | | const onlineCheckingTimeoutSettingInput = viewUtils.input(onlineCheckingTimeoutSettingBox, 'onlineCheckingTimeoutSettingInput', 2, undefined, 'doorControlView.input') |
| | | onlineCheckingTimeoutSettingInput.align(dxui.Utils.ALIGN.RIGHT_MID, -45, 0) |
| | | onlineCheckingTimeoutSettingInput.setSize(150, 60) |
| | | |
| | | // HTTPæ¥å£è·¯å¾è®¾ç½® |
| | | // åºåºå称设置 |
| | | const GranarySettingBox = dxui.View.build('GranarySettingBox', screenMain) |
| | | viewUtils._clearStyle(GranarySettingBox) |
| | | GranarySettingBox.align(dxui.Utils.ALIGN.TOP_MID, 0, 692) |
| | | GranarySettingBox.setSize(750, 76) |
| | | GranarySettingBox.borderWidth(1) |
| | | GranarySettingBox.setBorderColor(0xDEDEDE) |
| | | GranarySettingBox.obj.setStyleBorderSide(dxui.Utils.ENUM.LV_BORDER_SIDE_BOTTOM, 0) |
| | | |
| | | const GranarySettingLbl = dxui.Label.build('GranarySettingLbl', GranarySettingBox) |
| | | GranarySettingLbl.text('åºåºåç§°') |
| | | GranarySettingLbl.align(dxui.Utils.ALIGN.LEFT_MID, 0, 0) |
| | | GranarySettingLbl.textFont(viewUtils.font(26)) |
| | | |
| | | const GranarySettingInput = viewUtils.input(GranarySettingBox, 'GranarySettingInput', undefined, undefined, 'doorControlView.input') |
| | | GranarySettingInput.align(dxui.Utils.ALIGN.RIGHT_MID, 0, 0) |
| | | GranarySettingInput.setSize(320, 60) |
| | | |
| | | // ä»å»å称设置 |
| | | const houseNameSettingBox = dxui.View.build('houseNameSettingBox', screenMain) |
| | | viewUtils._clearStyle(houseNameSettingBox) |
| | | houseNameSettingBox.align(dxui.Utils.ALIGN.TOP_MID, 0, 768) |
| | | houseNameSettingBox.setSize(750, 76) |
| | | houseNameSettingBox.borderWidth(1) |
| | | houseNameSettingBox.setBorderColor(0xDEDEDE) |
| | | houseNameSettingBox.obj.setStyleBorderSide(dxui.Utils.ENUM.LV_BORDER_SIDE_BOTTOM, 0) |
| | | |
| | | const houseNameSettingLbl = dxui.Label.build('houseNameSettingLbl', houseNameSettingBox) |
| | | houseNameSettingLbl.text('ä»å»åç§°') |
| | | houseNameSettingLbl.align(dxui.Utils.ALIGN.LEFT_MID, 0, 0) |
| | | houseNameSettingLbl.textFont(viewUtils.font(26)) |
| | | |
| | | const houseNameSettingInput = viewUtils.input(houseNameSettingBox, 'houseNameSettingInput', undefined, undefined, 'doorControlView.input') |
| | | houseNameSettingInput.align(dxui.Utils.ALIGN.RIGHT_MID, 0, 0) |
| | | houseNameSettingInput.setSize(320, 60) |
| | | |
| | | // HTTPæ¥å£è·¯å¾è®¾ç½® |
| | | const doorHttpGasSettingBox = dxui.View.build('doorHttpGasSettingBox', screenMain) |
| | | viewUtils._clearStyle(doorHttpGasSettingBox) |
| | | doorHttpGasSettingBox.align(dxui.Utils.ALIGN.TOP_MID, 0, 844) |
| | | doorHttpGasSettingBox.setSize(750, 76) |
| | | doorHttpGasSettingBox.borderWidth(1) |
| | | doorHttpGasSettingBox.setBorderColor(0xDEDEDE) |
| | | doorHttpGasSettingBox.obj.setStyleBorderSide(dxui.Utils.ENUM.LV_BORDER_SIDE_BOTTOM, 0) |
| | | |
| | | const doorHttpGasSettingLbl = dxui.Label.build('doorHttpGasSettingLbl', doorHttpGasSettingBox) |
| | | doorHttpGasSettingLbl.text('HTTPæ¥å£è·¯å¾') |
| | | doorHttpGasSettingLbl.align(dxui.Utils.ALIGN.LEFT_MID, 0, 0) |
| | | doorHttpGasSettingLbl.textFont(viewUtils.font(26)) |
| | | |
| | | const doorHttpGasSettingInput = viewUtils.input(doorHttpGasSettingBox, 'doorHttpGasSettingInput', undefined, undefined, 'doorControlView.input') |
| | | doorHttpGasSettingInput.align(dxui.Utils.ALIGN.RIGHT_MID, 0, 0) |
| | | doorHttpGasSettingInput.setSize(320, 60) |
| | | |
| | | const saveBtn = viewUtils.bottomBtn(screenMain, screenMain.id + 'saveBtn', 'doorControlView.save', () => { |
| | | const saveConfigData = { |
| | | access: { |
| | | relayTime: parseInt(delaySettingInput.text()), |
| | | tamperAlarm: alarmSettingSwitch.isSelect() ? 1 : 0 |
| | | }, |
| | | mqtt: { |
| | | addr: mqttSettingInput.text(), |
| | | username: mqttUserSettingInput.text(), |
| | | password: mqttPwdSettingInput.text(), |
| | | onlinecheck: onlineCheckingSettingSwitch.isSelect() ? 1 : 0, |
| | | timeout: parseInt(onlineCheckingTimeoutSettingInput.text()) |
| | | }, |
| | | GranaryName: GranarySettingInput.text(), |
| | | houseName: houseNameSettingInput.text(), |
| | | http: { |
| | | safeInputAccess: doorHttpGasSettingInput.text() |
| | | } |
| | | } |
| | | const res = screen.saveConfig(saveConfigData) |
| | | if (res === true) { |
| | | doorControlView.statusPanel.success() |
| | | // éç¥mainViewæ´æ°åºåºåç§°åä»å· |
| | | bus.fire('warehouseInfoUpdated') |
| | | std.setTimeout(() => { |
| | | // æåè¿åä¸ä¸å±çé¢ |
| | | dxui.loadMain(configView.screenMain) |
| | | }, 500) |
| | | } else { |
| | | doorControlView.statusPanel.fail() |
| | | } |
| | | }) |
| | | saveBtn.align(dxui.Utils.ALIGN.BOTTOM_MID, 0, -83) |
| | | |
| | | doorControlView.statusPanel = viewUtils.statusPanel(screenMain, 'doorControlView.success', 'doorControlView.fail') |
| | | } |
| | | |
| | | export default doorControlView |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | import dxui from "../../../../dxmodules/dxUi.js"; |
| | | import viewUtils from "../../viewUtils.js"; |
| | | import topView from "../../topView.js"; |
| | | import configView from "../configView.js"; |
| | | import i18n from "../../i18n.js"; |
| | | import screen from "../../../screen.js"; |
| | | const factoryTestView = {}; |
| | | factoryTestView.init = function () { |
| | | /**************************************************å建å±å¹*****************************************************/ |
| | | const screenMain = dxui.View.build("factoryTestView", dxui.Utils.LAYER.MAIN); |
| | | factoryTestView.screenMain = screenMain; |
| | | screenMain.scroll(false); |
| | | screenMain.bgColor(0xffffff); |
| | | screenMain.on(dxui.Utils.ENUM.LV_EVENT_SCREEN_LOADED, () => { |
| | | topView.changeTheme(true); |
| | | }); |
| | | |
| | | const titleBox = viewUtils.title( |
| | | screenMain, |
| | | configView.screenMain, |
| | | "factoryTestViewTitle", |
| | | "factoryTestView.title" |
| | | ); |
| | | titleBox.align(dxui.Utils.ALIGN.TOP_MID, 0, 70); |
| | | |
| | | const factoryTestBox = dxui.View.build("factoryTestBox", screenMain); |
| | | viewUtils._clearStyle(factoryTestBox); |
| | | factoryTestBox.setSize( |
| | | screen.screenSize.width, |
| | | screen.screenSize.height - 140 |
| | | ); |
| | | factoryTestBox.align(dxui.Utils.ALIGN.TOP_MID, 0, 140); |
| | | factoryTestBox.bgColor(0xf7f7f7); |
| | | factoryTestBox.flexFlow(dxui.Utils.FLEX_FLOW.ROW_WRAP); |
| | | factoryTestBox.flexAlign( |
| | | dxui.Utils.FLEX_ALIGN.CENTER, |
| | | dxui.Utils.FLEX_ALIGN.START, |
| | | dxui.Utils.FLEX_ALIGN.START |
| | | ); |
| | | factoryTestBox.obj.lvObjSetStylePadGap( |
| | | 10, |
| | | dxui.Utils.ENUM._LV_STYLE_STATE_CMP_SAME |
| | | ); |
| | | factoryTestBox.padTop(10); |
| | | factoryTestBox.padBottom(10); |
| | | |
| | | const calibrationBox = dxui.View.build("calibrationBox", factoryTestBox); |
| | | viewUtils._clearStyle(calibrationBox); |
| | | // calibrationBox.align(dxui.Utils.ALIGN.TOP_MID, 0, 150); |
| | | calibrationBox.setSize(560, 76); |
| | | // calibrationBox.bgColor(0xf7f7f7); |
| | | calibrationBox.bgColor(0xffffff); |
| | | calibrationBox.radius(10); |
| | | calibrationBox.on(dxui.Utils.ENUM.LV_EVENT_PRESSED, () => { |
| | | calibrationBox.bgColor(0xeaeaea); |
| | | }); |
| | | calibrationBox.on(dxui.Utils.ENUM.LV_EVENT_RELEASED, () => { |
| | | calibrationBox.bgColor(0xffffff); |
| | | }); |
| | | |
| | | const titleLbl = dxui.Label.build("calibrationBox" + "Label", calibrationBox); |
| | | titleLbl.dataI18n = "factoryTestView.calibration"; |
| | | titleLbl.align(dxui.Utils.ALIGN.LEFT_MID, 20, 0); |
| | | titleLbl.textFont(viewUtils.font(26)); |
| | | |
| | | const image = dxui.Image.build(calibrationBox.id + "Image", calibrationBox); |
| | | image.align(dxui.Utils.ALIGN.RIGHT_MID, -15, 0); |
| | | image.source("/app/code/resource/image/right.png"); |
| | | |
| | | calibrationBox.on(dxui.Utils.EVENT.CLICK, () => { |
| | | // dxui.loadMain(item.view.screenMain); |
| | | console.log(123); |
| | | |
| | | }); |
| | | }; |
| | | |
| | | export default factoryTestView; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | import dxui from '../../../../dxmodules/dxUi.js' |
| | | import viewUtils from "../../viewUtils.js" |
| | | import topView from "../../topView.js" |
| | | import configView from '../configView.js' |
| | | import i18n from "../../i18n.js" |
| | | const helpView = {} |
| | | helpView.init = function () { |
| | | /**************************************************å建å±å¹*****************************************************/ |
| | | const screenMain = dxui.View.build('helpView', dxui.Utils.LAYER.MAIN) |
| | | helpView.screenMain = screenMain |
| | | screenMain.scroll(false) |
| | | screenMain.bgColor(0xffffff) |
| | | screenMain.on(dxui.Utils.ENUM.LV_EVENT_SCREEN_LOADED, () => { |
| | | topView.changeTheme(true) |
| | | }) |
| | | |
| | | const titleBox = viewUtils.title(screenMain, configView.screenMain, 'helpViewTitle', 'helpView.title') |
| | | titleBox.align(dxui.Utils.ALIGN.TOP_MID, 0, 70) |
| | | |
| | | // äºç»´ç |
| | | const helpQrcode = dxui.View.build('helpQrcode', screenMain) |
| | | viewUtils._clearStyle(helpQrcode) |
| | | helpQrcode.setSize(344, 344) |
| | | helpQrcode.align(dxui.Utils.ALIGN.TOP_MID, 0, 170) |
| | | helpQrcode.bgOpa(0) |
| | | |
| | | const qrcode = dxui.View.build(helpQrcode.id + 'qrcode', helpQrcode) |
| | | viewUtils._clearStyle(qrcode) |
| | | qrcode.setSize(320, 320) |
| | | qrcode.align(dxui.Utils.ALIGN.CENTER, 0, 0); |
| | | const qrcodeObj = dxui.Utils.GG.NativeBasicComponent.lvQrcodeCreate(qrcode.obj, 320, 0x000000, 0xffffff) |
| | | dxui.Utils.GG.NativeBasicComponent.lvQrcodeUpdate(qrcodeObj, '微信æä¸æ¯æå±ç¤ºäºç»´ç ä¸çææ¬å
容') |
| | | |
| | | |
| | | const helpLabel = dxui.Label.build('helpLabel', screenMain) |
| | | helpLabel.dataI18n='helpView.scanCode' |
| | | helpLabel.align(dxui.Utils.ALIGN.TOP_MID, 0, 541) |
| | | helpLabel.textFont(viewUtils.font(26)) |
| | | } |
| | | |
| | | export default helpView |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | import dxui from '../../../../../dxmodules/dxUi.js' |
| | | import std from '../../../../../dxmodules/dxStd.js' |
| | | import viewUtils from "../../../viewUtils.js" |
| | | import topView from "../../../topView.js" |
| | | import i18n from "../../../i18n.js" |
| | | import localUserAddView from './localUserAddView.js' |
| | | import screen from '../../../../screen.js' |
| | | const faceEnterView = {} |
| | | faceEnterView.init = function () { |
| | | /**************************************************å建å±å¹*****************************************************/ |
| | | const screenMain = dxui.View.build('faceEnterView', dxui.Utils.LAYER.MAIN) |
| | | faceEnterView.screenMain = screenMain |
| | | screenMain.scroll(false) |
| | | screenMain.bgOpa(0) |
| | | screenMain.on(dxui.Utils.ENUM.LV_EVENT_SCREEN_LOADED, () => { |
| | | topView.changeTheme(false) |
| | | screen.faceEnterStart(localUserAddView.nowUser.id) |
| | | |
| | | faceEnterView.statusPanel.success("faceEnterView.faceAdd") |
| | | // faceEnterView.faceAdd.show() |
| | | // faceEnterView.faceError.hide() |
| | | // 注å10ç§è¶
æ¶ |
| | | faceEnterView.backTimer = std.setTimeout(() => { |
| | | if (!faceEnterView.successFlag) { |
| | | faceEnterView.statusPanel.fail("faceEnterView.faceError") |
| | | std.setTimeout(() => { |
| | | faceEnterView.backCb() |
| | | dxui.loadMain(localUserAddView.screenMain) |
| | | }, 500); |
| | | } |
| | | }, 10000); |
| | | }) |
| | | |
| | | screenMain.on(dxui.Utils.ENUM.LV_EVENT_SCREEN_UNLOADED, () => { |
| | | faceEnterView.successFlag = false |
| | | screen.faceEnterEnd() |
| | | if (faceEnterView.backTimer) { |
| | | std.clearTimeout(faceEnterView.backTimer) |
| | | faceEnterView.backTimer = null |
| | | } |
| | | }) |
| | | |
| | | const titleBoxBg = dxui.View.build(screenMain.id + 'titleBoxBg', screenMain) |
| | | viewUtils._clearStyle(titleBoxBg) |
| | | titleBoxBg.setSize(screen.screenSize.width, 70) |
| | | titleBoxBg.align(dxui.Utils.ALIGN.TOP_MID, 0, 0) |
| | | titleBoxBg.bgColor(0xffffff) |
| | | |
| | | const titleBox = viewUtils.title(screenMain, localUserAddView.screenMain, 'faceEnterViewTitle', 'faceEnterView.title', faceEnterView.backCb) |
| | | titleBox.align(dxui.Utils.ALIGN.TOP_MID, 0, 70) |
| | | |
| | | const faceRec2 = dxui.Image.build('faceRec2', screenMain) |
| | | faceRec2.align(dxui.Utils.ALIGN.TOP_MID, 0, -111) |
| | | faceRec2.source('/app/code/resource/image/faceRec2.png') |
| | | |
| | | // const faceAdd = dxui.Image.build('faceAdd', screenMain) |
| | | // faceEnterView.faceAdd = faceAdd |
| | | // faceAdd.align(dxui.Utils.ALIGN.BOTTOM_MID, 0, -90) |
| | | // faceAdd.source('/app/code/resource/image/faceAdd.png') |
| | | |
| | | // const faceAddLbl = dxui.Label.build('faceAddLbl', faceAdd) |
| | | // faceAddLbl.align(dxui.Utils.ALIGN.CENTER, 0, 0) |
| | | // faceAddLbl.textFont(viewUtils.font(30)) |
| | | // faceAddLbl.textColor(0xffffff) |
| | | // faceAddLbl.dataI18n = 'faceEnterView.faceAdd' |
| | | // faceAddLbl.textAlign(dxui.Utils.TEXT_ALIGN.CENTER) |
| | | |
| | | |
| | | faceEnterView.statusPanel = viewUtils.statusPanel(screenMain) |
| | | // const faceError = dxui.Image.build('faceError', screenMain) |
| | | // faceEnterView.faceError = faceError |
| | | // faceError.align(dxui.Utils.ALIGN.BOTTOM_MID, 0, -90) |
| | | // faceError.source('/app/code/resource/image/faceError.png') |
| | | // faceError.hide() |
| | | |
| | | // const faceErrorLbl = dxui.Label.build('faceErrorLbl', faceError) |
| | | // faceErrorLbl.align(dxui.Utils.ALIGN.CENTER, 0, 0) |
| | | // faceErrorLbl.textFont(viewUtils.font(30)) |
| | | // faceErrorLbl.textColor(0xffffff) |
| | | // faceErrorLbl.dataI18n = 'faceEnterView.faceError' |
| | | // faceErrorLbl.textAlign(dxui.Utils.TEXT_ALIGN.CENTER) |
| | | |
| | | // faceEnterView.timeout() |
| | | } |
| | | |
| | | faceEnterView.timeout = function () { |
| | | // faceEnterView.statusPanel.fail("faceEnterView.faceError") |
| | | // faceEnterView.faceAdd.hide() |
| | | // faceEnterView.faceError.show() |
| | | } |
| | | |
| | | faceEnterView.backCb = function () { |
| | | if (!localUserAddView.nowUser) { |
| | | return |
| | | } |
| | | if (localUserAddView.nowUser.id) { |
| | | localUserAddView.addID(localUserAddView.nowUser.id) |
| | | } |
| | | if (localUserAddView.nowUser.name) { |
| | | localUserAddView.addName(localUserAddView.nowUser.name) |
| | | } |
| | | if (localUserAddView.nowUser.idCard) { |
| | | localUserAddView.addIDCard(localUserAddView.nowUser.idCard) |
| | | } |
| | | if (localUserAddView.nowUser.face) { |
| | | localUserAddView.addFace(localUserAddView.nowUser.face) |
| | | } |
| | | if (localUserAddView.nowUser.pwd) { |
| | | localUserAddView.addPwd(localUserAddView.nowUser.pwd) |
| | | } |
| | | if (localUserAddView.nowUser.card) { |
| | | localUserAddView.addCard(localUserAddView.nowUser.card) |
| | | } |
| | | localUserAddView.addType(localUserAddView.nowUser.type) |
| | | } |
| | | |
| | | export default faceEnterView |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | import dxui from '../../../../../dxmodules/dxUi.js' |
| | | import std from '../../../../../dxmodules/dxStd.js' |
| | | import viewUtils from "../../../viewUtils.js" |
| | | import topView from "../../../topView.js" |
| | | import localUserView from '../localUserView.js' |
| | | import faceEnterView from './faceEnterView.js' |
| | | import i18n from "../../../i18n.js" |
| | | import pinyin from '../../../pinyin/pinyin.js' |
| | | import screen from '../../../../screen.js' |
| | | const localUserAddView = {} |
| | | const dropdownData = ['ä¿ç®¡å', 'ç§é¿'] |
| | | const dropdownData2 = ['User', 'Administrator'] |
| | | |
| | | localUserAddView.init = function () { |
| | | /**************************************************å建å±å¹*****************************************************/ |
| | | const screenMain = dxui.View.build('localUserAddView', dxui.Utils.LAYER.MAIN) |
| | | localUserAddView.screenMain = screenMain |
| | | screenMain.scroll(false) |
| | | screenMain.bgColor(0xffffff) |
| | | screenMain.on(dxui.Utils.ENUM.LV_EVENT_SCREEN_LOADED, () => { |
| | | topView.changeTheme(true) |
| | | refreshType() |
| | | if (!localUserAddView.deleteBtn.isHide()) { |
| | | //ä¿®æ¹ç¨æ·ä¸å
许æ¹id |
| | | localUserAddView.userInfo[0].input.disable(true) |
| | | } else { |
| | | localUserAddView.userInfo[0].input.disable(false) |
| | | } |
| | | }) |
| | | |
| | | screenMain.on(dxui.Utils.ENUM.LV_EVENT_SCREEN_UNLOADED, () => { |
| | | }) |
| | | |
| | | const titleBox = viewUtils.title(screenMain, localUserView.screenMain, 'localUserAddViewTitle', 'localUserAddView.title', undefined) |
| | | localUserAddView.titleBox = titleBox |
| | | titleBox.align(dxui.Utils.ALIGN.TOP_MID, 0, 70) |
| | | |
| | | const titleBox2 = viewUtils.title(screenMain, localUserView.screenMain, 'localUserAddViewTitle2', 'localUserAddView.title2', undefined) |
| | | localUserAddView.titleBox2 = titleBox2 |
| | | titleBox2.align(dxui.Utils.ALIGN.TOP_MID, 0, 70) |
| | | titleBox2.hide() |
| | | |
| | | const addUserBox = dxui.View.build('addUserBox', screenMain) |
| | | viewUtils._clearStyle(addUserBox) |
| | | addUserBox.setSize(screen.screenSize.width, 700) |
| | | addUserBox.align(dxui.Utils.ALIGN.TOP_MID, 0, 142) |
| | | addUserBox.borderWidth(1) |
| | | addUserBox.setBorderColor(0xDEDEDE) |
| | | addUserBox.obj.setStyleBorderSide(dxui.Utils.ENUM.LV_BORDER_SIDE_TOP, 0) |
| | | addUserBox.bgOpa(0) |
| | | |
| | | addUserBox.flexFlow(dxui.Utils.FLEX_FLOW.ROW_WRAP) |
| | | addUserBox.flexAlign(dxui.Utils.FLEX_ALIGN.CENTER, dxui.Utils.FLEX_ALIGN.CENTER, dxui.Utils.FLEX_ALIGN.START) |
| | | addUserBox.obj.lvObjSetStylePadGap(0, dxui.Utils.ENUM._LV_STYLE_STATE_CMP_SAME) |
| | | |
| | | localUserAddView.userInfo = [ |
| | | { |
| | | title: 'localUserAddView.id', |
| | | value: null, |
| | | required: true, |
| | | type: 'input', |
| | | input: null |
| | | }, |
| | | { |
| | | title: 'localUserAddView.name', |
| | | value: null, |
| | | required: true, |
| | | type: 'input', |
| | | input: null |
| | | }, |
| | | { |
| | | title: 'localUserAddView.idCard', |
| | | value: null, |
| | | type: 'input', |
| | | input: null |
| | | }, |
| | | { |
| | | title: 'localUserAddView.face', |
| | | value: null, |
| | | type: 'button', |
| | | btn: null, |
| | | btnEdit: null, |
| | | faceImg: null, |
| | | deleteBtn: null |
| | | }, |
| | | { |
| | | title: 'localUserAddView.pwd', |
| | | value: null, |
| | | type: 'button', |
| | | btn: null, |
| | | btnEdit: null, |
| | | pwdLbl: null, |
| | | deleteBtn: null |
| | | }, |
| | | { |
| | | title: 'localUserAddView.card', |
| | | value: null, |
| | | type: 'button', |
| | | btn: null, |
| | | btnEdit: null, |
| | | cardLbl: null, |
| | | deleteBtn: null |
| | | }, |
| | | { |
| | | title: 'localUserAddView.type', |
| | | value: null, |
| | | type: 'dropdown' |
| | | } |
| | | ] |
| | | |
| | | localUserAddView.userInfo.forEach((item, index) => { |
| | | const userBox = dxui.View.build('userInfo' + index, addUserBox) |
| | | viewUtils._clearStyle(userBox) |
| | | userBox.setSize(700, 65) |
| | | userBox.borderWidth(1) |
| | | userBox.setBorderColor(0xDEDEDE) |
| | | userBox.obj.setStyleBorderSide(dxui.Utils.ENUM.LV_BORDER_SIDE_BOTTOM, 0) |
| | | userBox.bgOpa(0) |
| | | |
| | | if (item.required) { |
| | | const titleLbl = dxui.Label.build('titleLblRequired' + index, userBox) |
| | | titleLbl.textFont(viewUtils.font(22)) |
| | | titleLbl.align(dxui.Utils.ALIGN.LEFT_MID, 0, 0) |
| | | titleLbl.text('*') |
| | | titleLbl.textColor(0xFD5353) |
| | | } |
| | | |
| | | const titleLbl = dxui.Label.build('titleLbl' + index, userBox) |
| | | titleLbl.textFont(viewUtils.font(22)) |
| | | titleLbl.align(dxui.Utils.ALIGN.LEFT_MID, 10, 0) |
| | | titleLbl.dataI18n = item.title |
| | | |
| | | if (item.type === 'input') { |
| | | const input = viewUtils.input(userBox, item.title, item.mode, undefined, "localUserAddView.input") |
| | | input.align(dxui.Utils.ALIGN.RIGHT_MID, 0, 0) |
| | | input.textFont(viewUtils.font(22)) |
| | | input.setSize(260, 50) |
| | | item.input = input |
| | | |
| | | input.on(dxui.Utils.EVENT.VALUE_CHANGED, () => { |
| | | if (input.text() === "") { |
| | | return |
| | | } |
| | | switch (item.title) { |
| | | case 'localUserAddView.id': |
| | | localUserAddView.nowUser.id = input.text() |
| | | localUserAddView.nowUser.userId = input.text() |
| | | break; |
| | | case 'localUserAddView.name': |
| | | localUserAddView.nowUser.name = input.text() |
| | | break; |
| | | case 'localUserAddView.idCard': |
| | | localUserAddView.nowUser.idCard = input.text() |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | }) |
| | | } else if (item.type === 'button') { |
| | | const btn = dxui.Button.build(item.title, userBox) |
| | | item.btn = btn |
| | | btn.setSize(150, 50) |
| | | btn.align(dxui.Utils.ALIGN.RIGHT_MID, 0, 0) |
| | | btn.bgColor(0xEEEEEE) |
| | | btn.radius(10) |
| | | const btnLbl = dxui.Label.build(item.title + 'btnLbl', btn) |
| | | btnLbl.textFont(viewUtils.font(22)) |
| | | btnLbl.textColor(0x05AA8D) |
| | | btnLbl.align(dxui.Utils.ALIGN.CENTER, 0, 0) |
| | | |
| | | const btnEdit = dxui.Button.build(item.title + 'edit', userBox) |
| | | item.btnEdit = btnEdit |
| | | btnEdit.setSize(150, 50) |
| | | btnEdit.align(dxui.Utils.ALIGN.RIGHT_MID, -60, 0) |
| | | btnEdit.bgColor(0xEEEEEE) |
| | | btnEdit.radius(10) |
| | | btnEdit.hide() |
| | | const btnEditLbl = dxui.Label.build(item.title + 'btnEditLbl', btnEdit) |
| | | btnEditLbl.textFont(viewUtils.font(22)) |
| | | btnEditLbl.textColor(0x05AA8D) |
| | | btnEditLbl.align(dxui.Utils.ALIGN.CENTER, 0, 0) |
| | | |
| | | const deleteBtn = viewUtils.imageBtn(userBox, item.title + 'deleteBtn', '/app/code/resource/image/delete.png') |
| | | item.deleteBtn = deleteBtn |
| | | deleteBtn.align(dxui.Utils.ALIGN.RIGHT_MID, 0, 0) |
| | | deleteBtn.hide() |
| | | |
| | | if (item.title === 'localUserAddView.pwd') { |
| | | btnLbl.dataI18n = 'localUserAddView.generate' |
| | | btnEditLbl.dataI18n = 'localUserAddView.reset' |
| | | |
| | | // å¯ç |
| | | const pwdLbl = dxui.Label.build(userBox.id + 'pwdLbl', userBox) |
| | | item.pwdLbl = pwdLbl |
| | | pwdLbl.align(dxui.Utils.ALIGN.LEFT_MID, 180, 0) |
| | | pwdLbl.textColor(0x767676) |
| | | pwdLbl.textFont(viewUtils.font(26)) |
| | | pwdLbl.hide() |
| | | |
| | | btn.on(dxui.Utils.EVENT.CLICK, () => { |
| | | pwdBoxBg.show() |
| | | pwdBoxBg.moveForeground() |
| | | topView.changeTheme(false) |
| | | localUserAddView.changePwd() |
| | | }) |
| | | |
| | | btnEdit.on(dxui.Utils.EVENT.CLICK, () => { |
| | | btn.send(dxui.Utils.EVENT.CLICK) |
| | | }) |
| | | |
| | | deleteBtn.on(dxui.Utils.EVENT.CLICK, () => { |
| | | viewUtils.confirmOpen('localUserAddView.confirm', 'localUserAddView.confirmPwd', () => { |
| | | localUserAddView.removePwd() |
| | | }, () => { }) |
| | | }) |
| | | |
| | | } else { |
| | | btnLbl.dataI18n = 'localUserAddView.enter' |
| | | btnEditLbl.dataI18n = 'localUserAddView.edit' |
| | | } |
| | | |
| | | if (item.title === 'localUserAddView.card') { |
| | | // å¡ |
| | | const cardLbl = dxui.Label.build(userBox.id + 'cardLbl', userBox) |
| | | item.cardLbl = cardLbl |
| | | cardLbl.align(dxui.Utils.ALIGN.LEFT_MID, 180, 0) |
| | | cardLbl.textColor(0x767676) |
| | | cardLbl.textFont(viewUtils.font(26)) |
| | | cardLbl.hide() |
| | | cardLbl.longMode(dxui.Utils.LABEL_LONG_MODE.SCROLL_CIRCULAR) |
| | | cardLbl.width(150) |
| | | |
| | | btn.on(dxui.Utils.EVENT.CLICK, () => { |
| | | cardBoxBg.show() |
| | | cardBoxBg.moveForeground() |
| | | topView.changeTheme(false) |
| | | // å¼å¯å·å¡è¯å« |
| | | screen.getCardStart() |
| | | }) |
| | | |
| | | btnEdit.on(dxui.Utils.EVENT.CLICK, () => { |
| | | btn.send(dxui.Utils.EVENT.CLICK) |
| | | }) |
| | | |
| | | deleteBtn.on(dxui.Utils.EVENT.CLICK, () => { |
| | | viewUtils.confirmOpen('localUserAddView.confirm', 'localUserAddView.confirmCard', () => { |
| | | localUserAddView.removeCard() |
| | | }, () => { }) |
| | | }) |
| | | } |
| | | |
| | | if (item.title === 'localUserAddView.face') { |
| | | // userBox.height(220) |
| | | btn.on(dxui.Utils.EVENT.CLICK, () => { |
| | | if (!checkRequired()) { |
| | | return |
| | | } |
| | | dxui.loadMain(faceEnterView.screenMain) |
| | | }) |
| | | |
| | | btnEdit.on(dxui.Utils.EVENT.CLICK, () => { |
| | | if (!checkRequired()) { |
| | | return |
| | | } |
| | | dxui.loadMain(faceEnterView.screenMain) |
| | | }) |
| | | |
| | | // 人è¸å¾ç |
| | | const facePreview = dxui.Button.build('facePreview', userBox) |
| | | item.facePreview = facePreview |
| | | facePreview.bgColor(0x000000) |
| | | facePreview.align(dxui.Utils.ALIGN.LEFT_MID, 180, 0) |
| | | const facePreviewLbl = dxui.Label.build('facePreviewLbl', facePreview) |
| | | facePreviewLbl.textFont(viewUtils.font(22)) |
| | | facePreviewLbl.dataI18n = "localUserAddView.preview" |
| | | facePreview.on(dxui.Utils.EVENT.CLICK, () => { |
| | | facePreviewBox.show() |
| | | facePreviewBox.moveForeground() |
| | | }) |
| | | |
| | | const facePreviewBox = dxui.View.build('facePreviewBox', screenMain) |
| | | viewUtils._clearStyle(facePreviewBox) |
| | | facePreviewBox.hide() |
| | | facePreviewBox.setSize(screenMain.width(), screenMain.height()) |
| | | facePreviewBox.on(dxui.Utils.EVENT.CLICK, () => { |
| | | facePreviewBox.hide() |
| | | }) |
| | | |
| | | const faceImg = dxui.Image.build('faceImg', facePreviewBox) |
| | | faceImg.align(dxui.Utils.ALIGN.CENTER, 0, 0) |
| | | item.faceImg = faceImg |
| | | |
| | | |
| | | deleteBtn.on(dxui.Utils.EVENT.CLICK, () => { |
| | | if (!checkRequired()) { |
| | | return |
| | | } |
| | | viewUtils.confirmOpen('localUserAddView.confirm', 'localUserAddView.confirmFace', () => { |
| | | localUserAddView.removeFace() |
| | | }, () => { }) |
| | | }) |
| | | } |
| | | } else if (item.type === 'dropdown') { |
| | | const dropdown = dxui.Dropdown.build(item.title, userBox) |
| | | item.dropdown = dropdown |
| | | dropdown.setSize(260, 50) |
| | | dropdown.align(dxui.Utils.ALIGN.RIGHT_MID, 0, 0) |
| | | dropdown.textFont(viewUtils.font(22)) |
| | | dropdown.getList().textFont(viewUtils.font(22)) |
| | | dropdown.setSymbol('/app/code/resource/image/down.png') |
| | | dropdown.on(dxui.Utils.EVENT.VALUE_CHANGED, () => { |
| | | localUserAddView.nowUser.type = dropdown.getSelected() |
| | | }) |
| | | } |
| | | }) |
| | | |
| | | // å¯ç çæé¡µ |
| | | const pwdBoxBg = dxui.View.build('pwdBoxBg', screenMain) |
| | | viewUtils._clearStyle(pwdBoxBg) |
| | | pwdBoxBg.bgColor(0x000000) |
| | | pwdBoxBg.bgOpa(50) |
| | | pwdBoxBg.setSize(screen.screenSize.width, screen.screenSize.height) |
| | | pwdBoxBg.scroll(false) |
| | | pwdBoxBg.hide() |
| | | pwdBoxBg.on(dxui.Utils.EVENT.CLICK, () => { |
| | | pwdBoxCloseBtn.send(dxui.Utils.EVENT.CLICK) |
| | | }) |
| | | |
| | | const pwdBox = dxui.View.build('pwdBox', pwdBoxBg) |
| | | viewUtils._clearStyle(pwdBox) |
| | | pwdBox.setSize(screen.screenSize.width, 694) |
| | | pwdBox.align(dxui.Utils.ALIGN.BOTTOM_MID, 0, 50) |
| | | pwdBox.bgColor(0xffffff) |
| | | pwdBox.radius(50) |
| | | |
| | | const pwdBoxLbl = dxui.Label.build('pwdBoxLbl', pwdBox) |
| | | pwdBoxLbl.dataI18n = 'localUserAddView.pwdBoxLbl' |
| | | pwdBoxLbl.textFont(viewUtils.font(36)) |
| | | pwdBoxLbl.align(dxui.Utils.ALIGN.TOP_MID, 0, 39) |
| | | |
| | | const pwdBoxCloseBtn = viewUtils.imageBtn(pwdBox, 'pwdBoxCloseBtn', '/app/code/resource/image/close_small.png') |
| | | pwdBoxCloseBtn.align(dxui.Utils.ALIGN.TOP_RIGHT, -55, 18) |
| | | pwdBoxCloseBtn.on(dxui.Utils.EVENT.CLICK, () => { |
| | | pwdBoxBg.hide() |
| | | topView.changeTheme(true) |
| | | }) |
| | | |
| | | const pwdBoxContent = dxui.View.build('pwdBoxContent', pwdBox) |
| | | viewUtils._clearStyle(pwdBoxContent) |
| | | pwdBoxContent.setSize(650, 100) |
| | | pwdBoxContent.align(dxui.Utils.ALIGN.TOP_MID, 0, 172) |
| | | pwdBoxContent.flexFlow(dxui.Utils.FLEX_FLOW.ROW_WRAP) |
| | | pwdBoxContent.flexAlign(dxui.Utils.FLEX_ALIGN.SPACE_AROUND, dxui.Utils.FLEX_ALIGN.CENTER, dxui.Utils.FLEX_ALIGN.CENTER) |
| | | |
| | | localUserAddView.pwdBoxContentItem = [] |
| | | for (let i = 0; i < 6; i++) { |
| | | const pwdBoxContentItem = dxui.View.build('pwdBoxContentItem' + i, pwdBoxContent) |
| | | pwdBoxContentItem.setSize(78, 90) |
| | | pwdBoxContentItem.radius(13) |
| | | pwdBoxContentItem.borderWidth(1) |
| | | pwdBoxContentItem.setBorderColor(0xEAEAEA) |
| | | |
| | | const pwdBoxContentItemLbl = dxui.Label.build('pwdBoxContentItemLbl' + i, pwdBoxContentItem) |
| | | pwdBoxContentItemLbl.textFont(viewUtils.font(30)) |
| | | pwdBoxContentItemLbl.align(dxui.Utils.ALIGN.CENTER, 0, 0) |
| | | pwdBoxContentItemLbl.text('0') |
| | | localUserAddView.pwdBoxContentItem.push(pwdBoxContentItemLbl) |
| | | } |
| | | |
| | | const pwdBoxSaveBtn = dxui.Button.build('pwdBoxSaveBtn', pwdBox) |
| | | pwdBoxSaveBtn.setSize(210, 60) |
| | | pwdBoxSaveBtn.align(dxui.Utils.ALIGN.TOP_LEFT, 87, 340) |
| | | pwdBoxSaveBtn.bgColor(0xEAEAEA) |
| | | pwdBoxSaveBtn.radius(10) |
| | | pwdBoxSaveBtn.on(dxui.Utils.EVENT.CLICK, () => { |
| | | localUserAddView.changePwd() |
| | | }) |
| | | |
| | | const pwdBoxSaveBtnLbl = dxui.Label.build('pwdBoxSaveBtnLbl', pwdBoxSaveBtn) |
| | | pwdBoxSaveBtnLbl.dataI18n = 'localUserAddView.pwdBoxSaveBtnLbl' |
| | | pwdBoxSaveBtnLbl.textFont(viewUtils.font(24)) |
| | | pwdBoxSaveBtnLbl.align(dxui.Utils.ALIGN.CENTER, 0, 0) |
| | | pwdBoxSaveBtnLbl.textColor(0x000000) |
| | | |
| | | const pwdBoxConfirmBtn = dxui.Button.build('pwdBoxConfirmBtn', pwdBox) |
| | | pwdBoxConfirmBtn.setSize(210, 60) |
| | | pwdBoxConfirmBtn.align(dxui.Utils.ALIGN.TOP_RIGHT, -76, 340) |
| | | pwdBoxConfirmBtn.bgColor(0x000000) |
| | | pwdBoxConfirmBtn.radius(10) |
| | | pwdBoxConfirmBtn.on(dxui.Utils.EVENT.CLICK, () => { |
| | | localUserAddView.addPwd(localUserAddView.pwdBoxContentFin) |
| | | pwdBoxCloseBtn.send(dxui.Utils.EVENT.CLICK) |
| | | }) |
| | | |
| | | const pwdBoxConfirmBtnLbl = dxui.Label.build('pwdBoxConfirmBtnLbl', pwdBoxConfirmBtn) |
| | | pwdBoxConfirmBtnLbl.dataI18n = 'localUserAddView.pwdBoxConfirmBtnLbl' |
| | | pwdBoxConfirmBtnLbl.textFont(viewUtils.font(24)) |
| | | pwdBoxConfirmBtnLbl.align(dxui.Utils.ALIGN.CENTER, 0, 0) |
| | | |
| | | // 读åå¡çä¸ |
| | | const cardBoxBg = dxui.View.build('cardBoxBg', screenMain) |
| | | viewUtils._clearStyle(cardBoxBg) |
| | | cardBoxBg.setSize(screen.screenSize.width, screen.screenSize.height) |
| | | cardBoxBg.align(dxui.Utils.ALIGN.TOP_MID, 0, 0) |
| | | cardBoxBg.bgColor(0x000000) |
| | | cardBoxBg.bgOpa(50) |
| | | cardBoxBg.scroll(false) |
| | | cardBoxBg.hide() |
| | | cardBoxBg.on(dxui.Utils.EVENT.CLICK, () => { |
| | | cardBoxCloseBtn.send(dxui.Utils.EVENT.CLICK) |
| | | }) |
| | | |
| | | const cardBox = dxui.View.build('cardBox', cardBoxBg) |
| | | viewUtils._clearStyle(cardBox) |
| | | cardBox.setSize(screen.screenSize.width, 694) |
| | | cardBox.align(dxui.Utils.ALIGN.BOTTOM_MID, 0, 50) |
| | | cardBox.bgColor(0xffffff) |
| | | cardBox.radius(50) |
| | | cardBox.on(dxui.Utils.EVENT.CLICK, () => { |
| | | }) |
| | | |
| | | const cardBoxLbl = dxui.Label.build('cardBoxLbl', cardBox) |
| | | cardBoxLbl.dataI18n = 'localUserAddView.cardBoxLbl' |
| | | cardBoxLbl.textFont(viewUtils.font(36)) |
| | | cardBoxLbl.align(dxui.Utils.ALIGN.TOP_MID, 0, 39) |
| | | |
| | | const cardBoxCloseBtn = viewUtils.imageBtn(cardBox, 'cardBoxCloseBtn', '/app/code/resource/image/close_small.png') |
| | | cardBoxCloseBtn.align(dxui.Utils.ALIGN.TOP_RIGHT, -55, 18) |
| | | cardBoxCloseBtn.on(dxui.Utils.EVENT.CLICK, () => { |
| | | cardBoxBg.hide() |
| | | topView.changeTheme(true) |
| | | // å
³éå·å¡è¯å« |
| | | screen.endCardEnd() |
| | | }) |
| | | |
| | | const cardBoxInput = viewUtils.input(cardBox, 'localUserAddView.cardBoxInput', undefined, undefined, 'localUserAddView.cardBoxInput') |
| | | localUserAddView.cardBoxInput = cardBoxInput |
| | | cardBoxInput.align(dxui.Utils.ALIGN.TOP_MID, 0, 183) |
| | | cardBoxInput.setSize(630, 75) |
| | | cardBoxInput.on(dxui.Utils.EVENT.CLICK, () => { |
| | | cardBoxInput.align(dxui.Utils.ALIGN.TOP_MID, 0, 90) |
| | | pinyin.hideCb(() => { |
| | | cardBoxInput.align(dxui.Utils.ALIGN.TOP_MID, 0, 183) |
| | | }) |
| | | }) |
| | | |
| | | const cardBoxResetBtn = dxui.Button.build('cardBoxResetBtn', cardBox) |
| | | cardBoxResetBtn.setSize(210, 60) |
| | | cardBoxResetBtn.align(dxui.Utils.ALIGN.TOP_LEFT, 87, 340) |
| | | cardBoxResetBtn.bgColor(0xEAEAEA) |
| | | cardBoxResetBtn.radius(10) |
| | | cardBoxResetBtn.on(dxui.Utils.EVENT.CLICK, () => { |
| | | cardBoxInput.text('') |
| | | }) |
| | | |
| | | const cardBoxResetBtnLbl = dxui.Label.build('cardBoxResetBtnLbl', cardBoxResetBtn) |
| | | cardBoxResetBtnLbl.dataI18n = 'localUserAddView.cardBoxResetBtnLbl' |
| | | cardBoxResetBtnLbl.textFont(viewUtils.font(24)) |
| | | cardBoxResetBtnLbl.align(dxui.Utils.ALIGN.CENTER, 0, 0) |
| | | cardBoxResetBtnLbl.textColor(0x000000) |
| | | |
| | | const cardBoxSaveBtn = dxui.Button.build('cardBoxSaveBtn', cardBox) |
| | | cardBoxSaveBtn.setSize(210, 60) |
| | | cardBoxSaveBtn.align(dxui.Utils.ALIGN.TOP_RIGHT, -76, 340) |
| | | cardBoxSaveBtn.bgColor(0x000000) |
| | | cardBoxSaveBtn.radius(10) |
| | | cardBoxSaveBtn.on(dxui.Utils.EVENT.CLICK, () => { |
| | | cardBoxCloseBtn.send(dxui.Utils.EVENT.CLICK) |
| | | if (cardBoxInput.text()) { |
| | | localUserAddView.addCard(cardBoxInput.text()) |
| | | } |
| | | }) |
| | | |
| | | const cardBoxSaveBtnLbl = dxui.Label.build('cardBoxSaveBtnLbl', cardBoxSaveBtn) |
| | | cardBoxSaveBtnLbl.dataI18n = 'localUserAddView.cardBoxSaveBtnLbl' |
| | | cardBoxSaveBtnLbl.textFont(viewUtils.font(24)) |
| | | cardBoxSaveBtnLbl.align(dxui.Utils.ALIGN.CENTER, 0, 0) |
| | | |
| | | const deleteBtn = viewUtils.bottomBtn(screenMain, screenMain.id + 'deleteBtn', 'localUserAddView.delete', () => { |
| | | if (!checkRequired()) { |
| | | return |
| | | } |
| | | |
| | | viewUtils.confirmOpen('localUserAddView.confirmDelete', 'localUserAddView.confirmDeleteContent', () => { |
| | | // å é¤ç¨æ· |
| | | const res = screen.deleteUser(localUserAddView.nowUser) |
| | | if (res) { |
| | | dxui.loadMain(localUserView.screenMain) |
| | | } else { |
| | | localUserAddView.statusPanel.fail() |
| | | } |
| | | }, () => { }) |
| | | |
| | | }, 0xEAEAEA, 0xEA0000) |
| | | deleteBtn.align(dxui.Utils.ALIGN.BOTTOM_MID, 0, -200) |
| | | localUserAddView.deleteBtn = deleteBtn |
| | | deleteBtn.hide() |
| | | |
| | | const saveBtn = viewUtils.bottomBtn(screenMain, screenMain.id + 'saveBtn', 'localUserAddView.save', async () => { |
| | | if (!checkRequired()) { |
| | | return |
| | | } |
| | | let res = false |
| | | if (localUserAddView.deleteBtn.isHide()) { |
| | | // æ°å¢ç¨æ· |
| | | res = await screen.insertUser(localUserAddView.nowUser) |
| | | } else { |
| | | // ä¿®æ¹ç¨æ· |
| | | res = screen.updateUser(localUserAddView.nowUser) |
| | | } |
| | | |
| | | if (res === true) { |
| | | localUserAddView.statusPanel.success() |
| | | std.setTimeout(() => { |
| | | // æåè¿åä¸ä¸å±çé¢ |
| | | dxui.loadMain(localUserView.screenMain) |
| | | }, 500) |
| | | } else { |
| | | if (typeof res === "string") { |
| | | localUserAddView.statusPanel.fail(res) |
| | | } else { |
| | | localUserAddView.statusPanel.fail() |
| | | } |
| | | } |
| | | }) |
| | | saveBtn.align(dxui.Utils.ALIGN.BOTTOM_MID, 0, -83) |
| | | localUserAddView.saveBtn = saveBtn |
| | | |
| | | localUserAddView.statusPanel = viewUtils.statusPanel(screenMain, 'localUserAddView.success', 'localUserAddView.fail') |
| | | } |
| | | |
| | | localUserAddView.addID = function (id) { |
| | | localUserAddView.userInfo[0].input.text(id) |
| | | localUserAddView.nowUser.id = id |
| | | } |
| | | |
| | | localUserAddView.removeID = function () { |
| | | localUserAddView.userInfo[0].input.text('') |
| | | } |
| | | |
| | | localUserAddView.addName = function (name) { |
| | | localUserAddView.userInfo[1].input.text(name) |
| | | localUserAddView.nowUser.name = name |
| | | } |
| | | |
| | | localUserAddView.removeName = function () { |
| | | localUserAddView.userInfo[1].input.text('') |
| | | } |
| | | |
| | | localUserAddView.addIDCard = function (idCard) { |
| | | localUserAddView.userInfo[2].input.text(idCard) |
| | | localUserAddView.nowUser.idCard = idCard |
| | | } |
| | | |
| | | localUserAddView.removeIDCard = function () { |
| | | localUserAddView.userInfo[2].input.text('') |
| | | } |
| | | |
| | | localUserAddView.addFace = function (face) { |
| | | localUserAddView.userInfo[3].btnEdit.show() |
| | | localUserAddView.userInfo[3].btn.hide() |
| | | |
| | | const faceImg = localUserAddView.userInfo[3].faceImg |
| | | faceImg.source(face) |
| | | faceImg.show() |
| | | |
| | | // let header = dxui.Utils.GG.NativeDraw.lvImgDecoderGetInfo(face) |
| | | // let zoom = 60 / header.h * 256 |
| | | // faceImg.obj.lvImgSetZoom(zoom) |
| | | // faceImg.obj.lvImgSetSizeMode(dxui.Utils.ENUM.LV_IMG_SIZE_MODE_REAL) |
| | | // faceImg.setSize(Math.ceil(zoom / 256 * header.w), 60) |
| | | |
| | | localUserAddView.userInfo[3].deleteBtn.show() |
| | | localUserAddView.nowUser.face = face |
| | | } |
| | | |
| | | localUserAddView.removeFace = function () { |
| | | localUserAddView.userInfo[3].btn.show() |
| | | localUserAddView.userInfo[3].btnEdit.hide() |
| | | localUserAddView.userInfo[3].deleteBtn.hide() |
| | | localUserAddView.userInfo[3].faceImg.hide() |
| | | if (localUserAddView.nowUser && localUserAddView.nowUser.face) { |
| | | delete localUserAddView.nowUser.face |
| | | } |
| | | } |
| | | |
| | | localUserAddView.addPwd = function (pwd) { |
| | | localUserAddView.userInfo[4].btn.hide() |
| | | localUserAddView.userInfo[4].btnEdit.show() |
| | | localUserAddView.userInfo[4].deleteBtn.show() |
| | | localUserAddView.userInfo[4].pwdLbl.show() |
| | | localUserAddView.userInfo[4].pwdLbl.text(pwd) |
| | | localUserAddView.nowUser.pwd = pwd |
| | | } |
| | | |
| | | localUserAddView.removePwd = function () { |
| | | localUserAddView.userInfo[4].btn.show() |
| | | localUserAddView.userInfo[4].btnEdit.hide() |
| | | localUserAddView.userInfo[4].deleteBtn.hide() |
| | | localUserAddView.userInfo[4].pwdLbl.hide() |
| | | if (localUserAddView.nowUser && localUserAddView.nowUser.pwd) { |
| | | delete localUserAddView.nowUser.pwd |
| | | } |
| | | } |
| | | |
| | | localUserAddView.addCard = function (card) { |
| | | localUserAddView.userInfo[5].btn.hide() |
| | | localUserAddView.userInfo[5].btnEdit.show() |
| | | localUserAddView.userInfo[5].deleteBtn.show() |
| | | localUserAddView.userInfo[5].cardLbl.show() |
| | | localUserAddView.userInfo[5].cardLbl.text(card) |
| | | localUserAddView.nowUser.card = card |
| | | } |
| | | |
| | | localUserAddView.removeCard = function () { |
| | | localUserAddView.userInfo[5].btn.show() |
| | | localUserAddView.userInfo[5].btnEdit.hide() |
| | | localUserAddView.userInfo[5].deleteBtn.hide() |
| | | localUserAddView.userInfo[5].cardLbl.hide() |
| | | if (localUserAddView.nowUser && localUserAddView.nowUser.card) { |
| | | delete localUserAddView.nowUser.card |
| | | } |
| | | } |
| | | |
| | | localUserAddView.addType = function (type) { |
| | | localUserAddView.userInfo[6].dropdown.setSelected(type) |
| | | } |
| | | |
| | | localUserAddView.changePwd = function () { |
| | | const randomPwd = Math.floor(Math.random() * 900000 + 100000).toString() |
| | | localUserAddView.pwdBoxContentFin = randomPwd |
| | | localUserAddView.pwdBoxContentItem.forEach((item, index) => { |
| | | item.text(randomPwd[index]) |
| | | }) |
| | | } |
| | | |
| | | localUserAddView.isEdit = function (flag) { |
| | | localUserAddView.removeFace() |
| | | localUserAddView.removePwd() |
| | | localUserAddView.removeCard() |
| | | localUserAddView.removeID() |
| | | localUserAddView.removeName() |
| | | localUserAddView.removeIDCard() |
| | | if (flag) { |
| | | localUserAddView.saveBtn.align(dxui.Utils.ALIGN.BOTTOM_MID, 0, -53) |
| | | localUserAddView.deleteBtn.show() |
| | | localUserAddView.titleBox2.show() |
| | | } else { |
| | | localUserAddView.saveBtn.align(dxui.Utils.ALIGN.BOTTOM_MID, 0, -83) |
| | | localUserAddView.deleteBtn.hide() |
| | | localUserAddView.titleBox2.hide() |
| | | localUserAddView.nowUser = {} |
| | | } |
| | | } |
| | | |
| | | // æ£æ¥å¿
填项 |
| | | function checkRequired() { |
| | | if (!localUserAddView.userInfo[0].input.text()) { |
| | | localUserAddView.statusPanel.fail("localUserAddView.requiredInfo") |
| | | return false |
| | | } |
| | | if (!localUserAddView.userInfo[1].input.text()) { |
| | | localUserAddView.statusPanel.fail("localUserAddView.requiredInfo") |
| | | return false |
| | | } |
| | | return true |
| | | } |
| | | |
| | | function refreshType() { |
| | | switch (screen.getConfig()['base.language']) { |
| | | case 'CN': |
| | | localUserAddView.userInfo[6].dropdown.setOptions(dropdownData) |
| | | break; |
| | | case 'EN': |
| | | localUserAddView.userInfo[6].dropdown.setOptions(dropdownData2) |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | |
| | | export default localUserAddView |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | import dxui from '../../../../dxmodules/dxUi.js' |
| | | import viewUtils from "../../viewUtils.js" |
| | | import topView from "../../topView.js" |
| | | import configView from '../configView.js' |
| | | import pinyin from '../../pinyin/pinyin.js' |
| | | import localUserAddView from './localUser/localUserAddView.js' |
| | | import faceEnterView from './localUser/faceEnterView.js' |
| | | import screen from '../../../screen.js' |
| | | const localUserView = {} |
| | | localUserView.init = function () { |
| | | /**************************************************å建å±å¹*****************************************************/ |
| | | const screenMain = dxui.View.build('localUserView', dxui.Utils.LAYER.MAIN) |
| | | localUserView.screenMain = screenMain |
| | | screenMain.scroll(false) |
| | | screenMain.bgColor(0xffffff) |
| | | screenMain.on(dxui.Utils.ENUM.LV_EVENT_SCREEN_LOADED, () => { |
| | | topView.changeTheme(true) |
| | | |
| | | localUserView.nowPage = localUserView.nowPage ? localUserView.nowPage : 0 |
| | | let users = screen.getUsers(localUserView.nowPage, 6) |
| | | while (users.data.length == 0 && localUserView.nowPage > 0) { |
| | | localUserView.nowPage -= 1 |
| | | users = screen.getUsers(localUserView.nowPage, 6) |
| | | } |
| | | if (users.data.length > 0) { |
| | | // localUserView.initData([{ id: "1", name: 'å¼ ä¸' }, { id: "2", name: 'æå' }, { id: "3", name: 'çäº' }, { id: "4", name: 'èµµå
' }, { id: "5", name: 'åä¸' }, { id: "6", name: 'å¨å
«' }, { id: "7", name: 'å´ä¹' }, { id: "8", name: 'éå' }, { id: "9", name: 'éåä¸' }, { id: "10", name: 'èµµåäº' }, { id: "11", name: 'ååä¸' }, { id: "12", name: 'å¨åå' }, { id: "13", name: 'å´åäº' }, { id: "14", name: 'éåå
' }, { id: "15", name: 'éåä¸' }, { id: "16", name: 'èµµåå
«' }, { id: "17", name: 'ååä¹' }, { id: "20", name: 'å¨äºå' },]) |
| | | localUserView.initData(users.data) |
| | | } else { |
| | | localUserView.initData() |
| | | } |
| | | // å·æ°åé¡µä¿¡æ¯ |
| | | refreshPageInfo(users) |
| | | }) |
| | | |
| | | const titleBox = viewUtils.title(screenMain, configView.screenMain, 'localUserViewTitle', 'localUserView.title', () => { localUserView.nowPage = 0 }) |
| | | titleBox.align(dxui.Utils.ALIGN.TOP_MID, 0, 70) |
| | | |
| | | const empty = dxui.Image.build('empty', screenMain) |
| | | localUserView.empty = empty |
| | | empty.align(dxui.Utils.ALIGN.TOP_MID, 0, 218) |
| | | empty.source('/app/code/resource/image/empty.png') |
| | | |
| | | const emptyLbl = dxui.Label.build('emptyLbl', screenMain) |
| | | localUserView.emptyLbl = emptyLbl |
| | | emptyLbl.textFont(viewUtils.font(26)) |
| | | emptyLbl.align(dxui.Utils.ALIGN.TOP_MID, 0, 479) |
| | | emptyLbl.dataI18n = 'localUserView.empty' |
| | | emptyLbl.textColor(0x888888) |
| | | |
| | | const userList = dxui.View.build('userList', screenMain) |
| | | viewUtils._clearStyle(userList) |
| | | localUserView.userList = userList |
| | | userList.setSize(screen.screenSize.width, 570) |
| | | userList.align(dxui.Utils.ALIGN.TOP_MID, 0, 142) |
| | | userList.flexFlow(dxui.Utils.FLEX_FLOW.ROW_WRAP) |
| | | userList.flexAlign(dxui.Utils.FLEX_ALIGN.START, dxui.Utils.FLEX_ALIGN.START, dxui.Utils.FLEX_ALIGN.START) |
| | | userList.obj.lvObjSetStylePadGap(5, dxui.Utils.ENUM._LV_STYLE_STATE_CMP_SAME) |
| | | userList.hide() |
| | | |
| | | const searchBox = dxui.View.build('searchBox', userList) |
| | | viewUtils._clearStyle(searchBox) |
| | | searchBox.setSize(screen.screenSize.width, 76) |
| | | searchBox.bgOpa(0) |
| | | searchBox.borderWidth(1) |
| | | searchBox.setBorderColor(0xDEDEDE) |
| | | searchBox.obj.setStyleBorderSide(dxui.Utils.ENUM.LV_BORDER_SIDE_BOTTOM, 0) |
| | | |
| | | const searchInput = viewUtils.input(searchBox, 'searchBoxInput', undefined, () => { |
| | | }, 'localUserView.search') |
| | | searchInput.setSize(screen.screenSize.width / 2, 60) |
| | | searchInput.align(dxui.Utils.ALIGN.LEFT_MID, 28, 0) |
| | | |
| | | const searchBtn = dxui.Button.build('searchBtn', searchBox) |
| | | searchBtn.setSize(126, 44) |
| | | searchBtn.align(dxui.Utils.ALIGN.RIGHT_MID, -29, 0) |
| | | searchBtn.bgColor(0xF6FAFA) |
| | | searchBtn.radius(10) |
| | | |
| | | searchBtn.on(dxui.Utils.EVENT.CLICK, () => { |
| | | const users = screen.getUsers(0, 6, searchInput.text(), searchInput.text()) |
| | | if (users.data) { |
| | | localUserView.initData(users.data) |
| | | } else { |
| | | localUserView.initData([]) |
| | | } |
| | | // pinyin.hide() |
| | | }) |
| | | |
| | | const searchBtnLbl = dxui.Label.build('searchBtnLbl', searchBtn) |
| | | searchBtnLbl.dataI18n = 'localUserView.searchBtn' |
| | | searchBtnLbl.textFont(viewUtils.font(26)) |
| | | searchBtnLbl.textColor(0x05AA8D) |
| | | searchBtnLbl.align(dxui.Utils.ALIGN.CENTER, 0, 0) |
| | | |
| | | localUserView.userItemList = [] |
| | | for (let i = 0; i < 6; i++) { |
| | | const userItem = dxui.View.build('userItem' + i, userList) |
| | | viewUtils._clearStyle(userItem) |
| | | userItem.setSize(screen.screenSize.width, 76) |
| | | userItem.align(dxui.Utils.ALIGN.TOP_MID, 0, 0) |
| | | userItem.bgOpa(0) |
| | | userItem.borderWidth(1) |
| | | userItem.setBorderColor(0xDEDEDE) |
| | | userItem.obj.setStyleBorderSide(dxui.Utils.ENUM.LV_BORDER_SIDE_BOTTOM, 0) |
| | | userItem.hide() |
| | | |
| | | const userItemId0 = dxui.Label.build('userItemId0' + i, userItem) |
| | | userItemId0.text('IDï¼') |
| | | userItemId0.textFont(viewUtils.font(26)) |
| | | userItemId0.align(dxui.Utils.ALIGN.LEFT_MID, 28, 0) |
| | | |
| | | const userItemId = dxui.Label.build('userItemId' + i, userItem) |
| | | userItemId.text(i + '') |
| | | userItemId.textFont(viewUtils.font(26)) |
| | | userItemId.align(dxui.Utils.ALIGN.LEFT_MID, 80, 0) |
| | | userItemId.width(100) |
| | | userItemId.longMode(dxui.Utils.LABEL_LONG_MODE.SCROLL_CIRCULAR) |
| | | |
| | | const userItemName = dxui.Label.build('userItemName' + i, userItem) |
| | | userItemName.text('') |
| | | userItemName.textFont(viewUtils.font(26)) |
| | | userItemName.align(dxui.Utils.ALIGN.LEFT_MID, 220, 0) |
| | | userItemName.width(200) |
| | | userItemName.longMode(dxui.Utils.LABEL_LONG_MODE.SCROLL_CIRCULAR) |
| | | |
| | | const userItemEdit = dxui.Button.build('userItemEdit' + i, userItem) |
| | | userItemEdit.setSize(126, 44) |
| | | userItemEdit.align(dxui.Utils.ALIGN.RIGHT_MID, -29, 0) |
| | | userItemEdit.bgColor(0xF6FAFA) |
| | | userItemEdit.radius(10) |
| | | |
| | | userItemEdit.on(dxui.Utils.EVENT.CLICK, () => { |
| | | localUserAddView.isEdit(true) |
| | | dxui.loadMain(localUserAddView.screenMain) |
| | | |
| | | let item = localUserView.userData.filter(item => { |
| | | return item.id === userItemId.text().replace('IDï¼', '') |
| | | }) |
| | | if (item) { |
| | | item = item[0] |
| | | const voucher = screen.getVoucher(item.id) |
| | | Object.assign(item, voucher); |
| | | localUserAddView.nowUser = item |
| | | |
| | | if (item.id) { |
| | | localUserAddView.addID(item.id) |
| | | } |
| | | if (item.name) { |
| | | localUserAddView.addName(item.name) |
| | | } |
| | | if (item.idCard) { |
| | | localUserAddView.addIDCard(item.idCard) |
| | | } |
| | | if (item.face) { |
| | | localUserAddView.addFace(item.face) |
| | | } |
| | | if (item.pwd) { |
| | | localUserAddView.addPwd(item.pwd) |
| | | } |
| | | if (item.card) { |
| | | localUserAddView.addCard(item.card) |
| | | } |
| | | localUserAddView.addType(item.type) |
| | | } |
| | | }) |
| | | |
| | | const userItemEditLbl = dxui.Label.build('userItemEditLbl' + i, userItemEdit) |
| | | userItemEditLbl.dataI18n = 'localUserView.edit' |
| | | userItemEditLbl.textFont(viewUtils.font(26)) |
| | | userItemEditLbl.textColor(0x05AA8D) |
| | | userItemEditLbl.align(dxui.Utils.ALIGN.CENTER, 0, 0) |
| | | |
| | | localUserView.userItemList.push({ userItem, userItemId, userItemName }) |
| | | } |
| | | |
| | | const pageNextBtn = dxui.Button.build('pageNextBtn', screenMain) |
| | | pageNextBtn.bgColor(0x000000) |
| | | localUserView.pageNextBtn = pageNextBtn |
| | | const pageNextLbl = dxui.Label.build('pageNextLbl', pageNextBtn) |
| | | pageNextLbl.text("â") |
| | | pageNextBtn.align(dxui.Utils.ALIGN.BOTTOM_RIGHT, -20, -372) |
| | | pageNextBtn.textFont(viewUtils.font(20)) |
| | | const pagePrevBtn = dxui.Button.build('pagePrevBtn', screenMain) |
| | | pagePrevBtn.bgColor(0x000000) |
| | | localUserView.pagePrevBtn = pagePrevBtn |
| | | const pagePrevLbl = dxui.Label.build('pagePrevLbl', pagePrevBtn) |
| | | pagePrevLbl.text("â") |
| | | pagePrevBtn.align(dxui.Utils.ALIGN.BOTTOM_LEFT, 20, -372) |
| | | pagePrevBtn.textFont(viewUtils.font(20)) |
| | | |
| | | pageNextBtn.on(dxui.Utils.EVENT.CLICK, () => { |
| | | if (!localUserView.nowPage) { |
| | | localUserView.nowPage = 0 |
| | | } |
| | | localUserView.pageNum += 1 |
| | | const users = screen.getUsers(localUserView.pageNum, 6) |
| | | if (users.data) { |
| | | localUserView.initData(users.data) |
| | | } else { |
| | | localUserView.initData([]) |
| | | } |
| | | refreshPageInfo(users) |
| | | }) |
| | | pagePrevBtn.on(dxui.Utils.EVENT.CLICK, () => { |
| | | if (!localUserView.nowPage) { |
| | | localUserView.nowPage = 0 |
| | | } |
| | | localUserView.pageNum -= 1 |
| | | const users = screen.getUsers(localUserView.pageNum, 6) |
| | | if (users.data) { |
| | | localUserView.initData(users.data) |
| | | } else { |
| | | localUserView.initData([]) |
| | | } |
| | | refreshPageInfo(users) |
| | | }) |
| | | |
| | | const pageSelect = dxui.Dropdown.build('pageSelect', screenMain) |
| | | localUserView.pageSelect = pageSelect |
| | | pageSelect.textFont(viewUtils.font(22)) |
| | | pageSelect.getList().textFont(viewUtils.font(22)) |
| | | pageSelect.setSize(150, 55) |
| | | pageSelect.setSymbol('/app/code/resource/image/down.png') |
| | | pageSelect.align(dxui.Utils.ALIGN.BOTTOM_MID, 0, -370) |
| | | pageSelect.on(dxui.Utils.EVENT.VALUE_CHANGED, () => { |
| | | localUserView.pageNum = pageSelect.getSelected() |
| | | const users = screen.getUsers(localUserView.pageNum, 6) |
| | | if (users.data) { |
| | | localUserView.initData(users.data) |
| | | } else { |
| | | localUserView.initData([]) |
| | | } |
| | | refreshPageInfo(users) |
| | | }) |
| | | |
| | | const syncBtn = viewUtils.bottomBtn(screenMain, screenMain.id + 'syncBtn', 'localUserView.sync', () => { |
| | | }, 0xEAEAEA, 0x000000) |
| | | syncBtn.align(dxui.Utils.ALIGN.BOTTOM_MID, 0, -204) |
| | | localUserView.syncBtn = syncBtn |
| | | syncBtn.hide() |
| | | |
| | | syncBtn.on(dxui.Utils.EVENT.CLICK, () => { |
| | | viewUtils.confirmOpen('localUserView.attention', 'localUserView.attentionContent', () => { |
| | | viewUtils.confirmOpen('localUserView.tip', 'localUserView.tipContent') |
| | | }) |
| | | }) |
| | | |
| | | const addBtn = viewUtils.bottomBtn(screenMain, screenMain.id + 'addBtn', 'localUserView.add', () => { |
| | | localUserAddView.isEdit(false) |
| | | dxui.loadMain(localUserAddView.screenMain) |
| | | }) |
| | | addBtn.align(dxui.Utils.ALIGN.BOTTOM_MID, 0, -83) |
| | | } |
| | | |
| | | localUserView.initData = function (data) { |
| | | // å½å页ç人åä¿¡æ¯ |
| | | localUserView.userData = data |
| | | localUserView.refresh(data) |
| | | } |
| | | |
| | | localUserView.refresh = function (data) { |
| | | if (data === undefined || data === null) { |
| | | localUserView.empty.show() |
| | | localUserView.emptyLbl.show() |
| | | localUserView.syncBtn.hide() |
| | | localUserView.userList.hide() |
| | | return |
| | | } |
| | | |
| | | localUserView.userItemList.forEach(item => { |
| | | item.userItem.hide() |
| | | }) |
| | | |
| | | // 渲æäººåå表 |
| | | data.forEach((item, index) => { |
| | | if (index >= localUserView.userItemList.length) { |
| | | return |
| | | } |
| | | localUserView.userItemList[index].userItemId.text(item.id) |
| | | // æ¾ç¤ºå§åå人åç±»å |
| | | let typeText = item.type == 1 ? 'ï¼ä¿ç®¡åï¼' : item.type == 2 ? 'ï¼ç§é¿ï¼' : '' |
| | | localUserView.userItemList[index].userItemName.text(item.name + typeText) |
| | | localUserView.userItemList[index].userItem.show() |
| | | }) |
| | | |
| | | localUserView.empty.hide() |
| | | localUserView.emptyLbl.hide() |
| | | // localUserView.syncBtn.show() |
| | | localUserView.userList.show() |
| | | } |
| | | |
| | | function refreshPageInfo(users) { |
| | | if (users.currentPage == 1) { |
| | | localUserView.pagePrevBtn.disable(true) |
| | | localUserView.pagePrevBtn.hide() |
| | | } else { |
| | | localUserView.pagePrevBtn.disable(false) |
| | | localUserView.pagePrevBtn.show() |
| | | } |
| | | if (users.currentPage == users.totalPage || users.totalPage == 0) { |
| | | localUserView.pageNextBtn.disable(true) |
| | | localUserView.pageNextBtn.hide() |
| | | } else { |
| | | localUserView.pageNextBtn.disable(false) |
| | | localUserView.pageNextBtn.show() |
| | | } |
| | | if (users.totalPage == 0 || users.totalPage == 1) { |
| | | localUserView.pageSelect.hide() |
| | | } else { |
| | | localUserView.pageSelect.show() |
| | | } |
| | | localUserView.pageSelect.setOptions(Array.from({ length: users.totalPage }, (_, index) => String(index + 1))) |
| | | localUserView.pageSelect.setSelected(users.currentPage - 1) |
| | | } |
| | | export default localUserView |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | import dxui from '../../../../dxmodules/dxUi.js' |
| | | import std from '../../../../dxmodules/dxStd.js' |
| | | import viewUtils from "../../viewUtils.js" |
| | | import topView from "../../topView.js" |
| | | import configView from '../configView.js' |
| | | import i18n from "../../i18n.js" |
| | | import screen from '../../../screen.js' |
| | | |
| | | const networkSettingView = {} |
| | | networkSettingView.init = function () { |
| | | /**************************************************å建å±å¹*****************************************************/ |
| | | const screenMain = dxui.View.build('networkSettingView', dxui.Utils.LAYER.MAIN) |
| | | networkSettingView.screenMain = screenMain |
| | | screenMain.scroll(false) |
| | | screenMain.bgColor(0xffffff) |
| | | screenMain.on(dxui.Utils.ENUM.LV_EVENT_SCREEN_LOADED, () => { |
| | | topView.changeTheme(true) |
| | | let devType = screen.getConfig()["sys.devType"] |
| | | let netTypes = [] |
| | | netTypes = devType == 1 ? [i18n.t('networkSettingView.ethernet'), i18n.t('networkSettingView._4G')] : [i18n.t('networkSettingView.ethernet'), i18n.t('networkSettingView.wifi'), i18n.t('networkSettingView._4G')] |
| | | networkSettingView.netInfo[0].value = netTypes |
| | | networkSettingView.netInfo[0].dropdown.setOptions(networkSettingView.netInfo[0].value) |
| | | const configAll = screen.getConfig() |
| | | networkSettingView.changeNetType(configAll["net.type"] - 1) |
| | | networkSettingView.netInfo[0].dropdown.setSelected(configAll["net.type"] - 1) |
| | | networkSettingView.netInfo[1].dropdown.setOptions([configAll["net.ssid"]]) |
| | | networkSettingView.netInfo[1].dropdown.setSelected(0) |
| | | networkSettingView.netInfo[2].input.text(configAll["net.psk"]) |
| | | networkSettingView.netInfo[3].switch.select(configAll["net.dhcp"] == 2) |
| | | networkSettingView.netInfo[4].input.text(configAll["net.ip"]) |
| | | networkSettingView.netInfo[5].input.text(configAll["net.mask"]) |
| | | networkSettingView.netInfo[6].input.text(configAll["net.gateway"]) |
| | | networkSettingView.netInfo[7].input.text(configAll["net.dns"].split(",")[0]) |
| | | networkSettingView.netInfo[8].input.text(configAll["net.dns"].split(",")[1]) |
| | | networkSettingView.netInfo[9].label.text(configAll["net.mac"]) |
| | | }) |
| | | |
| | | screenMain.on(dxui.Utils.ENUM.LV_EVENT_SCREEN_UNLOADED, () => { |
| | | wifiListBoxClose.send(dxui.Utils.EVENT.CLICK) |
| | | }) |
| | | |
| | | const titleBox = viewUtils.title(screenMain, configView.screenMain, 'networkSettingViewTitle', 'networkSettingView.title') |
| | | titleBox.align(dxui.Utils.ALIGN.TOP_MID, 0, 70) |
| | | |
| | | |
| | | const networkSettingBox = dxui.View.build('networkSettingBox', screenMain) |
| | | viewUtils._clearStyle(networkSettingBox) |
| | | networkSettingBox.setSize(screen.screenSize.width, 830) |
| | | networkSettingBox.bgColor(0xeeeeee) |
| | | networkSettingBox.align(dxui.Utils.ALIGN.TOP_MID, 0, 142) |
| | | networkSettingBox.borderWidth(1) |
| | | networkSettingBox.setBorderColor(0xDEDEDE) |
| | | networkSettingBox.obj.setStyleBorderSide(dxui.Utils.ENUM.LV_BORDER_SIDE_TOP, 0) |
| | | networkSettingBox.bgOpa(0) |
| | | networkSettingBox.flexFlow(dxui.Utils.FLEX_FLOW.ROW_WRAP) |
| | | networkSettingBox.flexAlign(dxui.Utils.FLEX_ALIGN.CENTER, dxui.Utils.FLEX_ALIGN.START, dxui.Utils.FLEX_ALIGN.START) |
| | | networkSettingBox.obj.lvObjSetStylePadGap(0, dxui.Utils.ENUM._LV_STYLE_STATE_CMP_SAME) |
| | | |
| | | networkSettingView.netInfo = [ |
| | | { |
| | | title: 'networkSettingView.type', |
| | | value: [i18n.t('networkSettingView.ethernet'), i18n.t('networkSettingView.wifi'), i18n.t('networkSettingView._4G')], |
| | | type: 'dropdown', |
| | | obj: null, |
| | | dropdown: null |
| | | }, |
| | | { |
| | | title: 'networkSettingView.wifiName', |
| | | value: [], |
| | | type: 'dropdown', |
| | | obj: null, |
| | | dropdown: null |
| | | }, |
| | | { |
| | | title: 'networkSettingView.wifiPwd', |
| | | value: null, |
| | | type: 'input', |
| | | obj: null |
| | | }, |
| | | { |
| | | title: 'networkSettingView.dhcp', |
| | | value: null, |
| | | type: 'switch', |
| | | obj: null |
| | | }, |
| | | { |
| | | title: 'networkSettingView.ip', |
| | | value: null, |
| | | type: 'input', |
| | | obj: null |
| | | }, |
| | | { |
| | | title: 'networkSettingView.mask', |
| | | value: null, |
| | | type: 'input', |
| | | obj: null |
| | | }, |
| | | { |
| | | title: 'networkSettingView.gateway', |
| | | value: null, |
| | | type: 'input', |
| | | obj: null |
| | | }, |
| | | { |
| | | title: 'networkSettingView.dns', |
| | | value: null, |
| | | type: 'input', |
| | | obj: null |
| | | }, |
| | | { |
| | | title: 'networkSettingView.dns2', |
| | | value: null, |
| | | type: 'input', |
| | | obj: null |
| | | }, |
| | | { |
| | | title: 'networkSettingView.mac', |
| | | value: 'DC-87-F2-97-3B-26', |
| | | type: 'label', |
| | | obj: null, |
| | | label: null |
| | | }, |
| | | { |
| | | title: 'networkSettingView.status', |
| | | value: i18n.t('networkSettingView.networkUnconnected'), |
| | | type: 'label', |
| | | obj: null, |
| | | label: null |
| | | } |
| | | ] |
| | | |
| | | networkSettingView.netInfo.forEach((item, index) => { |
| | | const networkSettingItem = dxui.View.build(networkSettingBox.id + item.title, networkSettingBox) |
| | | viewUtils._clearStyle(networkSettingItem) |
| | | item.obj = networkSettingItem |
| | | networkSettingItem.setSize(760, 76) |
| | | networkSettingItem.bgColor(0xffffff) |
| | | networkSettingItem.borderWidth(1) |
| | | networkSettingItem.setBorderColor(0xDEDEDE) |
| | | networkSettingItem.obj.setStyleBorderSide(dxui.Utils.ENUM.LV_BORDER_SIDE_BOTTOM, 0) |
| | | |
| | | const title = dxui.Label.build(item.title, networkSettingItem) |
| | | title.textFont(viewUtils.font(26)) |
| | | title.align(dxui.Utils.ALIGN.LEFT_MID, 0, 0) |
| | | title.dataI18n = item.title |
| | | |
| | | |
| | | if (item.type === 'input') { |
| | | const input = viewUtils.input(networkSettingItem, item.title + 'input', undefined, undefined, 'networkSettingView.input') |
| | | input.align(dxui.Utils.ALIGN.RIGHT_MID, 0, 0) |
| | | input.setSize(400, 60) |
| | | item.input = input |
| | | } |
| | | |
| | | if (item.type === 'switch') { |
| | | const __switch = dxui.Switch.build(item.title + 'switch', networkSettingItem) |
| | | __switch.align(dxui.Utils.ALIGN.RIGHT_MID, 0, 0) |
| | | __switch.setSize(70, 35) |
| | | item.switch = __switch |
| | | } |
| | | |
| | | if (item.type === 'dropdown') { |
| | | const dropdown = dxui.Dropdown.build(item.title + 'dropdown', networkSettingItem) |
| | | dropdown.align(dxui.Utils.ALIGN.RIGHT_MID, 0, 0) |
| | | dropdown.setSize(200, 60) |
| | | dropdown.textFont(viewUtils.font(26)) |
| | | dropdown.getList().textFont(viewUtils.font(26)) |
| | | dropdown.setSymbol('/app/code/resource/image/down.png') |
| | | dropdown.setOptions(item.value) |
| | | item.dropdown = dropdown |
| | | |
| | | if (item.title === 'networkSettingView.type') { |
| | | dropdown.on(dxui.Utils.EVENT.VALUE_CHANGED, () => { |
| | | networkSettingView.changeNetType(dropdown.getSelected()) |
| | | if(dropdown.getSelected() == 2) { |
| | | // screen.switchNetworkType(dropdown.getSelected() + 2) |
| | | } else { |
| | | screen.switchNetworkType(dropdown.getSelected() + 1) |
| | | } |
| | | }) |
| | | } |
| | | |
| | | if (item.title === 'networkSettingView.wifiName') { |
| | | dropdown.on(dxui.Utils.EVENT.CLICK, () => { |
| | | screen.netGetWifiSsidList() |
| | | wifiList.refresh() |
| | | wifiListBoxbg.moveForeground() |
| | | wifiListBoxbg.show() |
| | | }) |
| | | } |
| | | } |
| | | |
| | | if (item.type === 'label') { |
| | | const label = dxui.Label.build(item.title + 'label', networkSettingItem) |
| | | label.textFont(viewUtils.font(26)) |
| | | label.align(dxui.Utils.ALIGN.RIGHT_MID, 0, 0) |
| | | label.text(item.value) |
| | | label.textColor(0x333333) |
| | | item.label = label |
| | | } |
| | | |
| | | }) |
| | | |
| | | // wifiå表 |
| | | const wifiListBoxbg = dxui.View.build('wifiListBoxbg', screenMain) |
| | | viewUtils._clearStyle(wifiListBoxbg) |
| | | wifiListBoxbg.setSize(screen.screenSize.width, screen.screenSize.height) |
| | | wifiListBoxbg.bgColor(0x000000) |
| | | wifiListBoxbg.bgOpa(50) |
| | | wifiListBoxbg.hide() |
| | | wifiListBoxbg.on(dxui.Utils.EVENT.CLICK, () => { |
| | | wifiListBoxClose.send(dxui.Utils.EVENT.CLICK) |
| | | }) |
| | | |
| | | const wifiListBox = dxui.View.build('wifiListBox', wifiListBoxbg) |
| | | viewUtils._clearStyle(wifiListBox) |
| | | wifiListBox.setSize(520, 560) |
| | | wifiListBox.bgColor(0xffffff) |
| | | wifiListBox.radius(20) |
| | | wifiListBox.align(dxui.Utils.ALIGN.CENTER, 0, 0) |
| | | |
| | | const wifiListBoxTitle = dxui.Label.build('wifiListBoxTitle', wifiListBox) |
| | | wifiListBoxTitle.textFont(viewUtils.font(28)) |
| | | wifiListBoxTitle.align(dxui.Utils.ALIGN.TOP_MID, 0, 32) |
| | | wifiListBoxTitle.dataI18n = 'networkSettingView.wifiList' |
| | | |
| | | const wifiListBoxClose = viewUtils.imageBtn(wifiListBox, 'wifiListBoxClose', '/app/code/resource/image/close_small.png') |
| | | wifiListBoxClose.align(dxui.Utils.ALIGN.TOP_RIGHT, -36, 30) |
| | | wifiListBoxClose.on(dxui.Utils.EVENT.CLICK, () => { |
| | | wifiListBoxbg.hide() |
| | | }) |
| | | |
| | | const closeBtn = dxui.Button.build('closeBtn', wifiListBox) |
| | | closeBtn.setSize(172, 50) |
| | | closeBtn.radius(10) |
| | | closeBtn.bgColor(0xEAEAEA) |
| | | closeBtn.align(dxui.Utils.ALIGN.BOTTOM_LEFT, 69, -53) |
| | | closeBtn.on(dxui.Utils.EVENT.CLICK, () => { |
| | | wifiListBoxClose.send(dxui.Utils.EVENT.CLICK) |
| | | }) |
| | | |
| | | const closeBtnText = dxui.Label.build('closeBtnText', closeBtn) |
| | | closeBtnText.textFont(viewUtils.font(24)) |
| | | closeBtnText.dataI18n = 'networkSettingView.close' |
| | | closeBtnText.align(dxui.Utils.ALIGN.CENTER, 0, 0) |
| | | closeBtnText.textColor(0x000000) |
| | | |
| | | const confirmBtn = dxui.Button.build('confirmBtn', wifiListBox) |
| | | confirmBtn.setSize(172, 50) |
| | | confirmBtn.radius(10) |
| | | confirmBtn.bgColor(0x000000) |
| | | confirmBtn.align(dxui.Utils.ALIGN.BOTTOM_RIGHT, -69, -53) |
| | | confirmBtn.on(dxui.Utils.EVENT.CLICK, () => { |
| | | wifiListBoxClose.send(dxui.Utils.EVENT.CLICK) |
| | | networkSettingView.netInfo[1].dropdown.setOptions([networkSettingView.selectedValue]) |
| | | }) |
| | | |
| | | const confirmBtnText = dxui.Label.build('confirmBtnText', confirmBtn) |
| | | confirmBtnText.textFont(viewUtils.font(24)) |
| | | confirmBtnText.dataI18n = 'networkSettingView.confirm' |
| | | confirmBtnText.align(dxui.Utils.ALIGN.CENTER, 0, 0) |
| | | confirmBtnText.textColor(0xffffff) |
| | | networkSettingView.wifiListData = [] |
| | | networkSettingView.selectedValue = '' |
| | | networkSettingView.selectedItem = 0 |
| | | |
| | | const wifiList = viewUtils.cycleList(wifiListBox, 'wifiList', [440, 300], 5, (item) => { |
| | | const wifiItemLbl = dxui.Label.build(item.id + 'wifiItemLbl', item) |
| | | wifiItemLbl.align(dxui.Utils.ALIGN.LEFT_MID, 25, 0) |
| | | wifiItemLbl.textFont(viewUtils.font(26)) |
| | | wifiItemLbl.textColor(0x888888) |
| | | wifiItemLbl.width(300) |
| | | wifiItemLbl.longMode(dxui.Utils.LABEL_LONG_MODE.SCROLL_CIRCULAR) |
| | | item.radius(10) |
| | | item.on(dxui.Utils.EVENT.CLICK, () => { |
| | | if (networkSettingView.selectedItem) { |
| | | networkSettingView.selectedItem.bgOpa(0) |
| | | } |
| | | networkSettingView.selectedItem = item |
| | | networkSettingView.selectedValue = wifiItemLbl.text() |
| | | item.bgColor(0xEAEAEA) |
| | | item.bgOpa(100) |
| | | }) |
| | | |
| | | const wifiItemImg = dxui.Image.build(item.id + 'wifi', item) |
| | | wifiItemImg.align(dxui.Utils.ALIGN.RIGHT_MID, -24, 0) |
| | | wifiItemImg.source('/app/code/resource/image/wifi.png') |
| | | |
| | | const lockItemImg = dxui.Image.build(item.id + 'lock', item) |
| | | lockItemImg.align(dxui.Utils.ALIGN.RIGHT_MID, -55, 0) |
| | | lockItemImg.source('/app/code/resource/image/lock.png') |
| | | |
| | | return { wifiItemLbl, wifiItemImg, lockItemImg } |
| | | }, (userdata, index) => { |
| | | const txt = networkSettingView.wifiListData[Math.abs((index % 5))] |
| | | if (txt) { |
| | | userdata.wifiItemLbl.text(txt) |
| | | userdata.wifiItemImg.show() |
| | | userdata.lockItemImg.show() |
| | | } else { |
| | | userdata.wifiItemLbl.text(' ') |
| | | userdata.wifiItemImg.hide() |
| | | userdata.lockItemImg.hide() |
| | | } |
| | | }) |
| | | wifiList.align(dxui.Utils.ALIGN.TOP_MID, 0, 110) |
| | | wifiList.bgOpa(0) |
| | | networkSettingView.wifiList = wifiList |
| | | |
| | | const saveBtn = viewUtils.bottomBtn(screenMain, screenMain.id + 'saveBtn', 'networkSettingView.save', () => { |
| | | // è·åWiFi SSIDï¼ä¼å
使ç¨ä¸æéæ©çå¼ï¼å¦ææ²¡æå使ç¨é
ç½®ä¸çå¼ |
| | | let wifiSsid = networkSettingView.selectedValue || "" |
| | | |
| | | let saveConfigData = { |
| | | "net": { |
| | | "type": networkSettingView.netInfo[0].dropdown.getSelected() + 1, |
| | | "dhcp": networkSettingView.netInfo[3].switch.isSelect() ? 2 : 1, |
| | | "ip": networkSettingView.netInfo[4].input.text(), |
| | | "mask": networkSettingView.netInfo[5].input.text(), |
| | | "gateway": networkSettingView.netInfo[6].input.text(), |
| | | "dns": networkSettingView.netInfo[7].input.text() + ',' + networkSettingView.netInfo[8].input.text(), |
| | | "psk": networkSettingView.netInfo[2].input.text(), |
| | | "ssid": wifiSsid |
| | | } |
| | | } |
| | | if (!networkSettingView.netInfo[3].switch.isSelect()) { |
| | | // éæip |
| | | if (networkSettingView.netInfo[0].dropdown.getSelected() + 1 == 1) { |
| | | // ä»¥å¤ªç½ |
| | | saveConfigData = { |
| | | "net": { |
| | | "type": networkSettingView.netInfo[0].dropdown.getSelected() + 1, |
| | | "dhcp": networkSettingView.netInfo[3].switch.isSelect() ? 2 : 1, |
| | | "ip": networkSettingView.netInfo[4].input.text(), |
| | | "mask": networkSettingView.netInfo[5].input.text(), |
| | | "gateway": networkSettingView.netInfo[6].input.text(), |
| | | "dns": networkSettingView.netInfo[7].input.text() + ',' + networkSettingView.netInfo[8].input.text(), |
| | | } |
| | | } |
| | | } else if (networkSettingView.netInfo[0].dropdown.getSelected() + 1 == 2) { |
| | | // WIFI |
| | | saveConfigData = { |
| | | "net": { |
| | | "type": networkSettingView.netInfo[0].dropdown.getSelected() + 1, |
| | | "dhcp": networkSettingView.netInfo[3].switch.isSelect() ? 2 : 1, |
| | | "ip": networkSettingView.netInfo[4].input.text(), |
| | | "mask": networkSettingView.netInfo[5].input.text(), |
| | | "gateway": networkSettingView.netInfo[6].input.text(), |
| | | "dns": networkSettingView.netInfo[7].input.text() + ',' + networkSettingView.netInfo[8].input.text(), |
| | | "psk": networkSettingView.netInfo[2].input.text(), |
| | | "ssid": wifiSsid |
| | | } |
| | | } |
| | | } else { |
| | | //4G |
| | | saveConfigData = { |
| | | "net": { |
| | | "type": 4, |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | // 卿ip |
| | | if (networkSettingView.netInfo[0].dropdown.getSelected() + 1 == 1) { |
| | | // ä»¥å¤ªç½ |
| | | saveConfigData = { |
| | | "net": { |
| | | "type": networkSettingView.netInfo[0].dropdown.getSelected() + 1, |
| | | "dhcp": networkSettingView.netInfo[3].switch.isSelect() ? 2 : 1, |
| | | } |
| | | } |
| | | } else if (networkSettingView.netInfo[0].dropdown.getSelected() + 1 == 2) { |
| | | // WIFI |
| | | saveConfigData = { |
| | | "net": { |
| | | "type": networkSettingView.netInfo[0].dropdown.getSelected() + 1, |
| | | "dhcp": networkSettingView.netInfo[3].switch.isSelect() ? 2 : 1, |
| | | "psk": networkSettingView.netInfo[2].input.text(), |
| | | "ssid": wifiSsid |
| | | } |
| | | } |
| | | } else { |
| | | //4G |
| | | saveConfigData = { |
| | | "net": { |
| | | "type": 4, |
| | | } |
| | | } |
| | | } |
| | | } |
| | | const res = screen.saveConfig(saveConfigData) |
| | | if (res === true) { |
| | | networkSettingView.statusPanel.success() |
| | | std.setTimeout(() => { |
| | | // æåè¿åä¸ä¸å±çé¢ |
| | | dxui.loadMain(configView.screenMain) |
| | | }, 500) |
| | | } else { |
| | | networkSettingView.statusPanel.fail() |
| | | } |
| | | }) |
| | | saveBtn.align(dxui.Utils.ALIGN.BOTTOM_MID, 0, -83) |
| | | |
| | | networkSettingView.changeNetType(0) |
| | | |
| | | networkSettingView.statusPanel = viewUtils.statusPanel(screenMain, 'networkSettingView.success', 'networkSettingView.fail') |
| | | } |
| | | |
| | | // 0:ä»¥å¤ªç½ 1:wifi 3:4G |
| | | networkSettingView.changeNetType = function (type) { |
| | | if (type === 0) { |
| | | networkSettingView.netInfo[1].obj.hide() |
| | | networkSettingView.netInfo[2].obj.hide() |
| | | networkSettingView.netInfo[3].obj.show() |
| | | networkSettingView.netInfo[4].obj.show() |
| | | networkSettingView.netInfo[5].obj.show() |
| | | networkSettingView.netInfo[6].obj.show() |
| | | networkSettingView.netInfo[7].obj.show() |
| | | networkSettingView.netInfo[8].obj.show() |
| | | } else if (type === 1) { |
| | | networkSettingView.netInfo[1].obj.show() |
| | | networkSettingView.netInfo[2].obj.show() |
| | | networkSettingView.netInfo[3].obj.show() |
| | | networkSettingView.netInfo[4].obj.show() |
| | | networkSettingView.netInfo[5].obj.show() |
| | | networkSettingView.netInfo[6].obj.show() |
| | | networkSettingView.netInfo[7].obj.show() |
| | | networkSettingView.netInfo[8].obj.show() |
| | | } else { |
| | | networkSettingView.netInfo[1].obj.hide() |
| | | networkSettingView.netInfo[2].obj.hide() |
| | | networkSettingView.netInfo[3].obj.hide() |
| | | networkSettingView.netInfo[4].obj.hide() |
| | | networkSettingView.netInfo[5].obj.hide() |
| | | networkSettingView.netInfo[6].obj.hide() |
| | | networkSettingView.netInfo[7].obj.hide() |
| | | networkSettingView.netInfo[8].obj.hide() |
| | | } |
| | | } |
| | | |
| | | export default networkSettingView |
| vf205_access/src/view/config/menu/recordQuery/recordQueryDetailView.js
vf205_access/src/view/config/menu/recordQueryView.js
vf205_access/src/view/config/menu/systemSetting/displaySettingView.js
vf205_access/src/view/config/menu/systemSetting/faceRecognitionSettingView.js
vf205_access/src/view/config/menu/systemSetting/passLogSettingView.js
vf205_access/src/view/config/menu/systemSetting/passwordManagementView.js
vf205_access/src/view/config/menu/systemSetting/passwordOpenDoorSettingView.js
vf205_access/src/view/config/menu/systemSetting/swipeCardRecognitionSettingView.js
vf205_access/src/view/config/menu/systemSetting/timeSettingView.js
vf205_access/src/view/config/menu/systemSettingView.js
vf205_access/src/view/config/menu/voiceBroadcastView.js
vf205_access/src/view/config/newPwdView.js
vf205_access/src/view/emergencyPwdView.js
vf205_access/src/view/i18n.js
vf205_access/src/view/idleView.js
vf205_access/src/view/mainView.js
vf205_access/src/view/pinyin/dict.js
vf205_access/src/view/pinyin/pinyin.js
vf205_access/src/view/pwdView.js
vf205_access/src/view/topView.js
vf205_access/src/view/viewUtils.js |