| | |
| | | |
| | | } |
| | | |
| | | void CHsmsPassive::addReport(unsigned int id, const char* pszName) |
| | | void CHsmsPassive::linkEventReport(unsigned int CEID, unsigned int RPTID) |
| | | { |
| | | Lock(); |
| | | REPORT report; |
| | | report.id = id; |
| | | strcpy_s(report.szName, REPORT_NAME_MAX, pszName); |
| | | m_mapReport[id] = report; |
| | | Unlock(); |
| | | } |
| | | |
| | | void CHsmsPassive::linkEventReport(unsigned int RPTID, unsigned int CEID) |
| | | { |
| | | m_mapReportIdToCEID[RPTID] = CEID; |
| | | SERVO::CCollectionEvent* pEvent = getEvent(CEID); |
| | | SERVO::CReport* pReport = getReport(RPTID); |
| | | if (pEvent != nullptr) { |
| | | pEvent->setReport(pReport); |
| | | } |
| | | } |
| | | |
| | | void CHsmsPassive::unlinkEventReport(unsigned int CEID) |
| | | { |
| | | for (auto it = m_mapReportIdToCEID.begin(); it != m_mapReportIdToCEID.end(); ) { |
| | | if (it->second == CEID) { |
| | | m_mapReportIdToCEID.erase(it++); // 更新迭代器 |
| | | } |
| | | else { |
| | | ++it; |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | unsigned int CHsmsPassive::getCEID(int RPTID) |
| | | { |
| | | auto iter = m_mapReportIdToCEID.find(RPTID); |
| | | if (iter != m_mapReportIdToCEID.end()) return iter->second; |
| | | return 0; |
| | | } |
| | | |
| | | void CHsmsPassive::deleteReport(unsigned int RPTID) |
| | | { |
| | | for (auto it = m_mapValueIdToPRTID.begin(); it != m_mapValueIdToPRTID.end(); ) { |
| | | if (it->second == RPTID) { |
| | | m_mapValueIdToPRTID.erase(it++); // 更新迭代器 |
| | | } |
| | | else { |
| | | ++it; |
| | | } |
| | | SERVO::CCollectionEvent* pEvent = getEvent(CEID); |
| | | if (pEvent != nullptr) { |
| | | pEvent->setReport(nullptr); |
| | | } |
| | | } |
| | | |
| | | void CHsmsPassive::deleteAllReport() |
| | | SERVO::CReport* CHsmsPassive::defineReport(unsigned int RPTID, std::vector<unsigned int>& vids) |
| | | { |
| | | m_mapValueIdToPRTID.clear(); |
| | | } |
| | | // 添加定义report |
| | | SERVO::CReport* pReport = new SERVO::CReport(RPTID, vids); |
| | | for (auto vid : vids) { |
| | | SERVO::CVariable* pVariable = getVariable(vid); |
| | | if (pVariable != nullptr) { |
| | | pReport->addVariable(pVariable); |
| | | } |
| | | } |
| | | m_reports.push_back(pReport); |
| | | |
| | | void CHsmsPassive::defineReport(unsigned int VID, unsigned int RPTID) |
| | | { |
| | | m_mapValueIdToPRTID[VID] = RPTID; |
| | | return pReport; |
| | | } |
| | | |
| | | void CHsmsPassive::OnTimer(UINT nTimerid) |
| | |
| | | std::vector<SERVO::CReport*> reports; |
| | | int index; |
| | | CString strLine, strVariable; |
| | | CString strId, strName, strFormat, strRemark; |
| | | CString strId; |
| | | while (file.ReadString(strLine)) { |
| | | if (!std::regex_match((LPTSTR)(LPCTSTR)strLine, pattern)) { |
| | | continue; |
| | |
| | | return m_reports; |
| | | } |
| | | |
| | | SERVO::CReport* CHsmsPassive::getReport(int rptid) |
| | | { |
| | | for (auto item : m_reports) { |
| | | if (item->getReportId() == rptid) { |
| | | return item; |
| | | } |
| | | } |
| | | |
| | | return nullptr; |
| | | } |
| | | |
| | | bool CHsmsPassive::removeReport(int rptid) |
| | | { |
| | | for (auto iter = m_reports.begin(); iter != m_reports.end(); ++iter) { |
| | | if ((*iter)->getReportId() == rptid) { |
| | | delete (*iter); |
| | | m_reports.erase(iter); |
| | | return true; |
| | | } |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | |
| | | void CHsmsPassive::clearAllReport() |
| | | { |
| | | for (auto item : m_reports) { |
| | | delete item; |
| | | } |
| | | m_reports.clear(); |
| | | } |
| | | |
| | | int CHsmsPassive::loadCollectionEvents(const char* pszFilepath) |
| | | { |
| | | CStdioFile file; |
| | | if (!file.Open(pszFilepath, CFile::modeRead)) { |
| | | return -1; |
| | | } |
| | | |
| | | std::regex pattern("^\\d+,[^,]*,[^,]*,\\(\\d+(,\\d+)*\\).*"); // 匹配以数字+逗号开头的字符串 |
| | | std::vector<SERVO::CCollectionEvent*> events; |
| | | int index, last; |
| | | CString strLine, strRPTIDs; |
| | | CString strId, strName, strDescription; |
| | | while (file.ReadString(strLine)) { |
| | | if (!std::regex_match((LPTSTR)(LPCTSTR)strLine, pattern)) { |
| | | continue; |
| | | } |
| | | |
| | | last = 0; |
| | | index = strLine.Find(",", last); |
| | | if (index < 0) continue; |
| | | strId = strLine.Left(index); |
| | | last = index + 1; |
| | | |
| | | index = strLine.Find(",", last); |
| | | if (index < 0) continue; |
| | | strName = strLine.Mid(last, index - last); |
| | | last = index + 1; |
| | | |
| | | index = strLine.Find(",", last); |
| | | if (index < 0) continue; |
| | | strDescription = strLine.Mid(last, index - last); |
| | | strRPTIDs = strLine.Right(strLine.GetLength() - index - 1); |
| | | strRPTIDs.Delete(0); |
| | | strRPTIDs.Delete(strRPTIDs.GetLength() - 1); |
| | | auto prtids = parseVidList(strRPTIDs); |
| | | |
| | | SERVO::CCollectionEvent* pEvent = new SERVO::CCollectionEvent( |
| | | atoi(strId), (LPTSTR)(LPCTSTR)strName, (LPTSTR)(LPCTSTR)strDescription, prtids); |
| | | for (auto rptid : prtids) { |
| | | SERVO::CReport* pReport = getReport(rptid); |
| | | if (pReport != nullptr) { |
| | | pEvent->addReport(pReport); |
| | | } |
| | | } |
| | | events.push_back(pEvent); |
| | | } |
| | | |
| | | if (!events.empty()) { |
| | | clearAllCollectionEvent(); |
| | | for (auto item : events) { |
| | | m_collectionEvents.push_back(item); |
| | | } |
| | | } |
| | | |
| | | |
| | | file.Close(); |
| | | return 0; |
| | | } |
| | | |
| | | std::vector<SERVO::CCollectionEvent*>& CHsmsPassive::getCollectionEvents() |
| | | { |
| | | return m_collectionEvents; |
| | | } |
| | | |
| | | void CHsmsPassive::clearAllCollectionEvent() |
| | | { |
| | | for (auto item : m_collectionEvents) { |
| | | delete item; |
| | | } |
| | | m_collectionEvents.clear(); |
| | | } |
| | | |
| | | SERVO::CCollectionEvent* CHsmsPassive::getEvent(unsigned short CEID) |
| | | { |
| | | for (auto item : m_collectionEvents) { |
| | | if (item->getEventId() == CEID) { |
| | | return item; |
| | | } |
| | | } |
| | | |
| | | return nullptr; |
| | | } |
| | | |
| | | std::vector<unsigned int> CHsmsPassive::parseVidList(CString& strNums) |
| | |
| | | else if (nStream == 2 && pHeader->function == 41) { |
| | | replyCommand(pMessage); |
| | | } |
| | | else if (nStream == 2 && pHeader->function == 43) { |
| | | replyConfigureSpooling(pMessage); |
| | | } |
| | | else if (nStream == 5 && pHeader->function == 3) { |
| | | replyEanbleDisableAlarmReport(pMessage); |
| | | } |
| | |
| | | |
| | | clearAllVariabel(); |
| | | clearAllReport(); |
| | | clearAllCollectionEvent(); |
| | | |
| | | return 0; |
| | | } |
| | |
| | | ISECS2Item* pBody = pRecv->getBody(); |
| | | ISECS2Item* defineItem, *rptListItem, * vidListItem; |
| | | unsigned int dataId, rptid, vid; |
| | | |
| | | if (!pBody->getSubItemU4(0, dataId)) goto MYREPLY; |
| | | rptListItem = pBody->getSubItem(1); |
| | | if (rptListItem == nullptr) goto MYREPLY; |
| | | if (rptListItem->getSubItemSize() == 0) { |
| | | deleteAllReport(); |
| | | clearAllReport(); |
| | | goto MYREPLY; |
| | | } |
| | | |
| | | for (int i = 0; i < rptListItem->getSubItemSize(); i++) { |
| | | defineItem = rptListItem->getSubItem(i); |
| | | if (defineItem == nullptr) continue; |
| | | |
| | | std::vector<unsigned int> vids; |
| | | SERVO::CReport* pReport = nullptr; |
| | | vidListItem = defineItem->getSubItem(1); |
| | | if (defineItem->getSubItemU4(0, rptid) |
| | | && vidListItem != nullptr) { |
| | | int vidCount = vidListItem->getSubItemSize(); |
| | | if (vidCount == 0) { |
| | | deleteReport(rptid); |
| | | } |
| | | else { |
| | | for (int k = 0; k < vidCount; k++) { |
| | | if (vidListItem->getSubItemU4(k, vid)) { |
| | | defineReport(vid, rptid); |
| | | } |
| | | for (int k = 0; k < vidListItem->getSubItemSize(); k++) { |
| | | if (vidListItem->getSubItemU4(k, vid)) { |
| | | vids.push_back(vid); |
| | | } |
| | | } |
| | | } |
| | | |
| | | removeReport(rptid); |
| | | if (!vids.empty()) { |
| | | pReport = defineReport(rptid, vids); |
| | | } |
| | | |
| | | // 检验结果是否正确 |
| | | if (pReport != nullptr) { |
| | | auto variables = pReport->getVariables(); |
| | | for (auto item : variables) { |
| | | LOGE("=== prtid:%d, vid:%d", rptid, item->getVarialbleId()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | MYREPLY: |
| | | // 检验结果是否正确 |
| | | for (auto item : m_mapValueIdToPRTID) { |
| | | LOGE("=== vid:%d, prtid:%d", item.first, item.second); |
| | | } |
| | | |
| | | replyAck(2, 34, pRecv->getHeader()->systemBytes, BYTE(0), "DRACK"); |
| | | return 0; |
| | | } |
| | |
| | | else { |
| | | for (int k = 0; k < prtCount; k++) { |
| | | if (rptListItem->getSubItemU4(k, rptid)) { |
| | | linkEventReport(rptid, ceid); |
| | | linkEventReport(ceid, rptid); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | |
| | | // 检验结果是否正确 |
| | | for (auto item : m_mapReportIdToCEID) { |
| | | LOGE("=== prtid:%d, ceid:%d", item.first, item.second); |
| | | for (auto item : m_collectionEvents) { |
| | | LOGE("=== ceid:%d, prtid:%d", item->getEventId(), item->getPortID()); |
| | | } |
| | | |
| | | |
| | | MYREPLY: |
| | | replyAck(2, 36, pRecv->getHeader()->systemBytes, BYTE(0), "LRACK"); |
| | | return 0; |
| | |
| | | } |
| | | } |
| | | |
| | | MYREPLY: |
| | | replyAck(2, 42, pRecv->getHeader()->systemBytes, BYTE(0), "ERACK"); |
| | | return 0; |
| | | } |
| | | |
| | | // S2F43 |
| | | int CHsmsPassive::replyConfigureSpooling(IMessage* pRecv) |
| | | { |
| | | if (m_pPassive == NULL || STATE::SELECTED != m_pPassive->getState()) { |
| | | return ER_NOTSELECT; |
| | | } |
| | | ISECS2Item* pBody = pRecv->getBody(); |
| | | if (pBody == nullptr || pBody->getType() != SITYPE::L) ER_PARAM_ERROR; |
| | | |
| | | // 清空所有 |
| | | if (pBody->getSubItemSize() == 0) { |
| | | m_spoolingConfig.clear(); |
| | | goto MYREPLY; |
| | | } |
| | | |
| | | // 依次配置Stream |
| | | for (int i = 0; i < pBody->getSubItemSize(); i++) { |
| | | ISECS2Item* pStreamItem = pBody->getSubItem(i); |
| | | ASSERT(pStreamItem); |
| | | unsigned char STRID, FCNID; |
| | | pStreamItem->getSubItemU1(0, STRID); |
| | | ISECS2Item* pFcnItemList = pStreamItem->getSubItem(1); |
| | | if (pFcnItemList->getSubItemSize() == 0) { |
| | | m_spoolingConfig[STRID].clear(); |
| | | } |
| | | else { |
| | | for (int j = 0; j < pFcnItemList->getSubItemSize(); j++) { |
| | | pFcnItemList->getSubItemU1(j, FCNID); |
| | | m_spoolingConfig[STRID].insert(FCNID); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 打印验证结果 |
| | | for (auto s : m_spoolingConfig) { |
| | | LOGI("====> stream:%d", s.first); |
| | | for (auto f : s.second) { |
| | | LOGI("function:%d", f); |
| | | } |
| | | } |
| | | MYREPLY: |
| | | replyAck(2, 42, pRecv->getHeader()->systemBytes, BYTE(0), "ERACK"); |
| | | return 0; |
| | |
| | | } |
| | | |
| | | // S6F11 |
| | | int CHsmsPassive::requestEventReportSend(unsigned int DATAID, unsigned int RPTID, const std::vector<std::string>& values) |
| | | int CHsmsPassive::requestEventReportSend(unsigned int DATAID, unsigned int CEID, const std::vector<std::string>& values) |
| | | { |
| | | if (m_pPassive == NULL || STATE::SELECTED != m_pPassive->getState()) { |
| | | return ER_NOTSELECT; |
| | | } |
| | | |
| | | SERVO::CCollectionEvent* pEvent = getEvent(CEID); |
| | | if (pEvent == nullptr) { |
| | | return ER_NO_EVENT; |
| | | } |
| | | if (pEvent == nullptr) { |
| | | return ER_UNLINK_EVENT_REPORT; |
| | | } |
| | | |
| | | Lock(); |
| | |
| | | ASSERT(pMessage); |
| | | ISECS2Item* pItem = pMessage->getBody(); |
| | | pItem->addU4Item(DATAID, "DATAID"); |
| | | pItem->addU4Item(getCEID(RPTID), "CEID"); |
| | | pItem->addU4Item(CEID, "CEID"); |
| | | ISECS2Item* pItemList1 = pItem->addItem(); |
| | | ISECS2Item* pItemList2 = pItemList1->addItem(); |
| | | pItemList2->addU4Item(RPTID, "RPTID"); |
| | | pItemList2->addU4Item(pEvent->getPortID(), "RPTID"); |
| | | ISECS2Item* pItemList3 = pItemList2->addItem(); |
| | | for (auto item : values) { |
| | | pItemList3->addItem(item.c_str(), "V"); |