merge public-utilities to sdk/hginclude/util

This commit is contained in:
gb 2023-07-11 17:13:28 +08:00
parent 4ab2323a33
commit fbff9f073f
28 changed files with 823 additions and 1886 deletions

View File

@ -5,7 +5,7 @@ add_definitions(-DUOS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -O2") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -O2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -O2") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -O2")
aux_source_directory(${PROJECT_SOURCE_DIR} DIR_SRCS) aux_source_directory(${PROJECT_SOURCE_DIR} DIR_SRCS)
file(GLOB DIR_HEADS "${PROJECT_SOURCE_DIR}/*.h" "${PROJECT_SOURCE_DIR}/*.hpp") file(GLOB DIR_HEADS "${PROJECT_SOURCE_DIR}/*.h" "${PROJECT_SOURCE_DIR}/*.hpp" "${PROJECT_SOURCE_DIR}/../../sdk/hginclude/*.h" "${PROJECT_SOURCE_DIR}/../../sdk/hginclude/*.cpp")
set(DIR_SRCS ${DIR_SRCS} ${DIR_HEADS}) set(DIR_SRCS ${DIR_SRCS} ${DIR_HEADS})
add_library(${PROJECT_NAME} STATIC ${DIR_SRCS}) add_library(${PROJECT_NAME} STATIC ${DIR_SRCS})
@ -53,7 +53,7 @@ target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}/../3rdparty/opencv/include ${PROJECT_SOURCE_DIR}/../3rdparty/opencv/include
${PROJECT_SOURCE_DIR}/../3rdparty/tiff/include ${PROJECT_SOURCE_DIR}/../3rdparty/tiff/include
${PROJECT_SOURCE_DIR}/../../../sdk/include ${PROJECT_SOURCE_DIR}/../../../sdk/include
${PROJECT_SOURCE_DIR}/../wrapper ${PROJECT_SOURCE_DIR}/../../sdk/hginclude
) )
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/../../../build) set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/../../../build)

View File

@ -1,8 +1,8 @@
#include "common_setting.h" #include "common_setting.h"
#include "sane/sane_option_definitions.h" #include "sane/sane_option_definitions.h"
#include "hg_log.h" #include <lang/app_language.h>
#define MAKE_ID_AND_STR(id) id, hg_log::lang_load(id) #define MAKE_ID_AND_STR(id) id, lang_load_string(id, nullptr)
static struct _fixed_option static struct _fixed_option
{ {
int str_id; int str_id;
@ -251,7 +251,7 @@ static std::string get_str(struct _fixed_option* arr, int num, int enm, int defa
static void reload_string(struct _fixed_option* arr, int num) static void reload_string(struct _fixed_option* arr, int num)
{ {
for (int i = 0; i < num; ++i) for (int i = 0; i < num; ++i)
arr[i].str = hg_log::lang_load(arr[i].str_id); arr[i].str = lang_load_string(arr[i].str_id, nullptr);
} }
#define RELOAD_STRING(arr) reload_string(arr, ARRAY_SIZE(arr)) #define RELOAD_STRING(arr) reload_string(arr, ARRAY_SIZE(arr))
@ -504,16 +504,16 @@ int double_paper_flag_from_option_value(std::string& opt_val, bool* exact)
if (exact) if (exact)
*exact = true; *exact = true;
if (opt_val == hg_log::lang_load(ID_OPTION_VALUE_SZTPCL_SCTXBJXSM)) if (opt_val == lang_load_string(ID_OPTION_VALUE_SZTPCL_SCTXBJXSM, nullptr))
return DOUBLE_PAPER_CONTINUE | DOUBLE_PAPER_SAVE_IMG; return DOUBLE_PAPER_CONTINUE | DOUBLE_PAPER_SAVE_IMG;
else if (opt_val == hg_log::lang_load(ID_OPTION_VALUE_SZTPCL_SCTXBTZSM)) else if (opt_val == lang_load_string(ID_OPTION_VALUE_SZTPCL_SCTXBTZSM, nullptr))
return DOUBLE_PAPER_SAVE_IMG; return DOUBLE_PAPER_SAVE_IMG;
else if (opt_val == hg_log::lang_load(ID_OPTION_VALUE_SZTPCL_DQTXBJXSM)) else if (opt_val == lang_load_string(ID_OPTION_VALUE_SZTPCL_DQTXBJXSM, nullptr))
return DOUBLE_PAPER_CONTINUE; return DOUBLE_PAPER_CONTINUE;
else else
{ {
if (exact) if (exact)
*exact = opt_val == hg_log::lang_load(ID_OPTION_VALUE_SZTPCL_DQTXBTZSM); *exact = opt_val == lang_load_string(ID_OPTION_VALUE_SZTPCL_DQTXBTZSM, nullptr);
} }
return 0; return 0;
} }
@ -523,14 +523,14 @@ std::string double_paper_flag_to_option_value(int flag)
if (is_continue_when_double_paper(flag)) if (is_continue_when_double_paper(flag))
{ {
if (is_save_img_when_double_paper(flag)) if (is_save_img_when_double_paper(flag))
return hg_log::lang_load(ID_OPTION_VALUE_SZTPCL_SCTXBJXSM); return lang_load_string(ID_OPTION_VALUE_SZTPCL_SCTXBJXSM, nullptr);
else else
return hg_log::lang_load(ID_OPTION_VALUE_SZTPCL_DQTXBJXSM); return lang_load_string(ID_OPTION_VALUE_SZTPCL_DQTXBJXSM, nullptr);
} }
else if (is_save_img_when_double_paper(flag)) else if (is_save_img_when_double_paper(flag))
return hg_log::lang_load(ID_OPTION_VALUE_SZTPCL_SCTXBTZSM); return lang_load_string(ID_OPTION_VALUE_SZTPCL_SCTXBTZSM, nullptr);
else else
return hg_log::lang_load(ID_OPTION_VALUE_SZTPCL_DQTXBTZSM); return lang_load_string(ID_OPTION_VALUE_SZTPCL_DQTXBTZSM, nullptr);
} }
bool is_continue_when_double_paper(int flag) bool is_continue_when_double_paper(int flag)
{ {

View File

@ -1,6 +1,7 @@
#include "hg_ipc.h" #include "hg_ipc.h"
#include "../wrapper/hg_log.h"
#include "huagao/hgscanner_error.h" #include "huagao/hgscanner_error.h"
#include "../../sdk/hginclude/utils.h"
#if defined(WIN32) || defined(_WIN64) #if defined(WIN32) || defined(_WIN64)
//#include "scanner_manager.h" //#include "scanner_manager.h"
@ -98,7 +99,7 @@ platform_event::platform_event() : waiting_(false), dbg_info_("")
if (err == -1) if (err == -1)
{ {
err = errno; err = errno;
VLOG_MINI_2(LOG_LEVEL_FATAL, "(%s)sem_init failed: %d\n", hg_log::format_ptr(this).c_str(), err); utils::to_log(LOG_LEVEL_FATAL, "(%p)sem_init failed: %d\n", this, err);
} }
} }
platform_event::~platform_event() platform_event::~platform_event()
@ -114,7 +115,7 @@ bool platform_event::wait(unsigned timeout)
{ {
bool waited = true; bool waited = true;
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "platform_event(%s - %s) --> waiting...\n", hg_log::format_ptr(this).c_str(), dbg_info_.c_str()); utils::to_log(LOG_LEVEL_DEBUG, "platform_event(%p - %s) --> waiting...\n", this, dbg_info_.c_str());
waiting_ = true; waiting_ = true;
if (timeout == USB_TIMEOUT_INFINITE) if (timeout == USB_TIMEOUT_INFINITE)
sem_wait(&sem_); sem_wait(&sem_);
@ -125,7 +126,7 @@ bool platform_event::wait(unsigned timeout)
to.tv_nsec = (long)((timeout % 1000) * 1000 * 1000); to.tv_nsec = (long)((timeout % 1000) * 1000 * 1000);
waited = sem_timedwait(&sem_, &to) == 0; waited = sem_timedwait(&sem_, &to) == 0;
} }
VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "platform_event(%s - %s) --> %s.\n", hg_log::format_ptr(this).c_str(), dbg_info_.c_str(), waited ? "waited" : "wait timeout"); utils::to_log(LOG_LEVEL_DEBUG, "platform_event(%p - %s) --> %s.\n", this, dbg_info_.c_str(), waited ? "waited" : "wait timeout");
waiting_ = false; waiting_ = false;
return waited; return waited;
@ -149,7 +150,7 @@ void platform_event::set_debug_info(const char* info)
shared_memory::shared_memory(unsigned long long key, size_t size) : key_(key), obj_((void*)-1), first_(true), bytes_(size), len_(0) shared_memory::shared_memory(unsigned long long key, size_t size) : key_(key), obj_((void*)-1), first_(true), bytes_(size), len_(0)
{ {
unsigned int* ptr = (unsigned int*)&key_; unsigned int* ptr = (unsigned int*)&key_;
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "shared memory key = 0x%x%08x\n", ptr[1], ptr[0]); utils::to_log(LOG_LEVEL_DEBUG, "shared memory key = 0x%x%08x\n", ptr[1], ptr[0]);
init(); init();
} }
@ -183,11 +184,11 @@ void shared_memory::init(void)
obj = shmget(key_, bytes_, 0600); obj = shmget(key_, bytes_, 0600);
if(obj == -1) if(obj == -1)
obj = shmget(key_, bytes_, 0); obj = shmget(key_, bytes_, 0);
VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "open existing: shmget(0x%x%08x) = %d\n", v[1], v[0], obj); utils::to_log(LOG_LEVEL_DEBUG, "open existing: shmget(0x%x%08x) = %d\n", v[1], v[0], obj);
obj_ = (void*)obj; obj_ = (void*)obj;
std::string prev(read()), proc(""); std::string prev(read()), proc("");
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "shared memory content: %s\n", prev.c_str()); utils::to_log(LOG_LEVEL_DEBUG, "shared memory content: %s\n", prev.c_str());
if(prev.length()) if(prev.length())
{ {
proc = prev; proc = prev;
@ -212,23 +213,23 @@ void shared_memory::init(void)
first_ = true; first_ = true;
clear(); clear();
obj = shmget(key_, bytes_, IPC_EXCL | IPC_CREAT | 0600); obj = shmget(key_, bytes_, IPC_EXCL | IPC_CREAT | 0600);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "%s is not existing and reopen it\n", prev.c_str()); utils::to_log(LOG_LEVEL_DEBUG, "%s is not existing and reopen it\n", prev.c_str());
} }
} }
else else
{ {
VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "shmget(0x%x%08x) = %d\n", v[1], v[0], errno); utils::to_log(LOG_LEVEL_DEBUG, "shmget(0x%x%08x) = %d\n", v[1], v[0], errno);
return; return;
} }
} }
obj_ = (void*)obj; obj_ = (void*)obj;
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "shared memory id = %d[%s], \n", obj, first_ ? "created" : "opened"); utils::to_log(LOG_LEVEL_DEBUG, "shared memory id = %d[%s], \n", obj, first_ ? "created" : "opened");
#endif #endif
if(first_) if(first_)
{ {
pid_t pid = getpid(); pid_t pid = getpid();
std::string me(""); std::string me(utils::get_module_full_path());
char buf[40] = { 0 }; char buf[40] = { 0 };
unsigned int* pn = (unsigned int*)&pid; unsigned int* pn = (unsigned int*)&pid;
@ -236,7 +237,10 @@ void shared_memory::init(void)
sprintf(buf, "(pid: 0x%x%08x)", pn[1], pn[0]); sprintf(buf, "(pid: 0x%x%08x)", pn[1], pn[0]);
else else
sprintf(buf, "(pid: %u)", pn[0]); sprintf(buf, "(pid: %u)", pn[0]);
hg_log::pe_path(&me);
size_t pos = me.rfind(PATH_SEPARATOR[0]);
if(pos++ != std::string::npos)
me.erase(0, pos);
me += buf; me += buf;
write(me.c_str(), me.length()); write(me.c_str(), me.length());
} }
@ -268,7 +272,7 @@ char* shared_memory::get_buf(void)
#else #else
int* h = (int*)&obj_; int* h = (int*)&obj_;
char* buf = (char*)shmat(*h, 0, 0); char* buf = (char*)shmat(*h, 0, 0);
VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "shared memory %d buffer = %s, error = %d\n", *h, hg_log::format_ptr(buf).c_str(), errno); utils::to_log(LOG_LEVEL_DEBUG, "shared memory %d buffer = %p, error = %d\n", *h, buf, errno);
#endif #endif
return buf; return buf;
@ -307,11 +311,11 @@ std::string shared_memory::get_proc_name_by_pid(pid_t pid)
} }
if (sizeof(pid) > 4 && v[1]) if (sizeof(pid) > 4 && v[1])
{ {
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "PID(%lld) name is: %s\n", pid, ret.c_str()); utils::to_log(LOG_LEVEL_DEBUG, "PID(%lld) name is: %s\n", pid, ret.c_str());
} }
else else
{ {
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "PID(%u) name is: %s\n", pid, ret.c_str()); utils::to_log(LOG_LEVEL_DEBUG, "PID(%u) name is: %s\n", pid, ret.c_str());
} }
return ret; return ret;
@ -367,9 +371,9 @@ int shared_memory::write(const char* data, size_t len)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// tiny_file_map ... // tiny_file_map ...
tiny_file_map::tiny_file_map() : size_(0), map_(INVALID_HANDLE_NAME), buf_(nullptr), file_(""), keep_f_(false) tiny_file_map::tiny_file_map() : size_(0), map_(INVALID_HANDLE_NAME), buf_(nullptr), file_(""), keep_f_(false)
, map_off_(0), map_bytes_(0), page_size_(hg_log::get_page_size()) , map_off_(0), map_bytes_(0), page_size_(utils::get_page_size())
{ {
hg_log::get_page_size(&page_size_); utils::get_page_size(&page_size_);
} }
tiny_file_map::~tiny_file_map() tiny_file_map::~tiny_file_map()
{ {
@ -414,14 +418,14 @@ HANDLE_NAME tiny_file_map::open_file_for_mapping(const char* file, unsigned* byt
{ {
if (lseek(ret, *bytes - 1, SEEK_SET) < 0) if (lseek(ret, *bytes - 1, SEEK_SET) < 0)
{ {
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "set file size to %u - 1 bytes failed: %d\n", *bytes, errno); utils::to_log(LOG_LEVEL_DEBUG, "set file size to %u - 1 bytes failed: %d\n", *bytes, errno);
::close(ret); ::close(ret);
remove(file); remove(file);
ret = INVALID_HANDLE_NAME; ret = INVALID_HANDLE_NAME;
} }
if (write(ret, "0", 1) < 0) if (write(ret, "0", 1) < 0)
{ {
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "set file size to %u bytes failed: %d\n", *bytes, errno); utils::to_log(LOG_LEVEL_DEBUG, "set file size to %u bytes failed: %d\n", *bytes, errno);
::close(ret); ::close(ret);
remove(file); remove(file);
ret = INVALID_HANDLE_NAME; ret = INVALID_HANDLE_NAME;
@ -543,7 +547,7 @@ int tiny_file_map::open(const char* file, bool existing, unsigned int size)
size_ = size; size_ = size;
} }
VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "map([%s]%s) = %d\n", existing ? "existing" : "new", file, ret); utils::to_log(LOG_LEVEL_DEBUG, "map([%s]%s) = %d\n", existing ? "existing" : "new", file, ret);
if (ret == SCANNER_ERR_OK) if (ret == SCANNER_ERR_OK)
file_ = file; file_ = file;
@ -857,7 +861,7 @@ void final_img_queue::fetch_front(void* buf, int* len, bool* over)
{ {
if (!imgd.data->swap()) if (!imgd.data->swap())
{ {
VLOG_MINI_1(LOG_LEVEL_FATAL, "Reload final image '%s' failed!\n", imgd.data->file().c_str()); utils::to_log(LOG_LEVEL_FATAL, "Reload final image '%s' failed!\n", imgd.data->file().c_str());
} }
} }
@ -871,7 +875,7 @@ void final_img_queue::fetch_front(void* buf, int* len, bool* over)
} }
else else
{ {
VLOG_MINI_2(LOG_LEVEL_FATAL, "Remap final image '%s + 0x%08x' failed!\n", imgd.data->file().c_str(), imgd.offset); utils::to_log(LOG_LEVEL_FATAL, "Remap final image '%s + 0x%08x' failed!\n", imgd.data->file().c_str(), imgd.offset);
} }
imgd.offset += *len; imgd.offset += *len;
if (imgd.offset >= imgd.header.bytes) if (imgd.offset >= imgd.header.bytes)

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,7 @@
#include "hg_scanner_200.h" #include "hg_scanner_200.h"
#include "../wrapper/hg_log.h"
#include "../../sdk/hginclude/utils.h"
#include <lang/app_language.h>
#if defined(WIN32) || defined(_WIN64) #if defined(WIN32) || defined(_WIN64)
#include "scanner_manager.h" #include "scanner_manager.h"
@ -120,7 +122,7 @@ void hg_scanner_200::discard_prev(void)
ret = get_scanner_status(usb); ret = get_scanner_status(usb);
} }
if (imgs || packets) if (imgs || packets)
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "discard prev-scanning %d packets and %d images.\n", packets, imgs); utils::to_log(LOG_LEVEL_DEBUG, "discard prev-scanning %d packets and %d images.\n", packets, imgs);
} }
int hg_scanner_200::on_scanner_closing(bool force) int hg_scanner_200::on_scanner_closing(bool force)
{ {
@ -263,7 +265,7 @@ void hg_scanner_200::thread_handle_usb_read(void)
} }
this_thread::sleep_for(chrono::milliseconds(2)); this_thread::sleep_for(chrono::milliseconds(2));
} }
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_)); utils::to_log(LOG_LEVEL_DEBUG, "USB thread exit with code: %s, status = %s\n", hg_scanner_err_name(ret), hg_scanner_err_description(status_));
} }
int hg_scanner_200::start(void) int hg_scanner_200::start(void)
{ {
@ -292,7 +294,7 @@ int hg_scanner_200::start(void)
{ {
status_ = ret = SCANNER_ERR_DEVICE_NO_PAPER; status_ = ret = SCANNER_ERR_DEVICE_NO_PAPER;
//notify_ui_working_status(STATU_DESC_SCANNER_ERR_DEVICE_NO_PAPER, SANE_EVENT_ERROR, status_); //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", hg_log::lang_load(ID_STATU_DESC_SCANNER_ERR_DEVICE_NO_PAPER)); utils::to_log(LOG_LEVEL_WARNING, "device start status is(%s)\n", lang_load_string(ID_STATU_DESC_SCANNER_ERR_DEVICE_NO_PAPER, nullptr));
return ret; return ret;
} }
@ -302,7 +304,7 @@ int hg_scanner_200::start(void)
ret = writeusb(usb); ret = writeusb(usb);
io_->set_timeout(500); io_->set_timeout(500);
} }
VLOG_MINI_1(LOG_LEVEL_WARNING, "write start command = %s\n", hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_WARNING, "write start command = %s\n", hg_scanner_err_name(ret));
if(ret == SCANNER_ERR_OK) if(ret == SCANNER_ERR_OK)
{ {
@ -312,7 +314,7 @@ int hg_scanner_200::start(void)
} }
else else
status_ = ret; status_ = ret;
VLOG_MINI_1(LOG_LEVEL_WARNING, "start result: %s\n", hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_WARNING, "start result: %s\n", hg_scanner_err_name(ret));
return ret; return ret;
} }
@ -328,7 +330,7 @@ int hg_scanner_200::stop(void)
user_cancel_ = true; user_cancel_ = true;
if (ret == SCANNER_ERR_DEVICE_BUSY) if (ret == SCANNER_ERR_DEVICE_BUSY)
{ {
LOG_INFO(LOG_LEVEL_DEBUG_INFO,"stop status is busy\r\n"); utils::log_info("stop status is busy\r\n", LOG_LEVEL_DEBUG);
std::this_thread::sleep_for(std::chrono::milliseconds(2000)); std::this_thread::sleep_for(std::chrono::milliseconds(2000));
} }
else if (ret == SCANNER_ERR_OK) else if (ret == SCANNER_ERR_OK)
@ -433,7 +435,7 @@ int hg_scanner_200::get_img_data(unsigned int bytes, SANE_Image_Statu statu)
void* buf = imagedata->data(index, &size); void* buf = imagedata->data(index, &size);
if (!buf) if (!buf)
{ {
VLOG_MINI_3(LOG_LEVEL_FATAL, "memory(0x%08x + %u) fatal when read USB image %d !!!\n", index, block, usb_img_index_); utils::to_log(LOG_LEVEL_FATAL, "memory(0x%08x + %u) fatal when read USB image %d !!!\n", index, block, usb_img_index_);
ret = SCANNER_ERR_INSUFFICIENT_MEMORY; ret = SCANNER_ERR_INSUFFICIENT_MEMORY;
break; break;
} }
@ -483,7 +485,7 @@ int hg_scanner_200::writedown_device_configuration(bool type,setting_hardware::H
ret = io_->write_bulk(&usbcb, &len); ret = io_->write_bulk(&usbcb, &len);
} }
VLOG_MINI_1(LOG_LEVEL_WARNING, "writedown_device_configuration is .(%s)\n", hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_WARNING, "writedown_device_configuration is .(%s)\n", hg_scanner_err_name(ret));
return ret; return ret;
} }
@ -693,7 +695,7 @@ void hg_scanner_200::writedown_image_configuration(void)
ic.imageRotateDegree = 0; ic.imageRotateDegree = 0;
if (test_1_paper_) if (test_1_paper_)
{ {
LOG_INFO(LOG_LEVEL_DEBUG_INFO, "scanning mode: testing ONE paper ...\n"); utils::log_info("scanning mode: testing ONE paper ...\n", LOG_LEVEL_DEBUG);
ic.scannum = 1; ic.scannum = 1;
} }
else else
@ -716,18 +718,18 @@ void hg_scanner_200::printf_devconfig(setting_hardware::HGSCANCONF_DSP *d)
if (!d) if (!d)
d = &dsp_config_; d = &dsp_config_;
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"\r\ndsp_config.params_dsp.color:%d\r\n",d->params_dsp.color); utils::to_log(LOG_LEVEL_DEBUG,"\r\ndsp_config.params_dsp.color:%d\r\n",d->params_dsp.color);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"dsp_config_.params_dsp.double_feed_enbale:%d\r\n",d->params_dsp.double_feed_enbale); utils::to_log(LOG_LEVEL_DEBUG,"dsp_config_.params_dsp.double_feed_enbale:%d\r\n",d->params_dsp.double_feed_enbale);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"dsp_config_.params_dsp.dpi:%d\r\n",d->params_dsp.dpi); utils::to_log(LOG_LEVEL_DEBUG,"dsp_config_.params_dsp.dpi:%d\r\n",d->params_dsp.dpi);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"dsp_config_.params_dsp.enable_sizecheck:%d\r\n",d->params_dsp.enable_sizecheck); utils::to_log(LOG_LEVEL_DEBUG,"dsp_config_.params_dsp.enable_sizecheck:%d\r\n",d->params_dsp.enable_sizecheck);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"dsp_config_.params_dsp.paper:%d\r\n",d->params_dsp.paper); utils::to_log(LOG_LEVEL_DEBUG,"dsp_config_.params_dsp.paper:%d\r\n",d->params_dsp.paper);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"dsp_config_.params_dsp.pc_correct:%d\r\n",d->params_dsp.pc_correct); utils::to_log(LOG_LEVEL_DEBUG,"dsp_config_.params_dsp.pc_correct:%d\r\n",d->params_dsp.pc_correct);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"dsp_config_.params_dsp.screw_detect_enable:%d\r\n",d->params_dsp.screw_detect_enable); utils::to_log(LOG_LEVEL_DEBUG,"dsp_config_.params_dsp.screw_detect_enable:%d\r\n",d->params_dsp.screw_detect_enable);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"dsp_config_.params_dsp.screw_detect_level:%d\r\n",d->params_dsp.screw_detect_level); utils::to_log(LOG_LEVEL_DEBUG,"dsp_config_.params_dsp.screw_detect_level:%d\r\n",d->params_dsp.screw_detect_level);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"dsp_config_.params_dsp.stable_enbale:%d\r\n",d->params_dsp.stable_enbale); utils::to_log(LOG_LEVEL_DEBUG,"dsp_config_.params_dsp.stable_enbale:%d\r\n",d->params_dsp.stable_enbale);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"dsp_config_.params_dsp.unused_one:%d\r\n",d->params_dsp.unused_one); utils::to_log(LOG_LEVEL_DEBUG,"dsp_config_.params_dsp.unused_one:%d\r\n",d->params_dsp.unused_one);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"dsp_config_.params_dsp.unused_two:%d\r\n",d->params_dsp.unused_two); utils::to_log(LOG_LEVEL_DEBUG,"dsp_config_.params_dsp.unused_two:%d\r\n",d->params_dsp.unused_two);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"dsp_config_.params_dsp.value:%d\r\n",d->value); utils::to_log(LOG_LEVEL_DEBUG,"dsp_config_.params_dsp.value:%d\r\n",d->value);
} }
std::string hg_scanner_200::get_firmware_version() std::string hg_scanner_200::get_firmware_version()
{ {
@ -1001,7 +1003,7 @@ int hg_scanner_200::set_auto_flat(int data)
} }
else else
status_ = ret; status_ = ret;
VLOG_MINI_1(LOG_LEVEL_WARNING, "set_auto_flat ret: %s\n", hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_WARNING, "set_auto_flat ret: %s\n", hg_scanner_err_name(ret));
return ret; return ret;
} }

View File

@ -10,7 +10,6 @@
#include <algorithm> #include <algorithm>
#include "hg_scanner.h" #include "hg_scanner.h"
#include "../wrapper/hg_log.h"
//#ifdef OEM_HANWANG //#ifdef OEM_HANWANG
//#define hg_scanner_200 hw_scanner_200 //#define hg_scanner_200 hw_scanner_200

View File

@ -1,5 +1,7 @@
#include "hg_scanner_239.h" #include "hg_scanner_239.h"
#include "../wrapper/hg_log.h"
#include "../../sdk/hginclude/utils.h"
#include <lang/app_language.h>
#include "filetools.h" #include "filetools.h"
#if defined(WIN32) || defined(_WIN64) #if defined(WIN32) || defined(_WIN64)
@ -159,7 +161,7 @@ hg_scanner_239::hg_scanner_239(const char* dev_name, int pid,usb_io* io) : hg_sc
{ {
init_version(); init_version();
//pid_ = pid; //pid_ = pid;
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "hg_scanner_239(%s) constructing ...\n", hg_log::format_ptr(this).c_str()); utils::to_log(LOG_LEVEL_DEBUG, "hg_scanner_239(%p) constructing ...\n", this);
dev_conf_.value = 0; dev_conf_.value = 0;
#ifndef MAPPING_FUNCTION_IN_BASE #ifndef MAPPING_FUNCTION_IN_BASE
init_setting_map(setting_map_, ARRAY_SIZE(setting_map_)); init_setting_map(setting_map_, ARRAY_SIZE(setting_map_));
@ -181,7 +183,7 @@ hg_scanner_239::hg_scanner_239(const char* dev_name, int pid,usb_io* io) : hg_sc
} }
hg_scanner_239::~hg_scanner_239() 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()); utils::to_log(LOG_LEVEL_DEBUG, "hg_scanner_239(%p) destroyed.\n", this);
} }
int hg_scanner_239::read_register(int addr, int* val) int hg_scanner_239::read_register(int addr, int* val)
{ {
@ -222,12 +224,12 @@ std::string hg_scanner_239::control_fetch(int addr, int val, int size)
ret = io_->read_bulk(&data[0], &l); ret = io_->read_bulk(&data[0], &l);
if (ret || l == 0) if (ret || l == 0)
{ {
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)); utils::to_log(LOG_LEVEL_DEBUG, "control_fetch(%d, %d) - read_bulk %d byte(s) = %s\n", addr, val, l, hg_scanner_err_name(ret));
data.clear(); data.clear();
} }
} }
else else
VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "control_fetch(%d, %d) = %s\n", addr, val, hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_DEBUG, "control_fetch(%d, %d) = %s\n", addr, val, hg_scanner_err_name(ret));
return data; return data;
} }
@ -255,7 +257,7 @@ int hg_scanner_239::get_scan_mode(bool &type)
ret = read_register(setting3399::SR_OS, &val); //val == 1计数模式 ret = read_register(setting3399::SR_OS, &val); //val == 1计数模式
type =val == 1 ? false : true; type =val == 1 ? false : true;
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)); utils::to_log(LOG_LEVEL_DEBUG, "get_scan_mode: %s\n", type ? hg_scanner_err_description(SCANNER_ERR_DEVICE_COUNT_MODE) : hg_scanner_err_description(SCANNER_ERR_OK));
return ret; return ret;
} }
@ -342,7 +344,7 @@ int hg_scanner_239::set_auto_flat(int data)
std::this_thread::sleep_for(std::chrono::milliseconds(300)); std::this_thread::sleep_for(std::chrono::milliseconds(300));
ret = try_third_app_after_start(ret); ret = try_third_app_after_start(ret);
} }
VLOG_MINI_1(LOG_LEVEL_WARNING, "set_auto_flat ret: %s\n", hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_WARNING, "set_auto_flat ret: %s\n", hg_scanner_err_name(ret));
return ret; return ret;
} }
int hg_scanner_239::get_motor_board_ver(string &ver) int hg_scanner_239::get_motor_board_ver(string &ver)
@ -363,7 +365,7 @@ int hg_scanner_239::get_status(void)
if (ret) if (ret)
{ {
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "get status error: %s\n", hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_DEBUG, "get status error: %s\n", hg_scanner_err_name(ret));
status_ = ret; status_ = ret;
return -1; return -1;
@ -380,7 +382,7 @@ bool hg_scanner_239::is_dev_image_process_done(void)
if (ret) if (ret)
{ {
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "is_dev_image_process_done() error: %s\n", hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_DEBUG, "is_dev_image_process_done() error: %s\n", hg_scanner_err_name(ret));
status_ = ret; status_ = ret;
return true; return true;
@ -397,7 +399,7 @@ bool hg_scanner_239::is_dev_image_keep_last_paper(void)
if (ret) if (ret)
{ {
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "is_dev_image_keep_last_paper() error: %s\n", hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_DEBUG, "is_dev_image_keep_last_paper() error: %s\n", hg_scanner_err_name(ret));
status_ = ret; status_ = ret;
return true; return true;
@ -412,7 +414,7 @@ int hg_scanner_239::get_image_count(void)
int val = 0, int val = 0,
ret = read_register(setting3399::SR_IM_COUNT, &val); ret = read_register(setting3399::SR_IM_COUNT, &val);
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Gets The image queue in the 'DEVICE':[%d]\n", val); //utils::to_log(LOG_LEVEL_DEBUG, "Gets The image queue in the 'DEVICE':[%d]\n", val);
if (ret == SCANNER_ERR_OK) if (ret == SCANNER_ERR_OK)
return val; return val;
@ -430,7 +432,7 @@ int hg_scanner_239::get_front_data_size(void)
return val; return val;
else else
{ {
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "get_front_data_size = %s\n", hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_DEBUG, "get_front_data_size = %s\n", hg_scanner_err_name(ret));
return -1; return -1;
} }
} }
@ -516,18 +518,18 @@ void hg_scanner_239::init_version(void)
firmware_sup_color_fill_ = year >= "3C" ? true : false; firmware_sup_color_fill_ = year >= "3C" ? true : false;
} }
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Firmware_sup_wait_paper_:%s\r\n", firmware_sup_wait_paper_ ? "enable" : "close"); utils::to_log(LOG_LEVEL_DEBUG, "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"); utils::to_log(LOG_LEVEL_DEBUG, "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"); utils::to_log(LOG_LEVEL_DEBUG, "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"); utils::to_log(LOG_LEVEL_DEBUG, "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"); utils::to_log(LOG_LEVEL_DEBUG, "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"); utils::to_log(LOG_LEVEL_DEBUG, "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"); utils::to_log(LOG_LEVEL_DEBUG, "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"); utils::to_log(LOG_LEVEL_DEBUG, "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"); utils::to_log(LOG_LEVEL_DEBUG, "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"); utils::to_log(LOG_LEVEL_DEBUG, "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"); utils::to_log(LOG_LEVEL_DEBUG, "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()); utils::to_log(LOG_LEVEL_DEBUG, "Firmware version: %s\n", fv.c_str());
//is_kernelsnap_239_220429_ = date >= "B0429" ? true : false; //is_kernelsnap_239_220429_ = date >= "B0429" ? true : false;
//is_kernelsnap_239_220430_ = date >= "B0430" ? true : false; //is_kernelsnap_239_220430_ = date >= "B0430" ? true : false;
@ -598,7 +600,7 @@ int hg_scanner_239::writedown_device_configuration(bool type, setting_hardware:
ret = write_register(setting3399::SR_CONFIG_SCAN_PARAM, dev_conf->value); ret = write_register(setting3399::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)); utils::to_log(LOG_LEVEL_DEBUG, "Writedown scanner configuration(0x%x) = %s\n", dev_conf->value, hg_scanner_err_name(ret));
return ret; return ret;
} }
int hg_scanner_239::writedown_image_configuration(void) int hg_scanner_239::writedown_image_configuration(void)
@ -625,7 +627,7 @@ int hg_scanner_239::writedown_image_configuration(void)
ic.hardwarecaps.skrewdetectlevel = dev_conf_.params_3399.screw_detect_level; ic.hardwarecaps.skrewdetectlevel = dev_conf_.params_3399.screw_detect_level;
if (test_1_paper_) if (test_1_paper_)
{ {
LOG_INFO(LOG_LEVEL_DEBUG_INFO, "scanning mode: testing ONE paper ...\n"); utils::log_info("scanning mode: testing ONE paper ...\n", LOG_LEVEL_DEBUG);
ic.scannum = ic.is_duplex ? 2 : 1; ic.scannum = ic.is_duplex ? 2 : 1;
} }
else else
@ -656,7 +658,7 @@ int hg_scanner_239::pop_first_image(void)
int ret = write_register(setting3399::SR_IM_POP, 1); int ret = write_register(setting3399::SR_IM_POP, 1);
if (ret) if (ret)
{ {
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "popup first image = %s\n", hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_DEBUG, "popup first image = %s\n", hg_scanner_err_name(ret));
} }
return ret; return ret;
} }
@ -701,7 +703,7 @@ int hg_scanner_239::read_one_image_from_usb(SANE_Image_Statu statu)
int block = 0; int block = 0;
if (!buff) if (!buff)
{ {
VLOG_MINI_3(LOG_LEVEL_FATAL, "memory(0x%08x + %u) fatal when read USB image %d !!!\n", off, r, usb_img_index_); utils::to_log(LOG_LEVEL_FATAL, "memory(0x%08x + %u) fatal when read USB image %d !!!\n", off, r, usb_img_index_);
ret = SCANNER_ERR_INSUFFICIENT_MEMORY; ret = SCANNER_ERR_INSUFFICIENT_MEMORY;
} }
else else
@ -718,7 +720,7 @@ int hg_scanner_239::read_one_image_from_usb(SANE_Image_Statu statu)
void* buff = buf->data(off, &size); void* buff = buf->data(off, &size);
if (!buf) if (!buf)
{ {
//VLOG_MINI_3(LOG_LEVEL_FATAL, "memory(0x%08x + %u) fatal when read USB image %d !!!\n", index, block, usb_img_index_); //utils::to_log(LOG_LEVEL_FATAL, "memory(0x%08x + %u) fatal when read USB image %d !!!\n", index, block, usb_img_index_);
ret = SCANNER_ERR_INSUFFICIENT_MEMORY; ret = SCANNER_ERR_INSUFFICIENT_MEMORY;
break; break;
} }
@ -727,7 +729,7 @@ int hg_scanner_239::read_one_image_from_usb(SANE_Image_Statu statu)
if (ret != SCANNER_ERR_OK) 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); utils::to_log(LOG_LEVEL_FATAL, "read_one_image_from_usb read_data:%s!!! read data[%d/:%d]\n", hg_scanner_err_name(ret),size, block);
break; break;
} }
@ -738,7 +740,7 @@ int hg_scanner_239::read_one_image_from_usb(SANE_Image_Statu statu)
} }
if (r > 0) if (r > 0)
{ {
VLOG_MINI_2(LOG_LEVEL_FATAL, "read_one_image_from_usb 'total' is %d, 'left' total len is:%d!!!\n", total, r); utils::to_log(LOG_LEVEL_FATAL, "read_one_image_from_usb 'total' is %d, 'left' total len is:%d!!!\n", total, r);
} }
if (ret == SCANNER_ERR_OK) if (ret == SCANNER_ERR_OK)
@ -751,7 +753,7 @@ int hg_scanner_239::read_one_image_from_usb(SANE_Image_Statu statu)
} }
else else
{ {
VLOG_MINI_1(LOG_LEVEL_FATAL, "Read image data from USB err: %s\n", hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_FATAL, "Read image data from USB err: %s\n", hg_scanner_err_name(ret));
} }
} }
} }
@ -804,7 +806,7 @@ int hg_scanner_239::discard_all_images(void)
//} //}
if (pre_int) 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); utils::to_log(LOG_LEVEL_DEBUG, "prev-connection has left %d interrupt packet(s) && %d image(s).\n", pre_int, pre_img);
return 0; return 0;
} }
int hg_scanner_239::get_roller_life(void) int hg_scanner_239::get_roller_life(void)
@ -1106,8 +1108,8 @@ void hg_scanner_239::thread_correction(void)
if (sw.elapsed_s() > 10) if (sw.elapsed_s() > 10)
{ {
status_ = SCANNER_ERR_DEVICE_AUTO_FAIL_OVER; 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); // 通信超时 //notify_ui_working_status(lang_load_string(ID_STATU_DESC_SCANNER_ERR_DEVICE_FAIL_OUTTIME), SANE_EVENT_ERROR, ret); // 通信超时
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "设备校正超时 '%s'\n", hg_scanner_err_name(status_)); utils::to_log(LOG_LEVEL_DEBUG, "设备校正超时 '%s'\n", hg_scanner_err_name(status_));
break; break;
} }
std::this_thread::sleep_for(std::chrono::milliseconds(500)); std::this_thread::sleep_for(std::chrono::milliseconds(500));
@ -1171,7 +1173,7 @@ void hg_scanner_239::thread_get_dves_image(void)
{ {
status_ = ret; status_ = ret;
notify_ui_working_status(from_default_language(STATU_DESC_SCANNER_ERR_DEVICE_GET_IMAGE_OUTTIME), SANE_EVENT_ERROR, 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_)); utils::to_log(LOG_LEVEL_DEBUG, "get image time out:%s\n", hg_scanner_err_name(status_));
break; break;
} }
@ -1179,7 +1181,7 @@ void hg_scanner_239::thread_get_dves_image(void)
{ {
stop(); stop();
notify_ui_working_status(from_default_language(STATU_DESC_SCANNER_ERR_DEVICE_EXIT_WAIT_SCAN), SANE_EVENT_ERROR, status_); 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)); utils::to_log(LOG_LEVEL_DEBUG, "auto paper scan exit :%s\n", from_default_language(STATU_DESC_SCANNER_ERR_DEVICE_EXIT_WAIT_SCAN));
} }
if ((get_status() & 0x03) == 0) if ((get_status() & 0x03) == 0)
@ -1193,7 +1195,7 @@ void hg_scanner_239::thread_get_dves_image(void)
size = sizeof(buf); size = sizeof(buf);
memset(buf, 0, size); memset(buf, 0, size);
info->From = setting3399::STOPSCAN; info->From = setting3399::STOPSCAN;
LOG_INFO(LOG_LEVEL_DEBUG_INFO, "User cancelled (checked when read INT timeout), we faked a 'STOP' messag to enter exiting process ...\n"); utils::log_info("User cancelled (checked when read INT timeout), we faked a 'STOP' messag to enter exiting process ...\n", LOG_LEVEL_DEBUG);
} }
else else
continue; continue;
@ -1211,7 +1213,7 @@ void hg_scanner_239::thread_get_dves_image(void)
status_ = settings::device_status_to_hg_err(info); status_ = settings::device_status_to_hg_err(info);
if (status_) if (status_)
{ {
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "status from interrupt point is '%s'\n", hg_scanner_err_description(status_)); utils::to_log(LOG_LEVEL_DEBUG, "status from interrupt point is '%s'\n", hg_scanner_err_description(status_));
} }
if (status_ != SCANNER_ERR_OK if (status_ != SCANNER_ERR_OK
&& status_ != SCANNER_ERR_TIMEOUT && status_ != SCANNER_ERR_TIMEOUT
@ -1280,7 +1282,7 @@ void hg_scanner_239::thread_get_dves_image(void)
} }
} }
//else //else
// VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "status(0x%x) is not accept in usb thread\n", status); // utils::to_log(LOG_LEVEL_DEBUG, "status(0x%x) is not accept in usb thread\n", status);
} }
else if (info->From == setting3399::STOPSCAN)//固件版本:3B0326获取无纸时下面中断信息会先发无纸在停止扫描,然后在发无纸 else if (info->From == setting3399::STOPSCAN)//固件版本:3B0326获取无纸时下面中断信息会先发无纸在停止扫描,然后在发无纸
{ //此时int端点还要信息没有读取完而且退出点击继续扫描下面设备还未结束扫描 { //此时int端点还要信息没有读取完而且退出点击继续扫描下面设备还未结束扫描
@ -1288,7 +1290,7 @@ void hg_scanner_239::thread_get_dves_image(void)
{ {
status_ = svdevs_err_.front(); status_ = svdevs_err_.front();
} }
LOG_INFO(LOG_LEVEL_DEBUG_INFO, "received 'STOPSCAN' message in usb thread, check remaining image and finish scanning ...\n"); utils::log_info("received 'STOPSCAN' message in usb thread, check remaining image and finish scanning ...\n", LOG_LEVEL_DEBUG);
// fetch all buffered images and exit ... // fetch all buffered images and exit ...
//while(!is_dev_image_process_done()) //while(!is_dev_image_process_done())
@ -1313,7 +1315,7 @@ void hg_scanner_239::thread_get_dves_image(void)
else else
status_ = ret = SCANNER_ERR_USER_CANCELED; 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)); utils::to_log(LOG_LEVEL_DEBUG, "%s\n", lang_load_string(ID_STATU_DESC_SCANNER_ERR_DEVICE_GET_USER_CANCEL_SCAN, nullptr));
auoto_paper_indx = 0; auoto_paper_indx = 0;
break; break;
} }
@ -1321,7 +1323,7 @@ void hg_scanner_239::thread_get_dves_image(void)
{ {
//std::lock_guard<std::mutex> lock(io_lock_); //std::lock_guard<std::mutex> lock(io_lock_);
//LOG_INFO(LOG_LEVEL_DEBUG_INFO, "First message received from USB is 'STOPSCAN'\n"); //utils::log_info(LOG_LEVEL_DEBUG, "First message received from USB is 'STOPSCAN'\n");
// notify_ui_working_status(STATU_DESC_DEVICE_RESET); // notify_ui_working_status(STATU_DESC_DEVICE_RESET);
// reset_ = true; // reset_ = true;
// ret = io_->reset(); // ret = io_->reset();
@ -1334,9 +1336,9 @@ void hg_scanner_239::thread_get_dves_image(void)
if (count == 0 || (s & 3) == 0) if (count == 0 || (s & 3) == 0)
{ {
LOG_INFO(LOG_LEVEL_DEBUG_INFO, "Really stopped ^_^\n"); utils::log_info("Really stopped ^_^\n", LOG_LEVEL_DEBUG);
string str = hg_log::lang_load(ID_STATU_DESC_SCANNER_ERR_DEVICE_ROUND_SACN_OVER); string str = lang_load_string(ID_STATU_DESC_SCANNER_ERR_DEVICE_ROUND_SACN_OVER, nullptr);
str += ":" + to_string(++auoto_paper_indx); str += ":" + to_string(++auoto_paper_indx);
if (!user_cancel_ && is_auto_paper_scan && svdevs_err_.empty()) if (!user_cancel_ && is_auto_paper_scan && svdevs_err_.empty())
@ -1347,7 +1349,7 @@ void hg_scanner_239::thread_get_dves_image(void)
} }
else if (info->From == setting3399::V4L2) 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); utils::to_log(LOG_LEVEL_WARNING, "V4L2 message received, code = %d, index = %d\n", info->Code, info->Img_Index);
// stop(); // stop();
break; break;
} }
@ -1367,14 +1369,14 @@ void hg_scanner_239::thread_get_dves_image(void)
else else
{ {
// error handling ... // 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_)); utils::to_log(LOG_LEVEL_DEBUG, "Read HGEIntInfo: From = %d, Code = %d, Img_Index = %d, status = %s\n", info->From, info->Code, info->Img_Index, hg_scanner_err_description(status_));
} }
} }
this_thread::sleep_for(chrono::milliseconds(10)); this_thread::sleep_for(chrono::milliseconds(10));
} }
// stop 通过int端点返回 如果不反回则是固件问题,软件不做处理 // stop 通过int端点返回 如果不反回则是固件问题,软件不做处理
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_)); utils::to_log(LOG_LEVEL_DEBUG, "USB thread exit with code: %s, status = %s\n", hg_scanner_err_name(ret), hg_scanner_err_description(status_));
} }
void hg_scanner_239::thread_handle_usb_read(void) void hg_scanner_239::thread_handle_usb_read(void)
{ {
@ -1399,7 +1401,7 @@ int hg_scanner_239::start(void)
split3399_ = 0; split3399_ = 0;
cb_mem_ = true; cb_mem_ = true;
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "scanner status: 0x%x\n", get_status()); utils::to_log(LOG_LEVEL_DEBUG, "scanner status: 0x%x\n", get_status());
reset(); reset();
@ -1408,7 +1410,7 @@ int hg_scanner_239::start(void)
if (!val && ret == SCANNER_ERR_OK) if (!val && ret == SCANNER_ERR_OK)
{ {
status_ = SCANNER_ERR_DEVICE_SLEEPING; 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)); utils::to_log(LOG_LEVEL_WARNING, "device start status is(%s)\n", lang_load_string(ID_STATU_DESC_SCANNER_ERR_DEVICE_SLEEPING, nullptr));
set_notify_sleep(); set_notify_sleep();
@ -1437,12 +1439,12 @@ int hg_scanner_239::start(void)
if (ret) 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)); utils::to_log(LOG_LEVEL_WARNING, "Write down image process parameters fail is(%s), the result will be unpredictable.\n", hg_scanner_err_name(ret));
} }
if (ret != SCANNER_ERR_OK) if (ret != SCANNER_ERR_OK)
{ {
VLOG_MINI_1(LOG_LEVEL_WARNING, "start status01 is(%s), the result will be unpredictable.\n", hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_WARNING, "start status01 is(%s), the result will be unpredictable.\n", hg_scanner_err_name(ret));
return ret; return ret;
} }
@ -1466,9 +1468,9 @@ int hg_scanner_239::start(void)
else else
{ {
status_ = ret; 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)); utils::to_log(LOG_LEVEL_WARNING, "(Thread 0x%x)Send start command = %s\n", GetCurrentProcessId(), hg_scanner_err_name(ret));
} }
VLOG_MINI_1(LOG_LEVEL_WARNING, "----------Main start scan status : %s----------\n", hg_scanner_err_description(ret)); utils::to_log(LOG_LEVEL_WARNING, "----------Main start scan status : %s----------\n", hg_scanner_err_description(ret));
return ret; return ret;
} }
@ -1675,7 +1677,7 @@ int hg_scanner_239::get_sleep_time(int& data)
data = val; data = val;
} }
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "get_sleep_time = %d with %s\n", data,hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_DEBUG, "get_sleep_time = %d with %s\n", data,hg_scanner_err_name(ret));
return ret; return ret;
} }
int hg_scanner_239::set_sleep_time(int setsleepime) int hg_scanner_239::set_sleep_time(int setsleepime)
@ -1684,7 +1686,7 @@ int hg_scanner_239::set_sleep_time(int setsleepime)
int ret = write_register(setting3399::SR_SET_SLEEPTIME, setsleepime); int ret = write_register(setting3399::SR_SET_SLEEPTIME, setsleepime);
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "set sleep time to %d = %s\n", setsleepime, hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_DEBUG, "set sleep time to %d = %s\n", setsleepime, hg_scanner_err_name(ret));
return ret; return ret;
} }
@ -1700,7 +1702,7 @@ int hg_scanner_239::get_scanner_paperon(SANE_Bool& type)
{ {
type = val == 0 ? false : true; type = val == 0 ? false : true;
} }
VLOG_MINI_1(LOG_LEVEL_WARNING, "get_scanner_paperon is(%s)\n", !type ? hg_scanner_err_description(SCANNER_ERR_DEVICE_NO_PAPER) : hg_scanner_err_description(SCANNER_ERR_OK)); utils::to_log(LOG_LEVEL_WARNING, "get_scanner_paperon is(%s)\n", !type ? hg_scanner_err_description(SCANNER_ERR_DEVICE_NO_PAPER) : hg_scanner_err_description(SCANNER_ERR_OK));
return ret; return ret;
} }
@ -1715,7 +1717,7 @@ int hg_scanner_239::get_scan_is_sleep(SANE_Bool& type)
{ {
type = val == 1 ? true : false; type = val == 1 ? true : false;
} }
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)); utils::to_log(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));
return ret; return ret;
} }
@ -1745,7 +1747,7 @@ int hg_scanner_239::get_device_log(string &logpath)
} }
std::lock_guard<std::mutex> lock(io_lock_); std::lock_guard<std::mutex> lock(io_lock_);
string save_path = hg_log::temporary_path() + PATH_SEPARATOR + "device.log"; string save_path = utils::temporary_path() + PATH_SEPARATOR + "device.log";
string device_log_path = "/var/log/syslog"; string device_log_path = "/var/log/syslog";
string str ; string str ;
@ -1801,7 +1803,7 @@ int hg_scanner_239::get_device_log(string &logpath)
f << str << endl; f << str << endl;
f.close(); f.close();
logpath = save_path; logpath = save_path;
VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "log path:%s ret:%s buffersize: %d\n", logpath.c_str(),hg_scanner_err_name(ret),buffersize); utils::to_log(LOG_LEVEL_DEBUG, "log path:%s ret:%s buffersize: %d\n", logpath.c_str(),hg_scanner_err_name(ret),buffersize);
return ret; return ret;
} }
int hg_scanner_239::set_devreboot(int data) int hg_scanner_239::set_devreboot(int data)
@ -1826,19 +1828,19 @@ int hg_scanner_239::set_scan_islock(SANE_Bool set_islock)
if (!firmware_sup_devs_lock_) if (!firmware_sup_devs_lock_)
{ {
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "devs lock:%s \n", hg_scanner_err_description(SCANNER_ERR_DEVICE_NOT_SUPPORT)); utils::to_log(LOG_LEVEL_DEBUG, "devs lock:%s \n", hg_scanner_err_description(SCANNER_ERR_DEVICE_NOT_SUPPORT));
return SCANNER_ERR_DEVICE_NOT_SUPPORT; return SCANNER_ERR_DEVICE_NOT_SUPPORT;
} }
if (set_islock != 0 && set_islock != 1) if (set_islock != 0 && set_islock != 1)
{ {
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "devs lock:%s \n", hg_scanner_err_description(SCANNER_ERR_INVALID_PARAMETER)); utils::to_log(LOG_LEVEL_DEBUG, "devs lock:%s \n", hg_scanner_err_description(SCANNER_ERR_INVALID_PARAMETER));
return SCANNER_ERR_INVALID_PARAMETER; return SCANNER_ERR_INVALID_PARAMETER;
} }
int val = 0, int val = 0,
ret = write_register(setting3399::SR_SET_LOCK_STATES, set_islock); ret = write_register(setting3399::SR_SET_LOCK_STATES, set_islock);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Set scanner is lock:%d\r\n", set_islock); utils::to_log(LOG_LEVEL_DEBUG, "Set scanner is lock:%d\r\n", set_islock);
return ret; return ret;
} }
@ -1848,7 +1850,7 @@ int hg_scanner_239::get_scan_islock(SANE_Bool& islock)
if (!firmware_sup_devs_lock_) if (!firmware_sup_devs_lock_)
{ {
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "devs lock:%s \n", hg_scanner_err_description(SCANNER_ERR_DEVICE_NOT_SUPPORT)); utils::to_log(LOG_LEVEL_DEBUG, "devs lock:%s \n", hg_scanner_err_description(SCANNER_ERR_DEVICE_NOT_SUPPORT));
return SCANNER_ERR_DEVICE_NOT_SUPPORT; return SCANNER_ERR_DEVICE_NOT_SUPPORT;
} }
@ -1861,14 +1863,14 @@ int hg_scanner_239::get_scan_islock(SANE_Bool& islock)
islock = val; islock = val;
ret = islock ? SCANNER_ERR_DEVICE_ISLOCK : SCANNER_ERR_OK; ret = islock ? SCANNER_ERR_DEVICE_ISLOCK : SCANNER_ERR_OK;
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Get scanner is lock:%d\r\n", ret); utils::to_log(LOG_LEVEL_DEBUG, "Get scanner is lock:%d\r\n", ret);
return ret; return ret;
} }
int hg_scanner_239::set_scan_lock_check_val(string check_str) int hg_scanner_239::set_scan_lock_check_val(string check_str)
{ {
if (!firmware_sup_devs_lock_) if (!firmware_sup_devs_lock_)
{ {
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "devs lock:%s \n", hg_scanner_err_description(SCANNER_ERR_DEVICE_NOT_SUPPORT)); utils::to_log(LOG_LEVEL_DEBUG, "devs lock:%s \n", hg_scanner_err_description(SCANNER_ERR_DEVICE_NOT_SUPPORT));
return SCANNER_ERR_DEVICE_NOT_SUPPORT; return SCANNER_ERR_DEVICE_NOT_SUPPORT;
} }
@ -2022,7 +2024,7 @@ int hg_scanner_239::get_dev_islock_file(int& islockfile)
if (!firmware_sup_devs_lock_) if (!firmware_sup_devs_lock_)
{ {
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "devs lock:%s \n", hg_scanner_err_description(SCANNER_ERR_DEVICE_NOT_SUPPORT)); utils::to_log(LOG_LEVEL_DEBUG, "devs lock:%s \n", hg_scanner_err_description(SCANNER_ERR_DEVICE_NOT_SUPPORT));
return SCANNER_ERR_DEVICE_NOT_SUPPORT; return SCANNER_ERR_DEVICE_NOT_SUPPORT;
} }
@ -2054,7 +2056,7 @@ int hg_scanner_239::get_dev_islock_file(int& islockfile)
else else
islockfile = -1; islockfile = -1;
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); utils::to_log(LOG_LEVEL_DEBUG, "get list file is:%s ret:%s buffersize: %d\n", device_log_path.c_str(), hg_scanner_err_description(ret), buffersize);
return ret; return ret;
} }
int hg_scanner_239::set_dev_islock_file(int islockfile) int hg_scanner_239::set_dev_islock_file(int islockfile)
@ -2063,7 +2065,7 @@ int hg_scanner_239::set_dev_islock_file(int islockfile)
if (!firmware_sup_devs_lock_) if (!firmware_sup_devs_lock_)
{ {
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "devs lock:%s \n", hg_scanner_err_description(SCANNER_ERR_DEVICE_NOT_SUPPORT)); utils::to_log(LOG_LEVEL_DEBUG, "devs lock:%s \n", hg_scanner_err_description(SCANNER_ERR_DEVICE_NOT_SUPPORT));
return SCANNER_ERR_DEVICE_NOT_SUPPORT; return SCANNER_ERR_DEVICE_NOT_SUPPORT;
} }
if (islockfile != 0 && islockfile != 1) if (islockfile != 0 && islockfile != 1)
@ -2095,7 +2097,7 @@ int hg_scanner_239::set_dev_islock_file(int islockfile)
if (ret != SCANNER_ERR_OK) if (ret != SCANNER_ERR_OK)
return ret; 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); //utils::to_log(LOG_LEVEL_DEBUG, "log path:%s ret:%s buffersize: %d\n", logpath.c_str(), hg_scanner_err_name(ret), buffersize);
//return ret; //return ret;
return SCANNER_ERR_OK; return SCANNER_ERR_OK;
} }

View File

@ -1,5 +1,7 @@
#include "hg_scanner_300.h" #include "hg_scanner_300.h"
#include "../wrapper/hg_log.h"
#include "../../sdk/hginclude/utils.h"
#include <lang/app_language.h>
#if defined(WIN32) || defined(_WIN64) #if defined(WIN32) || defined(_WIN64)
#include "scanner_manager.h" #include "scanner_manager.h"
@ -117,7 +119,7 @@ void hg_scanner_300::thread_handle_usb_read(void)
ret = get_scanner_status(usb); ret = get_scanner_status(usb);
if (ret && ret != SCANNER_ERR_NO_DATA) if (ret && ret != SCANNER_ERR_NO_DATA)
{ {
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "status from bulk point is '%s'\n", hg_scanner_err_description(ret)); utils::to_log(LOG_LEVEL_DEBUG, "status from bulk point is '%s'\n", hg_scanner_err_description(ret));
} }
//printf("usb.u32_Data = %d ret = %d\r\n",usb.u32_Data,ret); //printf("usb.u32_Data = %d ret = %d\r\n",usb.u32_Data,ret);
@ -133,9 +135,9 @@ void hg_scanner_300::thread_handle_usb_read(void)
ret = status_; ret = status_;
else else
status_ = ret = SCANNER_ERR_USER_CANCELED; status_ = ret = SCANNER_ERR_USER_CANCELED;
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "%s\n", hg_scanner_err_description(status_)); utils::to_log(LOG_LEVEL_DEBUG, "%s\n", hg_scanner_err_description(status_));
} }
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "'STOPSCAN' message in usb thread:%s\n" , hg_scanner_err_description(status_)); utils::to_log(LOG_LEVEL_DEBUG, "'STOPSCAN' message in usb thread:%s\n" , hg_scanner_err_description(status_));
break; break;
} }
@ -199,14 +201,14 @@ void hg_scanner_300::thread_handle_usb_read(void)
else if (ret == SCANNER_ERR_IO) else if (ret == SCANNER_ERR_IO)
{ {
status_ = ret; status_ = ret;
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "%s\n", hg_scanner_err_description(status_)); utils::to_log(LOG_LEVEL_DEBUG, "%s\n", hg_scanner_err_description(status_));
break; break;
} }
if (sw.elapsed_ms() > 30000 && img_conf_.resolution_dst != 600)//防止状态信息一直取不上来导致卡死 if (sw.elapsed_ms() > 30000 && img_conf_.resolution_dst != 600)//防止状态信息一直取不上来导致卡死
{ {
if ((img_conf_.papertype == TwSS::MaxSize || img_conf_.papertype == TwSS::USStatement) && pid_ == 0x0300 && firmware_sup_dpi_600) if ((img_conf_.papertype == TwSS::MaxSize || img_conf_.papertype == TwSS::USStatement) && pid_ == 0x0300 && firmware_sup_dpi_600)
{ {
hg_log::log(LOG_LEVEL_WARNING, "while 30S\n"); utils::log_info("while 30S\n", LOG_LEVEL_WARNING);
} }
else else
{ {
@ -215,8 +217,8 @@ void hg_scanner_300::thread_handle_usb_read(void)
status_ = savestatus_[0]; status_ = savestatus_[0];
} }
savestatus_.clear(); savestatus_.clear();
hg_log::log(LOG_LEVEL_WARNING, "Get Status TimeOut,get image out 30S\n"); utils::log_info("Get Status TimeOut,get image out 30S\n", LOG_LEVEL_WARNING);
notify_ui_working_status(hg_log::lang_load(ID_STATU_DESC_SCANNER_ERR_DEVICE_GET_IMAGE_OUTTIME), SANE_EVENT_ERROR, status_); // 取图通信超时 notify_ui_working_status(lang_load_string(ID_STATU_DESC_SCANNER_ERR_DEVICE_GET_IMAGE_OUTTIME, nullptr), SANE_EVENT_ERROR, status_); // 取图通信超时
break; break;
} }
} }
@ -227,14 +229,14 @@ void hg_scanner_300::thread_handle_usb_read(void)
status_ = savestatus_[0]; status_ = savestatus_[0];
} }
savestatus_.clear(); savestatus_.clear();
hg_log::log(LOG_LEVEL_WARNING, "MaxSize TimeOut,Get Image 130s\n"); utils::log_info("MaxSize TimeOut,Get Image 130s\n", LOG_LEVEL_WARNING);
notify_ui_working_status(hg_log::lang_load(ID_STATU_DESC_SCANNER_ERR_DEVICE_GET_IMAGE_OUTTIME), SANE_EVENT_ERROR, status_); // 取图通信超时 notify_ui_working_status(lang_load_string(ID_STATU_DESC_SCANNER_ERR_DEVICE_GET_IMAGE_OUTTIME, nullptr), SANE_EVENT_ERROR, status_); // 取图通信超时
break; break;
} }
if (ret == SCANNER_ERR_OK && usb.u32_Count > 0) if (ret == SCANNER_ERR_OK && usb.u32_Count > 0)
{ {
int totalNum = usb.u32_Count & 0x3fffffff; // 2022-08-04: 兼容Android默认图片大小均在1GB以内 int totalNum = usb.u32_Count & 0x3fffffff; // 2022-08-04: 兼容Android默认图片大小均在1GB以内
VLOG_MINI_2(LOG_LEVEL_WARNING, "Get Scaner Image Size:%d bytes,Image Num[%d]\n", totalNum,img_num); utils::to_log(LOG_LEVEL_WARNING, "Get Scaner Image Size:%d bytes,Image Num[%d]\n", totalNum,img_num);
img_num++; img_num++;
if (totalNum) if (totalNum)
{ {
@ -269,7 +271,7 @@ void hg_scanner_300::thread_handle_usb_read(void)
} }
this_thread::sleep_for(chrono::milliseconds(10)); 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_description(status_)); utils::to_log(LOG_LEVEL_DEBUG, "USB thread exit with code: %s, status = %s\n", hg_scanner_err_name(ret), hg_scanner_err_description(status_));
} }
int hg_scanner_300::discard_all_images(void) int hg_scanner_300::discard_all_images(void)
{ {
@ -322,7 +324,7 @@ int hg_scanner_300::start(void)
//if (is_read_int) //if (is_read_int)
//{ //{
// VLOG_MINI_1(LOG_LEVEL_WARNING, "device status is(%s)\n", STATU_DESC_SCANNER_ERR_DEVICE_DEVS_BOOTING); // utils::to_log(LOG_LEVEL_WARNING, "device status is(%s)\n", STATU_DESC_SCANNER_ERR_DEVICE_DEVS_BOOTING);
// return SCANNER_ERR_DEVICE_DEVS_BOOTING; // return SCANNER_ERR_DEVICE_DEVS_BOOTING;
//} //}
ret = get_scan_is_sleep(val); ret = get_scan_is_sleep(val);
@ -375,7 +377,7 @@ int hg_scanner_300::start(void)
} }
else else
status_ = ret; status_ = ret;
VLOG_MINI_1(LOG_LEVEL_WARNING, "----------Main start scan status : %s----------\n", hg_scanner_err_description(ret)); utils::to_log(LOG_LEVEL_WARNING, "----------Main start scan status : %s----------\n", hg_scanner_err_description(ret));
return ret; return ret;
} }
int hg_scanner_300::stop(void) int hg_scanner_300::stop(void)
@ -390,7 +392,7 @@ int hg_scanner_300::stop(void)
if (status_ == SCANNER_ERR_DEVICE_BUSY) if (status_ == SCANNER_ERR_DEVICE_BUSY)
{ {
LOG_INFO(LOG_LEVEL_DEBUG_INFO,"stop status is busy\r\n"); utils::log_info("stop status is busy\r\n", LOG_LEVEL_DEBUG);
std::this_thread::sleep_for(std::chrono::milliseconds(2000)); std::this_thread::sleep_for(std::chrono::milliseconds(2000));
} }
user_cancel_ = true; user_cancel_ = true;
@ -450,14 +452,14 @@ int hg_scanner_300::get_scanner_status(USBCB &usb)
ret = writeusb(usb); ret = writeusb(usb);
if (ret != SCANNER_ERR_OK) if (ret != SCANNER_ERR_OK)
{ {
VLOG_MINI_1(LOG_LEVEL_WARNING, "get_scanner_status write usb: %s\n", hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_WARNING, "get_scanner_status write usb: %s\n", hg_scanner_err_name(ret));
return ret; return ret;
} }
ret = readusb(usb); ret = readusb(usb);
if (ret != SCANNER_ERR_OK) if (ret != SCANNER_ERR_OK)
{ {
VLOG_MINI_1(LOG_LEVEL_WARNING, "get_scanner_status read usb: %s\n", hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_WARNING, "get_scanner_status read usb: %s\n", hg_scanner_err_name(ret));
status_ = ret; status_ = ret;
return ret; return ret;
} }
@ -477,11 +479,11 @@ int hg_scanner_300::get_img_data(std::shared_ptr<tiny_buffer> &imagedata)
ret = writeusb(usb); ret = writeusb(usb);
if (ret != SCANNER_ERR_OK) if (ret != SCANNER_ERR_OK)
{ {
VLOG_MINI_1(LOG_LEVEL_WARNING, "get_img_data setting3288dsp::GET_IMAGE write usb: %s\n", hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_WARNING, "get_img_data setting3288dsp::GET_IMAGE write usb: %s\n", hg_scanner_err_name(ret));
} }
else else
{ {
VLOG_MINI_1(LOG_LEVEL_FATAL, "get_img_data get data total len is:%d\n", total); utils::to_log(LOG_LEVEL_FATAL, "get_img_data get data total len is:%d\n", total);
while (total > 0) while (total > 0)
{ {
block = 512 * 1024; block = 512 * 1024;
@ -493,7 +495,7 @@ int hg_scanner_300::get_img_data(std::shared_ptr<tiny_buffer> &imagedata)
void* buf = imagedata->data(index, &size); void* buf = imagedata->data(index, &size);
if (!buf) if (!buf)
{ {
VLOG_MINI_3(LOG_LEVEL_FATAL, "memory(0x%08x + %u) fatal when read USB image %d !!!\n", index, block, usb_img_index_); utils::to_log(LOG_LEVEL_FATAL, "memory(0x%08x + %u) fatal when read USB image %d !!!\n", index, block, usb_img_index_);
ret = SCANNER_ERR_INSUFFICIENT_MEMORY; ret = SCANNER_ERR_INSUFFICIENT_MEMORY;
break; break;
} }
@ -502,12 +504,12 @@ int hg_scanner_300::get_img_data(std::shared_ptr<tiny_buffer> &imagedata)
if (ret != SCANNER_ERR_OK && ret != SCANNER_ERR_TIMEOUT) if (ret != SCANNER_ERR_OK && ret != SCANNER_ERR_TIMEOUT)
{ {
VLOG_MINI_1(LOG_LEVEL_FATAL, "get_img_data read_data:%s!!! \n", hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_FATAL, "get_img_data read_data:%s!!! \n", hg_scanner_err_name(ret));
break; break;
} }
else if (ret == SCANNER_ERR_TIMEOUT && io_->get_timeout() > 3000) else if (ret == SCANNER_ERR_TIMEOUT && io_->get_timeout() > 3000)
{ {
VLOG_MINI_2(LOG_LEVEL_FATAL, "get_img_data read_data:%s!!! ,get_timeout is %d\n", hg_scanner_err_name(ret), io_->get_timeout()); utils::to_log(LOG_LEVEL_FATAL, "get_img_data read_data:%s!!! ,get_timeout is %d\n", hg_scanner_err_name(ret), io_->get_timeout());
break; break;
} }
@ -522,7 +524,7 @@ int hg_scanner_300::get_img_data(std::shared_ptr<tiny_buffer> &imagedata)
} }
else else
{ {
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Read image data from USB err: %s\n", hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_DEBUG, "Read image data from USB err: %s\n", hg_scanner_err_name(ret));
stop(); stop();
string str = STATU_DESC_SCANNER_ERR_DEVICE_GET_IMAGE_ERR; string str = STATU_DESC_SCANNER_ERR_DEVICE_GET_IMAGE_ERR;
str = str + '-' + STATU_DESC_SCANNER_ERR_DEVICE_STOPPED; str = str + '-' + STATU_DESC_SCANNER_ERR_DEVICE_STOPPED;
@ -562,7 +564,7 @@ int hg_scanner_300::writedown_device_configuration(bool type,setting_hardware::H
if ((is_quality_ == IMG_SPEED) && (resolution_ >= 300)) if ((is_quality_ == IMG_SPEED) && (resolution_ >= 300))
{ {
VLOG_MINI_1(LOG_LEVEL_WARNING, "writedown_device_configuration is_quality_ is .(%d)\n", is_quality_) utils::to_log(LOG_LEVEL_WARNING, "writedown_device_configuration is_quality_ is .(%d)\n", is_quality_);
d->params_3288.dpi = 1; d->params_3288.dpi = 1;
} }
if (image_prc_param_.bits.paper == PAPER_AUTO_MATCH if (image_prc_param_.bits.paper == PAPER_AUTO_MATCH
@ -589,7 +591,7 @@ int hg_scanner_300::writedown_device_configuration(bool type,setting_hardware::H
{ {
printf_devconfig(d); printf_devconfig(d);
} }
VLOG_MINI_1(LOG_LEVEL_WARNING, "writedown_device_configuration is .(%s)\n", hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_WARNING, "writedown_device_configuration is .(%s)\n", hg_scanner_err_name(ret));
return ret; return ret;
} }
@ -660,7 +662,7 @@ int hg_scanner_300::on_resolution_changed(int& dpi)
else else
dsp_config.params_3288.dpi = 1; dsp_config.params_3288.dpi = 1;
VLOG_MINI_3(LOG_LEVEL_WARNING, "on_resolution_changed is dpi:%d .set device dpi(%d),firmware_sup_dpi_300 is :%d\n", dpi, dsp_config.params_3288.dpi, firmware_sup_dpi_300); utils::to_log(LOG_LEVEL_WARNING, "on_resolution_changed is dpi:%d .set device dpi(%d),firmware_sup_dpi_300 is :%d\n", dpi, dsp_config.params_3288.dpi, firmware_sup_dpi_300);
ret = writedown_device_configuration(); ret = writedown_device_configuration();
return ret; return ret;
@ -704,7 +706,7 @@ int hg_scanner_300::set_kernelsnap_ver()
ret = SCANNER_ERR_NO_DATA; ret = SCANNER_ERR_NO_DATA;
} }
VLOG_MINI_2(LOG_LEVEL_WARNING, "hg_scanner_300 firmware_sup_dpi_300 :%d ,firmware_sup_dpi_600:%d\n", firmware_sup_dpi_300, firmware_sup_dpi_600); utils::to_log(LOG_LEVEL_WARNING, "hg_scanner_300 firmware_sup_dpi_300 :%d ,firmware_sup_dpi_600:%d\n", firmware_sup_dpi_300, firmware_sup_dpi_600);
return SCANNER_ERR_OK; return SCANNER_ERR_OK;
} }
int hg_scanner_300::agreement(TwSS tw,int align) int hg_scanner_300::agreement(TwSS tw,int align)
@ -737,8 +739,11 @@ int hg_scanner_300::initdevice()
{ {
if (fw.substr(4, 6) == "230303") if (fw.substr(4, 6) == "230303")
{ {
string scanner_path = hg_log::get_module_full_path(LIBNAME); string scanner_path(utils::get_module_full_path(SCANNER_DRIVER_PART_NAME));
scanner_path = scanner_path.substr(0, scanner_path.size() - strlen(LIBNAME)); size_t pos = scanner_path.rfind(PATH_SEPARATOR[0]);
if(pos++ == std::string::npos)
pos = 0;
scanner_path.erase(pos);
scanner_path += "update.zip"; scanner_path += "update.zip";
set_firmware_upgrade(scanner_path); set_firmware_upgrade(scanner_path);
return SCANNER_ERR_OK; return SCANNER_ERR_OK;
@ -767,7 +772,7 @@ void hg_scanner_300::writedown_image_configuration(void)
ic.imageRotateDegree = 0; ic.imageRotateDegree = 0;
if (test_1_paper_) if (test_1_paper_)
{ {
LOG_INFO(LOG_LEVEL_DEBUG_INFO, "scanning mode: testing ONE paper ...\n"); utils::log_info("scanning mode: testing ONE paper ...\n", LOG_LEVEL_DEBUG);
ic.scannum = 1; ic.scannum = 1;
} }
else else
@ -788,18 +793,18 @@ void hg_scanner_300::printf_devconfig(setting_hardware::HGSCANCONF_3288 *d)
if (!d) if (!d)
d = &dsp_config; d = &dsp_config;
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"dsp_config.params_3288.doubleFeeded:%d\r\n",d->params_3288.doubleFeeded); utils::to_log(LOG_LEVEL_DEBUG,"dsp_config.params_3288.doubleFeeded:%d\r\n",d->params_3288.doubleFeeded);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"dsp_config.params_3288.dpi:%d\r\n",d->params_3288.dpi); utils::to_log(LOG_LEVEL_DEBUG,"dsp_config.params_3288.dpi:%d\r\n",d->params_3288.dpi);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"dsp_config.params_3288.dstHeight:%d\r\n",d->params_3288.dstHeight); utils::to_log(LOG_LEVEL_DEBUG,"dsp_config.params_3288.dstHeight:%d\r\n",d->params_3288.dstHeight);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"dsp_config.params_3288.enableLed:%d\r\n",d->params_3288.enableLed); utils::to_log(LOG_LEVEL_DEBUG,"dsp_config.params_3288.enableLed:%d\r\n",d->params_3288.enableLed);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"dsp_config.params_3288.enableStable:%d\r\n",d->params_3288.enableStable); utils::to_log(LOG_LEVEL_DEBUG,"dsp_config.params_3288.enableStable:%d\r\n",d->params_3288.enableStable);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"dsp_config.params_3288.isColor:%d\r\n",d->params_3288.isColor); utils::to_log(LOG_LEVEL_DEBUG,"dsp_config.params_3288.isColor:%d\r\n",d->params_3288.isColor);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"dsp_config.params_3288.isCorrect:%d\r\n",d->params_3288.isCorrect); utils::to_log(LOG_LEVEL_DEBUG,"dsp_config.params_3288.isCorrect:%d\r\n",d->params_3288.isCorrect);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"dsp_config.params_3288.pageSize:%d\r\n",d->params_3288.pageSize); utils::to_log(LOG_LEVEL_DEBUG,"dsp_config.params_3288.pageSize:%d\r\n",d->params_3288.pageSize);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"dsp_config.params_3288.reversed1:%d\r\n",d->params_3288.reversed1); utils::to_log(LOG_LEVEL_DEBUG,"dsp_config.params_3288.reversed1:%d\r\n",d->params_3288.reversed1);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"dsp_config.params_3288.reversed2:%d\r\n",d->params_3288.reversed2); utils::to_log(LOG_LEVEL_DEBUG,"dsp_config.params_3288.reversed2:%d\r\n",d->params_3288.reversed2);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"dsp_config.params_3288.enableSizeDetect:%d\r\n",d->params_3288.enableSizeDetect); utils::to_log(LOG_LEVEL_DEBUG,"dsp_config.params_3288.enableSizeDetect:%d\r\n",d->params_3288.enableSizeDetect);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"dsp_config.params_3288.value:%d\r\n",d->value); utils::to_log(LOG_LEVEL_DEBUG,"dsp_config.params_3288.value:%d\r\n",d->value);
} }
std::string hg_scanner_300::get_firmware_version() std::string hg_scanner_300::get_firmware_version()
{ {
@ -815,7 +820,7 @@ std::string hg_scanner_300::get_firmware_version()
ret = io_->read_bulk(buf, &len); ret = io_->read_bulk(buf, &len);
} }
string fw = buf; string fw = buf;
VLOG_MINI_1(LOG_LEVEL_WARNING, "get_firmware_version:%s\n", !fw.empty() ? fw.c_str() : "not find devs firmware_version"); utils::to_log(LOG_LEVEL_WARNING, "get_firmware_version:%s\n", !fw.empty() ? fw.c_str() : "not find devs firmware_version");
return buf; return buf;
} }
@ -834,7 +839,7 @@ std::string hg_scanner_300::get_firmware_version()
ret = io_->read_bulk(&SerialNum[0], &len); ret = io_->read_bulk(&SerialNum[0], &len);
} }
VLOG_MINI_1(LOG_LEVEL_WARNING, "get_serial_num:%s\n", !SerialNum.empty() ? SerialNum.c_str() : "not find devs get_serial_num"); utils::to_log(LOG_LEVEL_WARNING, "get_serial_num:%s\n", !SerialNum.empty() ? SerialNum.c_str() : "not find devs get_serial_num");
return SerialNum; return SerialNum;
} }
std::string hg_scanner_300::get_ip(void) std::string hg_scanner_300::get_ip(void)
@ -891,7 +896,7 @@ int hg_scanner_300::get_sleep_time(int &data)
{ {
data = (SANE_Power)usbcb.u32_Data; data = (SANE_Power)usbcb.u32_Data;
} }
VLOG_MINI_1(LOG_LEVEL_WARNING, "get_sleep_time:%d\n", data); utils::to_log(LOG_LEVEL_WARNING, "get_sleep_time:%d\n", data);
return ret; return ret;
} }
int hg_scanner_300::set_sleep_time(int data) int hg_scanner_300::set_sleep_time(int data)
@ -924,7 +929,7 @@ int hg_scanner_300::get_scanner_paperon(SANE_Bool& type)
// ret = SCANNER_ERR_DEVICE_NO_PAPER; // ret = SCANNER_ERR_DEVICE_NO_PAPER;
//else //else
// ret = SCANNER_ERR_OK; // ret = SCANNER_ERR_OK;
VLOG_MINI_1(LOG_LEVEL_WARNING, "get_scanner_paperon is(%s)\n", !type ? hg_scanner_err_description(SCANNER_ERR_DEVICE_NO_PAPER) : hg_scanner_err_description(SCANNER_ERR_OK)); utils::to_log(LOG_LEVEL_WARNING, "get_scanner_paperon is(%s)\n", !type ? hg_scanner_err_description(SCANNER_ERR_DEVICE_NO_PAPER) : hg_scanner_err_description(SCANNER_ERR_OK));
return ret; return ret;
} }
@ -953,7 +958,7 @@ int hg_scanner_300::get_scan_is_sleep(SANE_Bool& type)
type = false; type = false;
//return SCANNER_ERR_DEVICE_SLEEPING; //return SCANNER_ERR_DEVICE_SLEEPING;
} }
VLOG_MINI_1(LOG_LEVEL_WARNING, "get_scan_is_sleep is(%s)\n", !type ? hg_scanner_err_description(SCANNER_ERR_DEVICE_SLEEPING) : hg_scanner_err_description(SCANNER_ERR_OK)); utils::to_log(LOG_LEVEL_WARNING, "get_scan_is_sleep is(%s)\n", !type ? hg_scanner_err_description(SCANNER_ERR_DEVICE_SLEEPING) : hg_scanner_err_description(SCANNER_ERR_OK));
return ret; return ret;
} }
///此款设备无此功能 ///此款设备无此功能
@ -1101,12 +1106,12 @@ int hg_scanner_300::set_firmware_upgrade(std::string str)
if (ret != SCANNER_ERR_OK) if (ret != SCANNER_ERR_OK)
{ {
VLOG_MINI_1(LOG_LEVEL_WARNING, "updata result read_bulk:%s\n", hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_WARNING, "updata result read_bulk:%s\n", hg_scanner_err_name(ret));
//return ret; //return ret;
} }
if (result.u32_Data == 2 || result.u32_Data == 3) if (result.u32_Data == 2 || result.u32_Data == 3)
{ {
VLOG_MINI_1(LOG_LEVEL_WARNING, "updata result:%d\n", result.u32_Data); utils::to_log(LOG_LEVEL_WARNING, "updata result:%d\n", result.u32_Data);
break; break;
} }
} }
@ -1163,7 +1168,7 @@ int hg_scanner_300::set_devs_distortion_check_val(float data)
USBCB usbcb = { setting3288dsp::SET_JUST_COF_V ,val,protocol_dpi }; USBCB usbcb = { setting3288dsp::SET_JUST_COF_V ,val,protocol_dpi };
len = sizeof(usbcb); len = sizeof(usbcb);
float f = *(float*)&(val); float f = *(float*)&(val);
VLOG_MINI_3(LOG_LEVEL_WARNING, "set_devs_distortion_check_val dpi is:%d,config dpi = %d,distortion_check_val(%f)\n", resolution_, protocol_dpi,f); utils::to_log(LOG_LEVEL_WARNING, "set_devs_distortion_check_val dpi is:%d,config dpi = %d,distortion_check_val(%f)\n", resolution_, protocol_dpi,f);
io_->set_timeout(5000); io_->set_timeout(5000);
{ {
std::lock_guard<std::mutex> lock(io_lock_); std::lock_guard<std::mutex> lock(io_lock_);
@ -1200,7 +1205,7 @@ int hg_scanner_300::get_devs_distortion_check_val(float& data)
val = usbcb.u32_Data; val = usbcb.u32_Data;
data = *(float *) &val; data = *(float *) &val;
VLOG_MINI_3(LOG_LEVEL_WARNING, "get_distortion_check_val dpi is:%d,protocol_dpi = %d get_distortion_check_val(%f)\n", resolution_, protocol_dpi, data); utils::to_log(LOG_LEVEL_WARNING, "get_distortion_check_val dpi is:%d,protocol_dpi = %d get_distortion_check_val(%f)\n", resolution_, protocol_dpi, data);
return ret; return ret;
} }
int hg_scanner_300::set_auto_flat(int data) int hg_scanner_300::set_auto_flat(int data)
@ -1227,7 +1232,7 @@ int hg_scanner_300::set_auto_flat(int data)
} }
else else
status_ = ret; status_ = ret;
VLOG_MINI_1(LOG_LEVEL_WARNING, "set_auto_flat ret: %s\n", hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_WARNING, "set_auto_flat ret: %s\n", hg_scanner_err_name(ret));
return ret; return ret;
} }
int hg_scanner_300::set_updata0303(void) int hg_scanner_300::set_updata0303(void)
@ -1237,8 +1242,11 @@ int hg_scanner_300::set_updata0303(void)
{ {
if (fw.substr(4, 6) == "230303") if (fw.substr(4, 6) == "230303")
{ {
string scanner_path = hg_log::get_module_full_path(LIBNAME); string scanner_path = utils::get_module_full_path(SCANNER_DRIVER_PART_NAME);
scanner_path = scanner_path.substr(0, scanner_path.size() - strlen(LIBNAME)); size_t pos = scanner_path.rfind(PATH_SEPARATOR[0]);
if(pos++ == std::string::npos)
pos = 0;
scanner_path.erase(pos);
scanner_path += "update.zip"; scanner_path += "update.zip";
set_firmware_upgrade(scanner_path); set_firmware_upgrade(scanner_path);
} }

View File

@ -10,7 +10,6 @@
#include <algorithm> #include <algorithm>
#include "hg_scanner.h" #include "hg_scanner.h"
#include "../wrapper/hg_log.h"
#include "PaperSize.h" #include "PaperSize.h"
//#ifdef OEM_HANWANG //#ifdef OEM_HANWANG

View File

@ -1,5 +1,7 @@
#include "hg_scanner_302.h" #include "hg_scanner_302.h"
#include "../wrapper/hg_log.h"
#include "../../sdk/hginclude/utils.h"
#include <lang/app_language.h>
#include "filetools.h" #include "filetools.h"
#if defined(WIN32) || defined(_WIN64) #if defined(WIN32) || defined(_WIN64)
@ -163,7 +165,7 @@ namespace settings302
// *r = true; // *r = true;
// else // else
// *r = false; // *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_3399[ind].dev_value); // utils::to_log(LOG_LEVEL_DEBUG, "Paper '%s' index = %d, device value = %d\n", paper_string(paper).c_str(), ind, paper_map_3399[ind].dev_value);
// paper = paper_map_3399[ind].paper; // paper = paper_map_3399[ind].paper;
// if (type) // if (type)
// *type = paper_map_3399[ind].type; // *type = paper_map_3399[ind].type;
@ -178,7 +180,7 @@ hg_scanner_302::hg_scanner_302(const char* dev_name, int pid, usb_io* io) : hg_s
, rewrite_conf_(false), reset_(false) , rewrite_conf_(false), reset_(false)
{ {
//pid_ = pid; //pid_ = pid;
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "hg_scanner_302(%s) constructing ...\n", hg_log::format_ptr(this).c_str()); utils::to_log(LOG_LEVEL_DEBUG, "hg_scanner_302(%p) constructing ...\n", this);
dev_conf_.value = 0; dev_conf_.value = 0;
#ifndef MAPPING_FUNCTION_IN_BASE #ifndef MAPPING_FUNCTION_IN_BASE
init_setting_map(setting_map_, ARRAY_SIZE(setting_map_)); init_setting_map(setting_map_, ARRAY_SIZE(setting_map_));
@ -195,7 +197,7 @@ hg_scanner_302::hg_scanner_302(const char* dev_name, int pid, usb_io* io) : hg_s
} }
hg_scanner_302::~hg_scanner_302() hg_scanner_302::~hg_scanner_302()
{ {
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "hg_scanner_302(%s) destroyed.\n", hg_log::format_ptr(this).c_str()); utils::to_log(LOG_LEVEL_DEBUG, "hg_scanner_302(%p) destroyed.\n", this);
} }
int hg_scanner_302::read_register(int addr, int* val) int hg_scanner_302::read_register(int addr, int* val)
{ {
@ -238,16 +240,16 @@ std::string hg_scanner_302::control_fetch(int addr, int val, int size)
ret = io_->read_bulk(&data[0], &l); ret = io_->read_bulk(&data[0], &l);
if (ret == SCANNER_ERR_OK) if (ret == SCANNER_ERR_OK)
{ {
VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "control_fetch(%d, %d) - read_bulk %d bytes\n", addr, val, l); utils::to_log(LOG_LEVEL_DEBUG, "control_fetch(%d, %d) - read_bulk %d bytes\n", addr, val, l);
} }
else else
{ {
VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "control_fetch(%d, %d) - read_bulk = %s\n", addr, val, hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_DEBUG, "control_fetch(%d, %d) - read_bulk = %s\n", addr, val, hg_scanner_err_name(ret));
data.clear(); data.clear();
} }
} }
else else
VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "control_fetch(%d, %d) = %s\n", addr, val, hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_DEBUG, "control_fetch(%d, %d) = %s\n", addr, val, hg_scanner_err_name(ret));
return data; return data;
} }
@ -278,7 +280,7 @@ int hg_scanner_302::clr_roller_num(void)
return val; return val;
else else
{ {
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "clr_roller_num = %s\n", hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_DEBUG, "clr_roller_num = %s\n", hg_scanner_err_name(ret));
return -1; return -1;
} }
} }
@ -292,7 +294,7 @@ int hg_scanner_302::get_sleep_time(void)
return val; return val;
else else
{ {
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "get_sleep_time = %s\n", hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_DEBUG, "get_sleep_time = %s\n", hg_scanner_err_name(ret));
return -1; return -1;
} }
} }
@ -304,7 +306,7 @@ int hg_scanner_302::get_scan_mode(void)
if (ret) if (ret)
{ {
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "get scan mode error: %s\n", hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_DEBUG, "get scan mode error: %s\n", hg_scanner_err_name(ret));
status_ = ret; status_ = ret;
return -1; return -1;
@ -320,7 +322,7 @@ int hg_scanner_302::get_status(void)
if (ret) if (ret)
{ {
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "get status error: %s\n", hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_DEBUG, "get status error: %s\n", hg_scanner_err_name(ret));
status_ = ret; status_ = ret;
return -1; return -1;
@ -336,7 +338,7 @@ bool hg_scanner_302::is_dev_tx(void)
if (ret) if (ret)
{ {
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "is_dev_tx() error: %s\n", hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_DEBUG, "is_dev_tx() error: %s\n", hg_scanner_err_name(ret));
status_ = ret; status_ = ret;
return false; return false;
@ -352,7 +354,7 @@ bool hg_scanner_302::is_dev_image_process_done(void)
if (ret) if (ret)
{ {
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "is_dev_image_process_done() error: %s\n", hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_DEBUG, "is_dev_image_process_done() error: %s\n", hg_scanner_err_name(ret));
status_ = ret; status_ = ret;
return true; return true;
@ -369,7 +371,7 @@ bool hg_scanner_302::is_dev_image_keep_last_paper(void)
if (ret) if (ret)
{ {
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "is_dev_image_keep_last_paper() error: %s\n", hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_DEBUG, "is_dev_image_keep_last_paper() error: %s\n", hg_scanner_err_name(ret));
status_ = ret; status_ = ret;
return true; return true;
@ -387,7 +389,7 @@ int hg_scanner_302::get_scanned_count(void)
return val; return val;
else else
{ {
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "get_scanned_count = %s\n", hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_DEBUG, "get_scanned_count = %s\n", hg_scanner_err_name(ret));
return -1; return -1;
} }
} }
@ -397,7 +399,7 @@ int hg_scanner_302::get_image_count(void)
int val = 0, int val = 0,
ret = read_register(setting3399::SR_IM_COUNT, &val); ret = read_register(setting3399::SR_IM_COUNT, &val);
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "get_image_count() = %d, error: %s\n", val, hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_DEBUG, "get_image_count() = %d, error: %s\n", val, hg_scanner_err_name(ret));
if (ret == SCANNER_ERR_OK) if (ret == SCANNER_ERR_OK)
return val; return val;
@ -414,7 +416,7 @@ int hg_scanner_302::get_front_data_size(void)
return val; return val;
else else
{ {
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "get_front_data_size = %s\n", hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_DEBUG, "get_front_data_size = %s\n", hg_scanner_err_name(ret));
return -1; return -1;
} }
} }
@ -424,9 +426,9 @@ void hg_scanner_302::init_version(void)
sn(get_serial_num()); sn(get_serial_num());
if (fv.empty() || sn.empty()) if (fv.empty() || sn.empty())
return; return;
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Firmware version: %s\n", fv.c_str()); utils::to_log(LOG_LEVEL_DEBUG, "Firmware version: %s\n", fv.c_str());
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Serial number: %s\n", sn.c_str()); utils::to_log(LOG_LEVEL_DEBUG, "Serial number: %s\n", sn.c_str());
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, " HG3399 IP: %s\n", get_ip().c_str()); //utils::to_log(LOG_LEVEL_DEBUG, " HG3399 IP: %s\n", get_ip().c_str());
//if (fv.length() >= 10 && (fv[5] > 'A' || atoi(fv.substr(6, 4).c_str()) >= 1209)) //if (fv.length() >= 10 && (fv[5] > 'A' || atoi(fv.substr(6, 4).c_str()) >= 1209))
//{ //{
@ -485,7 +487,7 @@ int hg_scanner_302::writedown_device_configuration(bool type,setting_hardware::H
ret = write_register(setting3399::SR_CONFIG_SCAN_PARAM, dev_conf->value); ret = write_register(setting3399::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)); utils::to_log(LOG_LEVEL_DEBUG, "Writedown scanner configuration(0x%x) = %s\n", dev_conf->value, hg_scanner_err_name(ret));
return ret; return ret;
} }
int hg_scanner_302::writedown_image_configuration(void) int hg_scanner_302::writedown_image_configuration(void)
@ -507,7 +509,7 @@ int hg_scanner_302::writedown_image_configuration(void)
ic.hardwarecaps.skrewdetectlevel = dev_conf_.params_3399.screw_detect_level; ic.hardwarecaps.skrewdetectlevel = dev_conf_.params_3399.screw_detect_level;
if (test_1_paper_) if (test_1_paper_)
{ {
LOG_INFO(LOG_LEVEL_DEBUG_INFO, "scanning mode: testing ONE paper ...\n"); utils::log_info("scanning mode: testing ONE paper ...\n", LOG_LEVEL_DEBUG);
ic.scannum = /*ic.is_duplex ? 2 :*/ 1; ic.scannum = /*ic.is_duplex ? 2 :*/ 1;
} }
else else
@ -536,7 +538,7 @@ int hg_scanner_302::pop_first_image(void)
std::lock_guard<std::mutex> lock(io_lock_); std::lock_guard<std::mutex> lock(io_lock_);
int ret = write_register(setting3399::SR_IM_POP, 1); int ret = write_register(setting3399::SR_IM_POP, 1);
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "popup first image = %s\n", hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_DEBUG, "popup first image = %s\n", hg_scanner_err_name(ret));
return ret; return ret;
} }
@ -548,7 +550,7 @@ int hg_scanner_302::read_one_image_from_usb(SANE_Image_Statu statu)
ret = SCANNER_ERR_OK; ret = SCANNER_ERR_OK;
bool popimg = false; bool popimg = false;
VLOG_MINI_1(LOG_LEVEL_ALL, "New image size: %u\n", total); utils::to_log(LOG_LEVEL_ALL, "New image size: %u\n", total);
if (!waiting_for_memory_enough(total)) if (!waiting_for_memory_enough(total))
{ {
status_ = SCANNER_ERR_INSUFFICIENT_MEMORY; status_ = SCANNER_ERR_INSUFFICIENT_MEMORY;
@ -593,7 +595,7 @@ int hg_scanner_302::read_one_image_from_usb(SANE_Image_Statu statu)
buff = buf->data(off, (unsigned int*)&r); buff = buf->data(off, (unsigned int*)&r);
} }
} }
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Read image from USB = %s\n", hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_DEBUG, "Read image from USB = %s\n", hg_scanner_err_name(ret));
if (ret == SCANNER_ERR_OK) if (ret == SCANNER_ERR_OK)
{ {
//{ //{
@ -608,17 +610,17 @@ int hg_scanner_302::read_one_image_from_usb(SANE_Image_Statu statu)
} }
else else
{ {
VLOG_MINI_1(LOG_LEVEL_FATAL, "save usb data failed: %s\n", hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_FATAL, "save usb data failed: %s\n", hg_scanner_err_name(ret));
} }
} }
else else
{ {
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Read image data from USB err: %s\n", hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_DEBUG, "Read image data from USB err: %s\n", hg_scanner_err_name(ret));
} }
} }
else else
{ {
VLOG_MINI_1(LOG_LEVEL_FATAL, "write command SR_IM_TX failed: %s\n", hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_FATAL, "write command SR_IM_TX failed: %s\n", hg_scanner_err_name(ret));
} }
} }
if(popimg) if(popimg)
@ -665,7 +667,7 @@ int hg_scanner_302::discard_all_images(void)
io_->set_timeout(oto); io_->set_timeout(oto);
} }
if (pre_int) 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); utils::to_log(LOG_LEVEL_DEBUG, "prev-connection has left %d interrupt packet(s) && %d image(s).\n", pre_int, pre_img);
return 0; return 0;
} }
int hg_scanner_302::get_roller_life(void) int hg_scanner_302::get_roller_life(void)
@ -924,7 +926,7 @@ void hg_scanner_302::thread_handle_usb_read(void)
} }
if (ret != SCANNER_ERR_OK && ret != SCANNER_ERR_TIMEOUT) if (ret != SCANNER_ERR_OK && ret != SCANNER_ERR_TIMEOUT)
{ {
VLOG_MINI_5(LOG_LEVEL_DEBUG_INFO, "read-INT = %s: From(%d), Code(%d), Index(%d), size = %d\n", hg_scanner_err_name(ret), utils::to_log(LOG_LEVEL_DEBUG, "read-INT = %s: From(%d), Code(%d), Index(%d), size = %d\n", hg_scanner_err_name(ret),
info->From, info->Code, info->Img_Index, size); info->From, info->Code, info->Img_Index, size);
} }
@ -938,7 +940,7 @@ void hg_scanner_302::thread_handle_usb_read(void)
//int statu = get_status(); //int statu = get_status();
//if ((statu & 0x03) == 0) //if ((statu & 0x03) == 0)
//{ //{
// VLOG_MINI_1(LOG_LEVEL_FATAL, "USB thread over with status: 0x%x\n", statu); // utils::to_log(LOG_LEVEL_FATAL, "USB thread over with status: 0x%x\n", statu);
// status_ = SCANNER_ERR_OK; // status_ = SCANNER_ERR_OK;
// break; // break;
//} //}
@ -953,7 +955,7 @@ void hg_scanner_302::thread_handle_usb_read(void)
if (size == sizeof(buf)) if (size == sizeof(buf))
{ {
ret = settings302::device_status_to_hg_err(info); ret = settings302::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_)); utils::to_log(LOG_LEVEL_DEBUG, "status from interrupt point is '%s'\n", hg_scanner_err_name(status_));
if (ret != SCANNER_ERR_OK && ret != SCANNER_ERR_TIMEOUT && ret != SCANNER_ERR_DEVICE_STOPPED) if (ret != SCANNER_ERR_OK && ret != SCANNER_ERR_TIMEOUT && ret != SCANNER_ERR_DEVICE_STOPPED)
{ {
@ -983,7 +985,7 @@ void hg_scanner_302::thread_handle_usb_read(void)
status_ = st; status_ = st;
} }
VLOG_MINI_1(LOG_LEVEL_WARNING, "\346\211\253\346\217\217\345\244\261\350\264\245, read interrupt\350\277\224\345\233\236\347\212\266\346\200\201\344\270\272\357\274\232%s\n", hg_scanner_err_description(status_)); utils::to_log(LOG_LEVEL_WARNING, "\346\211\253\346\217\217\345\244\261\350\264\245, read interrupt\350\277\224\345\233\236\347\212\266\346\200\201\344\270\272\357\274\232%s\n", hg_scanner_err_description(status_));
break; break;
} }
@ -996,11 +998,11 @@ void hg_scanner_302::thread_handle_usb_read(void)
} }
else else
{ {
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "receive IMG event but no image count(%d)!", get_image_count()); utils::to_log(LOG_LEVEL_DEBUG, "receive IMG event but no image count(%d)!", get_image_count());
} }
break; break;
case setting3399::V4L2: case setting3399::V4L2:
VLOG_MINI_1(LOG_LEVEL_FATAL, "V4L2 error: %d\n", info->Code); utils::to_log(LOG_LEVEL_FATAL, "V4L2 error: %d\n", info->Code);
{ {
bool cancel = user_cancel_; bool cancel = user_cancel_;
stop(); stop();
@ -1010,7 +1012,7 @@ void hg_scanner_302::thread_handle_usb_read(void)
break; break;
case setting3399::STOPSCAN: case setting3399::STOPSCAN:
go = false; go = false;
LOG_INFO(LOG_LEVEL_ALL, "Received STOPSCAN event ...\n"); utils::log_info("Received STOPSCAN event ...\n", LOG_LEVEL_ALL);
std::this_thread::sleep_for(std::chrono::milliseconds(500)); std::this_thread::sleep_for(std::chrono::milliseconds(500));
while (get_image_count() > 0) // lost IMG message, check image count to receive rest images (BUG-228)... while (get_image_count() > 0) // lost IMG message, check image count to receive rest images (BUG-228)...
{ {
@ -1029,11 +1031,11 @@ void hg_scanner_302::thread_handle_usb_read(void)
break; break;
} }
else else
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "read %d bytes, sizeof(buf) = %d\n", size, sizeof(buf)); utils::to_log(LOG_LEVEL_DEBUG, "read %d bytes, sizeof(buf) = %d\n", size, sizeof(buf));
this_thread::sleep_for(chrono::milliseconds(10)); 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_)); utils::to_log(LOG_LEVEL_DEBUG, "USB thread exit with code: %s, status = %s\n", hg_scanner_err_name(ret), hg_scanner_err_name(status_));
} }
int hg_scanner_302::start(void) int hg_scanner_302::start(void)
{ {
@ -1048,7 +1050,7 @@ int hg_scanner_302::start(void)
user_cancel_ = false; user_cancel_ = false;
split3399_ = 0; split3399_ = 0;
cb_mem_ = true; cb_mem_ = true;
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "scanner status: 0x%x\n", get_status()); utils::to_log(LOG_LEVEL_DEBUG, "scanner status: 0x%x\n", get_status());
reset(); reset();
@ -1079,11 +1081,11 @@ int hg_scanner_302::start(void)
else else
{ {
ret = status_ = SCANNER_ERR_DEVICE_UNKNOWN_STATUS; ret = status_ = SCANNER_ERR_DEVICE_UNKNOWN_STATUS;
VLOG_MINI_2(LOG_LEVEL_WARNING, "The device is abnormal(%d) and can not be scanned : %s\n", val, hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_WARNING, "The device is abnormal(%d) and can not be scanned : %s\n", val, hg_scanner_err_name(ret));
//break; //break;
} }
VLOG_MINI_2(LOG_LEVEL_WARNING, "failed on SR_GET_ANDROID_STATE(%d) result: %s\n", val, hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_WARNING, "failed on SR_GET_ANDROID_STATE(%d) result: %s\n", val, hg_scanner_err_name(ret));
return ret; return ret;
} }
@ -1096,7 +1098,7 @@ int hg_scanner_302::start(void)
write_register(0x1000, count); write_register(0x1000, count);
ret = write_command(setting3399::SC_START); ret = write_command(setting3399::SC_START);
} }
VLOG_MINI_1(LOG_LEVEL_WARNING, "start result: %s\n", hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_WARNING, "start result: %s\n", hg_scanner_err_name(ret));
if (ret == SCANNER_ERR_OK) if (ret == SCANNER_ERR_OK)
{ {
@ -1107,7 +1109,7 @@ int hg_scanner_302::start(void)
else else
{ {
status_ = ret; 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)); utils::to_log(LOG_LEVEL_WARNING, "(Thread 0x%x)Send start command = %s\n", GetCurrentThreadId(), hg_scanner_err_name(ret));
} }
return ret; return ret;
@ -1236,7 +1238,7 @@ int hg_scanner_302::get_sleep_time(int& data)
data = val; data = val;
} }
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "get_sleep_time = %d with %s\n", data, hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_DEBUG, "get_sleep_time = %d with %s\n", data, hg_scanner_err_name(ret));
return ret; return ret;
} }
int hg_scanner_302::set_sleep_time(int setsleepime) int hg_scanner_302::set_sleep_time(int setsleepime)
@ -1244,7 +1246,7 @@ int hg_scanner_302::set_sleep_time(int setsleepime)
std::lock_guard<std::mutex> lock(io_lock_); std::lock_guard<std::mutex> lock(io_lock_);
int ret = write_register(setting3399::SR_SET_SLEEPTIME, setsleepime); int ret = write_register(setting3399::SR_SET_SLEEPTIME, setsleepime);
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "set sleep time to %d = %s\n", setsleepime, hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_DEBUG, "set sleep time to %d = %s\n", setsleepime, hg_scanner_err_name(ret));
return ret; return ret;
} }
@ -1283,7 +1285,7 @@ int hg_scanner_302::get_device_log(string &log)
if (ret == SCANNER_ERR_OK) if (ret == SCANNER_ERR_OK)
ret = io_->write_bulk(&log[0],&len); ret = io_->write_bulk(&log[0],&len);
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "log path:%s ret:%s\n", log.c_str(),hg_scanner_err_name(ret)); utils::to_log(LOG_LEVEL_DEBUG, "log path:%s ret:%s\n", log.c_str(),hg_scanner_err_name(ret));
return ret; return ret;
} }
int hg_scanner_302::set_devreboot(int data) int hg_scanner_302::set_devreboot(int data)

View File

@ -1,5 +1,9 @@
#include "image_process.h" #include "image_process.h"
#include "../wrapper/hg_log.h"
#include "../../sdk/hginclude/utils.h"
#include "../../sdk/hginclude/huagaoxxx_warraper_ex.h"
#include <lang/app_language.h>
#include <vector> #include <vector>
#include <string.h> #include <string.h>
#if !defined(WIN32) && !defined(_WIN64) #if !defined(WIN32) && !defined(_WIN64)
@ -218,14 +222,19 @@ namespace hg_imgproc
public: public:
imgproc(int pid, bool isx86_Advan) : pid_(pid),papersize_(pid_) imgproc(int pid, bool isx86_Advan) : pid_(pid),papersize_(pid_)
, img_statu_(SANE_Image_Statu_OK) , img_statu_(SANE_Image_Statu_OK)
, my_path_(hg_log::pe_path()) , my_path_(utils::get_module_full_path())
,ocrinit_(NULL),ocrgetdirectimage_(NULL) ,ocrinit_(NULL),ocrgetdirectimage_(NULL)
,ocrexit_(NULL),HGBase_CreatImg(NULL) ,ocrexit_(NULL),HGBase_CreatImg(NULL)
,HGBase_FreeImg(NULL),Auto_Txt_pHanld(NULL) ,HGBase_FreeImg(NULL),Auto_Txt_pHanld(NULL)
,Dynamicopen_HGBase_pHandle_(NULL) ,Dynamicopen_HGBase_pHandle_(NULL)
,Dynamicopen_HGImageprc_pHandle_(NULL),isx86_Advan_(isx86_Advan) ,Dynamicopen_HGImageprc_pHandle_(NULL),isx86_Advan_(isx86_Advan)
{ {
cv::setUseOptimized(isx86_Advan_); //开关cpu高级指令é? size_t pos = my_path_.rfind(PATH_SEPARATOR[0]);
if(pos++ == std::string::npos)
pos = 0;
my_path_.erase(pos);
cv::setUseOptimized(isx86_Advan_); //开关cpu高级指令<E68C87>?
} }
~imgproc() ~imgproc()
{ {
@ -294,29 +303,18 @@ namespace hg_imgproc
int init_auto_txt_hanld() int init_auto_txt_hanld()
{ {
int ret = 0; int ret = 0;
#ifndef WIN32 string scanner_path = utils::get_module_full_path(SCANNER_DRIVER_PART_NAME);
#ifdef OEM_HANWANG size_t pos = scanner_path.rfind(PATH_SEPARATOR[0]);
string libname = "libhwdriver.so";
#elif defined(OEM_LISICHENG)
string libname = "liblscdriver.so";
#elif defined(OEM_CANGTIAN)
string libname = "libctsdriver.so";
#elif defined(OEM_ZHONGJING)
string libname = "libzjdriver.so";
#elif defined(OEM_ZIGUANG)
string libname = "libzgdriver.so";
#else
string libname = "libhgdriver.so";
#endif
string scanner_path = hg_log::get_module_full_path(libname.c_str());
if (scanner_path.empty()) if (scanner_path.empty())
{ {
return SCANNER_ERR_OUT_OF_RANGE; return SCANNER_ERR_OUT_OF_RANGE;
} }
scanner_path = scanner_path.substr(0, scanner_path.size() - libname.size()); if(pos++ == std::string::npos)
pos = 0;
scanner_path.erase(pos);
#ifndef WIN32
string HGImagePrclib_path = scanner_path + IMGPRC_LIBNANE; string HGImagePrclib_path = scanner_path + IMGPRC_LIBNANE;
string HGBaselib_path = scanner_path + HGBASE_LIBNAME; string HGBaselib_path = scanner_path + HGBASE_LIBNAME;
@ -326,14 +324,14 @@ namespace hg_imgproc
{ {
return SCANNER_ERR_OUT_OF_RANGE; return SCANNER_ERR_OUT_OF_RANGE;
} }
printf("HGBaselib_pathï¼?s HGImagePrclib_path:%s\r\n",HGBaselib_path.c_str(),HGImagePrclib_path.c_str()); printf("HGBaselib_path<EFBFBD>?s HGImagePrclib_path:%s\r\n",HGBaselib_path.c_str(),HGImagePrclib_path.c_str());
Dynamicopen_HGImageprc_pHandle_ = dlopen(HGImagePrclib_path.c_str(), RTLD_LAZY); Dynamicopen_HGImageprc_pHandle_ = dlopen(HGImagePrclib_path.c_str(), RTLD_LAZY);
Dynamicopen_HGBase_pHandle_ = dlopen(HGBaselib_path.c_str(), RTLD_LAZY); Dynamicopen_HGBase_pHandle_ = dlopen(HGBaselib_path.c_str(), RTLD_LAZY);
if (!Dynamicopen_HGBase_pHandle_ || !Dynamicopen_HGImageprc_pHandle_) if (!Dynamicopen_HGBase_pHandle_ || !Dynamicopen_HGImageprc_pHandle_)
{ {
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "auto txt open dll is error: %s\n", hg_scanner_err_name(SCANNER_ERR_INSUFFICIENT_MEMORY)); utils::to_log(LOG_LEVEL_DEBUG, "auto txt open dll is error: %s\n", hg_scanner_err_name(SCANNER_ERR_INSUFFICIENT_MEMORY));
return SCANNER_ERR_INSUFFICIENT_MEMORY; return SCANNER_ERR_INSUFFICIENT_MEMORY;
} }
@ -345,9 +343,6 @@ namespace hg_imgproc
HGBase_FreeImg = (SDKHGBase_FreeImage_)dlsym(Dynamicopen_HGBase_pHandle_,"HGBase_DestroyImage"); HGBase_FreeImg = (SDKHGBase_FreeImage_)dlsym(Dynamicopen_HGBase_pHandle_,"HGBase_DestroyImage");
#else #else
string scanner_path = hg_log::get_module_full_path("scanner.dll");
scanner_path = scanner_path.substr(0, scanner_path.size() - strlen("scanner.dll"));
string HGImagePrclib_path = scanner_path + IMGPRC_LIBNANE; string HGImagePrclib_path = scanner_path + IMGPRC_LIBNANE;
string HGBaselib_path = scanner_path + HGBASE_LIBNAME; string HGBaselib_path = scanner_path + HGBASE_LIBNAME;
@ -371,7 +366,7 @@ namespace hg_imgproc
if (!Dynamicopen_HGBase_pHandle_ || !Dynamicopen_HGImageprc_pHandle_) if (!Dynamicopen_HGBase_pHandle_ || !Dynamicopen_HGImageprc_pHandle_)
{ {
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "auto txt open dll is error: %s\n", hg_scanner_err_name(SCANNER_ERR_INSUFFICIENT_MEMORY)); utils::to_log(LOG_LEVEL_DEBUG, "auto txt open dll is error: %s\n", hg_scanner_err_name(SCANNER_ERR_INSUFFICIENT_MEMORY));
return SCANNER_ERR_INSUFFICIENT_MEMORY; return SCANNER_ERR_INSUFFICIENT_MEMORY;
} }
ocrinit_ = (SDKHGImgProc_InitOCR_)GetProcAddress(Dynamicopen_HGImageprc_pHandle_, "HGImgProc_CreateOCRMgr"); ocrinit_ = (SDKHGImgProc_InitOCR_)GetProcAddress(Dynamicopen_HGImageprc_pHandle_, "HGImgProc_CreateOCRMgr");
@ -488,7 +483,7 @@ namespace hg_imgproc
if (mat.empty()) if (mat.empty())
{ {
LOG_INFO(LOG_LEVEL_FATAL, "decode image data error\n"); utils::log_info("decode image data error\n", LOG_LEVEL_FATAL);
continue; continue;
} }
if (param_.cis_image) if (param_.cis_image)
@ -510,8 +505,8 @@ namespace hg_imgproc
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
LOG_INFO(LOG_LEVEL_FATAL, e.what()); utils::log_info(e.what(), LOG_LEVEL_FATAL);
throw(e); // 继续æŠåˆ°ä¸Šå±å¤„ç<EFBFBD>†ã€? throw(e); // 继续抛到上层处理<EFBFBD>?
} }
} }
@ -523,7 +518,7 @@ namespace hg_imgproc
if (pid_ == 0x100 || pid_ == 0x200 || pid_ == 0x300 || pid_ == 0x400 || pid == 0x402 || pid == 0x302) if (pid_ == 0x100 || pid_ == 0x200 || pid_ == 0x300 || pid_ == 0x400 || pid == 0x402 || pid == 0x302)
{ {
//////除穿孔算法移至解åŽå¾åƒ<EFBFBD>ä¹å<EFBFBD>? //////除穿孔算法移至解压图像之<EFBFBD>?
double left = img_conf_.fillholeratio_left / 100.0; double left = img_conf_.fillholeratio_left / 100.0;
double right = img_conf_.fillholeratio_right / 100.0; double right = img_conf_.fillholeratio_right / 100.0;
double top = img_conf_.fillholeratio_up / 100.0; double top = img_conf_.fillholeratio_up / 100.0;
@ -531,7 +526,7 @@ namespace hg_imgproc
if (left > 0 || right > 0 || top > 0 || low > 0) if (left > 0 || right > 0 || top > 0 || low > 0)
fillhole1(Temp_mat, top, low, left, right); fillhole1(Temp_mat, top, low, left, right);
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "Remove hole is '%s',Hole image buffer size is:%d\n", !Temp_mat.empty() ? "enable" : "close", Temp_mat.size()); utils::to_log(LOG_LEVEL_DEBUG, "Remove hole is '%s',Hole image buffer size is:%d\n", !Temp_mat.empty() ? "enable" : "close", Temp_mat.size());
if (param_.cis_image) if (param_.cis_image)
{ {
mats_ = Temp_mat; mats_ = Temp_mat;
@ -563,7 +558,7 @@ namespace hg_imgproc
Temp_mat.clear(); Temp_mat.clear();
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "Decode %u bytes to %u picture(s)\n", origin, mats_.size()); utils::to_log(LOG_LEVEL_DEBUG, "Decode %u bytes to %u picture(s)\n", origin, mats_.size());
if (mats_.empty()) if (mats_.empty())
{ {
return SCANNER_ERR_NO_DATA; return SCANNER_ERR_NO_DATA;
@ -853,7 +848,7 @@ namespace hg_imgproc
std::vector<cv::Mat> mats(mats_); std::vector<cv::Mat> mats(mats_);
mats_.clear(); mats_.clear();
//VLOG_MINI_4(LOG_LEVEL_DEBUG_INFO, "adjust_color: table len = %d, brightness = %f, contrast = %f, gamma = %f\n", tableLength //utils::to_log(LOG_LEVEL_DEBUG, "adjust_color: table len = %d, brightness = %f, contrast = %f, gamma = %f\n", tableLength
// , img_conf_.brightness, img_conf_.contrast, img_conf_.gamma); // , img_conf_.brightness, img_conf_.contrast, img_conf_.gamma);
if (gamma_table && tableLength) if (gamma_table && tableLength)
{ {
@ -1166,13 +1161,16 @@ namespace hg_imgproc
string libname = "libhgdriver.so"; string libname = "libhgdriver.so";
#endif #endif
string scanner_path = hg_log::get_module_full_path(libname.c_str()); string scanner_path = utils::get_module_full_path(SCANNER_DRIVER_PART_NAME);
if(scanner_path.empty()) if(scanner_path.empty())
{ {
return SCANNER_ERR_OUT_OF_RANGE; return SCANNER_ERR_OUT_OF_RANGE;
} }
scanner_path = scanner_path.substr(0,scanner_path.size() - libname.size()); size_t pos = scanner_path.rfind(PATH_SEPARATOR[0]);
if(pos++ == std::string::npos)
pos = 0;
scanner_path.erase(pos);
scanner_path+="libhwocrdetect.so"; scanner_path+="libhwocrdetect.so";
printf("hwlib path:%s\r\n",scanner_path.c_str()); printf("hwlib path:%s\r\n",scanner_path.c_str());
@ -1343,7 +1341,7 @@ namespace hg_imgproc
info.width = mats.cols; info.width = mats.cols;
info.origin = HGBASE_IMGORIGIN_TOP; info.origin = HGBASE_IMGORIGIN_TOP;
int bits = mats.channels() == 1 ? 8 : 24; int bits = mats.channels() == 1 ? 8 : 24;
info.widthStep = mats.step; //opencv原始å€? info.widthStep = mats.step; //opencv原始<EFBFBD>?
info.type = mats.channels() == 1 ? HGBASE_IMGTYPE_GRAY : HGBASE_IMGTYPE_BGR; info.type = mats.channels() == 1 ? HGBASE_IMGTYPE_GRAY : HGBASE_IMGTYPE_BGR;
int ret = HGBase_CreatImg(const_cast<uchar*>(mats.data), &info, &image); int ret = HGBase_CreatImg(const_cast<uchar*>(mats.data), &info, &image);
@ -1355,11 +1353,11 @@ namespace hg_imgproc
/// <summary> /// <summary>
/// 8ä½<EFBFBD>å¾è½?ä½<C3A4>å¾ /// 8位图<EFBFBD>?位图
/// </summary> /// </summary>
/// <param name="image">8bitå›?/param> /// <param name="image">8bit<EFBFBD>?/param>
/// <param name="threshold">阈值建议默认127</param> /// <param name="threshold">阈值建议默认127</param>
/// <param name="reverse">true为å<EFBFBD><EFBFBD>色,å<EFBFBD>³é»0ç™?ï¼å<E280BA><C3A5>ä¹äº¦ç„?/param> /// <param name="reverse">true为反色即黑0<EFBFBD>?反之亦<E4B98B>?/param>
/// <param name="align">true为四字节对齐</param> /// <param name="align">true为四字节对齐</param>
/// <returns>1位图</returns> /// <returns>1位图</returns>
/// ///
@ -1519,7 +1517,7 @@ namespace hg_imgproc
} }
else else
{ {
LOG_INFO(LOG_LEVEL_ALL, "No image output in image_process!\n"); utils::log_info("No image output in image_process!\n", LOG_LEVEL_ALL);
} }
} }
}; };
@ -1876,7 +1874,7 @@ namespace hg_imgproc
} }
else else
{ {
std::string tmpf(hg_log::temporary_path() + PATH_SEPARATOR + "imgtrans.jpg"); std::string tmpf(utils::temporary_path() + PATH_SEPARATOR + "imgtrans.jpg");
cv::imwrite(tmpf.c_str(), imsg, cpr); cv::imwrite(tmpf.c_str(), imsg, cpr);
size_t bytes = 0; size_t bytes = 0;
conv->dst.data = (SANE_String_Const)G4Tiff::load_mini_file(tmpf.c_str(), &bytes, allocate_memory); conv->dst.data = (SANE_String_Const)G4Tiff::load_mini_file(tmpf.c_str(), &bytes, allocate_memory);

View File

@ -1,5 +1,7 @@
#include "scanner_manager.h" #include "scanner_manager.h"
#include "../wrapper/hg_log.h"
#include "../../sdk/hginclude/utils.h"
#include <lang/app_language.h>
#include <iostream> #include <iostream>
#include <string.h> #include <string.h>
#include "raw_src.h" #include "raw_src.h"
@ -142,7 +144,12 @@ std::mutex hg_scanner_mgr::mutex_img_id;
hg_scanner_mgr::hg_scanner_mgr() : same_ind_(1), user_(""), pwd_(""), cf_name("") hg_scanner_mgr::hg_scanner_mgr() : same_ind_(1), user_(""), pwd_(""), cf_name("")
{ {
cf_name = hg_log::ini_get("devs_name", "name"); std::string cfgf(utils::get_local_data_path() + PATH_SEPARATOR + "config" + PATH_SEPARATOR + "debug.cfg");
char buf[260] = {0};
int l = GetPrivateProfileStringA("devs_name", "name", "", buf, _countof(buf) - 1, cfgf.c_str());
buf[l] = 0;
cf_name = buf;
usb_manager::instance()->register_hotplug(&hg_scanner_mgr::usb_event_handle, this); usb_manager::instance()->register_hotplug(&hg_scanner_mgr::usb_event_handle, this);
int code_page = lang_get_cur_code_page(); int code_page = lang_get_cur_code_page();
url_en = BRAND_COMPANY_URL; url_en = BRAND_COMPANY_URL;
@ -184,7 +191,7 @@ hg_scanner_mgr* hg_scanner_mgr::instance(sane_callback cb)
hg_scanner_mgr::async_io_enabled_ = cb(NULL, SANE_EVENT_SUPPORT_ASYNC_IO, NULL, NULL, NULL) == 0; hg_scanner_mgr::async_io_enabled_ = cb(NULL, SANE_EVENT_SUPPORT_ASYNC_IO, NULL, NULL, NULL) == 0;
hg_scanner_mgr::unique_img_id_ = (uint32_t)INT_MAX + 1; hg_scanner_mgr::unique_img_id_ = (uint32_t)INT_MAX + 1;
hg_scanner_mgr::inst_ = new hg_scanner_mgr(); hg_scanner_mgr::inst_ = new hg_scanner_mgr();
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "async image transferring is %s\n", hg_scanner_mgr::async_io_enabled_ ? "enabled" : "disabled"); utils::to_log(LOG_LEVEL_DEBUG, "async image transferring is %s\n", hg_scanner_mgr::async_io_enabled_ ? "enabled" : "disabled");
} }
return hg_scanner_mgr::inst_; return hg_scanner_mgr::inst_;
@ -210,17 +217,21 @@ void hg_scanner_mgr::set_version(int hh, int hl, int lh, int ll)
} }
void hg_scanner_mgr::set_exe_name(const char* path, const char* name) void hg_scanner_mgr::set_exe_name(const char* path, const char* name)
{ {
std::string cfgf(utils::get_local_data_path() + PATH_SEPARATOR + "config" + PATH_SEPARATOR + "debug.cfg");
char buf[260] = {0};
int l = 0;
hg_scanner_mgr::pe_path_ = path ? path : ""; hg_scanner_mgr::pe_path_ = path ? path : "";
hg_scanner_mgr::pe_name_ = name ? name : ""; hg_scanner_mgr::pe_name_ = name ? name : "";
std::string str = hg_log::get_scanimage_ver(); std::string str(utils::get_command_result("scanimage -V"));
bool is_scanimg =false; bool is_scanimg =false;
is_scanimg = str >= "1.0.29" ? true : false; is_scanimg = str >= "1.0.29" ? true : false;
VLOG_MINI_2(LOG_LEVEL_ALL, "imgascan ver is: %s is_scanimg is:%d\n", str.c_str(),is_scanimg); utils::to_log(LOG_LEVEL_ALL, "imgascan ver is: %s is_scanimg is:%d\n", str.c_str(),is_scanimg);
if (name && *name) if (name && *name)
{ {
// int ret = system("scanimage -V"); // int ret = system("scanimage -V");
std::string eof(hg_log::ini_get("read_eof", name)); l = GetPrivateProfileStringA("read_eof", name, "", buf, _countof(buf) - 1, cfgf.c_str());
if (eof.empty()) if (l == 0)
{ {
if(is_scanimg) if(is_scanimg)
hg_scanner_mgr::read_over_with_eof_ = STRICMP(name, "simple-scan") != 0; hg_scanner_mgr::read_over_with_eof_ = STRICMP(name, "simple-scan") != 0;
@ -228,18 +239,18 @@ void hg_scanner_mgr::set_exe_name(const char* path, const char* name)
hg_scanner_mgr::read_over_with_eof_ = STRICMP(name, "simple-scan") != 0 && (!is_scanimg? (STRICMP(name, "scanimage") != 0) : 1); hg_scanner_mgr::read_over_with_eof_ = STRICMP(name, "simple-scan") != 0 && (!is_scanimg? (STRICMP(name, "scanimage") != 0) : 1);
} }
else else
hg_scanner_mgr::read_over_with_eof_ = eof != "0"; hg_scanner_mgr::read_over_with_eof_ = strcmp(buf, "0") != 0;
} }
else else
{ {
std::string eof(hg_log::ini_get("read_eof", "first")); l = GetPrivateProfileStringA("read_eof", "first", "", buf, _countof(buf) - 1, cfgf.c_str());
if (eof.empty()) if (l == 0)
hg_scanner_mgr::read_over_with_eof_ = true; hg_scanner_mgr::read_over_with_eof_ = true;
else else
hg_scanner_mgr::read_over_with_eof_ = eof != "0"; hg_scanner_mgr::read_over_with_eof_ = strcmp(buf, "0") != 0;
} }
VLOG_MINI_1(LOG_LEVEL_ALL, "read image data end with EOF: %s\n", hg_scanner_mgr::read_over_with_eof_ ? "true" : "false"); utils::to_log(LOG_LEVEL_ALL, "read image data end with EOF: %s\n", hg_scanner_mgr::read_over_with_eof_ ? "true" : "false");
} }
std::string hg_scanner_mgr::get_pe_name(std::string* path) std::string hg_scanner_mgr::get_pe_name(std::string* path)
{ {
@ -429,7 +440,7 @@ void hg_scanner_mgr::on_hgscanner_pnp(usb_event ev, libusb_device* device, int v
libusb_ref_device(ols.dev); // ref to the device of queue online_devices_ libusb_ref_device(ols.dev); // ref to the device of queue online_devices_
online_devices_.push_back(ols); online_devices_.push_back(ols);
name = ols.display_name; name = ols.display_name;
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "%s connected.\n", name.c_str()); utils::to_log(LOG_LEVEL_DEBUG, "%s connected.\n", name.c_str());
type = g_supporting_devices[ols.ind].type; type = g_supporting_devices[ols.ind].type;
} }
else if (online_devices_[i].scanner && !online_devices_[i].scanner->is_online()) else if (online_devices_[i].scanner && !online_devices_[i].scanner->is_online())
@ -446,7 +457,7 @@ void hg_scanner_mgr::on_hgscanner_pnp(usb_event ev, libusb_device* device, int v
if (pid == 0x300 || pid == 0x400) if (pid == 0x300 || pid == 0x400)
std::this_thread::sleep_for(std::chrono::milliseconds(1000)); std::this_thread::sleep_for(std::chrono::milliseconds(1000));
len = usb_manager::instance()->open(device, &io); len = usb_manager::instance()->open(device, &io);
VLOG_MINI_3(LOG_LEVEL_WARNING, "[%04x:%04x]%s re-connected.\n", pid, vid, online_devices_[i].display_name.c_str()); utils::to_log(LOG_LEVEL_WARNING, "[%04x:%04x]%s re-connected.\n", pid, vid, online_devices_[i].display_name.c_str());
if (len == SCANNER_ERR_OK) if (len == SCANNER_ERR_OK)
{ {
online_devices_[i].scanner->reset_io(io); online_devices_[i].scanner->reset_io(io);
@ -467,7 +478,7 @@ void hg_scanner_mgr::on_hgscanner_pnp(usb_event ev, libusb_device* device, int v
name = it->display_name; name = it->display_name;
type = g_supporting_devices[it->ind].type; type = g_supporting_devices[it->ind].type;
h = it->scanner; h = it->scanner;
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "%s Dis-connected.\n", name.c_str()); utils::to_log(LOG_LEVEL_DEBUG, "%s Dis-connected.\n", name.c_str());
if (it->scanner) if (it->scanner)
it->scanner->io_disconnected(); it->scanner->io_disconnected();
else else
@ -864,18 +875,7 @@ scanner_err hg_scanner_mgr::hg_scanner_get_parameter(scanner_handle h, const cha
if (user_ == ADMIN_NAME && pwd_ == ADMIN_PWD) if (user_ == ADMIN_NAME && pwd_ == ADMIN_PWD)
{ {
std::string f(hg_log::log_file_path()); return (scanner_err)utils::copy_log_file_to(data);
if (f.empty())
return SCANNER_ERR_NO_DATA;
{
std::ifstream in(f.c_str(), ios::in | ios::binary);
std::ofstream out(data, ios::out | ios::binary);
out << in.rdbuf();
}
remove(f.c_str());
return SCANNER_ERR_OK;
} }
else else
return SCANNER_ERR_ACCESS_DENIED; return SCANNER_ERR_ACCESS_DENIED;
@ -978,9 +978,7 @@ scanner_err hg_scanner_mgr::hg_scanner_set_parameter(scanner_handle h, const cha
{ {
if (user_ == ADMIN_NAME && pwd_ == ADMIN_PWD) if (user_ == ADMIN_NAME && pwd_ == ADMIN_PWD)
{ {
hg_log::clear_log(); return (scanner_err)utils::clear_log_file();
return SCANNER_ERR_OK;
} }
return SCANNER_ERR_ACCESS_DENIED; return SCANNER_ERR_ACCESS_DENIED;
@ -1067,14 +1065,15 @@ scanner_err hg_scanner_mgr::hg_scanner_control(scanner_handle h, unsigned long c
if (!data) if (!data)
return SCANNER_ERR_INVALID_PARAMETER; return SCANNER_ERR_INVALID_PARAMETER;
std::string f(hg_log::log_file_path()); std::string f(utils::temporary_path() + PATH_SEPARATOR + "scanner-tmplog.txt");
if (f.empty()) int ret = utils::copy_log_file_to(f.c_str());
if (ret)
*((char*)data) = 0; *((char*)data) = 0;
else else
strcpy((char*)data, f.c_str()); strcpy((char*)data, f.c_str());
return SCANNER_ERR_OK; return (scanner_err)ret;
} }
else if (!h) else if (!h)
return SCANNER_ERR_INVALID_PARAMETER; return SCANNER_ERR_INVALID_PARAMETER;

View File

@ -1,5 +1,8 @@
#include "usb_manager.h" #include "usb_manager.h"
#include "../wrapper/hg_log.h"
#include "../../sdk/hginclude/utils.h"
#include "../../sdk/hginclude/huagaoxxx_warraper_ex.h"
#include <lang/app_language.h>
#include <iostream> #include <iostream>
#define IF_CLASS(code, cls) \ #define IF_CLASS(code, cls) \
@ -29,7 +32,7 @@ usb_manager::usb_manager() : run_(true)
int ret = libusb_init(&context_); int ret = libusb_init(&context_);
// libusb_set_log_cb(context_, &usb_manager::usb_log_callback, LIBUSB_LOG_CB_CONTEXT); // LIBUSB_API_VERSION >= 0x01000107 // libusb_set_log_cb(context_, &usb_manager::usb_log_callback, LIBUSB_LOG_CB_CONTEXT); // LIBUSB_API_VERSION >= 0x01000107
VLOG_MINI_4(LOG_LEVEL_DEBUG_INFO, "usb_manager(%s) libusb_init(%s) = %s, context = %s\n", hg_log::format_ptr(this).c_str(), hg_log::format_ptr(&context_).c_str(), libusb_error_name(ret), hg_log::format_ptr(context_).c_str()); utils::to_log(LOG_LEVEL_DEBUG, "usb_manager(%p) libusb_init(%p) = %s, context = %p\n", this, &context_, libusb_error_name(ret), context_);
if (ret) if (ret)
status_ = SCANNER_ERR_USB_INIT_FAILED; status_ = SCANNER_ERR_USB_INIT_FAILED;
@ -62,7 +65,7 @@ usb_manager::~usb_manager()
usb_notify_thread_.reset(); usb_notify_thread_.reset();
} }
libusb_exit(context_); libusb_exit(context_);
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "usb_manager(%s) destroying and free context(%s)\n", hg_log::format_ptr(this).c_str(), hg_log::format_ptr(context_).c_str()); utils::to_log(LOG_LEVEL_DEBUG, "usb_manager(%p) destroying and free context(%p)\n", this, context_);
} }
int LIBUSB_CALL usb_manager::usb_pnp_callback(libusb_context* ctx, libusb_device* device, libusb_hotplug_event event, void* monitor) int LIBUSB_CALL usb_manager::usb_pnp_callback(libusb_context* ctx, libusb_device* device, libusb_hotplug_event event, void* monitor)
@ -85,11 +88,11 @@ void usb_manager::usb_log_callback(libusb_context* ctx, libusb_log_level level,
// used when LIBUSB_API_VERSION >= 0x01000107 // used when LIBUSB_API_VERSION >= 0x01000107
if (level == LIBUSB_LOG_LEVEL_NONE || LIBUSB_LOG_LEVEL_INFO || LIBUSB_LOG_LEVEL_DEBUG) if (level == LIBUSB_LOG_LEVEL_NONE || LIBUSB_LOG_LEVEL_INFO || LIBUSB_LOG_LEVEL_DEBUG)
{ {
LOG_INFO(LOG_LEVEL_DEBUG_INFO, str); utils::log_info(str, LOG_LEVEL_DEBUG);
} }
else else
{ {
LOG_INFO(LOG_LEVEL_FATAL, str); utils::log_info(str, LOG_LEVEL_FATAL);
} }
} }
@ -110,7 +113,7 @@ int usb_manager::register_usb_pnp(void)
if (ret != LIBUSB_SUCCESS) if (ret != LIBUSB_SUCCESS)
{ {
LOG_INFO(LOG_LEVEL_FATAL, (std::string("regist usbhotplug callback error msg: ") + libusb_error_name(ret) + "\n").c_str()); utils::to_log(LOG_LEVEL_FATAL, "regist usbhotplug callback error msg: %s\n", libusb_error_name(ret));
usb_cb_handle_ = NULL; usb_cb_handle_ = NULL;
status_ = SCANNER_ERR_USB_REGISTER_PNP_FAILED; status_ = SCANNER_ERR_USB_REGISTER_PNP_FAILED;
} }
@ -227,7 +230,7 @@ void usb_manager::notify_usb_event(PNPDEV& pd, bool* retry)
sprintf(buf, "0x%x", pd.event); sprintf(buf, "0x%x", pd.event);
evstr = buf; evstr = buf;
} }
VLOG_MINI_5(LOG_LEVEL_DEBUG_INFO, "USB%u.%x of pid:vid(%x:%x) event(%s) received.\n" utils::to_log(LOG_LEVEL_DEBUG, "USB%u.%x of pid:vid(%x:%x) event(%s) received.\n"
, HIBYTE(ud.ver), LOBYTE(ud.ver) / 0x10, ud.pid, ud.vid, evstr.c_str()); , HIBYTE(ud.ver), LOBYTE(ud.ver) / 0x10, ud.pid, ud.vid, evstr.c_str());
if (ev != USB_EVENT_NULL) if (ev != USB_EVENT_NULL)
{ {
@ -261,7 +264,7 @@ void usb_manager::thread_trigger_usb_event()
{ {
// ^_^ // ^_^
devices.clear(); devices.clear();
LOG_INFO(LOG_LEVEL_DEBUG_INFO, "register_usb_pnp success ^_^\n"); utils::log_info("register_usb_pnp success ^_^\n", LOG_LEVEL_DEBUG);
break; break;
} }
} }
@ -273,7 +276,7 @@ void usb_manager::thread_trigger_usb_event()
timeval tm={1,0}; timeval tm={1,0};
int ret=libusb_handle_events_timeout(context_, &tm); int ret=libusb_handle_events_timeout(context_, &tm);
if(ret < 0) if(ret < 0)
LOG_INFO(LOG_LEVEL_FATAL, (std::string("libusb_handle_events_timeout error ") + libusb_error_name(ret) + "\n").c_str()); utils::to_log(LOG_LEVEL_FATAL, "libusb_handle_events_timeout error %s\n", libusb_error_name(ret));
std::this_thread::sleep_for(std::chrono::milliseconds(10)); std::this_thread::sleep_for(std::chrono::milliseconds(10));
} }
@ -412,13 +415,12 @@ void usb_manager::enum_endpoints(libusb_device* device, USBTRANSENDP* endp)
{ {
libusb_device_descriptor desc; libusb_device_descriptor desc;
libusb_config_descriptor *conf = NULL; libusb_config_descriptor *conf = NULL;
std::string dev(hg_log::format_ptr(device));
int ret = libusb_get_device_descriptor(device, &desc); int ret = libusb_get_device_descriptor(device, &desc);
bool found_ep = false; bool found_ep = false;
if (ret != 0) if (ret != 0)
{ {
LOG_INFO(LOG_LEVEL_WARNING, (std::string("Get device descriptor of device(") + dev + ") failed.\n").c_str()); utils::to_log(LOG_LEVEL_WARNING, "Get device descriptor of device(%p) failed.\n", device);
return; return;
} }
@ -432,26 +434,26 @@ void usb_manager::enum_endpoints(libusb_device* device, USBTRANSENDP* endp)
usb_manager::init_endpoint(&endp->isochronous); usb_manager::init_endpoint(&endp->isochronous);
} }
else else
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, " +Device(%s) has %u configurations ...\n", dev.c_str(), desc.bNumConfigurations); utils::to_log(LOG_LEVEL_DEBUG, " +Device(%p) has %u configurations ...\n", device, desc.bNumConfigurations);
for (int i = 0; i < (int)desc.bNumConfigurations; ++i) for (int i = 0; i < (int)desc.bNumConfigurations; ++i)
{ {
ret = libusb_get_config_descriptor(device, i, &conf); ret = libusb_get_config_descriptor(device, i, &conf);
if (ret != 0) if (ret != 0)
{ {
if (!endp) if (!endp)
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, " Get %d configuration failed.\n", i + 1); utils::to_log(LOG_LEVEL_DEBUG, " Get %d configuration failed.\n", i + 1);
continue; continue;
} }
if (!endp) if (!endp)
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, " Configuration %d has %d interfaces\n", i + 1, conf->bNumInterfaces); utils::to_log(LOG_LEVEL_DEBUG, " Configuration %d has %d interfaces\n", i + 1, conf->bNumInterfaces);
for (int j = 0; j < conf->bNumInterfaces; ++j) for (int j = 0; j < conf->bNumInterfaces; ++j)
{ {
if (!endp) if (!endp)
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, " Interface %d has %d alt-settings\n", j + 1, conf->interface[j].num_altsetting); utils::to_log(LOG_LEVEL_DEBUG, " Interface %d has %d alt-settings\n", j + 1, conf->interface[j].num_altsetting);
for (int k = 0; k < conf->interface[j].num_altsetting; ++k) for (int k = 0; k < conf->interface[j].num_altsetting; ++k)
{ {
if (!endp) if (!endp)
VLOG_MINI_4(LOG_LEVEL_DEBUG_INFO, " Setting %d: %d - %s has %d endpoints\n", k + 1, conf->interface[j].altsetting[k].bInterfaceNumber utils::to_log(LOG_LEVEL_DEBUG, " Setting %d: %d - %s has %d endpoints\n", k + 1, conf->interface[j].altsetting[k].bInterfaceNumber
, usb_manager::device_class((libusb_class_code)conf->interface[j].altsetting[k].bInterfaceClass).c_str() , usb_manager::device_class((libusb_class_code)conf->interface[j].altsetting[k].bInterfaceClass).c_str()
, conf->interface[j].altsetting[k].bNumEndpoints); , conf->interface[j].altsetting[k].bNumEndpoints);
for (int l = 0; l < conf->interface[j].altsetting[k].bNumEndpoints; ++l) for (int l = 0; l < conf->interface[j].altsetting[k].bNumEndpoints; ++l)
@ -462,27 +464,27 @@ void usb_manager::enum_endpoints(libusb_device* device, USBTRANSENDP* endp)
if (conf->interface[j].altsetting[k].endpoint[l].bmAttributes == LIBUSB_TRANSFER_TYPE_CONTROL) if (conf->interface[j].altsetting[k].endpoint[l].bmAttributes == LIBUSB_TRANSFER_TYPE_CONTROL)
{ {
VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "Found endpoint(%x) for device(VID: %x, PID: %x) of control\n", conf->interface[j].altsetting[k].endpoint[l].bEndpointAddress, desc.idVendor, desc.idProduct); utils::to_log(LOG_LEVEL_DEBUG, "Found endpoint(%x) for device(VID: %x, PID: %x) of control\n", conf->interface[j].altsetting[k].endpoint[l].bEndpointAddress, desc.idVendor, desc.idProduct);
ep = &endp->control; ep = &endp->control;
} }
else if (conf->interface[j].altsetting[k].endpoint[l].bmAttributes == LIBUSB_TRANSFER_TYPE_ISOCHRONOUS) else if (conf->interface[j].altsetting[k].endpoint[l].bmAttributes == LIBUSB_TRANSFER_TYPE_ISOCHRONOUS)
{ {
VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "Found endpoint(%x) for device(VID: %x, PID: %x) of isochronous\n", conf->interface[j].altsetting[k].endpoint[l].bEndpointAddress, desc.idVendor, desc.idProduct); utils::to_log(LOG_LEVEL_DEBUG, "Found endpoint(%x) for device(VID: %x, PID: %x) of isochronous\n", conf->interface[j].altsetting[k].endpoint[l].bEndpointAddress, desc.idVendor, desc.idProduct);
ep = &endp->isochronous; ep = &endp->isochronous;
} }
if (conf->interface[j].altsetting[k].endpoint[l].bmAttributes == LIBUSB_TRANSFER_TYPE_BULK) if (conf->interface[j].altsetting[k].endpoint[l].bmAttributes == LIBUSB_TRANSFER_TYPE_BULK)
{ {
VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "Found endpoint(%x) for device(VID: %x, PID: %x) of bulk\n", conf->interface[j].altsetting[k].endpoint[l].bEndpointAddress, desc.idVendor, desc.idProduct); utils::to_log(LOG_LEVEL_DEBUG, "Found endpoint(%x) for device(VID: %x, PID: %x) of bulk\n", conf->interface[j].altsetting[k].endpoint[l].bEndpointAddress, desc.idVendor, desc.idProduct);
ep = &endp->bulk; ep = &endp->bulk;
} }
if (conf->interface[j].altsetting[k].endpoint[l].bmAttributes == LIBUSB_TRANSFER_TYPE_INTERRUPT) if (conf->interface[j].altsetting[k].endpoint[l].bmAttributes == LIBUSB_TRANSFER_TYPE_INTERRUPT)
{ {
VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "Found endpoint(%x) for device(VID: %x, PID: %x) of interrupt\n", conf->interface[j].altsetting[k].endpoint[l].bEndpointAddress, desc.idVendor, desc.idProduct); utils::to_log(LOG_LEVEL_DEBUG, "Found endpoint(%x) for device(VID: %x, PID: %x) of interrupt\n", conf->interface[j].altsetting[k].endpoint[l].bEndpointAddress, desc.idVendor, desc.idProduct);
ep = &endp->interrupt; ep = &endp->interrupt;
} }
if (conf->interface[j].altsetting[k].endpoint[l].bmAttributes == LIBUSB_TRANSFER_TYPE_BULK_STREAM) if (conf->interface[j].altsetting[k].endpoint[l].bmAttributes == LIBUSB_TRANSFER_TYPE_BULK_STREAM)
{ {
VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "Found endpoint(%x) for device(VID: %x, PID: %x) of bulk-stream\n", conf->interface[j].altsetting[k].endpoint[l].bEndpointAddress, desc.idVendor, desc.idProduct); utils::to_log(LOG_LEVEL_DEBUG, "Found endpoint(%x) for device(VID: %x, PID: %x) of bulk-stream\n", conf->interface[j].altsetting[k].endpoint[l].bEndpointAddress, desc.idVendor, desc.idProduct);
ep = &endp->bulk_stream; ep = &endp->bulk_stream;
} }
if (ep) if (ep)
@ -493,7 +495,7 @@ void usb_manager::enum_endpoints(libusb_device* device, USBTRANSENDP* endp)
else else
s = &ep->out; // = (conf->interface[j].altsetting[k].endpoint[l].bEndpointAddress & 3) | LIBUSB_ENDPOINT_OUT; s = &ep->out; // = (conf->interface[j].altsetting[k].endpoint[l].bEndpointAddress & 3) | LIBUSB_ENDPOINT_OUT;
// NOTE: 这里应该尽é‡<EFBFBD>将输入输出端å<EFBFBD>£ç»Ÿä¸€åˆ°å<EFBFBD>Œä¸€ä¸ªæŽ¥å<EFBFBD>£ä¸Šæ<EFBFBD>¥ï¼Œç®å‰<EFBFBD>未å<EFBFBD>šï¼Œå<EFBFBD>ªå<EFBFBD>第一ä¸? // NOTE: 这里应该尽量将输入输出端口统一到同一个接口上来目前未做只取第一<EFBFBD>?
if (s->port == usb_manager::uninit_uint8) if (s->port == usb_manager::uninit_uint8)
{ {
s->port = conf->interface[j].altsetting[k].endpoint[l].bEndpointAddress & (LIBUSB_ENDPOINT_IN | LIBUSB_ENDPOINT_OUT | 3); s->port = conf->interface[j].altsetting[k].endpoint[l].bEndpointAddress & (LIBUSB_ENDPOINT_IN | LIBUSB_ENDPOINT_OUT | 3);
@ -501,14 +503,14 @@ void usb_manager::enum_endpoints(libusb_device* device, USBTRANSENDP* endp)
s->iface = j; s->iface = j;
s->claimed = 0; s->claimed = 0;
s->max_packet = conf->interface[j].altsetting[k].endpoint[l].wMaxPacketSize; s->max_packet = conf->interface[j].altsetting[k].endpoint[l].wMaxPacketSize;
VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, " Endpoint address = 0x%02x, origin = 0x%02x, max packet: 0x%x\n", s->port, conf->interface[j].altsetting[k].endpoint[l].bEndpointAddress utils::to_log(LOG_LEVEL_DEBUG, " Endpoint address = 0x%02x, origin = 0x%02x, max packet: 0x%x\n", s->port, conf->interface[j].altsetting[k].endpoint[l].bEndpointAddress
, s->max_packet); , s->max_packet);
} }
found_ep = true; found_ep = true;
} }
} }
else else
VLOG_MINI_4(LOG_LEVEL_DEBUG_INFO, " Endpoint %d(%s) address: %x, Max packet: 0x%x bytes\n", l + 1 utils::to_log(LOG_LEVEL_DEBUG, " Endpoint %d(%s) address: %x, Max packet: 0x%x bytes\n", l + 1
, usb_manager::endpoint_type((libusb_transfer_type)conf->interface[j].altsetting[k].endpoint[l].bmAttributes).c_str() , usb_manager::endpoint_type((libusb_transfer_type)conf->interface[j].altsetting[k].endpoint[l].bmAttributes).c_str()
, conf->interface[j].altsetting[k].endpoint[l].bEndpointAddress , conf->interface[j].altsetting[k].endpoint[l].bEndpointAddress
, conf->interface[j].altsetting[k].endpoint[l].wMaxPacketSize); , conf->interface[j].altsetting[k].endpoint[l].wMaxPacketSize);
@ -519,7 +521,7 @@ void usb_manager::enum_endpoints(libusb_device* device, USBTRANSENDP* endp)
} }
if (endp && !found_ep) if (endp && !found_ep)
VLOG_MINI_2(LOG_LEVEL_FATAL, "No endpoint has been found on device (VID: %x, PID: %x)\n", desc.idVendor, desc.idProduct); utils::to_log(LOG_LEVEL_FATAL, "No endpoint has been found on device (VID: %x, PID: %x)\n", desc.idVendor, desc.idProduct);
} }
int usb_manager::register_hotplug(usb_event_handler cb, void* user) int usb_manager::register_hotplug(usb_event_handler cb, void* user)
@ -558,7 +560,7 @@ int usb_manager::open(libusb_device* device, usb_io** usbio, std::string* msg)
if (msg) if (msg)
*msg = usb->init_error_msg(); *msg = usb->init_error_msg();
usb->release(); usb->release();
VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "Open %04x:%04x failed: %s\n", dev.vid, dev.pid, hg_scanner_err_name(err)); utils::to_log(LOG_LEVEL_DEBUG, "Open %04x:%04x failed: %s\n", dev.vid, dev.pid, hg_scanner_err_name(err));
return err; return err;
} }
@ -630,7 +632,7 @@ bool usb_io::make_singleton(void)
str.insert(0, "\350\256\276\345\244\207\345\267\262\347\273\217\350\242\253\350\277\233\347\250\213 '"); str.insert(0, "\350\256\276\345\244\207\345\267\262\347\273\217\350\242\253\350\277\233\347\250\213 '");
str += "' \345\215\240\347\224\250"; str += "' \345\215\240\347\224\250";
init_err_msg_ = str; init_err_msg_ = str;
VLOG_MINI_1(LOG_LEVEL_FATAL, "Open failed: %s\n", str.c_str()); utils::to_log(LOG_LEVEL_FATAL, "Open failed: %s\n", str.c_str());
return false; return false;
} }
@ -651,38 +653,38 @@ bool usb_io::claim_interterface(usb_manager::USBSIMPLEX* spl)
return true; return true;
} }
VLOG_MINI_2(LOG_LEVEL_FATAL, "libusb_claim_interface(%d) = %s, now try some actions ...\n", spl->iface, libusb_error_name(ret)); utils::to_log(LOG_LEVEL_FATAL, "libusb_claim_interface(%d) = %s, now try some actions ...\n", spl->iface, libusb_error_name(ret));
ret = libusb_kernel_driver_active(handle_, spl->iface); ret = libusb_kernel_driver_active(handle_, spl->iface);
if (ret == 1) if (ret == 1)
{ {
ret = libusb_detach_kernel_driver(handle_, spl->iface); ret = libusb_detach_kernel_driver(handle_, spl->iface);
VLOG_MINI_2(LOG_LEVEL_FATAL, " libusb_detach_kernel_driver(%d) = %s\n", spl->iface, libusb_error_name(ret)); utils::to_log(LOG_LEVEL_FATAL, " libusb_detach_kernel_driver(%d) = %s\n", spl->iface, libusb_error_name(ret));
} }
else if (ret == LIBUSB_ERROR_NO_DEVICE) else if (ret == LIBUSB_ERROR_NO_DEVICE)
{ {
last_err_ = SCANNER_ERR_DEVICE_NOT_FOUND; last_err_ = SCANNER_ERR_DEVICE_NOT_FOUND;
VLOG_MINI_1(LOG_LEVEL_FATAL, " device(%s) maybe left when libusb_kernel_driver_active.\n", hg_log::format_ptr(dev_info_.device).c_str()); utils::to_log(LOG_LEVEL_FATAL, " device(%p) maybe left when libusb_kernel_driver_active.\n", dev_info_.device);
return false; return false;
} }
else else
{ {
VLOG_MINI_2(LOG_LEVEL_FATAL, " libusb_kernel_driver_active(%d) = %d\n", spl->iface, ret); utils::to_log(LOG_LEVEL_FATAL, " libusb_kernel_driver_active(%d) = %d\n", spl->iface, ret);
} }
ret = libusb_clear_halt(handle_, spl->port); ret = libusb_clear_halt(handle_, spl->port);
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, " libusb_clear_halt(%x) = %s\n", spl->port, libusb_error_name(ret)); utils::to_log(LOG_LEVEL_DEBUG, " libusb_clear_halt(%x) = %s\n", spl->port, libusb_error_name(ret));
ret = libusb_release_interface(handle_, spl->iface); ret = libusb_release_interface(handle_, spl->iface);
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, " libusb_release_interface(%u) = %s\n", spl->iface, libusb_error_name(ret)); utils::to_log(LOG_LEVEL_DEBUG, " libusb_release_interface(%u) = %s\n", spl->iface, libusb_error_name(ret));
ret = libusb_set_configuration(handle_, spl->iconf); ret = libusb_set_configuration(handle_, spl->iconf);
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, " libusb_set_configuration(%u) = %s\n", spl->iconf, libusb_error_name(ret)); utils::to_log(LOG_LEVEL_DEBUG, " libusb_set_configuration(%u) = %s\n", spl->iconf, libusb_error_name(ret));
//ret = libusb_reset_device(handle_); //ret = libusb_reset_device(handle_);
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, " libusb_reset_device = %s\n", libusb_error_name(ret)); //utils::to_log(LOG_LEVEL_DEBUG, " libusb_reset_device = %s\n", libusb_error_name(ret));
//if (ret == LIBUSB_ERROR_NOT_FOUND) //if (ret == LIBUSB_ERROR_NOT_FOUND)
//{ //{
// last_err_ = usb_manager::usb_error_2_hg_err(ret); // last_err_ = usb_manager::usb_error_2_hg_err(ret);
// VLOG_MINI_1(LOG_LEVEL_FATAL, "device(%s) maybe left when libusb_reset_device.\n", hg_log::format_ptr(dev_info_.device).c_str()); // utils::to_log(LOG_LEVEL_FATAL, "device(%s) maybe left when libusb_reset_device.\n", hg_log::format_ptr(dev_info_.device).c_str());
// //
// return false; // return false;
//} //}
@ -692,11 +694,11 @@ bool usb_io::claim_interterface(usb_manager::USBSIMPLEX* spl)
if (ret == LIBUSB_SUCCESS) if (ret == LIBUSB_SUCCESS)
{ {
spl->claimed = true; spl->claimed = true;
VLOG_MINI_2(LOG_LEVEL_FATAL, "second libusb_claim_interface(%d) = %s\n", spl->iface, libusb_error_name(ret)); utils::to_log(LOG_LEVEL_FATAL, "second libusb_claim_interface(%d) = %s\n", spl->iface, libusb_error_name(ret));
return true; return true;
} }
VLOG_MINI_2(LOG_LEVEL_FATAL, "second try libusb_claim_interface(%d) = %s\n", spl->iface, libusb_error_name(ret)); utils::to_log(LOG_LEVEL_FATAL, "second try libusb_claim_interface(%d) = %s\n", spl->iface, libusb_error_name(ret));
last_err_ = SCANNER_ERR_USB_CLAIM_INTERFACE_FAILED; last_err_ = SCANNER_ERR_USB_CLAIM_INTERFACE_FAILED;
return false; return false;
@ -717,7 +719,7 @@ int usb_io::claim_interfaces(bool claim)
break; break;
claimed.push_back(eps[i]->in.iface); claimed.push_back(eps[i]->in.iface);
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "claimed %s interface %d\n", usb_manager::endpoint_type((libusb_transfer_type)i).c_str(), eps[i]->in.iface); utils::to_log(LOG_LEVEL_DEBUG, "claimed %s interface %d\n", usb_manager::endpoint_type((libusb_transfer_type)i).c_str(), eps[i]->in.iface);
} }
if (eps[i]->out.port != usb_manager::uninit_uint8 && eps[i]->out.iface != eps[i]->in.iface if (eps[i]->out.port != usb_manager::uninit_uint8 && eps[i]->out.iface != eps[i]->in.iface
&& std::find(claimed.begin(), claimed.end(), eps[i]->out.iface) == claimed.end()) && std::find(claimed.begin(), claimed.end(), eps[i]->out.iface) == claimed.end())
@ -725,7 +727,7 @@ int usb_io::claim_interfaces(bool claim)
if (!claim_interterface(&eps[i]->out)) if (!claim_interterface(&eps[i]->out))
break; break;
claimed.push_back(eps[i]->out.iface); claimed.push_back(eps[i]->out.iface);
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "claimed %s interface %d\n", usb_manager::endpoint_type((libusb_transfer_type)i).c_str(), eps[i]->out.iface); utils::to_log(LOG_LEVEL_DEBUG, "claimed %s interface %d\n", usb_manager::endpoint_type((libusb_transfer_type)i).c_str(), eps[i]->out.iface);
} }
} }
} }
@ -766,8 +768,7 @@ void usb_io::open(void)
ref_device_ = libusb_ref_device(dev_info_.device); ref_device_ = libusb_ref_device(dev_info_.device);
int ret = libusb_open(dev_info_.device, &handle_); int ret = libusb_open(dev_info_.device, &handle_);
VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "call libusb_open(%s, %s) = %s\n", hg_log::format_ptr(dev_info_.device).c_str() utils::to_log(LOG_LEVEL_DEBUG, "call libusb_open(%p, %p) = %s\n", dev_info_.device, handle_, libusb_error_name(ret));
, hg_log::format_ptr(handle_).c_str(), libusb_error_name(ret));
if (ret == LIBUSB_SUCCESS) if (ret == LIBUSB_SUCCESS)
{ {
init_after_open(); init_after_open();
@ -782,7 +783,7 @@ void usb_io::open(void)
return; return;
} }
last_err_ = usb_manager::usb_error_2_hg_err(ret); last_err_ = usb_manager::usb_error_2_hg_err(ret);
VLOG_MINI_4(LOG_LEVEL_FATAL, "Open USB%u.%u-%s failed: %s\n", HIBYTE(dev_info_.ver), LOBYTE(dev_info_.ver) / 0x10, hg_log::format_ptr(dev_info_.device).c_str(), libusb_error_name(ret)); utils::to_log(LOG_LEVEL_FATAL, "Open USB%u.%u-%p failed: %s\n", HIBYTE(dev_info_.ver), LOBYTE(dev_info_.ver) / 0x10, dev_info_.device, libusb_error_name(ret));
init_err_msg_ = hg_scanner_err_description(last_err_); init_err_msg_ = hg_scanner_err_description(last_err_);
handle_ = NULL; handle_ = NULL;
} }
@ -794,8 +795,8 @@ bool usb_io::on_io_error(scanner_err err, usb_manager::USBSIMPLEX* endp)
if (err == SCANNER_ERR_TIMEOUT) if (err == SCANNER_ERR_TIMEOUT)
{ {
//å ä¸ºåœ¨å<EFBFBD>é€<EFBFBD>imgå<EFBFBD>数出现timeout,æšæ—¶ç¦<EFBFBD>ç”? //因为在发送img参数出现timeout暂时禁<EFBFBD>?
// //LOG_INFO(LOG_LEVEL_DEBUG_INFO, "Operation timeout\n"); // //utils::log_info(LOG_LEVEL_DEBUG, "Operation timeout\n");
// libusb_clear_halt(handle_, endp->port); // libusb_clear_halt(handle_, endp->port);
// return libusb_reset_device(handle_) == LIBUSB_SUCCESS; // return libusb_reset_device(handle_) == LIBUSB_SUCCESS;
@ -861,7 +862,7 @@ int usb_io::control_io(uint8_t type, uint8_t req, uint16_t val, uint16_t ind, vo
//} //}
//else //else
*len = 0; *len = 0;
VLOG_MINI_5(LOG_LEVEL_DEBUG_INFO, "libusb_control_transfer(%x, %x, %d, %d) = %s\n", type, req, val, ind, libusb_error_name(ret)); utils::to_log(LOG_LEVEL_DEBUG, "libusb_control_transfer(%x, %x, %d, %d) = %s\n", type, req, val, ind, libusb_error_name(ret));
last_err_ = usb_manager::usb_error_2_hg_err(ret); last_err_ = usb_manager::usb_error_2_hg_err(ret);
} }
@ -894,14 +895,14 @@ int usb_io::read_bulk(void* buf, int* len)
if (err) if (err)
{ {
VLOG_MINI_4(LOG_LEVEL_DEBUG_INFO, "read_bulk(%x, %d/%d) = %s\n", endpoints_.bulk.in.port, total, *len, libusb_error_name(err)); utils::to_log(LOG_LEVEL_DEBUG, "read_bulk(%x, %d/%d) = %s\n", endpoints_.bulk.in.port, total, *len, libusb_error_name(err));
if (err == LIBUSB_ERROR_TIMEOUT && *len == total) if (err == LIBUSB_ERROR_TIMEOUT && *len == total)
{ {
int old = to_; int old = to_;
if(to_ < 10 * 1000) if(to_ < 10 * 1000)
to_ *= 1.5f; to_ *= 1.5f;
//err = LIBUSB_SUCCESS; //err = LIBUSB_SUCCESS;
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, " Read full length, we consider it as success, and increament timeout from %d to %d\n", old, to_); utils::to_log(LOG_LEVEL_DEBUG, " Read full length, we consider it as success, and increament timeout from %d to %d\n", old, to_);
} }
} }
*len = total; *len = total;
@ -930,7 +931,7 @@ int usb_io::write_bulk(void* buf, int* len)
err = usb_manager::usb_error_2_hg_err(libusb_bulk_transfer(handle_, endpoints_.bulk.out.port, data, *len, &t, to_)); err = usb_manager::usb_error_2_hg_err(libusb_bulk_transfer(handle_, endpoints_.bulk.out.port, data, *len, &t, to_));
//VLOG_MINI_6(LOG_LEVEL_DEBUG_INFO, "First write port %x bulk %d/%d = %s(timeout = %d, packet size = %x)\n", endpoints_.bulk.out.port, t, *len, hg_scanner_err_name((scanner_err)err).c_str(), to_, endpoints_.bulk.out.max_packet); //VLOG_MINI_6(LOG_LEVEL_DEBUG, "First write port %x bulk %d/%d = %s(timeout = %d, packet size = %x)\n", endpoints_.bulk.out.port, t, *len, hg_scanner_err_name((scanner_err)err).c_str(), to_, endpoints_.bulk.out.max_packet);
// printf("First write port %x bulk %d/%d = %s(timeout = %d, packet size = %x)\n", endpoints_.bulk.out.port, t, *len, hg_scanner_err_name((scanner_err)err).c_str(), to_, endpoints_.bulk.out.max_packet); // printf("First write port %x bulk %d/%d = %s(timeout = %d, packet size = %x)\n", endpoints_.bulk.out.port, t, *len, hg_scanner_err_name((scanner_err)err).c_str(), to_, endpoints_.bulk.out.max_packet);
if (!on_io_error((scanner_err)err, &endpoints_.bulk.out)) if (!on_io_error((scanner_err)err, &endpoints_.bulk.out))
{ {
@ -949,7 +950,7 @@ int usb_io::write_bulk(void* buf, int* len)
err = usb_manager::usb_error_2_hg_err(libusb_bulk_transfer(handle_, endpoints_.bulk.out.port, data, *len - total, &t, to_)); err = usb_manager::usb_error_2_hg_err(libusb_bulk_transfer(handle_, endpoints_.bulk.out.port, data, *len - total, &t, to_));
total += t; total += t;
} }
//VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "Last write bulk %d/%d = %s\n", total, *len, hg_scanner_err_name((scanner_err)err).c_str()); //utils::to_log(LOG_LEVEL_DEBUG, "Last write bulk %d/%d = %s\n", total, *len, hg_scanner_err_name((scanner_err)err).c_str());
*len = total; *len = total;
last_err_ = err; last_err_ = err;

View File

@ -13,7 +13,7 @@ add_compile_options(-std=c++11)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -O2") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -O2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -O2") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -O2")
aux_source_directory(${PROJECT_SOURCE_DIR} DIR_SRCS) aux_source_directory(${PROJECT_SOURCE_DIR} DIR_SRCS)
file(GLOB DIR_HEADS "${PROJECT_SOURCE_DIR}/*.h" "${PROJECT_SOURCE_DIR}/*.hpp") file(GLOB DIR_HEADS "${PROJECT_SOURCE_DIR}/*.h" "${PROJECT_SOURCE_DIR}/*.hpp" "${PROJECT_SOURCE_DIR}/../../sdk/hginclude/*.h" "${PROJECT_SOURCE_DIR}/../../sdk/hginclude/*.cpp")
set(DIR_SRCS ${DIR_SRCS} ${DIR_HEADS}) set(DIR_SRCS ${DIR_SRCS} ${DIR_HEADS})
if(COMMAND cmake_policy) if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW) cmake_policy(SET CMP0003 NEW)
@ -98,6 +98,7 @@ target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}/../ImageProcess ${PROJECT_SOURCE_DIR}/../ImageProcess
${PROJECT_SOURCE_DIR}/../hgdev ${PROJECT_SOURCE_DIR}/../hgdev
${PROJECT_SOURCE_DIR}/../wrapper ${PROJECT_SOURCE_DIR}/../wrapper
${PROJECT_SOURCE_DIR}/../sdk/hginclude
${PROJECT_SOURCE_DIR}/../../../sdk/include ${PROJECT_SOURCE_DIR}/../../../sdk/include
) )
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/../../../release/uos/${CMAKE_SYSTEM_PROCESSOR}) set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/../../../release/uos/${CMAKE_SYSTEM_PROCESSOR})

View File

@ -1,889 +0,0 @@
#include <vector>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <stdarg.h>
#include <huagao/brand.h>
#if defined(WIN32) || defined(_WIN64)
#include <Windows.h>
#include <direct.h>
#include <Psapi.h>
#include <Tlhelp32.h>
#include <imagehlp.h>
#define MKDIR(a, b) mkdir(a)
#pragma comment(lib, "imagehlp.lib")
#pragma comment(lib, "Psapi.lib")
#pragma comment(lib, "shlwapi.lib")
#else
#define MKDIR(a, b) mkdir(a, b)
#include <pthread.h>
#include <sys/sysinfo.h>
#include <unistd.h>
#include <dirent.h>
#include <fcntl.h>
#include <sys/stat.h>
#endif
#include <time.h>
#include "../wrapper/hg_log.h"
#include <algorithm>
#include <mutex>
#include "ini_file.h"
#define VMRSS_LINE 21 //ʵ¼ÊÎïÀíÄÚ´æʹÓÃÂÊ
#define MAX_LOG_FILE_SIZE 10 * 1024 * 1024
#ifdef _INTSIZEOF
#undef _INTSIZEOF
#define _INTSIZEOF(n) ((sizeof(n) + sizeof(long) - 1) & ~(sizeof(long) - 1))
#endif
extern std::string g_scanner_path; // Ending with '\\'
static std::string log_divider("=========================================================================\n");
class log_cls
{
typedef void(*log_to)(const char*, void*, void*);
std::string path_file_;
FILE* file_;
log_to log_;
int level_;
log_callback lcb_;
std::mutex lock_;
static log_cls* inst_;
static FILE* create_log_file(const char* path_file, bool truncate)
{
FILE* file_ = fopen(path_file, "a+b");
if (file_)
{
fseek(file_, 0, SEEK_END);
if (ftell(file_) == 0)
{
unsigned char bom[] = { 0x0ef, 0x0bb, 0x0bf };
fwrite(bom, sizeof(bom), 1, file_);
}
std::string now(g_time_tag + hg_log::current_time() + g_time_tag);
now += truncate ? " trcated.\n" : " started.\n";
now.insert(0, log_divider);
fwrite(now.c_str(), 1, now.length(), file_);
}
return file_;
}
static void log_none(const char* info, void* param, void* param2)
{}
static void log_consonle(const char* info, void* param, void* param2)
{
printf(info);
}
static void log_file(const char* info, void* param, void* param2)
{
FILE** file = (FILE**)param;
if(*file == nullptr)
*file = create_log_file(((std::string*)param2)->c_str(), false);
if (*file)
{
fwrite(info, 1, strlen(info), *file);
fflush(*file);
if (ftell(*file) >= MAX_LOG_FILE_SIZE)
{
fclose(*file);
remove(((std::string*)param2)->c_str());
*file = create_log_file(((std::string*)param2)->c_str(), true);
}
}
}
protected:
log_cls() : path_file_(""), file_(0), log_(&log_cls::log_consonle), level_(LOG_LEVEL_ALL), lcb_(NULL)
{}
~log_cls()
{
if (file_)
{
fclose(file_);
file_ = 0;
}
}
public:
static std::string g_time_tag;
static log_cls* instance(void)
{
if (!log_cls::inst_)
log_cls::inst_ = new log_cls();
return log_cls::inst_;
}
int set_log_type(int type, void* param)
{
int ret = 0;
if (file_)
{
fclose(file_);
file_ = 0;
}
lcb_ = NULL;
log_ = NULL;
if (type == LOG_TYPE_NONE)
log_ = &log_cls::log_none;
else if(type == LOG_TYPE_CONSOLE)
log_ = &log_cls::log_consonle;
else if (type == LOG_TYPE_FILE)
{
log_ = &log_cls::log_file;
ret = -1;
if (param)
{
path_file_ = (char*)param;
file_ = create_log_file(path_file_.c_str(), false);
if (file_)
ret = 0;
}
}
else if (type == LOG_TYPE_CALLBACK)
{
lcb_ = (log_callback)param;
}
if(ret != 0)
log_ = &log_cls::log_none;
return ret;
}
void set_log_level(int level)
{
level_ = level;
}
bool is_log_level_enabled(int level)
{
return level >= level_;
}
void log(const char* info)
{
std::lock_guard<std::mutex> lock(lock_);
log_(info, &file_, &path_file_);
}
std::string get_log_file_path(bool copy)
{
std::string file("");
if (log_ == &log_cls::log_file && file_)
{
file = path_file_;
if (copy)
{
file += ".txt";
FILE* dst = fopen(file.c_str(), "wb");
if (!dst)
file = "";
else
{
std::lock_guard<std::mutex> lock(lock_);
char buf[1024] = { 0 };
size_t l = 0;
fseek(file_, 0, SEEK_SET);
while ((l = fread(buf, 1, sizeof(buf), file_)))
fwrite(buf, 1, l, dst);
fclose(dst);
}
}
}
return file;
}
void clear_log(void)
{
if (log_ == &log_cls::log_file && file_)
{
std::lock_guard<std::mutex> lock(lock_);
fclose(file_);
remove(path_file_.c_str());
file_ = create_log_file(path_file_.c_str(), true);
}
}
};
log_cls* log_cls::inst_ = NULL;
std::string log_cls::g_time_tag = "=====";
#ifdef EXPORT_AS_C
extern "C"
{
#endif
namespace hg_log
{
static simple_ini ini_;
static log_callback lcb_ = NULL;
typedef struct _find_file
{
std::string pattern;
std::string found;
}FINDFILE, * LPFF;
static bool on_found(const char* file, void* param)
{
LPFF lpff = (LPFF)param;
char pth = PATH_SEPARATOR[0];
const char* name = strrchr(file, pth);
if (name++ == nullptr)
name = file;
std::string lc(name);
str_tolower(lc);
if (lc.find(lpff->pattern) != std::string::npos)
{
lpff->found = file;
return false;
}
return true;
}
#if defined(WIN32) || defined(_WIN64)
static std::string u2a(const wchar_t* u, UINT cp = CP_ACP)
{
std::string a("");
if (u)
{
char stack[256] = { 0 }, * ansi = NULL;
int len = 0;
len = WideCharToMultiByte(cp, 0, u, lstrlenW(u), NULL, 0, NULL, NULL);
ansi = new char[len + 2];
len = WideCharToMultiByte(cp, 0, u, lstrlenW(u), ansi, len, NULL, NULL);
ansi[len--] = 0;
a = ansi;
delete[] ansi;
}
return a;
}
static int enum_files(const char* dir, bool recursive, bool(*found_file)(const char* path_file, void* param), void* param)
{
int ret = 0;
HANDLE h = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, GetCurrentProcessId());
MODULEENTRY32W pei = { 0 };
if (h == INVALID_HANDLE_VALUE)
ret = GetLastError();
else
{
pei.dwSize = sizeof(pei);
if (Module32FirstW(h, &pei))
{
do
{
std::string ansi(u2a(pei.szExePath));
if (!found_file(ansi.c_str(), param))
break;
pei.dwSize = sizeof(pei);
} while (Module32NextW(h, &pei));
}
CloseHandle(h);
}
return ret;
}
#else
static std::string link_file(const char* lnk)
{
char path[256] = { 0 };
int len = readlink(lnk, path, sizeof(path) - 1);
return len > 0 ? path : lnk;
}
static int enum_files(const char* dir, bool recursive, bool(*found_file)(const char* path_file, void* param), void* param)
{
int ret = 0;
DIR* pdir = nullptr;
struct dirent* ent = nullptr;
pdir = opendir(dir);
if (!pdir)
return errno;
while ((ent = readdir(pdir)))
{
if (ent->d_type & DT_DIR)
{
if (recursive)
{
if (strcmp(ent->d_name, ".") && strcmp(ent->d_name, ".."))
{
std::string sub(dir);
sub += "/";
sub += ent->d_name;
ret = enum_files(sub.c_str(), recursive, found_file, param);
if (ret == 0x5e17)
break;
}
}
}
else
{
std::string file(dir);
file += "/";
file += ent->d_name;
if (!found_file(link_file(file.c_str()).c_str(), param))
{
ret = 0x5e17;
break;
}
}
}
return ret;
}
#endif
std::string get_scanimage_ver()
{
#if defined(WIN32) || defined(_WIN64)
return "";
#else
FILE* fp = NULL;
char buf[128] = { 0 };
fp = popen("scanimage -V", "r");
if (!fp)
return "";
int ret = fread(buf, 1, sizeof(buf) - 1, fp);
if(ret<1)
return "";
pclose(fp);
std::string str = buf;
return str.substr(str.size()-7);
#endif
}
void clear_log(void)
{
log_cls::instance()->clear_log();
}
//static std::string get_scanimage_ver()
//{
// FILE* fp = popen("scanimage -V","r");
// if (!fp)
// {
// return "";
// }
// long len = 0;
// fseek(fp, 0, SEEK_END);
// len = ftell(fp);
// fseek(fp, 0, SEEK_SET);
// char* buf = new char[len];
// if (!buf)
// {
// return "";
// }
// int ret = fread(buf, 1, sizeof(buf) - 1, fp);
// pclose();
//}
std::string format_ptr(void* ptr)
{
char buf[40];
if (sizeof(ptr) == sizeof(int))
{
sprintf(buf, "0x%08x", ptr);
}
else
{
unsigned int* n = (unsigned int*)&ptr;
sprintf(buf, "0x%x%08x", n[1], n[0]);
}
return buf;
}
std::string format_current_thread_id(void)
{
#if defined(WIN32) || defined(_WIN64)
return format_ptr((void*)GetCurrentThreadId());
#else
return format_ptr((void*)pthread_self());
#endif
}
std::string current_time(void)
{
char buf[40] = { 0 };
hg_get_current_time(buf);
return buf;
}
std::string format_size(unsigned long size)
{
char buf[40];
if (size > 1024 * 1024 * 1024)
{
double d = size;
d /= 1024 * 1024 * 1024;
sprintf(buf, "%.2fGB", d);
}
else if (size > 1024 * 1024)
{
double d = size;
d /= 1024 * 1024;
sprintf(buf, "%.2fMB", d);
}
else if (size > 1024)
{
double d = size;
d /= 1024;
sprintf(buf, "%.1fKB", d);
}
else
{
sprintf(buf, "%u bytes", (unsigned int)size);
}
return buf;
}
std::string u2utf8(const wchar_t* u)
{
std::string utf8("");
#if defined(WIN32) || defined(_WIN64)
utf8 = u2a(u, CP_UTF8);
#else
#endif
return utf8;
}
std::string pe_path(std::string* name)
{
#if defined(WIN32) || defined(_WIN64)
wchar_t path[MAX_PATH] = { 0 }, * last = NULL;
GetModuleFileNameW(NULL, path, _countof(path) - 1);
last = wcsrchr(path, L'\\');
if (last)
{
if (name)
*name = u2utf8(last + 1);
*last = 0;
}
return u2utf8(path);
#else
char path[256] = { 0 };
int len = readlink("/proc/self/exe", path, sizeof(path) - 1);
if (len > 0 && len < sizeof(path))
{
for (--len; len > 0; --len)
{
if (path[len] == '/')
{
path[len] = 0;
if (name)
*name = path + len + 1;
break;
}
}
}
return path;
#endif
}
unsigned long long available_memory(void)
{
#if defined(WIN32) || defined(_WIN64)
MEMORYSTATUSEX ms;
if (GlobalMemoryStatusEx(&ms))
return ms.ullAvailPhys;
else
return -1;
#else
struct sysinfo si;
if (sysinfo(&si) == 0)
return si.freeram * si.mem_unit;
#endif
}
void str_tolower(std::string& str)
{
std::transform(str.begin(), str.end(), str.begin(), tolower);
}
bool create_folder(const char* fodler)
{
return MKDIR(fodler, S_IREAD | S_IWRITE | S_IEXEC) == 0 || errno == EEXIST;
}
std::string ini_get(const char* app, const char* key)
{
return ini_.get(app, key);
}
void ini_set(const char* app, const char* key, const char* val)
{
ini_.set(app, key, val);
}
std::string get_module_full_path(const char* module_part_name)
{
char path[128] = { 0 };
FINDFILE ff;
ff.pattern = module_part_name;
str_tolower(ff.pattern);
#if defined(WIN32) || defined(_WIN64)
#else
sprintf(path, "/proc/%u/map_files/", getpid());
#endif
enum_files(path, false, on_found, &ff);
return ff.found;
}
std::string get_scanner_path(void)
{
return g_scanner_path;
}
unsigned int get_page_size(unsigned int* map_unit)
{
unsigned int ps = 1024;
#if defined(WIN32) || defined(_WIN64)
SYSTEM_INFO si = { 0 };
GetSystemInfo(&si);
ps = si.dwPageSize;
if (map_unit)
*map_unit = si.dwAllocationGranularity;
#else
ps = sysconf(_SC_PAGESIZE);
if(ps < 1024 || (ps & 0x0fe0000ff)) // nKB && < 16MB
ps = getpagesize();
if (map_unit)
*map_unit = ps;
#endif
if (ps < 1024 || (ps & 0x0fe0000ff)) // nKB && < 16MB
ps = 1024;
return ps;
}
static int get_log_config(const std::string& root, hg_log_type* type, std::string* path)
{
std::string me(root + PATH_SEPARATOR + "config" + PATH_SEPARATOR + "debug.cfg");
int lv = LOG_LEVEL_ALL;
hg_log_type tp = LOG_TYPE_FILE;
if (!type)
type = &tp;
*type = LOG_TYPE_FILE;
if (ini_.load(me.c_str()) == 0)
{
std::string val(ini_.get("log", "type"));
if (val == "console")
*type = LOG_TYPE_CONSOLE;
else if (val == "none")
*type = LOG_TYPE_NONE;
else
*type = LOG_TYPE_FILE;
if (*type == LOG_TYPE_FILE && path)
{
*path = ini_.get("log", "path");
}
val = ini_.get("log", "level");
if (val == "debug")
lv = LOG_LEVEL_DEBUG_INFO;
else if (val == "warning")
lv = LOG_LEVEL_WARNING;
else if (val == "fatal")
lv = LOG_LEVEL_FATAL;
}
else
create_folder((root + PATH_SEPARATOR + "config").c_str());
return lv;
}
std::string get_command_result(const char* cmd, int len)
{
std::string result("");
#if OS_WIN
#else
FILE* src = popen(cmd, "r");
if (src)
{
char buf[128] = { 0 };
int rv = fread(buf, 1, sizeof(buf) - 1, src);
while (rv > 0)
{
buf[rv] = 0;
result += buf;
if (len != -1 && result.length() >= len)
{
result.erase(len);
break;
}
rv = fread(buf, 1, sizeof(buf) - 1, src);
}
pclose(src);
}
#endif
return std::move(result);
}
const char* trim(std::string& str, const char* sp = " \r\n\t")
{
int pos = 0;
char ch[2] = { 0 };
for (; pos < str.length(); ++pos)
{
ch[0] = str[pos];
if (!strstr(sp, ch))
break;
}
if (pos)
str.erase(0, pos);
pos = str.length() - 1;
for (; pos >= 0; --pos)
{
ch[0] = str[pos];
if (!strstr(sp, ch))
break;
}
if (++pos < str.length())
str.erase(pos);
return str.c_str();
}
std::string get_local_data_path(void)
{
static std::string ldp("");
if (ldp.empty())
{
#if OS_WIN
const char* path(getenv("LOCALAPPDATA"));
if (path)
{
ldp = path;
ldp += PATH_SEPARATOR;
}
#else
const char* path(getenv("HOME"));
if (path)
{
if (strstr(path, "/root"))
{
std::string usr(get_command_result("logname", -1));
ldp = std::string("/home/") + trim(usr);
if (!opendir(ldp.c_str()))
{
printf("opendir(%s) failed: %s\n", ldp.c_str(), strerror(errno));
ldp = path;
}
}
else
{
ldp = path;
}
ldp += std::string(PATH_SEPARATOR) + ".";
}
#endif
ldp += PRODUCT_VENDOR;
ldp += "Scan";
create_folder(ldp.c_str());
printf("# local data path: %s\n", ldp.c_str());
}
return ldp;
}
std::string local_data_path(void)
{
static std::string local_data_path("");
static bool load_first = true;
if (load_first)
{
simple_ini first;
load_first = false;
if (first.load((get_scanner_path() + "first.cfg").c_str()) == 0)
{
std::string env = first.get("constraints", "local_data_path");
if (env.length())
local_data_path = env;
}
}
std::string home(local_data_path);
if (home.empty())
{
local_data_path = home = get_local_data_path();
}
return std::move(home);
}
std::string temporary_path(void)
{
return simple_ini::temporary_path();
}
std::string log_file_path(void)
{
return log_cls::instance()->get_log_file_path(true);
}
int init(void)
{
char* file = nullptr;
std::string path("");
hg_log_type type = LOG_TYPE_FILE;
int level = get_log_config(local_data_path(), &type, &path);
if (type == LOG_TYPE_FILE)
{
std::string name(""),
paths[] = { local_data_path(), pe_path(&name), get_scanner_path(), temporary_path()};
int ind = 0;
if (!path.empty() && create_folder(path.c_str()))
ind = sizeof(paths) / sizeof(paths[0]) + 2;
for (; ind < sizeof(paths) / sizeof(paths[0]); ++ind)
{
path = paths[ind] + PATH_SEPARATOR + "Log";
if (create_folder(path.c_str()))
break;
}
if(ind == sizeof(paths) / sizeof(paths[0]))
{
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "# Try PE, scanner and temporary path failed(%d), log to console\n", errno);
type = LOG_TYPE_CONSOLE;
}
if (type == LOG_TYPE_FILE)
{
if (name.empty())
path += std::string(PATH_SEPARATOR) + "scanner.log";
else
path += PATH_SEPARATOR + name + ".log";
file = &path[0];
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "# Log to file: '%s'\n", path.c_str());
}
}
log_cls::instance()->set_log_level(level);
return log_cls::instance()->set_log_type(type, file);
}
void unint(void)
{
std::string now(log_cls::g_time_tag + hg_log::current_time() + log_cls::g_time_tag + " exited.\n");
log(now.c_str());
log((log_divider + "\n\n\n\n").c_str());
}
void log(int level, const char* info)
{
if (lcb_)
lcb_(level, info);
else if (log_cls::instance()->is_log_level_enabled(level))
log_cls::instance()->log(info);
}
bool is_log_level_enabled(int level)
{
return log_cls::instance()->is_log_level_enabled(level);
}
void log(const char* info)
{
log_cls::instance()->log(info);
}
float GetMemoryUsage(int pid)
{
#ifdef WIN32
uint64_t mem = 0, vmem = 0;
PROCESS_MEMORY_COUNTERS pmc;
HANDLE process = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
if (GetProcessMemoryInfo(process, &pmc, sizeof(pmc)))
{
mem = pmc.WorkingSetSize;
vmem = pmc.PagefileUsage;
}
CloseHandle(process);
return mem / 1024.0 / 1024.0;//byte TO MB
#else
char file_name[64] = { 0 };
FILE* fd;
char line_buff[512] = { 0 };
sprintf(file_name, "/proc/%d/status", pid);
fd = fopen(file_name, "r");
if (nullptr == fd)
return 0;
char name[64];
int vmrss = 0;
for (int i = 0; i < VMRSS_LINE - 1; i++)
fgets(line_buff, sizeof(line_buff), fd);
fgets(line_buff, sizeof(line_buff), fd);
sscanf(line_buff, "%s %d", name, &vmrss);
fclose(fd);
return vmrss / 1024.0;//KB TO MB
#endif
}
float GetAppMemoryUsage()
{
return GetMemoryUsage(getpid());
}
const char* lang_load(uint32_t id)
{
int err = 0;
const char *lang = lang_load_string(id, &err);
if (err != 0)
{
return "";
}
return lang;
}
}
#ifdef EXPORT_AS_C
}
#endif
#if defined(WIN32) || defined(_WIN64)
void hg_debug_log(int level, const char* info)
{
hg_log::log(level, info);
}
#endif

View File

@ -1,84 +0,0 @@
// this file is include huagao logging tools
//
// created: 2022-02-09
//
#pragma once
#include <string>
#include "../../sdk/hginclude/huagaoxxx_warraper_ex.h"
#include "lang/app_language.h"
#if defined(WIN32) || defined(_WIN64)
#define bzero(a, l) memset(a, 0, l)
#define PATH_SEPARATOR "\\"
#define DLL_EXTESION ".dll"
#define STRICMP stricmp
#else
#include <string.h>
#define PATH_SEPARATOR "/"
#define DLL_EXTESION ".so"
#define STRICMP strcasecmp
#endif
//#ifdef OEM_HANWANG
//#define hg_log hw_log
//#define hg_log_type hw_log_type
//#elif defined(OEM_LISICHENG)
//#define hg_log lsc_log
//#define hg_log_type lsc_log_type
//#endif
enum hg_log_type
{
LOG_TYPE_NONE = 0, // no logging
LOG_TYPE_CONSOLE, // print to console
LOG_TYPE_FILE, // write log into file
LOG_TYPE_CALLBACK, // invoke callback log_callback
};
typedef void (*log_callback)(int, const char* info);
#ifdef EXPORT_AS_C
extern "C"
{
#endif
namespace hg_log
{
std::string format_ptr(void* ptr);
std::string format_current_thread_id(void);
std::string current_time(void);
std::string format_size(unsigned long size);
std::string u2utf8(const wchar_t* u);
std::string pe_path(std::string* name = nullptr);
std::string get_module_full_path(const char* module_part_name);
std::string get_scanner_path(void);
std::string local_data_path(void);
std::string temporary_path(void);
std::string log_file_path(void);
std::string get_scanimage_ver();
void clear_log(void);
float GetMemoryUsage(int pid);
float GetAppMemoryUsage();
const char* lang_load(uint32_t id);
unsigned int get_page_size(unsigned int* map_unit = nullptr);
unsigned long long available_memory(void);
void str_tolower(std::string& str);
bool create_folder(const char* fodler);
std::string ini_get(const char* app, const char* key);
void ini_set(const char* app, const char* key, const char* val);
// Function: initialize the logging type and level
//
// Return: 0 - success, or -1 in LOG_TYPE_FILE and log_file cannot be created
int init(void);
void unint(void);
void log(int level, const char* info);
bool is_log_level_enabled(int level);
void log(const char* info);
}
#ifdef EXPORT_AS_C
}
#endif

View File

@ -1,5 +1,7 @@
#include "../../sdk/hginclude/huagaoxxx_warraper_ex.h" #include "../../sdk/hginclude/huagaoxxx_warraper_ex.h"
#include "../wrapper/hg_log.h"
#include "../../../sdk/include/huagao/brand.h"
#include "../../sdk/hginclude/utils.h"
#include "../hgdev/scanner_manager.h" #include "../hgdev/scanner_manager.h"
#include <iostream> #include <iostream>
@ -78,30 +80,33 @@ extern "C"
scanner_err hg_scanner_initialize(sane_callback callback, void* reserve) scanner_err hg_scanner_initialize(sane_callback callback, void* reserve)
{ {
std::string name(""), std::string name(""),
pe(hg_log::pe_path(&name)), pe(utils::get_module_full_path()),
path(PATH_SEPARATOR), path(PATH_SEPARATOR),
scanner(g_scanner_path), scanner(g_scanner_path),
sane(hg_log::get_module_full_path((g_sane_name + DLL_EXTESION).c_str())); sane(utils::get_module_full_path((g_sane_name + "." + DLL_EXTESION).c_str()));
#if defined(WIN32) || defined(_WIN64) size_t pos = pe.rfind(path[0]);
size_t pos = g_scanner_path.rfind('\\');
if (pos++ != std::string::npos) if(pos++ == std::string::npos)
g_scanner_path.erase(pos); pos = 0;
#else name = pe.substr(pos);
size_t pos = 0; pe.erase(pos);
g_scanner_path = hg_log::get_module_full_path((std::string(GET_BACKEND_NAME) + ".so").c_str());
#if !defined(WIN32) && !defined(_WIN64)
g_scanner_path = utils::get_module_full_path((std::string(SCANNER_DRIVER_PART_NAME) + "." + DLL_EXTESION).c_str());
scanner = g_scanner_path; scanner = g_scanner_path;
pos = g_scanner_path.rfind('/'); #endif
pos = g_scanner_path.rfind(path[0]);
if (pos++ != std::string::npos) if (pos++ != std::string::npos)
g_scanner_path.erase(pos); g_scanner_path.erase(pos);
#endif
hg_log::init(); utils::init_log(LOG_TYPE_FILE);
VLOG_MINI_5(LOG_LEVEL_DEBUG_INFO, "Module device: [%u.%u.%u.%u] - %s\n", VERSION_MAJOR, VERSION_MINOR, VERSION_YEAR, GET_BUILD_VER, scanner.c_str()); utils::to_log(LOG_LEVEL_DEBUG, "Module device: [%u.%u.%u.%u] - %s\n", VERSION_MAJOR, VERSION_MINOR, VERSION_YEAR, GET_BUILD_VER, scanner.c_str());
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "Module sane : [%s] - %s\n", g_sane_ver.c_str(), sane.c_str()); utils::to_log(LOG_LEVEL_DEBUG, "Module sane : [%s] - %s\n", g_sane_ver.c_str(), sane.c_str());
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Module exe : %s\n", (pe + path + name).c_str()); utils::to_log(LOG_LEVEL_DEBUG, "Module exe : %s\n", (pe + name).c_str());
if (lang_initialize() == -1) if (lang_initialize() == -1)
{ {
VLOG_MINI_1(LOG_LEVEL_FATAL, "No language package found(%d)!\n", -1); utils::to_log(LOG_LEVEL_FATAL, "No language package found!\n");
return SCANNER_ERR_LANG_PAK_LOST; return SCANNER_ERR_LANG_PAK_LOST;
} }
register_language_changed_notify(language_changed, true); register_language_changed_notify(language_changed, true);
@ -116,7 +121,7 @@ extern "C"
{ {
register_language_changed_notify(language_changed, false); register_language_changed_notify(language_changed, false);
hg_scanner_mgr::clear(); hg_scanner_mgr::clear();
hg_log::unint(); utils::uninit();
} }
unsigned long long hg_scanner_get_version(void) unsigned long long hg_scanner_get_version(void)
@ -332,78 +337,18 @@ extern "C"
// NOTE: multi-thread unsafe here // NOTE: multi-thread unsafe here
static char g_unk_err[80] = { 0 }; static char g_unk_err[80] = { 0 };
strcpy(g_unk_err, hg_log::lang_load(ID_STATU_DESC_SCANNER_ERR_DEVICE_UNKNOWN_ERROR)); strcpy(g_unk_err, from_default_language(STATU_DESC_SCANNER_ERR_DEVICE_UNKNOWN_ERROR));
sprintf(g_unk_err + strlen(g_unk_err), ":0x%x", err); sprintf(g_unk_err + strlen(g_unk_err), ":0x%x", err);
return g_unk_err; return g_unk_err;
} }
bool hg_scanner_log_is_enable(int level) bool hg_scanner_log_is_enable(int level)
{ {
return hg_log::is_log_level_enabled(level); return level >= utils::get_log_level() && utils::get_log_type() != LOG_TYPE_NONE;
} }
void hg_scanner_log(const char* info) void hg_scanner_log(const char* info)
{ {
hg_log::log(info); utils::log_info(info, LOG_LEVEL_DEBUG);
}
char* get_file_path(const char* name, char* buf)
{
std::string fp(hg_log::get_module_full_path(name));
if (fp.empty())
*buf = 0;
else
strcpy(buf, fp.c_str());
return buf;
}
int get_disk_space(const char* path, unsigned long long* total, unsigned long long* avail, unsigned long long* block)
{
int ret = SCANNER_ERR_OK;
#if defined(WIN32) || defined(_WIN64)
ULARGE_INTEGER av = { 0 },
all = { 0 };
if (GetDiskFreeSpaceExA(path, &av, &all, NULL))
{
if (total)
*total = all.QuadPart;
if (avail)
*avail = av.QuadPart;
if (block)
{
DWORD sec = 0,
clu = 0;
std::string root(path);
size_t pos = root.find(":\\");
if (pos != std::string::npos)
root.erase(pos + 2);
if (GetDiskFreeSpaceA(root.c_str(), &clu, &sec, NULL, NULL))
{
*block = clu * sec;
}
}
}
else
ret = GetLastError();
#else
struct statfs fs = { 0 };
ret = statfs(path, &fs);
if (ret == 0)
{
VLOG_MINI_4(LOG_LEVEL_DEBUG_INFO, " Total: %lld, Free: %lld, Avail: %lld, block size: %lld\n",
fs.f_blocks, fs.f_bfree, fs.f_bavail, fs.f_bsize);
if (total)
*total = fs.f_blocks * fs.f_bsize;
if (avail)
*avail = fs.f_bavail * fs.f_bsize;
if (block)
*block = fs.f_bsize;
}
#endif
return ret;
} }
const char* hg_scanner_image_statu_name(int img_statu) const char* hg_scanner_image_statu_name(int img_statu)
@ -420,47 +365,6 @@ extern "C"
return g_unk_statu; return g_unk_statu;
} }
void hg_get_current_time(char* tmbuf, struct tm* t)
{
#if defined(WIN32) || defined(_WIN64)
static long bias = -1;
static bool as_start = true;
if (bias == -1)
{
_get_timezone(&bias);
as_start = hg_log::ini_get("time", "adjust") != "no";
}
#endif
time_t now = time(nullptr);
struct tm* l = localtime(&now);
#if defined(WIN32) || defined(_WIN64)
long after = 0;
if (as_start && _get_timezone(&after) == 0 &&
(after != bias && after != -bias))
{
now += bias;
l = localtime(&now);
}
#endif
if (t)
*t = *l;
if (tmbuf)
sprintf(tmbuf, "%04d-%02d-%02d %02d:%02d:%02d--->", l->tm_year + 1900, l->tm_mon + 1, l->tm_mday, l->tm_hour, l->tm_min, l->tm_sec);
}
void hg_get_current_time_w(wchar_t* tmbuf, struct tm* t)
{
struct tm tmp = { 0 }, * l = &tmp;
hg_get_current_time(nullptr, l);
if (t)
*t = *l;
if (tmbuf)
swprintf(tmbuf, 40, L"%04d-%02d-%02d %02d:%02d:%02d--->", l->tm_year + 1900, l->tm_mon + 1, l->tm_mday, l->tm_hour, l->tm_min, l->tm_sec);
}
} }

View File

@ -1,4 +1,5 @@
#include "sane_hg_mdw.h" #include "sane_hg_mdw.h"
#include "json.h" #include "json.h"
#include <stdarg.h> #include <stdarg.h>
#include <time.h> #include <time.h>
@ -20,6 +21,7 @@
#include "../../sdk/include/sane/sane_option_definitions.h" #include "../../sdk/include/sane/sane_option_definitions.h"
#include "sane_option.h" #include "sane_option.h"
#include <lang/app_language.h> #include <lang/app_language.h>
#include "../sdk/hginclude/utils.h"
#ifndef SIGUSR1 #ifndef SIGUSR1
#define SIGUSR1 10 #define SIGUSR1 10
@ -175,7 +177,7 @@ namespace local_utility
return str > bgn; return str > bgn;
} }
// æšä¸<EFBFBD>支æŒ<EFBFBD>ç§å­¦è®¡æ•°ï¿?1.2e+10 // 暂不支持科学计数<EFBFBD>?1.2e+10
bool get_number(const char*& str, double& val) bool get_number(const char*& str, double& val)
{ {
const char* bgn = str; const char* bgn = str;
@ -452,7 +454,7 @@ namespace local_utility
SANE_Handle h = hg_sane_middleware::scanner_handle_to_sane(dev); SANE_Handle h = hg_sane_middleware::scanner_handle_to_sane(dev);
// VLOG_MINI_1(LOG_LEVEL_ALL, "sane callback invoked of event %s\n", sane_event((SANE_Event)code).c_str()); // utils::to_log(LOG_LEVEL_ALL, "sane callback invoked of event %s\n", sane_event((SANE_Event)code).c_str());
if (cb_ui) if (cb_ui)
{ {
@ -540,7 +542,7 @@ hg_sane_middleware::hg_sane_middleware(void) : opt_0_(nullptr), init_ok_(false)
char path[512] = { 0 }; char path[512] = { 0 };
size_t pos = 0; size_t pos = 0;
g_sane_path = get_file_path((std::string(GET_BACKEND_NAME) + ".so").c_str(), path); g_sane_path = utils::get_module_full_path((std::string(GET_BACKEND_NAME) + ".so").c_str());
pos = g_sane_path.rfind('/'); pos = g_sane_path.rfind('/');
if (pos++ != std::string::npos) if (pos++ != std::string::npos)
g_sane_path.erase(pos); g_sane_path.erase(pos);
@ -614,7 +616,7 @@ const SANE_Device** hg_sane_middleware::to_sane_device(ScannerInfo* hgscanner, i
COPY_DEVICE_MEMBER(type); COPY_DEVICE_MEMBER(type);
} }
//VLOG_MINI_2(LOG_LEVEL_ALL, "Memory usage: %u / %u\n", val - (char*)ret, total); //utils::to_log(LOG_LEVEL_ALL, "Memory usage: %u / %u\n", val - (char*)ret, total);
return (const SANE_Device**)ret; return (const SANE_Device**)ret;
} }
@ -629,7 +631,7 @@ void hg_sane_middleware::free_sane_device(SANE_Device** dev)
} }
void hg_sane_middleware::device_pnp(int sig) void hg_sane_middleware::device_pnp(int sig)
{ {
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Device list changed (%d)...", sig); utils::to_log(LOG_LEVEL_DEBUG, "Device list changed (%d)...", sig);
} }
SANE_Fixed hg_sane_middleware::double_2_sane_fixed(double v) SANE_Fixed hg_sane_middleware::double_2_sane_fixed(double v)
{ {
@ -846,7 +848,7 @@ SANE_Option_Descriptor* hg_sane_middleware::number_option_to_SANE_descriptor(con
for (size_t i = 0; i < values.size(); ++i) for (size_t i = 0; i < values.size(); ++i)
val[i] = values[i]; val[i] = values[i];
} }
//VLOG_MINI_2(LOG_LEVEL_ALL, "Memory usage: %u/%u\n", str - (char*)sod, bytes); //utils::to_log(LOG_LEVEL_ALL, "Memory usage: %u/%u\n", str - (char*)sod, bytes);
return sod; return sod;
} }
@ -1078,7 +1080,7 @@ SANE_Option_Descriptor* hg_sane_middleware::from_json(scanner_handle h, const st
lower = l; lower = l;
upper = u; upper = u;
step = s; step = s;
VLOG_MINI_4(LOG_LEVEL_DEBUG_INFO, "%s range: [%d, +%d, %d]\n", name.c_str(), l, s, u); utils::to_log(LOG_LEVEL_DEBUG, "%s range: [%d, +%d, %d]\n", name.c_str(), l, s, u);
ret = hg_sane_middleware::number_option_to_SANE_descriptor(name.c_str(), title.c_str(), desc.c_str() ret = hg_sane_middleware::number_option_to_SANE_descriptor(name.c_str(), title.c_str(), desc.c_str()
, false, &lower, &upper, &step); , false, &lower, &upper, &step);
} }
@ -1104,7 +1106,7 @@ SANE_Option_Descriptor* hg_sane_middleware::from_json(scanner_handle h, const st
range->get_value("max", upper); range->get_value("max", upper);
step = (upper - lower) / 10.0f; step = (upper - lower) / 10.0f;
range->get_value("step", step); range->get_value("step", step);
VLOG_MINI_4(LOG_LEVEL_DEBUG_INFO, "%s range: (%f, +%f, %f)\n", name.c_str(), lower, step, upper); utils::to_log(LOG_LEVEL_DEBUG, "%s range: (%f, +%f, %f)\n", name.c_str(), lower, step, upper);
ret = hg_sane_middleware::number_option_to_SANE_descriptor(name.c_str(), title.c_str(), desc.c_str() ret = hg_sane_middleware::number_option_to_SANE_descriptor(name.c_str(), title.c_str(), desc.c_str()
, true, &lower, &upper, &step); , true, &lower, &upper, &step);
} }
@ -1183,7 +1185,7 @@ SANE_Option_Descriptor* hg_sane_middleware::from_json(scanner_handle h, const st
//if (jsn->get_value("enable", enabled) && !enabled) //if (jsn->get_value("enable", enabled) && !enabled)
// ret->cap |= SANE_CAP_INACTIVE; // ret->cap |= SANE_CAP_INACTIVE;
// å…³è<EFBFBD>”ï¿? // 关联<EFBFBD>?
json* depend = NULL; json* depend = NULL;
SLAVEOP so; SLAVEOP so;
if (jsn->get_value("depend_or", depend)) if (jsn->get_value("depend_or", depend))
@ -1481,7 +1483,7 @@ bool hg_sane_middleware::get_current_value(scanner_handle handle, const void* op
if (setv == &hg_sane_middleware::set_value_to_new) if (setv == &hg_sane_middleware::set_value_to_new)
value = *(void**)value; value = *(void**)value;
VLOG_MINI_3(LOG_LEVEL_ALL, "<--Get option(%d - %s) value: %s\n", option, val.c_str(), hg_sane_middleware::option_value_2_string(t, value).c_str()); utils::to_log(LOG_LEVEL_ALL, "<--Get option(%d - %s) value: %s\n", option, val.c_str(), hg_sane_middleware::option_value_2_string(t, value).c_str());
} }
delete jsn; delete jsn;
@ -1509,7 +1511,7 @@ void* hg_sane_middleware::get_default_value(scanner_handle handle, const void* o
*bytes = sizeof(SANE_Bool); *bytes = sizeof(SANE_Bool);
if (log) if (log)
{ {
VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "option %d(%s) default value is: %s\n", option, title.c_str(), v ? "true" : "false"); utils::to_log(LOG_LEVEL_DEBUG, "option %d(%s) default value is: %s\n", option, title.c_str(), v ? "true" : "false");
} }
} }
else if (val == "int") else if (val == "int")
@ -1523,7 +1525,7 @@ void* hg_sane_middleware::get_default_value(scanner_handle handle, const void* o
*bytes = sizeof(v); *bytes = sizeof(v);
if (log) if (log)
{ {
VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "option %d(%s) default value is: %d\n", option, title.c_str(), v); utils::to_log(LOG_LEVEL_DEBUG, "option %d(%s) default value is: %d\n", option, title.c_str(), v);
} }
} }
else if (val == "float") else if (val == "float")
@ -1539,7 +1541,7 @@ void* hg_sane_middleware::get_default_value(scanner_handle handle, const void* o
memcpy(data, &sd, sizeof(sd)); memcpy(data, &sd, sizeof(sd));
if (log) if (log)
{ {
VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "option %d(%s) default value is: %f\n", option, title.c_str(), v); utils::to_log(LOG_LEVEL_DEBUG, "option %d(%s) default value is: %f\n", option, title.c_str(), v);
} }
} }
else if (val == "string") else if (val == "string")
@ -1557,12 +1559,12 @@ void* hg_sane_middleware::get_default_value(scanner_handle handle, const void* o
*bytes = val.length() + 1; *bytes = val.length() + 1;
if (log) if (log)
{ {
VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "option %d(%s) default value is: %s\n", option, title.c_str(), (char*)data); utils::to_log(LOG_LEVEL_DEBUG, "option %d(%s) default value is: %s\n", option, title.c_str(), (char*)data);
} }
} }
else else
{ {
VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "option %d(%s) is '%s' and no value action.\n", option, title.c_str(), val.c_str()); utils::to_log(LOG_LEVEL_DEBUG, "option %d(%s) is '%s' and no value action.\n", option, title.c_str(), val.c_str());
} }
} }
delete jsn; delete jsn;
@ -1592,7 +1594,7 @@ SANE_Status hg_sane_middleware::get_devices(const SANE_Device*** device_list, SA
if (hgerr == SCANNER_ERR_INSUFFICIENT_MEMORY) if (hgerr == SCANNER_ERR_INSUFFICIENT_MEMORY)
{ {
count += 4; // 为两次hg_scanner_enumé—´éš™å<EFBFBD>¯èƒ½æ°å¢žçš„设备预留空ï¿? count += 4; // 为两次hg_scanner_enum间隙可能新增的设备预留空<EFBFBD>?
dev = (ScannerInfo*)local_utility::acquire_memory(sizeof(ScannerInfo) * count, "hg_sane_middleware::get_devices"); dev = (ScannerInfo*)local_utility::acquire_memory(sizeof(ScannerInfo) * count, "hg_sane_middleware::get_devices");
hgerr = hg_scanner_enum(dev, &count, local_only); hgerr = hg_scanner_enum(dev, &count, local_only);
if (hgerr != SCANNER_ERR_OK) if (hgerr != SCANNER_ERR_OK)
@ -1722,7 +1724,7 @@ SANE_Option_Descriptor* hg_sane_middleware::get_option_descriptor(SANE_Handle h,
opt_0_->type = SANE_TYPE_INT; opt_0_->type = SANE_TYPE_INT;
opt_0_->size = sizeof(SANE_TYPE_INT); opt_0_->size = sizeof(SANE_TYPE_INT);
} }
LOG_INFO(LOG_LEVEL_DEBUG_INFO, "get_option_descriptor(0)\n"); utils::log_info("get_option_descriptor(0)\n", LOG_LEVEL_DEBUG);
return opt_0_; return opt_0_;
} }
@ -1789,7 +1791,7 @@ SANE_Status hg_sane_middleware::set_option(SANE_Handle h, const void* option, SA
hg_scanner_get_parameter(handle, (const char*)option, NULL, &count); hg_scanner_get_parameter(handle, (const char*)option, NULL, &count);
*((SANE_Int*)value) = count; *((SANE_Int*)value) = count;
ret = SANE_STATUS_GOOD; ret = SANE_STATUS_GOOD;
VLOG_MINI_1(LOG_LEVEL_WARNING, "get option count = %d.\n", count); utils::to_log(LOG_LEVEL_WARNING, "get option count = %d.\n", count);
} }
else else
{ {
@ -1859,7 +1861,7 @@ SANE_Status hg_sane_middleware::set_option(SANE_Handle h, const void* option, SA
if (action == SANE_ACTION_SET_AUTO && desc && desc->type != SANE_TYPE_BUTTON && desc->type != SANE_TYPE_GROUP) // we assume the driver can set the option properbly, and no work to do if (action == SANE_ACTION_SET_AUTO && desc && desc->type != SANE_TYPE_BUTTON && desc->type != SANE_TYPE_GROUP) // we assume the driver can set the option properbly, and no work to do
{ {
VLOG_MINI_2(LOG_LEVEL_WARNING, "Option %d(%s) call SANE_ACTION_SET_AUTO, we set default value.\n", option, desc->title); utils::to_log(LOG_LEVEL_WARNING, "Option %d(%s) call SANE_ACTION_SET_AUTO, we set default value.\n", option, desc->title);
int len = 0; int len = 0;
void* val = get_default_value(handle, option, &len); void* val = get_default_value(handle, option, &len);
@ -1884,7 +1886,7 @@ SANE_Status hg_sane_middleware::set_option(SANE_Handle h, const void* option, SA
SANE_Option_Descriptor* known = dev->std_opt->get_option(id); SANE_Option_Descriptor* known = dev->std_opt->get_option(id);
unsigned char* cont = (unsigned char*)value; unsigned char* cont = (unsigned char*)value;
prev = hg_sane_middleware::option_value_2_string(known->type, value); prev = hg_sane_middleware::option_value_2_string(known->type, value);
VLOG_MINI_5(LOG_LEVEL_DEBUG_INFO, "$First 4-bytes of origin value for option %d is: %02X%02X%02X%02X\n", option, cont[0], cont[1], cont[2], cont[3]); utils::to_log(LOG_LEVEL_DEBUG, "$First 4-bytes of origin value for option %d is: %02X%02X%02X%02X\n", option, cont[0], cont[1], cont[2], cont[3]);
err = dev->std_opt->set_value(handle, id, value); err = dev->std_opt->set_value(handle, id, value);
v = hg_sane_middleware::option_value_2_string(known->type, value); v = hg_sane_middleware::option_value_2_string(known->type, value);
} }
@ -1901,14 +1903,14 @@ SANE_Status hg_sane_middleware::set_option(SANE_Handle h, const void* option, SA
return local_utility::scanner_err_2_sane_statu(hg_scanner_set_parameter(handle, name.c_str(), value, 0)); return local_utility::scanner_err_2_sane_statu(hg_scanner_set_parameter(handle, name.c_str(), value, 0));
} }
VLOG_MINI_1(LOG_LEVEL_FATAL, "Option descriptor %d not found.\n", option); utils::to_log(LOG_LEVEL_FATAL, "Option descriptor %d not found.\n", option);
return SANE_STATUS_UNSUPPORTED; return SANE_STATUS_UNSUPPORTED;
} }
else if (!value && desc->type != SANE_TYPE_BUTTON) else if (!value && desc->type != SANE_TYPE_BUTTON)
{ {
//if (action == SANE_ACTION_SET_AUTO) // we assume the driver can set the option properbly, and no work to do //if (action == SANE_ACTION_SET_AUTO) // we assume the driver can set the option properbly, and no work to do
//{ //{
// VLOG_MINI_2(LOG_LEVEL_WARNING, "Option %d(%s) call SANE_ACTION_SET_AUTO, we set default value.\n", option, desc->title); // utils::to_log(LOG_LEVEL_WARNING, "Option %d(%s) call SANE_ACTION_SET_AUTO, we set default value.\n", option, desc->title);
// //
// value = get_default_value(handle, option); // value = get_default_value(handle, option);
// if (!value) // if (!value)
@ -1917,7 +1919,7 @@ SANE_Status hg_sane_middleware::set_option(SANE_Handle h, const void* option, SA
//} //}
//else //else
{ {
VLOG_MINI_2(LOG_LEVEL_WARNING, "Option descriptor %d(%s) need a value!.\n", option, desc->title); utils::to_log(LOG_LEVEL_WARNING, "Option descriptor %d(%s) need a value!.\n", option, desc->title);
return SANE_STATUS_INVAL; return SANE_STATUS_INVAL;
} }
@ -1957,11 +1959,11 @@ SANE_Status hg_sane_middleware::set_option(SANE_Handle h, const void* option, SA
if (prev == v) if (prev == v)
{ {
VLOG_MINI_3(LOG_LEVEL_ALL, "-->Set option(%d - %s) value: %s\n", option, desc_title.c_str(), v.c_str()); utils::to_log(LOG_LEVEL_ALL, "-->Set option(%d - %s) value: %s\n", option, desc_title.c_str(), v.c_str());
} }
else else
{ {
VLOG_4(LOG_LEVEL_ALL, 512, "-->Set option(%d - %s) value: %s(Applied: %s)\n", option, desc_title.c_str(), prev.c_str(), v.c_str()); utils::to_log(LOG_LEVEL_ALL, "-->Set option(%d - %s) value: %s(Applied: %s)\n", option, desc_title.c_str(), prev.c_str(), v.c_str());
} }
if (err == SCANNER_ERR_OK) if (err == SCANNER_ERR_OK)
@ -1974,7 +1976,7 @@ SANE_Status hg_sane_middleware::set_option(SANE_Handle h, const void* option, SA
} }
else if (err == SCANNER_ERR_CONFIGURATION_CHANGED) else if (err == SCANNER_ERR_CONFIGURATION_CHANGED)
{ {
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "the setting '%s' affects other options value, RELOAD ...\n", desc_title.c_str()); utils::to_log(LOG_LEVEL_DEBUG, "the setting '%s' affects other options value, RELOAD ...\n", desc_title.c_str());
//on_SCANNER_ERR_CONFIGURATION_CHANGED(dev); //on_SCANNER_ERR_CONFIGURATION_CHANGED(dev);
if(dev->fixed_id.count(SANE_OPT_ID_LANGUAGE) == 0 || dev->fixed_id[SANE_OPT_ID_LANGUAGE] != id) // language reload by callback already if(dev->fixed_id.count(SANE_OPT_ID_LANGUAGE) == 0 || dev->fixed_id[SANE_OPT_ID_LANGUAGE] != id) // language reload by callback already
reload_options(handle); reload_options(handle);
@ -1982,12 +1984,12 @@ SANE_Status hg_sane_middleware::set_option(SANE_Handle h, const void* option, SA
} }
else if(err == SCANNER_ERR_RELOAD_IMAGE_PARAM) else if(err == SCANNER_ERR_RELOAD_IMAGE_PARAM)
{ {
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "the setting '%s' affects image parameter, APP should re-get ...\n", desc_title.c_str()); utils::to_log(LOG_LEVEL_DEBUG, "the setting '%s' affects image parameter, APP should re-get ...\n", desc_title.c_str());
err = (scanner_err)SANE_INFO_RELOAD_PARAMS; err = (scanner_err)SANE_INFO_RELOAD_PARAMS;
} }
else if(err == SCANNER_ERR_RELOAD_OPT_PARAM) else if(err == SCANNER_ERR_RELOAD_OPT_PARAM)
{ {
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "the setting '%s' affects image parameter and options, APP should re-get image info and reload options...\n", desc_title.c_str()); utils::to_log(LOG_LEVEL_DEBUG, "the setting '%s' affects image parameter and options, APP should re-get image info and reload options...\n", desc_title.c_str());
//on_SCANNER_ERR_CONFIGURATION_CHANGED(dev); //on_SCANNER_ERR_CONFIGURATION_CHANGED(dev);
if (dev->fixed_id.count(SANE_OPT_ID_LANGUAGE) == 0 || dev->fixed_id[SANE_OPT_ID_LANGUAGE] != id) // language reload by callback already if (dev->fixed_id.count(SANE_OPT_ID_LANGUAGE) == 0 || dev->fixed_id[SANE_OPT_ID_LANGUAGE] != id) // language reload by callback already
reload_options(handle); reload_options(handle);
@ -2058,7 +2060,7 @@ SANE_Status hg_sane_middleware::io_control(SANE_Handle h, unsigned long code, vo
if (ret == SCANNER_ERR_CONFIGURATION_CHANGED) if (ret == SCANNER_ERR_CONFIGURATION_CHANGED)
{ {
int nc = code; int nc = code;
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "the setting '0x%08x' affects other options value, RELOAD ...\n", nc); utils::to_log(LOG_LEVEL_DEBUG, "the setting '0x%08x' affects other options value, RELOAD ...\n", nc);
on_SCANNER_ERR_CONFIGURATION_CHANGED(dev); on_SCANNER_ERR_CONFIGURATION_CHANGED(dev);
} }
@ -2070,7 +2072,7 @@ bool hg_sane_middleware::is_ready(void)
} }
/// <summary> /// <summary>
/// å…³è<EFBFBD>”项处ï¿? /// 关联项处<EFBFBD>?
bool hg_sane_middleware::compare_val_equal(const char* cur_val, const char* limit_l, const char* limit_r) bool hg_sane_middleware::compare_val_equal(const char* cur_val, const char* limit_l, const char* limit_r)
{ {
return strcmp(cur_val, limit_l) == 0; return strcmp(cur_val, limit_l) == 0;
@ -2114,7 +2116,7 @@ bool hg_sane_middleware::is_enable_and(scanner_handle hdev, const std::vector<MA
std::vector<CURVAL>::iterator it = std::find(curvals.begin(), curvals.end(), master[i].name); std::vector<CURVAL>::iterator it = std::find(curvals.begin(), curvals.end(), master[i].name);
if (it == curvals.end()) if (it == curvals.end())
{ {
VLOG_MINI_1(LOG_LEVEL_WARNING, "option %s's current value is not found, other options depend it maybe in wrong status.\n", master[i].name.c_str()); utils::to_log(LOG_LEVEL_WARNING, "option %s's current value is not found, other options depend it maybe in wrong status.\n", master[i].name.c_str());
continue; continue;
} }
@ -2136,7 +2138,7 @@ bool hg_sane_middleware::is_enable_or(scanner_handle hdev, const std::vector<MAS
std::vector<CURVAL>::iterator it = std::find(curvals.begin(), curvals.end(), master[i].name); std::vector<CURVAL>::iterator it = std::find(curvals.begin(), curvals.end(), master[i].name);
if (it == curvals.end()) if (it == curvals.end())
{ {
VLOG_MINI_1(LOG_LEVEL_WARNING, "option %s's current value is not found, other options depend it maybe in wrong status.\n", master[i].name.c_str()); utils::to_log(LOG_LEVEL_WARNING, "option %s's current value is not found, other options depend it maybe in wrong status.\n", master[i].name.c_str());
continue; continue;
} }
@ -2551,7 +2553,7 @@ extern "C" { // avoid compiler exporting name in C++ style !!!
} }
SANE_Status inner_sane_start(SANE_Handle handle) SANE_Status inner_sane_start(SANE_Handle handle)
{ {
LOG_INFO(LOG_LEVEL_ALL, "sane_start\n"); utils::log_info("sane_start\n", LOG_LEVEL_ALL);
return hg_sane_middleware::instance()->start(handle, NULL); return hg_sane_middleware::instance()->start(handle, NULL);
} }
@ -2566,13 +2568,13 @@ extern "C" { // avoid compiler exporting name in C++ style !!!
} }
void inner_sane_cancel(SANE_Handle handle) void inner_sane_cancel(SANE_Handle handle)
{ {
LOG_INFO(LOG_LEVEL_ALL, "sane_cancel\n"); utils::log_info("sane_cancel\n", LOG_LEVEL_ALL);
hg_sane_middleware::instance()->stop(handle); hg_sane_middleware::instance()->stop(handle);
} }
SANE_Status inner_sane_set_io_mode(SANE_Handle handle, SANE_Bool non_blocking) SANE_Status inner_sane_set_io_mode(SANE_Handle handle, SANE_Bool non_blocking)
{ {
LOG_INFO(LOG_LEVEL_ALL, "sane_set_io_mode\n"); utils::log_info("sane_set_io_mode\n", LOG_LEVEL_ALL);
return non_blocking ? SANE_STATUS_UNSUPPORTED : SANE_STATUS_GOOD; return non_blocking ? SANE_STATUS_UNSUPPORTED : SANE_STATUS_GOOD;
} }

View File

@ -1,6 +1,8 @@
#include "sane_option.h" #include "sane_option.h"
#include <sane/sane_option_definitions.h> #include <sane/sane_option_definitions.h>
#include "../sdk/hginclude/huagaoxxx_warraper_ex.h" #include "../sdk/hginclude/huagaoxxx_warraper_ex.h"
#include "../sdk/hginclude/utils.h"
#include "../../sdk/include/lang/app_language.h" #include "../../sdk/include/lang/app_language.h"
@ -50,7 +52,7 @@ static void match_paper(char* buf, int cx, int cy)
else else
strcpy(buf, from_default_language(g_paper[index].title, NULL)); strcpy(buf, from_default_language(g_paper[index].title, NULL));
VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "match paper(%u * %u) to '%s'\n", cx, cy, (char*)buf); utils::to_log(LOG_LEVEL_DEBUG, "match paper(%u * %u) to '%s'\n", cx, cy, (char*)buf);
} }
@ -395,7 +397,7 @@ scanner_err sane_std_opts::set_value(scanner_handle h, int opt, void* buf)
long len = 0; long len = 0;
void* data = from_known_opt_value(op, buf, &len); void* data = from_known_opt_value(op, buf, &len);
VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "%d->%d: %s\n", opt, op->user.opt, (char*)data); utils::to_log(LOG_LEVEL_DEBUG, "%d->%d: %s\n", opt, op->user.opt, (char*)data);
statu = hg_scanner_set_parameter(h, (const char*)op->user.opt, data, &len); statu = hg_scanner_set_parameter(h, (const char*)op->user.opt, data, &len);
if (statu == SCANNER_ERR_NOT_EXACT) if (statu == SCANNER_ERR_NOT_EXACT)

View File

@ -28,8 +28,8 @@
#include "sane/sane_ex.h" #include "sane/sane_ex.h"
#include <string> #include <string>
#if defined(WIN32) || defined(_WIN64) #if defined(WIN32) || defined(_WIN64)
#include "../../../sdk/include/huagao/brand.h"
#ifndef HGSCANNER_EXPORT #ifndef HGSCANNER_EXPORT
#pragma comment(lib, "scanner.lib") #pragma comment(lib, "scanner.lib")
#endif #endif
@ -440,51 +440,12 @@ extern "C"{
const char* hg_scanner_err_name(int err); const char* hg_scanner_err_name(int err);
const char* hg_scanner_err_description(int err); const char* hg_scanner_err_description(int err);
enum log_level
{
LOG_LEVEL_ALL = 0,
LOG_LEVEL_DEBUG_INFO,
LOG_LEVEL_WARNING,
LOG_LEVEL_FATAL,
};
bool hg_scanner_log_is_enable(int level); bool hg_scanner_log_is_enable(int level);
void hg_scanner_log(const char* info); void hg_scanner_log(const char* info);
// Function: 获取模块全路径名称
//
// Parameters: name - 模块名称(模块名称的一部分即可,不支持通配符)
//
// buf - 返回的全路径空间,必须保证足够大小
//
// Return: 返回buf
char* get_file_path(const char* name, char* buf);
// Function: 获取磁盘空间
//
// Parameters: path - 全路径
//
// total - 总空间大小(字节)
//
// avail - 可用空间大小(字节)
//
// block - 磁盘单元(块/簇)大小(字节)
//
// Return: 0 - 成功;其它为失败代码
int get_disk_space(const char* path, unsigned long long* total, unsigned long long* avail, unsigned long long* block);
// Function: 图像状态名称 // Function: 图像状态名称
const char* hg_scanner_image_statu_name(int img_statu); const char* hg_scanner_image_statu_name(int img_statu);
// Function: 获取当前时间字符串
//
// Parameters: tmbuf - 用于接收时间字符串不小于40个字符长度
//
// t - 用于接收原始的时间结构
//
// Return: void
void hg_get_current_time(char* tmbuf, struct tm* t = nullptr);
void hg_get_current_time_w(wchar_t* tmbuf, struct tm* t = nullptr);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
@ -494,113 +455,6 @@ if (NULL != (p)) {free((p)); \
}\ }\
} }
/////////////////////////////////////////////////////////////////////////////////////
// log ...
#define VLOG_MINI_BYTES 512
#define LOG_INFO(level, info) \
if(hg_scanner_log_is_enable(level)) \
{\
char* msgbuf = (char*)malloc(VLOG_MINI_BYTES); \
if (msgbuf != NULL) \
{ \
hg_get_current_time(msgbuf);\
strcpy(msgbuf+strlen(msgbuf),info); \
hg_scanner_log(msgbuf); \
SAFE_FREE(msgbuf); \
} \
} \
#define VLOG_1(level, bytes, fmt, arg1) \
if(hg_scanner_log_is_enable(level)) \
{ \
char* msgbuf = (char*)malloc(bytes); \
if (msgbuf != NULL) \
{ \
hg_get_current_time(msgbuf);\
sprintf(msgbuf +strlen(msgbuf), fmt, arg1); \
} \
hg_scanner_log(msgbuf); \
SAFE_FREE(msgbuf); \
}
#define VLOG_MINI_1(level, fmt, arg1) VLOG_1(level, VLOG_MINI_BYTES, fmt, arg1)
#define VLOG_2(level, bytes, fmt, arg1, arg2) \
if(hg_scanner_log_is_enable(level)) \
{ \
char* msgbuf = (char*)malloc(bytes); \
if (msgbuf != NULL) \
{ \
hg_get_current_time(msgbuf);\
sprintf(msgbuf+strlen(msgbuf), fmt, arg1, arg2); \
} \
hg_scanner_log(msgbuf); \
SAFE_FREE(msgbuf); \
}
#define VLOG_MINI_2(level, fmt, arg1, arg2) VLOG_2(level, VLOG_MINI_BYTES, fmt, arg1, arg2)
#define VLOG_3(level, bytes, fmt, arg1, arg2, arg3) \
if(hg_scanner_log_is_enable(level)) \
{ \
char* msgbuf = (char*)malloc(bytes); \
if (msgbuf != NULL) \
{ \
hg_get_current_time(msgbuf);\
sprintf(msgbuf +strlen(msgbuf), fmt, arg1, arg2, arg3); \
}\
hg_scanner_log(msgbuf); \
SAFE_FREE(msgbuf); \
}
#define VLOG_MINI_3(level, fmt, arg1, arg2, arg3) VLOG_3(level, VLOG_MINI_BYTES, fmt, arg1, arg2, arg3)
#define VLOG_4(level, bytes, fmt, arg1, arg2, arg3, arg4) \
if(hg_scanner_log_is_enable(level)) \
{ \
char* msgbuf = (char*)malloc(bytes); \
if (msgbuf != NULL) \
{ \
hg_get_current_time(msgbuf);\
sprintf(msgbuf+strlen(msgbuf), fmt, arg1, arg2, arg3, arg4); \
}\
hg_scanner_log(msgbuf); \
SAFE_FREE(msgbuf); \
}
#define VLOG_MINI_4(level, fmt, arg1, arg2, arg3, arg4) \
VLOG_4(level, VLOG_MINI_BYTES, fmt, arg1, arg2, arg3, arg4)
#define VLOG_5(level, bytes, fmt, arg1, arg2, arg3, arg4, arg5) \
if(hg_scanner_log_is_enable(level)) \
{ \
char* msgbuf = (char*)malloc(bytes); \
if(msgbuf) \
{ \
hg_get_current_time(msgbuf);\
sprintf(msgbuf+strlen(msgbuf), fmt, arg1, arg2, arg3, arg4, arg5); \
}\
hg_scanner_log(msgbuf); \
SAFE_FREE(msgbuf); \
}
#define VLOG_MINI_5(level, fmt, arg1, arg2, arg3, arg4, arg5) \
VLOG_5(level, VLOG_MINI_BYTES, fmt, arg1, arg2, arg3, arg4, arg5)
#define VLOG_6(level, bytes, fmt, arg1, arg2, arg3, arg4, arg5, arg6) \
if(hg_scanner_log_is_enable(level)) \
{ \
char* msgbuf = (char*)malloc(bytes); \
if (msgbuf != NULL) \
{ \
hg_get_current_time(msgbuf);\
sprintf(msgbuf+strlen(msgbuf), fmt, arg1, arg2, arg3, arg4, arg5, arg6); \
}\
hg_scanner_log(msgbuf); \
SAFE_FREE(msgbuf); \
}
#define VLOG_MINI_6(level, fmt, arg1, arg2, arg3, arg4, arg5, arg6) \
VLOG_6(level, VLOG_MINI_BYTES, fmt, arg1, arg2, arg3, arg4, arg5, arg6)
#endif // WRRPER_SANE_SCANNER_H_EX #endif // WRRPER_SANE_SCANNER_H_EX

View File

@ -1,4 +1,5 @@
#include "utils.h" #include "utils.h"
#include "huagao/brand.h" #include "huagao/brand.h"
@ -63,6 +64,7 @@ int gettimeofday(TIMEV* tv, struct timezone* tz)
#include <sys/stat.h> #include <sys/stat.h>
#include <thread> #include <thread>
#include <iconv.h> #include <iconv.h>
#include <sys/vfs.h>
static std::mutex ini_lock_; static std::mutex ini_lock_;
static std::map<std::string, simple_ini*> ini_files_; static std::map<std::string, simple_ini*> ini_files_;
@ -269,6 +271,14 @@ public:
return log_cls::inst_; return log_cls::inst_;
} }
static void clear(void)
{
if(log_cls::inst_)
{
delete log_cls::inst_;
log_cls::inst_ = nullptr;
}
}
int set_log_type(int type, void* param) int set_log_type(int type, void* param)
{ {
@ -326,7 +336,7 @@ public:
log_(info, &file_, &path_file_); log_(info, &file_, &path_file_);
} }
std::string get_log_file_path(bool copy) std::string get_log_file_path(const char* dst = nullptr)
{ {
std::string file(""); std::string file("");
@ -334,9 +344,9 @@ public:
{ {
file = path_file_; file = path_file_;
if (copy) if (dst)
{ {
file += ".txt"; file = dst;
FILE* dst = fopen(file.c_str(), "wb"); FILE* dst = fopen(file.c_str(), "wb");
@ -580,6 +590,10 @@ namespace utils
return ldp; return ldp;
} }
std::string temporary_path(void)
{
return std::move(simple_ini::temporary_path());
}
std::string format_current_time(void) std::string format_current_time(void)
{ {
return std::move(chronograph::now()); return std::move(chronograph::now());
@ -780,6 +794,76 @@ namespace utils
return rename(from, to); return rename(from, to);
} }
int get_disk_space(const char* path, unsigned long long* total, unsigned long long* avail, unsigned long long* block)
{
int ret = 0;
#if defined(WIN32) || defined(_WIN64)
ULARGE_INTEGER av = { 0 },
all = { 0 };
if (GetDiskFreeSpaceExA(path, &av, &all, NULL))
{
if (total)
*total = all.QuadPart;
if (avail)
*avail = av.QuadPart;
if (block)
{
DWORD sec = 0,
clu = 0;
std::string root(path);
size_t pos = root.find(":\\");
if (pos != std::string::npos)
root.erase(pos + 2);
if (GetDiskFreeSpaceA(root.c_str(), &clu, &sec, NULL, NULL))
{
*block = clu * sec;
}
}
}
else
ret = GetLastError();
#else
struct statfs fs = { 0 };
ret = statfs(path, &fs);
if (ret == 0)
{
utils::to_log(LOG_LEVEL_DEBUG, " Total: %lld, Free: %lld, Avail: %lld, block size: %lld\n",
fs.f_blocks, fs.f_bfree, fs.f_bavail, fs.f_bsize);
if (total)
*total = fs.f_blocks * fs.f_bsize;
if (avail)
*avail = fs.f_bavail * fs.f_bsize;
if (block)
*block = fs.f_bsize;
}
#endif
return ret;
}
unsigned int get_page_size(unsigned int* map_unit)
{
unsigned int ps = 1024;
#if defined(WIN32) || defined(_WIN64)
SYSTEM_INFO si = { 0 };
GetSystemInfo(&si);
ps = si.dwPageSize;
if (map_unit)
*map_unit = si.dwAllocationGranularity;
#else
ps = sysconf(_SC_PAGESIZE);
if(ps < 1024 || (ps & 0x0fe0000ff)) // nKB && < 16MB
ps = getpagesize();
if (map_unit)
*map_unit = ps;
#endif
if (ps < 1024 || (ps & 0x0fe0000ff)) // nKB && < 16MB
ps = 1024;
return ps;
}
void init_log(log_type type, log_level level, const char* fn_appendix) void init_log(log_type type, log_level level, const char* fn_appendix)
{ {
std::string file(""); std::string file("");
@ -803,6 +887,10 @@ namespace utils
log_cls::instance()->set_log_type(type, &file[0]); log_cls::instance()->set_log_type(type, &file[0]);
log_cls::instance()->set_log_level(level); log_cls::instance()->set_log_level(level);
} }
void uninit(void)
{
log_cls::clear();
}
void log_info(const char* info, int level) void log_info(const char* info, int level)
{ {
if (get_log_type() != LOG_TYPE_NONE && get_log_level() <= level) if (get_log_type() != LOG_TYPE_NONE && get_log_level() <= level)
@ -810,6 +898,33 @@ namespace utils
log_cls::instance()->log(("[" + format_current_time() + "]: " + info).c_str()); log_cls::instance()->log(("[" + format_current_time() + "]: " + info).c_str());
} }
} }
void log_mem_info(const char* desc, const void* data, size_t bytes, int level)
{
if (get_log_type() == LOG_TYPE_NONE || get_log_level() > level)
return;
std::string line(desc);
char buf[40] = {0};
utils::log_info((line + "\n").c_str(), level);
line = "";
for(size_t i = 0; i < bytes; ++i)
{
if((i % 16) == 0)
{
if(line.length())
utils::log_info((line + "\n").c_str(), level);
sprintf(buf, "%p ", (const char*)data + i);
line = buf;
}
else if((i % 8) == 0)
line += " ";
sprintf(buf, "%02x ", ((const unsigned char*)data)[i]);
line += buf;
}
if(line.length())
utils::log_info((line + "\n").c_str(), level);
}
int get_log_type(void) int get_log_type(void)
{ {
return log_cls::instance()->type(); return log_cls::instance()->type();
@ -818,6 +933,19 @@ namespace utils
{ {
return log_cls::instance()->level(); return log_cls::instance()->level();
} }
int copy_log_file_to(const char* dst)
{
log_cls::instance()->get_log_file_path(dst);
return 0;
}
int clear_log_file(void)
{
log_cls::instance()->clear_log();
return 0;
}
}; };

View File

@ -30,6 +30,7 @@ namespace utils
std::string get_command_result(const char* cmd, int len = -1); std::string get_command_result(const char* cmd, int len = -1);
std::string get_local_data_path(void); std::string get_local_data_path(void);
std::string temporary_path(void);
std::string format_current_time(void); std::string format_current_time(void);
std::string get_module_full_path(const char* part_name = nullptr/*nullptr to get main-pe/first module's full path*/); std::string get_module_full_path(const char* part_name = nullptr/*nullptr to get main-pe/first module's full path*/);
std::string target_file_from_link(const char* lnk_file); std::string target_file_from_link(const char* lnk_file);
@ -43,10 +44,17 @@ namespace utils
int enum_file(const char* folder, bool recursive, bool/*return false to stop enumeration*/(STDCALL* found)(const char* path_name, bool dir, void* param), void* param); int enum_file(const char* folder, bool recursive, bool/*return false to stop enumeration*/(STDCALL* found)(const char* path_name, bool dir, void* param), void* param);
int move_file(const char* from, const char* to); int move_file(const char* from, const char* to);
int get_disk_space(const char* path, unsigned long long* total, unsigned long long* avail, unsigned long long* block);
unsigned int get_page_size(unsigned int* map_unit = nullptr);
void init_log(log_type type, log_level level = LOG_LEVEL_ALL, const char* fn_appendix = nullptr/*appendix to default log-file-name*/); void init_log(log_type type, log_level level = LOG_LEVEL_ALL, const char* fn_appendix = nullptr/*appendix to default log-file-name*/);
void uninit(void);
void log_info(const char* info, int level = LOG_LEVEL_ALL); void log_info(const char* info, int level = LOG_LEVEL_ALL);
void log_mem_info(const char* desc, const void* data, size_t bytes, int level = LOG_LEVEL_ALL); // log as 0x12345678 00 01 02 ...
int get_log_type(void); int get_log_type(void);
int get_log_level(void); int get_log_level(void);
int copy_log_file_to(const char* dst);
int clear_log_file(void);
template<typename ... Args> template<typename ... Args>
void to_log(int level, const char* fmt, Args ... args) void to_log(int level, const char* fmt, Args ... args)

View File

@ -8,8 +8,9 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -fvisibility=hidden")
aux_source_directory(${PROJECT_SOURCE_DIR} DIR_SRCS) aux_source_directory(${PROJECT_SOURCE_DIR} DIR_SRCS)
# add_subdirectory(twain) # add_subdirectory(twain)
file(GLOB DIR_HEADS "${PROJECT_SOURCE_DIR}/*.h" "${PROJECT_SOURCE_DIR}/*.hpp" "${PROJECT_SOURCE_DIR}/*.cpp" file(GLOB DIR_HEADS "${PROJECT_SOURCE_DIR}/*.h" "${PROJECT_SOURCE_DIR}/*.hpp" "${PROJECT_SOURCE_DIR}/*.cpp"
"${PROJECT_SOURCE_DIR}/../hgdriver/wrapper/ini_file.h" "${PROJECT_SOURCE_DIR}/../sdk/hginclude/*.h"
"${PROJECT_SOURCE_DIR}/../hgdriver/wrapper/ini_file.cpp") "${PROJECT_SOURCE_DIR}/../sdk/hginclude/*.cpp"
)
set(DIR_SRCS ${DIR_SRCS} ${DIR_HEADS}) set(DIR_SRCS ${DIR_SRCS} ${DIR_HEADS})
add_library(${PROJECT_NAME} SHARED ${DIR_SRCS}) add_library(${PROJECT_NAME} SHARED ${DIR_SRCS})
@ -21,11 +22,11 @@ link_libraries(dl)
# ) # )
target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCE_DIR} target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}/../sdk/hginclude
${PROJECT_SOURCE_DIR}/../../sdk/include ${PROJECT_SOURCE_DIR}/../../sdk/include
${PROJECT_SOURCE_DIR}/../../sdk/include/huagao ${PROJECT_SOURCE_DIR}/../../sdk/include/huagao
${PROJECT_SOURCE_DIR}/../../sdk/include/twain ${PROJECT_SOURCE_DIR}/../../sdk/include/twain
${PROJECT_SOURCE_DIR}/../../sdk/include/twain/twpp ${PROJECT_SOURCE_DIR}/../../sdk/include/twain/twpp
${PROJECT_SOURCE_DIR}/../hgdriver/wrapper
) )
target_link_directories(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCE_DIR} target_link_directories(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCE_DIR}

View File

@ -1020,7 +1020,7 @@ Result huagao_ds::identityOpenDs(const Identity& id)
m_fileXfer.setFormat(ImageFileFormat::Bmp); m_fileXfer.setFormat(ImageFileFormat::Bmp);
scanner_status_ = SCANNER_STATUS_READY; scanner_status_ = SCANNER_STATUS_READY;
log_mem_info("srcIdent:", srcIdent, sizeof(*srcIdent)); utils::log_mem_info("srcIdent:", srcIdent, sizeof(*srcIdent));
return success(); return success();
} }
@ -2145,11 +2145,11 @@ void huagao_ds::init_support_caps(void)
return badValue(); return badValue();
} }
} }
log_mem_info("IXferMech data before:", &data, sizeof(data)); utils::log_mem_info("IXferMech data before:", &data, sizeof(data));
Result r = CapSupGetAllReset<XferMech, XferMech, CapType::IXferMech>(msg, data, { XferMech::Native, XferMech::File, XferMech::Memory }, m_capXferMech, XferMech::Native, (int)m_capXferMech, 0); Result r = CapSupGetAllReset<XferMech, XferMech, CapType::IXferMech>(msg, data, { XferMech::Native, XferMech::File, XferMech::Memory }, m_capXferMech, XferMech::Native, (int)m_capXferMech, 0);
log_mem_info("IXferMech data after:", &data, sizeof(data)); utils::log_mem_info("IXferMech data after:", &data, sizeof(data));
return r; return r;
}; };

View File

@ -437,8 +437,6 @@ extern "C"
int open_scanner(SCANNERID scanner_id, ISaneInvoker** invoker, bool last_try); int open_scanner(SCANNERID scanner_id, ISaneInvoker** invoker, bool last_try);
bool is_scanner_online(SCANNERID scanner_id); bool is_scanner_online(SCANNERID scanner_id);
int uninitialize_sane(void* reserve); int uninitialize_sane(void* reserve);
void log_debug_info(const char* info, int level);
void log_mem_info(const char* desc, const void* data, size_t bytes);
ISaneInvoker* sane_wapper_open_scanner(SCANNERID scanner_id, int* err, bool last_try); ISaneInvoker* sane_wapper_open_scanner(SCANNERID scanner_id, int* err, bool last_try);
} }

View File

@ -79,7 +79,7 @@ namespace callback
{ {
char msg[218] = { 0 }; char msg[218] = { 0 };
sprintf_s(msg, _countof(msg) - 1, "Lost device(0x%08X) when event(%u) occurs!\r\n", hdev, code); sprintf_s(msg, _countof(msg) - 1, "Lost device(0x%08X) when event(%u) occurs!\r\n", hdev, code);
log_debug_info(msg, 1); utils::log_info(msg, (log_level)1);
return 0; return 0;
} }
@ -285,7 +285,7 @@ namespace callback
info += "' failed: " + std::string(strerror(GetLastError())) + "\r\n"; info += "' failed: " + std::string(strerror(GetLastError())) + "\r\n";
log_debug_info(info.c_str(), 1); utils::log_info(info.c_str(), LOG_LEVEL_DEBUG);
} }
else else
{ {
@ -1024,7 +1024,7 @@ void scanner::extension_page(int id)
ex_opts_.push_back(ea); ex_opts_.push_back(ea);
{ {
sprintf_s(msg, _countof(msg) - 1, "handle_ex_duplex of id: %d\r\n", ea.ind); sprintf_s(msg, _countof(msg) - 1, "handle_ex_duplex of id: %d\r\n", ea.ind);
log_debug_info(msg, 0); utils::log_info(msg, (log_level)0);
} }
ea.ind = ex_discard_blank_page_id_ = ex_id_++; ea.ind = ex_discard_blank_page_id_ = ex_id_++;
@ -1033,7 +1033,7 @@ void scanner::extension_page(int id)
ex_opts_.push_back(ea); ex_opts_.push_back(ea);
{ {
sprintf_s(msg, _countof(msg) - 1, "handle_ex_discard_blank_page of id: %d\r\n", ea.ind); sprintf_s(msg, _countof(msg) - 1, "handle_ex_discard_blank_page of id: %d\r\n", ea.ind);
log_debug_info(msg, 0); utils::log_info(msg, (log_level)0);
} }
ea.ind = ex_discard_blank_receipt_id_ = ex_id_++; ea.ind = ex_discard_blank_receipt_id_ = ex_id_++;
@ -1042,7 +1042,7 @@ void scanner::extension_page(int id)
ex_opts_.push_back(ea); ex_opts_.push_back(ea);
{ {
sprintf_s(msg, _countof(msg) - 1, "handle_ex_discard_blank_receipt of id: %d\r\n", ea.ind); sprintf_s(msg, _countof(msg) - 1, "handle_ex_discard_blank_receipt of id: %d\r\n", ea.ind);
log_debug_info(msg, 0); utils::log_info(msg, (log_level)0);
} }
ea.ind = ex_is_page_fold_id_ = ex_id_++; ea.ind = ex_is_page_fold_id_ = ex_id_++;
@ -1051,7 +1051,7 @@ void scanner::extension_page(int id)
ex_opts_.push_back(ea); ex_opts_.push_back(ea);
{ {
sprintf_s(msg, _countof(msg) - 1, "handle_ex_page_fold of id: %d\r\n", ea.ind); sprintf_s(msg, _countof(msg) - 1, "handle_ex_page_fold of id: %d\r\n", ea.ind);
log_debug_info(msg, 0); utils::log_info(msg, (log_level)0);
} }
} }
void scanner::extension_erase_color(int id) void scanner::extension_erase_color(int id)
@ -2368,7 +2368,7 @@ COM_API_IMPLEMENT(scanner, int, get_scanned_images(DWORD milliseconds))
{ {
char msg[128] = { 0 }; char msg[128] = { 0 };
sprintf_s(msg, _countof(msg) - 1, "Wait image count = %d\r\n", count); sprintf_s(msg, _countof(msg) - 1, "Wait image count = %d\r\n", count);
log_debug_info(msg, 1); utils::log_info(msg, (log_level)1);
} }
return count; return count;
@ -2718,7 +2718,7 @@ COM_API_IMPLEMENT(scanner, int, set_value(int sn, void* val))
desc = sane_helper_->invoke_sane_get_option_descriptor(handle_, ex->base_ind); desc = sane_helper_->invoke_sane_get_option_descriptor(handle_, ex->base_ind);
sprintf_s(msg, _countof(msg) - 1, "set_value of %s(0x%x) of ID %d, base id = %d)\r\n", desc->name, *(unsigned*)val, sn, ex->base_ind); sprintf_s(msg, _countof(msg) - 1, "set_value of %s(0x%x) of ID %d, base id = %d)\r\n", desc->name, *(unsigned*)val, sn, ex->base_ind);
} }
log_debug_info(msg, 0); utils::log_info(msg, (log_level)0);
} }
twain_set_ = true; twain_set_ = true;
@ -2969,6 +2969,7 @@ COM_API_IMPLEMENT(scanner, bool, ui_show_setting(HWND parent, bool with_scan, bo
COM_API_IMPLEMENT(scanner, bool, ui_show_progress(HWND parent, bool bIndicator)) COM_API_IMPLEMENT(scanner, bool, ui_show_progress(HWND parent, bool bIndicator))
{ {
bIndicator = false;
is_bIndicator = bIndicator; is_bIndicator = bIndicator;
ui_notify = std::function<void(int, void*, int)>(); ui_notify = std::function<void(int, void*, int)>();
auto ui_process = [this](ui_result res) auto ui_process = [this](ui_result res)
@ -3026,7 +3027,7 @@ int scanner::handle_device_event(int ev_code, void* data, unsigned int* len)
if (callback::show_progress_ui && is_bIndicator) if (callback::show_progress_ui && is_bIndicator)
ui_notify(ev_code, data, *len); ui_notify(ev_code, data, *len);
on_ui_event(ev_code, (void*)ev_code); on_ui_event(ev_code, (void*)ev_code);
log_debug_info("Scanning ...\r\n", 1); utils::log_info("Scanning ...\r\n", LOG_LEVEL_DEBUG);
} }
else if (ev_code == SANE_EVENT_IMAGE_OK) else if (ev_code == SANE_EVENT_IMAGE_OK)
{ {
@ -3050,7 +3051,7 @@ int scanner::handle_device_event(int ev_code, void* data, unsigned int* len)
images_.count(&bytes); images_.count(&bytes);
bytes /= 1024 * 1024; bytes /= 1024 * 1024;
if (times == 1) if (times == 1)
log_debug_info("Memory usage upto limit! wait up to 100 ms ...\r\n", 1); utils::log_info("Memory usage upto limit! wait up to 100 ms ...\r\n", LOG_LEVEL_DEBUG);
} }
images_.save(img, img->bytes()); images_.save(img, img->bytes());
} }
@ -3065,7 +3066,7 @@ int scanner::handle_device_event(int ev_code, void* data, unsigned int* len)
{ {
char msg[128] = { 0 }; char msg[128] = { 0 };
sprintf_s(msg, _countof(msg) - 1, "New image(%u) received with %u bytes\r\n", img_ind_, simg->bytes); sprintf_s(msg, _countof(msg) - 1, "New image(%u) received with %u bytes\r\n", img_ind_, simg->bytes);
log_debug_info(msg, 1); utils::log_info(msg, (log_level)1);
} }
} }
else if (ev_code == SANE_EVENT_USB_DATA_RECEIVED) else if (ev_code == SANE_EVENT_USB_DATA_RECEIVED)
@ -3096,7 +3097,7 @@ int scanner::handle_device_event(int ev_code, void* data, unsigned int* len)
{ {
char msg[128] = { 0 }; char msg[128] = { 0 };
sprintf_s(msg, _countof(msg) - 1, "Scan finished with error: %u\r\n", *len); sprintf_s(msg, _countof(msg) - 1, "Scan finished with error: %u\r\n", *len);
log_debug_info(msg, 1); utils::log_info(msg, (log_level)1);
} }
} }
//else if (ev_code == SANE_EVENT_ERROR) // 屏蔽,在停止扫描时展示信息 - 2023-05-30 //else if (ev_code == SANE_EVENT_ERROR) // 屏蔽,在停止扫描时展示信息 - 2023-05-30
@ -3233,35 +3234,6 @@ extern "C"
return 0; return 0;
} }
void log_debug_info(const char* info, int level)
{
utils::log_info(info, (log_level)level);
}
void log_mem_info(const char* desc, const void* data, size_t bytes)
{
std::string line(desc);
char buf[40] = {0};
utils::log_info((line + "\n").c_str());
line = "";
for(size_t i = 0; i < bytes; ++i)
{
if((i % 16) == 0)
{
if(line.length())
utils::log_info((line + "\n").c_str());
sprintf(buf, "%p ", (const char*)data + i);
line = buf;
}
else if((i % 8) == 0)
line += " ";
sprintf(buf, "%02x ", ((const unsigned char*)data)[i]);
line += buf;
}
if(line.length())
utils::log_info((line + "\n").c_str());
}
ISaneInvoker* sane_wapper_open_scanner(SCANNERID scanner_id, int* err, bool last_try) ISaneInvoker* sane_wapper_open_scanner(SCANNERID scanner_id, int* err, bool last_try)
{ {