| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- #include "FingerPrint_impl.h"
- #include "FingerPrint_httpans.h"
- #include <cstring>
- #include <cstdio>
- #include "log4vendor.h"
- #include <path.h>
- void writeFile(const char* filename)
- {
- FILE* fp = fopen(filename, "wb");
- fprintf(fp, "fingerImage");
- string content = "fingerImage";
- fwrite(content.c_str(), content.length(), 1, fp);
- fclose(fp);
- }
- FingerPrintImpl::FingerPrintImpl()
- {
- }
- FingerPrintImpl::~FingerPrintImpl()
- {
- }
- ErrorCodeEnum FingerPrintImpl::GetDevCategory(DevCategoryInfo& devCategory)
- {
- ErrorCodeEnum err = Error_Succeed;
- SimulatorDevCategoryAns ans;
- err = SimulatorHttpFunction(EntityName, "GetDevCategory", ans);
- LOG4VTM(INFO, "GetDevCategory err = " << err);
- strcpy(devCategory.szType, ans.szType.c_str());
- strcpy(devCategory.szModel, ans.szModel.c_str());
- strcpy(devCategory.szVendor, ans.szVendor.c_str());
- devCategory.eState = (DevStateEnum)ans.eState;
- devCategory.version.wMajor = ans.version.wMajor;
- devCategory.version.wMinor = ans.version.wMinor;
- devCategory.version.wRevision = ans.version.wRevision;
- devCategory.version.wBuild = ans.version.wBuild;
- return err;
- }
- ErrorCodeEnum FingerPrintImpl::Reset()
- {
- ErrorCodeEnum err = Error_Succeed;
- err = SimulatorHttpFunction(EntityName, "Reset");
- LOG4VTM(INFO, "Reset err = " << err);
- return err;
- }
- ErrorCodeEnum FingerPrintImpl::DevClose()
- {
- ErrorCodeEnum err = Error_Succeed;
- err = SimulatorHttpFunction(EntityName, "DevClose");
- LOG4VTM(INFO, "DevClose err = " << err);
- return err;
- }
- ErrorCodeEnum FingerPrintImpl::GetLastErr(DevErrorInfo& devErrInfo)
- {
- ErrorCodeEnum err = Error_Succeed;
- SimulatorDevErrInfoAns ans;
- err = SimulatorHttpFunction(EntityName, "GetLastErr", ans);
- LOG4VTM(INFO, "GetLastErr err = " << err);
- devErrInfo.dwErrMsgLen = ans.dwErrMsgLen;
- strcpy(devErrInfo.szErrMsg, ans.szErrMsg.c_str());
- return err;
- }
- ErrorCodeEnum FingerPrintImpl::DevOpen(DWORD dwPort, DWORD dwBaudRate)
- {
- ErrorCodeEnum err = Error_Succeed;
- err = SimulatorHttpFunction(EntityName, "DevOpen");
- LOG4VTM(INFO, "DevOpen err = " << err);
- return err;
- }
- ErrorCodeEnum FingerPrintImpl::Image2Feature(const char* imageName, LPBYTE lpbFeature, int& iLength)
- {
- ErrorCodeEnum err = Error_Succeed;
- Image2FeatureAns ans;
- err = SimulatorHttpFunction(EntityName, "Image2Feature", ans);
- LOG4VTM(INFO, "Image2Feature err = " << err);
- if (err == Error_Succeed)
- {
- //imageName写入的文件,lpbFeature 特征码,iLength特征码长度
- string imgName(imageName);
- string imgPath = GetCurrentDirectory() + SPLIT_SLASH_STR + imgName;
- writeFile(imgPath.c_str());
- #ifdef _MSC_VER
- strcpy_s((char*)lpbFeature, 1024, ans.lpbFeature.c_str());
- #else
- strncpy((char*)lpbFeature, ans.lpbFeature.c_str(), 1024);
- #endif
-
- iLength = ans.iLength;
- }
- return err;
- }
- ErrorCodeEnum FingerPrintImpl::Image2Template(const char* imagePath1, const char* imagePath2, const char* imagePath3, LPBYTE lpbTemplate, int& iLength)
- {
- //获取模板特征码
- LOG4VTM(INFO, "imagePath1 path = " << imagePath1);
- LOG4VTM(INFO, "imagePath2 path = " << imagePath2);
- LOG4VTM(INFO, "imagePath3 path = " << imagePath3);
-
- ErrorCodeEnum err = Error_Succeed;
- Image2TemplateAns ans;
- err = SimulatorHttpFunction(EntityName, "Image2Template", ans);
- LOG4VTM(INFO, "Image2Template err = " << err);
- if (err == Error_Succeed)
- {
- #ifdef _MSC_VER
- strcpy_s((char*)lpbTemplate, 1024, ans.lpbTemplate.c_str());
- #else
- strncpy((char*)lpbTemplate, ans.lpbTemplate.c_str(), 1024);
- #endif
- iLength = ans.iLength;
- }
- return err;
- }
- ErrorCodeEnum FingerPrintImpl::Match(LPBYTE lpbTemplate[], int iTemplateLen[], int templateNum, LPBYTE lbpFeature, int& iFeatureLen, int level /*= 3*/)
- {
- ErrorCodeEnum err = Error_Succeed;
- MatchAns ans;
- err = SimulatorHttpFunction(EntityName, "Match", ans);
- LOG4VTM(INFO, "Match err = " << err);
- if (err == Error_Succeed)
- {
- #ifdef _MSC_VER
- strcpy_s((char*)lbpFeature, 1024, ans.lbpFeature.c_str());
- #else
- strncpy((char*)lbpFeature, ans.lbpFeature.c_str(), 1024);
- #endif
- iFeatureLen = ans.iFeatureLen;
- }
- return err;
- }
- ErrorCodeEnum FingerPrintImpl::Cancel()
- {
- ErrorCodeEnum err = Error_Succeed;
- err = SimulatorHttpFunction(EntityName, "Cancel");
- LOG4VTM(INFO, "Cancel err = " << err);
- return err;
- }
- #ifdef _MSC_VER
- BOOL APIENTRY DllMain(HMODULE hModule,
- DWORD ul_reason_for_call,
- LPVOID lpReserved
- )
- {
- switch (ul_reason_for_call)
- {
- case DLL_PROCESS_ATTACH:
- case DLL_THREAD_ATTACH:
- case DLL_THREAD_DETACH:
- case DLL_PROCESS_DETACH:
- break;
- }
- return TRUE;
- }
- #endif
- DEVICEBASE_API ErrorCodeEnum CreateDevComponent(DeviceBaseClass*& pBaseObj)
- {
- pBaseObj = new FingerPrintImpl();
- if (pBaseObj == NULL) {
- return Error_Resource;
- }
- cmb::log_init_config config;
- config.dev_name = "vendor_FingerPrint";
- #ifdef _MSC_VER
- config.log_dir = ("C:\\rvc\\dbg\\");
- #else
- config.log_dir = ("/opt/rvc/dbg/");
- #endif
- std::string str;
- cmb::log4vendor::init(config, str);
-
- std::string tmpStr = GetSimulatorUrl();
- LOG4VTM(INFO, "URL = " << tmpStr.c_str());
- return Error_Succeed;
- }
- DEVICEBASE_API ErrorCodeEnum ReleaseDevComponent(DeviceBaseClass*& pBaseObj)
- {
- if (pBaseObj == NULL) {
- return Error_Param;
- }
- if (FingerPrintImpl* pTmp = dynamic_cast<FingerPrintImpl*>(pBaseObj))
- {
- delete pTmp;
- pTmp = NULL;
- return Error_Succeed;
- }
- return Error_Param;
- }
- #ifdef NEWER_COMPILER_WORKAROUNDS
- DEVICEBASE_API ErrorCodeEnum GetDevAdapterVersion(DevSoftVersion& retVesion)
- {
- retVesion.wMajor = retVesion.wMinor = retVesion.wBuild = retVesion.wRevision = 0;
- return Error_Succeed;
- }
- #endif // NEWER_COMPILER_WORKAROUNDS
|