2024-04-08 02:38:51 +00:00
|
|
|
|
#include "DealRfidEngine.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using namespace ai_matrix;
|
|
|
|
|
|
|
|
|
|
|
|
DealRfidEngine::DealRfidEngine() {}
|
|
|
|
|
|
|
|
|
|
|
|
DealRfidEngine::~DealRfidEngine() {}
|
|
|
|
|
|
|
|
|
|
|
|
APP_ERROR DealRfidEngine::Init()
|
|
|
|
|
|
{
|
|
|
|
|
|
strPort0_ = engineName_ + "_" + std::to_string(engineId_) + "_0";
|
|
|
|
|
|
strPort1_ = engineName_ + "_" + std::to_string(engineId_) + "_1";
|
|
|
|
|
|
strPort2_ = engineName_ + "_" + std::to_string(engineId_) + "_2";
|
|
|
|
|
|
|
|
|
|
|
|
this->baseConfig_ = Config::GetIns()->getBaseConfig();
|
2024-04-25 09:53:34 +00:00
|
|
|
|
this->videoAuxiliaryConfig_ = Config::GetIns()->getVideoAuxiliaryConfig();
|
2024-04-08 02:38:51 +00:00
|
|
|
|
|
|
|
|
|
|
this->initParam();
|
|
|
|
|
|
|
|
|
|
|
|
LogInfo << "DealRfidEngine Init ok";
|
|
|
|
|
|
return APP_ERR_OK;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
APP_ERROR DealRfidEngine::DeInit()
|
|
|
|
|
|
{
|
|
|
|
|
|
LogInfo << "DealRfidEngine DeInit ok";
|
|
|
|
|
|
return APP_ERR_OK;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
APP_ERROR DealRfidEngine::Process()
|
|
|
|
|
|
{
|
|
|
|
|
|
int iRet = APP_ERR_OK;
|
|
|
|
|
|
while (!isStop_)
|
|
|
|
|
|
{
|
2024-04-25 09:53:34 +00:00
|
|
|
|
if (this->videoAuxiliaryConfig_.bUseVideoAuxiliary)
|
|
|
|
|
|
{
|
|
|
|
|
|
//pop端口1
|
|
|
|
|
|
std::shared_ptr<void> pVoidData1 = nullptr;
|
|
|
|
|
|
iRet = inputQueMap_[strPort1_]->pop(pVoidData1);
|
|
|
|
|
|
if (nullptr != pVoidData1)
|
|
|
|
|
|
{
|
|
|
|
|
|
std::shared_ptr<ComeTrainInfo> pComeTrainInfo = std::static_pointer_cast<ComeTrainInfo>(pVoidData1);
|
|
|
|
|
|
this->videoHasTrain_ = pComeTrainInfo->bComeTrain;
|
|
|
|
|
|
this->identifyFlagUpdate();
|
|
|
|
|
|
if (this->iVDirection_ == 0 && pComeTrainInfo->iDirection != 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
LogInfo << "视频辅助检测来车状态 判定 来车方向:" << (pComeTrainInfo->iDirection > -1 ? (pComeTrainInfo->iDirection > 0 ? "需识别" : "待定") : "无需上传");
|
|
|
|
|
|
this->iVDirection_ = pComeTrainInfo->iDirection;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-08 02:38:51 +00:00
|
|
|
|
//pop端口0
|
|
|
|
|
|
std::shared_ptr<void> pVoidData0 = nullptr;
|
|
|
|
|
|
iRet = inputQueMap_[strPort0_]->pop(pVoidData0);
|
|
|
|
|
|
if (nullptr == pVoidData0)
|
|
|
|
|
|
{
|
|
|
|
|
|
usleep(1000);
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<RfidInfo> pRfidData = std::static_pointer_cast<RfidInfo>(pVoidData0);
|
|
|
|
|
|
|
|
|
|
|
|
this->tmpRfid_.append(pRfidData->strRfid);
|
|
|
|
|
|
|
|
|
|
|
|
if (this->tmpRfid_.substr(this->tmpRfid_.size()-1,1) != "&")
|
|
|
|
|
|
{
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this->tmpRfid_ = StringUtil::getins()->replace_all_distinct(this->tmpRfid_, "&", "");
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<std::string> vecRfidSub = StringUtil::getins()->split(this->tmpRfid_, "@");
|
|
|
|
|
|
|
|
|
|
|
|
this->tmpRfid_ = "";
|
|
|
|
|
|
|
|
|
|
|
|
auto split_lambda = [=](std::string strFirst, std::string strOther){
|
|
|
|
|
|
if (strFirst == "0")
|
|
|
|
|
|
{
|
|
|
|
|
|
this->rfidHasTrain_ = false;
|
|
|
|
|
|
LogInfo << "RFID-火车离开了";
|
|
|
|
|
|
this->identifyFlagUpdate();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// 注意: 此处按照4个磁钢来配置,可能存在一定限制
|
|
|
|
|
|
if (strOther == "000000") // 第一次检测来车时(前提是上一次功放已关闭)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (strFirst == this->baseConfig_.strMagnetSteelOrder.substr(0, 1)
|
|
|
|
|
|
|| strFirst == this->baseConfig_.strMagnetSteelOrder.substr(1, 1))
|
|
|
|
|
|
{
|
|
|
|
|
|
this->rfidHasTrain_ = true;
|
|
|
|
|
|
LogInfo << "RFID-来车了";
|
|
|
|
|
|
this->identifyFlagUpdate();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
LogInfo << "RFID-列车出厂";
|
|
|
|
|
|
this->rfidHasTrain_ = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
for (const auto & i : vecRfidSub)
|
|
|
|
|
|
{
|
2024-04-25 09:53:34 +00:00
|
|
|
|
if (i.empty()) continue;
|
2024-04-08 02:38:51 +00:00
|
|
|
|
if (i.size() == 26 || i.size() == 24)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 车厢信息
|
2024-04-25 09:53:34 +00:00
|
|
|
|
std::string strTrainInfo = i.substr(1, 13);
|
2024-04-08 02:38:51 +00:00
|
|
|
|
|
|
|
|
|
|
if (this->vecTrain_.empty() || !Utils::getins()->contains_vec(this->vecTrain_, strTrainInfo))
|
|
|
|
|
|
{
|
2024-04-25 09:53:34 +00:00
|
|
|
|
// 判断是否是车头 车头的第14位是 K或H (慎重)
|
|
|
|
|
|
if (!StringUtil::getins()->is_digits(i.substr(14, 1))) continue;
|
|
|
|
|
|
// 过滤掉车号中有非数字的
|
|
|
|
|
|
if (!StringUtil::getins()->is_digits(strTrainInfo.substr(strTrainInfo.size() -7, 7))) continue;
|
|
|
|
|
|
|
2024-04-08 02:38:51 +00:00
|
|
|
|
vecTrain_.emplace_back(strTrainInfo);
|
|
|
|
|
|
int train_order = vecTrain_.size();
|
|
|
|
|
|
LogInfo << "第" << train_order << "节 " << strTrainInfo;
|
|
|
|
|
|
// 将接收到的RFID使用@符拼接起来,以待后续上传web
|
|
|
|
|
|
this->rfidSourceInfo_.append("@" + i);
|
|
|
|
|
|
std::string rfidinfo = this->rfidSourceInfo_;
|
|
|
|
|
|
this->rfidSourceInfo_ = "";
|
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<TrainInfo> pTrainInfo = std::make_shared<TrainInfo>();
|
2024-04-25 09:53:34 +00:00
|
|
|
|
TrainInfo tmpTrainInfo;
|
2024-04-08 02:38:51 +00:00
|
|
|
|
this->makeTrainInfo(rfidinfo, pTrainInfo);
|
2024-04-25 09:53:34 +00:00
|
|
|
|
queueTmpTrainInfo_.Push(pTrainInfo);
|
2024-04-08 02:38:51 +00:00
|
|
|
|
|
|
|
|
|
|
if (this->needIdentify_) {
|
2024-04-25 09:53:34 +00:00
|
|
|
|
if (this->iVDirection_ < 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
queueTmpTrainInfo_.Clear();
|
|
|
|
|
|
}
|
|
|
|
|
|
if (this->iVDirection_ > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
while (!queueTmpTrainInfo_.IsEmpty())
|
|
|
|
|
|
{
|
|
|
|
|
|
queueTmpTrainInfo_.Pop(pTrainInfo);
|
|
|
|
|
|
// 上传识别结果
|
|
|
|
|
|
iRet = outputQueMap_[strPort1_]->push(std::static_pointer_cast<void>(pTrainInfo));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-04-08 02:38:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
// 存储识别结果
|
|
|
|
|
|
iRet = outputQueMap_[strPort2_]->push(std::static_pointer_cast<void>(pTrainInfo));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (i.size() == 7)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 不使用磁钢的情况下 过滤掉磁钢信号
|
|
|
|
|
|
if (!this->baseConfig_.bHaveMagnetSteel) continue;
|
|
|
|
|
|
// 磁钢信号
|
|
|
|
|
|
std::string strFirst = i.substr(0,1);
|
|
|
|
|
|
std::string strOther = i.substr(1, i.size() - 1);
|
|
|
|
|
|
// 将接收到的RFID使用@符拼接起来,以待后续上传web
|
|
|
|
|
|
this->rfidSourceInfo_.append("@" + i);
|
|
|
|
|
|
split_lambda(strFirst, strOther);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (i.size() == 14) // 特殊情况,来车信号少了&符
|
|
|
|
|
|
{
|
|
|
|
|
|
// 不使用磁钢的情况下 过滤掉磁钢信号
|
|
|
|
|
|
if (!this->baseConfig_.bHaveMagnetSteel) continue;
|
|
|
|
|
|
for (int j = 0; j < i.size(); j+=7) {
|
|
|
|
|
|
std::string rfid_cg = i.substr(j, 7);
|
|
|
|
|
|
std::string strFirst = rfid_cg.substr(0, 1);
|
|
|
|
|
|
std::string strOther = rfid_cg.substr(1, 6);
|
|
|
|
|
|
// 将接收到的RFID使用@符拼接起来,以待后续上传web
|
|
|
|
|
|
this->rfidSourceInfo_.append("@" + rfid_cg);
|
|
|
|
|
|
split_lambda(strFirst, strOther);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
pRfidData->strTrainTime = this->trainTime_;
|
|
|
|
|
|
// 存储原始数据
|
|
|
|
|
|
iRet = outputQueMap_[strPort0_]->push(std::static_pointer_cast<void>(pRfidData));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return APP_ERR_OK;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 参数初始化
|
|
|
|
|
|
*/
|
|
|
|
|
|
void DealRfidEngine::initParam() {
|
|
|
|
|
|
this->rfidSourceInfo_ = "";
|
|
|
|
|
|
this->trainTime_ = "";
|
|
|
|
|
|
this->vecTrain_.clear();
|
|
|
|
|
|
this->tmpRfid_ = "";
|
|
|
|
|
|
// 识别方向正确标志
|
|
|
|
|
|
this->needIdentify_ = false;
|
|
|
|
|
|
// 视频识别有火车标志(使用socket服务时才有用)
|
|
|
|
|
|
this->videoHasTrain_ = false;
|
|
|
|
|
|
// RFID识别有火车标志
|
|
|
|
|
|
this->rfidHasTrain_ = false;
|
2024-04-25 09:53:34 +00:00
|
|
|
|
//
|
|
|
|
|
|
this->iVDirection_ = 0;
|
2024-04-08 02:38:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 修改识别状态
|
|
|
|
|
|
*/
|
|
|
|
|
|
void DealRfidEngine::identifyFlagUpdate() {
|
|
|
|
|
|
if (this->rfidHasTrain_ || this->videoHasTrain_)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!this->needIdentify_)
|
|
|
|
|
|
{
|
|
|
|
|
|
LogInfo << "--- 来车了 ---";
|
|
|
|
|
|
this->vecTrain_.clear();
|
|
|
|
|
|
this->needIdentify_ = true;
|
|
|
|
|
|
this->trainTime_ = TimeUtil::getins()->getDateTime();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (!this->rfidHasTrain_ && !this->videoHasTrain_)
|
|
|
|
|
|
{
|
|
|
|
|
|
this->initParam();
|
|
|
|
|
|
LogInfo << "--- 火车离开了 ---";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 组织识别数据
|
|
|
|
|
|
* @param rfidinfo
|
|
|
|
|
|
* @param pTrainInfo
|
|
|
|
|
|
*/
|
|
|
|
|
|
void DealRfidEngine::makeTrainInfo(const std::string rfidinfo, std::shared_ptr<TrainInfo> pTrainInfo) {
|
|
|
|
|
|
std::string info = this->vecTrain_.back();
|
|
|
|
|
|
int order = this->vecTrain_.size();
|
2024-04-25 09:53:34 +00:00
|
|
|
|
if (order > this->videoAuxiliaryConfig_.iDelayedUpload && this->iVDirection_ == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
this->iVDirection_ = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!this->videoAuxiliaryConfig_.bUseVideoAuxiliary) this->iVDirection_ = 1;
|
2024-04-08 02:38:51 +00:00
|
|
|
|
|
|
|
|
|
|
if (this->trainTime_.empty()) this->trainTime_ = TimeUtil::getins()->getDateTime();
|
|
|
|
|
|
pTrainInfo->strCarriageType = StringUtil::getins()->trim(info.substr(0, 6));
|
|
|
|
|
|
pTrainInfo->strCarriageNum = StringUtil::getins()->trim(info.substr(6, info.size() - 6));
|
|
|
|
|
|
pTrainInfo->strOrder = std::to_string(order);
|
|
|
|
|
|
pTrainInfo->strTrainTime = this->trainTime_;
|
|
|
|
|
|
pTrainInfo->strRfidInfo = rfidinfo;
|
|
|
|
|
|
pTrainInfo->strNowTime = TimeUtil::getins()->getDateTime_usec();
|
|
|
|
|
|
}
|