|
|
@@ -60,14 +60,14 @@ unsigned int CFingerPrintFSM::s0_on_event(FSMEvent* e)
|
|
|
break;
|
|
|
}
|
|
|
case USER_EVT_MATCH:
|
|
|
- {
|
|
|
- e->SetHandled();
|
|
|
- MatchEvent* pMe = dynamic_cast<MatchEvent*>(e);
|
|
|
- MatchTask* pMt = new MatchTask(this);
|
|
|
- pMt->ctx = pMe->ctx;
|
|
|
- GetEntityBase()->GetFunction()->PostThreadPoolTask(pMt);
|
|
|
- break;
|
|
|
- }
|
|
|
+ {
|
|
|
+ e->SetHandled();
|
|
|
+ MatchEvent* pMe = dynamic_cast<MatchEvent*>(e);
|
|
|
+ MatchTask* pMt = new MatchTask(this);
|
|
|
+ pMt->ctx = pMe->ctx;
|
|
|
+ GetEntityBase()->GetFunction()->PostThreadPoolTask(pMt);
|
|
|
+ break;
|
|
|
+ }
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
@@ -153,7 +153,7 @@ unsigned CFingerPrintFSM::s3_on_event(FSMEvent* e)
|
|
|
int ret = 0;
|
|
|
switch(e->iEvt)
|
|
|
{
|
|
|
- case USER_EVT_MATCH_FINISHED:
|
|
|
+ case USER_EVT_MATCH_FINISHED:
|
|
|
{
|
|
|
e->SetHandled();
|
|
|
MatchFinishedEvent* mfe = dynamic_cast<MatchFinishedEvent*>(e);
|
|
|
@@ -161,21 +161,28 @@ unsigned CFingerPrintFSM::s3_on_event(FSMEvent* e)
|
|
|
mfe->ctx->Answer(Error_Succeed);
|
|
|
else
|
|
|
mfe->ctx->Answer((ErrorCodeEnum)mfe->param1);
|
|
|
+ break;
|
|
|
}
|
|
|
- break;
|
|
|
- case USER_EVT_CANCEL_MATCH:
|
|
|
- e->SetHandled();
|
|
|
- Dbg("Set cancel match flag");
|
|
|
- m_bCancelMatch = true;
|
|
|
- case USER_EVT_EXIT:
|
|
|
- e->SetHandled();
|
|
|
- m_bExit = true;
|
|
|
- break;
|
|
|
- case USER_EVT_QUIT:
|
|
|
- e->SetHandled();
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
+ case USER_EVT_CANCEL_MATCH:
|
|
|
+ {
|
|
|
+ e->SetHandled();
|
|
|
+ Dbg("Set cancel match flag");
|
|
|
+ m_bCancelMatch = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case USER_EVT_EXIT:
|
|
|
+ {
|
|
|
+ e->SetHandled();
|
|
|
+ m_bExit = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case USER_EVT_QUIT:
|
|
|
+ {
|
|
|
+ e->SetHandled();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ break;
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
@@ -254,84 +261,52 @@ void CFingerPrintFSM::SelfTest(EntityTestEnum eTestType
|
|
|
pTransactionContext->SendAnswer(m_testResult);
|
|
|
}
|
|
|
|
|
|
-ErrorCodeEnum CFingerPrintFSM::InitParamBeforeScan(ScanParam *initParam, int scanTime)
|
|
|
+int CFingerPrintFSM::GetImageAndFeature(SpReqAnsContext<FingerPrintService_GetImageAndFeature_Req, FingerPrintService_GetImageAndFeature_Ans>::Pointer ctx)
|
|
|
{
|
|
|
- ErrorCodeEnum errCode = Error_Succeed;
|
|
|
+ LOG_FUNCTION();
|
|
|
|
|
|
- if (!m_devInit)
|
|
|
- return Error_NotInit; //maybe no vendor adapter
|
|
|
+ ScanParam* pScanParam = new ScanParam();
|
|
|
+ ErrorCodeEnum errCode = InitParamBeforeScan(pScanParam, ctx->Req.times);
|
|
|
|
|
|
- if (m_bCancelRegister) //no cancel button anymore while register
|
|
|
- {
|
|
|
- m_bCancelRegister = false;
|
|
|
- return Error_Cancel;
|
|
|
+ if (errCode != Error_Succeed)
|
|
|
+ ctx->Answer(errCode);
|
|
|
+ else {
|
|
|
+ ScanProcess(pScanParam, ctx);
|
|
|
+ if (pScanParam != NULL && ctx != NULL)
|
|
|
+ ProcessAfterScan(pScanParam, ctx);
|
|
|
+ else
|
|
|
+ ctx->Answer(Error_Param);
|
|
|
}
|
|
|
|
|
|
- initParam->m_TimeStart = clock();
|
|
|
- initParam->m_TimeEnd = clock();
|
|
|
- initParam->m_TimeLeft = 0;
|
|
|
-
|
|
|
- initParam->m_Feature = new BYTE[MAX_FEATURE_LEN];
|
|
|
- initParam->m_Template = new BYTE[MAX_FEATURE_LEN];
|
|
|
- initParam->m_FeatureLen = MAX_FEATURE_LEN;
|
|
|
- initParam->m_FullFilePath = "";
|
|
|
-
|
|
|
- initParam->m_ScanSuc = false;
|
|
|
- initParam->m_GetTemplateSuc = true;
|
|
|
- initParam->m_NotFindImage = false;
|
|
|
- initParam->m_FeatureIsNull = false;
|
|
|
- initParam->m_Quit = false;
|
|
|
-
|
|
|
- m_bCancelRegister = false;
|
|
|
-
|
|
|
- memset(initParam->m_Feature, 0, sizeof(initParam->m_Feature));
|
|
|
- memset(initParam->m_Template, 0, sizeof(initParam->m_Template));
|
|
|
- LogEvent(Severity_Middle, LOG_EVT_FINGERPRINT_GREEN_ON, "FingerPrint warning on");
|
|
|
+ return 0;
|
|
|
+}
|
|
|
|
|
|
- if (scanTime == 1)
|
|
|
- {
|
|
|
- Dbg("Before scan fingerprint, clear bmp file");
|
|
|
- DeleteBmp(BmpImage);
|
|
|
- Dbg("Before scan fingerprint, finish doing clear job.");
|
|
|
- m_BmpFileFullPath1 = "";
|
|
|
- m_BmpFileFullPath2 = "";
|
|
|
- m_BmpFileFullPath3 = "";
|
|
|
- }
|
|
|
+ErrorCodeEnum CFingerPrintFSM::InitParamBeforeScan(ScanParam *initParam, int scanTime)
|
|
|
+{
|
|
|
+ ErrorCodeEnum errCode = Error_Succeed;
|
|
|
|
|
|
- errCode = m_pEntity->GetFunction()->GetPath("Dep", initParam->m_FullFilePath);
|
|
|
+ errCode = InitCommParam(initParam, RegisterType, scanTime);
|
|
|
if (errCode != Error_Succeed)
|
|
|
- {
|
|
|
- delete[] initParam->m_Feature;
|
|
|
- initParam->m_Feature = NULL;
|
|
|
- delete[] initParam->m_Template;
|
|
|
- initParam->m_Template = NULL;
|
|
|
- Dbg("Get dep path failed");
|
|
|
-
|
|
|
- LogError(Severity_High, Error_DevLoadFileFailed
|
|
|
- , LOG_ERR_FINGERPRINT_GET_DEP_PATH_FAILED_REGISTER
|
|
|
- , "Get dep path failed while register.");
|
|
|
-
|
|
|
- return Error_Param;
|
|
|
- }
|
|
|
+ return errCode;
|
|
|
|
|
|
switch (scanTime)
|
|
|
{
|
|
|
case 1:
|
|
|
initParam->m_BmpFileName = "finger1.bmp";
|
|
|
m_BmpFileFullPath1 = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s"
|
|
|
- , (const char*)initParam->m_FullFilePath
|
|
|
+ , (const char*)initParam->m_DepPath
|
|
|
, (const char*)initParam->m_BmpFileName);
|
|
|
break;
|
|
|
case 2:
|
|
|
initParam->m_BmpFileName = "finger2.bmp";
|
|
|
m_BmpFileFullPath2 = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s"
|
|
|
- , (const char*)initParam->m_FullFilePath
|
|
|
+ , (const char*)initParam->m_DepPath
|
|
|
, (const char*)initParam->m_BmpFileName);
|
|
|
break;
|
|
|
case 3:
|
|
|
initParam->m_BmpFileName = "finger3.bmp";
|
|
|
m_BmpFileFullPath3 = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s"
|
|
|
- , (const char*)initParam->m_FullFilePath
|
|
|
+ , (const char*)initParam->m_DepPath
|
|
|
, (const char*)initParam->m_BmpFileName);
|
|
|
break;
|
|
|
default:
|
|
|
@@ -339,7 +314,7 @@ ErrorCodeEnum CFingerPrintFSM::InitParamBeforeScan(ScanParam *initParam, int sca
|
|
|
break;
|
|
|
}
|
|
|
initParam->m_FullFilePath = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s"
|
|
|
- , (const char*)initParam->m_FullFilePath
|
|
|
+ , (const char*)initParam->m_DepPath
|
|
|
, (const char*)initParam->m_BmpFileName);
|
|
|
|
|
|
Dbg("get imageName success: %s", initParam->m_FullFilePath);
|
|
|
@@ -350,8 +325,10 @@ ErrorCodeEnum CFingerPrintFSM::InitParamBeforeScan(ScanParam *initParam, int sca
|
|
|
void CFingerPrintFSM::ScanProcess(ScanParam* pScanParam, SpReqAnsContext<FingerPrintService_GetImageAndFeature_Req, FingerPrintService_GetImageAndFeature_Ans>::Pointer &ctx)
|
|
|
{
|
|
|
LOG_FUNCTION();
|
|
|
+ LogEvent(Severity_Middle, LOG_EVT_FINGERPRINT_GREEN_ON, "FingerPrint warning on");
|
|
|
|
|
|
- while (pScanParam->m_TimeLeft < FINGERPRINT_SCAN_TIMEOUT && !m_bCancelRegister && !pScanParam->m_ScanSuc)
|
|
|
+ while (pScanParam->m_TimeLeft < FINGERPRINT_SCAN_TIMEOUT
|
|
|
+ && !m_bCancelRegister && !pScanParam->m_ScanSuc)
|
|
|
{
|
|
|
if (m_bExit)
|
|
|
{
|
|
|
@@ -378,6 +355,7 @@ void CFingerPrintFSM::ScanProcess(ScanParam* pScanParam, SpReqAnsContext<FingerP
|
|
|
{
|
|
|
Dbg("fingerprint feature length is %d", pScanParam->m_FeatureLen);
|
|
|
ctx->Ans.imageName = pScanParam->m_BmpFileName;
|
|
|
+
|
|
|
if (ctx->Req.times == 3) {
|
|
|
Dbg("m_strPath1 = %s", m_BmpFileFullPath1.GetData());
|
|
|
Dbg("m_strPath2 = %s", m_BmpFileFullPath2.GetData());
|
|
|
@@ -400,8 +378,7 @@ void CFingerPrintFSM::ScanProcess(ScanParam* pScanParam, SpReqAnsContext<FingerP
|
|
|
pScanParam->m_GetTemplateSuc = false;
|
|
|
break;
|
|
|
}
|
|
|
- }
|
|
|
- else {
|
|
|
+ }else {
|
|
|
pScanParam->m_GetTemplateSuc = false;
|
|
|
DevErrorInfo devErrorInfo;
|
|
|
m_pFingerPrint->GetLastErr(devErrorInfo);
|
|
|
@@ -447,8 +424,7 @@ void CFingerPrintFSM::ProcessAfterScan(ScanParam* pScanParam, SpReqAnsContext<Fi
|
|
|
else if (m_bCancelRegister)
|
|
|
{
|
|
|
ctx->Answer(Error_Cancel);
|
|
|
- }
|
|
|
- else {
|
|
|
+ }else {
|
|
|
if (pScanParam->m_NotFindImage)
|
|
|
{
|
|
|
LogError(Severity_High, Error_Hardware
|
|
|
@@ -486,214 +462,110 @@ void CFingerPrintFSM::ProcessAfterScan(ScanParam* pScanParam, SpReqAnsContext<Fi
|
|
|
pScanParam = NULL;
|
|
|
}
|
|
|
|
|
|
-int CFingerPrintFSM::GetImageAndFeature(SpReqAnsContext<FingerPrintService_GetImageAndFeature_Req, FingerPrintService_GetImageAndFeature_Ans>::Pointer ctx)
|
|
|
+ErrorCodeEnum CFingerPrintFSM::Match(SpReqAnsContext<FingerPrintService_Match_Req, FingerPrintService_Match_Ans>::Pointer ctx)
|
|
|
{
|
|
|
LOG_FUNCTION();
|
|
|
-
|
|
|
- ScanParam* pScanParam = new ScanParam();
|
|
|
- ErrorCodeEnum errCode = InitParamBeforeScan(pScanParam, ctx->Req.times);
|
|
|
|
|
|
+ ScanParam* initParam = new ScanParam();
|
|
|
+ ErrorCodeEnum errCode = InitParamBeforeMatch(initParam, ctx->Req.templateNum);
|
|
|
if (errCode != Error_Succeed)
|
|
|
- ctx->Answer(errCode);
|
|
|
- else {
|
|
|
- ScanProcess(pScanParam, ctx);
|
|
|
- if (pScanParam != NULL && ctx != NULL)
|
|
|
- ProcessAfterScan(pScanParam, ctx);
|
|
|
- else
|
|
|
- ctx->Answer(Error_Param);
|
|
|
- }
|
|
|
+ return errCode;
|
|
|
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-ErrorCodeEnum CFingerPrintFSM::CheckCardSwiperStatus()
|
|
|
-{
|
|
|
- ErrorCodeEnum errCode = Error_Unexpect;
|
|
|
- CardSwiperService_ClientBase *pCardSwiperClient = new CardSwiperService_ClientBase(this->GetEntityBase());
|
|
|
- errCode = pCardSwiperClient->Connect();
|
|
|
- if(errCode != Error_Succeed)
|
|
|
- {
|
|
|
- Dbg("connect CardSwiper fail 0x%x(%d).", errCode, errCode);
|
|
|
- }else{
|
|
|
- CardSwiperService_GetDevInfo_Req req = {};
|
|
|
- CardSwiperService_GetDevInfo_Ans ans = {};
|
|
|
- errCode = pCardSwiperClient->GetDevInfo(req, ans, 3000);
|
|
|
+ ScanBeforeMatch(initParam);
|
|
|
|
|
|
- if(errCode != Error_Succeed){
|
|
|
- Dbg("CardSwiper::GetDevInfo() fail: 0x%x", errCode);
|
|
|
- }else{
|
|
|
- Dbg("CardSwiper::GetDevInfo() return state: %d", ans.state);
|
|
|
- if (ans.state == DEVICE_STATUS_NOT_READY)
|
|
|
- {
|
|
|
- std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
|
|
- CardSwiperService_GetDevInfo_Req req2 = {};
|
|
|
- CardSwiperService_GetDevInfo_Ans ans2 = {};
|
|
|
- errCode = pCardSwiperClient->GetDevInfo(req2, ans2, 3000);
|
|
|
- if(errCode != Error_Succeed){
|
|
|
- Dbg("CardSwiper::GetDevInfo() again fail: 0x%x", errCode);
|
|
|
- }else{
|
|
|
- Dbg("CardSwiper::GetDevInfo() again return state: %d", ans2.state);
|
|
|
- if(ans2.state != DEVICE_STATUS_NORMAL){
|
|
|
- errCode = Error_DevNotAvailable;
|
|
|
- }
|
|
|
- }
|
|
|
- }else if(ans.state != DEVICE_STATUS_NORMAL){
|
|
|
- errCode = Error_DevNotAvailable;
|
|
|
- }
|
|
|
- }
|
|
|
- pCardSwiperClient->GetFunction()->CloseSession();
|
|
|
- }
|
|
|
- if(pCardSwiperClient != NULL){
|
|
|
- pCardSwiperClient->SafeDelete();
|
|
|
- pCardSwiperClient = NULL;
|
|
|
- }
|
|
|
-
|
|
|
+ errCode = MatchProcess(initParam, ctx);
|
|
|
return errCode;
|
|
|
}
|
|
|
|
|
|
-void CFingerPrintFSM::DeleteBmp(int type)
|
|
|
+ErrorCodeEnum CFingerPrintFSM::InitParamBeforeMatch(ScanParam* initParam, int templateNum)
|
|
|
{
|
|
|
- if ((type&BmpImage) == BmpImage)
|
|
|
- {
|
|
|
- Dbg("to delete fingerprint images...");
|
|
|
- DeleteFileIfExisted("finger.bmp");
|
|
|
- DeleteFileIfExisted("finger1.bmp");
|
|
|
- DeleteFileIfExisted("finger2.bmp");
|
|
|
- DeleteFileIfExisted("finger3.bmp");
|
|
|
- }
|
|
|
- if ((type&TestImage) == TestImage)
|
|
|
- {
|
|
|
- DeleteFileIfExisted("testFinger.bmp");
|
|
|
- }
|
|
|
-}
|
|
|
+ ErrorCodeEnum errCode = Error_Succeed;
|
|
|
|
|
|
-ErrorCodeEnum CFingerPrintFSM::DeleteFileIfExisted(LPCTSTR fileName)
|
|
|
-{
|
|
|
- if (strlen(fileName) == 0 || strchr(fileName, (int)'*') != NULL)
|
|
|
- {
|
|
|
- Dbg("Invalid or empty filename(%s)", fileName);
|
|
|
- return Error_Param;
|
|
|
- }
|
|
|
- CSimpleStringA strPath, strObjPath;
|
|
|
- ErrorCodeEnum errCode = m_pEntity->GetFunction()->GetPath("Dep", strPath);
|
|
|
- strObjPath = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", (const char*)strPath, (const char*)fileName);
|
|
|
- std::ifstream beDeletedFile((const char*)strObjPath, std::ifstream::binary);
|
|
|
- if (beDeletedFile)
|
|
|
- {
|
|
|
- if (remove((const char*)strObjPath) == 0)
|
|
|
- {
|
|
|
- Dbg("DeleteFile(%s) success.", (const char*)strObjPath);
|
|
|
- return Error_Succeed;
|
|
|
- } else {
|
|
|
- Dbg("DeleteFile(%s) failed LastError(%s).", (const char*)strObjPath, GetLastError());
|
|
|
- return Error_Unexpect;
|
|
|
- }
|
|
|
- }
|
|
|
- if (GetLastError() == ERROR_FILE_NOT_FOUND)
|
|
|
- {
|
|
|
- return Error_Succeed;
|
|
|
- }
|
|
|
- Dbg("DeleteFle(%s) Unexpect GetLastError(%s).", (LPCTSTR)strObjPath, GetLastError());
|
|
|
- return Error_Unexpect;
|
|
|
-}
|
|
|
+ errCode = InitCommParam(initParam, MatchType, 0, templateNum);
|
|
|
+ if (errCode != Error_Succeed)
|
|
|
+ return errCode;
|
|
|
|
|
|
-ErrorCodeEnum CFingerPrintFSM::Match(SpReqAnsContext<FingerPrintService_Match_Req, FingerPrintService_Match_Ans>::Pointer ctx)
|
|
|
-{
|
|
|
- LOG_FUNCTION();
|
|
|
- if (ctx->Req.templateNum <= 0)
|
|
|
- {
|
|
|
- return Error_Param;
|
|
|
- }
|
|
|
- if(!m_devInit) {
|
|
|
- return Error_NotInit;
|
|
|
- }
|
|
|
+ initParam->m_BmpFileName = "finger.bmp";
|
|
|
+ initParam->m_FullFilePath = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s"
|
|
|
+ , (const char*)initParam->m_DepPath
|
|
|
+ , (const char*)initParam->m_BmpFileName);
|
|
|
+ Dbg("get imageName success: %s", initParam->m_FullFilePath);
|
|
|
|
|
|
- Dbg("Before scan fingerprint, clear bmp file");
|
|
|
- DeleteBmp(BmpImage);
|
|
|
- Dbg("Before scan fingerprint, finish doing clear job.");
|
|
|
+ return Error_Succeed;
|
|
|
+}
|
|
|
|
|
|
- long elapsed = 0;
|
|
|
- clock_t timeStart = clock();
|
|
|
- clock_t timeEnd = clock();
|
|
|
- ErrorCodeEnum eErr;
|
|
|
- DevErrorInfo devErrInfo;
|
|
|
- LPBYTE lpbFeature = new BYTE[MAX_FEATURE_LEN];
|
|
|
- memset(lpbFeature, 0, sizeof(lpbFeature));
|
|
|
- int lpbLength = MAX_FEATURE_LEN;
|
|
|
+void CFingerPrintFSM::ScanBeforeMatch(ScanParam* initParam)
|
|
|
+{
|
|
|
+ ErrorCodeEnum errCode = Error_Succeed;
|
|
|
LogEvent(Severity_Middle, LOG_EVT_FINGERPRINT_GREEN_ON, "FingerPrint warning on");
|
|
|
|
|
|
- CSimpleStringA strPath;
|
|
|
- eErr = m_pEntity->GetFunction()->GetPath("Dep", strPath);
|
|
|
- if (eErr != Error_Succeed)
|
|
|
- {
|
|
|
- LogError(Severity_High, Error_DevLoadFileFailed, LOG_ERR_FINGERPRINT_GET_DEP_PATH_FAILED_MATCH, "get dep path failed while match.");
|
|
|
- Dbg("Get dep path failed");
|
|
|
- delete[] lpbFeature;
|
|
|
- lpbFeature = NULL;
|
|
|
- return Error_Param;
|
|
|
- }
|
|
|
- CSimpleStringA fileName = "finger.bmp";
|
|
|
- strPath = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", (const char*)strPath, (const char*)fileName);
|
|
|
- Dbg("get imageName success: %s", strPath);
|
|
|
- bool bScanSuccess = false;
|
|
|
- bool bNotFindImage = false;
|
|
|
- bool bFeatureIsNull = false;
|
|
|
- bool bExit = false;
|
|
|
- m_bCancelMatch = false;
|
|
|
- while(elapsed < FINGERPRINT_MATCH_TIMEOUT && !m_bCancelMatch && !bScanSuccess)
|
|
|
+ while (initParam->m_TimeLeft < FINGERPRINT_MATCH_TIMEOUT
|
|
|
+ && !m_bCancelMatch && !initParam->m_ScanSuc)
|
|
|
{
|
|
|
if (m_bExit)
|
|
|
{
|
|
|
Dbg("Exit");
|
|
|
- bExit = true;
|
|
|
+ initParam->m_Quit = true;
|
|
|
break;
|
|
|
}
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(FINGERPRINT_SCAN_INTERNAL));
|
|
|
//Sleep(FINGERPRINT_SCAN_INTERNAL);
|
|
|
- eErr = m_pFingerPrint->Image2Feature(fileName, lpbFeature, lpbLength);
|
|
|
- if (eErr == Error_Succeed)
|
|
|
+ initParam->m_FeatureLen = MAX_FEATURE_LEN;
|
|
|
+ errCode = m_pFingerPrint->Image2Feature(initParam->m_BmpFileName
|
|
|
+ , initParam->m_Feature
|
|
|
+ , initParam->m_FeatureLen);
|
|
|
+ if (errCode == Error_Succeed)
|
|
|
{
|
|
|
//TODO: union test
|
|
|
Dbg("Invoke routine 'Image2Feature' success.");
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
|
|
//Sleep(200);//save image may be delayed some time, not must happen
|
|
|
|
|
|
- std::ifstream bmpImage((const char*)strPath, std::fstream::binary);
|
|
|
- if (bmpImage && lpbFeature != NULL && lpbLength > 0)
|
|
|
+ std::ifstream bmpImage((const char*)initParam->m_FullFilePath, std::fstream::binary);
|
|
|
+ if (bmpImage && initParam->m_Feature != NULL && initParam->m_FeatureLen > 0)
|
|
|
{
|
|
|
- Dbg("fingerprint feature length is %d", lpbLength);
|
|
|
- bScanSuccess = true;
|
|
|
+ Dbg("fingerprint feature length is %d", initParam->m_FeatureLen);
|
|
|
+ initParam->m_ScanSuc = true;
|
|
|
break;
|
|
|
- } else if (!bmpImage){
|
|
|
+ }
|
|
|
+ else if (!bmpImage)
|
|
|
+ {
|
|
|
Dbg("Cannot find the fingerprint image finger.bmp");
|
|
|
- bNotFindImage = true;
|
|
|
+ initParam->m_NotFindImage = true;
|
|
|
break;
|
|
|
- } else {
|
|
|
+ }else {
|
|
|
Dbg("Fingerprint feature is NULL.");
|
|
|
- bFeatureIsNull = true;
|
|
|
+ initParam->m_FeatureIsNull = true;
|
|
|
break;
|
|
|
}
|
|
|
- } else {
|
|
|
- lpbLength = MAX_FEATURE_LEN;
|
|
|
+ }else {
|
|
|
+ DevErrorInfo devErrInfo;
|
|
|
m_pFingerPrint->GetLastErr(devErrInfo);
|
|
|
- Dbg("Invoke routine 'Image2Feature' failed which returned 0x%x(%s)", eErr, devErrInfo.szErrMsg);
|
|
|
+ Dbg("Invoke routine 'Image2Feature' failed which returned %s(%s)"
|
|
|
+ , SpStrError(errCode), devErrInfo.szErrMsg);
|
|
|
}
|
|
|
- timeEnd = clock();
|
|
|
- elapsed = timeEnd - timeStart;
|
|
|
+ initParam->m_TimeEnd = clock();
|
|
|
+ initParam->m_TimeLeft = initParam->m_TimeEnd - initParam->m_TimeStart;
|
|
|
}
|
|
|
LogEvent(Severity_Middle, LOG_EVT_FINGERPRINT_GREEN_OFF, "FingerPrint warning off");
|
|
|
m_bExit = false;
|
|
|
|
|
|
Dbg("after match, clear bmp file");
|
|
|
DeleteBmp(BmpImage);
|
|
|
+}
|
|
|
+
|
|
|
+ErrorCodeEnum CFingerPrintFSM::MatchProcess(ScanParam* initParam, SpReqAnsContext<FingerPrintService_Match_Req, FingerPrintService_Match_Ans>::Pointer& ctx)
|
|
|
+{
|
|
|
+ ErrorCodeEnum errCode = Error_Succeed;
|
|
|
|
|
|
- ErrorCodeEnum retErr;
|
|
|
- if (bScanSuccess)
|
|
|
+ if (initParam->m_ScanSuc)
|
|
|
{
|
|
|
+ Dbg("templateNum=%d", ctx->Req.templateNum);
|
|
|
+
|
|
|
int templateNum = ctx->Req.templateNum;
|
|
|
- Dbg("templateNum=%d", templateNum);
|
|
|
- LPBYTE *lpbTemplates = new LPBYTE[templateNum];
|
|
|
- int *lpbTemplateLen = new int[templateNum];
|
|
|
+ LPBYTE* lpbTemplates = new LPBYTE[templateNum];
|
|
|
+ int* lpbTemplateLen = new int[templateNum];
|
|
|
+
|
|
|
for (int i = 0; i < templateNum; ++i)
|
|
|
{
|
|
|
lpbTemplates[i] = new BYTE[MAX_FEATURE_LEN];
|
|
|
@@ -701,30 +573,30 @@ ErrorCodeEnum CFingerPrintFSM::Match(SpReqAnsContext<FingerPrintService_Match_Re
|
|
|
strcpy((char*)lpbTemplates[i], ctx->Req.templates[i]);
|
|
|
lpbTemplateLen[i] = ctx->Req.templateLen[i];
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
clock_t startMatch = clock();
|
|
|
- eErr = m_pFingerPrint->Match(lpbTemplates, lpbTemplateLen, templateNum, lpbFeature, lpbLength);
|
|
|
+ errCode = m_pFingerPrint->Match(lpbTemplates, lpbTemplateLen, templateNum,
|
|
|
+ initParam->m_Feature, initParam->m_FeatureLen);
|
|
|
clock_t endMatch = clock();
|
|
|
int duration = (endMatch - startMatch) * 1000 / CLOCKS_PER_SEC;
|
|
|
LogWarn(Severity_High, Error_Debug, LOG_ERR_FINGERPRINT_MATCH_TIME,
|
|
|
GenerateAlarmJson("FingerPrint", duration).GetData());
|
|
|
|
|
|
- if (eErr == Error_Succeed) //always true
|
|
|
+ if (errCode == Error_Succeed) //always true
|
|
|
{
|
|
|
Dbg("Invoke routine 'Match' success");
|
|
|
ctx->Ans.result.Init(templateNum);
|
|
|
for (int i = 0; i < templateNum; ++i)
|
|
|
- {
|
|
|
ctx->Ans.result[i] = lpbTemplateLen[i];
|
|
|
- }
|
|
|
- retErr = Error_Succeed;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ }else{
|
|
|
+ DevErrorInfo devErrInfo;
|
|
|
m_pFingerPrint->GetLastErr(devErrInfo);
|
|
|
- LogError(Severity_High, Error_Hardware, LOG_ERR_FINGERPRINT_INVOKE_MATCH_FAILED, "Invoke routine 'Match' failed.");//no this situation
|
|
|
- Dbg("Invoke routine 'Match' failed which returned 0x%x(%s)", eErr, devErrInfo.szErrMsg);
|
|
|
- retErr = Error_Unexpect;
|
|
|
+ LogError(Severity_High, Error_Hardware
|
|
|
+ , LOG_ERR_FINGERPRINT_INVOKE_MATCH_FAILED
|
|
|
+ , "Invoke routine 'Match' failed.");//no this situation
|
|
|
+ Dbg("Invoke routine 'Match' failed which returned %s(%s)"
|
|
|
+ , SpStrError(errCode), devErrInfo.szErrMsg);
|
|
|
+ errCode = Error_Unexpect;
|
|
|
}
|
|
|
for (int i = 0; i < templateNum; ++i)
|
|
|
{
|
|
|
@@ -736,29 +608,123 @@ ErrorCodeEnum CFingerPrintFSM::Match(SpReqAnsContext<FingerPrintService_Match_Re
|
|
|
delete[] lpbTemplates;
|
|
|
lpbTemplates = NULL;
|
|
|
}
|
|
|
- else if (elapsed >= FINGERPRINT_MATCH_TIMEOUT)
|
|
|
+ else if (initParam->m_TimeLeft >= FINGERPRINT_MATCH_TIMEOUT)
|
|
|
{
|
|
|
Dbg("Match timeout(Invoke vendor failed or not press finger)");
|
|
|
- retErr = Error_TimeOut;
|
|
|
+ errCode = Error_TimeOut;
|
|
|
}
|
|
|
-
|
|
|
else if (m_bCancelMatch)
|
|
|
{
|
|
|
- retErr = Error_Cancel;
|
|
|
+ errCode = Error_Cancel;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- if(bNotFindImage)
|
|
|
+ if (initParam->m_NotFindImage)
|
|
|
LogError(Severity_High, Error_Hardware, LOG_ERR_FINGERPRINT_NO_IMAGE_IN_DEP_MATCH, "not find fingerprint image in dep while match.");
|
|
|
- else if(bFeatureIsNull)
|
|
|
+ else if (initParam->m_FeatureIsNull)
|
|
|
LogError(Severity_High, Error_Hardware, LOG_ERR_FINGERPRINT_GETFEATURE_FAILED_MATCH, "fingerprint feature is null while match.");
|
|
|
- else if(bExit)
|
|
|
+ else if (initParam->m_Quit)
|
|
|
LogWarn(Severity_High, Error_Hardware, LOG_ERR_FINGERPRINT_MATCH_FAILED, "Exit to homepage when match.");
|
|
|
- retErr = Error_Unexpect;
|
|
|
+ errCode = Error_Unexpect;
|
|
|
}
|
|
|
- delete[] lpbFeature;
|
|
|
- lpbFeature = NULL;
|
|
|
- return retErr;
|
|
|
+ delete[] initParam->m_Feature;
|
|
|
+ initParam->m_Feature = NULL;
|
|
|
+ delete initParam;
|
|
|
+ initParam = NULL;
|
|
|
+
|
|
|
+ return errCode;
|
|
|
+}
|
|
|
+
|
|
|
+ErrorCodeEnum CFingerPrintFSM::InitCommParam(ScanParam* initParam, int operateType, int scanTime, int templateNum)
|
|
|
+{
|
|
|
+ ErrorCodeEnum errCode = Error_Succeed;
|
|
|
+
|
|
|
+ if (!initParam)
|
|
|
+ return Error_Param;
|
|
|
+
|
|
|
+ if (!m_devInit)
|
|
|
+ errCode = Error_NotInit; //maybe no vendor adapter
|
|
|
+
|
|
|
+ if ((operateType & RegisterType) == RegisterType)
|
|
|
+ {
|
|
|
+ if (m_bCancelRegister) //no cancel button anymore while register
|
|
|
+ {
|
|
|
+ m_bCancelRegister = false;
|
|
|
+ errCode = Error_Cancel;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ((operateType & MatchType) == MatchType && templateNum <= 0)
|
|
|
+ errCode = Error_Param;
|
|
|
+
|
|
|
+ if (errCode != Error_Succeed) {
|
|
|
+ delete initParam;
|
|
|
+ initParam = NULL;
|
|
|
+ }
|
|
|
+
|
|
|
+ initParam->m_TimeStart = clock();
|
|
|
+ initParam->m_TimeEnd = clock();
|
|
|
+ initParam->m_TimeLeft = 0;
|
|
|
+
|
|
|
+ initParam->m_Feature = new BYTE[MAX_FEATURE_LEN];
|
|
|
+ initParam->m_FeatureLen = MAX_FEATURE_LEN;
|
|
|
+ initParam->m_FullFilePath = "";
|
|
|
+
|
|
|
+ initParam->m_ScanSuc = false;
|
|
|
+ initParam->m_NotFindImage = false;
|
|
|
+ initParam->m_FeatureIsNull = false;
|
|
|
+ initParam->m_Quit = false;
|
|
|
+
|
|
|
+ if (scanTime == 1)
|
|
|
+ {
|
|
|
+ m_BmpFileFullPath1 = "";
|
|
|
+ m_BmpFileFullPath2 = "";
|
|
|
+ m_BmpFileFullPath3 = "";
|
|
|
+ }
|
|
|
+ Dbg("before scan fingerprint, clear bmp file");
|
|
|
+ DeleteBmp(BmpImage);
|
|
|
+ Dbg("before scan fingerprint, finish doing clear job");
|
|
|
+
|
|
|
+ if ((operateType & RegisterType) == RegisterType)
|
|
|
+ {
|
|
|
+ initParam->m_Template = new BYTE[MAX_FEATURE_LEN];
|
|
|
+ initParam->m_GetTemplateSuc = true;
|
|
|
+ m_bCancelRegister = false;
|
|
|
+
|
|
|
+ memset(initParam->m_Template, 0, sizeof(initParam->m_Template));
|
|
|
+ }else
|
|
|
+ m_bCancelMatch = false;
|
|
|
+
|
|
|
+ memset(initParam->m_Feature, 0, sizeof(initParam->m_Feature));
|
|
|
+
|
|
|
+ errCode = m_pEntity->GetFunction()->GetPath("Dep", initParam->m_DepPath);
|
|
|
+ if (errCode != Error_Succeed)
|
|
|
+ {
|
|
|
+ delete[] initParam->m_Feature;
|
|
|
+ initParam->m_Feature = NULL;
|
|
|
+
|
|
|
+ if ((operateType & RegisterType) == RegisterType)
|
|
|
+ {
|
|
|
+ delete[] initParam->m_Template;
|
|
|
+ initParam->m_Template = NULL;
|
|
|
+
|
|
|
+ Dbg("Get dep path failed while register.");
|
|
|
+ LogError(Severity_High, Error_DevLoadFileFailed
|
|
|
+ , LOG_ERR_FINGERPRINT_GET_DEP_PATH_FAILED_REGISTER
|
|
|
+ , "Get dep path failed while register.");
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ Dbg("Get dep path failed while match.");
|
|
|
+ LogError(Severity_High, Error_DevLoadFileFailed
|
|
|
+ , LOG_ERR_FINGERPRINT_GET_DEP_PATH_FAILED_MATCH
|
|
|
+ , "get dep path failed while match.");
|
|
|
+ }
|
|
|
+
|
|
|
+ delete initParam;
|
|
|
+ initParam = NULL;
|
|
|
+
|
|
|
+ return Error_Param;
|
|
|
+ }
|
|
|
+ return Error_Succeed;
|
|
|
}
|
|
|
|
|
|
ErrorCodeEnum CFingerPrintFSM::GetDevCatInfo(DevCategoryInfo& devInfo)
|
|
|
@@ -823,8 +789,7 @@ ErrorCodeEnum CFingerPrintFSM::DoDevOpen(CSmartPointer<IConfigInfo> spConfig)
|
|
|
m_DevAdptLibHelper = nullptr;
|
|
|
|
|
|
return Error_DevCommFailed;
|
|
|
- }
|
|
|
- else {
|
|
|
+ }else {
|
|
|
Dbg("this is FWB, device status is normal now.");
|
|
|
}
|
|
|
}
|
|
|
@@ -1010,4 +975,102 @@ bool CFingerPrintFSM::IsFWBDevice()
|
|
|
isFWB = true;
|
|
|
}
|
|
|
return isFWB;
|
|
|
+}
|
|
|
+
|
|
|
+ErrorCodeEnum CFingerPrintFSM::CheckCardSwiperStatus()
|
|
|
+{
|
|
|
+ ErrorCodeEnum errCode = Error_Unexpect;
|
|
|
+ CardSwiperService_ClientBase* pCardSwiperClient = new CardSwiperService_ClientBase(this->GetEntityBase());
|
|
|
+ errCode = pCardSwiperClient->Connect();
|
|
|
+ if (errCode != Error_Succeed)
|
|
|
+ {
|
|
|
+ Dbg("connect CardSwiper fail 0x%x(%d).", errCode, errCode);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ CardSwiperService_GetDevInfo_Req req = {};
|
|
|
+ CardSwiperService_GetDevInfo_Ans ans = {};
|
|
|
+ errCode = pCardSwiperClient->GetDevInfo(req, ans, 3000);
|
|
|
+
|
|
|
+ if (errCode != Error_Succeed)
|
|
|
+ {
|
|
|
+ Dbg("CardSwiper::GetDevInfo() fail: 0x%x", errCode);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ Dbg("CardSwiper::GetDevInfo() return state: %d", ans.state);
|
|
|
+ if (ans.state == DEVICE_STATUS_NOT_READY)
|
|
|
+ {
|
|
|
+ std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
|
|
+ CardSwiperService_GetDevInfo_Req req2 = {};
|
|
|
+ CardSwiperService_GetDevInfo_Ans ans2 = {};
|
|
|
+ errCode = pCardSwiperClient->GetDevInfo(req2, ans2, 3000);
|
|
|
+ if (errCode != Error_Succeed)
|
|
|
+ {
|
|
|
+ Dbg("CardSwiper::GetDevInfo() again fail: 0x%x", errCode);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ Dbg("CardSwiper::GetDevInfo() again return state: %d", ans2.state);
|
|
|
+ if (ans2.state != DEVICE_STATUS_NORMAL)
|
|
|
+ errCode = Error_DevNotAvailable;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (ans.state != DEVICE_STATUS_NORMAL)
|
|
|
+ errCode = Error_DevNotAvailable;
|
|
|
+ }
|
|
|
+ pCardSwiperClient->GetFunction()->CloseSession();
|
|
|
+ }
|
|
|
+ if (pCardSwiperClient != NULL)
|
|
|
+ {
|
|
|
+ pCardSwiperClient->SafeDelete();
|
|
|
+ pCardSwiperClient = NULL;
|
|
|
+ }
|
|
|
+
|
|
|
+ return errCode;
|
|
|
+}
|
|
|
+
|
|
|
+void CFingerPrintFSM::DeleteBmp(int type)
|
|
|
+{
|
|
|
+ if ((type & BmpImage) == BmpImage)
|
|
|
+ {
|
|
|
+ Dbg("to delete fingerprint images...");
|
|
|
+ DeleteFileIfExisted("finger.bmp");
|
|
|
+ DeleteFileIfExisted("finger1.bmp");
|
|
|
+ DeleteFileIfExisted("finger2.bmp");
|
|
|
+ DeleteFileIfExisted("finger3.bmp");
|
|
|
+ }
|
|
|
+ if ((type & TestImage) == TestImage)
|
|
|
+ {
|
|
|
+ DeleteFileIfExisted("testFinger.bmp");
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+ErrorCodeEnum CFingerPrintFSM::DeleteFileIfExisted(LPCTSTR fileName)
|
|
|
+{
|
|
|
+ if (strlen(fileName) == 0 || strchr(fileName, (int)'*') != NULL)
|
|
|
+ {
|
|
|
+ Dbg("Invalid or empty filename(%s)", fileName);
|
|
|
+ return Error_Param;
|
|
|
+ }
|
|
|
+ CSimpleStringA strPath, strObjPath;
|
|
|
+ ErrorCodeEnum errCode = m_pEntity->GetFunction()->GetPath("Dep", strPath);
|
|
|
+ strObjPath = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", (const char*)strPath, (const char*)fileName);
|
|
|
+ std::ifstream beDeletedFile((const char*)strObjPath, std::ifstream::binary);
|
|
|
+
|
|
|
+ if (beDeletedFile)
|
|
|
+ {
|
|
|
+ if (remove((const char*)strObjPath) == 0)
|
|
|
+ {
|
|
|
+ Dbg("DeleteFile(%s) success.", (const char*)strObjPath);
|
|
|
+ return Error_Succeed;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ Dbg("DeleteFile(%s) failed LastError(%s).", (const char*)strObjPath, GetLastError());
|
|
|
+ return Error_Unexpect;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (GetLastError() == ERROR_FILE_NOT_FOUND)
|
|
|
+ {
|
|
|
+ return Error_Succeed;
|
|
|
+ }
|
|
|
+ Dbg("DeleteFle(%s) Unexpect GetLastError(%s).", (LPCTSTR)strObjPath, GetLastError());
|
|
|
+ return Error_Unexpect;
|
|
|
}
|