restore EP0 checking thread and fix reseting-bulk; reset bulk at openning if first bulk communication failed with error TIMEOUTED
This commit is contained in:
parent
4d65a65568
commit
14e5778fa3
|
@ -55,7 +55,7 @@ async_usb_gadget::async_usb_gadget(usb_gadget* gadget, std::function<FUNCTION_PR
|
|||
|
||||
threads_->thread_new(&async_usb_gadget::thread_pump_task);
|
||||
thread_ep0_id_ = threads_->thread_new(&async_usb_gadget::thread_read_ep0);
|
||||
//threads_->thread_new(&async_usb_gadget::thread_check_ep0_status);
|
||||
threads_->thread_new(&async_usb_gadget::thread_check_ep0_status);
|
||||
}
|
||||
|
||||
async_usb_gadget::~async_usb_gadget()
|
||||
|
@ -546,7 +546,7 @@ void async_usb_gadget::thread_read_bulk(void)
|
|||
// log_cls::log(LOG_LEVEL_ALL, "read bulk with 0 byte - %u time(s).\n", cnt_0);
|
||||
// cnt_0 = 0;
|
||||
// }
|
||||
log_cls::log(LOG_LEVEL_ALL, "thread_pump_task do reset-bulk ...\n");
|
||||
log_cls::log(LOG_LEVEL_ALL, "thread_read_bulk do reset-bulk ...\n");
|
||||
buf->release();
|
||||
if(!run_)
|
||||
break;
|
||||
|
@ -786,6 +786,7 @@ void async_usb_gadget::thread_pump_task(void)
|
|||
}
|
||||
void async_usb_gadget::thread_restart_bulk(void)
|
||||
{
|
||||
log_cls::log(LOG_LEVEL_ALL, "reset bulk: 1/5 - clear command queue and sent queue ...\n");
|
||||
dyn_mem_ptr data;
|
||||
while(cmd_que_.take(data, false))
|
||||
data->release();
|
||||
|
@ -794,17 +795,25 @@ void async_usb_gadget::thread_restart_bulk(void)
|
|||
while(sent_que_.take(src, false))
|
||||
src->release();
|
||||
|
||||
sent_que_.quit();
|
||||
cmd_que_.quit();
|
||||
log_cls::log(LOG_LEVEL_ALL, "reset bulk: 2/5 - waiting for IN-endpoint to be idle ...\n");
|
||||
while (status_.in_status != BULK_STATUS_IDLE)
|
||||
{
|
||||
sent_que_.quit();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
}
|
||||
log_cls::log(LOG_LEVEL_ALL, "reset bulk: 3/5 - waiting for task queue to be idle ...\n");
|
||||
while(status_.task_cmd)
|
||||
{
|
||||
cmd_que_.quit();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
}
|
||||
log_cls::log(LOG_LEVEL_ALL, "reset bulk: 4/5 - waiting for OUT-endpoint to be idle(wait data) ...\n");
|
||||
|
||||
// close_bulk();
|
||||
while(status_.in_status != BULK_STATUS_IDLE || status_.out_status != BULK_STATUS_IO || status_.task_cmd)
|
||||
while(status_.out_status != BULK_STATUS_IO)
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
|
||||
// open_bulk();
|
||||
// cmd_que_.quit();
|
||||
reset_bulk_ = false;
|
||||
log_cls::log(LOG_LEVEL_ALL, "reset bulk completed.\n");
|
||||
log_cls::log(LOG_LEVEL_ALL, "reset bulk: 5/5 - completed.\n");
|
||||
}
|
||||
|
||||
int async_usb_gadget::stop(void)
|
||||
|
|
|
@ -709,7 +709,14 @@ void CDlgScanner::set_device(usb::LPUSBPNP pnp)
|
|||
RECT r = { 0 };
|
||||
std::string all("");
|
||||
|
||||
scanner_->option_get_all(all);
|
||||
if (scanner_->option_get_all(all) == ETIMEDOUT)
|
||||
{
|
||||
// reset it ...
|
||||
msg_box(m_hWnd, MB_OK, L"Bulk Trouble", L"Bulk communication TIMEOUTED, will try reset bulk ...");
|
||||
scanner_->reset_message_que();
|
||||
refresh_bulk_status();
|
||||
scanner_->option_get_all(all);
|
||||
}
|
||||
scanner_handler::reorder_device_config_json(all);
|
||||
sane::reset_opts(all.c_str());
|
||||
|
||||
|
|
|
@ -186,7 +186,7 @@ scanner_handler::scanner_handler(void) : usb_(nullptr), status_(SCANNER_STATUS_N
|
|||
*more = dynamic_cast<packet_data_base_ptr>(receiver);
|
||||
}
|
||||
}
|
||||
else if (pack->cmd == PACK_CMD_SCAN_STOP_ROGER)
|
||||
else if (pack->cmd == PACK_CMD_SCAN_FINISHED_ROGER)
|
||||
{
|
||||
data_holder_ptr receiver = img_receiver_(NULL, pack->data);
|
||||
if (receiver)
|
||||
|
|
|
@ -287,10 +287,10 @@ void async_usb_host::thread_pump_task(void)
|
|||
|
||||
if (dh->is_complete() || err)
|
||||
{
|
||||
reply = dyn_mem::memory(sizeof(PACK_BASE));
|
||||
pack = (LPPACK_BASE)reply->ptr();
|
||||
BASE_PACKET_REPLY(*pack, dh->get_packet_command() + 1, dh->get_packet_id(), err);
|
||||
reply->set_len(sizeof(PACK_BASE));
|
||||
//reply = dyn_mem::memory(sizeof(PACK_BASE));
|
||||
//pack = (LPPACK_BASE)reply->ptr();
|
||||
//BASE_PACKET_REPLY(*pack, dh->get_packet_command() + 1, dh->get_packet_id(), err);
|
||||
//reply->set_len(sizeof(PACK_BASE));
|
||||
|
||||
dh->release();
|
||||
dh = nullptr;
|
||||
|
@ -348,24 +348,27 @@ int async_usb_host::bulk_write_buf(uint8_t* buf, int* len)
|
|||
s = 0,
|
||||
err = 0;
|
||||
|
||||
while ((err = libusb_bulk_transfer(usb_handle_, bulk_out_.port, buf, l, &s, 1000)) == 0)
|
||||
do
|
||||
{
|
||||
if (cancel_write_)
|
||||
while ((err = libusb_bulk_transfer(usb_handle_, bulk_out_.port, buf, l, &s, 1000)) == 0)
|
||||
{
|
||||
err = ECANCELED;
|
||||
break;
|
||||
if (cancel_write_)
|
||||
{
|
||||
err = ECANCELED;
|
||||
break;
|
||||
}
|
||||
|
||||
total += s;
|
||||
if (total >= *len)
|
||||
break;
|
||||
|
||||
buf += s;
|
||||
if (*len - total < bulk_size)
|
||||
l = *len - total;
|
||||
else
|
||||
l = bulk_size;
|
||||
}
|
||||
|
||||
total += s;
|
||||
if (total >= *len)
|
||||
break;
|
||||
|
||||
buf += s;
|
||||
if (*len - total < bulk_size)
|
||||
l = *len - total;
|
||||
else
|
||||
l = bulk_size;
|
||||
}
|
||||
} while (err == LIBUSB_ERROR_INTERRUPTED); // should pay more attention to this error !!!
|
||||
*len = total;
|
||||
|
||||
return err;
|
||||
|
|
Loading…
Reference in New Issue