控制台增加查看USB端口状态命令;隐藏属性不直接删除,改用临时不可用属性补位,以保证SANE协议输出属性总数不变。

This commit is contained in:
gb 2024-03-15 14:48:55 +08:00
parent 3e45a71083
commit 1731171766
12 changed files with 141 additions and 17 deletions

View File

@ -688,3 +688,17 @@ int async_scanner::last_error(void)
return last_err_;
}
void async_scanner::print_usb_status(void)
{
EP0REPLYSTATUS status;
char *stdesc[] = {"WORKER_STATUS_NOT_START", "WORKER_STATUS_IDLE"
, "WORKER_STATUS_BUSY", "WORKER_STATUS_ERROR", "WORKER_STATUS_RESET"
, "WORKER_STATUS_WAIT_RESOURCE"};
memset(&status, 0, sizeof(status));
usb_->get_ep_status(&status);
printf("Bulk-In status: %s, error = %d, %u bytes in que\n", stdesc[status.in_status], status.in_err, status.bytes_to_sent);
printf("Bulk-Out status: %s, error = %d, need %u bytes data of task %d\n", stdesc[status.out_status]
, status.out_err, status.task_required_bytes, status.task_cmd);
}

View File

@ -70,4 +70,8 @@ protected:
public:
uint32_t stop(void);
int last_error(void);
// console command ...
public:
void print_usb_status(void);
};

View File

@ -186,6 +186,8 @@ int main()
test_cmd::read_memory(cmd.c_str());
else if(cmd == "clear")
system("clear");
else if(cmd == "status")
scanner->print_usb_status();
else if(cmd.find(test_cmd::sys_cmd) == 0)
test_cmd::invoke_sys_command(cmd.c_str());
else

View File

@ -1712,6 +1712,79 @@ namespace utils
return std::move(std::string((char*)&bfh, sizeof(bfh)));
}
void exchange_rb(int w, int h, int line_len, uint8_t* bits)
{
for (int r = 0; r < h; ++r)
{
uint8_t* cur = bits;
for (int c = 0; c < w; ++c)
{
cur[0] ^= cur[2];
cur[2] ^= cur[0];
cur[0] ^= cur[2];
cur += 3;
}
bits += line_len;
}
}
void reverse_line(int line_len, int h, uint8_t* bits)
{
uint8_t* tail = bits + (h - 1) * line_len;
for (int r = 0; r < h / 2; ++r)
{
uint64_t *l1 = (uint64_t*)bits,
*l2 = (uint64_t*)tail;
uint64_t val = 0;
for (int c = 0; c < line_len / sizeof(val); ++c)
{
val = *l1;
*l1++ = *l2;
*l2++ = val;
}
if (line_len % sizeof(val))
{
uint8_t *r1 = (uint8_t*)l1,
*r2 = (uint8_t*)l2,
v = 0;
switch (line_len % sizeof(val))
{
case 7:
v = *r1;
*r1++ = *r2;
*r2++ = v;
case 6:
v = *r1;
*r1++ = *r2;
*r2++ = v;
case 5:
v = *r1;
*r1++ = *r2;
*r2++ = v;
case 4:
v = *r1;
*r1++ = *r2;
*r2++ = v;
case 3:
v = *r1;
*r1++ = *r2;
*r2++ = v;
case 2:
v = *r1;
*r1++ = *r2;
*r2++ = v;
case 1:
default:
v = *r1;
*r1++ = *r2;
*r2++ = v;
}
}
bits += line_len;
tail -= line_len;
}
}
int save_bitmap(const char* file, int w, int h, int bpp, int dpix, int dpiy, void* bits)
{
int err = 0;

View File

@ -134,6 +134,8 @@ namespace utils
// bitmap header ...
std::string bitmap_info_header(int pixel_w, int pixel_h, int bpp, int dpix, int dpiy = 0); // return BITMPINFOHEADER + pallete if need. dpiy same as dpix if was ZERO
std::string bitmap_file_header(BITMAPINFOHEADER *lpbi); // return BITMAPFILEHEADER
void exchange_rb(int w, int h, int line_len, uint8_t* bits);
void reverse_line(int line_len, int h, uint8_t* bits);
int save_bitmap(const char* file, int w, int h, int bpp, int dpix, int dpiy, void* bits);
#if OS_WIN

View File

@ -16,9 +16,6 @@
#ifndef sane_h
#define sane_h
#ifndef BACKEND_NAME
#define BACKEND_NAME hgsane
#endif
#ifdef __cplusplus
extern "C" {

View File

@ -210,6 +210,8 @@
// fixed-ids ...
//
// 借鉴TWAIN协议固定ID的做法定义SANE属性的固定ID - 这里与TWAIN中的ID保持一致以方便TWAIN的调用 over-line
#define FIXED_ID_BASE 0x8000
enum sane_option_id
{
SANE_OPT_ID_BASE = 0x8800,

View File

@ -897,6 +897,16 @@ bool device_option::calc_simple_logic_expression(const char* expr, void* param)
return ret;
}
gb_json* device_option::meaningless_option(const char* group)
{
gb_json* ml = new gb_json();
ml->set_value("type", JSON_SANE_TYPE_BUTTON);
ml->set_value("group", group);
ml->set_value("enabled", false);
return ml;
}
void device_option::clear_for_reconstruct(void)
{
@ -1803,7 +1813,7 @@ bool device_option::is_hidden_option(gb_json* opt)
{
bool hidden = false;
int auth = 0;
opt->get_value("auth", auth);
if (!user_ || !user_(auth))
{
@ -1841,6 +1851,10 @@ std::string device_option::option_value(gb_json* jsn, bool def_val)
if (!jsn->get_value(key.c_str(), type))
type = "";
}
else
{
type = "";
}
return std::move(type);
}
@ -2240,11 +2254,18 @@ std::string device_option::get_option_value(const char* name, int type, int* siz
{
gb_json *filter = new gb_json(),
*child = jsn->first_child();
int hidden = 0;
while(child)
{
if(!is_hidden_option(child))
filter->set_value(child->key().c_str(), child);
if (is_hidden_option(child)) // The option count must stay the same in SANE protocol, replace hidden option with meaninless option here
{
child->get_value("group", value);
child->release();
child = device_option::meaningless_option(value.c_str());
child->key() = "hidden-" + std::to_string(++hidden);
}
filter->set_value(child->key().c_str(), child);
child->release();
child = jsn->next_child();
}

View File

@ -184,6 +184,7 @@ class device_option : public refer
static bool parse_simple_logic_expression(gb_json* root, const char* expr, std::string* name, EXPRCALC& calc);
static void init_condition(const char* expr, void* param);
static bool calc_simple_logic_expression(const char* expr, void* param);
static gb_json* meaningless_option(const char* group);
void clear_for_reconstruct(void);
gb_json* group_opt(const char* title);

View File

@ -308,14 +308,8 @@ dyn_mem_ptr async_usb_gadget::handle_ctrl_setup(dyn_mem_ptr data)
reply->set_len(sizeof(struct _ep0_reply));
{
LPEP0REPLYSTATUS lps = (LPEP0REPLYSTATUS)reply->ptr();
lps->in_status = statu_in_;
lps->out_status = statu_out_;
lps->task_cnt = cmd_que_.size();
lps->task_cmd = task_cmd_;
lps->task_pack_id = task_packet_id_;
lps->task_required_bytes = want_bytes_task_;
lps->packets_to_sent = sent_que_.size();
lps->bytes_to_sent = want_bytes_in_;
get_ep_status(lps);
if(pev->u.setup.wValue)
utils::log_mem_info("threads status:", lps, sizeof(*lps), LOG_LEVEL_DEBUG);
}
@ -437,7 +431,7 @@ int async_usb_gadget::inner_write_bulk(int fd, data_source_ptr data, dyn_mem_ptr
}
statu_in_ = ret ? WORKER_STATUS_ERROR : WORKER_STATUS_IDLE;
want_bytes_in_ -= total;
// want_bytes_in_ -= total;
return ret;
}
@ -903,3 +897,15 @@ int async_usb_gadget::last_error(void)
{
return last_err_;
}
void async_usb_gadget::get_ep_status(LPEP0REPLYSTATUS status)
{
status->in_status = statu_in_;
status->out_status = statu_out_;
status->task_cnt = cmd_que_.size();
status->task_cmd = task_cmd_;
status->task_pack_id = task_packet_id_;
status->task_required_bytes = want_bytes_task_;
status->packets_to_sent = sent_que_.size();
status->bytes_to_sent = want_bytes_in_;
}

View File

@ -122,5 +122,7 @@ public:
int stop(void);
int write_bulk(data_source_ptr data); // return sent-que length
int last_error(void);
void get_ep_status(LPEP0REPLYSTATUS status);
};

View File

@ -60,8 +60,8 @@ add_packagedirs("sdk")
add_defines("BUILD_AS_DEVICE")
add_defines("VER_MAIN=2")
add_defines("VER_FAMILY=200")
add_defines("VER_DATE=20240312")
add_defines("VER_BUILD=10")
add_defines("VER_DATE=20240315")
add_defines("VER_BUILD=3")
target("conf")
set_kind("phony")