设备所线程,和打开准备线程(升级等),调整239 按照业务进行锁的操作

This commit is contained in:
13038267101 2023-05-24 14:46:34 +08:00
parent df805cc81c
commit 661f9bccd6
4 changed files with 170 additions and 118 deletions

View File

@ -333,30 +333,63 @@ int hg_scanner::save_2_tempory_file(std::shared_ptr<std::vector<char>> data, std
void hg_scanner::thread_devslock_handle(void) void hg_scanner::thread_devslock_handle(void)
{ {
int ret = SCANNER_ERR_OK; int ret = SCANNER_ERR_OK;
wait_devsislock_.wait(); while (run_)
while (is_firstopen_ && is_kernelsnap_devsislock)
{ {
if (!is_read_int) wait_devsislock_.wait();
#ifdef OEM_HUAGAO
if (is_firstopen_ && is_kernelsnap_devsislock)
{ {
std::this_thread::sleep_for(std::chrono::milliseconds(500)); std::this_thread::sleep_for(std::chrono::milliseconds(500));
ret = set_server_blacklist_lock(); ret = set_server_blacklist_lock();
hg_version_free_handle(); hg_version_free_handle();
is_firstopen_ = false;
} }
#endif
is_firstopen_ = false;
is_read_int = false;
} }
//int ret = SCANNER_ERR_OK;
//wait_devsislock_.wait();
//while (is_firstopen_ && is_kernelsnap_devsislock)
//{
// if (!is_read_int)
// {
// std::this_thread::sleep_for(std::chrono::milliseconds(500));
// ret = set_server_blacklist_lock();
// hg_version_free_handle();
// is_firstopen_ = false;
// }
//}
} }
void hg_scanner::thread_read_int(void) void hg_scanner::thread_read_int(void)
{ {
if (is_read_int && pid_ == 0x0300) while (run_)
{ {
wait_read_int.wait(); wait_read_int.wait();
is_read_int = true; if (is_read_int && is_firstopen_)
notify_ui_working_status(STATU_DESC_SCANNER_ERR_DEVICE_DEVS_BOOTING, SANE_EVENT_STATUS, status_); {
//discard_all_images(); is_read_int = true;
set_updata0303(); notify_ui_working_status(STATU_DESC_SCANNER_ERR_DEVICE_DEVS_BOOTING, SANE_EVENT_STATUS, status_);
notify_ui_working_status(STATU_DESC_SCANNER_ERR_DEVICE_DEVS_START_SUCCES, SANE_EVENT_STATUS, status_); discard_all_images();
//set_updata0303();
notify_ui_working_status(STATU_DESC_SCANNER_ERR_DEVICE_DEVS_START_SUCCES, SANE_EVENT_STATUS, status_);
}
if (is_firstopen_)
{
wait_devsislock_.notify();
}
} }
is_read_int = false;
//if (is_read_int && pid_ == 0x0300)
//{
// wait_read_int.wait();
// is_read_int = true;
// notify_ui_working_status(STATU_DESC_SCANNER_ERR_DEVICE_DEVS_BOOTING, SANE_EVENT_STATUS, status_);
// //discard_all_images();
// set_updata0303();
// notify_ui_working_status(STATU_DESC_SCANNER_ERR_DEVICE_DEVS_START_SUCCES, SANE_EVENT_STATUS, status_);
//}
//is_read_int = false;
} }
void hg_scanner::thread_handle_usb(void) void hg_scanner::thread_handle_usb(void)
{ {

View File

@ -127,6 +127,7 @@ int hg_scanner_200::on_scanner_closing(bool force)
} }
int hg_scanner_200::discard_all_images(void) int hg_scanner_200::discard_all_images(void)
{ {
discard_prev();
return SCANNER_ERR_OK; return SCANNER_ERR_OK;
} }
void hg_scanner_200::thread_handle_usb_read(void) void hg_scanner_200::thread_handle_usb_read(void)

View File

@ -170,12 +170,12 @@ hg_scanner_239::hg_scanner_239(const char* dev_name, int pid,usb_io* io) : hg_sc
init_settings((jsontext4 + jsontext5).c_str()); init_settings((jsontext4 + jsontext5).c_str());
} }
hg_version_init_handle(); hg_version_init_handle();
init_version(); //init_version();
#ifdef OEM_HUAGAO //#ifdef OEM_HUAGAO
wait_devsislock_.notify(); // wait_devsislock_.notify();
#endif //#endif
//wait_read_int.notify(); wait_read_int.notify();
} }
hg_scanner_239::~hg_scanner_239() hg_scanner_239::~hg_scanner_239()
{ {
@ -183,8 +183,6 @@ hg_scanner_239::~hg_scanner_239()
} }
int hg_scanner_239::read_register(int addr, int* val) int hg_scanner_239::read_register(int addr, int* val)
{ {
std::lock_guard<std::mutex> lock(io_lock_);
int l = sizeof(*val), int l = sizeof(*val),
ret = io_->control_io(0x0c0, USB_REQ_GET_DEV_REGS, addr, 0, val, &l); ret = io_->control_io(0x0c0, USB_REQ_GET_DEV_REGS, addr, 0, val, &l);
@ -195,8 +193,6 @@ int hg_scanner_239::read_register(int addr, int* val)
} }
int hg_scanner_239::write_register(int addr, int val) int hg_scanner_239::write_register(int addr, int val)
{ {
std::lock_guard<std::mutex> lock(io_lock_);
int l = sizeof(val), int l = sizeof(val),
ret = io_->control_io(0x040, USB_REQ_SET_DEV_REGS, addr, 0, &val, &l); ret = io_->control_io(0x040, USB_REQ_SET_DEV_REGS, addr, 0, &val, &l);
@ -218,8 +214,6 @@ std::string hg_scanner_239::control_fetch(int addr, int val, int size)
ret = write_register(addr, val); ret = write_register(addr, val);
if (ret == SCANNER_ERR_OK) if (ret == SCANNER_ERR_OK)
{ {
std::lock_guard<std::mutex> lock(io_lock_);
l = size + 1; l = size + 1;
data.resize(size + 2); data.resize(size + 2);
bzero(&data[0], size + 2); bzero(&data[0], size + 2);
@ -265,14 +259,20 @@ int hg_scanner_239::get_scan_mode(bool &type)
} }
int hg_scanner_239::set_speed_mode(int data) int hg_scanner_239::set_speed_mode(int data)
{ {
std::lock_guard<std::mutex> lock(io_lock_);
return write_register(setting3399::SR_SET_SPEEDMODE, data); return write_register(setting3399::SR_SET_SPEEDMODE, data);
} }
int hg_scanner_239::get_speed_mode(int& data) int hg_scanner_239::get_speed_mode(int& data)
{ {
std::lock_guard<std::mutex> lock(io_lock_);
return read_register(setting3399::SR_GET_SPEEDMODE, &data); return read_register(setting3399::SR_GET_SPEEDMODE, &data);
} }
int hg_scanner_239::set_devs_distortion_check_val(float data) int hg_scanner_239::set_devs_distortion_check_val(float data)
{ {
std::lock_guard<std::mutex> lock(io_lock_);
int val = *(int*)&data; int val = *(int*)&data;
setting3399::Scanner_Reg_Defs ratio = setting3399::SR_SET_V_200_RATIO; setting3399::Scanner_Reg_Defs ratio = setting3399::SR_SET_V_200_RATIO;
if (resolution_ <= 200) if (resolution_ <= 200)
@ -286,6 +286,8 @@ int hg_scanner_239::set_devs_distortion_check_val(float data)
} }
int hg_scanner_239::get_devs_distortion_check_val(float& data) int hg_scanner_239::get_devs_distortion_check_val(float& data)
{ {
std::lock_guard<std::mutex> lock(io_lock_);
int val = 0; int val = 0;
setting3399::Scanner_Reg_Defs ratio = setting3399::SR_SET_V_200_RATIO; setting3399::Scanner_Reg_Defs ratio = setting3399::SR_SET_V_200_RATIO;
if (resolution_ <= 200) if (resolution_ <= 200)
@ -301,6 +303,8 @@ int hg_scanner_239::get_devs_distortion_check_val(float& data)
} }
int hg_scanner_239::set_auto_flat(int data) int hg_scanner_239::set_auto_flat(int data)
{ {
std::lock_guard<std::mutex> lock(io_lock_);
int ret = SCANNER_ERR_OK; int ret = SCANNER_ERR_OK;
auto fw = get_firmware_version(); auto fw = get_firmware_version();
if (fw.empty()) if (fw.empty())
@ -332,6 +336,8 @@ int hg_scanner_239::set_auto_flat(int data)
} }
int hg_scanner_239::get_status(void) int hg_scanner_239::get_status(void)
{ {
std::lock_guard<std::mutex> lock(io_lock_);
int val = 0, int val = 0,
ret = read_register(setting3399::SR_STATUS, &val); ret = read_register(setting3399::SR_STATUS, &val);
@ -347,6 +353,8 @@ int hg_scanner_239::get_status(void)
} }
bool hg_scanner_239::is_dev_image_process_done(void) bool hg_scanner_239::is_dev_image_process_done(void)
{ {
std::lock_guard<std::mutex> lock(io_lock_);
int val = 0, int val = 0,
ret = read_register(setting3399::SR_GET_IMAGEPROCESSDONE, &val); ret = read_register(setting3399::SR_GET_IMAGEPROCESSDONE, &val);
@ -362,7 +370,8 @@ bool hg_scanner_239::is_dev_image_process_done(void)
} }
bool hg_scanner_239::is_dev_image_keep_last_paper(void) bool hg_scanner_239::is_dev_image_keep_last_paper(void)
{ {
std::lock_guard<std::mutex> lock(io_lock_);
int val = 0, int val = 0,
ret = read_register(setting3399::SR_GET_KEEP_LAST_PAPER, &val); ret = read_register(setting3399::SR_GET_KEEP_LAST_PAPER, &val);
@ -378,6 +387,8 @@ bool hg_scanner_239::is_dev_image_keep_last_paper(void)
} }
int hg_scanner_239::get_image_count(void) int hg_scanner_239::get_image_count(void)
{ {
std::lock_guard<std::mutex> lock(io_lock_);
int val = 0, int val = 0,
ret = read_register(setting3399::SR_IM_COUNT, &val); ret = read_register(setting3399::SR_IM_COUNT, &val);
@ -390,6 +401,8 @@ int hg_scanner_239::get_image_count(void)
} }
int hg_scanner_239::get_front_data_size(void) int hg_scanner_239::get_front_data_size(void)
{ {
std::lock_guard<std::mutex> lock(io_lock_);
int val = 0, int val = 0,
ret = read_register(setting3399::SR_IM_FRONT_SIZE, &val); ret = read_register(setting3399::SR_IM_FRONT_SIZE, &val);
@ -403,6 +416,7 @@ int hg_scanner_239::get_front_data_size(void)
} }
void hg_scanner_239::init_version(void) void hg_scanner_239::init_version(void)
{ {
std::string fv(get_firmware_version()), std::string fv(get_firmware_version()),
sn(get_serial_num()); sn(get_serial_num());
if (fv.empty() || sn.empty()) if (fv.empty() || sn.empty())
@ -471,6 +485,8 @@ void hg_scanner_239::init_version(void)
} }
int hg_scanner_239::writedown_device_configuration(bool type, setting_hardware::HGSCANCONF_3399* dev_conf) int hg_scanner_239::writedown_device_configuration(bool type, setting_hardware::HGSCANCONF_3399* dev_conf)
{ {
std::lock_guard<std::mutex> lock(io_lock_);
int ret = SCANNER_ERR_OK; int ret = SCANNER_ERR_OK;
if (!type) if (!type)
return ret; return ret;
@ -516,7 +532,8 @@ int hg_scanner_239::writedown_device_configuration(bool type, setting_hardware:
} }
int hg_scanner_239::writedown_image_configuration(void) int hg_scanner_239::writedown_image_configuration(void)
{ {
int ret = write_register(setting3399::SR_CONFIF_IMGPROCPARAM, sizeof(SCANCONF)); int ret = 0;
if (ret != SCANNER_ERR_OK) if (ret != SCANNER_ERR_OK)
return ret; return ret;
@ -553,7 +570,7 @@ int hg_scanner_239::writedown_image_configuration(void)
{ {
std::lock_guard<std::mutex> lock(io_lock_); std::lock_guard<std::mutex> lock(io_lock_);
ret = write_register(setting3399::SR_CONFIF_IMGPROCPARAM, sizeof(SCANCONF));
ret = io_->write_bulk(&ic, &len); ret = io_->write_bulk(&ic, &len);
this_thread::sleep_for(chrono::milliseconds(500)); this_thread::sleep_for(chrono::milliseconds(500));
@ -563,6 +580,8 @@ int hg_scanner_239::writedown_image_configuration(void)
} }
int hg_scanner_239::pop_first_image(void) int hg_scanner_239::pop_first_image(void)
{ {
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);
if (ret) if (ret)
{ {
@ -576,9 +595,7 @@ int hg_scanner_239::read_one_image_from_usb(SANE_Image_Statu statu)
total = get_front_data_size(), total = get_front_data_size(),
off = 0, off = 0,
ret = SCANNER_ERR_OK; ret = SCANNER_ERR_OK;
//LOG_INFO(LOG_LEVEL_DEBUG_INFO, "\n") bool is_scanner_err_ok = false;
//LOG_INFO(LOG_LEVEL_DEBUG_INFO,"------------------------------------------------------------\n")
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "read_one_image_from_usb get data total len is:%d\n", total);
if (!waiting_for_memory_enough(total)) if (!waiting_for_memory_enough(total))
{ {
@ -590,12 +607,16 @@ int hg_scanner_239::read_one_image_from_usb(SANE_Image_Statu statu)
ret = status_; ret = status_;
else else
{ {
std::lock_guard<std::mutex> lock(io_lock_);
std::shared_ptr<tiny_buffer> buf(aquire_memory(total)); std::shared_ptr<tiny_buffer> buf(aquire_memory(total));
if (!buf.get()) if (!buf.get())
return SCANNER_ERR_INSUFFICIENT_MEMORY; return SCANNER_ERR_INSUFFICIENT_MEMORY;
// write reading command // write reading command
ret = write_register(setting3399::SR_IM_TX, 1); ret = write_register(setting3399::SR_IM_TX, 1);
buf->set_image_statu(statu); buf->set_image_statu(statu);
if (ret == SCANNER_ERR_OK) if (ret == SCANNER_ERR_OK)
@ -603,7 +624,6 @@ int hg_scanner_239::read_one_image_from_usb(SANE_Image_Statu statu)
std::this_thread::sleep_for(std::chrono::milliseconds(10)); std::this_thread::sleep_for(std::chrono::milliseconds(10));
r = total; r = total;
{ {
std::lock_guard<std::mutex> lock(io_lock_);
unsigned int size = r; unsigned int size = r;
void* buff = buf->data(off, &size); void* buff = buf->data(off, &size);
@ -652,13 +672,10 @@ 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_1(LOG_LEVEL_DEBUG_INFO, "Read image from USB = %s\n", hg_scanner_err_name(ret));
ret = save_usb_data(buf); ret = save_usb_data(buf);
if (ret == SCANNER_ERR_OK) if (ret == SCANNER_ERR_OK)
{ {
pop_first_image(); is_scanner_err_ok = true;
//if(image_prc_param_.bits.page == PAGE_SINGLE)
// pop_first_image();
} }
} }
else else
@ -667,7 +684,10 @@ int hg_scanner_239::read_one_image_from_usb(SANE_Image_Statu statu)
} }
} }
} }
if (is_scanner_err_ok)
{
pop_first_image();
}
return ret; return ret;
} }
int hg_scanner_239::discard_all_images(void) int hg_scanner_239::discard_all_images(void)
@ -685,12 +705,6 @@ int hg_scanner_239::discard_all_images(void)
setting3399::HGEIntInfo* info = (setting3399::HGEIntInfo*)buf; setting3399::HGEIntInfo* info = (setting3399::HGEIntInfo*)buf;
{ {
std::lock_guard<std::mutex> lock(io_lock_); std::lock_guard<std::mutex> lock(io_lock_);
if (!io_)
{
return 0;
}
oto = io_->get_timeout();
io_->set_timeout(100);
ret = io_->read_interrupt(buf, &size); ret = io_->read_interrupt(buf, &size);
} }
while (ret == SCANNER_ERR_OK) while (ret == SCANNER_ERR_OK)
@ -713,13 +727,9 @@ int hg_scanner_239::discard_all_images(void)
} }
} }
std::this_thread::sleep_for(std::chrono::milliseconds(1000)); std::this_thread::sleep_for(std::chrono::milliseconds(1000));
if (!io_)
{
return 0;
}
if (is_read_int) if (is_read_int)
{ {
//init_version(); init_version();
} }
if (pre_int) if (pre_int)
@ -912,6 +922,7 @@ int hg_scanner_239::on_skew_check_level_changed(int& check)
} }
int hg_scanner_239::on_get_feedmode(int &feedmode)//获取分纸强度 int hg_scanner_239::on_get_feedmode(int &feedmode)//获取分纸强度
{ {
std::lock_guard<std::mutex> lock(io_lock_);
int ret = SCANNER_ERR_OK, int ret = SCANNER_ERR_OK,
val = 0; val = 0;
@ -925,6 +936,7 @@ int hg_scanner_239::on_get_feedmode(int &feedmode)//获取分纸强度
} }
int hg_scanner_239::on_set_feedmode(int feedmode)//设置分纸强度 int hg_scanner_239::on_set_feedmode(int feedmode)//设置分纸强度
{ {
std::lock_guard<std::mutex> lock(io_lock_);
int ret = SCANNER_ERR_OK, int ret = SCANNER_ERR_OK,
val = 0; val = 0;
@ -941,6 +953,8 @@ int hg_scanner_239::on_pic_type(bool& pic)
} }
int hg_scanner_239::on_pick_paper(bool autostrength) int hg_scanner_239::on_pick_paper(bool autostrength)
{ {
std::lock_guard<std::mutex> lock(io_lock_);
int val = 0, int val = 0,
ret = write_register(setting3399::SR_SET_AUTOMATICCONTROLFEEDMODE_ENABLE, autostrength); ret = write_register(setting3399::SR_SET_AUTOMATICCONTROLFEEDMODE_ENABLE, autostrength);
if (ret != SCANNER_ERR_OK) if (ret != SCANNER_ERR_OK)
@ -1175,9 +1189,8 @@ void hg_scanner_239::thread_get_dves_image(void)
//break; //break;
} }
svdevs_err_.push_back(status_); svdevs_err_.push_back(status_);
//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_)); //break;
//break; //这个时候退出的话消息就还没读完错误信息先保存下来只有获取到stop时才退出如果没获取完退出可能会导致第二次扫描直接返回扫描完成 //这个时候退出的话消息就还没读完错误信息先保存下来只有获取到stop时才退出如果没获取完退出可能会导致第二次扫描直接返回扫描完成
//设备返回stop就是告诉我设备已经准备好可以进行下来操作。
} }
if (info->From == setting3399::IMG) if (info->From == setting3399::IMG)
@ -1229,6 +1242,7 @@ void hg_scanner_239::thread_get_dves_image(void)
ret = status_; ret = status_;
else else
status_ = ret = SCANNER_ERR_USER_CANCELED; status_ = ret = SCANNER_ERR_USER_CANCELED;
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "%s:%s\n", hg_log::lang_load(ID_STATU_DESC_SCANNER_ERR_DEVICE_GET_USER_CANCEL_SCAN), hg_scanner_err_name(status_)); VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "%s:%s\n", hg_log::lang_load(ID_STATU_DESC_SCANNER_ERR_DEVICE_GET_USER_CANCEL_SCAN), hg_scanner_err_name(status_));
auoto_paper_indx = 0; auoto_paper_indx = 0;
break; break;
@ -1247,15 +1261,14 @@ void hg_scanner_239::thread_get_dves_image(void)
status_ = SCANNER_ERR_OK; status_ = SCANNER_ERR_OK;
int s = get_status(); int s = get_status();
//VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "status after received 'STOPSCAN': 0x%x\n", s);
if (count == 0 || (s & 3) == 0) if (count == 0 || (s & 3) == 0)
{ {
LOG_INFO(LOG_LEVEL_DEBUG_INFO, "Really stopped ^_^\n"); LOG_INFO(LOG_LEVEL_DEBUG_INFO, "Really stopped ^_^\n");
//string str = "当前批次扫描完成(第"+to_string(++auoto_paper_indx)+"批)";
//string str = "\345\275\223\345\211\215\346\211\271\346\254\241\346\211\253\346\217\217\345\256\214\346\210\220(\347\254\254" + to_string(++auoto_paper_indx) + "\346\211\271)";
string str = hg_log::lang_load(ID_STATU_DESC_SCANNER_ERR_DEVICE_ROUND_SACN_OVER); string str = hg_log::lang_load(ID_STATU_DESC_SCANNER_ERR_DEVICE_ROUND_SACN_OVER);
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())
notify_ui_working_status(str.c_str(), SANE_EVENT_ERROR, status_); notify_ui_working_status(str.c_str(), SANE_EVENT_ERROR, status_);
else else
@ -1287,22 +1300,10 @@ void hg_scanner_239::thread_get_dves_image(void)
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_)); 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_));
} }
} }
/*else
VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "read %d bytes, sizeof(buf) = %d\n", size, sizeof(buf));*/
this_thread::sleep_for(chrono::milliseconds(10)); this_thread::sleep_for(chrono::milliseconds(10));
} }
if (status_ == SCANNER_ERR_DEVICE_STOPPED && !user_cancel_)
{ // stop 通过int端点返回 如果不反回则是固件问题,软件不做处理
//通过int端点返回 如果不反回则是固件问题,软件不做处理
//SANE_Bool b = true;
//ret = get_scanner_paperon(b);
//if (ret != SCANNER_ERR_OK)
//{
// status_ = ret;
//}
//status_ = b ? SCANNER_ERR_OK : SCANNER_ERR_DEVICE_NO_PAPER;
}
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_)); 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_));
} }
void hg_scanner_239::thread_handle_usb_read(void) void hg_scanner_239::thread_handle_usb_read(void)
@ -1315,16 +1316,6 @@ void hg_scanner_239::thread_handle_usb_read(void)
int hg_scanner_239::start(void) int hg_scanner_239::start(void)
{ {
/*StopWatch sw;
while (is_read_int)
{
if (sw.elapsed_s() > 10)
{
break;
}
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
VLOG_MINI_1(LOG_LEVEL_WARNING, "device status is(%s)\n", STATU_DESC_SCANNER_ERR_DEVICE_DEVS_BOOTING);
}*/
bool handled = false; bool handled = false;
int ret = try_third_app_handle_start(handled), int ret = try_third_app_handle_start(handled),
val = 0; val = 0;
@ -1332,6 +1323,11 @@ int hg_scanner_239::start(void)
if (handled) if (handled)
return ret; return ret;
if (is_read_int)
{
VLOG_MINI_1(LOG_LEVEL_WARNING, "device status is(%s)\n", STATU_DESC_SCANNER_ERR_DEVICE_DEVS_BOOTING);
return SCANNER_ERR_DEVICE_DEVS_BOOTING;
}
user_cancel_ = false; user_cancel_ = false;
ret = on_is_auto_paper(is_auto_paper_scan); ret = on_is_auto_paper(is_auto_paper_scan);
@ -1339,10 +1335,8 @@ int hg_scanner_239::start(void)
cb_mem_ = true; cb_mem_ = true;
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "scanner status: 0x%x\n", get_status()); VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "scanner status: 0x%x\n", get_status());
//notify_ui_working_status(hg_log::lang_load(ID_STATU_DESC_PREPARE_START));
reset(); reset();
//ret = get_roller_num(val);
//211220固件版本不支持返回 //211220固件版本不支持返回
ret = get_scan_is_sleep(val); ret = get_scan_is_sleep(val);
@ -1352,7 +1346,7 @@ int hg_scanner_239::start(void)
VLOG_MINI_1(LOG_LEVEL_WARNING, "device start status is(%s)\n", hg_log::lang_load(ID_STATU_DESC_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));
if(is_kernelsnap_220830_) if(is_kernelsnap_220830_)
ret = set_notify_sleep(); ret = set_notify_sleep();
//notify_ui_working_status(STATU_DESC_SCANNER_ERR_DEVICE_NOTIFY_SLEEP, SANE_EVENT_ERROR, status_);
return status_; return status_;
} }
if (ret != SCANNER_ERR_OK) if (ret != SCANNER_ERR_OK)
@ -1367,7 +1361,6 @@ int hg_scanner_239::start(void)
return status_; return status_;
} }
//notify_ui_working_status(STATU_DESC_REWRITE_CONFIGURATION);
if(ret == SCANNER_ERR_OK) if(ret == SCANNER_ERR_OK)
{ {
ret = writedown_device_configuration(true); ret = writedown_device_configuration(true);
@ -1380,11 +1373,6 @@ 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)); 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));
//std::string info(STATU_DESC_REWRITE_CONFIGURATION);
//info += std::string("\345\244\261\350\264\245\357\274\232") + hg_scanner_err_name(ret);
//notify_ui_working_status(info.c_str(), SANE_EVENT_ERROR, ret);
} }
if (ret != SCANNER_ERR_OK) if (ret != SCANNER_ERR_OK)
@ -1464,22 +1452,26 @@ int hg_scanner_239::device_io_control(unsigned long code, void* data, unsigned*
} }
std::string hg_scanner_239::get_firmware_version(void) std::string hg_scanner_239::get_firmware_version(void)
{ {
std::lock_guard<std::mutex> lock(io_lock_);
return control_fetch(setting3399::SR_GET_FWVERSION, 0, 20); return control_fetch(setting3399::SR_GET_FWVERSION, 0, 20);
} }
std::string hg_scanner_239::get_serial_num(void) std::string hg_scanner_239::get_serial_num(void)
{ {
std::lock_guard<std::mutex> lock(io_lock_);
int len = 0; int len = 0;
read_register(setting3399::SR_GET_SERIAL_LEN, &len);///??? read_register(setting3399::SR_GET_SERIAL_LEN, &len);///???
return control_fetch(setting3399::SR_GET_SERIALNUM, 0, len).substr(0,len); return control_fetch(setting3399::SR_GET_SERIALNUM, 0, len).substr(0,len);
} }
std::string hg_scanner_239::get_ip(void) std::string hg_scanner_239::get_ip(void)
{ {
std::lock_guard<std::mutex> lock(io_lock_);
int len = 0; int len = 0;
read_register(setting3399::SR_GET_SERIAL_LEN, &len); read_register(setting3399::SR_GET_SERIAL_LEN, &len);
return control_fetch(setting3399::SR_GET_IPADDR, 0, len); return control_fetch(setting3399::SR_GET_IPADDR, 0, len);
} }
std::string hg_scanner_239::get_device_model(void) std::string hg_scanner_239::get_device_model(void)
{ {
std::lock_guard<std::mutex> lock(io_lock_);
string device_model = "/home/linaro/microtek_sn"; string device_model = "/home/linaro/microtek_sn";
string str; string str;
@ -1517,6 +1509,7 @@ int hg_scanner_239::set_device_model(string str)
{ {
return SCANNER_ERR_NO_DATA; return SCANNER_ERR_NO_DATA;
} }
std::lock_guard<std::mutex> lock(io_lock_);
string device_model = "/home/linaro/microtek_sn"; string device_model = "/home/linaro/microtek_sn";
int ret = SCANNER_ERR_OK; int ret = SCANNER_ERR_OK;
@ -1545,6 +1538,7 @@ int hg_scanner_239::set_device_model(string str)
} }
int hg_scanner_239::set_serial_num(string str) int hg_scanner_239::set_serial_num(string str)
{ {
std::lock_guard<std::mutex> lock(io_lock_);
int len = str.size(), int len = str.size(),
ret = write_register(setting3399::SR_SET_SERIALNUM, len); ret = write_register(setting3399::SR_SET_SERIALNUM, len);
if (ret == SCANNER_ERR_OK) if (ret == SCANNER_ERR_OK)
@ -1555,19 +1549,23 @@ int hg_scanner_239::set_serial_num(string str)
} }
int hg_scanner_239::set_vid_pid(int data) int hg_scanner_239::set_vid_pid(int data)
{ {
std::lock_guard<std::mutex> lock(io_lock_);
return write_register(setting3399::SR_SET_USBVIDPID, data); return write_register(setting3399::SR_SET_USBVIDPID, data);
} }
int hg_scanner_239::get_vid_pid(int& data) int hg_scanner_239::get_vid_pid(int& data)
{ {
std::lock_guard<std::mutex> lock(io_lock_);
return read_register(setting3399::SR_GET_USBVIDPID, &data); return read_register(setting3399::SR_GET_USBVIDPID, &data);
} }
int hg_scanner_239::get_history_scan_count(int &val) int hg_scanner_239::get_history_scan_count(int &val)
{ {
std::lock_guard<std::mutex> lock(io_lock_);
int ret = read_register(setting3399::SR_GET_SCANN_NUM, &val); int ret = read_register(setting3399::SR_GET_SCANN_NUM, &val);
return ret; return ret;
} }
int hg_scanner_239::set_clear_roller_num(void) int hg_scanner_239::set_clear_roller_num(void)
{ {
std::lock_guard<std::mutex> lock(io_lock_);
int val = 0, int val = 0,
ret = read_register(setting3399::SR_CLR_ROLLER_NUM, &val); ret = read_register(setting3399::SR_CLR_ROLLER_NUM, &val);
@ -1575,6 +1573,7 @@ int hg_scanner_239::set_clear_roller_num(void)
} }
int hg_scanner_239::set_clear_history_num(void) int hg_scanner_239::set_clear_history_num(void)
{ {
std::lock_guard<std::mutex> lock(io_lock_);
int val = 0, int val = 0,
ret = read_register(setting3399::SR_CLR_SCANN_NUM, &val); ret = read_register(setting3399::SR_CLR_SCANN_NUM, &val);
@ -1583,6 +1582,7 @@ int hg_scanner_239::set_clear_history_num(void)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int hg_scanner_239::set_leaflet_scan(void) int hg_scanner_239::set_leaflet_scan(void)
{ {
std::lock_guard<std::mutex> lock(io_lock_);
int ret = SCANNER_ERR_OK; int ret = SCANNER_ERR_OK;
test_1_paper_ = true; test_1_paper_ = true;
@ -1596,6 +1596,7 @@ int hg_scanner_239::get_device_code(void)
} }
int hg_scanner_239::get_sleep_time(int& data) int hg_scanner_239::get_sleep_time(int& data)
{ {
std::lock_guard<std::mutex> lock(io_lock_);
int val = 0; int val = 0;
int ret = read_register(setting3399::SR_GET_SLEEPTIME, &val); int ret = read_register(setting3399::SR_GET_SLEEPTIME, &val);
@ -1610,6 +1611,8 @@ int hg_scanner_239::get_sleep_time(int& data)
} }
int hg_scanner_239::set_sleep_time(int setsleepime) int hg_scanner_239::set_sleep_time(int setsleepime)
{ {
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)); VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "set sleep time to %d = %s\n", setsleepime, hg_scanner_err_name(ret));
@ -1620,6 +1623,8 @@ int hg_scanner_239::set_sleep_time(int setsleepime)
int hg_scanner_239::get_scanner_paperon(SANE_Bool& type) int hg_scanner_239::get_scanner_paperon(SANE_Bool& type)
{ {
std::lock_guard<std::mutex> lock(io_lock_);
int val = 0; int val = 0;
int ret = read_register(setting3399::SR_GET_PAPERON, &val); //0无纸 1有纸 int ret = read_register(setting3399::SR_GET_PAPERON, &val); //0无纸 1有纸
if (ret == SCANNER_ERR_OK) if (ret == SCANNER_ERR_OK)
@ -1633,6 +1638,8 @@ int hg_scanner_239::get_scanner_paperon(SANE_Bool& type)
int hg_scanner_239::get_scan_is_sleep(SANE_Bool& type) int hg_scanner_239::get_scan_is_sleep(SANE_Bool& type)
{ {
std::lock_guard<std::mutex> lock(io_lock_);
int ret = 0,val; int ret = 0,val;
ret = read_register(setting3399::SR_GET_SLEEP_STAUTUS, &val); //0休眠 1唤醒状态 ret = read_register(setting3399::SR_GET_SLEEP_STAUTUS, &val); //0休眠 1唤醒状态
if (ret == SCANNER_ERR_OK) if (ret == SCANNER_ERR_OK)
@ -1643,6 +1650,8 @@ int hg_scanner_239::get_scan_is_sleep(SANE_Bool& type)
} }
int hg_scanner_239::set_notify_sleep() int hg_scanner_239::set_notify_sleep()
{ {
std::lock_guard<std::mutex> lock(io_lock_);
int val = 0, int val = 0,
ret = SCANNER_ERR_OK; ret = SCANNER_ERR_OK;
if (is_kernelsnap_220830_) if (is_kernelsnap_220830_)
@ -1653,11 +1662,15 @@ int hg_scanner_239::set_notify_sleep()
} }
int hg_scanner_239::get_roller_num(int &num) int hg_scanner_239::get_roller_num(int &num)
{ {
std::lock_guard<std::mutex> lock(io_lock_);
int ret = read_register(setting3399::SR_GET_ROLLER_NUM, &num); int ret = read_register(setting3399::SR_GET_ROLLER_NUM, &num);
return ret; return ret;
} }
int hg_scanner_239::get_device_log(string &logpath) int hg_scanner_239::get_device_log(string &logpath)
{ {
std::lock_guard<std::mutex> lock(io_lock_);
string save_path = hg_log::temporary_path() + PATH_SEPARATOR + "device.log"; string save_path = hg_log::temporary_path() + PATH_SEPARATOR + "device.log";
string device_log_path = "/var/log/syslog"; string device_log_path = "/var/log/syslog";
string str ; string str ;
@ -1719,10 +1732,14 @@ int hg_scanner_239::get_device_log(string &logpath)
} }
int hg_scanner_239::set_devreboot(int data) int hg_scanner_239::set_devreboot(int data)
{ {
std::lock_guard<std::mutex> lock(io_lock_);
return write_register(setting3399::SR_REBOOT, data); return write_register(setting3399::SR_REBOOT, data);
} }
int hg_scanner_239::set_devshtudown() int hg_scanner_239::set_devshtudown()
{ {
std::lock_guard<std::mutex> lock(io_lock_);
int val = 0, int val = 0,
ret = write_register(setting3399::SR_POWEROFF, val); ret = write_register(setting3399::SR_POWEROFF, val);
@ -1731,6 +1748,8 @@ int hg_scanner_239::set_devshtudown()
} }
int hg_scanner_239::set_scan_islock(SANE_Bool set_islock) int hg_scanner_239::set_scan_islock(SANE_Bool set_islock)
{ {
std::lock_guard<std::mutex> lock(io_lock_);
if (!is_kernelsnap_devsislock) if (!is_kernelsnap_devsislock)
{ {
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "devs lock:%s \n", hg_scanner_err_name(SCANNER_ERR_DEVICE_NOT_SUPPORT)); VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "devs lock:%s \n", hg_scanner_err_name(SCANNER_ERR_DEVICE_NOT_SUPPORT));
@ -1751,23 +1770,25 @@ int hg_scanner_239::set_scan_islock(SANE_Bool set_islock)
} }
int hg_scanner_239::get_scan_islock(SANE_Bool& islock) int hg_scanner_239::get_scan_islock(SANE_Bool& islock)
{ {
std::lock_guard<std::mutex> lock(io_lock_);
if (!is_kernelsnap_devsislock) if (!is_kernelsnap_devsislock)
{ {
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "devs lock:%s \n", hg_scanner_err_name(SCANNER_ERR_DEVICE_NOT_SUPPORT)); VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "devs lock:%s \n", hg_scanner_err_name(SCANNER_ERR_DEVICE_NOT_SUPPORT));
return SCANNER_ERR_DEVICE_NOT_SUPPORT; return SCANNER_ERR_DEVICE_NOT_SUPPORT;
} }
int val = 0, int val = 0,
ret = read_register(setting3399::SR_GET_LOCK_STATES, &val); ret = read_register(setting3399::SR_GET_LOCK_STATES, &val);
if (ret != SCANNER_ERR_OK) if (ret != SCANNER_ERR_OK)
return ret;
islock = val;
ret = islock ? SCANNER_ERR_DEVICE_ISLOCK : SCANNER_ERR_OK;
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Get scanner is lock:%d\r\n", ret);
return ret; return ret;
islock = val;
ret = islock ? SCANNER_ERR_DEVICE_ISLOCK : SCANNER_ERR_OK;
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Get scanner is lock:%d\r\n", 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)
{ {
@ -1814,13 +1835,16 @@ int hg_scanner_239::set_scan_lock_check_val(string check_str)
CryptoPP::StringSource* source_cipher = new CryptoPP::StringSource(cipher, true, hex_encode); CryptoPP::StringSource* source_cipher = new CryptoPP::StringSource(cipher, true, hex_encode);
int len = encoded.length(); int len = encoded.length();
int ret = write_register(setting3399::SR_DECODE_TOKEN, len);
if (ret != SCANNER_ERR_OK)
{
return ret;
}
ret = io_->write_bulk(&encoded[0], &len); int ret = SCANNER_ERR_OK;
{
std::lock_guard<std::mutex> lock(io_lock_);
ret = write_register(setting3399::SR_DECODE_TOKEN, len);
if (ret == SCANNER_ERR_OK)
{
ret = io_->write_bulk(&encoded[0], &len);
}
}
SAFE_DELETE(source_plain); SAFE_DELETE(source_plain);
//SAFE_DELETE(ecb_filter); //SAFE_DELETE(ecb_filter);
@ -1833,7 +1857,8 @@ int hg_scanner_239::set_scan_lock_check_val(string check_str)
} }
int hg_scanner_239::set_firmware_upgrade(std::string filename) int hg_scanner_239::set_firmware_upgrade(std::string filename)
{ {
// std::lock_guard<std::mutex> lock(io_lock_); std::lock_guard<std::mutex> lock(io_lock_);
std::ifstream fwname; std::ifstream fwname;
int ret = SCANNER_ERR_OK; int ret = SCANNER_ERR_OK;
@ -1911,13 +1936,16 @@ int hg_scanner_239::set_firmware_upgrade(std::string filename)
} }
int hg_scanner_239::set_clean_paper_road() int hg_scanner_239::set_clean_paper_road()
{ {
//std::lock_guard<std::mutex> lock(io_lock_); std::lock_guard<std::mutex> lock(io_lock_);
int ret = 0, len = 0; int ret = 0, len = 0;
ret = write_register(setting3399::SR_CLEAN_PAPER_ROAD, len); ret = write_register(setting3399::SR_CLEAN_PAPER_ROAD, len);
return ret; return ret;
} }
int hg_scanner_239::get_dev_islock_file(int& islockfile) int hg_scanner_239::get_dev_islock_file(int& islockfile)
{ {
std::lock_guard<std::mutex> lock(io_lock_);
if (!is_kernelsnap_devsislock) if (!is_kernelsnap_devsislock)
{ {
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "devs lock:%s \n", hg_scanner_err_name(SCANNER_ERR_DEVICE_NOT_SUPPORT)); VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "devs lock:%s \n", hg_scanner_err_name(SCANNER_ERR_DEVICE_NOT_SUPPORT));
@ -1957,6 +1985,8 @@ int hg_scanner_239::get_dev_islock_file(int& islockfile)
} }
int hg_scanner_239::set_dev_islock_file(int islockfile) int hg_scanner_239::set_dev_islock_file(int islockfile)
{ {
std::lock_guard<std::mutex> lock(io_lock_);
if (!is_kernelsnap_devsislock) if (!is_kernelsnap_devsislock)
{ {
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "devs lock:%s \n", hg_scanner_err_name(SCANNER_ERR_DEVICE_NOT_SUPPORT)); VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "devs lock:%s \n", hg_scanner_err_name(SCANNER_ERR_DEVICE_NOT_SUPPORT));

View File

@ -91,7 +91,7 @@ hg_scanner_300::hg_scanner_300(const char* dev_name,int pid, usb_io* io) : hg_sc
else else
init_settings((jsontext3 + jsontext4 + jsontext5).c_str()); init_settings((jsontext3 + jsontext4 + jsontext5).c_str());
} }
initdevice(); //initdevice();
wait_read_int.notify(); wait_read_int.notify();
} }
hg_scanner_300::~hg_scanner_300() hg_scanner_300::~hg_scanner_300()
@ -295,24 +295,12 @@ int hg_scanner_300::discard_all_images(void)
if (is_read_int) if (is_read_int)
{ {
//initdevice(); initdevice();
} }
return SCANNER_ERR_OK; return SCANNER_ERR_OK;
} }
int hg_scanner_300::start(void) int hg_scanner_300::start(void)
{ {
//StopWatch sw;
// while (is_read_int)
//{
// if (sw.elapsed_s() > 10)
//{
// break;
//}
//std::this_thread::sleep_for(std::chrono::milliseconds(1000));
//VLOG_MINI_1(LOG_LEVEL_WARNING, "device status is(%s)\n", STATU_DESC_SCANNER_ERR_DEVICE_DEVS_BOOTING);
//}
//discard_all_images();
bool handled = false; bool handled = false;
int ret = try_third_app_handle_start(handled), //sane调用是每次都会调用一次start和stop int ret = try_third_app_handle_start(handled), //sane调用是每次都会调用一次start和stop
count = -1, count = -1,