From 661f9bccd61b1daac2bd8811e4c30a85703dfdc6 Mon Sep 17 00:00:00 2001 From: 13038267101 Date: Wed, 24 May 2023 14:46:34 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E6=89=80=E7=BA=BF=E7=A8=8B?= =?UTF-8?q?=EF=BC=8C=E5=92=8C=E6=89=93=E5=BC=80=E5=87=86=E5=A4=87=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=EF=BC=88=E5=8D=87=E7=BA=A7=E7=AD=89=EF=BC=89=EF=BC=8C?= =?UTF-8?q?=E8=B0=83=E6=95=B4239=20=E6=8C=89=E7=85=A7=E4=B8=9A=E5=8A=A1?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E9=94=81=E7=9A=84=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hgdriver/hgdev/hg_scanner.cpp | 61 +++++++-- hgdriver/hgdev/hg_scanner_200.cpp | 1 + hgdriver/hgdev/hg_scanner_239.cpp | 210 +++++++++++++++++------------- hgdriver/hgdev/hg_scanner_300.cpp | 16 +-- 4 files changed, 170 insertions(+), 118 deletions(-) diff --git a/hgdriver/hgdev/hg_scanner.cpp b/hgdriver/hgdev/hg_scanner.cpp index fe6c31b..29c6544 100644 --- a/hgdriver/hgdev/hg_scanner.cpp +++ b/hgdriver/hgdev/hg_scanner.cpp @@ -333,30 +333,63 @@ int hg_scanner::save_2_tempory_file(std::shared_ptr> data, std void hg_scanner::thread_devslock_handle(void) { int ret = SCANNER_ERR_OK; - wait_devsislock_.wait(); - while (is_firstopen_ && is_kernelsnap_devsislock) + while (run_) { - 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)); - ret = set_server_blacklist_lock(); - hg_version_free_handle(); - is_firstopen_ = false; + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + ret = set_server_blacklist_lock(); + hg_version_free_handle(); } +#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) { - if (is_read_int && pid_ == 0x0300) + while (run_) { 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_); + if (is_read_int && is_firstopen_) + { + 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_); + } + 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) { diff --git a/hgdriver/hgdev/hg_scanner_200.cpp b/hgdriver/hgdev/hg_scanner_200.cpp index b7cd52e..58363ea 100644 --- a/hgdriver/hgdev/hg_scanner_200.cpp +++ b/hgdriver/hgdev/hg_scanner_200.cpp @@ -127,6 +127,7 @@ int hg_scanner_200::on_scanner_closing(bool force) } int hg_scanner_200::discard_all_images(void) { + discard_prev(); return SCANNER_ERR_OK; } void hg_scanner_200::thread_handle_usb_read(void) diff --git a/hgdriver/hgdev/hg_scanner_239.cpp b/hgdriver/hgdev/hg_scanner_239.cpp index 18c5168..968bdbf 100644 --- a/hgdriver/hgdev/hg_scanner_239.cpp +++ b/hgdriver/hgdev/hg_scanner_239.cpp @@ -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()); } hg_version_init_handle(); - init_version(); + //init_version(); -#ifdef OEM_HUAGAO - wait_devsislock_.notify(); -#endif - //wait_read_int.notify(); +//#ifdef OEM_HUAGAO +// wait_devsislock_.notify(); +//#endif + wait_read_int.notify(); } 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) { - std::lock_guard lock(io_lock_); - int l = sizeof(*val), 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) { - std::lock_guard lock(io_lock_); - int l = sizeof(val), 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); if (ret == SCANNER_ERR_OK) { - std::lock_guard lock(io_lock_); - l = size + 1; data.resize(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) { + std::lock_guard lock(io_lock_); + return write_register(setting3399::SR_SET_SPEEDMODE, data); } int hg_scanner_239::get_speed_mode(int& data) { + std::lock_guard lock(io_lock_); + return read_register(setting3399::SR_GET_SPEEDMODE, &data); } int hg_scanner_239::set_devs_distortion_check_val(float data) { + std::lock_guard lock(io_lock_); + int val = *(int*)&data; setting3399::Scanner_Reg_Defs ratio = setting3399::SR_SET_V_200_RATIO; 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) { + std::lock_guard lock(io_lock_); + int val = 0; setting3399::Scanner_Reg_Defs ratio = setting3399::SR_SET_V_200_RATIO; 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) { + std::lock_guard lock(io_lock_); + int ret = SCANNER_ERR_OK; auto fw = get_firmware_version(); if (fw.empty()) @@ -332,6 +336,8 @@ int hg_scanner_239::set_auto_flat(int data) } int hg_scanner_239::get_status(void) { + std::lock_guard lock(io_lock_); + int val = 0, 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) { + std::lock_guard lock(io_lock_); + int val = 0, 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) { - + std::lock_guard lock(io_lock_); + int val = 0, 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) { + std::lock_guard lock(io_lock_); + int val = 0, 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) { + std::lock_guard lock(io_lock_); + int val = 0, 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) { + std::string fv(get_firmware_version()), sn(get_serial_num()); 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) { + std::lock_guard lock(io_lock_); + int ret = SCANNER_ERR_OK; if (!type) 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 ret = write_register(setting3399::SR_CONFIF_IMGPROCPARAM, sizeof(SCANCONF)); + int ret = 0; + if (ret != SCANNER_ERR_OK) return ret; @@ -553,7 +570,7 @@ int hg_scanner_239::writedown_image_configuration(void) { std::lock_guard lock(io_lock_); - + ret = write_register(setting3399::SR_CONFIF_IMGPROCPARAM, sizeof(SCANCONF)); ret = io_->write_bulk(&ic, &len); 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) { + std::lock_guard lock(io_lock_); + int ret = write_register(setting3399::SR_IM_POP, 1); if (ret) { @@ -576,9 +595,7 @@ int hg_scanner_239::read_one_image_from_usb(SANE_Image_Statu statu) total = get_front_data_size(), off = 0, ret = SCANNER_ERR_OK; - //LOG_INFO(LOG_LEVEL_DEBUG_INFO, "\n") - //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); + bool is_scanner_err_ok = false; 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_; else { + std::lock_guard lock(io_lock_); + std::shared_ptr buf(aquire_memory(total)); if (!buf.get()) return SCANNER_ERR_INSUFFICIENT_MEMORY; // write reading command + ret = write_register(setting3399::SR_IM_TX, 1); + buf->set_image_statu(statu); 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)); r = total; { - std::lock_guard lock(io_lock_); unsigned int size = r; 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) { - //VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Read image from USB = %s\n", hg_scanner_err_name(ret)); ret = save_usb_data(buf); if (ret == SCANNER_ERR_OK) { - pop_first_image(); - //if(image_prc_param_.bits.page == PAGE_SINGLE) - // pop_first_image(); + is_scanner_err_ok = true; } } 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; } 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; { std::lock_guard lock(io_lock_); - if (!io_) - { - return 0; - } - oto = io_->get_timeout(); - io_->set_timeout(100); ret = io_->read_interrupt(buf, &size); } 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)); - if (!io_) - { - return 0; - } if (is_read_int) { - //init_version(); + init_version(); } 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)//获取分纸强度 { + std::lock_guard lock(io_lock_); int ret = SCANNER_ERR_OK, val = 0; @@ -925,6 +936,7 @@ int hg_scanner_239::on_get_feedmode(int &feedmode)//获取分纸强度 } int hg_scanner_239::on_set_feedmode(int feedmode)//设置分纸强度 { + std::lock_guard lock(io_lock_); int ret = SCANNER_ERR_OK, val = 0; @@ -941,6 +953,8 @@ int hg_scanner_239::on_pic_type(bool& pic) } int hg_scanner_239::on_pick_paper(bool autostrength) { + std::lock_guard lock(io_lock_); + int val = 0, ret = write_register(setting3399::SR_SET_AUTOMATICCONTROLFEEDMODE_ENABLE, autostrength); if (ret != SCANNER_ERR_OK) @@ -1175,9 +1189,8 @@ void hg_scanner_239::thread_get_dves_image(void) //break; } 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; //这个时候退出的话消息就还没读完,错误信息先保存下来,只有获取到stop时才退出,如果没获取完退出,可能会导致第二次扫描直接返回扫描完成 - //设备返回stop就是告诉我设备已经准备好,可以进行下来操作。 + //break; + //这个时候退出的话消息就还没读完,错误信息先保存下来,只有获取到stop时才退出,如果没获取完退出,可能会导致第二次扫描直接返回扫描完成 } if (info->From == setting3399::IMG) @@ -1229,6 +1242,7 @@ void hg_scanner_239::thread_get_dves_image(void) ret = status_; else 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_)); auoto_paper_indx = 0; break; @@ -1247,15 +1261,14 @@ void hg_scanner_239::thread_get_dves_image(void) status_ = SCANNER_ERR_OK; 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) { 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); str += ":" + to_string(++auoto_paper_indx); + if (!user_cancel_ && is_auto_paper_scan && svdevs_err_.empty()) notify_ui_working_status(str.c_str(), SANE_EVENT_ERROR, status_); 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_)); } } - /*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)); } - if (status_ == SCANNER_ERR_DEVICE_STOPPED && !user_cancel_) - { - //通过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; - } + + // stop 通过int端点返回 如果不反回则是固件问题,软件不做处理 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) @@ -1315,16 +1316,6 @@ void hg_scanner_239::thread_handle_usb_read(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; int ret = try_third_app_handle_start(handled), val = 0; @@ -1332,6 +1323,11 @@ int hg_scanner_239::start(void) if (handled) 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; ret = on_is_auto_paper(is_auto_paper_scan); @@ -1339,10 +1335,8 @@ int hg_scanner_239::start(void) cb_mem_ = true; 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(); - //ret = get_roller_num(val); //211220固件版本不支持返回 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)); if(is_kernelsnap_220830_) ret = set_notify_sleep(); - //notify_ui_working_status(STATU_DESC_SCANNER_ERR_DEVICE_NOTIFY_SLEEP, SANE_EVENT_ERROR, status_); + return status_; } if (ret != SCANNER_ERR_OK) @@ -1367,7 +1361,6 @@ int hg_scanner_239::start(void) return status_; } - //notify_ui_working_status(STATU_DESC_REWRITE_CONFIGURATION); if(ret == SCANNER_ERR_OK) { ret = writedown_device_configuration(true); @@ -1380,11 +1373,6 @@ int hg_scanner_239::start(void) 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)); - - //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) @@ -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::lock_guard lock(io_lock_); return control_fetch(setting3399::SR_GET_FWVERSION, 0, 20); } std::string hg_scanner_239::get_serial_num(void) { + std::lock_guard lock(io_lock_); int len = 0; read_register(setting3399::SR_GET_SERIAL_LEN, &len);///??? return control_fetch(setting3399::SR_GET_SERIALNUM, 0, len).substr(0,len); } std::string hg_scanner_239::get_ip(void) { + std::lock_guard lock(io_lock_); int len = 0; read_register(setting3399::SR_GET_SERIAL_LEN, &len); return control_fetch(setting3399::SR_GET_IPADDR, 0, len); } std::string hg_scanner_239::get_device_model(void) { + std::lock_guard lock(io_lock_); string device_model = "/home/linaro/microtek_sn"; string str; @@ -1517,6 +1509,7 @@ int hg_scanner_239::set_device_model(string str) { return SCANNER_ERR_NO_DATA; } + std::lock_guard lock(io_lock_); string device_model = "/home/linaro/microtek_sn"; 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) { + std::lock_guard lock(io_lock_); int len = str.size(), ret = write_register(setting3399::SR_SET_SERIALNUM, len); 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) { + std::lock_guard lock(io_lock_); return write_register(setting3399::SR_SET_USBVIDPID, data); } int hg_scanner_239::get_vid_pid(int& data) { + std::lock_guard lock(io_lock_); return read_register(setting3399::SR_GET_USBVIDPID, &data); } int hg_scanner_239::get_history_scan_count(int &val) { + std::lock_guard lock(io_lock_); int ret = read_register(setting3399::SR_GET_SCANN_NUM, &val); return ret; } int hg_scanner_239::set_clear_roller_num(void) { + std::lock_guard lock(io_lock_); int val = 0, 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) { + std::lock_guard lock(io_lock_); int val = 0, 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) { + std::lock_guard lock(io_lock_); int ret = SCANNER_ERR_OK; 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) { + std::lock_guard lock(io_lock_); int val = 0; 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) { + std::lock_guard lock(io_lock_); + 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)); @@ -1620,6 +1623,8 @@ int hg_scanner_239::set_sleep_time(int setsleepime) int hg_scanner_239::get_scanner_paperon(SANE_Bool& type) { + std::lock_guard lock(io_lock_); + int val = 0; int ret = read_register(setting3399::SR_GET_PAPERON, &val); //0无纸 1有纸 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) { + std::lock_guard lock(io_lock_); + int ret = 0,val; ret = read_register(setting3399::SR_GET_SLEEP_STAUTUS, &val); //0休眠 1唤醒状态 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() { + std::lock_guard lock(io_lock_); + int val = 0, ret = SCANNER_ERR_OK; if (is_kernelsnap_220830_) @@ -1653,11 +1662,15 @@ int hg_scanner_239::set_notify_sleep() } int hg_scanner_239::get_roller_num(int &num) { + std::lock_guard lock(io_lock_); + int ret = read_register(setting3399::SR_GET_ROLLER_NUM, &num); return ret; } int hg_scanner_239::get_device_log(string &logpath) { + std::lock_guard lock(io_lock_); + string save_path = hg_log::temporary_path() + PATH_SEPARATOR + "device.log"; string device_log_path = "/var/log/syslog"; string str ; @@ -1719,10 +1732,14 @@ int hg_scanner_239::get_device_log(string &logpath) } int hg_scanner_239::set_devreboot(int data) { + std::lock_guard lock(io_lock_); + return write_register(setting3399::SR_REBOOT, data); } int hg_scanner_239::set_devshtudown() { + std::lock_guard lock(io_lock_); + int val = 0, 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) { + std::lock_guard lock(io_lock_); + if (!is_kernelsnap_devsislock) { 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) { + std::lock_guard lock(io_lock_); + if (!is_kernelsnap_devsislock) { 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; } - int val = 0, - ret = read_register(setting3399::SR_GET_LOCK_STATES, &val); + int val = 0, + ret = read_register(setting3399::SR_GET_LOCK_STATES, &val); - 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); + 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; } 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); 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 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(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) { -// std::lock_guard lock(io_lock_); + std::lock_guard lock(io_lock_); + std::ifstream fwname; 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() { - //std::lock_guard lock(io_lock_); + std::lock_guard lock(io_lock_); + int ret = 0, len = 0; ret = write_register(setting3399::SR_CLEAN_PAPER_ROAD, len); return ret; } int hg_scanner_239::get_dev_islock_file(int& islockfile) { + std::lock_guard lock(io_lock_); + if (!is_kernelsnap_devsislock) { 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) { + std::lock_guard lock(io_lock_); + if (!is_kernelsnap_devsislock) { VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "devs lock:%s \n", hg_scanner_err_name(SCANNER_ERR_DEVICE_NOT_SUPPORT)); diff --git a/hgdriver/hgdev/hg_scanner_300.cpp b/hgdriver/hgdev/hg_scanner_300.cpp index 2c873e8..aa9f171 100644 --- a/hgdriver/hgdev/hg_scanner_300.cpp +++ b/hgdriver/hgdev/hg_scanner_300.cpp @@ -91,7 +91,7 @@ hg_scanner_300::hg_scanner_300(const char* dev_name,int pid, usb_io* io) : hg_sc else init_settings((jsontext3 + jsontext4 + jsontext5).c_str()); } - initdevice(); + //initdevice(); wait_read_int.notify(); } hg_scanner_300::~hg_scanner_300() @@ -295,24 +295,12 @@ int hg_scanner_300::discard_all_images(void) if (is_read_int) { - //initdevice(); + initdevice(); } return SCANNER_ERR_OK; } 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; int ret = try_third_app_handle_start(handled), //sane调用是每次都会调用一次start和stop count = -1,