135 lines
5.3 KiB
C++
135 lines
5.3 KiB
C++
|
|
#include <TestProject/DCR/Snapshot.h>
|
||
|
|
#include <TestProject/DCR/connection/connection.h>
|
||
|
|
#include <mix_cc/type/mix_time.h>
|
||
|
|
SnapShot::SnapShot() {
|
||
|
|
logger_ = std::make_unique<LOG>("SnapShot");
|
||
|
|
DCR::ihd::auto_connect();
|
||
|
|
if (DCR::ihd::Connection::State::disconnected ==
|
||
|
|
DCR::ihd::read_conn().state) {
|
||
|
|
logger_->Error() << "ihd connect failure! " << endl;
|
||
|
|
}
|
||
|
|
GetTagIDs(2020);
|
||
|
|
logger_->Debug() << "SnapShot::SnapShot()" << (int)DCR::ihd::read_conn().state
|
||
|
|
<< ",thid:" << DCR::ihd::read_conn().tid << endl;
|
||
|
|
}
|
||
|
|
SnapShot::~SnapShot() {
|
||
|
|
DCR::ihd::disconnect_maybe(DCR::ihd::read_conn());
|
||
|
|
for (auto& it : m_mapfix) {
|
||
|
|
if (it.second != nullptr) {
|
||
|
|
delete it.second;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
bool SnapShot::is_connected() {
|
||
|
|
logger_->Debug() << "SnapShot::is_connected()"
|
||
|
|
<< (int)DCR::ihd::read_conn().state
|
||
|
|
<< ",thid:" << DCR::ihd::read_conn().tid << endl;
|
||
|
|
return (int)DCR::ihd::read_conn().state;
|
||
|
|
}
|
||
|
|
|
||
|
|
bool SnapShot::to_connect() {
|
||
|
|
if (DCR::ihd::Connection::State::disconnected ==
|
||
|
|
DCR::ihd::read_conn().state) {
|
||
|
|
DCR::ihd::auto_connect();
|
||
|
|
}
|
||
|
|
return (int)DCR::ihd::read_conn().state;
|
||
|
|
}
|
||
|
|
bool SnapShot::GetTagIDs(int eventNo) {
|
||
|
|
if (mv_tagids_.find(eventNo) == mv_tagids_.end()) {
|
||
|
|
logger_->Debug() << "SnapShot::GetTagIDs---1" << std::endl;
|
||
|
|
binary_tele.ReBuild(eventNo);
|
||
|
|
logger_->Debug() << "SnapShot::GetTagIDs---2" << std::endl;
|
||
|
|
int size = binary_tele.size();
|
||
|
|
logger_->Debug() << "binary_tele size:" << size << std::endl;
|
||
|
|
mv_tagids_[eventNo].nTagNum = size;
|
||
|
|
std::vector<std::string> items;
|
||
|
|
for (int i = 0; i < size; i++) {
|
||
|
|
// sprintf(mv_tagids_[eventNo].szTagNames[i], "%s_%s",
|
||
|
|
// msz_unit_no,binary_tele[i].item);
|
||
|
|
strcpy(mv_tagids_[eventNo].szTagNames[i], binary_tele[i].item);
|
||
|
|
}
|
||
|
|
int nRet = tag3_query_ids_by_names(
|
||
|
|
mv_tagids_[eventNo].nTagNum, mv_tagids_[eventNo].szTagNames,
|
||
|
|
mv_tagids_[eventNo].tagID, mv_tagids_[eventNo].nErrCodes);
|
||
|
|
if (nRet == RD_SUCCESS) {
|
||
|
|
// for (int j = 0; j < size; j++) {
|
||
|
|
// logger_->Debug() << "eventNo:" << eventNo
|
||
|
|
// << ",item:" << mv_tagids_[eventNo].szTagNames[j]
|
||
|
|
// << ",tagid:" << mv_tagids_[eventNo].tagID[j]
|
||
|
|
// << std::endl;
|
||
|
|
// }
|
||
|
|
return true;
|
||
|
|
} else {
|
||
|
|
for (int j = 0; j < size; j++) {
|
||
|
|
if (mv_tagids_[eventNo].nErrCodes[j] = !RD_SUCCESS) {
|
||
|
|
logger_->Error() << "eventNo:" << eventNo
|
||
|
|
<< ",item:" << mv_tagids_[eventNo].szTagNames[j]
|
||
|
|
<< ",tagid:" << mv_tagids_[eventNo].tagID[j]
|
||
|
|
<< ",ErrCode:" << mv_tagids_[eventNo].nErrCodes[j]
|
||
|
|
<< std::endl;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
logger_->Error() << "SnapShot::GetTagIDs failure!---ErrCode:" << nRet
|
||
|
|
<< std::endl;
|
||
|
|
return false;
|
||
|
|
} else {
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (mv_tagids_[eventNo].nTagNum == 0) {
|
||
|
|
logger_->Debug() << "SnapShot::GetTagIDs()---- No data item!" << std::endl;
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
void SnapShot::update_data(int eventNo) {
|
||
|
|
if (m_mapfix.find(eventNo) == m_mapfix.end()) {
|
||
|
|
m_mapfix.insert(make_pair(
|
||
|
|
eventNo,
|
||
|
|
new CMemFix<PLC_DATA>(std::to_string(eventNo), TEL_CACHE_SIZE)));
|
||
|
|
}
|
||
|
|
if (GetTagIDs(eventNo)) {
|
||
|
|
int nRet = sn3_query_snapshots(
|
||
|
|
mv_tagids_[eventNo].nTagNum, mv_tagids_[eventNo].tagID,
|
||
|
|
mv_tagids_[eventNo].pRec, mv_tagids_[eventNo].nErrCodes);
|
||
|
|
if (nRet == RD_SUCCESS) {
|
||
|
|
binary_tele.ReBuild(eventNo);
|
||
|
|
for (int j = 0; j < mv_tagids_[eventNo].nTagNum; j++) {
|
||
|
|
if (mv_tagids_[eventNo].nErrCodes[j] == RD_SUCCESS) {
|
||
|
|
binary_tele[j] = (float)mv_tagids_[eventNo].pRec[j].NumberValue();
|
||
|
|
logger_->Debug() << "eventNo:" << eventNo
|
||
|
|
<< ",item:" << mv_tagids_[eventNo].szTagNames[j]
|
||
|
|
<< ",tagid:" << mv_tagids_[eventNo].tagID[j]
|
||
|
|
<< ",value:"
|
||
|
|
<< mv_tagids_[eventNo].pRec[j].NumberValue()
|
||
|
|
<< ",time:"
|
||
|
|
<< mix_cc::mix_time_t(
|
||
|
|
HD3Time(mv_tagids_[eventNo].pRec[j].nSec,
|
||
|
|
mv_tagids_[eventNo].pRec[j].nMsec))
|
||
|
|
.to_formatted_time("%Y-%m-%d %H:%M:%S:%M")
|
||
|
|
<< std::endl;
|
||
|
|
} else {
|
||
|
|
logger_->Error() << "eventNo:" << eventNo
|
||
|
|
<< ",item:" << mv_tagids_[eventNo].szTagNames[j]
|
||
|
|
<< ",tagid:" << mv_tagids_[eventNo].tagID[j]
|
||
|
|
<< ",ErrCode:" << mv_tagids_[eventNo].nErrCodes[j]
|
||
|
|
<< std::endl;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
for (int j = 0; j < mv_tagids_[eventNo].nTagNum; j++) {
|
||
|
|
if (mv_tagids_[eventNo].nErrCodes[j] != RD_SUCCESS) {
|
||
|
|
logger_->Error() << "eventNo:" << eventNo
|
||
|
|
<< ",item:" << mv_tagids_[eventNo].szTagNames[j]
|
||
|
|
<< ",tagid:" << mv_tagids_[eventNo].tagID[j]
|
||
|
|
<< ",ErrCode:" << mv_tagids_[eventNo].nErrCodes[j]
|
||
|
|
<< std::endl;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
char* buff = binary_tele.GetTeleData();
|
||
|
|
m_mapfix[eventNo]->push((PLC_DATA*)buff);
|
||
|
|
}
|
||
|
|
}
|