diff --git a/hgdriver/hgdev/hg_scanner.cpp b/hgdriver/hgdev/hg_scanner.cpp index 8f2de91..eb2f866 100644 --- a/hgdriver/hgdev/hg_scanner.cpp +++ b/hgdriver/hgdev/hg_scanner.cpp @@ -395,10 +395,10 @@ int hg_scanner::read_image_data(uint8_t* buf, size_t* len) { return SCANNER_ERR_OK; } -int hg_scanner::status(EP0REPLYSTATUS* ds) +int hg_scanner::status(EP0REPLYSTATUS* ds, bool en_dev_log) { if (ds) - scanner_->get_scanner_status(ds); + scanner_->get_scanner_status(ds, en_dev_log); return status_; } diff --git a/hgdriver/hgdev/hg_scanner.h b/hgdriver/hgdev/hg_scanner.h index c379aa2..2efb1c2 100644 --- a/hgdriver/hgdev/hg_scanner.h +++ b/hgdriver/hgdev/hg_scanner.h @@ -118,7 +118,7 @@ public: int re_connect(void); int get_image_info(SANE_Parameters* pii); int read_image_data(uint8_t* buf, size_t* len); - int status(EP0REPLYSTATUS* ds = nullptr); + int status(EP0REPLYSTATUS* ds = nullptr, bool en_dev_log = false/*enable device write log of this status*/); std::string status_message(void); bool is_online(void); diff --git a/hgdriver/hgdev/scanner/async_usb_host.cpp b/hgdriver/hgdev/scanner/async_usb_host.cpp index a6095de..835bf78 100644 --- a/hgdriver/hgdev/scanner/async_usb_host.cpp +++ b/hgdriver/hgdev/scanner/async_usb_host.cpp @@ -601,10 +601,22 @@ int async_usb_host::get_peer_config(LPPEERCFG cfg) { SIMPLE_LOCK(io_lock_); PEERCFG v = { 0 }; - int err = libusb_control_transfer(usb_handle_, LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_IN - , USB_REQ_EP0_GET_PEER_CONFIG, 0, 0 - , (unsigned char*)&v, sizeof(v) - , 1000); + int err = 0; + + v.pid = GetCurrentProcessId(); + v.io_size = utils::get_page_size(); + v.ver = PROTOCOL_VER; + err = libusb_control_transfer(usb_handle_, LIBUSB_REQUEST_TYPE_VENDOR/* | LIBUSB_ENDPOINT_IN*/ + , USB_REQ_EP0_HAND_SHAKE, 0, 0 + , (unsigned char*)&v, sizeof(v) + , 1000); + if (err == sizeof(v)) + { + err = libusb_control_transfer(usb_handle_, LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_IN + , USB_REQ_EP0_HAND_SHAKE, 0, 0 + , (unsigned char*)&v, sizeof(v) + , 1000); + } if (cfg) *cfg = v; @@ -619,12 +631,12 @@ uint32_t async_usb_host::get_io_buffer_size(void) { return peer_cfg_.io_size; } -int async_usb_host::get_peer_status(LPEP0REPLYSTATUS status) +int async_usb_host::get_peer_status(LPEP0REPLYSTATUS status, bool en_dev_log) { SIMPLE_LOCK(io_lock_); return libusb_control_transfer(usb_handle_, LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_IN - , USB_REQ_EP0_GET_STATUS, 0, 0 + , USB_REQ_EP0_GET_STATUS, 0, en_dev_log , (unsigned char*)status, sizeof(*status) , 1000) == sizeof(*status) ? 0 : EFAULT; } @@ -653,7 +665,7 @@ int async_usb_host::reset_peer(uint32_t timeout) empty->release(); tc.reset(); - while ((err = get_peer_status(&status)) == 0) + while ((err = get_peer_status(&status, false)) == 0) { if (status.in_status == WORKER_STATUS_IDLE && status.out_status == WORKER_STATUS_IDLE && status.task_cnt == 0 && status.task_required_bytes == 0 && status.packets_to_sent == 0) diff --git a/hgdriver/hgdev/scanner/async_usb_host.h b/hgdriver/hgdev/scanner/async_usb_host.h index b1d9371..7f18921 100644 --- a/hgdriver/hgdev/scanner/async_usb_host.h +++ b/hgdriver/hgdev/scanner/async_usb_host.h @@ -93,7 +93,7 @@ public: int get_peer_config(LPPEERCFG cfg); uint16_t get_protocol_version(void); uint32_t get_io_buffer_size(void); - int get_peer_status(LPEP0REPLYSTATUS status); + int get_peer_status(LPEP0REPLYSTATUS status, bool en_dev_log); int reset_peer(uint32_t timeout = 2000/*ms*/); int set_gadget_encrypting_method(uint32_t cmd_enc = ENCRYPT_CMD_NONE, uint32_t payload_enc = ENCRYPT_NONE, uint8_t enc_data = 0); diff --git a/hgdriver/hgdev/scanner/scanner_handler.cpp b/hgdriver/hgdev/scanner/scanner_handler.cpp index 5cb9c16..15d6a14 100644 --- a/hgdriver/hgdev/scanner/scanner_handler.cpp +++ b/hgdriver/hgdev/scanner/scanner_handler.cpp @@ -324,12 +324,12 @@ int scanner_handler::get_peer_config(LPPEERCFG cfg) return 0; } -int scanner_handler::get_scanner_status(LPEP0REPLYSTATUS status) +int scanner_handler::get_scanner_status(LPEP0REPLYSTATUS status, bool en_dev_log) { if (!is_scanner_available()) return ENODEV; - return usb_->get_peer_status(status); + return usb_->get_peer_status(status, en_dev_log); } int scanner_handler::restart_peer_bulk(uint32_t timeout) { diff --git a/hgdriver/hgdev/scanner/scanner_handler.h b/hgdriver/hgdev/scanner/scanner_handler.h index c67e753..0cce736 100644 --- a/hgdriver/hgdev/scanner/scanner_handler.h +++ b/hgdriver/hgdev/scanner/scanner_handler.h @@ -99,7 +99,7 @@ protected: public: // following methods transferred by EP0 int get_peer_config(LPPEERCFG cfg); - int get_scanner_status(LPEP0REPLYSTATUS status); + int get_scanner_status(LPEP0REPLYSTATUS status, bool en_dev_log); int restart_peer_bulk(uint32_t timeout = 1000/*ms*/); // following methods transferred by Bulk, blocked ... diff --git a/sdk/base/data.cpp b/sdk/base/data.cpp index 2af22e5..c13c361 100644 --- a/sdk/base/data.cpp +++ b/sdk/base/data.cpp @@ -486,7 +486,7 @@ file_reader::~file_reader() if (map_) map_->release(); notify_progress(len_, len_, 0); // ensure 100% - utils::to_log(LOG_LEVEL_DEBUG, "Read over of file(%s) at(%p/%p).\n", path_.c_str(), consume_, len_); + utils::to_log(LOG_LEVEL_DEBUG, "Read over of file(%s) at(%llu/%llu).\n", path_.c_str(), consume_, len_); } int file_reader::open(const char* file, bool in_mem, size_t off) diff --git a/sdk/base/packet.h b/sdk/base/packet.h index 50ea2d0..cb89e61 100644 --- a/sdk/base/packet.h +++ b/sdk/base/packet.h @@ -46,8 +46,8 @@ enum cancel_io }; enum ep0_req { - USB_REQ_EP0_GET_PEER_CONFIG = 100, // get protocol version (PROTOCOL_VER), req = me, ind = 0, val = 0, len = sizeof(PEERCFG) - USB_REQ_EP0_GET_STATUS, // 获取各工作线程状态, return EP0REPLYSTATUS. req = me, ind = 0, val = 0, len = sizeof(EP0REPLYSTATUS) + USB_REQ_EP0_HAND_SHAKE = 100, // hand-shake[in/out] with data LPPEERCFG, req = me, ind = 0, val = 0, len = sizeof(PEERCFG) + USB_REQ_EP0_GET_STATUS, // 获取各工作线程状态, return EP0REPLYSTATUS. req = me, ind = 0, val = bool: whether write log, len = sizeof(EP0REPLYSTATUS) USB_REQ_EP0_CANCEL_IO, // 设置当前IO数据的有效性. req = me, ind = 0, val = 0, len = sizeof(uint32_t), discard IO data when data is CANCEL_IO_CANCEL // work-flow: write control with 'CANCEL_IO_CANCEL', write bulk with 1 byte, write control with not 'CANCEL_IO_CANCEL' to restore USB_REQ_EP0_SET_ENCRYPT, // 设置加密方式, req = me, ind = 0, val = 0, len = sizeof(PACK_BASE) @@ -258,9 +258,10 @@ typedef struct _ep0_reply typedef struct _peer_config { - uint16_t ver; // protocol version + uint64_t pid; // [in] - host pc process id; [out] - usb service process id uint32_t io_size; // IO buffer size -}PEERCFG, *LPPEERCFG; + uint16_t ver; // protocol version +}PEERCFG, * LPPEERCFG; typedef struct _pack_base // A piece of data has only one header { diff --git a/sdk/base/plat_types.h b/sdk/base/plat_types.h index 17f31ce..354fe72 100644 --- a/sdk/base/plat_types.h +++ b/sdk/base/plat_types.h @@ -16,6 +16,7 @@ #define ALIGN_TO(v, align) (((v) + (align) - 1) / (align) * (align)) #define ALIGN_INT(v) ALIGN_TO(v, sizeof(int)) +#define CLEAN_ARRAY(a) memset(a, 0, sizeof(a)) #define RETURN_ENUM_STR(v, e) \ if(v == e) \ diff --git a/sdk/base/utils.h b/sdk/base/utils.h index 52c53af..f01aef7 100644 --- a/sdk/base/utils.h +++ b/sdk/base/utils.h @@ -94,6 +94,17 @@ namespace utils bool run_get_message(HWND hwnd, UINT filter_min = 0, UINT filter_max = 0, std::function msghandler = std::function()); #endif + template + std::string format_string(const char* fmt, Args ... args) + { + size_t size = snprintf(nullptr, 0, fmt, args ...) + 2; + std::unique_ptr buf(new char[size]); + + snprintf(buf.get(), size, fmt, args ...); + + return buf.get(); + } + template void to_log(int level, const char* fmt, Args ... args) { diff --git a/sdk/imgprc/img_processor.h b/sdk/imgprc/img_processor.h index df3193c..2f48463 100644 --- a/sdk/imgprc/img_processor.h +++ b/sdk/imgprc/img_processor.h @@ -31,6 +31,7 @@ typedef struct _proc_img_info_ { HGIMGINFO info; cv::Mat img; + std::string ext_info; // 图片扩展信息(图像处理过程中可以保存各算法间的共有信息;处理完后为向用户提供的扩展信息) }PROCIMGINFO, *LPPROCIMGINFO; typedef struct _proc_img_info_modules // 跨模块参数 diff --git a/sdk/sane_opt_json/base_opt.cpp b/sdk/sane_opt_json/base_opt.cpp index 70ae256..63069d2 100644 --- a/sdk/sane_opt_json/base_opt.cpp +++ b/sdk/sane_opt_json/base_opt.cpp @@ -2,6 +2,8 @@ #include #include +#include +#include sane_opt_provider::sane_opt_provider() @@ -16,6 +18,20 @@ sane_opt_provider::~sane_opt_provider() following_.clear(); } +std::string sane_opt_provider::sane_value_2_text(const char* type, void* value) +{ + if(strcmp(type, JSON_SANE_TYPE_BOOL) == 0) + return *(bool*)value ? "true" : "false"; + else if(strcmp(type, JSON_SANE_TYPE_INT) == 0) + return std::to_string(*(int*)value); + else if(strcmp(type, JSON_SANE_TYPE_FIXED) == 0) + return std::to_string(*(double*)value); + else if(strcmp(type, JSON_SANE_TYPE_STRING) == 0) + return (char*)value; + else + return ""; +} + bool sane_opt_provider::set_opt_json_text(char* txt) { gb_json* jsn = new gb_json(); diff --git a/sdk/sane_opt_json/base_opt.h b/sdk/sane_opt_json/base_opt.h index 6f163cd..cb87518 100644 --- a/sdk/sane_opt_json/base_opt.h +++ b/sdk/sane_opt_json/base_opt.h @@ -22,6 +22,8 @@ protected: public: sane_opt_provider(); + static std::string sane_value_2_text(const char* type, void* value); // convert to readable text. e.g. bool to "true" or "false", ... + protected: virtual ~sane_opt_provider(); diff --git a/sdk/sane_opt_json/device_opt.cpp b/sdk/sane_opt_json/device_opt.cpp index 59aa556..54f2ed0 100644 --- a/sdk/sane_opt_json/device_opt.cpp +++ b/sdk/sane_opt_json/device_opt.cpp @@ -1207,7 +1207,11 @@ void device_option::insert_option(gb_json* opt, sane_opt_provider* from, const c if (!opt->get_value("auto", can_auto) || can_auto) { + std::string type(""); + opt->get_value("type", type); val.resize(size); + type = sane_opt_provider::sane_value_2_text(type.c_str(), &val[0]); + utils::to_log(LOG_LEVEL_ALL, "Set option '%s' to default value: '%s'\n", opt->key().c_str(), type.c_str()); from->set_value(opt->key().c_str(), &val[0]); } } @@ -1716,8 +1720,9 @@ bool device_option::refine_data(const char* name, void* value) now_->get_value(name, child); if (child) { - std::string type(""); + std::string type(""), org(""), result(""); child->get_value("type", type); + org = sane_opt_provider::sane_value_2_text(type.c_str(), value); if (type == JSON_SANE_TYPE_BOOL) { refined = refine_data_to_range(child, value); @@ -1734,6 +1739,11 @@ bool device_option::refine_data(const char* name, void* value) { refined = refine_string_data(child, value); } + if(refined) + { + result = sane_opt_provider::sane_value_2_text(type.c_str(), value); + utils::to_log(LOG_LEVEL_DEBUG, "Refine value of '%s' from '%s' to '%s'.\n", name, org.c_str(), result.c_str()); + } child->release(); } @@ -1788,11 +1798,13 @@ int device_option::update_data(const char* name, void* value, bool reorder_if_ne } } + child->get_value("type", type); + utils::to_log(LOG_LEVEL_DEBUG, "set option '%s' value to '%s' = %d.\n", name, sane_opt_provider::sane_value_2_text(type.c_str(), value).c_str(), err); + if (err == SCANNER_ERR_OK || err == SCANNER_ERR_NOT_EXACT || err == SCANNER_ERR_RELOAD_IMAGE_PARAM || err == SCANNER_ERR_RELOAD_OPT_PARAM || err == SCANNER_ERR_CONFIGURATION_CHANGED) { - child->get_value("type", type); if (type == JSON_SANE_TYPE_BOOL) { child->set_value("cur", *(bool*)value);