|
|
@@ -10,6 +10,8 @@
|
|
|
#include <thread>
|
|
|
#include <chrono>
|
|
|
|
|
|
+#include <winpr/sysinfo.h>
|
|
|
+
|
|
|
using namespace std;
|
|
|
|
|
|
const int PINPAD_INIT_TRIES = 3;
|
|
|
@@ -804,13 +806,12 @@ ErrorCodeEnum CPinPadFSM::GetEncryptText(SpReqAnsContext<PinPadService_GetInput_
|
|
|
return Error_DevCommFailed;
|
|
|
}
|
|
|
if (!bSMFlag)
|
|
|
- errCode = m_hDevHelper->ActiveWorkingKey(0,0);
|
|
|
+ errCode = m_hDevHelper->ActiveWorkingKey(0, 0);
|
|
|
else
|
|
|
- errCode = m_hDevHelper->ActiveWorkingKey(1,0);
|
|
|
+ errCode = m_hDevHelper->ActiveWorkingKey(1, 0);
|
|
|
if (errCode != Error_Succeed)
|
|
|
{
|
|
|
LOG_PINPAD_ERROR_MSG_MACRO(errCode, ActiveWorkingKey);
|
|
|
- Dbg("ActiveWorkingKey failed.");
|
|
|
return Error_DevCommFailed;
|
|
|
}
|
|
|
if (!bSMFlag)
|
|
|
@@ -825,35 +826,40 @@ ErrorCodeEnum CPinPadFSM::GetEncryptText(SpReqAnsContext<PinPadService_GetInput_
|
|
|
}
|
|
|
if (errCode != Error_Succeed)
|
|
|
{
|
|
|
- //Dbg("set param failed.");
|
|
|
LOG_PINPAD_ERROR_MSG_MACRO(errCode, SetParam);
|
|
|
return Error_DevCommFailed;
|
|
|
}
|
|
|
- Dbg("to start");
|
|
|
+ Dbg("to start pininput...");
|
|
|
errCode = m_hDevHelper->StartPinInput(len);
|
|
|
if (errCode != Error_Succeed)
|
|
|
{
|
|
|
LOG_PINPAD_ERROR_MSG_MACRO(errCode, StartPinInput);
|
|
|
return Error_DevCommFailed;
|
|
|
}
|
|
|
- Dbg("start end");
|
|
|
+ Dbg("start pininput end");
|
|
|
char *buf = new char[len+1];
|
|
|
memset(buf,0,len+1);
|
|
|
int readed = 0;
|
|
|
DWORD elapsed = 0;
|
|
|
- DWORD dwStart = get_tick_count();
|
|
|
- DWORD dwEnd = get_tick_count();
|
|
|
+ DWORD dwStart = GetTickCount();
|
|
|
bool bCancelInput = false;
|
|
|
- Dbg("reqqqq(pin)[%d][%d][%d]",len,timeout,confirm);
|
|
|
- Dbg("bExit(%d)",m_bExit);
|
|
|
- while (elapsed < MAX_PINPAD_INPUT_TIMEOUT) {
|
|
|
- if (m_bExit)
|
|
|
+ Dbg("reqqqq(pin) len: %d, timeout:%d, need to confirm or not: %d",len,timeout,confirm);
|
|
|
+ Dbg("exit flag: %d",m_bExit);
|
|
|
+ while (elapsed < MAX_PINPAD_INPUT_TIMEOUT)
|
|
|
+ {
|
|
|
+ if (m_bExit) {
|
|
|
+ Dbg("exit read routine.");
|
|
|
break;
|
|
|
- if (!confirm && readed >= len)
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!confirm && readed >= len) {
|
|
|
+ Dbg("has been fulfill, exit");
|
|
|
break;
|
|
|
+ }
|
|
|
+
|
|
|
if (m_bWaitingMore)
|
|
|
{
|
|
|
- dwStart = get_tick_count();
|
|
|
+ dwStart = GetTickCount();
|
|
|
elapsed = 0;
|
|
|
m_bWaitingMore = false;
|
|
|
continue;
|
|
|
@@ -861,9 +867,10 @@ ErrorCodeEnum CPinPadFSM::GetEncryptText(SpReqAnsContext<PinPadService_GetInput_
|
|
|
if (m_bFrontCancel)
|
|
|
{
|
|
|
bCancelInput = true;
|
|
|
+ Dbg("detect cancel cmd!");
|
|
|
goto Err;
|
|
|
}
|
|
|
- //char ch[4] = {0};
|
|
|
+
|
|
|
BYTE btCh;
|
|
|
Sleep(100);
|
|
|
errCode = m_hDevHelper->KeyRead(btCh);
|
|
|
@@ -880,15 +887,13 @@ ErrorCodeEnum CPinPadFSM::GetEncryptText(SpReqAnsContext<PinPadService_GetInput_
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- dwEnd = get_tick_count();
|
|
|
- elapsed = dwEnd - dwStart;
|
|
|
+ elapsed = GetTickCount() - dwStart;
|
|
|
continue;
|
|
|
}
|
|
|
} else if (btCh == 0x08) { // back
|
|
|
if (confirm)
|
|
|
{
|
|
|
- dwEnd = get_tick_count();
|
|
|
- elapsed = dwEnd - dwStart;
|
|
|
+ elapsed = GetTickCount() - dwStart;
|
|
|
continue;
|
|
|
}
|
|
|
Dbg("clear input");
|
|
|
@@ -910,8 +915,7 @@ ErrorCodeEnum CPinPadFSM::GetEncryptText(SpReqAnsContext<PinPadService_GetInput_
|
|
|
} else if (btCh == 0x3f){
|
|
|
if (confirm)
|
|
|
{
|
|
|
- dwEnd = get_tick_count();
|
|
|
- elapsed = dwEnd - dwStart;
|
|
|
+ elapsed = GetTickCount() - dwStart;
|
|
|
continue;
|
|
|
}
|
|
|
push_char(buf, &readed, '*');
|
|
|
@@ -920,23 +924,15 @@ ErrorCodeEnum CPinPadFSM::GetEncryptText(SpReqAnsContext<PinPadService_GetInput_
|
|
|
//continue;
|
|
|
}
|
|
|
|
|
|
- } else {
|
|
|
}
|
|
|
- dwEnd = get_tick_count();
|
|
|
- elapsed = dwEnd - dwStart;
|
|
|
+
|
|
|
+ elapsed = GetTickCount() - dwStart;
|
|
|
}
|
|
|
+
|
|
|
buf[readed] = 0;
|
|
|
- //strOutput = buf;
|
|
|
+
|
|
|
Err:
|
|
|
- //oilyang 20131017 commented
|
|
|
- //errCode = m_hDevHelper->StopInput();
|
|
|
- //if (errCode != Error_Succeed)
|
|
|
- // Dbg("StopInput failed(%d).",errCode);
|
|
|
- //else
|
|
|
- //{
|
|
|
- // Dbg("after pin input close pinpad suc.");
|
|
|
- // m_bPlainOpen = false;
|
|
|
- //}
|
|
|
+
|
|
|
if (m_bExit)
|
|
|
{
|
|
|
Dbg("exit");
|
|
|
@@ -1116,9 +1112,9 @@ void CPinPadFSM::OpenInputText(void *pUserdata)
|
|
|
|
|
|
|
|
|
BYTE btCh;
|
|
|
- INT64 i64Start = get_tick_count();
|
|
|
+ INT64 i64Start = GetTickCount();
|
|
|
err = m_hDevHelper->KeyRead(btCh);
|
|
|
- INT64 i64End = get_tick_count();
|
|
|
+ INT64 i64End = GetTickCount();
|
|
|
if ((i64End - i64Start) > 3000)//more than 3 seconds
|
|
|
Dbg("KeyRead cost more than %d seconds.", (i64End - i64Start)/1000);
|
|
|
if (err == Error_Succeed) {
|
|
|
@@ -1160,8 +1156,8 @@ ErrorCodeEnum CPinPadFSM::GetText(SpReqAnsContext<PinPadService_GetInput_Req, Pi
|
|
|
memset(buf,0,len+1);
|
|
|
int readed = 0;
|
|
|
DWORD elapsed = 0;
|
|
|
- DWORD dwStart = get_tick_count();
|
|
|
- DWORD dwEnd = get_tick_count();
|
|
|
+ DWORD dwStart = GetTickCount();
|
|
|
+ DWORD dwEnd = GetTickCount();
|
|
|
bool bCancelInput = false;
|
|
|
//Dbg("reqqqq[%d][%d][%d]",len,timeout,confirm);
|
|
|
//bool bPlainOpen = false;
|
|
|
@@ -1184,7 +1180,7 @@ ErrorCodeEnum CPinPadFSM::GetText(SpReqAnsContext<PinPadService_GetInput_Req, Pi
|
|
|
if (m_bWaitingMore)
|
|
|
{
|
|
|
Dbg("WaitMore");
|
|
|
- dwStart = get_tick_count();
|
|
|
+ dwStart = GetTickCount();
|
|
|
elapsed = 0;
|
|
|
m_bWaitingMore = false;
|
|
|
continue;
|
|
|
@@ -1228,14 +1224,14 @@ ErrorCodeEnum CPinPadFSM::GetText(SpReqAnsContext<PinPadService_GetInput_Req, Pi
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- dwEnd = get_tick_count();
|
|
|
+ dwEnd = GetTickCount();
|
|
|
elapsed = dwEnd - dwStart;
|
|
|
continue;
|
|
|
}
|
|
|
} else if (btCh == 0x08) { // back
|
|
|
if (confirm)
|
|
|
{
|
|
|
- dwEnd = get_tick_count();
|
|
|
+ dwEnd = GetTickCount();
|
|
|
elapsed = dwEnd - dwStart;
|
|
|
continue;
|
|
|
}
|
|
|
@@ -1258,7 +1254,7 @@ ErrorCodeEnum CPinPadFSM::GetText(SpReqAnsContext<PinPadService_GetInput_Req, Pi
|
|
|
} else {
|
|
|
if (confirm)
|
|
|
{
|
|
|
- dwEnd = get_tick_count();
|
|
|
+ dwEnd = GetTickCount();
|
|
|
elapsed = dwEnd - dwStart;
|
|
|
continue;
|
|
|
}
|
|
|
@@ -1285,7 +1281,7 @@ ErrorCodeEnum CPinPadFSM::GetText(SpReqAnsContext<PinPadService_GetInput_Req, Pi
|
|
|
} else {
|
|
|
//Dbg("else[%s]", buf);
|
|
|
}
|
|
|
- dwEnd = get_tick_count();
|
|
|
+ dwEnd = GetTickCount();
|
|
|
elapsed = dwEnd - dwStart;
|
|
|
}
|
|
|
|