code_device/hgdriver/hgdev/hg_scanner_239.cpp

1976 lines
92 KiB
C++
Raw Normal View History

2022-05-03 03:56:07 +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
#include <map>
//#define SAVE_TO_FILE
#define USB_REQ_GET_FPGA_REGS 0x40
#define USB_REQ_SET_FPGA_REGS 0x41
#define USB_REQ_GET_MOTOR_REGS 0x42
#define USB_REQ_SET_MOTOR_REGS 0x43
#define USB_REQ_GET_DEV_STATUS 0x60
#define USB_REQ_GET_DEV_CONFIGURATION 0x61
#define USB_REQ_SET_DEV_CONFIGURATION 0x62
#define USB_REQ_GET_DEV_REGS 0x63
#define USB_REQ_SET_DEV_REGS 0x64
#ifdef OEM_LISICHENG
2022-07-26 09:37:21 +00:00
static std::string jsontext1("{\"device_type\":\"G239-lsc\",\"option_count\":61,\"1\":{\"category\":\"base\",\"name\":\"cfg-1\",\"title\":\"\\u6062\\u590d\\u9ed8\\u8ba4\\u8bbe\\u7f6e\",\"desc\":\"\\u6062\\u590d\\u9ed8\\u8ba4\\u8bbe\\u7f6e\",\"type\":\"button\",\"cur\":\"button\",\"default\":\"button\",\"size\":0},\"2\":{\"category\":\"advanced\",\"name\":\"cfg-2\",\"title\":\"\\u5e2e\\u52a9\",\"desc\":\"\\u663e\\u793a\\u8f6f\\u4ef6\\u5e2e\\u52a9\\u6587\\u6863\",\"type\":\"button\",\"cur\":\"true\",\"default\":\"true\",\"size\":4},\"3\":{\"category\":\"base\",\"name\":\"grp-1\",\"title\":\"\\u57fa\\u672c\\u8bbe\\u7f6e\",\"type\":\"group\"},\"4\":{\"category\":\"base\",\"name\":\"cfg-4\",\"title\":\"\\u591a\\u6d41\\u8f93\\u51fa\",\"desc\":\"\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4},\"5\":{\"category\":\"base\",\"name\":\"cfg-5\",\"title\":\"\\u591a\\u6d41\\u8f93\\u51fa\\u7c7b\\u578b\",\"desc\":\"\",\"type\":\"string\",\"cur\":\"\\u65e0\",\"default\":\"\\u65e0\",\"size\":32,\"range\":[\"\\u5f69\\u8272+\\u7070\\u5ea6+\\u9ed1\\u767d\",\"\\u5f69\\u8272+\\u7070\\u5ea6\",\"\\u5f69\\u8272+\\u9ed1\\u767d\",\"\\u7070\\u5ea6+\\u9ed1\\u767d\"],\"depend_or\":[\"4==true\"]},\"6\":{\"category\":\"base\",\"name\":\"mode\",\"title\":\"\\u989c\\u8272\\u6a21\\u5f0f\",\"desc\":\"\\u8bbe\\u7f6e\\u989c\\u8272\\u4f4d\\u6df1\",\"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\":[\"4!=true\"]},\"7\":{\"category\":\"base\",\"name\":\"cfg-7\",\"title\":\"\\u9ed1\\u767d\\u56fe\\u50cf\\u9608\\u503c\",\"desc\":\"\",\"type\":\"int\",\"cur\":128,\"default\":128,\"size\":4,\"range\":{\"min\":0,\"max\":255},\"depend_or\":[\"6==\\u9ed1\\u767d\"]},\"8\":{\"category\":\"base\",\"name\":\"cfg-8\",\"title\":\"\\u7070\\u5ea6\\u6216\\u9ed1\\u767d\\u56fe\\u50cf - \\u9664\\u8272\",\"desc\":\"\\u9664\\u53bb\\u56fe\\u50cf\\u5f69\\u8272\",\"type\":\"string\",\"cur\":\"\\u4e0d\\u9664\\u8272\",\"default\":\"\\u4e0d\\u9664\\u8272\",\"size\":24,\"range\":[\"\\u4e0d\\u9664\\u8272\",\"\\u9664\\u7ea2\\u8272\",\"\\u9664\\u7eff\\u8272\",\"\\u9664\\u84dd\\u8272\",\"\\u7ea2\\u8272\\u589e\\u5f3a\",\"\\u7eff\\u8272\\u589e\\u5f3a\",\"\\u84dd\\u8272\\u589e\\u5f3a\"],\"depend_and\":[\"4!=true\",\"6!=24\\u4f4d\\u5f69\\u8272\",\"6!=\\u989c\\u8272\\u81ea\\u52a8\\u8bc6\\u522b\"]},\"9\":{\"category\":\"base\",\"name\":\"cfg-9\",\"title\":\"24\\u4f4d\\u5f69\\u8272\\u56fe\\u50cf - \\u591a\\u6d41\\u8f93\\u51fa\\u9664\\u7ea2\",\"desc\":\"\\u591a\\u901a\\u9053\\u8f93\\u51fa\\u4e2d\\uff0c\\u53bb\\u9664\\u7ea2\\u8272\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4,\"depend_and\":[\"4!=true\",\"6!=256\\u7ea7\\u7070\\u5ea6\",\"6!=\\u9ed1\\u767d\",\"6!=\\u989c\\u8272\\u81ea\\u52a8\\u8bc6\\u522b\"]},\"10\":{\"category\":\"base\",\"name\":\"cfg-10\",\"title\":\"24\\u4f4d\\u5f69\\u8272\\u56fe\\u50cf - \\u7b54\\u9898\\u5361\\u9664\\u7ea2\",\"desc\":\"\\u7b54\\u9898\\u5361\\u626b\\u63cf\\u4e2d\\u53bb\\u9664\\u7ea2\\u8272\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4,\"depend_and\":[\"4!=true\",\"6!=256\\u7ea7\\u7070\\u5ea6\",\"6!=\\u9ed1\\u767d\",\"6!=\\u989c\\u8272\\u81ea\\u52a8\\u8bc6\\u522b\"]},\"11\":{\"category\":\"base\",\"name\":\"cfg-11\",\"title\":\"\\u80cc\\u666f\\u79fb\\u9664\",\"desc\":\"\\u79fb\\u9664\\u5f69\\u8272\\u56fe\\u50cf\\u80cc\\u666f\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4,\"depend_and\":[\"4!=true\",\"6!=256\\u7ea7\\u7070\\u5ea6\",\"6!=\\u9ed1\\u767d\",\"6!=\\u989c\\u8272\\u81ea\\u52a8\\u8bc6\\u522b\"]},\"12\":{\"category\":\"base\",\"name\":\"cfg-12\",\"title\":\" \\u80cc\\u666f\\u8272\\u5f69\\u6d6e\\u52a8\\u8303\\u56f4\",\"desc\":\"\\u8bbe\\u5b9a\\u80cc\\u666f\\u8272\\u5f69\\u7684\\u6d6e\\u52a8\\u8303\\u56f4\\uff0c\\u5728\\u8be5\\u8303\\u56f4\\u5185\\u7684\\u90fd\\u5f53\\u4f5c\\u80cc\\u666f\\u79fb\\u9664\",\"type\":\"int\",\"cur\":20,\"default\":20,\"size\":4,\"range\":{\"min\":1,\"max\":128},\"d
static std::string jsontext2("");
2022-07-26 09:03:50 +00:00
#else
static std::string jsontext1("{\"device_type\":\"G239\",\"option_count\":65,\"1\":{\"category\":\"base\",\"name\":\"cfg-1\",\"title\":\"\\u6062\\u590d\\u9ed8\\u8ba4\\u8bbe\\u7f6e\",\"desc\":\"\\u6062\\u590d\\u9ed8\\u8ba4\\u8bbe\\u7f6e\",\"type\":\"button\",\"cur\":\"button\",\"default\":\"button\",\"size\":0},\"2\":{\"category\":\"advanced\",\"name\":\"cfg-2\",\"title\":\"\\u5e2e\\u52a9\",\"desc\":\"\\u663e\\u793a\\u8f6f\\u4ef6\\u5e2e\\u52a9\\u6587\\u6863\",\"type\":\"button\",\"cur\":\"true\",\"default\":\"true\",\"size\":4},\"3\":{\"category\":\"base\",\"name\":\"grp-1\",\"title\":\"\\u57fa\\u672c\\u8bbe\\u7f6e\",\"type\":\"group\"},\"4\":{\"category\":\"base\",\"name\":\"cfg-4\",\"title\":\"\\u591a\\u6d41\\u8f93\\u51fa\",\"desc\":\"\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4},\"5\":{\"category\":\"base\",\"name\":\"cfg-5\",\"title\":\"\\u591a\\u6d41\\u8f93\\u51fa\\u7c7b\\u578b\",\"desc\":\"\",\"type\":\"string\",\"cur\":\"\\u65e0\",\"default\":\"\\u65e0\",\"size\":32,\"range\":[\"\\u5f69\\u8272+\\u7070\\u5ea6+\\u9ed1\\u767d\",\"\\u5f69\\u8272+\\u7070\\u5ea6\",\"\\u5f69\\u8272+\\u9ed1\\u767d\",\"\\u7070\\u5ea6+\\u9ed1\\u767d\"],\"depend_or\":[\"4==true\"]},\"6\":{\"category\":\"base\",\"name\":\"mode\",\"title\":\"\\u989c\\u8272\\u6a21\\u5f0f\",\"desc\":\"\\u8bbe\\u7f6e\\u989c\\u8272\\u4f4d\\u6df1\",\"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\":[\"4!=true\"]},\"7\":{\"category\":\"base\",\"name\":\"cfg-7\",\"title\":\"\\u9ed1\\u767d\\u56fe\\u50cf\\u9608\\u503c\",\"desc\":\"\",\"type\":\"int\",\"cur\":128,\"default\":128,\"size\":4,\"range\":{\"min\":0,\"max\":255},\"depend_or\":[\"6==\\u9ed1\\u767d\"]},\"8\":{\"category\":\"base\",\"name\":\"cfg-8\",\"title\":\"\\u7070\\u5ea6\\u6216\\u9ed1\\u767d\\u56fe\\u50cf - \\u9664\\u8272\",\"desc\":\"\\u9664\\u53bb\\u56fe\\u50cf\\u5f69\\u8272\",\"type\":\"string\",\"cur\":\"\\u4e0d\\u9664\\u8272\",\"default\":\"\\u4e0d\\u9664\\u8272\",\"size\":24,\"range\":[\"\\u4e0d\\u9664\\u8272\",\"\\u9664\\u7ea2\\u8272\",\"\\u9664\\u7eff\\u8272\",\"\\u9664\\u84dd\\u8272\",\"\\u7ea2\\u8272\\u589e\\u5f3a\",\"\\u7eff\\u8272\\u589e\\u5f3a\",\"\\u84dd\\u8272\\u589e\\u5f3a\"],\"depend_and\":[\"4!=true\",\"6!=24\\u4f4d\\u5f69\\u8272\",\"6!=\\u989c\\u8272\\u81ea\\u52a8\\u8bc6\\u522b\"]},\"9\":{\"category\":\"base\",\"name\":\"cfg-9\",\"title\":\"24\\u4f4d\\u5f69\\u8272\\u56fe\\u50cf - \\u591a\\u6d41\\u8f93\\u51fa\\u9664\\u7ea2\",\"desc\":\"\\u591a\\u901a\\u9053\\u8f93\\u51fa\\u4e2d\\uff0c\\u53bb\\u9664\\u7ea2\\u8272\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4,\"depend_and\":[\"4!=true\",\"6!=256\\u7ea7\\u7070\\u5ea6\",\"6!=\\u9ed1\\u767d\",\"6!=\\u989c\\u8272\\u81ea\\u52a8\\u8bc6\\u522b\"]},\"10\":{\"category\":\"base\",\"name\":\"cfg-10\",\"title\":\"24\\u4f4d\\u5f69\\u8272\\u56fe\\u50cf - \\u7b54\\u9898\\u5361\\u9664\\u7ea2\",\"desc\":\"\\u7b54\\u9898\\u5361\\u626b\\u63cf\\u4e2d\\u53bb\\u9664\\u7ea2\\u8272\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4,\"depend_and\":[\"4!=true\",\"6!=256\\u7ea7\\u7070\\u5ea6\",\"6!=\\u9ed1\\u767d\",\"6!=\\u989c\\u8272\\u81ea\\u52a8\\u8bc6\\u522b\"]},\"11\":{\"category\":\"base\",\"name\":\"cfg-11\",\"title\":\"\\u80cc\\u666f\\u79fb\\u9664\",\"desc\":\"\\u79fb\\u9664\\u5f69\\u8272\\u56fe\\u50cf\\u80cc\\u666f\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4,\"depend_and\":[\"4!=true\",\"6!=256\\u7ea7\\u7070\\u5ea6\",\"6!=\\u9ed1\\u767d\",\"6!=\\u989c\\u8272\\u81ea\\u52a8\\u8bc6\\u522b\"]},\"12\":{\"category\":\"base\",\"name\":\"cfg-12\",\"title\":\" \\u80cc\\u666f\\u8272\\u5f69\\u6d6e\\u52a8\\u8303\\u56f4\",\"desc\":\"\\u8bbe\\u5b9a\\u80cc\\u666f\\u8272\\u5f69\\u7684\\u6d6e\\u52a8\\u8303\\u56f4\\uff0c\\u5728\\u8be5\\u8303\\u56f4\\u5185\\u7684\\u90fd\\u5f53\\u4f5c\\u80cc\\u666f\\u79fb\\u9664\",\"type\":\"int\",\"cur\":20,\"default\":20,\"size\":4,\"range\":{\"min\":1,\"max\":128},\"depen
static std::string jsontext2("\"58\":{\"category\":\"base\",\"name\":\"cfg-58\",\"title\":\"\\u80cc\\u9762\\u65cb\\u8f6c180\\u00b0\",\"desc\":\"\\u80cc\\u9762\\u626b\\u63cf\\u7684\\u56fe\\u50cf\\u65cb\\u8f6c180\\u00b0\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4,\"depend_and\":[\"26!=\\u5355\\u9762\",\"26!=\\u5bf9\\u6298\",\"57!=\\u81ea\\u52a8\\u6587\\u672c\\u65b9\\u5411\\u8bc6\\u522b\\u00b0\"]},\"59\":{\"category\":\"base\",\"name\":\"cfg-59\",\"title\":\"\\u6298\\u89d2\\u68c0\\u6d4b\",\"desc\":\"\\u7eb8\\u5f20\\u6298\\u89d2\\u68c0\\u6d4b\",\"type\":\"bool\",\"cur\":false,\"default\":false,\"size\":4},\"60\":{\"category\":\"base\",\"name\":\"cfg-60\",\"title\":\" \\u6298\\u89d2\\u5927\\u5c0f\",\"desc\":\"\\u503c\\u8d8a\\u5c0f\\uff0c\\u4ee3\\u8868\\u80fd\\u68c0\\u6d4b\\u5230\\u7684\\u6298\\u89d2\\u8d8a\\u5c0f\",\"type\":\"int\",\"cur\":70,\"default\":70,\"size\":4,\"range\":{\"min\":0,\"max\":100},\"depend_or\":[\"59==true\"]},\"61\":{\"category\":\"base\",\"name\":\"cfg-61\",\"title\":\"\\u6b6a\\u659c\\u68c0\\u6d4b\",\"desc\":\"\\u7eb8\\u5f20\\u6b6a\\u659c\\u68c0\\u6d4b\",\"type\":\"bool\",\"cur\":true,\"default\":true,\"size\":4},\"62\":{\"category\":\"base\",\"name\":\"cfg-62\",\"title\":\"\\u6b6a\\u659c\\u5bb9\\u5fcd\\u5ea6\",\"desc\":\"\\u503c\\u8d8a\\u5c0f\\uff0c\\u4ee3\\u8868\\u80fd\\u68c0\\u6d4b\\u5230\\u7eb8\\u5f20\\u7684\\u6b6a\\u659c\\u89d2\\u5ea6\\u8d8a\\u5c0f\",\"type\":\"int\",\"cur\":3,\"default\":3,\"size\":4,\"range\":{\"min\":1,\"max\":5},\"depend_or\":[\"61==true\"]},\"63\":{\"category\":\"base\",\"name\":\"cfg-63\",\"title\":\"\\u5206\\u7eb8\\u5f3a\\u5ea6\",\"desc\":\"\",\"type\":\"int\",\"cur\":0,\"default\":0,\"size\":4,\"range\":[0,1,2]},\"64\":{\"category\":\"base\",\"name\":\"cfg-64\",\"title\":\"\\u4f11\\u7720\\u65f6\\u95f4\",\"desc\":\"\",\"type\":\"int\",\"cur\":-1,\"default\":-1,\"size\":4,\"range\":[-1,5,10,30,60,120,240]}}");
#endif
2022-05-03 03:56:07 +00:00
enum hg_239_setting_item
{
HG_239_SETTING_RESTORE = 1, // 恢复默认设置
HG_239_SETTING_HELP, // 帮助
HG__239_SETTING_GROUP_1,
HG_239_SETTING_COLOR_MODE, // 颜色模式
HG_239_SETTING_ERASE_COLOR, // 除色
HG_239_SETTING_ERASE_MULTI_RED, // 多流输出除红
HG_239_SETTING_ERASE_ANSWER_RED, // 答题卡除红
HG_239_SETTING_ERASE_BACKGROUND, // 移除背景
HG_239_SETTING_ERASE_BKG_RANGE, // 移除背景范围
HG_239_SETTING_NOISE, // 黑白图像噪点优化
HG_239_SETTING_NOISE_SIZE, // 噪点优化尺寸
HG_239_SETTING_PAPER_SIZE, // 纸张尺寸
2022-05-07 07:39:48 +00:00
HG_239_SETTING_CUSTOM_AREA, // 自定义扫描区域
HG_239_SETTING_CUSTOM_AREA_LEFT, // 扫描区域左侧mm
HG_239_SETTING_CUSTOM_AREA_RIGHT, // 扫描区域右侧mm
HG_239_SETTING_CUSTOM_AREA_TOP, // 扫描区域上侧mm
HG_239_SETTING_CUSTOM_AREA_BOTTOM, // 扫描区域下侧mm
2022-05-03 03:56:07 +00:00
HG_239_SETTING_PAPER_SIZE_CHECK, // 尺寸检测
HG_239_SETTING_PAGE, // 扫描页面
HG_239_SETTING_SKIP_NILL, // 跳过空白页灵敏度
HG_239_SETTING_RESOLUTION, // 分辨率
2022-05-09 07:02:00 +00:00
HG_239_SETTING_IMG_QUALITY, // 画质
2022-05-03 03:56:07 +00:00
HG_239_SETTING_REVERSE, // 交换正反面
HG_239_SETTING_SPLIT, // 图像拆分
HG_239_SETTING_CORRECT, // 自动纠偏
HG_239_SETTING_ERASE_HOLE, // 穿孔移除
HG_239_SETTING_HOLE_SEARCH, // 穿孔搜索范围
HG__239_SETTING_GROUP_2,
2022-05-07 07:39:48 +00:00
HG_239_SETTING_CUSTOM_GAMMA, // 启用色调曲线
2022-05-03 03:56:07 +00:00
HG_239_SETTING_LIGHT, // 亮度
HG_239_SETTING_CONTRAST, // 对比度
HG_239_SETTING_GAMMA, // 伽玛
HG__239_SETTING_GROUP_3,
HG_239_SETTING_SHARP, // 锐化与模糊
HG_239_SETTING_ERASE_BLACK_BORDER, // 消除黑框
HG_239_SETTING_SAMPLE, // 深色样张
HG_239_SETTING_THRESHOLD, // 阈值
HG_239_SETTING_ANTI_NOISE, // 背景抗噪等级
HG_239_SETTING_MARGIN, // 边缘缩进
HG_239_SETTING_FILLING, // 背景填充方式
HG_239_SETTING_PERMEATE, // 防止渗透
HG_239_SETTING_PERMEATE_lv, // 防止渗透等级
HG_239_SETTING_REMOVE_MORR, // 去除摩尔纹
HG_239_SETTING_ERROR_EXTENTION, // 错误扩散
HG_239_SETTING_REMOVE_TXTTURE, // 除网纹
HG__239_SETTING_GROUP_4,
HG_239_SETTING_ULTRASONIC, // 超声波检测
HG_239_SETTING_STAPLE, // 装订检测
HG_239_SETTING_SCAN_METHOD, // 连续扫描或扫描指定张数
HG_239_SETTING_SCAN_COUNT, // 扫描指定数量
HG_239_SETTING_DIRECTION, // 文稿方向 删除文稿自动识别
HG_239_SETTING_ROTATE, // 背面旋转180°
HG_239_SETTING_FRACTATE, // 折角检测
HG_239_SETTING_FRACTATE_COMPLEX, // 折角检测复杂度
HG_239_SETTING_SCREW, // 歪斜检测
HG_239_SETTING_SCREW_COMPLEX, // 歪斜检测复杂度
HG_239_SETTING_END,
//暂时屏蔽
HG_239_SETTING_MULTI_OUT = 500, // 多流输出
};
enum Scanner_Reg_Defs
{
SR_CMD,
SR_STATUS,
SR_SCAN_COUNT,
SR_OS,
SR_SENSORS,
SR_MOTOR,
SR_IM_TYPE,
SR_IM_COUNT,
SR_IM_TX,
SR_IM_FRONT_SIZE,
SR_IM_CLEAR,
SR_IM_TXING,
SR_IM_POP,
SR_IM_ABORT,
SR_COUNT,
SR_CONFIG_SCAN_PARAM,
SR_GET_FWVERSION,
SR_SET_FWERSION,
SR_GET_SERIALNUM,
SR_SET_SERIALNUM,
SR_CONFIF_IMGPROCPARAM,
SC_AUTOCORRECT,
SC_GET_CORRECT_PARAM,
SC_SET_CORRECT_PARAM,
SR_GET_H_RATIO,
SR_SET_H_RATIO,
SR_GET_V_RATIO,
SR_SET_V_RATIO,
SR_GET_SERIAL_LEN,
SR_GET_GRAY_SP,
SR_GET_COLOR_SP,
SR_SET_GRAY_SP,
SR_SET_COLOR_SP,
SR_SET_SLEEPTIME,
SR_GET_SLEEPTIME,
SR_GET_SLEEP_STAUTUS,
SR_GET_IMAGEPROCESSDONE,
SR_GET_KEEP_LAST_PAPER,
SR_GET_PAPERON,
SR_SET_SPEEDMODE,
SR_GET_SPEEDMODE,
SR_GET_JSON_SIZE,
SR_GET_JSON,
SR_SET_JSON_PATH,
SR_SET_JSON,
SR_GET_FILE_POS,
SR_SET_FILE_POS,
SR_NOTIFY_SLEEP,
SR_GET_FEEDMODE,
SR_SET_FEEDMODE,
2022-05-03 03:56:07 +00:00
SR_GET_CUO_ERROR = 0x50,
SR_GET_DOU_ERROR,
SR_GET_JAM_ERROR,
SR_GET_SCANN_NUM,
SR_CLR_ROLLER_NUM,
SR_GET_ROLLER_NUM,
SR_UPDATA_START = 0x100,
SR_UPDATA_STAUTUS = 0x101,
SR_UPDATA_MD5_RELUST = 0x102,
SR_UPDATA_RECOVERY = 0x103,
SR_UPDATA_REBOOT = 0x104,
SR_POWEROFF = 0x105,
SR_REBOOT = 0x106,
SR_FLAT_CLR_MAX_BRIGHT,
SR_FLAT_GRAY_MAX_BRIGHT,
SR_KERNEL_VERSION_INFO_LENGTH,
SR_GET_KERNEL_VERSION,
SR_GET_MBSTATUS,
SR_GET_IPADDR_LENGHT = 0x200,
SR_GET_MACADDR,
SR_GET_IPADDR,
SR_GET_MBVERSION_LENGHT,
SR_GET_MBVERSION,
SR_GET_USBVIDPID,
SR_SET_USBVIDPID
};
enum Scanner_Cmd_Defs
{
SC_START,
SC_STOP,
SC_CLEAR,
SC_COUNT
};
enum HGType
{
MtBoard = 1,
FPGA,
V4L2,
IMG,
AutoCorrect,
STOPSCAN,
};
struct HGEIntInfo
{
HGType From;
unsigned int Code;
unsigned int Img_Index;
};
namespace settings
{
// device status to scanner_err
scanner_err device_status_to_hg_err(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 == HGType::FPGA)
code = SCANNER_ERR_OK;
2022-05-03 03:56:07 +00:00
else if (ds->From == HGType::MtBoard)
{
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;
default:
break;
}
}
else if (ds->From == HGType::IMG)
{
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;
2022-05-03 03:56:07 +00:00
}
else if (ds->From == HGType::V4L2)
{
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 == HGType::STOPSCAN)
code = SCANNER_ERR_DEVICE_STOPPED;
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},
{600.0f, 1} //临时版本发1 原来发2
};
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;
}
2022-06-07 09:06:09 +00:00
enum PaperSize_
{
G400_A3 = 0,
G400_A4,
G400_A4R,
G400_A5,
G400_A5R,
G400_A6,
G400_A6R,
G400_B4,
G400_B5,
G400_B5R,
G400_B6,
G400_B6R,
G400_DOUBLELETTER,
G400_LEGAL,
G400_LETTER,
G400_LETTERR,
G400_LONGLETTER = 16,
G400_MAXSIZE = 16,
G400_AUTO = 16,
G400_MAXAUTO = 16
};
2022-05-03 03:56:07 +00:00
// paper
static struct
{
int paper;
TwSS type;
int dev_value;
}paper_map[] =
{
2022-06-07 09:06:09 +00:00
{PAPER_A3, TwSS::A3, PaperSize_::G400_A3},
2022-05-03 03:56:07 +00:00
{PAPER_8K, TwSS::K8, 0},
2022-06-07 09:06:09 +00:00
{PAPER_A4, TwSS::A4, PaperSize_::G400_A4},
{PAPER_A4_LATERAL, TwSS::A4, PaperSize_::G400_A4R},
2022-05-03 03:56:07 +00:00
{PAPER_16K, TwSS::K16, 0},
{PAPER_16K_LATERAL, TwSS::K16, 0},
2022-06-07 09:06:09 +00:00
{PAPER_A5, TwSS::A5, PaperSize_::G400_A5},
{PAPER_A5_LATERAL, TwSS::A5, PaperSize_::G400_A5R},
{PAPER_A6, TwSS::A6, PaperSize_::G400_A6},
{PAPER_A6_LATERAL, TwSS::A6, PaperSize_::G400_A6R},
{PAPER_B4, TwSS::B4, PaperSize_::G400_B4},
{PAPER_B5, TwSS::B5, PaperSize_::G400_B5},
{PAPER_B5_LATERAL, TwSS::B5, PaperSize_::G400_B5R},
{PAPER_B6, TwSS::B6, PaperSize_::G400_B6},
{PAPER_B6_LATERAL, TwSS::B6, PaperSize_::G400_B6R},
{PAPER_LETTER, TwSS::USLetter, PaperSize_::G400_LETTER},
{PAPER_LETTER_LATERAL, TwSS::USLetter, PaperSize_::G400_LETTERR},
{PAPER_DOUBLE_LETTER, TwSS::USLedger, PaperSize_::G400_DOUBLELETTER},
{PAPER_LEGAL, TwSS::USLegal, PaperSize_::G400_LEGAL},
2022-05-03 03:56:07 +00:00
{PAPER_AUTO_MATCH, TwSS::None, 0},
2022-06-07 09:06:09 +00:00
{PAPER_MAX_SIZE_CLIP, TwSS::USStatement, PaperSize_::G400_MAXAUTO},
{PAPER_MAX_SIZE, TwSS::MaxSize, PaperSize_::G400_MAXSIZE},
2022-05-03 03:56:07 +00:00
{PAPER_TRIGEMINY, TwSS::Trigeminy, 16}
};
int match_best_paper(int& paper, bool* exact, TwSS* type)
{
int ind = 0;
bool good = true, * r = exact ? exact : &good;
for (int i = 0; i < ARRAY_SIZE(paper_map); ++i)
{
if (paper == paper_map[i].paper)
{
ind = i;
break;
}
}
if (paper == paper_map[ind].paper)
*r = true;
else
*r = false;
VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "Paper '%s' index = %d, device value = %d\n", paper_string(paper).c_str(), ind, paper_map[ind].dev_value);
2022-05-03 03:56:07 +00:00
paper = paper_map[ind].paper;
if (type)
*type = paper_map[ind].type;
return ind;
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// class ...
hg_scanner_239::hg_scanner_239(const char* dev_name, int pid,usb_io* io) : hg_scanner(G20039Serial, dev_name, io)
, rewrite_conf_(false), reset_(false),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
init_settings((jsontext1 + jsontext2).c_str());
2022-05-03 03:56:07 +00:00
writedown_device_configuration(); // initialize the hardware settings
init_version();
}
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)
{
std::lock_guard<std::mutex> lock(io_lock_);
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)
{
std::lock_guard<std::mutex> lock(io_lock_);
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
{
std::lock_guard<std::mutex> lock(io_lock_);
l = size + 1;
data.resize(size + 2);
bzero(&data[0], size + 2);
ret = io_->read_bulk(&data[0], &l);
if (ret)
{
VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "control_fetch(%d, %d) - read_bulk = %s\n", addr, val, 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)
{
int val = 0,
ret = read_register(SR_GET_MBVERSION_LENGHT, &val);
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(SR_GET_MBVERSION, 0, val);
}
return fpga;
}
int hg_scanner_239::clr_roller_num(void)
{
int val = 0,
ret = read_register(SR_CLR_ROLLER_NUM, &val);
if (ret == SCANNER_ERR_OK)
2022-05-03 03:56:07 +00:00
return val;
else
{
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "clr_roller_num = %s\n", hg_scanner_err_name(ret));
2022-05-03 03:56:07 +00:00
return -1;
}
}
int hg_scanner_239::get_sleep_time(void)
{
int val = 0,
ret = read_register(SR_GET_SLEEPTIME, &val);
if (ret == SCANNER_ERR_OK)
2022-05-03 03:56:07 +00:00
return val;
else
{
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "get_sleep_time = %s\n", hg_scanner_err_name(ret));
2022-05-03 03:56:07 +00:00
return -1;
}
}
int hg_scanner_239::get_scan_mode(void)
{
int val = 0,
ret = read_register(SR_OS, &val);
if (ret)
{
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "get scan mode error: %s\n", hg_scanner_err_name(ret));
2022-05-03 03:56:07 +00:00
status_ = ret;
return -1;
}
else
return val;
}
int hg_scanner_239::get_status(void)
{
int val = 0,
ret = read_register(SR_STATUS, &val);
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_tx(void)
{
int val = 0,
ret = read_register(SR_STATUS, &val);
if (ret)
{
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "is_dev_tx() error: %s\n", hg_scanner_err_name(ret));
2022-05-03 03:56:07 +00:00
status_ = ret;
return false;
}
else
return val;
}
bool hg_scanner_239::is_dev_image_process_done(void)
{
int val = 0,
ret = read_register(SR_GET_IMAGEPROCESSDONE, &val);
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)
{
int val = 0,
ret = read_register(SR_GET_KEEP_LAST_PAPER, &val);
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_scanned_count(void)
{
int val = 0,
ret = read_register(SR_GET_SCANN_NUM, &val);
if (ret == SCANNER_ERR_OK)
2022-05-03 03:56:07 +00:00
return val;
else
{
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "get_scanned_count = %s\n", hg_scanner_err_name(ret));
2022-05-03 03:56:07 +00:00
return -1;
}
}
int hg_scanner_239::get_image_count(void)
{
int val = 0,
ret = read_register(SR_IM_COUNT, &val);
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "get_image_count() = %d, error: %s\n", val, 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
return val;
else
return -1;
}
int hg_scanner_239::get_front_data_size(void)
{
int val = 0,
ret = read_register(SR_IM_FRONT_SIZE, &val);
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());
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, " HG3399 firmware version: %s\n", fv.c_str());
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, " HG3399 serial number: %s\n", sn.c_str());
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, " HG3399 IP: %s\n", get_ip().c_str());
2022-05-03 03:56:07 +00:00
if (fv.length() >= 10 && (fv[5] > 'A' || atoi(fv.substr(6, 4).c_str()) >= 1209))
{
is_kernelsnap_211209_ = atoi(get_fpga().c_str()) >= 35211210;
}
else
is_kernelsnap_211209_ = false;
}
void hg_scanner_239::image_process(std::shared_ptr<tiny_buffer>& buff)
2022-05-03 03:56:07 +00:00
{
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Process image with %u bytes content ...\n", buff->size());
2022-05-03 03:56:07 +00:00
hg_imgproc::HIMGPRC handle = get_image_process_object(pid_);
2022-05-03 03:56:07 +00:00
hg_imgproc::IMGHEAD ih;
int err = SCANNER_ERR_OK,
2022-05-03 03:56:07 +00:00
index = 0;
void* buf = NULL;
err = hg_imgproc::load_buffer(handle, buff);
err = hg_imgproc::decode(handle,pid_);
if(image_prc_param_.bits.erase_bakground && !user_cancel_)
{
err = hg_imgproc::fadeback(handle,img_conf_.fadebackrange,img_conf_.is_duplex);
}
if (image_prc_param_.bits.rid_red && img_conf_.pixtype == COLOR_MODE_24_BITS)
err = hg_imgproc::multi_out_red(handle);
if (image_prc_param_.bits.split && !user_cancel_)
{
2022-07-06 08:19:14 +00:00
split3399_++;
2022-05-03 03:56:07 +00:00
int colormode=1;
if(img_conf_.filter == RID_COLOR_NONE)
colormode=img_conf_.pixtype;
2022-07-06 08:19:14 +00:00
err = hg_imgproc::split(handle,img_conf_.multiOutput,img_conf_.splitImage,img_conf_.multi_output_red,colormode,img_conf_.is_duplex,split3399_);
VLOG_MINI_5(LOG_LEVEL_DEBUG_INFO, "img split-> multiOutput is:%d splitImage is:%d multi_output_red is:%d pixtype is:%d is_duplex:%d\r\n"
2022-05-03 03:56:07 +00:00
,img_conf_.multiOutput
,img_conf_.splitImage
,img_conf_.multi_output_red
,img_conf_.pixtype
,img_conf_.is_duplex);
}
if (!image_prc_param_.bits.split || !image_prc_param_.bits.rid_red || !is_multiout)
2022-05-03 03:56:07 +00:00
{
if(img_conf_.automaticcolor)
{
hg_imgproc::auto_matic_color(handle,img_conf_.automaticcolortype);
}
}
2022-05-11 03:27:11 +00:00
if (img_conf_.is_autotext)
{
printf("文本方向自动识别\r\n");
hg_imgproc::ocr_auto_txtdirect(handle);
}
if (is_quality_ == IMG_SPEED && resolution_ >= 300)
{
err = hg_imgproc::quality(handle,resolution_);
}
2022-05-21 08:56:14 +00:00
//多流输出最后处理
if (is_multiout)
{
2022-05-23 08:54:55 +00:00
int multi_out = image_prc_param_.bits.multi_out;
2022-05-21 08:56:14 +00:00
err = hg_imgproc::multi_out(handle,multi_out);
}
2022-05-03 03:56:07 +00:00
hg_imgproc::final(handle);
2022-05-09 11:27:10 +00:00
while (hg_imgproc::get_final_data(handle, &ih, &buf, index++) == SCANNER_ERR_OK && !user_cancel_)
2022-05-03 03:56:07 +00:00
{
VLOG_MINI_5(LOG_LEVEL_DEBUG_INFO, "Final picture %d (%d * %d * %d) with %u bytes!\n", index
2022-05-03 03:56:07 +00:00
, ih.width, ih.height, ih.bits * ih.channels, ih.total_bytes);
if(!img_type_.empty())
{
std::vector<unsigned char>bmpdata;
hg_imgproc::imgtypechange(handle,img_type_,buf,bmpdata);
//cv::imencode(img_type_,*((cv::Mat*)buf),bmpdata);
if(bmpdata.empty())
{
status_ = SCANNER_ERR_NO_DATA;
2022-05-03 03:56:07 +00:00
return ;
}
buf = bmpdata.data();
ih.total_bytes = bmpdata.size();
VLOG_MINI_6(LOG_LEVEL_DEBUG_INFO, "Set img type is:%s Final picture %d (%d * %d * %d) with %u bytes!\n",img_type_.c_str() ,index
2022-05-03 03:56:07 +00:00
, ih.width, ih.height, ih.bits * ih.channels, ih.total_bytes);
}
save_final_image(&ih, buf);
}
hg_imgproc::release(handle);
}
int hg_scanner_239::get_device_sleep_stautus(void)
{
int ret =read_register(SR_GET_SLEEP_STAUTUS,0);
return ret;
}
int hg_scanner_239::get_device_paperon_stautus(void)
{
int ret =read_register(SR_GET_PAPERON,0);
return ret;
}
// int hg_scanner_239::writedown_device_configuration()
// {
// int ret = SCANNER_ERR_OK;
2022-05-03 03:56:07 +00:00
// ret = write_register(SR_CONFIG_SCAN_PARAM, dev_conf_.value);
// 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_device_configuration(HGSCANCONF *dev_conf)
{
int ret = SCANNER_ERR_OK;
2022-05-03 03:56:07 +00:00
if (!dev_conf)
{
2022-05-03 03:56:07 +00:00
dev_conf = &dev_conf_;
dev_conf_.g200params.is_textcorrect = !keep_watermark_;
}
2022-05-03 03:56:07 +00:00
ret = write_register(SR_CONFIG_SCAN_PARAM, dev_conf->value);
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)
{
int ret = write_register(SR_CONFIF_IMGPROCPARAM, sizeof(SCANCONF));
if (ret != SCANNER_ERR_OK)
2022-05-03 03:56:07 +00:00
return ret;
SCANCONF ic;
int len = sizeof(ic);
bzero(&ic, len);
ic.papertype = paper_size_;
if (is_lateral(image_prc_param_.bits.paper))
ic.paperAlign = Rot270;
// else if (image_prc_param_.bits.text_direction == TEXT_DIRECTION_AUTO)
// ic.paperAlign = AutoTextOrientation;
else
ic.paperAlign = Rot0;
2022-05-03 03:56:07 +00:00
ic.en_sizecheck = dev_conf_.g200params.enable_sizecheck;
2022-05-11 03:27:11 +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;
2022-05-11 03:27:11 +00:00
ic.imageRotateDegree *= 90.0f;
2022-06-07 09:06:09 +00:00
ic.is_duplex = (image_prc_param_.bits.page == PAGE_DOUBLE
|| image_prc_param_.bits.page == PAGE_OMIT_EMPTY
|| image_prc_param_.bits.page == PAGE_OMIT_EMPTY_RECEIPT
|| image_prc_param_.bits.page ==PAGE_FOLIO);
2022-06-15 02:09:26 +00:00
ic.en_fold = (image_prc_param_.bits.page == PAGE_FOLIO);
ic.pixtype = image_prc_param_.bits.color_mode == COLOR_MODE_AUTO_MATCH ? 2 : image_prc_param_.bits.color_mode;
ic.automaticcolor = is_auto_matic_color;
2022-05-03 03:56:07 +00:00
ic.automaticcolortype = 1;// ic.pixtype; //存疑
if (resolution_ >= 300)
2022-05-09 11:27:10 +00:00
{
if(is_quality_ == IMG_SPEED)
{
ic.resolution_dst = 200;
}
else if(is_quality_ ==IMG_QUALITY)
{
ic.resolution_dst = resolution_;
}
2022-05-09 11:27:10 +00:00
}
else
2022-05-09 11:27:10 +00:00
{
ic.resolution_dst = resolution_;
}
2022-05-03 03:56:07 +00:00
ic.resolution_native = 200.0f;
ic.gamma = (float)gamma_;
ic.contrast = (contrast_ - 4) * 333.0;
ic.brightness = (bright_ - 128) * (2000.0 / 254.0);
ic.threshold = threshold_;
ic.is_autocontrast = 0; //无参数
ic.is_autocrop = (ic.papertype == TwSS::None || ic.papertype ==TwSS::USStatement);
ic.is_autodiscradblank_normal = image_prc_param_.bits.page == PAGE_OMIT_EMPTY;
ic.discardblank_percent = omit_empty_level_ >= 70 ? 70 : omit_empty_level_;
2022-05-03 03:56:07 +00:00
ic.is_autodiscradblank_vince = image_prc_param_.bits.page == PAGE_OMIT_EMPTY_RECEIPT;
ic.is_switchfrontback = image_prc_param_.bits.exchange;
ic.autodescrew = image_prc_param_.bits.automatic_skew;
//ic.multi_output_red = image_prc_param_.bits.rid_red; //必须屏蔽,否则超时,未知错误不可描述。
ic.hsvcorrect = image_prc_param_.bits.rid_answer_red;
ic.sharpen = image_prc_param_.bits.sharpen;
ic.enhance_color = image_prc_param_.bits.rid_color;
ic.fillbackground = image_prc_param_.bits.erase_black_frame;
ic.is_convex = (image_prc_param_.bits.fill_background == FILL_BKG_CONVEX_POLYGON);
2022-07-25 06:25:08 +00:00
ic.noise = anti_noise_;
2022-05-03 03:56:07 +00:00
ic.indent = margin_;
ic.AutoCrop_threshold = threshold_;
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
{
ic.scannum = (ic.is_duplex ? scan_count_ * 2 : scan_count_);
}
ic.is_backrotate180 = image_prc_param_.bits.rotate_back_180;
ic.is_dogeardetection = image_prc_param_.bits.fractate_check;
ic.hardwarecaps.en_skrewdetect = dev_conf_.g200params.screw_detect_enable;
ic.hardwarecaps.en_doublefeed = dev_conf_.g200params.ultrasonic_enable;
ic.hardwarecaps.en_stapledetect = dev_conf_.g200params.staple_enbale;
ic.hardwarecaps.skrewdetectlevel = dev_conf_.g200params.screw_detect_level;
// ic.hardwarecaps.is_autopaper = dev_conf_.g200params.is_autopaper;
ic.hardwarecaps.capturepixtype = 0; //暂无参数 获取图像类型
ic.hardwarecaps.lowpowermode = LowPowerMode::Min_None; //暂无参数 设置休眠时间 两个参数3399未使用
ic.fillhole.is_fillhole = image_prc_param_.bits.rid_hole;
ic.fillhole.fillholeratio = rid_hole_range_;
ic.detachnoise.is_detachnoise = image_prc_param_.bits.noise_optimize;
ic.detachnoise.detachnoise = noise_range_;
2022-05-11 03:27:11 +00:00
ic.is_autotext = image_prc_param_.bits.text_direction == TEXT_DIRECTION_AUTO ? 1 :0;
2022-06-07 09:06:09 +00:00
ic.isfillcolor = is_color_fill;
2022-05-03 03:56:07 +00:00
ic.refuseInflow = image_prc_param_.bits.is_permeate;
ic.colorCorrection = 0;
ic.removeMorr = image_prc_param_.bits.remove_morr;
2022-06-07 09:06:09 +00:00
ic.errorExtention = image_prc_param_.bits.error_extention ;//
ic.textureRemove = image_prc_param_.bits.remove_txtture;//
2022-05-03 03:56:07 +00:00
ic.splitImage = image_prc_param_.bits.split;
{
ic.cropRect.enable = custom_area_;
int height = (custom_area_br_y_ *ic.resolution_dst) /25.4 - (custom_area_lt_y_ *ic.resolution_dst /25.4);
2022-06-15 01:47:17 +00:00
int width = (custom_area_br_x_ *ic.resolution_dst) /25.4 - (custom_area_lt_x_ *ic.resolution_dst /25.4);
ic.cropRect.height = height;
ic.cropRect.width = width;
2022-05-07 07:39:48 +00:00
ic.cropRect.x = custom_area_lt_x_ *ic.resolution_dst /25.4;
ic.cropRect.y = custom_area_lt_y_ *ic.resolution_dst /25.4;
}
2022-06-07 09:06:09 +00:00
ic.multiOutput = (MultiOutput)image_prc_param_.bits.multi_out;
2022-05-03 03:56:07 +00:00
ic.normalCrop = image_prc_param_.bits.dark_sample;
ic.dogeardistabce = fractate_level_;
ic.fadeback = image_prc_param_.bits.erase_bakground;
ic.fadebackrange = erase_bkg_range_;
ic.isuoloadexceptionimage = (double_paper_handle_ & DOUBLE_PAPER_SAVE_IMG) == DOUBLE_PAPER_SAVE_IMG;
2022-05-03 03:56:07 +00:00
int filter_clr[] = { 3, 0, 1, 2, 5, 6, 7 };
if(image_prc_param_.bits.color_mode == COLOR_MODE_24_BITS || image_prc_param_.bits.color_mode == COLOR_MODE_AUTO_MATCH)
ic.filter = 3;
else
{
ic.filter = filter_clr[image_prc_param_.bits.rid_color];
// if(ic.filter != 3)
// ic.pixtype = 2;
ic.hsvcorrect = 0;
ic.multi_output_red = 0;
ic.multiOutput = MultiOutput::Unused;
2022-06-14 09:02:19 +00:00
2022-05-03 03:56:07 +00:00
}
//多留输出的处理
if (image_prc_param_.bits.multi_out == MULTI_GRAY_AND_BW && is_multiout)
{
ic.pixtype = 1;
}
else if ((image_prc_param_.bits.multi_out == MULTI_OUT_ALL ||image_prc_param_.bits.multi_out == MULTI_COLOR_AND_GRAY||image_prc_param_.bits.multi_out == MULTI_COLOR_AND_BW) && is_multiout)
{
ic.pixtype = 2;
2022-06-14 09:02:19 +00:00
}
2022-06-14 09:02:19 +00:00
if (is_multiout)
{
ic.hsvcorrect = 0;
ic.multi_output_red = 0;
ic.fadeback = false;
ic.sharpen = 0;
ic.removeMorr = 0;
ic.textureRemove = 0;
ic.errorExtention = 0;
ic.detachnoise.is_detachnoise = 0;
}
2022-06-15 02:35:09 +00:00
if (ic.pixtype == 0)
{
ic.hsvcorrect = 0;
ic.multi_output_red = 0;
ic.fadeback = false;
ic.sharpen = 0;
ic.removeMorr = 0;
ic.textureRemove = 0;
}
2022-06-14 09:02:19 +00:00
//自定义裁切
if (image_prc_param_.bits.paper == PAPER_AUTO_MATCH
||image_prc_param_.bits.paper == PAPER_MAX_SIZE
||image_prc_param_.bits.paper == PAPER_MAX_SIZE_CLIP
||image_prc_param_.bits.paper == PAPER_TRIGEMINY
)
{
ic.cropRect.enable = false;
}
2022-05-03 03:56:07 +00:00
{
std::lock_guard<std::mutex> lock(io_lock_);
ret = io_->write_bulk(&ic, &len);
this_thread::sleep_for(chrono::milliseconds(500));
io_->set_timeout(2000);//必要延时
}
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Write-down 0x%x bytes image process parameters\n", len);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.pixtype=%d", ic.pixtype);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.papertype=%d", ic.papertype);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.AutoCrop_threshold=%d", ic.AutoCrop_threshold);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.autodescrew=%d", ic.autodescrew);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.automaticcolor=%d", ic.automaticcolor);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.brightness=%f", ic.brightness);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.contrast=%f", ic.contrast);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.en_fold=%d", ic.en_fold);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.en_sizecheck=%d", ic.en_sizecheck);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.enhance_color=%d", ic.enhance_color);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.fillbackground=%d", ic.fillbackground);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.filter=%d", ic.filter);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.gamma=%f", ic.gamma);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.hardwarecaps.capturepixtype=%d", ic.hardwarecaps.capturepixtype);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.hardwarecaps.en_doublefeed=%d", ic.hardwarecaps.en_doublefeed);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.hsvcorrect=%d", ic.hsvcorrect);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.imageRotateDegree=%f", ic.imageRotateDegree);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.indent=%d", 5);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.is_autocontrast=%d", ic.is_autocontrast);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.is_autocrop=%d", ic.is_autocrop);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.is_autodiscradblank_normal=%d", ic.is_autodiscradblank_normal);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.is_autodiscradblank_vince=%d", ic.is_autodiscradblank_vince);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.is_autotext=%d", ic.is_autotext);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.is_backrotate180=%d", ic.is_backrotate180);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.is_convex=%d", ic.is_convex);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.is_duplex=%d", ic.is_duplex);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.is_switchfrontback=%d", ic.is_switchfrontback);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.is_dogeardetection=%d", ic.is_dogeardetection);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.fillhole.multi_output_red=%d", ic.multi_output_red);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.noise=%d", 8);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.pixtype=%d", ic.pixtype);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.resolution_dst=%f", ic.resolution_dst);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.resolution_native=%f", ic.resolution_native);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.scannum=%d", ic.scannum);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.sharpen=%d", ic.sharpen);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.discardblank_percent=%d", ic.discardblank_percent);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.detachnoise.is_detachnoise=%d", ic.detachnoise.is_detachnoise);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.detachnoise.detachnoise=%d\r ", ic.detachnoise.detachnoise);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.detachnoise.refuseInflow=%d\r ", ic.refuseInflow);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.detachnoise.refuseInflow=%d\r ", ic.refuseInflow);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.removeMorr=%d\r ", ic.removeMorr);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.errorExtention=%d\r ", ic.errorExtention);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.textureRemove=%d\r\n ", ic.refuseInflow);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.fillhole.is_fillhole=%d\r\n ", ic.fillhole.is_fillhole);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.ic.fillhole.fillholeratio=%d\r\n ", ic.fillhole.fillholeratio);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.fadeback=%d\r\n ",ic.fadeback);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.cropRect.enable=%d\r ", ic.cropRect.enable);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.cropRect.width=%d\r\n ", ic.cropRect.width);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.cropRect.height=%d\r\n ", ic.cropRect.height);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.cropRect.x=%f\r\n ", ic.cropRect.x);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\n ic.cropRect.y=%d\r\n ",ic.cropRect.y);
2022-05-11 07:39:38 +00:00
2022-05-03 03:56:07 +00:00
img_conf_ = ic;
return ret;
}
int hg_scanner_239::pop_first_image(void)
{
int ret = write_register(SR_IM_POP, 1);
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
{
//if (is_dev_tx())
// return SCANNER_ERR_OK;
2022-05-03 03:56:07 +00:00
//if (!is_kernelsnap_211209_)
//{
// if (image_prc_param_.bits.page == PAGE_DOUBLE && !image_prc_param_.bits.fractate_check)
// if (get_image_count() < 3)
// return SCANNER_ERR_DEVICE_NO_IMAGE;
2022-05-03 03:56:07 +00:00
// if (get_image_count() < 2)
// return SCANNER_ERR_DEVICE_NO_IMAGE;
2022-05-03 03:56:07 +00:00
//}
int r = 0,
total = get_front_data_size(),
off = 0,
ret = SCANNER_ERR_OK;
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 (user_cancel_)
return SCANNER_ERR_USER_CANCELED;
2022-05-03 03:56:07 +00:00
if (total == -1)
ret = status_;
else
{
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(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;
{
std::lock_guard<std::mutex> lock(io_lock_);
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);
if (ret != SCANNER_ERR_OK)
break;
off += block;
r -= block;
}
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_DEBUG_INFO, "Read image from USB = %s\n", hg_scanner_err_name(ret));
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
{
pop_first_image();
//if(image_prc_param_.bits.page == PAGE_SINGLE)
// pop_first_image();
}
}
else
{
char msg[128];
sprintf(msg, "Read image data from USB err: %s\n", hg_scanner_err_name(ret));
LOG_INFO(LOG_LEVEL_DEBUG_INFO, msg);
2022-05-03 03:56:07 +00:00
notify_ui_working_status(msg);
notify_ui_working_status(STATU_DESC_SCANNER_ERR_TIMEOUT, SANE_EVENT_ERROR);
2022-05-03 03:56:07 +00:00
}
}
}
return ret;
}
void hg_scanner_239::discard_all_images(void)
{
char buf[64];
HGEIntInfo* info = (HGEIntInfo*)buf;
int size = sizeof(buf),
oto = 0,
pre_img = 0,
pre_int = 0,
ret = SCANNER_ERR_OK;
2022-05-03 03:56:07 +00:00
{
std::lock_guard<std::mutex> lock(io_lock_);
oto = io_->get_timeout();
io_->set_timeout(100);
ret = io_->read_interrupt(buf, &size);
}
while (ret == SCANNER_ERR_OK)
2022-05-03 03:56:07 +00:00
{
pre_int++;
if (info->From == IMG)
{
while (get_image_count() > 0)
{
pop_first_image();
pre_img++;
}
}
size = sizeof(buf);
{
std::lock_guard<std::mutex> lock(io_lock_);
ret = io_->read_interrupt(buf, &size);
}
}
{
std::lock_guard<std::mutex> lock(io_lock_);
io_->set_timeout(oto);
}
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);
2022-05-03 03:56:07 +00:00
}
//color_mode =-1 除色选项
int hg_scanner_239::on_color_mode_changed(int& color_mode)
{
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_.g200params.color) ||
((color_mode != COLOR_MODE_24_BITS && color_mode != COLOR_MODE_AUTO_MATCH) && dev_conf_.g200params.color)) && color_mode != -1)
{
dev_conf_.g200params.color ^= 1;
ret = writedown_device_configuration();
if(ret)
dev_conf_.g200params.color ^= 1;
}
if(color_mode == COLOR_MODE_AUTO_MATCH)
{
dev_conf_.g200params.color = 1;
}
2022-05-03 03:56:07 +00:00
HGSCANCONF d = dev_conf_;
if (image_prc_param_.bits.rid_color != RID_COLOR_NONE
&&(image_prc_param_.bits.color_mode == COLOR_MODE_256_GRAY || image_prc_param_.bits.color_mode == COLOR_MODE_BLACK_WHITE)
)
{
d.g200params.color = 1;
ret = writedown_device_configuration(&d);
}
if(image_prc_param_.bits.rid_color != RID_COLOR_NONE
&& (image_prc_param_.bits.color_mode == COLOR_MODE_256_GRAY || image_prc_param_.bits.color_mode == COLOR_MODE_BLACK_WHITE)
&& color_mode == -1)
{
d.g200params.color = 1;
}
else if (image_prc_param_.bits.rid_color == RID_COLOR_NONE
&& (image_prc_param_.bits.color_mode == COLOR_MODE_256_GRAY || image_prc_param_.bits.color_mode == COLOR_MODE_BLACK_WHITE)
&& color_mode == -1)
{
d.g200params.color = 0;
}
if(color_mode == -1)
ret = writedown_device_configuration(&d);
2022-05-03 03:56:07 +00:00
return ret;
}
int hg_scanner_239::on_paper_changed(int& paper)
{
bool exact = true;
int ind = settings::match_best_paper(paper, &exact, &paper_size_),
ret = exact ? SCANNER_ERR_OK : SCANNER_ERR_NOT_EXACT;
2022-05-03 03:56:07 +00:00
if (dev_conf_.g200params.paper != settings::paper_map[ind].dev_value)
{
int old = dev_conf_.g200params.paper;
dev_conf_.g200params.paper = settings::paper_map[ind].dev_value;
ret = writedown_device_configuration();
if (ret)
{
dev_conf_.g200params.paper = old;
for (int i = 0; i < ARRAY_SIZE(settings::paper_map); ++i)
{
if (settings::paper_map[i].dev_value == old)
{
paper = settings::paper_map[i].paper;
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 (dev_conf_.g200params.enable_sizecheck ^ check)
{
dev_conf_.g200params.enable_sizecheck = check;
ret = writedown_device_configuration();
2022-06-08 10:33:49 +00:00
2022-05-03 03:56:07 +00:00
if (ret)
{
dev_conf_.g200params.enable_sizecheck = !check;
check = dev_conf_.g200params.enable_sizecheck;
}
}
2022-06-08 10:33:49 +00:00
if (image_prc_param_.bits.paper == PAPER_AUTO_MATCH
||image_prc_param_.bits.paper == PAPER_MAX_SIZE
||image_prc_param_.bits.paper == PAPER_MAX_SIZE_CLIP
||image_prc_param_.bits.paper == PAPER_TRIGEMINY
||image_prc_param_.bits.paper == PAPER_16K
||image_prc_param_.bits.paper == PAPER_8K
||image_prc_param_.bits.paper == PAPER_16K_LATERAL
2022-06-08 10:33:49 +00:00
)
{
HGSCANCONF *d = &dev_conf_;
d->g200params.enable_sizecheck = false;
ret = writedown_device_configuration(d);
}
2022-05-03 03:56:07 +00:00
return ret;
}
int hg_scanner_239::on_resolution_changed(int& dpi)
{
bool exact = true;
int ind = settings::match_best_resolution(dpi, &exact),
ret = exact ? SCANNER_ERR_OK : SCANNER_ERR_NOT_EXACT;
2022-05-09 11:27:10 +00:00
2022-05-03 03:56:07 +00:00
if (dev_conf_.g200params.dpi != settings::resolution_map[ind].dev_value)
{
2022-05-09 11:27:10 +00:00
int old = dev_conf_.g200params.dpi;
2022-05-03 03:56:07 +00:00
dev_conf_.g200params.dpi = settings::resolution_map[ind].dev_value;
2022-07-25 10:40:29 +00:00
//dev_conf_.g200params.dpi = 1;
2022-05-03 03:56:07 +00:00
ret = writedown_device_configuration();
if (ret)
{
dev_conf_.g200params.dpi = old;
}
else if (!exact)
ret = SCANNER_ERR_NOT_EXACT;
2022-05-09 11:27:10 +00:00
}
2022-05-03 03:56:07 +00:00
if (ret == SCANNER_ERR_NOT_EXACT)
2022-05-03 03:56:07 +00:00
dpi = settings::resolution_map[ind].resolution;
2022-05-09 07:02:00 +00:00
2022-05-09 11:27:10 +00:00
2022-05-03 03:56:07 +00:00
return ret;
}
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_.g200params.ultrasonic_enable ^ check)
{
dev_conf_.g200params.ultrasonic_enable = check;
ret = writedown_device_configuration();
if (ret)
{
dev_conf_.g200params.ultrasonic_enable = !check;
check = dev_conf_.g200params.ultrasonic_enable;
}
}
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_.g200params.staple_enbale ^ check)
{
dev_conf_.g200params.staple_enbale = check;
ret = writedown_device_configuration();
if (ret)
{
dev_conf_.g200params.staple_enbale = !check;
check = dev_conf_.g200params.staple_enbale;
}
}
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_.g200params.screw_detect_enable ^ check)
{
dev_conf_.g200params.screw_detect_enable = check;
ret = writedown_device_configuration();
if (ret)
{
dev_conf_.g200params.screw_detect_enable = !check;
check = dev_conf_.g200params.screw_detect_enable;
}
}
return ret;
}
int hg_scanner_239::on_skew_check_level_changed(int& check)
{
int ret = SCANNER_ERR_OK,
2022-05-03 03:56:07 +00:00
val = check,
old = dev_conf_.g200params.screw_detect_level;
HGSCANCONF cf;
cf.g200params.screw_detect_level = -1;
if (val < 0)
{
val = 0;
ret = SCANNER_ERR_NOT_EXACT;
2022-05-03 03:56:07 +00:00
}
else if (val > cf.g200params.screw_detect_level)
{
val = cf.g200params.screw_detect_level;
ret = SCANNER_ERR_NOT_EXACT;
2022-05-03 03:56:07 +00:00
}
if (val != dev_conf_.g200params.screw_detect_level)
{
dev_conf_.g200params.screw_detect_level = val;
ret = writedown_device_configuration();
if (ret)
check = dev_conf_.g200params.screw_detect_level = old;
}
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;
}
2022-07-23 11:08:18 +00:00
int hg_scanner_239::on_get_feedmode(int &feedmode)//获取分纸强度
{
int ret = SCANNER_ERR_OK,
val = 0;
ret = read_register(SR_GET_FEEDMODE,&feedmode);
if (ret == SCANNER_ERR_OK)
{
save_feedmode_type_ = true;
}
return ret;
}
2022-07-23 11:08:18 +00:00
int hg_scanner_239::on_set_feedmode(int feedmode)//设置分纸强度
{
int ret = SCANNER_ERR_OK,
val = 0;
ret = write_register(SR_SET_FEEDMODE,feedmode);
return ret;
}
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
}
void hg_scanner_239::thread_handle_usb_read(void)
{
char buf[64];
HGEIntInfo* info = (HGEIntInfo*)buf;
int size = sizeof(buf),
ret = SCANNER_ERR_OK,
2022-05-03 03:56:07 +00:00
to_cnt = 0,
count = 0;
//status_ = SCANNER_ERR_DEVICE_BUSY;
2022-05-03 03:56:07 +00:00
while (run_ )//&& !user_cancel_
{
if (user_cancel_)
{
break;
}
size = sizeof(buf);
{
std::lock_guard<std::mutex> lock(io_lock_);
ret = io_->read_interrupt(buf, &size);
io_->set_timeout(1000);
}
if (ret == SCANNER_ERR_TIMEOUT)
2022-05-03 03:56:07 +00:00
{
2022-06-13 09:31:03 +00:00
if (img_conf_.resolution_dst == 600.0 && ++to_cnt > 50)
2022-05-03 03:56:07 +00:00
{
status_ = ret;
notify_ui_working_status("通信超时", SANE_EVENT_ERROR, ret);
2022-06-13 09:31:03 +00:00
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "600dpi '%s'\n", hg_scanner_err_name(status_));
break;
}
else if (img_conf_.resolution_dst != 600.0 &&++to_cnt > 20)
{
status_ = ret;
notify_ui_working_status("通信超时", SANE_EVENT_ERROR, ret);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "其他dpi '%s'\n", hg_scanner_err_name(status_));
2022-05-03 03:56:07 +00:00
break;
}
std::this_thread::sleep_for(std::chrono::milliseconds(500));
if ((get_status() & 0x03) == 0)
{
status_ = SCANNER_ERR_OK;
2022-07-25 06:25:08 +00:00
//break;
2022-05-03 03:56:07 +00:00
}
continue;
}
else if (ret != SCANNER_ERR_OK)
2022-05-03 03:56:07 +00:00
{
status_ = ret;
break;
}
to_cnt = 0;
if (size == sizeof(buf))
{
status_ = settings::device_status_to_hg_err(info);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "status from interrupt point is '%s'\n", hg_scanner_err_name(status_));
2022-05-03 03:56:07 +00:00
if (status_ != SCANNER_ERR_OK && status_ != SCANNER_ERR_TIMEOUT && status_ != SCANNER_ERR_DEVICE_STOPPED)
2022-05-03 03:56:07 +00:00
{
if (!is_dev_image_process_done())
{
int st = status_, count = 0, statu = last_usb_image_statu(st);
2022-05-03 03:56:07 +00:00
while (!is_dev_image_process_done())
std::this_thread::sleep_for(std::chrono::milliseconds(30));
while ((count = get_image_count()) > 0)
2022-05-03 03:56:07 +00:00
{
int s = SANE_Image_Statu_OK;
if (count <= 2)
{
if (image_prc_param_.bits.page == PAGE_SINGLE)
s = count == 1 ? statu : s;
else
s = statu;
}
ret = read_one_image_from_usb((SANE_Image_Statu)s);
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;
}
status_ = st;
}
VLOG_MINI_1(LOG_LEVEL_WARNING, "扫描失败, read interrupt返回状态为%s\n", hg_scanner_err_description(status_));
//notify_ui_working_status(("扫描失败 " + hg_scanner::error_description((scanner_err)status_)).c_str(), SANE_EVENT_ERROR, status_);
2022-05-03 03:56:07 +00:00
break;
}
if (info->From == IMG)
{
int s = get_status();
// if (s > 0 && s < 4) // running ...
{
while (get_image_count() > 0)
{
count++;
ret = read_one_image_from_usb();
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;
}
if (user_cancel_)
{
if (ret == SCANNER_ERR_INSUFFICIENT_MEMORY)
2022-05-03 03:56:07 +00:00
stop();
status_ = ret = SCANNER_ERR_USER_CANCELED;
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "用户取消操作 '%s'\n", hg_scanner_err_name(status_));
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);
2022-05-03 03:56:07 +00:00
}
else if (info->From == STOPSCAN)
{
LOG_INFO(LOG_LEVEL_DEBUG_INFO, "received 'STOPSCAN' message in usb thread, check remaining image and finish scanning ...\n");
2022-05-03 03:56:07 +00:00
// fetch all buffered images and exit ...
//while(!is_dev_image_process_done())
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
2022-05-03 03:56:07 +00:00
while (get_image_count() > 0)
{
ret = read_one_image_from_usb();
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;
}
if (count == 0)
{
std::lock_guard<std::mutex> lock(io_lock_);
LOG_INFO(LOG_LEVEL_DEBUG_INFO, "First message received from USB is 'STOPSCAN'\n");
2022-05-03 03:56:07 +00:00
// notify_ui_working_status(STATU_DESC_DEVICE_RESET);
// reset_ = true;
// ret = io_->reset();
// status_ = SCANNER_ERR_IO;
2022-05-03 03:56:07 +00:00
}
else if (status_ == SCANNER_ERR_TIMEOUT || status_ == SCANNER_ERR_IO || status_ == SCANNER_ERR_DEVICE_STOPPED)
status_ = SCANNER_ERR_OK;
2022-05-03 03:56:07 +00:00
int s = get_status();
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "status after received 'STOPSCAN': 0x%x\n", s);
2022-05-03 03:56:07 +00:00
if (count || (s & 3) == 0)
{
LOG_INFO(LOG_LEVEL_DEBUG_INFO, "Really stopped ^_^\n");
2022-05-03 03:56:07 +00:00
break;
}
}
else if (info->From == V4L2)
{
VLOG_MINI_2(LOG_LEVEL_WARNING, "V4L2 message received, code = %d, index = %d\n", info->Code, info->Img_Index);
2022-05-03 03:56:07 +00:00
// stop();
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_name(status_));
2022-05-03 03:56:07 +00:00
}
}
else
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "read %d bytes, sizeof(buf) = %d\n", size, sizeof(buf));
2022-05-03 03:56:07 +00:00
this_thread::sleep_for(chrono::milliseconds(10));
}
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "USB thread exit with code: %s, status = %s\n", hg_scanner_err_name(ret), hg_scanner_err_name(status_));
2022-05-03 03:56:07 +00:00
}
int hg_scanner_239::start(void)
{
2022-07-06 08:19:14 +00:00
split3399_ = 0;
bool handled = false;
int ret = try_third_app_handle_start(handled),
2022-05-03 03:56:07 +00:00
val = 0;
user_cancel_ = false;
// for third-sane-app invoking, added on 2022-05-19
if (handled)
return ret;
2022-05-03 03:56:07 +00:00
user_cancel_ = false;
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
notify_ui_working_status(STATU_DESC_PREPARE_START);
reset();
get_roller_num();
val = get_sleep_time();
2022-07-26 07:14:29 +00:00
string a;
2022-05-03 03:56:07 +00:00
//if (val != 1)
//{
// status_ = SCANNER_ERR_DEVICE_SLEEPING;
// VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "scanner's status(0x%x) is considerring as sleepping.\n", val);
2022-05-03 03:56:07 +00:00
// return status_;
//}
val = get_scan_mode();
if (status_ == SCANNER_ERR_DEVICE_NOT_FOUND)
2022-05-03 03:56:07 +00:00
return status_;
if (val == -1)
return status_;
if (val & 1)
{
status_ = SCANNER_ERR_DEVICE_COUNT_MODE;
2022-05-03 03:56:07 +00:00
return status_;
}
notify_ui_working_status(STATU_DESC_REWRITE_CONFIGURATION);
//if(rewrite_conf_)
{
//协议设置方式一定要注意 1协议结构体做好start一起发送 2每次设置一次发送一次 注意事项除色时颜色切换维彩色使用的是临时变量下发一次被释放如果start再次发就会导致协议层被覆盖
//ret = writedown_device_configuration();
}
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
std::string info(STATU_DESC_REWRITE_CONFIGURATION);
info += std::string("\345\244\261\350\264\245\357\274\232") + hg_scanner_err_name(ret);
2022-05-03 03:56:07 +00:00
notify_ui_working_status(info.c_str(), SANE_EVENT_ERROR, ret);
}
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;
}
ret = get_scanner_paperon();
if (ret == SCANNER_ERR_DEVICE_NO_PAPER)
2022-05-03 03:56:07 +00:00
{
status_ = ret;
notify_ui_working_status(STATU_DESC_SCANNER_ERR_DEVICE_NO_PAPER, SANE_EVENT_ERROR, status_);
VLOG_MINI_1(LOG_LEVEL_WARNING, "device start status is(%s)\n", STATU_DESC_SCANNER_ERR_DEVICE_NO_PAPER);
2022-05-04 03:07:55 +00:00
return ret;
2022-05-03 03:56:07 +00:00
}
ret = write_command(SC_START);
io_->set_timeout(1000);
if (ret == SCANNER_ERR_OK)
2022-05-03 03:56:07 +00:00
{
//status_ = SCANNER_ERR_DEVICE_BUSY;
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
}
VLOG_MINI_1(LOG_LEVEL_WARNING, "start result: %s\n", hg_scanner_err_name(ret));
2022-05-03 03:56:07 +00:00
return ret;
}
int hg_scanner_239::stop(void)
{
int ret = SCANNER_ERR_OK;
2022-05-03 03:56:07 +00:00
user_cancel_ = true;
ret = write_command(SC_STOP);
io_->set_timeout(500);
final_imgs_.clear();
2022-05-03 03:56:07 +00:00
return status_;
}
int hg_scanner_239::reset(void)
{
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;
2022-05-03 03:56:07 +00:00
if (opten->opt_num == HG_239_SETTING_CORRECT && !opten->enabled) // for BUG-20 modified by Gongbing on 2022-03-12
{
bool enable = true;
setting_automatic_skew(opten->opt_num, &enable);
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)
{
return control_fetch(SR_GET_FWVERSION, 0, 20);
}
std::string hg_scanner_239::get_serial_num(void)
{
return control_fetch(SR_GET_SERIALNUM, 0, 20);
}
std::string hg_scanner_239::get_ip(void)
{
return control_fetch(SR_GET_IPADDR, 0, 40);
}
int hg_scanner_239::get_roller_num(void)
{
int val = 0,
ret = read_register(SR_GET_ROLLER_NUM, &val);
if (ret == SCANNER_ERR_OK)
2022-05-03 03:56:07 +00:00
return val;
else
{
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "get_roller_num = %s\n", hg_scanner_err_name(ret));
2022-05-03 03:56:07 +00:00
return -1;
}
}
int hg_scanner_239::clear_roller_num(void)
{
int val = 0,
ret = read_register(SR_CLR_ROLLER_NUM, &val);
return ret;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int hg_scanner_239::set_leaflet_scan(void)
{
int ret = SCANNER_ERR_OK;
2022-05-03 03:56:07 +00:00
test_1_paper_ = true;
ret = start();
return ret;
}
int hg_scanner_239::get_abuot_info(void)
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
2022-05-03 03:56:07 +00:00
}
int hg_scanner_239::restore_default_setting(void)
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
2022-05-03 03:56:07 +00:00
}
int hg_scanner_239::set_final_image_format(SANE_FinalImgFormat* fmt)
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
2022-05-03 03:56:07 +00:00
}
int hg_scanner_239::get_compression_format(void)
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
2022-05-03 03:56:07 +00:00
}
int hg_scanner_239::set_compression_format(void)
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
2022-05-03 03:56:07 +00:00
}
int hg_scanner_239::set_auto_color_type(void)
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
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-07-23 13:02:00 +00:00
int hg_scanner_239::get_sleep_time(int& getime)
2022-05-03 03:56:07 +00:00
{
int val = 0,
ret = read_register(SR_GET_SLEEPTIME, &val);
if (ret == SCANNER_ERR_OK)
2022-05-03 03:56:07 +00:00
{
getime = val;
save_sleeptime_type_ = true;
2022-05-03 03:56:07 +00:00
}
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "get_sleep_time = %s\n", hg_scanner_err_name(ret));
return ret;
2022-05-03 03:56:07 +00:00
}
int hg_scanner_239::set_sleep_time(int setsleepime)
{
int ret = write_register(SR_SET_SLEEPTIME, setsleepime);
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
}
int hg_scanner_239::get_dogear_distance(void)
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
2022-05-03 03:56:07 +00:00
}
int hg_scanner_239::set_dogear_distance(void)
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
2022-05-03 03:56:07 +00:00
}
int hg_scanner_239::get_scanner_paperon(SANE_Bool* paperon)
{
int val = 0,
ret = read_register(SR_GET_PAPERON, &val);
if (ret == SCANNER_ERR_OK)
2022-05-03 03:56:07 +00:00
{
if (!val)
{
ret = SCANNER_ERR_DEVICE_NO_PAPER;
2022-05-03 03:56:07 +00:00
if (paperon)
{
*paperon = true;
}
}
else
{
ret = SCANNER_ERR_OK;
2022-05-03 03:56:07 +00:00
if (paperon)
{
*paperon = false;
}
}
}
else
{
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "get_scanner_paperon = %s\n", hg_scanner_err_name(ret));
2022-05-03 03:56:07 +00:00
return -1;
}
return ret;
}
int hg_scanner_239::set_scan_when_paper_on(void)
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
2022-05-03 03:56:07 +00:00
}
int hg_scanner_239::get_scan_when_paper_on(void)
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
2022-05-03 03:56:07 +00:00
}
int hg_scanner_239::get_scan_with_hole(void)
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
2022-05-03 03:56:07 +00:00
}
int hg_scanner_239::set_scan_with_hole(void)
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
2022-05-03 03:56:07 +00:00
}
int hg_scanner_239::get_scan_is_sleep()
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
2022-05-03 03:56:07 +00:00
}
int hg_scanner_239::notify_sleep()
{
int val = 0,
ret = write_register(SR_NOTIFY_SLEEP, val);
return ret;
}
int hg_scanner_239::get_history_count()
{
return -2;
}
2022-07-26 07:14:29 +00:00
int hg_scanner_239::get_device_log(string &logpath)
{
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(SR_SET_JSON_PATH, len);
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(SR_GET_JSON_SIZE,&buffersize);
if (ret != SCANNER_ERR_OK || buffersize <= 0)
return ret;
ret = write_register(SR_GET_JSON,buffersize);
if (ret != SCANNER_ERR_OK || buffersize <= 0)
return ret;
str.resize(buffersize);
ret = io_->read_bulk(&str[0],&buffersize);
if (ret != SCANNER_ERR_OK)
return ret;
ofstream f;
f.open(save_path,ios::out | ios::app);
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;
}