2024-04-08 02:38:51 +00:00
|
|
|
#include "SaveRfidEngine.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using namespace ai_matrix;
|
|
|
|
|
|
|
|
|
|
SaveRfidEngine::SaveRfidEngine() {}
|
|
|
|
|
|
|
|
|
|
SaveRfidEngine::~SaveRfidEngine() {}
|
|
|
|
|
|
|
|
|
|
APP_ERROR SaveRfidEngine::Init()
|
|
|
|
|
{
|
|
|
|
|
strPort0_ = engineName_ + "_" + std::to_string(engineId_) + "_0";
|
|
|
|
|
this->baseConfig_ = Config::GetIns()->getBaseConfig();
|
|
|
|
|
|
|
|
|
|
LogInfo << "SaveRfidEngine Init ok";
|
|
|
|
|
return APP_ERR_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
APP_ERROR SaveRfidEngine::DeInit()
|
|
|
|
|
{
|
|
|
|
|
LogInfo << "SaveRfidEngine DeInit ok";
|
|
|
|
|
return APP_ERR_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
APP_ERROR SaveRfidEngine::Process()
|
|
|
|
|
{
|
|
|
|
|
int iRet = APP_ERR_OK;
|
|
|
|
|
while (!isStop_)
|
|
|
|
|
{
|
|
|
|
|
//pop端口0
|
|
|
|
|
std::shared_ptr<void> pVoidData0 = nullptr;
|
|
|
|
|
iRet = inputQueMap_[strPort0_]->pop(pVoidData0);
|
|
|
|
|
if (nullptr == pVoidData0)
|
|
|
|
|
{
|
|
|
|
|
usleep(1000);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<RfidInfo> pRfidInfo = std::static_pointer_cast<RfidInfo>(pVoidData0);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if (pRfidInfo->strTrainTime == "") continue;
|
|
|
|
|
|
2024-04-25 09:53:34 +00:00
|
|
|
std::string strTrainPath = this->baseConfig_.strRfidPath + "/" + TimeUtil::getins()->getDate() + "/";
|
2024-04-08 02:38:51 +00:00
|
|
|
|
2024-04-25 09:53:34 +00:00
|
|
|
//1. 创建保存路径
|
2024-04-08 02:38:51 +00:00
|
|
|
if (!FileUtil::getins()->CreateDirPath(strTrainPath))
|
|
|
|
|
{
|
|
|
|
|
LogError << "结果目录:" << strTrainPath << " 创建失败!";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2024-04-25 09:53:34 +00:00
|
|
|
std::string strLogName = pRfidInfo->strTrainTime + "_source.log";
|
2024-04-08 02:38:51 +00:00
|
|
|
strLogName = StringUtil::getins()->replace_all_distinct(strLogName, ":", "-");
|
|
|
|
|
strLogName = StringUtil::getins()->replace_all_distinct(strLogName, " ", "T");
|
2024-04-25 09:53:34 +00:00
|
|
|
std::string strLogPath = strTrainPath + "/" + strLogName;
|
2024-04-08 02:38:51 +00:00
|
|
|
|
|
|
|
|
std::ofstream fs(strLogPath, std::ios::app);
|
|
|
|
|
if (!fs)
|
|
|
|
|
{
|
|
|
|
|
LogError << "open file " << strLogPath << " fail" << std::endl;
|
|
|
|
|
}
|
|
|
|
|
fs.seekp(0, std::ofstream::end);
|
|
|
|
|
fs << pRfidInfo->strRfid << std::endl;
|
|
|
|
|
fs.close();
|
|
|
|
|
} catch (const std::exception &e) {
|
|
|
|
|
LogError << "保存RFID原数据失败";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return APP_ERR_OK;
|
|
|
|
|
}
|