| | |
| | | else if (nStream == 10 && pHeader->function == 3) { |
| | | replyTerminalDisplay(pMessage); |
| | | } |
| | | else if (nStream == 14 && pHeader->function == 9) { |
| | | replyCreateObj(pMessage); |
| | | } |
| | | else if (nStream == 16 && pHeader->function == 15) { |
| | | replyPRJobMultiCreate(pMessage); |
| | | } |
| | |
| | | return 0; |
| | | } |
| | | |
| | | // S14F9 |
| | | int CHsmsPassive::replyCreateObj(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; |
| | | |
| | | |
| | | // 是否创建成功并准备回复报文 |
| | | bool bCreateOk = false; |
| | | IMessage* pReply = NULL; |
| | | HSMS_Create1Message(pReply, m_nSessionId, 14, 10, ++m_nSystemByte); |
| | | ASSERT(pReply); |
| | | |
| | | |
| | | |
| | | // 解释数据,得到ControlJob |
| | | ISECS2Item* pItemAttrs, * pItemAttr, *pItemAttrData; |
| | | const char* pszObjSpec, *pszObjType, *pszAttrId, *pszProcessJobId; |
| | | std::string strObjName, strObjId; |
| | | if (!pBody->getSubItemString(0, pszObjSpec)) return ER_PARAM_ERROR; |
| | | if (!pBody->getSubItemString(1, pszObjType)) return ER_PARAM_ERROR; |
| | | |
| | | pReply->getBody()->addItem(pszObjSpec, "OBJSPEC"); |
| | | ISECS2Item* pReplyItemAttrs = pReply->getBody()->addItem(); |
| | | ISECS2Item* pReplyItemAcks = pReply->getBody()->addItem(); |
| | | ISECS2Item* pReplyItemAck = pReplyItemAcks->addU1Item(0, "OBJACK"); |
| | | ISECS2Item* pReplyItemErrs = pReplyItemAcks->addItem(); |
| | | |
| | | // 当前只处理类各为ControlJob |
| | | if (_strcmpi(pszObjType, "ControlJob") == 0) { |
| | | |
| | | // 类id |
| | | std::regex re("^([^:]+):([^>]+)>"); |
| | | std::smatch match; |
| | | std::string strObjSpec(pszObjSpec); |
| | | if (!std::regex_search(strObjSpec, match, re)) { |
| | | ISECS2Item* pItemError = pReplyItemErrs->addItem(); |
| | | pItemError->addU4Item(2001, "ERRCODE"); |
| | | pItemError->addItem("参数或报文不正确", "ERRTEXT"); |
| | | goto MYREPLY; |
| | | } |
| | | |
| | | if (match[1].compare("ControlJob") != 0) { |
| | | ISECS2Item* pItemError = pReplyItemErrs->addItem(); |
| | | pItemError->addU4Item(2001, "ERRCODE"); |
| | | pItemError->addItem("不支持的OBJ", "ERRTEXT"); |
| | | goto MYREPLY; |
| | | } |
| | | strObjId = match[2]; |
| | | |
| | | // 创建类CControlJob |
| | | SERVO::CControlJob controlJob(strObjId); |
| | | |
| | | // 类属性 |
| | | pItemAttrs = pBody->getSubItem(2); |
| | | if (pItemAttrs == nullptr) return ER_PARAM_ERROR; |
| | | for (int i = 0; i < pItemAttrs->getSubItemSize(); i++) { |
| | | pItemAttr = pItemAttrs->getSubItem(i); |
| | | if (pItemAttr == nullptr) continue; |
| | | if (!pItemAttr->getSubItemString(0, pszAttrId)) continue; |
| | | if (_strcmpi(pszAttrId, CJ_ATTR_PRIORITY) == 0) { |
| | | uint8_t priority; |
| | | if (pItemAttr->getSubItemU1(1, priority)) { |
| | | controlJob.setPriority(priority); |
| | | } |
| | | } |
| | | else if (_strcmpi(pszAttrId, CJ_ATTR_PRJOBLIST) == 0) { |
| | | pItemAttrData = pItemAttr->getSubItem(1); |
| | | if (pItemAttrData != nullptr && pItemAttrData->getType() == SITYPE::L) { |
| | | for (int i = 0; i < pItemAttrData->getSubItemSize(); i++) { |
| | | if (pItemAttrData->getSubItemString(i, pszProcessJobId)) { |
| | | std::string strProcessJobId(pszProcessJobId); |
| | | controlJob.addPJ(strProcessJobId); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | ASSERT(m_listener.onControlJobCreate != nullptr); |
| | | int nRet = m_listener.onControlJobCreate(this, controlJob); |
| | | bCreateOk = nRet == 0; |
| | | |
| | | // 添加新建类的各种属性到回复报文中 |
| | | if(bCreateOk) { |
| | | { |
| | | ISECS2Item* pReplyItemAttr = pReplyItemAttrs->addItem(); |
| | | pReplyItemAttr->addItem(CJ_ATTR_PRIORITY, "ATTRID"); |
| | | pReplyItemAttr->addU1Item(controlJob.priority(), "ATTRDATA"); |
| | | } |
| | | |
| | | { |
| | | ISECS2Item* pReplyItemAttr = pReplyItemAttrs->addItem(); |
| | | pReplyItemAttr->addItem(CJ_ATTR_PRJOBLIST, "ATTRID"); |
| | | ISECS2Item* pItemPjs = pReplyItemAttr->addItem(); |
| | | auto pjIds = controlJob.pjIds(); |
| | | for (auto id : pjIds) { |
| | | pItemPjs->addItem(id.c_str(), "PRJOBID"); |
| | | } |
| | | } |
| | | } |
| | | else { |
| | | auto issues = controlJob.issues(); |
| | | for (auto i : issues) { |
| | | ISECS2Item* pItemError = pReplyItemErrs->addItem(); |
| | | pItemError->addU4Item(i.code, "ERRCODE"); |
| | | pItemError->addItem(i.text.c_str(), "ERRTEXT"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | else { |
| | | ISECS2Item* pItemError = pReplyItemErrs->addItem(); |
| | | pItemError->addU4Item(2001, "ERRCODE"); |
| | | pItemError->addItem("不支持的OBJ", "ERRTEXT"); |
| | | } |
| | | |
| | | |
| | | // 完善报文并回复 |
| | | MYREPLY: |
| | | pReplyItemAck->setU1(bCreateOk ? 0 : 1, "OBJACK"); |
| | | m_pPassive->sendMessage(pReply); |
| | | LOGI("<HSMS>[SECS Msg SEND]S14F10 (SysByte=%u)", pReply->getHeader()->systemBytes); |
| | | HSMS_Destroy1Message(pReply); |
| | | |
| | | |
| | | return 0; |
| | | } |
| | | |
| | | // S16F15 |
| | | int CHsmsPassive::replyPRJobMultiCreate(IMessage* pRecv) |
| | | { |
| | |
| | | ISECS2Item* pItemErrors = pMessage->getBody()->addItem(); |
| | | bool bHasError = false; |
| | | for (auto p : pjs) { |
| | | if (p->issue().empty()) { |
| | | if (p->issues().empty()) { |
| | | pItemPrjobIds->addItem(p->id().c_str(), "PRJOBID"); |
| | | } |
| | | else { |
| | |
| | | pItemErrors->addBoolItem(false, "ACKA"); |
| | | ISECS2Item* pItemErrors2 = pItemErrors->addItem(); |
| | | for (auto p : pjs) { |
| | | if (!p->issue().empty()) { |
| | | if (!p->issues().empty()) { |
| | | ISECS2Item* pItemErr = pItemErrors2->addItem(); |
| | | pItemErr->addU4Item(p->issue()[0].code, "ERRCODE"); |
| | | pItemErr->addItem(("<" + p->id() + ">" + p->issue()[0].text).c_str(), "ERRTEXT"); |
| | | pItemErr->addU4Item(p->issues()[0].code, "ERRCODE"); |
| | | pItemErr->addItem(("<" + p->id() + ">" + p->issues()[0].text).c_str(), "ERRTEXT"); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | // 释放有问题(未添加到master)的内存 |
| | | for (auto p : pjs) { |
| | | if(!p->issue().empty()) delete p; |
| | | if(!p->issues().empty()) delete p; |
| | | } |
| | | pjs.clear(); |
| | | |
| | |
| | | return requestEventReportSend("PJ_Queued"); |
| | | } |
| | | |
| | | int CHsmsPassive::requestEventReportSend_PJ_Start() |
| | | { |
| | | return requestEventReportSend("PJ_Start"); |
| | | } |
| | | |
| | | int CHsmsPassive::requestEventReportSend_PJ_End() |
| | | { |
| | | return requestEventReportSend("PJ_End"); |
| | | } |
| | | |
| | | |
| | | |
| | | |