code_device/hgdriver/hgdev/hg_scanner_239.cpp

2205 lines
128 KiB
C++
Raw Normal View History

2023-11-23 03:09:31 +00:00
#include "hg_scanner_239.h"
#include "../wrapper/hg_log.h"
2022-05-03 03:56:07 +00:00
#include "filetools.h"
#if defined(WIN32) || defined(_WIN64)
2022-05-03 03:56:07 +00:00
#include "scanner_manager.h"
#endif
2022-11-23 07:39:13 +00:00
//100 200 3399
static std::string jsontext1("{\"global\":{\"device_type\":\"G139-G239\",\"option_count\":79},\"restore\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"none\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u6062\\u590d\\u9ed8\\u8ba4\\u8bbe\\u7f6e\",\"desc\":\"\\u6062\\u590d\\u9ed8\\u8ba4\\u8bbe\\u7f6e\",\"type\":\"button\",\"cur\":\"button\",\"default\":\"button\",\"size\":0},\"help\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"none\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u5e2e\\u52a9\",\"desc\":\"\\u663e\\u793a\\u8f6f\\u4ef6\\u5e2e\\u52a9\\u6587\\u6863\",\"type\":\"button\",\"cur\":\"true\",\"default\":\"true\",\"size\":4},\"grp-1\":{\"cat\":\"base\",\"title\":\"\\u57fa\\u672c\\u8bbe\\u7f6e\",\"type\":\"group\",\"readonly\":false,\"affect\":0,\"group\":\"base\",\"field\":\"Common\",\"pos\":0,\"visible\":true,\"unit\":\"None\"},\"is-multiout\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"base\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u591a\\u6d41\\u8f93\\u51fa\",\"desc\":\"\\u540c\\u65f6\\u8f93\\u51fa\\u591a\\u79cd\\u989c\\u8272\\u6a21\\u5f0f\\u7684\\u56fe\\u50cf\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4},\"multiout-type\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"base\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u591a\\u6d41\\u8f93\\u51fa\\u7c7b\\u578b\",\"desc\":\"\\u9009\\u62e9\\u591a\\u6d41\\u8f93\\u51fa\\u7684\\u7c7b\\u578b\",\"type\":\"string\",\"cur\":\"\\u5f69\\u8272+\\u7070\\u5ea6+\\u9ed1\\u767d\",\"default\":\"\\u5f69\\u8272+\\u7070\\u5ea6+\\u9ed1\\u767d\",\"size\":32,\"range\":[\"\\u5f69\\u8272+\\u7070\\u5ea6+\\u9ed1\\u767d\",\"\\u5f69\\u8272+\\u7070\\u5ea6\",\"\\u5f69\\u8272+\\u9ed1\\u767d\",\"\\u7070\\u5ea6+\\u9ed1\\u767d\"],\"depend_or\":[\"is-multiout==true\"]},\"mode\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"base\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u989c\\u8272\\u6a21\\u5f0f\",\"desc\":\"\\u9009\\u62e9\\u8272\\u5f69\\u6a21\\u5f0f\",\"type\":\"string\",\"cur\":\"24\\u4f4d\\u5f69\\u8272\",\"default\":\"24\\u4f4d\\u5f69\\u8272\",\"size\":32,\"range\":[\"24\\u4f4d\\u5f69\\u8272\",\"256\\u7ea7\\u7070\\u5ea6\",\"\\u9ed1\\u767d\",\"\\u989c\\u8272\\u81ea\\u52a8\\u8bc6\\u522b\"],\"depend_or\":[\"is-multiout!=true\"]},\"binary-threshold\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"base\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u9ed1\\u767d\\u56fe\\u50cf\\u9608\\u503c\",\"desc\":\"\\u9ad8\\u4e8e\\u8be5\\u9608\\u503c\\u4e3a1\\uff08\\u767d\\uff09\\uff0c\\u4f4e\\u4e8e\\u8be5\\u9608\\u503c\\u4e3a0\\uff08\\u9ed1\\uff09\",\"type\":\"int\",\"cur\":127,\"default\":127,\"size\":4,\"range\":{\"min\":0,\"max\":255,\"step\":1},\"depend_or\":[\"multiout-type!=\\u5f69\\u8272+\\u7070\\u5ea6\",\"mode==\\u9ed1\\u767d\"]},\"reverse-bw\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"base\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u9ed1\\u767d\\u56fe\\u50cf\\u53cd\\u8272\\u8f93\\u51fa\",\"desc\":\"\\u8f93\\u51fa\\u7684\\u9ed1\\u767d\\u56fe\\u50cf\\u4ee5\\u201c1\\u201d\\u4ee3\\u8868\\u9ed1\\u8272\\uff0c\\u201c0\\u201d\\u4ee3\\u8868\\u767d\\u8272\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4,\"depend_or\":[\"multiout-type!=\\u5f69\\u8272+\\u7070\\u5ea6\",\"mode==\\u9ed1\\u767d\"]},\"filter\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"base\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u7070\\u5ea6\\u6216\\u9ed1\\u767d\\u56fe\\u50cf - \\u9664\\u8272\\u4e0e\\u589e\\u5f3a\",\"desc\":\"\\u6d88\\u9664\\u6216\\u589e\\u5f3a\\u6307\\u5b9a\\u8272\\u5f69\",\"type\":\"string\",\"cur\":\"\\u4e0d\\u9664\\u8272\",\"default\":\"\\u4e0d\\u9664\\u8272\",\"size\":24,\"range\":[\"\\u4e0d\\u9664\\u8272\",\"\\u9664\\u7ea2\\u8272\",\"\\u9664\\u7eff\\u8272\",\"\\u9664\\u8
static std::string jsontext2("u57df\\u5de6\\u4e0a\\u89d2y\\u5750\\u6807\",\"type\":\"float\",\"cur\":0.000000,\"default\":0.000000,\"size\":4,\"range\":{\"min\":0.000000,\"max\":297.000000,\"step\":29.700000},\"depend_and\":[\"is-custom-area==true\"]},\"br-y\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"base\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u626b\\u63cf\\u533a\\u57df\\u4e0b\\u4fa7\\uff08mm\\uff09\",\"desc\":\"\\u81ea\\u5b9a\\u4e49\\u626b\\u63cf\\u533a\\u57df\\u53f3\\u4e0b\\u89d2y\\u5750\\u6807\",\"type\":\"float\",\"cur\":297.000000,\"default\":297.000000,\"size\":4,\"range\":{\"min\":0.000000,\"max\":297.000000,\"step\":29.700000},\"depend_and\":[\"is-custom-area==true\"]},\"is-size-check\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"base\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u5c3a\\u5bf8\\u68c0\\u6d4b\",\"desc\":\"\\u68c0\\u6d4b\\u7eb8\\u5f20\\u5b9e\\u9645\\u5c3a\\u5bf8\\u4e0e\\u8bbe\\u7f6e\\u662f\\u5426\\u5339\\u914d\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4,\"depend_or\":[\"paper==A3\",\"==A4\",\"==A4\\u6a2a\\u5411\",\"==A5\",\"==A5\\u6a2a\\u5411\",\"==A6\",\"==A6\\u6a2a\\u5411\",\"==B4\",\"==B5\",\"==B5\\u6a2a\\u5411\",\"==B6\",\"==B6\\u6a2a\\u5411\",\"==Double Letter\",\"==LEGAL\",\"==Letter\",\"==Letter\\u6a2a\\u5411\"]},\"page\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"base\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u626b\\u63cf\\u9875\\u9762\",\"desc\":\"\\u8bbe\\u7f6e\\u9875\\u9762\\u626b\\u63cf\\u65b9\\u5f0f\",\"type\":\"string\",\"cur\":\"\\u53cc\\u9762\",\"default\":\"\\u53cc\\u9762\",\"size\":40,\"range\":[\"\\u5355\\u9762\",\"\\u53cc\\u9762\",\"\\u8df3\\u8fc7\\u7a7a\\u767d\\u9875\\uff08\\u901a\\u7528\\uff09\",\"\\u8df3\\u8fc7\\u7a7a\\u767d\\u9875\\uff08\\u53d1\\u7968\\u7eb8\\uff09\",\"\\u5bf9\\u6298\"]},\"discardblank\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"base\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u8df3\\u8fc7\\u7a7a\\u767d\\u9875\",\"desc\":\"\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4,\"depend_or\":[\"page!=\\u5bf9\\u6298\"]},\"blank-sensitivity\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"base\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\" \\u8df3\\u8fc7\\u7a7a\\u767d\\u9875\\u7075\\u654f\\u5ea6\",\"desc\":\"\\u6570\\u503c\\u8d8a\\u5927\\uff0c\\u5219\\u8d8a\\u5bb9\\u6613\\u8df3\\u8fc7\",\"type\":\"int\",\"cur\":30,\"default\":30,\"size\":4,\"range\":{\"min\":1,\"max\":100,\"step\":1},\"depend_or\":[\"page==\\u8df3\\u8fc7\\u7a7a\\u767d\\u9875\\uff08\\u53d1\\u7968\\u7eb8\\uff09\",\"==\\u8df3\\u8fc7\\u7a7a\\u767d\\u9875\\uff08\\u901a\\u7528\\uff09\",\"discardblank==true\"]},\"fold-type\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"base\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u5bf9\\u6298\\u6a21\\u5f0f\",\"desc\":\"\",\"type\":\"string\",\"cur\":\"\\u5de6\\u53f3\\u5bf9\\u6298\",\"default\":\"\\u5de6\\u53f3\\u5bf9\\u6298\",\"size\":50,\"range\":[\"\\u5de6\\u53f3\\u5bf9\\u6298\",\"\\u4e0a\\u4e0b\\u5bf9\\u6298\",\"\\u81ea\\u52a8\\u5bf9\\u6298\"],\"depend_or\":[\"page==\\u5bf9\\u6298\"]},\"resolution\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"base\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u5206\\u8fa8\\u7387\",\"desc\":\"\\u8bbe\\u7f6e\\u626b\\u63cf\\u56fe\\u50cf\\u7684\\u5206\\u8fa8\\u7387\",\"type\":\"int\",\"cur\":200,\"default\":200,\"size\":4,\"range\":{\"min\":100,\"max\":600,\"step\":1}},\"image-quality\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"base\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u753b\\u8d28\",\"desc\":\"\\u9009\\u62e9\\u626b\\u63cf\\u4eea\\u7684\\u753b\\u8d28\\u6a21\\u5f0f\",\"type\":\"string\",\"cur\":\"\\u753b\\u8d28\\u4f18\\u5148\",\"default\":\"\\u753b\\u8d28\\
static std::string jsontext3("ly\":false,\"affect\":0,\"group\":\"imgproc\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\" \\u9632\\u6b62\\u6e17\\u900f\\u7b49\\u7ea7\",\"desc\":\"\\u9009\\u62e9\\u9632\\u6b62\\u6e17\\u900f\\u7684\\u7b49\\u7ea7\",\"type\":\"string\",\"cur\":\"\\u8f83\\u5f31\",\"default\":\"\\u8f83\\u5f31\",\"size\":16,\"range\":[\"\\u5f31\",\"\\u8f83\\u5f31\",\"\\u4e00\\u822c\",\"\\u8f83\\u5f3a\",\"\\u5f3a\"],\"depend_or\":[\"is-anti-permeate==true\"]},\"is-rid-hole-l\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"imgproc\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u7a7f\\u5b54\\u79fb\\u9664\\u2014\\u5de6\\u4fa7\",\"desc\":\"\\u7a7f\\u5b54\\u5728\\u7eb8\\u5f20\\u4e0a\\u7684\\u5de6\\u4fa7\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4},\"search-hole-range-l\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"imgproc\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\" \\u5de6\\u4fa7\\u7a7f\\u5b54\\u641c\\u7d22\\u8303\\u56f4\\u5360\\u5e45\\u9762\\u6bd4\\u4f8b\",\"desc\":\"\\u7a7f\\u5b54\\u641c\\u7d22\\u8303\\u56f4\\u5360\\u5e45\\u9762\\u6bd4\\u4f8b\",\"type\":\"float\",\"cur\":0.100000,\"default\":0.100000,\"size\":4,\"range\":{\"min\":0.000000,\"max\":0.500000,\"step\":0.050000},\"depend_and\":[\"is-rid-hole-l==true\"]},\"is-rid-hole-r\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"imgproc\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u7a7f\\u5b54\\u79fb\\u9664\\u2014\\u53f3\\u4fa7\",\"desc\":\"\\u7a7f\\u5b54\\u5728\\u7eb8\\u5f20\\u4e0a\\u7684\\u53f3\\u4fa7\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4},\"search-hole-range-r\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"imgproc\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\" \\u53f3\\u4fa7\\u7a7f\\u5b54\\u641c\\u7d22\\u8303\\u56f4\\u5360\\u5e45\\u9762\\u6bd4\\u4f8b\",\"desc\":\"\\u7a7f\\u5b54\\u641c\\u7d22\\u8303\\u56f4\\u5360\\u5e45\\u9762\\u6bd4\\u4f8b\",\"type\":\"float\",\"cur\":0.100000,\"default\":0.100000,\"size\":4,\"range\":{\"min\":0.000000,\"max\":0.500000,\"step\":0.050000},\"depend_and\":[\"is-rid-hole-r==true\"]},\"is-rid-hole-t\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"imgproc\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u7a7f\\u5b54\\u79fb\\u9664\\u2014\\u4e0a\\u4fa7\",\"desc\":\"\\u7a7f\\u5b54\\u5728\\u7eb8\\u5f20\\u7684\\u4e0a\\u90e8\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4},\"search-hole-range-t\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"imgproc\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\" \\u4e0a\\u4fa7\\u7a7f\\u5b54\\u641c\\u7d22\\u8303\\u56f4\\u5360\\u5e45\\u9762\\u6bd4\\u4f8b\",\"desc\":\"\\u7a7f\\u5b54\\u641c\\u7d22\\u8303\\u56f4\\u5360\\u5e45\\u9762\\u6bd4\\u4f8b\",\"type\":\"float\",\"cur\":0.100000,\"default\":0.100000,\"size\":4,\"range\":{\"min\":0.000000,\"max\":0.500000,\"step\":0.050000},\"depend_and\":[\"is-rid-hole-t==true\"]},\"is-rid-hole-b\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"imgproc\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u7a7f\\u5b54\\u79fb\\u9664\\u2014\\u4e0b\\u4fa7\",\"desc\":\"\\u7a7f\\u5b54\\u5728\\u7eb8\\u5f20\\u7684\\u4e0b\\u90e8\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4},\"search-hole-range-b\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"imgproc\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\" \\u4e0b\\u4fa7\\u7a7f\\u5b54\\u641c\\u7d22\\u8303\\u56f4\\u5360\\u5e45\\u9762\\u6bd4\\u4f8b\",\"desc\":\"\\u7a7f\\u5b54\\u641c\\u7d22\\u8303\\u56f4\\u5360\\u5e45\\u9762\\u6bd4\\u4f8b\",\"type\":\"float\",\"cur\":0.100000,\"default\":0.100000,\"size\":4,\"range\":{\"min\":0.000000,\"max\":0.500000,\"step\":0.050000},\"depend_and\":[\"is-rid-hole-b==true\"]},\"grp
static std::string jsontext4("34a\\u5c0f\\u65f6\",\"\\u4e00\\u5c0f\\u65f6\",\"\\u4e24\\u5c0f\\u65f6\",\"\\u56db\\u5c0f\\u65f6\"]}}");
2022-08-08 10:15:51 +00:00
2022-11-23 07:39:13 +00:00
//G439
static std::string jsontext5("{\"global\":{\"device_type\":\"G439\",\"option_count\":73},\"restore\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"none\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u6062\\u590d\\u9ed8\\u8ba4\\u8bbe\\u7f6e\",\"desc\":\"\\u6062\\u590d\\u9ed8\\u8ba4\\u8bbe\\u7f6e\",\"type\":\"button\",\"cur\":\"button\",\"default\":\"button\",\"size\":0},\"help\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"none\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u5e2e\\u52a9\",\"desc\":\"\\u663e\\u793a\\u8f6f\\u4ef6\\u5e2e\\u52a9\\u6587\\u6863\",\"type\":\"button\",\"cur\":\"true\",\"default\":\"true\",\"size\":4},\"grp-1\":{\"cat\":\"base\",\"title\":\"\\u57fa\\u672c\\u8bbe\\u7f6e\",\"type\":\"group\",\"readonly\":false,\"affect\":0,\"group\":\"base\",\"field\":\"Common\",\"pos\":0,\"visible\":true,\"unit\":\"None\"},\"is-multiout\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"base\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u591a\\u6d41\\u8f93\\u51fa\",\"desc\":\"\\u540c\\u65f6\\u8f93\\u51fa\\u591a\\u79cd\\u989c\\u8272\\u6a21\\u5f0f\\u7684\\u56fe\\u50cf\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4},\"multiout-type\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"base\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u591a\\u6d41\\u8f93\\u51fa\\u7c7b\\u578b\",\"desc\":\"\\u9009\\u62e9\\u591a\\u6d41\\u8f93\\u51fa\\u7684\\u7c7b\\u578b\",\"type\":\"string\",\"cur\":\"\\u5f69\\u8272+\\u7070\\u5ea6+\\u9ed1\\u767d\",\"default\":\"\\u5f69\\u8272+\\u7070\\u5ea6+\\u9ed1\\u767d\",\"size\":32,\"range\":[\"\\u5f69\\u8272+\\u7070\\u5ea6+\\u9ed1\\u767d\",\"\\u5f69\\u8272+\\u7070\\u5ea6\",\"\\u5f69\\u8272+\\u9ed1\\u767d\",\"\\u7070\\u5ea6+\\u9ed1\\u767d\"],\"depend_or\":[\"is-multiout==true\"]},\"mode\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"base\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u989c\\u8272\\u6a21\\u5f0f\",\"desc\":\"\\u9009\\u62e9\\u8272\\u5f69\\u6a21\\u5f0f\",\"type\":\"string\",\"cur\":\"24\\u4f4d\\u5f69\\u8272\",\"default\":\"24\\u4f4d\\u5f69\\u8272\",\"size\":32,\"range\":[\"24\\u4f4d\\u5f69\\u8272\",\"256\\u7ea7\\u7070\\u5ea6\",\"\\u9ed1\\u767d\",\"\\u989c\\u8272\\u81ea\\u52a8\\u8bc6\\u522b\"],\"depend_or\":[\"is-multiout!=true\"]},\"binary-threshold\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"base\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u9ed1\\u767d\\u56fe\\u50cf\\u9608\\u503c\",\"desc\":\"\\u9ad8\\u4e8e\\u8be5\\u9608\\u503c\\u4e3a1\\uff08\\u767d\\uff09\\uff0c\\u4f4e\\u4e8e\\u8be5\\u9608\\u503c\\u4e3a0\\uff08\\u9ed1\\uff09\",\"type\":\"int\",\"cur\":127,\"default\":127,\"size\":4,\"range\":{\"min\":0,\"max\":255,\"step\":1},\"depend_or\":[\"multiout-type!=\\u5f69\\u8272+\\u7070\\u5ea6\",\"mode==\\u9ed1\\u767d\"]},\"reverse-bw\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"base\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u9ed1\\u767d\\u56fe\\u50cf\\u53cd\\u8272\\u8f93\\u51fa\",\"desc\":\"\\u8f93\\u51fa\\u7684\\u9ed1\\u767d\\u56fe\\u50cf\\u4ee5\\u201c1\\u201d\\u4ee3\\u8868\\u9ed1\\u8272\\uff0c\\u201c0\\u201d\\u4ee3\\u8868\\u767d\\u8272\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4,\"depend_or\":[\"multiout-type!=\\u5f69\\u8272+\\u7070\\u5ea6\",\"mode==\\u9ed1\\u767d\"]},\"filter\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"base\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u7070\\u5ea6\\u6216\\u9ed1\\u767d\\u56fe\\u50cf - \\u9664\\u8272\\u4e0e\\u589e\\u5f3a\",\"desc\":\"\\u6d88\\u9664\\u6216\\u589e\\u5f3a\\u6307\\u5b9a\\u8272\\u5f69\",\"type\":\"string\",\"cur\":\"\\u4e0d\\u9664\\u8272\",\"default\":\"\\u4e0d\\u9664\\u8272\",\"size\":24,\"range\":[\"\\u4e0d\\u9664\\u8272\",\"\\u9664\\u7ea2\\u8272\",\"\\u9664\\u7eff\\u8272\",\"\\u9664\\u84dd\\
static std::string jsontext6("df\\u5de6\\u4e0a\\u89d2y\\u5750\\u6807\",\"type\":\"float\",\"cur\":0.000000,\"default\":0.000000,\"size\":4,\"range\":{\"min\":0.000000,\"max\":297.000000,\"step\":29.700000},\"depend_and\":[\"is-custom-area==true\"]},\"br-y\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"base\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u626b\\u63cf\\u533a\\u57df\\u4e0b\\u4fa7\\uff08mm\\uff09\",\"desc\":\"\\u81ea\\u5b9a\\u4e49\\u626b\\u63cf\\u533a\\u57df\\u53f3\\u4e0b\\u89d2y\\u5750\\u6807\",\"type\":\"float\",\"cur\":297.000000,\"default\":297.000000,\"size\":4,\"range\":{\"min\":0.000000,\"max\":297.000000,\"step\":29.700000},\"depend_and\":[\"is-custom-area==true\"]},\"is-size-check\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"base\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u5c3a\\u5bf8\\u68c0\\u6d4b\",\"desc\":\"\\u68c0\\u6d4b\\u7eb8\\u5f20\\u5b9e\\u9645\\u5c3a\\u5bf8\\u4e0e\\u8bbe\\u7f6e\\u662f\\u5426\\u5339\\u914d\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4,\"depend_or\":[\"paper==A3\",\"==A4\",\"==A4\\u6a2a\\u5411\",\"==A5\",\"==A5\\u6a2a\\u5411\",\"==A6\",\"==A6\\u6a2a\\u5411\",\"==B4\",\"==B5\",\"==B5\\u6a2a\\u5411\",\"==B6\",\"==B6\\u6a2a\\u5411\",\"==Double Letter\",\"==LEGAL\",\"==Letter\",\"==Letter\\u6a2a\\u5411\"]},\"page\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"base\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u626b\\u63cf\\u9875\\u9762\",\"desc\":\"\\u8bbe\\u7f6e\\u9875\\u9762\\u626b\\u63cf\\u65b9\\u5f0f\",\"type\":\"string\",\"cur\":\"\\u53cc\\u9762\",\"default\":\"\\u53cc\\u9762\",\"size\":40,\"range\":[\"\\u5355\\u9762\",\"\\u53cc\\u9762\",\"\\u8df3\\u8fc7\\u7a7a\\u767d\\u9875\\uff08\\u901a\\u7528\\uff09\",\"\\u8df3\\u8fc7\\u7a7a\\u767d\\u9875\\uff08\\u53d1\\u7968\\u7eb8\\uff09\",\"\\u5bf9\\u6298\"]},\"discardblank\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"base\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u8df3\\u8fc7\\u7a7a\\u767d\\u9875\",\"desc\":\"\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4,\"depend_or\":[\"page!=\\u5bf9\\u6298\"]},\"blank-sensitivity\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"base\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\" \\u8df3\\u8fc7\\u7a7a\\u767d\\u9875\\u7075\\u654f\\u5ea6\",\"desc\":\"\\u6570\\u503c\\u8d8a\\u5927\\uff0c\\u5219\\u8d8a\\u5bb9\\u6613\\u8df3\\u8fc7\",\"type\":\"int\",\"cur\":30,\"default\":30,\"size\":4,\"range\":{\"min\":1,\"max\":100,\"step\":1},\"depend_or\":[\"page==\\u8df3\\u8fc7\\u7a7a\\u767d\\u9875\\uff08\\u53d1\\u7968\\u7eb8\\uff09\",\"==\\u8df3\\u8fc7\\u7a7a\\u767d\\u9875\\uff08\\u901a\\u7528\\uff09\",\"discardblank==true\"]},\"fold-type\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"base\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u5bf9\\u6298\\u6a21\\u5f0f\",\"desc\":\"\",\"type\":\"string\",\"cur\":\"\\u5de6\\u53f3\\u5bf9\\u6298\",\"default\":\"\\u5de6\\u53f3\\u5bf9\\u6298\",\"size\":50,\"range\":[\"\\u5de6\\u53f3\\u5bf9\\u6298\",\"\\u4e0a\\u4e0b\\u5bf9\\u6298\",\"\\u81ea\\u52a8\\u5bf9\\u6298\"],\"depend_or\":[\"page==\\u5bf9\\u6298\"]},\"resolution\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"base\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u5206\\u8fa8\\u7387\",\"desc\":\"\\u8bbe\\u7f6e\\u626b\\u63cf\\u56fe\\u50cf\\u7684\\u5206\\u8fa8\\u7387\",\"type\":\"int\",\"cur\":200,\"default\":200,\"size\":4,\"range\":{\"min\":100,\"max\":600,\"step\":1}},\"image-quality\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"base\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u753b\\u8d28\",\"desc\":\"\\u9009\\u62e9\\u626b\\u63cf\\u4eea\\u7684\\u753b\\u8d28\\u6a21\\u5f0f\",\"type\":\"string\",\"cur\":\"\\u753b\\u8d28\\u4f18\\u5148\",\"default\":\"\\u753b\\u8d28\\u4f
static std::string jsontext7("},\"permeate-level\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"imgproc\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\" \\u9632\\u6b62\\u6e17\\u900f\\u7b49\\u7ea7\",\"desc\":\"\\u9009\\u62e9\\u9632\\u6b62\\u6e17\\u900f\\u7684\\u7b49\\u7ea7\",\"type\":\"string\",\"cur\":\"\\u8f83\\u5f31\",\"default\":\"\\u8f83\\u5f31\",\"size\":16,\"range\":[\"\\u5f31\",\"\\u8f83\\u5f31\",\"\\u4e00\\u822c\",\"\\u8f83\\u5f3a\",\"\\u5f3a\"],\"depend_or\":[\"is-anti-permeate==true\"]},\"is-rid-hole-l\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"imgproc\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u7a7f\\u5b54\\u79fb\\u9664\\u2014\\u5de6\\u4fa7\",\"desc\":\"\\u7a7f\\u5b54\\u5728\\u7eb8\\u5f20\\u4e0a\\u7684\\u5de6\\u4fa7\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4},\"search-hole-range-l\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"imgproc\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\" \\u5de6\\u4fa7\\u7a7f\\u5b54\\u641c\\u7d22\\u8303\\u56f4\\u5360\\u5e45\\u9762\\u6bd4\\u4f8b\",\"desc\":\"\\u7a7f\\u5b54\\u641c\\u7d22\\u8303\\u56f4\\u5360\\u5e45\\u9762\\u6bd4\\u4f8b\",\"type\":\"float\",\"cur\":0.100000,\"default\":0.100000,\"size\":4,\"range\":[0.500000,0.050000,0.000000],\"depend_and\":[\"is-rid-hole-l==true\"]},\"is-rid-hole-r\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"imgproc\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u7a7f\\u5b54\\u79fb\\u9664\\u2014\\u53f3\\u4fa7\",\"desc\":\"\\u7a7f\\u5b54\\u5728\\u7eb8\\u5f20\\u4e0a\\u7684\\u53f3\\u4fa7\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4},\"search-hole-range-r\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"imgproc\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\" \\u53f3\\u4fa7\\u7a7f\\u5b54\\u641c\\u7d22\\u8303\\u56f4\\u5360\\u5e45\\u9762\\u6bd4\\u4f8b\",\"desc\":\"\\u7a7f\\u5b54\\u641c\\u7d22\\u8303\\u56f4\\u5360\\u5e45\\u9762\\u6bd4\\u4f8b\",\"type\":\"float\",\"cur\":0.100000,\"default\":0.100000,\"size\":4,\"range\":[0.500000,0.050000,0.000000],\"depend_and\":[\"is-rid-hole-r==true\"]},\"is-rid-hole-t\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"imgproc\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u7a7f\\u5b54\\u79fb\\u9664\\u2014\\u4e0a\\u4fa7\",\"desc\":\"\\u7a7f\\u5b54\\u5728\\u7eb8\\u5f20\\u7684\\u4e0a\\u90e8\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4},\"search-hole-range-t\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"imgproc\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\" \\u4e0a\\u4fa7\\u7a7f\\u5b54\\u641c\\u7d22\\u8303\\u56f4\\u5360\\u5e45\\u9762\\u6bd4\\u4f8b\",\"desc\":\"\\u7a7f\\u5b54\\u641c\\u7d22\\u8303\\u56f4\\u5360\\u5e45\\u9762\\u6bd4\\u4f8b\",\"type\":\"float\",\"cur\":0.100000,\"default\":0.100000,\"size\":4,\"range\":[0.500000,0.050000,0.000000],\"depend_and\":[\"is-rid-hole-t==true\"]},\"is-rid-hole-b\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"imgproc\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u7a7f\\u5b54\\u79fb\\u9664\\u2014\\u4e0b\\u4fa7\",\"desc\":\"\\u7a7f\\u5b54\\u5728\\u7eb8\\u5f20\\u7684\\u4e0b\\u90e8\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4},\"search-hole-range-b\":{\"cat\":\"base\",\"readonly\":false,\"affect\":0,\"group\":\"imgproc\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\" \\u4e0b\\u4fa7\\u7a7f\\u5b54\\u641c\\u7d22\\u8303\\u56f4\\u5360\\u5e45\\u9762\\u6bd4\\u4f8b\",\"desc\":\"\\u7a7f\\u5b54\\u641c\\u7d22\\u8303\\u56f4\\u5360\\u5e45\\u9762\\u6bd4\\u4f8b\",\"type\":\"float\",\"cur\":0.100000,\"default\":0.100000,\"size\":4,\"range\":[0.500000,0.050000,0.000000],\"depend_and\":[\"is-rid-hole-b==true\"]},\"grp-4\":{\"cat\":\"base\",\"title\":\"\\u9001\\u7eb8\\u6
2022-05-03 03:56:07 +00:00
namespace settings
{
scanner_err device_status_to_hg_err(setting3399::HGEIntInfo* ds)
2022-05-03 03:56:07 +00:00
{
scanner_err code = SCANNER_ERR_OK;
2022-05-03 03:56:07 +00:00
if (ds->From == setting3399::HGType::FPGA)
code = SCANNER_ERR_OK;
else if (ds->From == setting3399::HGType::MtBoard)
2022-05-03 03:56:07 +00:00
{
switch (ds->Code)
{
case 0x00002:
code = SCANNER_ERR_DEVICE_NO_PAPER;
2022-05-03 03:56:07 +00:00
break;
case 0x00004:
code = SCANNER_ERR_DEVICE_COVER_OPENNED;
2022-05-03 03:56:07 +00:00
break;
case 0x00008:
code = SCANNER_ERR_DEVICE_FEEDING_PAPER;
2022-05-03 03:56:07 +00:00
break;
case 0x00010:
code = SCANNER_ERR_DEVICE_PAPER_JAMMED;
2022-05-03 03:56:07 +00:00
break;
case 0x00020:
code = SCANNER_ERR_DEVICE_DOUBLE_FEEDING;
2022-05-03 03:56:07 +00:00
break;
case 0x00040:
code = SCANNER_ERR_DEVICE_STAPLE_ON;
2022-05-03 03:56:07 +00:00
break;
case 0x00080:
code = SCANNER_ERR_DEVICE_PAPER_SKEW;
2022-05-03 03:56:07 +00:00
break;
case 0x10000:
case 0x80000:
code = SCANNER_ERR_TIMEOUT;
2022-05-03 03:56:07 +00:00
break;
case 0x20000:
code = SCANNER_ERR_DEVICE_SIZE_CHECK;
2022-05-03 03:56:07 +00:00
break;
case 0x00100:
code = SCANNER_ERR_DEVICE_ISLOCK;
break;
2023-10-25 07:00:31 +00:00
case 0x100000:
code = SCANNER_ERR_DEVICE_LENS_DIRTY;
break;
2022-05-03 03:56:07 +00:00
default:
break;
}
}
else if (ds->From == setting3399::HGType::IMG)
2022-05-03 03:56:07 +00:00
{
if (ds->Code == 1)
code = SCANNER_ERR_DEVICE_DOGEAR;
2022-05-03 03:56:07 +00:00
else if (ds->Code == 2)
code = SCANNER_ERR_DEVICE_SIZE_CHECK;
else if (ds->Img_Status == 1)
code = SCANNER_ERR_DEVICE_DOUBLE_FEEDING;
2022-05-03 03:56:07 +00:00
}
else if (ds->From == setting3399::HGType::V4L2)
2022-05-03 03:56:07 +00:00
{
if (ds->Code == 0)
code = SCANNER_ERR_DEVICE_SCANN_ERROR;
2022-05-03 03:56:07 +00:00
else if (ds->Code == 1)
code = SCANNER_ERR_DEVICE_NO_IMAGE;
2022-05-03 03:56:07 +00:00
}
else if (ds->From == setting3399::HGType::STOPSCAN)
code = SCANNER_ERR_DEVICE_STOPPED;
2022-12-30 09:14:49 +00:00
else if (ds->From == setting3399::HGType::AutoCorrect)
{
if (ds->Code == 4)
code = SCANNER_ERR_DEVICE_AUTO_FAIL_OVER;
else
code = SCANNER_ERR_DEVICE_AUTO_FAIL_INFO;
}
2022-05-03 03:56:07 +00:00
return code;
}
// resolution
static struct
{
float resolution;
int dev_value;
}resolution_map[] =
{
{100.0f, 1},
{150.0f, 1},
{200.0f, 1},
{240.0f, 1},
{300.0f, 0},
2023-11-23 03:09:31 +00:00
{600.0f, 1} //临时版本发1 原来发2
2022-05-03 03:56:07 +00:00
};
bool is_equal(float l, float r)
{
return fabs(l - r) < .000001f;
}
int match_best_resolution(int resolution, bool* exact)
{
int rsl = resolution,
ind = 0;
bool good = true, *r = exact ? exact : &good;
if (rsl <= resolution_map[0].resolution)
{
ind = 0;
}
else if (rsl >= resolution_map[ARRAY_SIZE(resolution_map) - 1].resolution)
{
ind = ARRAY_SIZE(resolution_map) - 1;
}
else
{
for (int i = 1; i < ARRAY_SIZE(resolution_map); ++i)
{
if (is_equal(rsl, resolution_map[i].resolution))
{
ind = i;
break;
}
if (rsl < resolution_map[i].resolution)
{
float dif_l = rsl - resolution_map[i - 1].resolution,
dif_r = resolution_map[i].resolution - rsl;
if (dif_l > dif_r)
ind = i;
else
ind = i - 1;
break;
}
}
}
*r = is_equal(rsl, resolution_map[ind].resolution);
return ind;
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// class ...
2023-01-17 07:07:58 +00:00
hg_scanner_239::hg_scanner_239(const char* dev_name, int pid,usb_io* io) : hg_scanner(G20039Serial, dev_name, io,pid)
, rewrite_conf_(false), reset_(false),is_start_status(false)
2022-05-03 03:56:07 +00:00
{
2023-06-26 10:00:58 +00:00
init_version();
2023-01-17 07:07:58 +00:00
//pid_ = pid;
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "hg_scanner_239(%s) constructing ...\n", hg_log::format_ptr(this).c_str());
2022-05-03 03:56:07 +00:00
dev_conf_.value = 0;
#ifndef MAPPING_FUNCTION_IN_BASE
2022-05-03 03:56:07 +00:00
init_setting_map(setting_map_, ARRAY_SIZE(setting_map_));
#endif
if (init_settings(pid_))
{
if (pid_ == 0x239)
2023-10-25 07:00:31 +00:00
init_settings((jsontext1 + jsontext2 + jsontext3 + jsontext4).c_str());
else
2023-10-25 07:00:31 +00:00
init_settings((jsontext5 + jsontext6 + jsontext7).c_str());
}
2023-11-23 02:25:10 +00:00
2023-08-16 06:11:59 +00:00
string str;
get_devs_time(str);
#ifdef OEM_HUAGAO
wait_devsislock_.notify();
#endif
if (firmware_sup_boardTime)
update_boarddatetime();
status_ = SCANNER_ERR_OK;
2022-05-03 03:56:07 +00:00
}
hg_scanner_239::~hg_scanner_239()
{
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "hg_scanner_239(%s) destroyed.\n", hg_log::format_ptr(this).c_str());
2022-05-03 03:56:07 +00:00
}
int hg_scanner_239::read_register(int addr, int* val)
{
int l = sizeof(*val),
ret = io_->control_io(0x0c0, USB_REQ_GET_DEV_REGS, addr, 0, val, &l);
if (ret)
status_ = ret;
return ret;
}
int hg_scanner_239::write_register(int addr, int val)
{
int l = sizeof(val),
ret = io_->control_io(0x040, USB_REQ_SET_DEV_REGS, addr, 0, &val, &l);
if (ret)
status_ = ret;
return ret;
}
int hg_scanner_239::write_command(int cmd)
{
return write_register(0, cmd);
}
std::string hg_scanner_239::control_fetch(int addr, int val, int size)
{
int l = sizeof(val),
ret = 0;
std::string data("");
ret = write_register(addr, val);
if (ret == SCANNER_ERR_OK)
2022-05-03 03:56:07 +00:00
{
l = size + 1;
data.resize(size + 2);
bzero(&data[0], size + 2);
ret = io_->read_bulk(&data[0], &l);
if (ret || l == 0)
2022-05-03 03:56:07 +00:00
{
VLOG_MINI_4(LOG_LEVEL_DEBUG_INFO, "control_fetch(%d, %d) - read_bulk %d byte(s) = %s\n", addr, val, l, hg_scanner_err_name(ret));
2022-05-03 03:56:07 +00:00
data.clear();
}
}
else
VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "control_fetch(%d, %d) = %s\n", addr, val, hg_scanner_err_name(ret));
2022-05-03 03:56:07 +00:00
return data;
}
std::string hg_scanner_239::get_fpga(void)
{
2023-05-25 01:09:52 +00:00
std::lock_guard<std::mutex> lock(io_lock_);
2022-05-03 03:56:07 +00:00
int val = 0,
ret = read_register(setting3399::SR_GET_MBVERSION_LENGHT, &val);
2022-05-03 03:56:07 +00:00
std::string fpga("");
if (ret == SCANNER_ERR_OK)
2022-05-03 03:56:07 +00:00
{
fpga.resize(val + 2);
bzero(&fpga[0], val + 2);
return control_fetch(setting3399::SR_GET_MBVERSION, 0, val);
2022-05-03 03:56:07 +00:00
}
return fpga;
}
2022-12-22 10:37:53 +00:00
int hg_scanner_239::get_scan_mode(bool &type)
2022-05-03 03:56:07 +00:00
{
2023-05-25 01:09:52 +00:00
std::lock_guard<std::mutex> lock(io_lock_);
2022-05-03 03:56:07 +00:00
int val = 0,
ret = read_register(setting3399::SR_OS, &val); //val == 1计数模式
2022-12-22 10:37:53 +00:00
type =val == 1 ? false : true;
2023-06-15 08:27:20 +00:00
2023-08-03 08:48:05 +00:00
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "get_scan_mode: %s\n", !type ? hg_scanner_err_description(SCANNER_ERR_DEVICE_COUNT_MODE) : hg_scanner_err_description(SCANNER_ERR_OK));
2023-06-15 08:27:20 +00:00
return ret;
2022-05-03 03:56:07 +00:00
}
2022-12-28 01:56:54 +00:00
int hg_scanner_239::set_speed_mode(int data)
{
std::lock_guard<std::mutex> lock(io_lock_);
2022-12-28 01:56:54 +00:00
return write_register(setting3399::SR_SET_SPEEDMODE, data);
}
2022-12-29 10:05:59 +00:00
int hg_scanner_239::get_speed_mode(int& data)
{
std::lock_guard<std::mutex> lock(io_lock_);
2022-12-29 10:05:59 +00:00
return read_register(setting3399::SR_GET_SPEEDMODE, &data);
}
int hg_scanner_239::set_devs_distortion_check_val(float data)
2022-12-28 01:56:54 +00:00
{
std::lock_guard<std::mutex> lock(io_lock_);
int val = *(int*)&data;
setting3399::Scanner_Reg_Defs ratio = setting3399::SR_SET_V_RATIO; //华凌畸变设置
2023-06-28 10:31:03 +00:00
if (firmware_sup_log_export_)//敦南畸变设置
2023-06-28 10:31:03 +00:00
{
if (resolution_ <= 200)
ratio = setting3399::SR_SET_V_200_RATIO;
else if (resolution_ > 200 && resolution_ <= 300)
ratio = setting3399::SR_SET_V_300_RATIO;
else if (resolution_ > 300 && resolution_ <= 600)
ratio = setting3399::SR_SET_V_600_RATIO;
}
2022-12-28 01:56:54 +00:00
return write_register(ratio, val);
2022-12-28 01:56:54 +00:00
}
int hg_scanner_239::get_devs_distortion_check_val(float& data)
2022-12-28 01:56:54 +00:00
{
std::lock_guard<std::mutex> lock(io_lock_);
int val = 0;
2023-06-28 10:31:03 +00:00
setting3399::Scanner_Reg_Defs ratio = setting3399::SR_GET_V_RATIO;
if (firmware_sup_log_export_)
{
if (resolution_ <= 200)
ratio = setting3399::SR_GET_V_200_RATIO;
else if (resolution_ > 200 && resolution_ <= 300)
ratio = setting3399::SR_GET_V_300_RATIO;
else if (resolution_ > 300 && resolution_ <= 600)
ratio = setting3399::SR_GET_V_600_RATIO;
}
int ret = read_register(ratio, &val);
2023-06-28 10:31:03 +00:00
data = *(float*)&val;
2022-12-28 01:56:54 +00:00
return ret;
}
int hg_scanner_239::set_auto_flat(int data)
2022-12-30 09:14:49 +00:00
{
int ret = SCANNER_ERR_OK;
2022-12-30 09:14:49 +00:00
auto fw = get_firmware_version();
2023-02-07 08:57:53 +00:00
if (fw.empty())
{
return SCANNER_ERR_NO_DATA;
}
2022-12-30 09:14:49 +00:00
if ((fw[5] == 'A' && atoi(fw.substr(6, 4).c_str()) <= 9999))
{
2023-11-23 03:09:31 +00:00
data = data == 1 ? 1 : 0; //暂时没有用。
2022-12-30 09:14:49 +00:00
}
if (!wait_usb_.is_waiting())
{
return SCANNER_ERR_DEVICE_BUSY;
}
else
{
2023-05-24 07:07:13 +00:00
std::lock_guard<std::mutex> lock(io_lock_);
ret = write_register(setting3399::SC_AUTOCORRECT, data);
2022-12-30 09:14:49 +00:00
if (ret != SCANNER_ERR_OK)
{
return ret;
}
//status_ = SCANNER_ERR_DEVICE_BUSY;
wait_usb_.notify();
std::this_thread::sleep_for(std::chrono::milliseconds(300));
ret = try_third_app_after_start(ret);
}
VLOG_MINI_1(LOG_LEVEL_WARNING, "set_auto_flat ret: %s\n", hg_scanner_err_name(ret));
return ret;
}
2023-06-16 10:01:28 +00:00
int hg_scanner_239::get_motor_board_ver(string &ver)
{
std::lock_guard<std::mutex> lock(io_lock_);
int val = 0,
ret = read_register(setting3399::SR_GET_MBVERSION_LENGHT, &val);
ver = control_fetch(setting3399::SR_GET_MBVERSION, 0, val);
return ret;
}
2023-08-16 06:11:59 +00:00
int hg_scanner_239::set_devs_time(string times)
{
string path = "/usr/local/huago/PC_TIMES.txt";
return write_control_device_files(path, times);
}
int hg_scanner_239::get_devs_time(string& times)
{
string path = "/usr/local/huago/PC_TIMES.txt";
char buf[128] = {0};
int ret = read_control_device_files(path, times);
if (ret == SCANNER_ERR_NO_DATA)
{
hg_get_current_time(buf);
ret = write_control_device_files(path,buf);
if (ret == SCANNER_ERR_OK)
{
ret = read_control_device_files(path, times);
}
}
if (ret != SCANNER_ERR_OK)
{
times = "";
}
return ret;
}
int hg_scanner_239::get_devs_cpu(string& cpu)
{
string path = "/usr/local/huago/sysinfo.json";
long long cpu_size = 0;
std:string str;
int ret = read_control_device_files(path, str);
json js = json::parse(str);
if (js.contains("MemTotal"))
{
cpu_size = js["MemTotal"];
}
float num = (float)cpu_size / 1024 / 1024 / 1024;
char buf[10] = { 0 };
sprintf(buf, "%.2f", num);
strcat(buf, "GB");
cpu = buf;
return ret;
}
int hg_scanner_239::get_devs_disk(string& disk)
{
string path = "/usr/local/huago/sysinfo.json";
long disk_size = 0;
std:string str;
int ret = read_control_device_files(path, str);
json js = json::parse(str);
if (js.contains("DiskTotal"))
{
disk_size = js["DiskTotal"];
}
float num = (float)disk_size / 1024 / 1024;
char buf[10] = { 0 };
sprintf(buf, "%.2f", num);
strcat(buf, "GB");
disk = buf;
return ret;
}
int hg_scanner_239::set_restore()
{
if (!firmware_sup_backup_restore)
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
std::lock_guard<std::mutex> lock(io_lock_);
int ret = write_register(setting3399::SR_BACKUP_RESTORES_HUAGODIR, 2);
return ret;
}
int hg_scanner_239::set_backup()
{
if (!firmware_sup_backup_restore)
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
std::lock_guard<std::mutex> lock(io_lock_);
int ret = write_register(setting3399::SR_BACKUP_RESTORES_HUAGODIR, 1);
return ret;
}
int hg_scanner_239::get_status(void)
2022-05-03 03:56:07 +00:00
{
std::lock_guard<std::mutex> lock(io_lock_);
2022-05-03 03:56:07 +00:00
int val = 0,
ret = read_register(setting3399::SR_STATUS, &val);
2022-05-03 03:56:07 +00:00
if (ret)
{
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "get status error: %s\n", hg_scanner_err_name(ret));
2022-05-03 03:56:07 +00:00
status_ = ret;
return -1;
}
else
return val;
}
bool hg_scanner_239::is_dev_image_process_done(void)
{
std::lock_guard<std::mutex> lock(io_lock_);
2022-05-03 03:56:07 +00:00
int val = 0,
ret = read_register(setting3399::SR_GET_IMAGEPROCESSDONE, &val);
2022-05-03 03:56:07 +00:00
if (ret)
{
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "is_dev_image_process_done() error: %s\n", hg_scanner_err_name(ret));
2022-05-03 03:56:07 +00:00
status_ = ret;
return true;
}
else
return val;
}
bool hg_scanner_239::is_dev_image_keep_last_paper(void)
{
std::lock_guard<std::mutex> lock(io_lock_);
2022-05-03 03:56:07 +00:00
int val = 0,
ret = read_register(setting3399::SR_GET_KEEP_LAST_PAPER, &val);
2022-05-03 03:56:07 +00:00
if (ret)
{
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "is_dev_image_keep_last_paper() error: %s\n", hg_scanner_err_name(ret));
2022-05-03 03:56:07 +00:00
status_ = ret;
return true;
}
else
return val;
}
int hg_scanner_239::get_image_count(void)
2022-05-03 03:56:07 +00:00
{
std::lock_guard<std::mutex> lock(io_lock_);
2022-05-03 03:56:07 +00:00
int val = 0,
ret = read_register(setting3399::SR_IM_COUNT, &val);
2022-05-03 03:56:07 +00:00
2023-05-05 09:00:37 +00:00
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Gets The image queue in the 'DEVICE':[%d]\n", val);
2022-05-03 03:56:07 +00:00
if (ret == SCANNER_ERR_OK)
2022-05-03 03:56:07 +00:00
return val;
else
return -1;
}
int hg_scanner_239::get_front_data_size(void)
2022-05-03 03:56:07 +00:00
{
std::lock_guard<std::mutex> lock(io_lock_);
2022-05-03 03:56:07 +00:00
int val = 0,
ret = read_register(setting3399::SR_IM_FRONT_SIZE, &val);
2022-05-03 03:56:07 +00:00
if (ret == SCANNER_ERR_OK)
2022-05-03 03:56:07 +00:00
return val;
else
{
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "get_front_data_size = %s\n", hg_scanner_err_name(ret));
2022-05-03 03:56:07 +00:00
return -1;
}
}
void hg_scanner_239::init_version(void)
{
std::string fv(get_firmware_version()),
sn(get_serial_num());
2023-02-07 08:57:53 +00:00
if (fv.empty() || sn.empty())
2023-02-07 08:45:25 +00:00
return;
2022-12-06 09:47:27 +00:00
string dev = fv.substr(0, 2);
string ver = fv.substr(2, 3);
string date = fv.substr(5, 5);
string year = fv.substr(4, 2);
2022-12-06 09:47:27 +00:00
string devType;
2023-06-26 10:00:58 +00:00
string year_date = fv.substr(4, 6);
firmware_sup_double_check = year_date.compare("3C1027") >= 0 ? true : false;
firmware_sup_dirty_check = year_date.compare("3C1027") >= 0 ? true : false;
firmware_sup_backup_restore = year_date.compare("3C1021") >= 0 ? true : false;
firmware_sup_boardTime = year_date.compare("3C1021") >= 0 ? true : false;
2023-10-25 11:50:29 +00:00
2023-06-26 10:00:58 +00:00
if (dev == "G1" || dev == "G2")
2023-03-01 07:07:47 +00:00
{
2023-08-16 06:11:59 +00:00
firmware_sup_wait_paper_ = year_date.compare("3B0431") >= 0 ? true : false;
firmware_sup_log_export_ = year_date.compare("3B0429") >= 0 ? true : false;
firmware_sup_pick_strength_ = year_date.compare("3B0830") >= 0 ? true : false;
firmware_sup_wake_device_ = year_date.compare("3B0830") >= 0 ? true : false;
firmware_sup_color_corr_ = year.compare("3C") >= 0 ? true : false;
firmware_sup_double_img = year.compare("3C") >= 0 ? true : false;
firmware_sup_devs_lock_ = year_date.compare("3B0500") >= 0 ? true : false;
2023-06-26 10:00:58 +00:00
firmware_sup_dpi_300 = false;
2023-08-16 06:11:59 +00:00
firmware_sup_dpi_600 = date.compare("A1227") >= 0 ? true : false;
firmware_sup_auto_speed_ = year.compare("3C") >= 0 ? true : false;
firmware_sup_morr_ = year_date.compare("3C0518") >= 0 ? true : false;
firmware_sup_color_fill_ = year.compare("3B03C830") >= 0 ? true : false;
}
else
{
2023-08-16 06:11:59 +00:00
firmware_sup_wait_paper_ = year_date.compare("3B0629") >= 0 ? true : false;
2023-06-26 10:00:58 +00:00
firmware_sup_log_export_ = true;
2023-11-23 03:09:31 +00:00
firmware_sup_pick_strength_ = false; //不支持
2023-08-16 06:11:59 +00:00
firmware_sup_wake_device_ = year_date.compare("3C0518") >= 0 ? true : false;
firmware_sup_color_corr_ = year.compare("3C") >= 0 ? true : false;
firmware_sup_double_img = year_date.compare("3C1021") >= 0 ? true : false;
2023-08-16 06:11:59 +00:00
firmware_sup_devs_lock_ = year.compare("3C") >= 0 ? true : false;
2023-06-26 10:00:58 +00:00
firmware_sup_dpi_300 = false;
firmware_sup_dpi_600 = true;
2023-08-16 06:11:59 +00:00
firmware_sup_auto_speed_ = year.compare("3C") >= 0 ? true : false;
firmware_sup_morr_ = year_date.compare("3C0518") >= 0 ? true : false;
firmware_sup_color_fill_ = year.compare("3C") >= 0 ? true : false;
}
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Firmware_sup_wait_paper_:%s\r\n", firmware_sup_wait_paper_ ? "enable" : "close");
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Firmware_sup_log_export_:%s\r\n", firmware_sup_log_export_ ? "enable" : "close");
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Firmware_sup_pick_strength_:%s\r\n", firmware_sup_pick_strength_ ? "enable" : "close");
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Firmware_sup_color_corr_:%s\r\n", firmware_sup_color_corr_ ? "enable" : "close");
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Firmware_sup_double_img:%s\r\n", firmware_sup_double_img ? "enable" : "close");
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Firmware_sup_devs_lock_:%s\r\n", firmware_sup_devs_lock_ ? "enable" : "close");
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Firmware_sup_dpi_300:%s\r\n", firmware_sup_dpi_300 ? "enable" : "close");
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Firmware_sup_dpi_600:%s\r\n", firmware_sup_dpi_600 ? "enable" : "close");
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Firmware_sup_auto_speed_:%s\r\n", firmware_sup_auto_speed_ ? "enable" : "close");
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Firmware_sup_morr_:%s\r\n", firmware_sup_morr_ ? "enable" : "close");
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Firmware_sup_color_fill_:%s\r\n", firmware_sup_color_fill_ ? "enable" : "close");
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Firmware version: %s\n", fv.c_str());
2022-11-02 10:06:49 +00:00
}
int hg_scanner_239::writedown_device_configuration(bool type, setting_hardware::HGSCANCONF_3399* dev_conf)
2022-05-03 03:56:07 +00:00
{
std::lock_guard<std::mutex> lock(io_lock_);
int ret = SCANNER_ERR_OK;
2022-11-19 10:16:43 +00:00
if (!type)
return ret;
2023-11-23 03:09:31 +00:00
setting_hardware::HGSCANCONF_3399 p = dev_conf_; //不得改变外部的值
p.params_3399.is_autopaper = is_auto_scan();
if (!dev_conf)
dev_conf = &p;
2022-11-19 10:16:43 +00:00
if (is_multiout)
2022-10-11 08:22:32 +00:00
{
dev_conf->params_3399.color = image_prc_param_.bits.multi_out == MULTI_GRAY_AND_BW ? 0 : 1;
2022-10-11 08:22:32 +00:00
}
2022-11-19 10:16:43 +00:00
else if ((image_prc_param_.bits.color_mode == COLOR_MODE_256_GRAY
|| image_prc_param_.bits.color_mode == COLOR_MODE_BLACK_WHITE)
&& image_prc_param_.bits.rid_color != RID_COLOR_NONE)
2022-10-28 03:01:01 +00:00
{
2022-11-19 10:16:43 +00:00
dev_conf->params_3399.color = 1;
2022-10-28 03:01:01 +00:00
}
2022-11-19 10:16:43 +00:00
2023-06-26 10:00:58 +00:00
if (firmware_sup_auto_speed_ && image_prc_param_.bits.paper == PAPER_AUTO_MATCH)
{
dev_conf->params_3399.is_fixedpaper = false;
dev_conf->params_3399.en_autosize = true;
}
2023-11-23 03:09:31 +00:00
if (!firmware_sup_auto_speed_ && image_prc_param_.bits.paper == PAPER_AUTO_MATCH)//3399 ,在3C之前的版本 匹配原始尺寸设置 12
{
dev_conf->params_3399.paper = 12;
}
ret = write_register(setting3399::SR_CONFIG_SCAN_PARAM, dev_conf->value);
2022-05-03 03:56:07 +00:00
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "Writedown scanner configuration(0x%x) = %s\n", dev_conf->value, hg_scanner_err_name(ret));
2022-05-03 03:56:07 +00:00
return ret;
}
int hg_scanner_239::writedown_image_configuration(void)
2022-05-03 03:56:07 +00:00
{
int ret = 0;
if (ret != SCANNER_ERR_OK)
2022-05-03 03:56:07 +00:00
return ret;
SCANCONF ic;
2022-08-11 09:19:24 +00:00
int len = sizeof(ic);
2022-05-03 03:56:07 +00:00
bzero(&ic, len);
2022-11-23 11:00:17 +00:00
if (image_prc_param_.bits.text_direction != TEXT_DIRECTION_AUTO)
ic.imageRotateDegree = (float)image_prc_param_.bits.text_direction;
else
ic.imageRotateDegree = 0;
ic.imageRotateDegree *= 90.0f;
ic.en_sizecheck = size_check;
2022-11-19 10:16:43 +00:00
ic.hardwarecaps.en_skrewdetect = dev_conf_.params_3399.screw_detect_enable;
ic.hardwarecaps.en_doublefeed = dev_conf_.params_3399.ultrasonic_enable;
ic.hardwarecaps.en_stapledetect = dev_conf_.params_3399.staple_enbale;
ic.hardwarecaps.skrewdetectlevel = dev_conf_.params_3399.screw_detect_level;
2022-05-03 03:56:07 +00:00
if (test_1_paper_)
{
LOG_INFO(LOG_LEVEL_DEBUG_INFO, "scanning mode: testing ONE paper ...\n");
2022-05-03 03:56:07 +00:00
ic.scannum = ic.is_duplex ? 2 : 1;
}
else
{
if (scan_count_ == -1 /*|| is_auto_paper_scan*/)
ic.scannum = -1;
else
2023-02-08 09:24:07 +00:00
ic.scannum = ((image_prc_param_.bits.page != PAGE_SINGLE) ? scan_count_ * 2 : scan_count_);
2022-05-03 03:56:07 +00:00
}
2022-11-19 10:16:43 +00:00
ic.contrast = (contrast_ - 4) * 333.0;
ic.brightness = (bright_ - 128) * (2000.0 / 254.0);
2022-11-19 10:16:43 +00:00
image_configuration(ic);
{
2022-11-19 10:16:43 +00:00
std::lock_guard<std::mutex> lock(io_lock_);
ret = write_register(setting3399::SR_CONFIF_IMGPROCPARAM, sizeof(SCANCONF));
2022-11-19 10:16:43 +00:00
ret = io_->write_bulk(&ic, &len);
2022-05-03 03:56:07 +00:00
2022-11-19 10:16:43 +00:00
this_thread::sleep_for(chrono::milliseconds(500));
io_->set_timeout(2000);//必要延时
2022-11-19 10:16:43 +00:00
}
2022-05-03 03:56:07 +00:00
return ret;
}
int hg_scanner_239::pop_first_image(void)
2022-05-03 03:56:07 +00:00
{
std::lock_guard<std::mutex> lock(io_lock_);
int ret = write_register(setting3399::SR_IM_POP, 1);
2023-05-05 09:00:37 +00:00
if (ret)
{
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "popup first image = %s\n", hg_scanner_err_name(ret));
}
2022-05-03 03:56:07 +00:00
return ret;
}
int hg_scanner_239::read_one_image_from_usb(SANE_Image_Statu statu)
2022-05-03 03:56:07 +00:00
{
int r = 0,
total = get_front_data_size(),
off = 0,
ret = SCANNER_ERR_OK;
bool is_scanner_err_ok = false;
2022-05-03 03:56:07 +00:00
if (!waiting_for_memory_enough(total))
{
status_ = SCANNER_ERR_INSUFFICIENT_MEMORY;
2022-05-03 03:56:07 +00:00
return status_;
}
if (total == -1)
ret = status_;
else
{
std::lock_guard<std::mutex> lock(io_lock_);
std::shared_ptr<tiny_buffer> buf(aquire_memory(total));
if (!buf.get())
return SCANNER_ERR_INSUFFICIENT_MEMORY;
2022-05-03 03:56:07 +00:00
// write reading command
ret = write_register(setting3399::SR_IM_TX, 1);
buf->set_image_statu(statu);
if (ret == SCANNER_ERR_OK)
2022-05-03 03:56:07 +00:00
{
std::this_thread::sleep_for(std::chrono::milliseconds(10));
r = total;
{
unsigned int size = r;
void* buff = buf->data(off, &size);
2022-06-07 09:06:09 +00:00
int block = 0;
if (!buff)
2022-05-03 03:56:07 +00:00
{
VLOG_MINI_3(LOG_LEVEL_FATAL, "memory(0x%08x + %u) fatal when read USB image %d !!!\n", off, r, usb_img_index_);
ret = SCANNER_ERR_INSUFFICIENT_MEMORY;
}
else
{
r = size;
2022-06-07 09:06:09 +00:00
while (r > 0)
{
2022-06-07 09:06:09 +00:00
block = 512 * 1024;
if (r < block)
block = r;
unsigned int size = block;
void* buff = buf->data(off, &size);
if (!buf)
{
2022-06-07 09:06:09 +00:00
//VLOG_MINI_3(LOG_LEVEL_FATAL, "memory(0x%08x + %u) fatal when read USB image %d !!!\n", index, block, usb_img_index_);
ret = SCANNER_ERR_INSUFFICIENT_MEMORY;
break;
}
2022-06-07 09:06:09 +00:00
block = size;
ret = io_->read_bulk(buff, &block); //可能会出现TIME_OUT 然后只能退出去,下一次再来取
if (ret != SCANNER_ERR_OK)
{
VLOG_MINI_3(LOG_LEVEL_FATAL, "read_one_image_from_usb read_data:%s!!! read data[%d/:%d]\n", hg_scanner_err_name(ret),size, block);
2022-06-07 09:06:09 +00:00
break;
2023-03-14 09:02:38 +00:00
}
2022-06-07 09:06:09 +00:00
off += block;
r -= block;
}
2022-05-03 03:56:07 +00:00
}
}
if (r > 0)
{
2023-05-05 09:00:37 +00:00
VLOG_MINI_2(LOG_LEVEL_FATAL, "read_one_image_from_usb 'total' is %d, 'left' total len is:%d!!!\n", total, r);
}
if (ret == SCANNER_ERR_OK)
2022-05-03 03:56:07 +00:00
{
ret = save_usb_data(buf);
if (ret == SCANNER_ERR_OK)
2022-05-03 03:56:07 +00:00
{
is_scanner_err_ok = true;
2022-05-03 03:56:07 +00:00
}
}
else
{
2023-05-05 09:00:37 +00:00
VLOG_MINI_1(LOG_LEVEL_FATAL, "Read image data from USB err: %s\n", hg_scanner_err_name(ret));
2022-05-03 03:56:07 +00:00
}
}
}
if (is_scanner_err_ok)
{
pop_first_image();
}
2022-05-03 03:56:07 +00:00
return ret;
}
int hg_scanner_239::discard_all_images(void)
2022-05-03 03:56:07 +00:00
{
int block = 1024 * 512,
2023-11-22 08:53:52 +00:00
oto = io_->set_timeout(100), pre_img = 0,
pre_int = 0,
ret = SCANNER_ERR_OK;
string str;
str.resize(block);
2022-05-03 03:56:07 +00:00
{
char buf[64];
int size = sizeof(buf);
ret = SCANNER_ERR_OK;
setting3399::HGEIntInfo* info = (setting3399::HGEIntInfo*)buf;
2022-05-03 03:56:07 +00:00
{
std::lock_guard<std::mutex> lock(io_lock_);
ret = io_->read_interrupt(buf, &size);
2022-05-03 03:56:07 +00:00
}
while (ret == SCANNER_ERR_OK && size)
{
pre_int++;
if (info->From == setting3399::IMG)
{
while (get_image_count() > 0)
{
pop_first_image();
pre_img++;
}
}
2022-05-03 03:56:07 +00:00
size = sizeof(buf);
{
std::lock_guard<std::mutex> lock(io_lock_);
ret = io_->read_interrupt(buf, &size);
}
}
2023-11-22 08:53:52 +00:00
io_->set_timeout(oto);
}
2023-11-22 08:53:52 +00:00
std::this_thread::sleep_for(std::chrono::milliseconds(200));
2022-05-03 03:56:07 +00:00
if (pre_int)
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "prev-connection has left %d interrupt packet(s) && %d image(s).\n", pre_int, pre_img);
return 0;
2022-05-03 03:56:07 +00:00
}
2023-06-13 04:28:20 +00:00
int hg_scanner_239::get_roller_life(void)
{
return 450000;
}
2022-05-03 03:56:07 +00:00
int hg_scanner_239::on_color_mode_changed(int& color_mode)
{
2022-11-19 10:16:43 +00:00
dev_conf_.params_3399.color = (color_mode == COLOR_MODE_BLACK_WHITE || color_mode == COLOR_MODE_256_GRAY) ? 0 : 1;
return SCANNER_ERR_OK;
/*int ret = SCANNER_ERR_OK;
2022-05-03 03:56:07 +00:00
if ((((color_mode == COLOR_MODE_24_BITS || color_mode == COLOR_MODE_AUTO_MATCH) && !dev_conf_.params_3399.color) ||
((color_mode != COLOR_MODE_24_BITS && color_mode != COLOR_MODE_AUTO_MATCH) && dev_conf_.params_3399.color)) && color_mode != -1)
2022-05-03 03:56:07 +00:00
{
dev_conf_.params_3399.color ^= 1;
2022-05-03 03:56:07 +00:00
ret = writedown_device_configuration();
if(ret)
dev_conf_.params_3399.color ^= 1;
2022-05-03 03:56:07 +00:00
}
if(color_mode == COLOR_MODE_AUTO_MATCH)
{
dev_conf_.params_3399.color = 1;
2022-05-03 03:56:07 +00:00
}
2022-11-19 10:16:43 +00:00
return ret;*/
2022-05-03 03:56:07 +00:00
}
int hg_scanner_239::on_paper_changed(int& paper)
{
bool exact = true;
int ind = hgpaper_to_devspaper(paper_map_3399, ARRAY_SIZE(paper_map_3399),paper, &exact, &paper_size_),
ret = exact ? SCANNER_ERR_OK : SCANNER_ERR_NOT_EXACT;
2022-05-03 03:56:07 +00:00
if (dev_conf_.params_3399.paper != paper_map_3399[ind].dev_value)
2022-05-03 03:56:07 +00:00
{
int old = dev_conf_.params_3399.paper;
2022-05-03 03:56:07 +00:00
dev_conf_.params_3399.paper = paper_map_3399[ind].dev_value;
2022-05-03 03:56:07 +00:00
ret = writedown_device_configuration();
if (ret)
{
dev_conf_.params_3399.paper = old;
for (int i = 0; i < ARRAY_SIZE(paper_map_3399); ++i)
2022-05-03 03:56:07 +00:00
{
if (paper_map_3399[i].dev_value == old)
2022-05-03 03:56:07 +00:00
{
paper = paper_map_3399[i].paper;
2022-05-03 03:56:07 +00:00
break;
}
}
}
else if (!exact)
ret = SCANNER_ERR_NOT_EXACT;
2022-05-03 03:56:07 +00:00
}
return ret;
}
int hg_scanner_239::on_paper_check_changed(bool& check)
{
int ret = SCANNER_ERR_OK;
2022-05-03 03:56:07 +00:00
if (size_check ^ check)
2022-05-03 03:56:07 +00:00
{
//dev_conf_.params_3399.enable_sizecheck = check;
size_check = check;
2022-05-03 03:56:07 +00:00
ret = writedown_device_configuration();
2022-06-08 10:33:49 +00:00
2022-05-03 03:56:07 +00:00
if (ret)
{
//dev_conf_.params_3399.enable_sizecheck = !check;
check = size_check;// dev_conf_.params_3399.enable_sizecheck;
2022-05-03 03:56:07 +00:00
}
}
return ret;
}
int hg_scanner_239::on_resolution_changed(int& dpi)
{
2023-06-26 10:00:58 +00:00
if (!firmware_sup_dpi_600)
2023-03-15 03:03:36 +00:00
dev_conf_.params_3399.dpi = 1;
else
2023-06-26 10:00:58 +00:00
dev_conf_.params_3399.dpi = dpi >= 500 ? 3 : (dpi < 500 && dpi> 299) ? 2 : 1;
2023-03-15 03:03:36 +00:00
2023-11-23 03:09:31 +00:00
//dev_conf_.params_3399.dpi = 1; //dpi 华凌cis和敦南cis 默认发1无需改变
2023-02-08 08:19:42 +00:00
int ret = writedown_device_configuration();
return ret;
2022-05-03 03:56:07 +00:00
}
int hg_scanner_239::on_ultrasonic_check_changed(bool& check)
{
int ret = SCANNER_ERR_OK;
2022-05-03 03:56:07 +00:00
if (dev_conf_.params_3399.ultrasonic_enable ^ check)
2022-05-03 03:56:07 +00:00
{
dev_conf_.params_3399.ultrasonic_enable = check;
2022-05-03 03:56:07 +00:00
ret = writedown_device_configuration();
if (ret)
{
dev_conf_.params_3399.ultrasonic_enable = !check;
check = dev_conf_.params_3399.ultrasonic_enable;
2022-05-03 03:56:07 +00:00
}
}
return ret;
}
int hg_scanner_239::on_staple_check_changed(bool& check)
{
int ret = SCANNER_ERR_OK;
2022-05-03 03:56:07 +00:00
if (dev_conf_.params_3399.staple_enbale ^ check)
2022-05-03 03:56:07 +00:00
{
dev_conf_.params_3399.staple_enbale = check;
2022-05-03 03:56:07 +00:00
ret = writedown_device_configuration();
if (ret)
{
dev_conf_.params_3399.staple_enbale = !check;
check = dev_conf_.params_3399.staple_enbale;
2022-05-03 03:56:07 +00:00
}
}
return ret;
}
int hg_scanner_239::on_skew_check_changed(bool& check)
{
int ret = SCANNER_ERR_OK;
2022-05-03 03:56:07 +00:00
if (dev_conf_.params_3399.screw_detect_enable ^ check)
2022-05-03 03:56:07 +00:00
{
dev_conf_.params_3399.screw_detect_enable = check;
2022-05-03 03:56:07 +00:00
ret = writedown_device_configuration();
if (ret)
{
dev_conf_.params_3399.screw_detect_enable = !check;
check = dev_conf_.params_3399.screw_detect_enable;
2022-05-03 03:56:07 +00:00
}
}
return ret;
}
int hg_scanner_239::on_skew_check_level_changed(int& check)
{
int ret = SCANNER_ERR_OK,
2023-11-23 03:09:31 +00:00
val = check - 1,//涓婇潰璁剧疆鐨勬槸1 - 5 锛屾帴鍙楄寖鍥村€间负0 - 4锛岄粯璁?
old = dev_conf_.params_3399.screw_detect_level;
setting_hardware::HGSCANCONF_3399 cf;
2022-05-03 03:56:07 +00:00
if (val < 0 && val>5)
{
check = 3;
ret = SCANNER_ERR_NOT_EXACT;
}
if (val != dev_conf_.params_3399.screw_detect_level)
{
dev_conf_.params_3399.screw_detect_level = val;
ret = writedown_device_configuration();
if (ret)
{
check = dev_conf_.params_3399.screw_detect_level = old;
check += 1;
}
}
/*cf.params_3399.screw_detect_level = -1;
2022-05-03 03:56:07 +00:00
if (val < 0)
{
val = 0;
ret = SCANNER_ERR_NOT_EXACT;
2022-05-03 03:56:07 +00:00
}
else if (val > cf.params_3399.screw_detect_level)
2022-05-03 03:56:07 +00:00
{
val = cf.params_3399.screw_detect_level;
ret = SCANNER_ERR_NOT_EXACT;
2022-05-03 03:56:07 +00:00
}
if (val != dev_conf_.params_3399.screw_detect_level)
2022-05-03 03:56:07 +00:00
{
dev_conf_.params_3399.screw_detect_level = val;
2022-05-03 03:56:07 +00:00
ret = writedown_device_configuration();
if (ret)
check = dev_conf_.params_3399.screw_detect_level = old;
2022-05-03 03:56:07 +00:00
}
if (ret == SCANNER_ERR_OK && val != check)
2022-05-03 03:56:07 +00:00
{
check = val;
ret = SCANNER_ERR_NOT_EXACT;
}*/
2022-05-03 03:56:07 +00:00
return ret;
}
int hg_scanner_239::on_get_feedmode(int &feedmode)//获取分纸强度
{
std::lock_guard<std::mutex> lock(io_lock_);
int ret = SCANNER_ERR_OK,
val = 0;
ret = read_register(setting3399::SR_GET_FEEDMODE,&feedmode);
if (ret == SCANNER_ERR_OK)
{
save_feedmode_type_ = true;
}
return ret;
}
int hg_scanner_239::on_set_feedmode(int feedmode)//设置分纸强度
{
std::lock_guard<std::mutex> lock(io_lock_);
int ret = SCANNER_ERR_OK,
val = 0;
ret = write_register(setting3399::SR_SET_FEEDMODE,feedmode);
return ret;
}
2022-07-30 03:19:20 +00:00
int hg_scanner_239::on_pic_type(bool& pic)
{
dev_conf_.params_3399.is_textcorrect = pic;
2022-07-30 03:19:20 +00:00
int ret = writedown_device_configuration();
return ret;
}
2022-08-09 07:59:01 +00:00
int hg_scanner_239::on_pick_paper(bool autostrength)
{
std::lock_guard<std::mutex> lock(io_lock_);
2022-08-09 07:59:01 +00:00
int val = 0,
ret = write_register(setting3399::SR_SET_AUTOMATICCONTROLFEEDMODE_ENABLE, autostrength);
2022-08-09 07:59:01 +00:00
if (ret != SCANNER_ERR_OK)
return ret;
ret = read_register(setting3399::SR_GET_AUTOMATICCONTROLFEEDMODE_ENABLE,&val);
2022-08-09 07:59:01 +00:00
return ret;
}
int hg_scanner_239::on_pick_paper_threshold(double threshold)
{
float f = threshold;
//threshold *= 10;
int val = *(int*)&f;
int ret = write_register(setting3399::SR_SET_AUTOMATICCONTROLFEEDMODE_THRESHOLD, val);
2022-08-09 07:59:01 +00:00
if (ret != SCANNER_ERR_OK)
return ret;
ret = read_register(setting3399::SR_GET_AUTOMATICCONTROLFEEDMODE_THRESHOLD,&val);
float v = *(float*)&val;
2022-08-09 07:59:01 +00:00
return ret;
}
2022-08-11 09:19:24 +00:00
int hg_scanner_239::on_is_auto_paper(bool isautopaper)
{
2022-10-28 10:42:22 +00:00
int val = 0,
ret = SCANNER_ERR_OK;
dev_conf_.params_3399.is_autopaper = isautopaper;
2022-08-11 09:19:24 +00:00
return ret;
}
2022-12-28 01:56:54 +00:00
int hg_scanner_239::on_cis_get_image(bool isautopaper)
{
is_cis_image = isautopaper;
dev_conf_.params_3399.pc_correct = isautopaper;
2023-06-26 10:00:58 +00:00
return SCANNER_ERR_OK;
2022-12-28 01:56:54 +00:00
}
int hg_scanner_239::on_process_double_paper(bool type)
{
2023-10-25 11:50:29 +00:00
if (!firmware_sup_double_check)
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
dev_conf_.params_3399.double_out_en = type;
return SCANNER_ERR_OK;
}
int hg_scanner_239::on_detect_lens_dirty(bool &type)
2023-10-25 07:00:31 +00:00
{
2023-10-25 11:50:29 +00:00
if (!firmware_sup_dirty_check)
{
type = false;
2023-10-25 11:50:29 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
}
2023-10-25 07:00:31 +00:00
is_lens_dirty = type;
return SCANNER_ERR_OK;
}
2022-05-03 03:56:07 +00:00
void hg_scanner_239::on_device_reconnected(void)
{
int ret = writedown_device_configuration();
init_version();
rewrite_conf_ = ret != SCANNER_ERR_OK;
2022-05-03 03:56:07 +00:00
if (reset_)
{
reset_ = false;
start();
}
}
int hg_scanner_239::on_scanner_closing(bool force)
{
return SCANNER_ERR_OK;
2022-05-03 03:56:07 +00:00
}
2023-01-05 10:18:38 +00:00
void hg_scanner_239::thread_correction(void)
{
StopWatch sw;
unsigned char buf[64];
//setting3399::HGEIntInfo* info = (setting3399::HGEIntInfo*)buf;
int size = sizeof(buf);
int ret = SCANNER_ERR_OK;
2023-01-05 10:18:38 +00:00
bool autoFaltFinish = false;
2023-01-05 10:18:38 +00:00
while (run_)
{
size = sizeof(buf);
memset(buf, 0, sizeof(buf));
2023-01-05 10:18:38 +00:00
{
std::lock_guard<std::mutex> lock(io_lock_);
ret = io_->read_interrupt(buf, &size);
io_->set_timeout(1000);
printf("size:%d\r\n",size);
}
2023-01-05 10:18:38 +00:00
if (ret == SCANNER_ERR_TIMEOUT)
{
if (autoFaltFinish || sw.elapsed_s() > 60)
2023-01-05 10:18:38 +00:00
{
is_auto_falt = false;
status_ = SCANNER_ERR_DEVICE_AUTO_FAIL_OVER;
//notify_ui_working_status(hg_log::lang_load(ID_STATU_DESC_SCANNER_ERR_DEVICE_FAIL_OUTTIME), SANE_EVENT_ERROR, ret); // 通信超时
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "校正是否真正结束: %s\n", autoFaltFinish ? "true" : "false");
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "设备校正超时 '%s'\n", hg_scanner_err_name(status_));
2023-01-05 10:18:38 +00:00
break;
}
std::this_thread::sleep_for(std::chrono::milliseconds(5));
continue;
2023-01-05 10:18:38 +00:00
}
if (size == sizeof(buf))
{
setting3399::HGEIntInfo info = *(setting3399::HGEIntInfo*)&buf;
if (setting3399::AutoCorrect == info.From)
2023-01-05 10:18:38 +00:00
{
2023-06-16 09:29:55 +00:00
std::lock_guard<std::mutex> lock(io_lock_);
2023-01-05 10:18:38 +00:00
status_ == SCANNER_ERR_DEVICE_AUTO_FAIL_INFO;
sw.reset();
std::string sinfo;
int len = info.Img_Index;
2023-01-05 10:18:38 +00:00
sinfo.resize(len);
io_->read_bulk(&sinfo[0],&len);
2023-06-28 11:03:14 +00:00
char buf[2048];
2023-01-05 10:18:38 +00:00
strcpy(buf, sinfo.c_str());
notify_ui_working_status(buf, SANE_EVENT_STATUS, status_);
printf("%s\r\n", sinfo.c_str());
if (info.Code == 4)
2023-01-05 10:18:38 +00:00
{
is_auto_falt = false;
2023-01-05 10:18:38 +00:00
status_ = SCANNER_ERR_DEVICE_AUTO_FAIL_OVER;
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "固件层判断校正结束返回码return Code: %d \n", info.Code);
2023-03-20 01:19:34 +00:00
//notify_ui_working_status(buf, SANE_EVENT_STATUS, status_);
break;
2023-01-05 10:18:38 +00:00
}
if (NULL != strstr(sinfo.c_str(), "******Correct Done******"))
{
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Recived : ******Correct Done****** , return Code: %d \n", info.Code);
autoFaltFinish = true;
}
//break;
2023-01-05 10:18:38 +00:00
}
}
this_thread::sleep_for(chrono::milliseconds(10));
}
}
2023-08-16 06:11:59 +00:00
int hg_scanner_239::read_control_device_files(std::string file_path, std::string& file_str)
{
std::lock_guard<std::mutex> lock(io_lock_);
string path = file_path;
if (path.empty())
{
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "read_control_device_files is fail path is %s\n", path.empty() ? "NULL" : path.c_str());
return SCANNER_ERR_NO_DATA;
}
int ret = SCANNER_ERR_OK,
len = path.size(),
lenstr = file_str.size(),
get_buffer_size = 0;
io_->set_timeout(3000);
ret = write_register(setting3399::SR_SET_JSON_PATH, len);
if (ret == SCANNER_ERR_OK)
{
ret = io_->write_bulk(&path[0], &len);
}
if (ret == SCANNER_ERR_OK)
{
ret = read_register(setting3399::SR_GET_JSON_SIZE, &get_buffer_size);
}
if (ret == SCANNER_ERR_OK)
{
ret = write_register(setting3399::SR_GET_JSON, get_buffer_size);
}
if (ret == SCANNER_ERR_OK)
{
file_str.resize(get_buffer_size);
ret = io_->read_bulk(&file_str[0], &get_buffer_size);
if (file_str.empty())
{
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "read_control_device_files get buffer is NULL %d\n", get_buffer_size);
return SCANNER_ERR_NO_DATA;
}
}
return ret;
}
int hg_scanner_239::update_boarddatetime()
{
int len = 0;
int ret = read_register(setting3399::SR_GET_ARM_DATETIME_LENGHT, &len);
std::string datenow;
datenow.resize(len);
time_t now_time;
struct tm* info;
char buffer[32];
time(&now_time);
info = localtime(&now_time);
strftime(buffer, 32, "%Y-%m-%d %H:%M:%S", info);
std::string str = buffer;
ret = write_register(setting3399::SR_SET_ARM_DATETIME, len);
if (ret != SCANNER_ERR_OK)
{
LOG_INFO(LOG_LEVEL_DEBUG_INFO, "write_control_device_files write_register [SR_SET_ARM_DATETIME] is fail \n");
return ret;
}
ret = io_->write_bulk(&str[0], &len);
if (ret != SCANNER_ERR_OK)
{
LOG_INFO(LOG_LEVEL_DEBUG_INFO, "write_control_device_files write_bulk str is fail \n");
return ret;
}
return SCANNER_ERR_OK;
}
2023-08-16 06:11:59 +00:00
int hg_scanner_239::write_control_device_files(std::string file_path, std::string file_str)
{
std::lock_guard<std::mutex> lock(io_lock_);
string path = file_path;
string str = file_str;
if (path.empty() || str.empty())
{
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO ," write_control_device_files is fail path is %s str is %s\n", path.empty() ? "NULL" : path.c_str(), str.empty() ? "NULL":str.c_str());
return SCANNER_ERR_INVALID_PARAMETER;
}
int ret = SCANNER_ERR_OK;
int len = path.size(),
lenstr = str.size();
io_->set_timeout(2000);
ret = write_register(setting3399::SR_SET_JSON_PATH, len);
if (ret != SCANNER_ERR_OK)
{
LOG_INFO(LOG_LEVEL_DEBUG_INFO,"write_control_device_files write_register [SR_SET_JSON_PATH] is fail \n");
return ret;
}
ret = io_->write_bulk(&path[0], &len);
if (ret != SCANNER_ERR_OK)
{
LOG_INFO(LOG_LEVEL_DEBUG_INFO, "write_control_device_files write_bulk path is fail \n");
return ret;
}
ret = write_register(setting3399::SR_SET_JSON, lenstr);
if (ret != SCANNER_ERR_OK)
{
LOG_INFO(LOG_LEVEL_DEBUG_INFO, "write_control_device_files write_register [SR_SET_JSON] is fail \n");
return ret;
}
ret = io_->write_bulk(&str[0], &lenstr);
if (ret != SCANNER_ERR_OK)
{
LOG_INFO(LOG_LEVEL_DEBUG_INFO, "write_control_device_files write_bulk str is fail \n");
return ret;
}
//VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "log path:%s ret:%s buffersize: %d\n", logpath.c_str(), hg_scanner_err_name(ret), buffersize);
//return ret;
return SCANNER_ERR_OK;
}
2023-01-05 10:18:38 +00:00
void hg_scanner_239::thread_get_dves_image(void)
2022-05-03 03:56:07 +00:00
{
2023-01-04 09:54:30 +00:00
char buf[64];
setting3399::HGEIntInfo* info = (setting3399::HGEIntInfo*)buf;
2022-05-03 03:56:07 +00:00
int size = sizeof(buf),
2023-01-05 10:18:38 +00:00
ret = SCANNER_ERR_OK,
count = 0;
2022-08-11 09:19:24 +00:00
int auoto_paper_indx = 0;
svdevs_err_.clear();
StopWatch sw;
bool is_quit_wait_paper_scan = false;
2023-01-05 10:18:38 +00:00
while (run_)//&& !user_cancel_
2022-05-03 03:56:07 +00:00
{
size = sizeof(buf);
{
std::lock_guard<std::mutex> lock(io_lock_);
memset(buf, 0, size);
2022-05-03 03:56:07 +00:00
ret = io_->read_interrupt(buf, &size);
2022-08-26 07:44:22 +00:00
io_->set_timeout(1000);
2022-05-03 03:56:07 +00:00
}
2023-01-16 08:03:14 +00:00
if (ret == SCANNER_ERR_TIMEOUT)
2022-05-03 03:56:07 +00:00
{
std::this_thread::sleep_for(std::chrono::milliseconds(400));
if (sw.elapsed_s() > 60 && !is_auto_scan())
2022-05-03 03:56:07 +00:00
{
status_ = ret;
notify_ui_working_status(from_default_language(STATU_DESC_SCANNER_ERR_DEVICE_GET_IMAGE_OUTTIME), SANE_EVENT_ERROR, ret); // 取图通信超时
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "get image time out:%s\n", hg_scanner_err_name(status_));
2022-05-03 03:56:07 +00:00
break;
}
if (is_auto_scan() && sw.elapsed_s() >= is_auto_paper_scan_exit_time && is_auto_paper_scan_exit_time != 0)
{
is_quit_wait_paper_scan = true;//标记待纸扫描时间到了自动结束
do_stop();
notify_ui_working_status(from_default_language(STATU_DESC_SCANNER_ERR_DEVICE_EXIT_WAIT_SCAN), SANE_EVENT_ERROR, status_);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "auto paper scan exit :%s\n", from_default_language(STATU_DESC_SCANNER_ERR_DEVICE_EXIT_WAIT_SCAN));
}
if ((get_status() & 0x03) == 0)
{
status_ = SCANNER_ERR_OK;
//break;
}
if (user_cancel_ && is_auto_scan() || is_quit_wait_paper_scan) //其他直接跳过当此循坏
2022-08-26 07:44:22 +00:00
{
size = sizeof(buf);
memset(buf, 0, size);
info->From = setting3399::STOPSCAN;
2022-08-26 10:26:43 +00:00
LOG_INFO(LOG_LEVEL_DEBUG_INFO, "User cancelled (checked when read INT timeout), we faked a 'STOP' messag to enter exiting process ...\n");
2022-08-26 07:44:22 +00:00
}
else
continue;
2022-05-03 03:56:07 +00:00
}
else if (ret != SCANNER_ERR_OK)
2022-05-03 03:56:07 +00:00
{
status_ = ret;
break;
}
sw.reset();
2022-05-03 03:56:07 +00:00
if (size == sizeof(buf))
{
status_ = settings::device_status_to_hg_err(info);
2023-05-05 09:00:37 +00:00
if (status_)
{
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "status from interrupt point is '%s'\n", hg_scanner_err_description(status_));
}
2023-01-05 10:18:38 +00:00
if (status_ != SCANNER_ERR_OK
&& status_ != SCANNER_ERR_TIMEOUT
2022-12-30 09:14:49 +00:00
&& status_ != SCANNER_ERR_DEVICE_STOPPED
&& status_ != SCANNER_ERR_DEVICE_AUTO_FAIL_OVER
&& status_ != SCANNER_ERR_DEVICE_AUTO_FAIL_INFO
)
2022-05-03 03:56:07 +00:00
{
//if (info->From != setting3399::IMG /*&& status_ != SCANNER_ERR_DEVICE_DOUBLE_FEEDING*/)
svdevs_err_.push_back(status_);
2022-05-03 03:56:07 +00:00
}
//break;
2023-11-23 03:09:31 +00:00
//杩欎釜鏃跺€欓€€鍑虹殑璇濇秷鎭氨杩樻病璇诲畬锛岄敊璇俊鎭厛淇濆瓨涓嬫潵锛屽彧鏈夎幏鍙栧埌stop鏃舵墠閫€鍑猴紝濡傛灉娌¤幏鍙栧畬閫€鍑猴紝鍙兘浼氬鑷寸浜屾鎵弿鐩存帴杩斿洖鎵弿瀹屾垚
}
if (info->From == setting3399::IMG)
{
int s = get_status();
// if (s > 0 && s < 4) // running ...
2022-05-03 03:56:07 +00:00
{
while (get_image_count() > 0)
{
ret = read_one_image_from_usb((status_ == SCANNER_ERR_DEVICE_DOUBLE_FEEDING /*&& dev_conf_.params_3399.double_out_en*/) ? IMG_STATUS_DOUBLE : IMG_STATUS_OK);
//if (status_ == SCANNER_ERR_DEVICE_DOUBLE_FEEDING)
// svdevs_err_.push_back(IMG_STATUS_DOUBLE);
2022-05-03 03:56:07 +00:00
count++;
//if (ret != SCANNER_ERR_OK
// && ret != SCANNER_ERR_CREATE_FILE_FAILED
// && ret != SCANNER_ERR_WRITE_FILE_FAILED)
2022-05-03 03:56:07 +00:00
break;
}
}
//else
// VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "status(0x%x) is not accept in usb thread\n", status);
}
2023-11-23 03:09:31 +00:00
else if (info->From == setting3399::STOPSCAN)//鍥轰欢鐗堟湰:3B0326鑾峰彇鏃犵焊鏃讹紝涓嬮潰涓柇淇℃伅浼氬厛鍙戞棤绾稿湪鍋滄鎵弿,鐒跺悗鍦ㄥ彂鏃犵焊
{ //姝ゆ椂int绔偣杩樿淇℃伅娌℃湁璇诲彇瀹岋紝鑰屼笖閫€鍑虹偣鍑荤户缁壂鎻忥紝涓嬮潰璁惧杩樻湭缁撴潫鎵弿
if (!svdevs_err_.empty())
{
status_ = svdevs_err_.front();
}
LOG_INFO(LOG_LEVEL_DEBUG_INFO, "received 'STOPSCAN' message in usb thread, check remaining image and finish scanning ...\n");
2023-01-05 10:18:38 +00:00
// fetch all buffered images and exit ...
//while(!is_dev_image_process_done())
if (img_conf_.resolution_dst > 200 && is_quality_ == IMG_QUALITY) //鍒犻櫎杩欐浠g爜锛屼綘鍙兘闇€瑕佽€冭檻涓€涓嬪悗鏋?
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
else
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
int rest = 0;
while (get_image_count() > 0)
{
ret = read_one_image_from_usb();
rest++;
if (ret != SCANNER_ERR_OK
&& ret != SCANNER_ERR_CREATE_FILE_FAILED
&& ret != SCANNER_ERR_WRITE_FILE_FAILED)
break;
2022-05-03 03:56:07 +00:00
}
count += rest;
if (rest)
{
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "STOPSCAN message is ahead of %d image(s)!\n", rest);
}
if (user_cancel_ && !is_auto_scan())
2022-05-03 03:56:07 +00:00
{
if (status_ && status_ != SCANNER_ERR_DEVICE_STOPPED) // thread_handle_image_process maybe call stop() when insufficient memory occurs .
ret = status_;
else
status_ = ret = SCANNER_ERR_USER_CANCELED;
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "%s\n", hg_log::lang_load(ID_STATU_DESC_SCANNER_ERR_DEVICE_GET_USER_CANCEL_SCAN));
auoto_paper_indx = 0;
2022-05-03 03:56:07 +00:00
break;
}
if (count == 0)
2022-12-30 09:14:49 +00:00
{
//std::lock_guard<std::mutex> lock(io_lock_);
//LOG_INFO(LOG_LEVEL_DEBUG_INFO, "First message received from USB is 'STOPSCAN'\n");
// notify_ui_working_status(STATU_DESC_DEVICE_RESET);
// reset_ = true;
// ret = io_->reset();
// status_ = SCANNER_ERR_IO;
if (status_ == SCANNER_ERR_DEVICE_STOPPED)
status_ = SCANNER_ERR_OK;
}
else if (status_ == SCANNER_ERR_TIMEOUT || status_ == SCANNER_ERR_IO || status_ == SCANNER_ERR_DEVICE_STOPPED)
status_ = SCANNER_ERR_OK;
int s = get_status();
if (count == 0 || (s & 3) == 0)
{
LOG_INFO(LOG_LEVEL_DEBUG_INFO, "Really stopped ^_^\n");
string str = hg_log::lang_load(ID_STATU_DESC_SCANNER_ERR_DEVICE_ROUND_SACN_OVER);
str += ":" + to_string(++auoto_paper_indx);
if (!user_cancel_ && is_auto_scan() && svdevs_err_.empty() && !is_quit_wait_paper_scan)
notify_ui_working_status(str.c_str(), SANE_EVENT_ERROR, status_);
else
2022-12-30 09:14:49 +00:00
break;
}
}
else if (info->From == setting3399::V4L2)
{
VLOG_MINI_2(LOG_LEVEL_WARNING, "V4L2 message received, code = %d, index = %d\n", info->Code, info->Img_Index);
// do_stop();
break;
}
else if (info->From == setting3399::AutoCorrect)
{
std::string devs_info;
int len = info->Img_Index;
devs_info.resize(len);
ret = io_->read_bulk(&info[0], &len);
if (ret == SCANNER_ERR_OK)
2022-05-03 03:56:07 +00:00
{
notify_ui_working_status(devs_info.c_str(), SANE_EVENT_STATUS, status_);
2022-05-03 03:56:07 +00:00
}
if (status_ == SCANNER_ERR_DEVICE_AUTO_FAIL_OVER)
break;
}
else
{
// error handling ...
VLOG_MINI_4(LOG_LEVEL_DEBUG_INFO, "Read HGEIntInfo: From = %d, Code = %d, Img_Index = %d, status = %s\n", info->From, info->Code, info->Img_Index, hg_scanner_err_description(status_));
2022-05-03 03:56:07 +00:00
}
}
this_thread::sleep_for(chrono::milliseconds(10));
// stop 通过int端点返回 如果不反回则是固件问题,软件不做处理
2023-05-05 09:00:37 +00:00
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "USB thread exit with code: %s, status = %s\n", hg_scanner_err_name(ret), hg_scanner_err_description(status_));
2022-05-03 03:56:07 +00:00
}
2023-01-05 10:18:38 +00:00
void hg_scanner_239::thread_handle_usb_read(void)
{
if (is_auto_falt)
thread_correction();
else
thread_get_dves_image();
}
2022-12-23 08:51:10 +00:00
int hg_scanner_239::do_start(void)
2022-05-03 03:56:07 +00:00
{
bool handled = false;
int ret = try_third_app_handle_start(handled),
2022-10-12 06:26:29 +00:00
val = 0;
// for third-sane-app invoking, added on 2022-05-19
if (handled)
return ret;
2022-12-13 10:13:46 +00:00
2022-10-12 06:26:29 +00:00
split3399_ = 0;
2022-05-03 03:56:07 +00:00
cb_mem_ = true;
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "scanner status: 0x%x\n", get_status());
2022-05-03 03:56:07 +00:00
reset();
2023-11-23 03:09:31 +00:00
//211220固件版本不支持返回
2022-12-22 10:37:53 +00:00
ret = get_scan_is_sleep(val);
2023-02-13 08:38:05 +00:00
if (!val && ret == SCANNER_ERR_OK)
{
2022-11-24 16:54:43 +00:00
status_ = SCANNER_ERR_DEVICE_SLEEPING;
VLOG_MINI_1(LOG_LEVEL_WARNING, "device start status is(%s)\n", hg_log::lang_load(ID_STATU_DESC_SCANNER_ERR_DEVICE_SLEEPING));
2023-06-26 10:00:58 +00:00
set_notify_sleep();
return status_;
}
2023-02-13 08:38:05 +00:00
if (ret != SCANNER_ERR_OK)
{
return ret;
}
2022-12-22 10:37:53 +00:00
bool type = true;
ret = get_scan_mode(type);
2023-02-13 08:38:05 +00:00
if (!type && ret == SCANNER_ERR_OK)
2022-05-03 03:56:07 +00:00
{
2022-11-24 16:54:43 +00:00
status_ = SCANNER_ERR_DEVICE_COUNT_MODE;
return status_;
}
2022-08-26 07:44:22 +00:00
2022-10-11 08:22:32 +00:00
if(ret == SCANNER_ERR_OK)
2022-05-03 03:56:07 +00:00
{
2022-11-19 10:16:43 +00:00
ret = writedown_device_configuration(true);
}
if(ret == SCANNER_ERR_OK)
2022-05-03 03:56:07 +00:00
{
ret = writedown_image_configuration();
}
if (ret)
{
VLOG_MINI_1(LOG_LEVEL_WARNING, "Write down image process parameters fail is(%s), the result will be unpredictable.\n", hg_scanner_err_name(ret));
2022-05-03 03:56:07 +00:00
}
if (ret != SCANNER_ERR_OK)
2022-05-03 03:56:07 +00:00
{
VLOG_MINI_1(LOG_LEVEL_WARNING, "start status01 is(%s), the result will be unpredictable.\n", hg_scanner_err_name(ret));
2022-05-03 03:56:07 +00:00
return ret;
}
2023-01-04 05:53:04 +00:00
#ifdef OEM_HUAGAO
2022-12-13 10:13:46 +00:00
if (is_checksum_strat_scan)
{
std::string str("C34E58CD5F3F2FF703E1AA24892FBD69");
set_scan_lock_check_val(str);
}
2023-01-04 05:53:04 +00:00
#endif
ret = write_command(setting3399::SC_START);
2022-05-03 03:56:07 +00:00
io_->set_timeout(1000);
if (ret == SCANNER_ERR_OK)
2022-05-03 03:56:07 +00:00
{
wait_usb_.notify();
this_thread::sleep_for(chrono::milliseconds(100));
ret = try_third_app_after_start(ret);
2022-05-03 03:56:07 +00:00
}
else
{
status_ = ret;
VLOG_MINI_3(LOG_LEVEL_WARNING, "(%s)[Thread %s]Send start command = %s\n", hg_log::current_time().c_str(), hg_log::format_current_thread_id().c_str(), hg_scanner_err_name(ret));
2022-05-03 03:56:07 +00:00
}
2023-05-05 09:00:37 +00:00
VLOG_MINI_1(LOG_LEVEL_WARNING, "----------Main start scan status : %s----------\n", hg_scanner_err_description(ret));
2022-05-03 03:56:07 +00:00
return ret;
}
int hg_scanner_239::do_stop(void)
2022-05-03 03:56:07 +00:00
{
2022-08-25 05:08:54 +00:00
int ret = SCANNER_ERR_OK;
2022-08-26 07:44:22 +00:00
ret = write_command(setting3399::SC_STOP);
2022-08-26 07:44:22 +00:00
io_->set_timeout(500);
return ret;
2022-05-03 03:56:07 +00:00
}
int hg_scanner_239::reset(void)
{
imgs_.Clear(); // move from scanning done
final_imgs_.clear();
2022-05-03 03:56:07 +00:00
discard_all_images();
return status_;
}
int hg_scanner_239::device_io_control(unsigned long code, void* data, unsigned* len)
{
int ret = SCANNER_ERR_OUT_OF_RANGE;
2022-05-03 03:56:07 +00:00
if (HG_CONTROL_CODE_OPTION_ENABLE == code)
{
OPTEN* opten = (OPTEN*)data;
ret = SCANNER_ERR_OK;
if (opten->name == SANE_STD_OPT_NAME_ANTI_SKEW && !opten->enabled) // for BUG-20 modified by Gongbing on 2022-03-12
2022-05-03 03:56:07 +00:00
{
bool enable = true;
long l = sizeof(enable);
setting_automatic_skew(&enable, &l);
2022-05-03 03:56:07 +00:00
}
}
else if (IO_CTRL_CODE_TEST_SINGLE == code)
{
test_1_paper_ = true;
ret = start();
}
else
ret = hg_scanner::device_io_control(code, data, len);
return ret;
}
std::string hg_scanner_239::get_firmware_version(void)
{
std::lock_guard<std::mutex> lock(io_lock_);
return control_fetch(setting3399::SR_GET_FWVERSION, 0, 20);
2022-05-03 03:56:07 +00:00
}
std::string hg_scanner_239::get_serial_num(void)
{
std::lock_guard<std::mutex> lock(io_lock_);
2022-12-13 10:13:46 +00:00
int len = 0;
read_register(setting3399::SR_GET_SERIAL_LEN, &len);///???
if (len > 30)
{
len = 30;
}
2022-12-13 10:13:46 +00:00
return control_fetch(setting3399::SR_GET_SERIALNUM, 0, len).substr(0,len);
2022-05-03 03:56:07 +00:00
}
std::string hg_scanner_239::get_ip(void)
{
std::lock_guard<std::mutex> lock(io_lock_);
int len = 20;
//read_register(setting3399::SR_GET_SERIAL_LEN, &len);
2023-02-21 01:54:26 +00:00
return control_fetch(setting3399::SR_GET_IPADDR, 0, len);
2022-05-03 03:56:07 +00:00
}
2023-02-03 02:30:57 +00:00
std::string hg_scanner_239::get_device_model(void)
{
string device_model = "/home/linaro/microtek_sn";
string str;
int ret = SCANNER_ERR_OK;
int buffersize = 0;
int len = device_model.size();
2023-08-16 06:11:59 +00:00
read_control_device_files(device_model, str);
2023-02-03 02:30:57 +00:00
return str;
}
2023-03-20 04:09:33 +00:00
int hg_scanner_239::set_device_model(string str)
{
if (str.empty())
{
return SCANNER_ERR_NO_DATA;
}
2023-08-16 06:11:59 +00:00
string device_model = "/home/linaro/microtek_sn";
2023-03-20 04:09:33 +00:00
2023-08-16 06:11:59 +00:00
return write_control_device_files(device_model, str);
2023-03-20 04:09:33 +00:00
}
2023-01-03 03:12:26 +00:00
int hg_scanner_239::set_serial_num(string str)
{
std::lock_guard<std::mutex> lock(io_lock_);
2023-01-03 03:12:26 +00:00
int len = str.size(),
ret = write_register(setting3399::SR_SET_SERIALNUM, len);
if (ret == SCANNER_ERR_OK)
{
ret = io_->write_bulk(&str[0],&len);
}
return ret;
}
int hg_scanner_239::set_vid_pid(int data)
{
std::lock_guard<std::mutex> lock(io_lock_);
2023-01-03 03:12:26 +00:00
return write_register(setting3399::SR_SET_USBVIDPID, data);
}
int hg_scanner_239::get_vid_pid(int& data)
{
std::lock_guard<std::mutex> lock(io_lock_);
2023-01-03 03:12:26 +00:00
return read_register(setting3399::SR_GET_USBVIDPID, &data);
}
2022-12-29 10:05:59 +00:00
int hg_scanner_239::get_history_scan_count(int &val)
2022-05-03 03:56:07 +00:00
{
std::lock_guard<std::mutex> lock(io_lock_);
int ret = read_register(setting3399::SR_GET_SCANN_NUM, &val);
return ret;
2022-05-03 03:56:07 +00:00
}
2022-12-22 10:37:53 +00:00
int hg_scanner_239::set_clear_roller_num(void)
2022-05-03 03:56:07 +00:00
{
std::lock_guard<std::mutex> lock(io_lock_);
2022-05-03 03:56:07 +00:00
int val = 0,
ret = read_register(setting3399::SR_CLR_ROLLER_NUM, &val);
2022-05-03 03:56:07 +00:00
return ret;
}
int hg_scanner_239::set_clear_history_num(void)
{
int ret = SCANNER_ERR_OK;
if (pid_ == 0x439)
{
2023-08-16 06:11:59 +00:00
string json_path = "/usr/local/huago/scannerinfo.json";
string str;
int buffersize = 0;
int len = json_path.size();
ret = read_control_device_files(json_path, str);
std::string str2;
json js = json::parse(str);
if (js.contains("TotalScanned"))
{
js["TotalScanned"] = 0;
str2 = js.dump();
}
2023-08-16 06:11:59 +00:00
if (ret == SCANNER_ERR_OK)
{
ret = write_control_device_files(json_path, str2);
}
}
else
{
std::lock_guard<std::mutex> lock(io_lock_);
int val = 0;
ret = read_register(setting3399::SR_CLR_SCANN_NUM, &val);
}
return ret;
}
2022-05-03 03:56:07 +00:00
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int hg_scanner_239::set_leaflet_scan(void)
{
2023-06-15 09:54:37 +00:00
//std::lock_guard<std::mutex> lock(io_lock_);
int ret = SCANNER_ERR_OK;
2022-05-03 03:56:07 +00:00
test_1_paper_ = true;
ret = start();
return ret;
}
2022-12-22 10:37:53 +00:00
2022-05-03 03:56:07 +00:00
int hg_scanner_239::get_device_code(void)
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
2022-05-03 03:56:07 +00:00
}
2022-12-22 10:37:53 +00:00
int hg_scanner_239::get_sleep_time(int& data)
2022-05-03 03:56:07 +00:00
{
std::lock_guard<std::mutex> lock(io_lock_);
2022-12-22 10:37:53 +00:00
int val = 0;
int ret = read_register(setting3399::SR_GET_SLEEPTIME, &val);
2022-05-03 03:56:07 +00:00
if (ret == SCANNER_ERR_OK)
2022-05-03 03:56:07 +00:00
{
save_sleeptime_type_ = true;
2022-12-22 10:37:53 +00:00
data = val;
2022-05-03 03:56:07 +00:00
}
2022-12-22 10:37:53 +00:00
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "get_sleep_time = %d with %s\n", data,hg_scanner_err_name(ret));
return ret;
2022-05-03 03:56:07 +00:00
}
int hg_scanner_239::set_sleep_time(int setsleepime)
{
std::lock_guard<std::mutex> lock(io_lock_);
int ret = write_register(setting3399::SR_SET_SLEEPTIME, setsleepime);
2022-05-03 03:56:07 +00:00
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "set sleep time to %d = %s\n", setsleepime, hg_scanner_err_name(ret));
2022-05-03 08:44:13 +00:00
return ret;
2022-05-03 03:56:07 +00:00
}
2022-12-22 10:37:53 +00:00
int hg_scanner_239::get_scanner_paperon(SANE_Bool& type)
2022-05-03 03:56:07 +00:00
{
std::lock_guard<std::mutex> lock(io_lock_);
2022-12-22 10:37:53 +00:00
int val = 0;
int ret = read_register(setting3399::SR_GET_PAPERON, &val); //0无纸 1有纸
2022-12-22 10:37:53 +00:00
if (ret == SCANNER_ERR_OK)
2022-05-03 03:56:07 +00:00
{
type = val == 0 ? SANE_FALSE : SANE_TRUE;
2022-05-03 03:56:07 +00:00
}
VLOG_MINI_1(LOG_LEVEL_WARNING, "get_scanner_paperon is(%s)\n", val == 0 ? hg_scanner_err_description(SCANNER_ERR_DEVICE_NO_PAPER) : "paper on");
2022-12-22 10:37:53 +00:00
2022-05-03 03:56:07 +00:00
return ret;
}
2022-12-22 10:37:53 +00:00
int hg_scanner_239::get_scan_is_sleep(SANE_Bool& type)
{
std::lock_guard<std::mutex> lock(io_lock_);
2022-12-22 10:37:53 +00:00
int ret = 0,val;
2023-11-23 03:09:31 +00:00
ret = read_register(setting3399::SR_GET_SLEEP_STAUTUS, &val); //0休眠 1唤醒状态
2022-12-22 10:37:53 +00:00
if (ret == SCANNER_ERR_OK)
{
type = val == 1 ? true : false;
}
2023-06-15 08:27:20 +00:00
VLOG_MINI_1(LOG_LEVEL_WARNING, "get_scanner_paperon is(%s)\n", !type ? hg_scanner_err_description(SCANNER_ERR_DEVICE_SLEEPING) : hg_scanner_err_description(SCANNER_ERR_OK));
2022-12-22 10:37:53 +00:00
return ret;
2022-05-03 03:56:07 +00:00
}
2022-12-22 10:37:53 +00:00
int hg_scanner_239::set_notify_sleep()
{
2023-06-26 10:00:58 +00:00
if (!firmware_sup_wake_device_)
{
2023-06-26 10:00:58 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
}
2023-06-26 10:00:58 +00:00
std::lock_guard<std::mutex> lock(io_lock_);
int val = 0;
return write_register(setting3399::SR_NOTIFY_SLEEP, val);
}
int hg_scanner_239::get_roller_num(int &num)
{
std::lock_guard<std::mutex> lock(io_lock_);
int ret = read_register(setting3399::SR_GET_ROLLER_NUM, &num);
return ret;
}
2022-07-26 07:14:29 +00:00
int hg_scanner_239::get_device_log(string &logpath)
{
2023-06-26 10:00:58 +00:00
if (!firmware_sup_log_export_)
2023-06-14 07:06:02 +00:00
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
}
std::lock_guard<std::mutex> lock(io_lock_);
2022-07-26 07:14:29 +00:00
string save_path = hg_log::temporary_path() + PATH_SEPARATOR + "device.log";
string device_log_path = "/var/log/syslog";
string str ;
int ret = SCANNER_ERR_OK;
int buffersize = 0;
int len = device_log_path.size();
io_->set_timeout(3000);
ret = write_register(setting3399::SR_SET_JSON_PATH, len);
2022-07-26 07:14:29 +00:00
if (ret != SCANNER_ERR_OK)
return ret;
ret = io_->write_bulk(&device_log_path[0],&len);
if (ret != SCANNER_ERR_OK)
return ret;
ret = read_register(setting3399::SR_GET_JSON_SIZE,&buffersize);
2022-07-26 07:14:29 +00:00
if (ret != SCANNER_ERR_OK || buffersize <= 0)
return ret;
ret = write_register(setting3399::SR_GET_JSON,buffersize);
2022-07-26 07:14:29 +00:00
if (ret != SCANNER_ERR_OK || buffersize <= 0)
return ret;
str.resize(buffersize);
2023-05-18 03:00:14 +00:00
int block = buffersize,
total = buffersize,
index = 0;
while (total > 0)
{
block = 512 * 1024;
if (total< block)
{
block = total;
}
ret = io_->read_bulk(&str[index], &block);
if (ret != SCANNER_ERR_OK)
return ret;
index += block;
total -= block;
}
2022-07-26 07:14:29 +00:00
if (ret != SCANNER_ERR_OK)
return ret;
ofstream f;
2023-05-18 06:39:08 +00:00
f.open(save_path,ios::out | ios::trunc);
2022-07-26 07:14:29 +00:00
if (!f.is_open())
return SCANNER_ERR_CREATE_FILE_FAILED;
f << str << endl;
f.close();
logpath = save_path;
2022-07-26 07:34:13 +00:00
VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "log path:%s ret:%s buffersize: %d\n", logpath.c_str(),hg_scanner_err_name(ret),buffersize);
return ret;
}
2022-12-28 01:56:54 +00:00
int hg_scanner_239::set_devreboot(int data)
2022-10-13 07:11:58 +00:00
{
std::lock_guard<std::mutex> lock(io_lock_);
2022-12-28 01:56:54 +00:00
return write_register(setting3399::SR_REBOOT, data);
2022-10-13 07:11:58 +00:00
}
int hg_scanner_239::set_devshtudown()
{
std::lock_guard<std::mutex> lock(io_lock_);
2022-10-13 07:11:58 +00:00
int val = 0,
ret = write_register(setting3399::SR_POWEROFF, val);
2022-10-13 07:11:58 +00:00
if (ret != SCANNER_ERR_OK)
return ret;
2022-10-28 03:01:01 +00:00
}
int hg_scanner_239::set_scan_islock(SANE_Bool set_islock)
{
std::lock_guard<std::mutex> lock(io_lock_);
2023-06-26 10:00:58 +00:00
if (!firmware_sup_devs_lock_)
2022-12-06 09:57:00 +00:00
{
2023-06-15 08:27:20 +00:00
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "devs lock:%s \n", hg_scanner_err_description(SCANNER_ERR_DEVICE_NOT_SUPPORT));
2022-12-06 09:47:27 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
2022-12-06 09:57:00 +00:00
}
2022-10-28 03:01:01 +00:00
2022-11-03 10:15:51 +00:00
if (set_islock != 0 && set_islock != 1)
2022-12-06 09:57:00 +00:00
{
2023-06-15 08:27:20 +00:00
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "devs lock:%s \n", hg_scanner_err_description(SCANNER_ERR_INVALID_PARAMETER));
2022-11-03 10:15:51 +00:00
return SCANNER_ERR_INVALID_PARAMETER;
2022-12-06 09:57:00 +00:00
}
2022-10-28 03:01:01 +00:00
int val = 0,
ret = write_register(setting3399::SR_SET_LOCK_STATES, set_islock);
2022-11-24 15:34:38 +00:00
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Set scanner is lock:%d\r\n", set_islock);
2022-10-28 03:01:01 +00:00
return ret;
}
int hg_scanner_239::get_scan_islock(SANE_Bool& islock)
2022-10-28 03:01:01 +00:00
{
std::lock_guard<std::mutex> lock(io_lock_);
2023-06-26 10:00:58 +00:00
if (!firmware_sup_devs_lock_)
2022-12-06 09:57:00 +00:00
{
2023-06-15 08:27:20 +00:00
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "devs lock:%s \n", hg_scanner_err_description(SCANNER_ERR_DEVICE_NOT_SUPPORT));
2022-12-06 09:47:27 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
2022-12-06 09:57:00 +00:00
}
2022-12-05 15:01:13 +00:00
int val = 0,
ret = read_register(setting3399::SR_GET_LOCK_STATES, &val);
2022-11-02 10:06:49 +00:00
if (ret != SCANNER_ERR_OK)
return ret;
2022-10-28 03:01:01 +00:00
islock = val;
ret = islock ? SCANNER_ERR_DEVICE_ISLOCK : SCANNER_ERR_OK;
2022-11-24 15:34:38 +00:00
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Get scanner is lock:%d\r\n", ret);
return ret;
2022-10-28 03:01:01 +00:00
}
int hg_scanner_239::set_scan_lock_check_val(string check_str)
{
2023-06-26 10:00:58 +00:00
if (!firmware_sup_devs_lock_)
2022-12-06 09:57:00 +00:00
{
2023-06-15 08:27:20 +00:00
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "devs lock:%s \n", hg_scanner_err_description(SCANNER_ERR_DEVICE_NOT_SUPPORT));
2022-12-06 09:47:27 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
2022-12-06 09:57:00 +00:00
}
#if defined(WIN32) || defined(_WIN64)
2022-12-13 10:13:46 +00:00
std::string encoded;
std::string cipher;
std::string keys = check_str;
//string sn = "G2396021071101";
string sn = get_serial_num();
if (sn.empty())
2022-10-28 03:01:01 +00:00
{
return SCANNER_ERR_INVALID_PARAMETER;
}
2023-11-23 03:09:31 +00:00
int num = 32 - keys.size(); //保持32位下发
2022-11-02 10:06:49 +00:00
if (num > 0)
2022-10-28 03:01:01 +00:00
{
2022-12-13 10:13:46 +00:00
std::string str(num, '0');
keys += str;
2022-10-28 03:01:01 +00:00
}
2022-12-13 10:13:46 +00:00
else
keys = keys.substr(0, 32);
2022-10-28 03:01:01 +00:00
2022-12-13 10:13:46 +00:00
unsigned char key[CryptoPP::AES::DEFAULT_KEYLENGTH] = { 0 };
for (int i = 0; i < 16; i++)
2022-11-02 10:06:49 +00:00
{
2022-12-13 10:13:46 +00:00
key[i] = _strtoi64(keys.substr(i * 2, 2).c_str(), nullptr, 16);
2022-11-02 10:06:49 +00:00
}
2022-12-13 10:13:46 +00:00
CryptoPP::ECB_Mode<CryptoPP::AES>::Encryption encode;
encode.SetKey(key, 16);
CryptoPP::StringSink* str_cip = new CryptoPP::StringSink(cipher);
CryptoPP::StreamTransformationFilter* ecb_filter = new CryptoPP::StreamTransformationFilter(encode, str_cip, CryptoPP::BlockPaddingSchemeDef::W3C_PADDING);
CryptoPP::StringSource* source_plain = new CryptoPP::StringSource(sn, true, ecb_filter);
encoded.clear();
2022-11-02 10:06:49 +00:00
CryptoPP::StringSink* str_encode = new CryptoPP::StringSink(encoded);
CryptoPP::HexEncoder* hex_encode = new CryptoPP::HexEncoder(str_encode);
2022-12-13 10:13:46 +00:00
CryptoPP::StringSource* source_cipher = new CryptoPP::StringSource(cipher, true, hex_encode);
2022-11-02 10:06:49 +00:00
2022-12-13 10:13:46 +00:00
int len = encoded.length();
int ret = SCANNER_ERR_OK;
2022-10-28 03:01:01 +00:00
{
std::lock_guard<std::mutex> lock(io_lock_);
ret = write_register(setting3399::SR_DECODE_TOKEN, len);
if (ret == SCANNER_ERR_OK)
{
ret = io_->write_bulk(&encoded[0], &len);
}
2022-10-28 03:01:01 +00:00
}
2022-12-13 10:13:46 +00:00
SAFE_DELETE(source_plain);
//SAFE_DELETE(ecb_filter);
2023-10-08 06:38:05 +00:00
//SAFE_DELETE(str_cip);
SAFE_DELETE(source_cipher);
2022-12-13 10:13:46 +00:00
//SAFE_DELETE(hex_encode);
2023-10-08 06:38:05 +00:00
//SAFE_DELETE(str_encode);
2022-10-28 03:01:01 +00:00
return ret;
#endif
2022-11-03 10:09:32 +00:00
}
2022-12-22 10:37:53 +00:00
int hg_scanner_239::set_firmware_upgrade(std::string filename)
2022-11-03 10:09:32 +00:00
{
std::lock_guard<std::mutex> lock(io_lock_);
2022-11-03 10:09:32 +00:00
std::ifstream fwname;
int ret = SCANNER_ERR_OK;
fwname.open(filename, std::ios_base::in | std::ios_base::binary);
if (!fwname.is_open())
{
return SCANNER_ERR_OPEN_FILE_FAILED;
2022-11-03 10:09:32 +00:00
}
fwname.seekg(0, std::ios::end);
2023-11-23 03:09:31 +00:00
int total = fwname.tellg();//记录总长度
2022-11-03 10:09:32 +00:00
fwname.seekg(0, std::ios::beg);
int pos = fwname.tellg();//记录pos位置
2022-11-03 10:09:32 +00:00
ret = write_register(setting3399::SR_UPDATA_START,total);
if (ret != SCANNER_ERR_OK)
{
return ret;
}
int block = total;
while (total > 0)
{
block = 512 * 1024;
if (total < block)
block = total;
std::vector<char>data;
data.resize(block + 1);
fwname.read(data.data(), block);
io_->write_bulk(data.data(), &block);
if (ret != SCANNER_ERR_OK)
return ret;
pos += block;
total -= block;
fwname.seekg(pos);
}
this_thread::sleep_for(std::chrono::milliseconds(200));
int val = 0;
2022-11-04 01:23:29 +00:00
ret = read_register(setting3399::SR_UPDATA_STAUTUS, &val);
2022-11-03 10:09:32 +00:00
if (ret != SCANNER_ERR_OK)
return ret;
else if (!val)
return SCANNER_ERR_DEVICE_UPGRADE_FAIL;
int to_cnt = 0;
2023-11-23 03:09:31 +00:00
// 到这个位置已经能够升级成功了 后面对升级结果做下判断
auto now = std::chrono::steady_clock::now();
while (std::chrono::duration<double>(std::chrono::steady_clock::now() - now).count() < 70)
2022-11-03 10:09:32 +00:00
{
int ret = read_register(setting3399::SR_UPDATA_MD5_RELUST, &val);
2022-11-03 10:09:32 +00:00
if (ret != SCANNER_ERR_OK)
{
return ret;
}
if (val == 1)
{
return SCANNER_ERR_DEVICE_UPGRADE_FAIL;
}
2022-11-03 10:09:32 +00:00
if (val == 2)
{
int ret = read_register(setting3399::SR_UPDATA_REBOOT, &val);
return ret;
2022-11-03 10:09:32 +00:00
}
else if(val ==3)
{
int ret = read_register(setting3399::SR_UPDATA_RECOVERY, &val);
return ret;
2022-11-03 10:09:32 +00:00
}
else if (val == 6)
2022-11-03 10:09:32 +00:00
{
return false;
2022-11-03 10:09:32 +00:00
}
this_thread::sleep_for(std::chrono::milliseconds(20));
2022-11-03 10:09:32 +00:00
}
return ret;
}
2022-12-22 10:37:53 +00:00
int hg_scanner_239::set_clean_paper_road()
{
std::lock_guard<std::mutex> lock(io_lock_);
int ret = 0, len = 0;
ret = write_register(setting3399::SR_CLEAN_PAPER_ROAD, len);
return ret;
}
int hg_scanner_239::get_dev_islock_file(int& islockfile)
{
2023-06-26 10:00:58 +00:00
if (!firmware_sup_devs_lock_)
{
2023-06-15 08:27:20 +00:00
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "devs lock:%s \n", hg_scanner_err_description(SCANNER_ERR_DEVICE_NOT_SUPPORT));
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
}
string device_log_path = "/var/log/black_list_file.txt";
string str;
2023-08-16 06:11:59 +00:00
int buffersize;
2023-08-16 06:11:59 +00:00
int ret = read_control_device_files(device_log_path, str);
if (ret == SCANNER_ERR_OK && str.size() > 0)
islockfile = std::stoi(str);
else
islockfile = -1;
2023-08-16 06:11:59 +00:00
buffersize = str.size();
2023-06-15 08:27:20 +00:00
VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "get list file is:%s ret:%s buffersize: %d\n", device_log_path.c_str(), hg_scanner_err_description(ret), buffersize);
return ret;
}
int hg_scanner_239::set_dev_islock_file(int islockfile)
{
2023-06-26 10:00:58 +00:00
if (!firmware_sup_devs_lock_)
{
2023-06-15 08:27:20 +00:00
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "devs lock:%s \n", hg_scanner_err_description(SCANNER_ERR_DEVICE_NOT_SUPPORT));
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
}
if (islockfile != 0 && islockfile != 1)
{
2023-11-23 03:09:31 +00:00
return SCANNER_ERR_INVALID_PARAMETER; //这个地方设置的参数必须保证正确
}
string device_log_path = "/var/log/black_list_file.txt";
string str = std::to_string(islockfile);
2023-08-16 06:11:59 +00:00
return write_control_device_files(device_log_path, str);
2023-04-28 08:19:59 +00:00
}