调整图像结构定义;第一个通讯改为握手协议
This commit is contained in:
parent
ae09199deb
commit
46c617fa8b
|
@ -395,10 +395,10 @@ int hg_scanner::read_image_data(uint8_t* buf, size_t* len)
|
||||||
{
|
{
|
||||||
return SCANNER_ERR_OK;
|
return SCANNER_ERR_OK;
|
||||||
}
|
}
|
||||||
int hg_scanner::status(EP0REPLYSTATUS* ds)
|
int hg_scanner::status(EP0REPLYSTATUS* ds, bool en_dev_log)
|
||||||
{
|
{
|
||||||
if (ds)
|
if (ds)
|
||||||
scanner_->get_scanner_status(ds);
|
scanner_->get_scanner_status(ds, en_dev_log);
|
||||||
|
|
||||||
return status_;
|
return status_;
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,7 +118,7 @@ public:
|
||||||
int re_connect(void);
|
int re_connect(void);
|
||||||
int get_image_info(SANE_Parameters* pii);
|
int get_image_info(SANE_Parameters* pii);
|
||||||
int read_image_data(uint8_t* buf, size_t* len);
|
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);
|
std::string status_message(void);
|
||||||
bool is_online(void);
|
bool is_online(void);
|
||||||
|
|
||||||
|
|
|
@ -601,10 +601,22 @@ int async_usb_host::get_peer_config(LPPEERCFG cfg)
|
||||||
{
|
{
|
||||||
SIMPLE_LOCK(io_lock_);
|
SIMPLE_LOCK(io_lock_);
|
||||||
PEERCFG v = { 0 };
|
PEERCFG v = { 0 };
|
||||||
int err = libusb_control_transfer(usb_handle_, LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_IN
|
int err = 0;
|
||||||
, USB_REQ_EP0_GET_PEER_CONFIG, 0, 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)
|
, (unsigned char*)&v, sizeof(v)
|
||||||
, 1000);
|
, 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)
|
if (cfg)
|
||||||
*cfg = v;
|
*cfg = v;
|
||||||
|
@ -619,12 +631,12 @@ uint32_t async_usb_host::get_io_buffer_size(void)
|
||||||
{
|
{
|
||||||
return peer_cfg_.io_size;
|
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_);
|
SIMPLE_LOCK(io_lock_);
|
||||||
|
|
||||||
return libusb_control_transfer(usb_handle_, LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_IN
|
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)
|
, (unsigned char*)status, sizeof(*status)
|
||||||
, 1000) == sizeof(*status) ? 0 : EFAULT;
|
, 1000) == sizeof(*status) ? 0 : EFAULT;
|
||||||
}
|
}
|
||||||
|
@ -653,7 +665,7 @@ int async_usb_host::reset_peer(uint32_t timeout)
|
||||||
empty->release();
|
empty->release();
|
||||||
|
|
||||||
tc.reset();
|
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
|
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)
|
&& status.task_required_bytes == 0 && status.packets_to_sent == 0)
|
||||||
|
|
|
@ -93,7 +93,7 @@ public:
|
||||||
int get_peer_config(LPPEERCFG cfg);
|
int get_peer_config(LPPEERCFG cfg);
|
||||||
uint16_t get_protocol_version(void);
|
uint16_t get_protocol_version(void);
|
||||||
uint32_t get_io_buffer_size(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 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);
|
int set_gadget_encrypting_method(uint32_t cmd_enc = ENCRYPT_CMD_NONE, uint32_t payload_enc = ENCRYPT_NONE, uint8_t enc_data = 0);
|
||||||
|
|
||||||
|
|
|
@ -324,12 +324,12 @@ int scanner_handler::get_peer_config(LPPEERCFG cfg)
|
||||||
|
|
||||||
return 0;
|
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())
|
if (!is_scanner_available())
|
||||||
return ENODEV;
|
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)
|
int scanner_handler::restart_peer_bulk(uint32_t timeout)
|
||||||
{
|
{
|
||||||
|
|
|
@ -99,7 +99,7 @@ protected:
|
||||||
public:
|
public:
|
||||||
// following methods transferred by EP0
|
// following methods transferred by EP0
|
||||||
int get_peer_config(LPPEERCFG cfg);
|
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*/);
|
int restart_peer_bulk(uint32_t timeout = 1000/*ms*/);
|
||||||
|
|
||||||
// following methods transferred by Bulk, blocked ...
|
// following methods transferred by Bulk, blocked ...
|
||||||
|
|
|
@ -486,7 +486,7 @@ file_reader::~file_reader()
|
||||||
if (map_)
|
if (map_)
|
||||||
map_->release();
|
map_->release();
|
||||||
notify_progress(len_, len_, 0); // ensure 100%
|
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)
|
int file_reader::open(const char* file, bool in_mem, size_t off)
|
||||||
|
|
|
@ -46,8 +46,8 @@ enum cancel_io
|
||||||
};
|
};
|
||||||
enum ep0_req
|
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_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 = 0, len = sizeof(EP0REPLYSTATUS)
|
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
|
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
|
// 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)
|
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
|
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
|
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
|
typedef struct _pack_base // A piece of data has only one header
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
#define ALIGN_TO(v, align) (((v) + (align) - 1) / (align) * (align))
|
#define ALIGN_TO(v, align) (((v) + (align) - 1) / (align) * (align))
|
||||||
#define ALIGN_INT(v) ALIGN_TO(v, sizeof(int))
|
#define ALIGN_INT(v) ALIGN_TO(v, sizeof(int))
|
||||||
|
#define CLEAN_ARRAY(a) memset(a, 0, sizeof(a))
|
||||||
|
|
||||||
#define RETURN_ENUM_STR(v, e) \
|
#define RETURN_ENUM_STR(v, e) \
|
||||||
if(v == e) \
|
if(v == e) \
|
||||||
|
|
|
@ -94,6 +94,17 @@ namespace utils
|
||||||
bool run_get_message(HWND hwnd, UINT filter_min = 0, UINT filter_max = 0, std::function<bool(MSG*, bool*)> msghandler = std::function<bool(MSG*, bool*)>());
|
bool run_get_message(HWND hwnd, UINT filter_min = 0, UINT filter_max = 0, std::function<bool(MSG*, bool*)> msghandler = std::function<bool(MSG*, bool*)>());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
template<typename ... Args>
|
||||||
|
std::string format_string(const char* fmt, Args ... args)
|
||||||
|
{
|
||||||
|
size_t size = snprintf(nullptr, 0, fmt, args ...) + 2;
|
||||||
|
std::unique_ptr<char[]> buf(new char[size]);
|
||||||
|
|
||||||
|
snprintf(buf.get(), size, fmt, args ...);
|
||||||
|
|
||||||
|
return buf.get();
|
||||||
|
}
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
|
|
@ -31,6 +31,7 @@ typedef struct _proc_img_info_
|
||||||
{
|
{
|
||||||
HGIMGINFO info;
|
HGIMGINFO info;
|
||||||
cv::Mat img;
|
cv::Mat img;
|
||||||
|
std::string ext_info; // 图片扩展信息(图像处理过程中可以保存各算法间的共有信息;处理完后为向用户提供的扩展信息)
|
||||||
}PROCIMGINFO, *LPPROCIMGINFO;
|
}PROCIMGINFO, *LPPROCIMGINFO;
|
||||||
|
|
||||||
typedef struct _proc_img_info_modules // 跨模块参数
|
typedef struct _proc_img_info_modules // 跨模块参数
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
#include <json/gb_json.h>
|
#include <json/gb_json.h>
|
||||||
#include <huagao/hgscanner_error.h>
|
#include <huagao/hgscanner_error.h>
|
||||||
|
#include <sane/sane_ex.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
sane_opt_provider::sane_opt_provider()
|
sane_opt_provider::sane_opt_provider()
|
||||||
|
@ -16,6 +18,20 @@ sane_opt_provider::~sane_opt_provider()
|
||||||
following_.clear();
|
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)
|
bool sane_opt_provider::set_opt_json_text(char* txt)
|
||||||
{
|
{
|
||||||
gb_json* jsn = new gb_json();
|
gb_json* jsn = new gb_json();
|
||||||
|
|
|
@ -22,6 +22,8 @@ protected:
|
||||||
public:
|
public:
|
||||||
sane_opt_provider();
|
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:
|
protected:
|
||||||
virtual ~sane_opt_provider();
|
virtual ~sane_opt_provider();
|
||||||
|
|
||||||
|
|
|
@ -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)
|
if (!opt->get_value("auto", can_auto) || can_auto)
|
||||||
{
|
{
|
||||||
|
std::string type("");
|
||||||
|
opt->get_value("type", type);
|
||||||
val.resize(size);
|
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]);
|
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);
|
now_->get_value(name, child);
|
||||||
if (child)
|
if (child)
|
||||||
{
|
{
|
||||||
std::string type("");
|
std::string type(""), org(""), result("");
|
||||||
child->get_value("type", type);
|
child->get_value("type", type);
|
||||||
|
org = sane_opt_provider::sane_value_2_text(type.c_str(), value);
|
||||||
if (type == JSON_SANE_TYPE_BOOL)
|
if (type == JSON_SANE_TYPE_BOOL)
|
||||||
{
|
{
|
||||||
refined = refine_data_to_range<bool>(child, value);
|
refined = refine_data_to_range<bool>(child, value);
|
||||||
|
@ -1734,6 +1739,11 @@ bool device_option::refine_data(const char* name, void* value)
|
||||||
{
|
{
|
||||||
refined = refine_string_data(child, 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();
|
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
|
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_RELOAD_IMAGE_PARAM || err == SCANNER_ERR_RELOAD_OPT_PARAM
|
||||||
|| err == SCANNER_ERR_CONFIGURATION_CHANGED)
|
|| err == SCANNER_ERR_CONFIGURATION_CHANGED)
|
||||||
{
|
{
|
||||||
child->get_value("type", type);
|
|
||||||
if (type == JSON_SANE_TYPE_BOOL)
|
if (type == JSON_SANE_TYPE_BOOL)
|
||||||
{
|
{
|
||||||
child->set_value("cur", *(bool*)value);
|
child->set_value("cur", *(bool*)value);
|
||||||
|
|
Loading…
Reference in New Issue