From 2e08abac89e09131da11cf750d9bb6a86576bb9d Mon Sep 17 00:00:00 2001 From: masayume_ht <1936714878@qq.com> Date: Mon, 13 Mar 2023 16:53:10 +0800 Subject: [PATCH] =?UTF-8?q?.=E6=B7=BB=E5=8A=A03288=20linux=E5=BE=85?= =?UTF-8?q?=E7=BA=B8=E6=89=AB=E6=8F=8F=E5=8A=9F=E8=83=BD=20=20--23.03.08?= =?UTF-8?q?=20.=E6=B7=BB=E5=8A=A0=E5=AE=89=E5=8D=93=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E9=94=81=E5=AE=9A=E5=8D=8F=E8=AE=AE=E6=94=AF=E6=8C=81=20--23.0?= =?UTF-8?q?3.13?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog.txt | 4 +- huagao/CIndicatorDlg.cpp | 6 +++ huagao/CIndicatorDlg.h | 1 + huagao/CTwainUI.cpp | 2 +- huagao/Device/GScan.h | 17 ++++++-- huagao/Device/GScan439Android.cpp | 66 +++++++++++++++++++++++++++++++ huagao/Device/GScanO1003399.cpp | 8 +++- huagao/Device/GScanO400.cpp | 38 +++++++++++++++++- huagao/Device/GScanO400.h | 1 + huagao/huagaods.cpp | 35 ++++++++++++++-- 10 files changed, 165 insertions(+), 13 deletions(-) diff --git a/changelog.txt b/changelog.txt index 8661c7ac..c4c227b6 100644 --- a/changelog.txt +++ b/changelog.txt @@ -82,4 +82,6 @@ 3.调整msvc与mfc链接顺序,默认开启多核编译 4.添加色偏算法 5.UI开放色偏校正,增加色偏校正协议 --23.01.05 - 6.除背景色二值化阈值调整为50(100-50) --23.02.21 \ No newline at end of file + 6.除背景色二值化阈值调整为50(100-50) --23.02.21 + 7.添加3288 linux待纸扫描功能 --23.03.08 + 8.添加安卓设备锁定协议支持 --23.03.13 \ No newline at end of file diff --git a/huagao/CIndicatorDlg.cpp b/huagao/CIndicatorDlg.cpp index 6b93b127..92b679c1 100644 --- a/huagao/CIndicatorDlg.cpp +++ b/huagao/CIndicatorDlg.cpp @@ -55,6 +55,12 @@ void CIndicatorDlg::setindicatortext(int aquire, int updata) SetDlgItemText(IDC_STATIC_TIPS,str); } +void CIndicatorDlg::setindicatortext(CString text) +{ + SetDlgItemText(IDC_STATIC_TIPS, text); +} + + void CIndicatorDlg::OnBnClickedBtnstopscan() { // TODO: 在此添加控件通知处理程序代码 diff --git a/huagao/CIndicatorDlg.h b/huagao/CIndicatorDlg.h index 4a61b5f3..b2a4cb78 100644 --- a/huagao/CIndicatorDlg.h +++ b/huagao/CIndicatorDlg.h @@ -12,6 +12,7 @@ public: CIndicatorDlg(std::function stop = std::function(), CWnd* pParent = nullptr); // 标准构造函数 virtual ~CIndicatorDlg(); void setindicatortext(int aquire, int updata); + void setindicatortext(CString text); // 对话框数据 #ifdef AFX_DESIGN_TIME enum { IDD = IDD_INDICATOR }; diff --git a/huagao/CTwainUI.cpp b/huagao/CTwainUI.cpp index 65ae9205..eebd9c56 100644 --- a/huagao/CTwainUI.cpp +++ b/huagao/CTwainUI.cpp @@ -159,7 +159,7 @@ BOOL CTwainUI::OnInitDialog() } #endif setvisable_dogear(false); - setvisable_autopaper(false); + setvisable_autopaper(true); setvisable_fixedpaper(false); } #else diff --git a/huagao/Device/GScan.h b/huagao/Device/GScan.h index 6427e294..c6bee0d0 100644 --- a/huagao/Device/GScan.h +++ b/huagao/Device/GScan.h @@ -223,20 +223,30 @@ public: return error_index; }; + + void UpdateScanInfo(CString str) + { + if (setindicatortext_str) + setindicatortext_str(str); + }; + void UpdateScanInfo(int aquire, int updata) { - imgreadednum = aquire; + imgreadednum = aquire; imgtransfered = updata; if (setindicatortext) setindicatortext(aquire, updata); }; - void regist_indicatortext_callback(std::function indicatortext) + void regist_indicatortext_callback(std::function indicatortext, std::function indicatortext_str) { - if (indicatortext) + if (indicatortext) setindicatortext = indicatortext; + if (indicatortext_str) + setindicatortext_str = indicatortext_str; }; + void set_token(std::string str) { m_token = str; @@ -290,6 +300,7 @@ protected: std::uint32_t MotorFpga; std::uint32_t ScanFpga; std::function setindicatortext; + std::function setindicatortext_str; int imgreadednum; int imgtransfered; int roller_num; diff --git a/huagao/Device/GScan439Android.cpp b/huagao/Device/GScan439Android.cpp index 17623d76..0d850679 100644 --- a/huagao/Device/GScan439Android.cpp +++ b/huagao/Device/GScan439Android.cpp @@ -2,6 +2,9 @@ #include "IUsb.h" #include "UsbScanEx.h" #include +#include "aes.h" +#include "hex.h" +#include "modes.h" using namespace std; static std::mutex mx_ctrl; @@ -250,11 +253,74 @@ void GScan439Android::Scanner_StartScan(UINT16 count) return; } int state = read_reg(m_usb, SR_GET_ANDROID_STATE); + if (state == 5) + { + if (read_reg(m_usb, SR_GET_LOCK_STATES)) { + std::string keys; + //m_token = "1AFE734C123F5FFCAD1113AD99A99011"; + if (m_token.length() != 32) + { + if (m_token.length() > 32) + { + keys = m_token.substr(0, 32); + } + else + { + auto fillstr = [](std::string str)-> std::string { + for (int i = 0; i < 32 - str.length();) + str += "0"; + return str.c_str(); + }; + keys = fillstr(m_token); + } + } + else + keys = m_token; + //keys = m_token; + std::uint8_t key[CryptoPP::AES::DEFAULT_KEYLENGTH] = { 0 }; + for (int i = 0; i < 16; i++) + { + key[i] = _strtoi64(keys.substr(i * 2, 2).c_str(), nullptr, 16); + } + + std::string plain = GetSerialNum(); + plain.resize(14); + std::string cipher; + std::string encoded; + CryptoPP::ECB_Mode::Encryption encode; + + encode.SetKey(key, 16); + //CryptoPP::StringSource(plain, true, new CryptoPP::StreamTransformationFilter(encode, new CryptoPP::StringSink(cipher), CryptoPP::BlockPaddingSchemeDef::W3C_PADDING)); + //encoded.clear(); + //CryptoPP::StringSource(cipher, true, new CryptoPP::HexEncoder(new CryptoPP::StringSink(encoded))); + + CryptoPP::StringSink* str_cip = new CryptoPP::StringSink(cipher); + CryptoPP::StreamTransformationFilter* ecb_filter = new CryptoPP::StreamTransformationFilter(encode, str_cip, CryptoPP::BlockPaddingSchemeDef::W3C_PADDING); + CryptoPP::StringSource* source_plain = new CryptoPP::StringSource(plain, true, ecb_filter); + encoded.clear(); + CryptoPP::StringSink* str_encode = new CryptoPP::StringSink(encoded); + CryptoPP::HexEncoder* hex_encode = new CryptoPP::HexEncoder(str_encode); + CryptoPP::StringSource* source_cipher = new CryptoPP::StringSource(cipher, true, hex_encode); + free(str_cip); + free(ecb_filter); + free(source_plain); + free(str_encode); + free(hex_encode); + free(source_cipher); + write_reg(m_usb, SR_DECODE_TOKEN, encoded.length()); + m_usb->write_bulk(&encoded[0], encoded.length()); + m_token = "null"; + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + } + } + + state = read_reg(m_usb, SR_GET_ANDROID_STATE); if (state != 0) { if (state == 1) Set_ErrorCode(OPEN_COVER); else if (state == 2) Set_ErrorCode(PAPER_JAM); else if (state == 3) Set_ErrorCode(NO_FEED); + else if (state == 5) Set_ErrorCode(DEVICE_LOCKED); else Set_ErrorCode(HARDWARE_ERROR); scanflag = false; m_status = DEV_WRONG; diff --git a/huagao/Device/GScanO1003399.cpp b/huagao/Device/GScanO1003399.cpp index a54ef948..b6233680 100644 --- a/huagao/Device/GScanO1003399.cpp +++ b/huagao/Device/GScanO1003399.cpp @@ -9,6 +9,7 @@ #include "aes.h" #include "hex.h" #include "modes.h" +#include static std::mutex mx_ctrl; @@ -598,9 +599,12 @@ void GScanO1003399::usb_run() StopWatch sw; while (sw.elapsed_s() < m_param.autopaper_timeout) { - std::this_thread::sleep_for(std::chrono::milliseconds(10)); if (m_autopaper_timeout == false) - return; + break; + CString str; + str.Format(L"\t 待纸扫描等待中 %d秒 ", std::max(m_param.autopaper_timeout - (int)ceil(sw.elapsed_s()), 0)); + this->UpdateScanInfo(str); + std::this_thread::sleep_for(std::chrono::milliseconds(30)); } if ((m_autopaper_timeout == false) || scanner_read_reg(m_usb, SR_STATUS)) return; diff --git a/huagao/Device/GScanO400.cpp b/huagao/Device/GScanO400.cpp index e15a5739..2152c057 100644 --- a/huagao/Device/GScanO400.cpp +++ b/huagao/Device/GScanO400.cpp @@ -211,7 +211,7 @@ int GScanO400::aquire_bmpdata(std::vector& bmpdata) if (m_pImages->empty()) { DoEvents(); this_thread::sleep_for(chrono::milliseconds(1)); - if (sw.elapsed_s() > 60.00) + if ((sw.elapsed_s() > 60.00) && (!gcap.hardwarecaps.is_autopaper)) { int roller_num_new = Get_Roller_num(); if (m_threadUsb && m_threadUsb->joinable()) { @@ -463,6 +463,7 @@ void GScanO400::config_params(GScanCap& params) void GScanO400::Scanner_StartScan(UINT16 count) { scanfalg = false; + autopaper_stop.exchange(false); Set_ErrorCode(0); roller_num = Get_Roller_num(); std::lock_guard lck(m_imgLocker); @@ -553,6 +554,8 @@ void GScanO400::Stop_scan() { m_usb->write_bulk(&usbcb, sizeof(usbcb)); scanfalg = true; + if (gcap.hardwarecaps.is_autopaper) + autopaper_stop.exchange(true); FileTools::writelog(log_INFO, "user stop scan"); } } @@ -699,8 +702,13 @@ void GScanO400::usbmain() this_thread::sleep_for(chrono::milliseconds(200)); break; } - if (sw.elapsed_ms() > 60000) + if ((sw.elapsed_s() > 60.00) && (!gcap.hardwarecaps.is_autopaper)) { + if (!m_pImages->empty()) + { + sw.reset(); + continue; + } m_pImages->setscanflags(false); Set_ErrorCode(AQUIRE_IMAGE_TIMEOUT); devState = DevState::DEV_WRONG; @@ -754,6 +762,32 @@ void GScanO400::usbmain() } case STOP_SCAN: { + if (gcap.hardwarecaps.is_autopaper && (!autopaper_stop) && (!haveError)) + { + StopWatch sw_p; + while (sw_p.elapsed_s() < gcap.autopaper_timeout) + { + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + CString str; + str.Format(L"\t ֽɨȴ %d", std::max(gcap.autopaper_timeout - (int)ceil(sw_p.elapsed_s()), 0)); + UpdateScanInfo(str); + if (Get_Scanner_PaperOn()) + { + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + USBCB usbcb = { START_COMMAND,(UINT32)gcap.scannum ,0 }; + m_usb->write_bulk(&usbcb, sizeof(usbcb)); + sw_p.reset(); + sw.reset(); + break; + } + if (autopaper_stop) + break; + } + if (sw_p.elapsed_s() < gcap.autopaper_timeout && (!autopaper_stop)) + break; + else + autopaper_stop = true; + } m_pImages->setscanflags(false); std::this_thread::sleep_for(std::chrono::milliseconds(500)); devState = haveError ? DevState::DEV_WRONG : DevState::DEV_STOP; diff --git a/huagao/Device/GScanO400.h b/huagao/Device/GScanO400.h index 004a80ab..12554cb6 100644 --- a/huagao/Device/GScanO400.h +++ b/huagao/Device/GScanO400.h @@ -50,6 +50,7 @@ private: bool m_bread_fixed_ratio_fromDSP; std::shared_ptr m_usb; std::unique_ptr m_threadUsb; + std::atomic_bool autopaper_stop; GScanCap gcap; volatile int image_num; volatile bool scanfalg; diff --git a/huagao/huagaods.cpp b/huagao/huagaods.cpp index 6471cbdf..163f84e4 100644 --- a/huagao/huagaods.cpp +++ b/huagao/huagaods.cpp @@ -75,6 +75,7 @@ enum class CapTypeEx : unsigned short { TwEx_SETTOKEN = 0x8116, TwEx_IHsvFilter = 0x8117, TwEx_ColorCast = 0x8118, + TwEx_IToBeScanTimeOut = 0x8119, }; enum class PaperSizeEx : unsigned short { @@ -2267,6 +2268,12 @@ Result HuagaoDs::identityOpenDs(const Identity&) { // { LowPowerMode::Min_None,LowPowerMode::Min_5,LowPowerMode::Min_10,LowPowerMode::Min_20, LowPowerMode::Min_30, LowPowerMode::Min_60, LowPowerMode::Min_120, LowPowerMode::Min_240 }, // m_scanparam->hardwarecaps.lowpowermode, LowPowerMode::Min_30, (BYTE)m_scanparam->hardwarecaps.lowpowermode, 4); }; + +#endif // LANXUM + + +#if defined G200 || defined G300 +#ifndef ANDROIDSERIAL //ֽɨ m_query[(CapType)(CapTypeEx::TwEx_IToBeScan)] = msgSupportGetAllSetReset; m_caps[(CapType)(CapTypeEx::TwEx_IToBeScan)] = [this](Msg msg, Capability& data)->Result { @@ -2274,6 +2281,7 @@ Result HuagaoDs::identityOpenDs(const Identity&) { if (Msg::Set == msg) { auto mech = data.currentItem(); m_scanparam->hardwarecaps.is_autopaper = mech; + m_scanparam->autopaper_timeout = 15; if (mech) m_scanparam->scannum = -1; return success(); @@ -2281,7 +2289,22 @@ Result HuagaoDs::identityOpenDs(const Identity&) { return CapSupGetAllResetEx(msg, data, m_scanparam->hardwarecaps.is_autopaper, FALSE); }; -#endif // LANXUM + + m_query[(CapType)(CapTypeEx::TwEx_IToBeScanTimeOut)] = msgSupportGetAllSetReset; + m_caps[(CapType)(CapTypeEx::TwEx_IToBeScanTimeOut)] = [this](Msg msg, Capability& data)->Result { + CapabilityPrintf(msg, enum2str(CapTypeEx::TwEx_IToBeScanTimeOut), msg == Msg::Set ? to_string((float)data.currentItem()) : ""); + if (Msg::Set == msg) { + auto mech = data.currentItem(); + if (mech > 60 || mech < 15) + return badValue(); + m_scanparam->autopaper_timeout = mech; + return success(); + } + return CapSupGetAllResetEx(msg, data, m_scanparam->autopaper_timeout, 15); + }; +#endif +#endif + m_query[(CapType)(CapTypeEx::TwEx_CropModel)] = msgSupportGetAllSetReset; m_caps[(CapType)(CapTypeEx::TwEx_CropModel)] = [this](Msg msg, Capability& data)->Result { @@ -3082,15 +3105,19 @@ Twpp::Result HuagaoDs::startScan() if (scanner.get()) scanner->Stop_scan(); //guiIndicator.reset();//ȡɨ رսָʾ - if (guiTwain.get()) { - ((CTwainUI*)(guiTwain.get()))->EnableID_OKorID_Cancel(true); - } + //if (guiTwain.get()) { + // ((CTwainUI*)(guiTwain.get()))->EnableID_OKorID_Cancel(true); + //} onDeviceEvent(USER_STOP); }; guiIndicator = new CIndicatorDlg(stopFunc); scanner->regist_indicatortext_callback([this](int aquire, int updata) { if (guiIndicator->GetSafeHwnd()) guiIndicator->setindicatortext(aquire, updata); + }, + [this](CString str) + { if (guiIndicator->GetSafeHwnd()) + guiIndicator->setindicatortext(str); }); guiIndicator->Create(IDD_INDICATOR, guiTwain.get() ? guiTwain.get() : guiBridge.get());//guiTwain ? guiTwain.get() : guiBridge.get() guiIndicator->ShowWindow(SW_SHOWNORMAL);