From b1b0c55e220bef1f83a11edd358c8e37eda7cc89 Mon Sep 17 00:00:00 2001 From: gb <741021719@qq.com> Date: Tue, 11 Oct 2022 14:41:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=BE=93=E5=87=BAUSB?= =?UTF-8?q?=E5=8E=9F=E5=A7=8B=E5=9B=BE=E5=83=8F=E5=8F=8A=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hgdriver/hgdev/hg_scanner.cpp | 33 +++++++++++++++++++++++++++++---- hgdriver/hgdev/hg_scanner.h | 3 ++- hgdriver/wrapper/hg_log.cpp | 4 ++-- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/hgdriver/hgdev/hg_scanner.cpp b/hgdriver/hgdev/hg_scanner.cpp index 2583fa6..6ec1c4f 100644 --- a/hgdriver/hgdev/hg_scanner.cpp +++ b/hgdriver/hgdev/hg_scanner.cpp @@ -98,10 +98,15 @@ hg_scanner::hg_scanner(ScannerSerial serial , double_paper_handle_(0), keep_watermark_(false), save_feedmode_type_(false), feedmode_(1), sleeptime_(-1),split3399_(0) , async_io_(false), is_white_0_(true), isremove_left_hole(false), isremove_right_hole(false), isremove_top_hole(false), isremove_low_hole(false) , isremove_left_hole_threshold(0), isremove_right_hole_threshold(0), isremove_top_hole_threshold(0), isremove_low_hole_threshold(0) + , dump_usb_path_("") { final_path_ = hg_log::ini_get("paths", "final_img"); if(final_path_.empty()) final_path_ = hg_log::local_data_path() + PATH_SEPARATOR + "imgs"; + if (hg_log::ini_get("dump", "dumpusb") == "1") + { + dump_usb_path_ = hg_log::ini_get("dump", "usb_path"); + } if (hg_log::create_folder(final_path_.c_str())) { VLOG_MINI_1(LOG_LEVEL_WARNING, "temporary image folder: %s\n", final_path_.c_str()); @@ -2270,9 +2275,32 @@ void hg_scanner::copy_to_sane_image_header(SANE_Parameters* header, int w, int h int hg_scanner::save_usb_data(std::shared_ptr data) { int ret = SCANNER_ERR_OK; + unsigned int bytes = data->size(); usb_img_index_++; VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "USB read one picture with %u bytes\n", data->size()); + if (dump_usb_path_.length()) + { + char name[80] = { 0 }; + FILE* dst = nullptr; + + sprintf(name, "%susb_img_%03u.jpg", PATH_SEPARATOR, usb_img_index_); + if ((dst = fopen((dump_usb_path_ + name).c_str(), "wb"))) + { + unsigned int off = 0, len = bytes; + unsigned char* buf = data->data(off, &len); + while (buf) + { + fwrite(buf, 1, len, dst); + off += len; + if (off >= bytes) + break; + len = bytes - off; + buf = data->data(off, &len); + } + fclose(dst); + } + } if (!data->swap()) { ret = SCANNER_ERR_OPEN_FILE_FAILED; @@ -2283,10 +2311,7 @@ int hg_scanner::save_usb_data(std::shared_ptr data) if (wait_img_.is_waiting()) wait_img_.notify(); } - unsigned int bytes = data->size(); - //int type = io_->get_pid() & 0x0ff; - - //if(type != 0x39 || (usb_img_index_ & 1)) + if((serial_ != G10039Serial && serial_ != G20039Serial) || (usb_img_index_ & 1)) ui_ev_cb_((scanner_handle)this, SANE_EVENT_USB_DATA_RECEIVED, NULL, &bytes, NULL); diff --git a/hgdriver/hgdev/hg_scanner.h b/hgdriver/hgdev/hg_scanner.h index 2ea6701..21cefb0 100644 --- a/hgdriver/hgdev/hg_scanner.h +++ b/hgdriver/hgdev/hg_scanner.h @@ -256,7 +256,8 @@ protected: SCANCONF img_conf_; //此参数外部不做任何改变,请在writedown_image_configuration做修改 std::string img_type_; - final_img_queue final_imgs_; // JPG ... + std::string dump_usb_path_; // 诊断模式,输出USB原始图像 + final_img_queue final_imgs_; // JPG ... unsigned int usb_img_index_; unsigned int final_img_index_; std::string final_path_; diff --git a/hgdriver/wrapper/hg_log.cpp b/hgdriver/wrapper/hg_log.cpp index d79e3dc..5883d1f 100644 --- a/hgdriver/wrapper/hg_log.cpp +++ b/hgdriver/wrapper/hg_log.cpp @@ -533,7 +533,7 @@ extern "C" } static int get_log_config(const std::string& root, hg_log_type* type, std::string* path) { - std::string me(root + PATH_SEPARATOR + "Cfg" + PATH_SEPARATOR + " scanner.conf"); + std::string me(root + PATH_SEPARATOR + "config" + PATH_SEPARATOR + "debug.cfg"); int lv = LOG_LEVEL_ALL; hg_log_type tp = LOG_TYPE_FILE; @@ -564,7 +564,7 @@ extern "C" lv = LOG_LEVEL_FATAL; } else - create_folder((root + PATH_SEPARATOR + "Cfg").c_str()); + create_folder((root + PATH_SEPARATOR + "config").c_str()); return lv; }