.添加3288 linux待纸扫描功能 --23.03.08

.添加安卓设备锁定协议支持 --23.03.13
This commit is contained in:
masayume_ht 2023-03-13 16:53:10 +08:00
parent f82353257c
commit 2e08abac89
10 changed files with 165 additions and 13 deletions

View File

@ -82,4 +82,6 @@
3.调整msvc与mfc链接顺序默认开启多核编译
4.添加色偏算法
5.UI开放色偏校正增加色偏校正协议 --23.01.05
6.除背景色二值化阈值调整为50100-50 --23.02.21
6.除背景色二值化阈值调整为50100-50 --23.02.21
7.添加3288 linux待纸扫描功能 --23.03.08
8.添加安卓设备锁定协议支持 --23.03.13

View File

@ -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: 在此添加控件通知处理程序代码

View File

@ -12,6 +12,7 @@ public:
CIndicatorDlg(std::function<void()> stop = std::function<void()>(), CWnd* pParent = nullptr); // 标准构造函数
virtual ~CIndicatorDlg();
void setindicatortext(int aquire, int updata);
void setindicatortext(CString text);
// 对话框数据
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_INDICATOR };

View File

@ -159,7 +159,7 @@ BOOL CTwainUI::OnInitDialog()
}
#endif
setvisable_dogear(false);
setvisable_autopaper(false);
setvisable_autopaper(true);
setvisable_fixedpaper(false);
}
#else

View File

@ -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<void(int, int)> indicatortext)
void regist_indicatortext_callback(std::function<void(int, int)> indicatortext, std::function<void(CString)> 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<void(int, int)> setindicatortext;
std::function<void(CString)> setindicatortext_str;
int imgreadednum;
int imgtransfered;
int roller_num;

View File

@ -2,6 +2,9 @@
#include "IUsb.h"
#include "UsbScanEx.h"
#include <iostream>
#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<CryptoPP::AES>::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;

View File

@ -9,6 +9,7 @@
#include "aes.h"
#include "hex.h"
#include "modes.h"
#include <cstring>
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;

View File

@ -211,7 +211,7 @@ int GScanO400::aquire_bmpdata(std::vector<unsigned char>& 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<std::mutex> 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;

View File

@ -50,6 +50,7 @@ private:
bool m_bread_fixed_ratio_fromDSP;
std::shared_ptr<IUsb> m_usb;
std::unique_ptr<thread> m_threadUsb;
std::atomic_bool autopaper_stop;
GScanCap gcap;
volatile int image_num;
volatile bool scanfalg;

View File

@ -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<BOOL>();
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<uint8_t, BOOL, (CapType)CapTypeEx::TwEx_IToBeScan>(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<UInt32>()) : "");
if (Msg::Set == msg) {
auto mech = data.currentItem<UInt32>();
if (mech > 60 || mech < 15)
return badValue();
m_scanparam->autopaper_timeout = mech;
return success();
}
return CapSupGetAllResetEx<int, int, (CapType)CapTypeEx::TwEx_IToBeScanTimeOut>(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);