#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 pVoidData0 = nullptr; iRet = inputQueMap_[strPort0_]->pop(pVoidData0); if (nullptr == pVoidData0) { usleep(1000); continue; } std::shared_ptr pRfidInfo = std::static_pointer_cast(pVoidData0); try { if (pRfidInfo->strTrainTime == "") continue; std::string strTrainPath = this->baseConfig_.strRfidPath + "/" + TimeUtil::getins()->getDate() + "/"; //1. 创建保存路径 if (!FileUtil::getins()->CreateDirPath(strTrainPath)) { LogError << "结果目录:" << strTrainPath << " 创建失败!"; return false; } std::string strLogName = pRfidInfo->strTrainTime + "_source.log"; strLogName = StringUtil::getins()->replace_all_distinct(strLogName, ":", "-"); strLogName = StringUtil::getins()->replace_all_distinct(strLogName, " ", "T"); std::string strLogPath = strTrainPath + "/" + strLogName; 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; }