| | |
| | | #include "stdafx.h" |
| | | #include "stdafx.h" |
| | | #include "Model.h" |
| | | #include "Log.h" |
| | | #include "Common.h" |
| | |
| | | #include "AlarmManager.h" |
| | | #include "CGlassPool.h" |
| | | #include "TransferManager.h" |
| | | #include "RecipeManager.h" |
| | | #include "GlassLogDb.h" |
| | | #include "CParam.h" |
| | | #include "CJobDataS.h" |
| | | #include <algorithm> |
| | | #include <iomanip> |
| | | #include <sstream> |
| | | #include <array> |
| | | #include <map> |
| | | |
| | | |
| | | CModel::CModel() |
| | |
| | | { |
| | | } |
| | | |
| | | void CModel::refreshDerivedSVs() |
| | | { |
| | | // CJobSpace: how many ControlJobs can be created (current implementation supports 0/1). |
| | | m_hsmsPassive.setVariableValue("CJobSpace", (__int64)(m_master.canCreateControlJob() ? 1 : 0)); |
| | | |
| | | // PJobSpace: how many ProcessJobs can be created (current implementation supports 0/1). |
| | | m_hsmsPassive.setVariableValue("PJobSpace", (__int64)(m_master.isProcessJobsEmpty() ? 1 : 0)); |
| | | } |
| | | |
| | | void CModel::notifyControlJobChanged() |
| | | { |
| | | // 1) 刷新派生 SV |
| | | refreshDerivedSVs(); |
| | | // 2) 通知上层 UI(RX_CODE_CONTROLJOB_CHANGED) |
| | | notify(RX_CODE_CONTROLJOB_CHANGED); |
| | | } |
| | | |
| | | bool CModel::raiseSoftAlarm(int alarmId, |
| | | const std::string& desc, |
| | | int level /*= -1*/, |
| | | int deviceId /*= 0*/, |
| | | int unitId /*= 0*/, |
| | | const char* deviceName /*= "Software"*/, |
| | | const char* unitName /*= "App"*/) |
| | | { |
| | | AlarmManager& alarmManager = AlarmManager::getInstance(); |
| | | const AlarmInfo* info = alarmManager.getAlarmInfoByID(alarmId); |
| | | |
| | | int severity = level; |
| | | if (severity < 0 && info != nullptr) severity = info->nAlarmLevel; |
| | | if (severity < 0) severity = 0; |
| | | |
| | | std::string descText = desc; |
| | | if (descText.empty() && info != nullptr) { |
| | | descText = !info->strDescription.empty() ? info->strDescription : info->strAlarmText; |
| | | } |
| | | if (descText.empty()) { |
| | | descText = CToolUnits::formatString("Alarm %d", alarmId); |
| | | } |
| | | |
| | | AlarmData alarmData; |
| | | alarmData.nId = alarmId; |
| | | alarmData.nSeverityLevel = severity; |
| | | alarmData.nDeviceId = deviceId; |
| | | alarmData.nUnitId = unitId; |
| | | alarmData.strDeviceName = deviceName; |
| | | alarmData.strUnitName = unitName; |
| | | // 若未显式提供设备/单元名称,尝试通过 deviceId/unitId 解析(soft alarm 默认均为 0) |
| | | if (alarmData.strDeviceName.empty()) { |
| | | alarmData.strDeviceName = alarmManager.getDeviceNameById(deviceId); |
| | | } |
| | | if (alarmData.strUnitName.empty()) { |
| | | alarmData.strUnitName = alarmManager.getUnitNameById(deviceId, unitId); |
| | | } |
| | | alarmData.strStartTime = CToolUnits::timeToString2(CToolUnits::getTimestamp()); |
| | | alarmData.strEndTime = ""; |
| | | alarmData.strDescription = descText; |
| | | |
| | | int nAlarmEventId = 0; |
| | | bool result = alarmManager.addAlarm(alarmData, nAlarmEventId); |
| | | if (result) { |
| | | notify(RX_CODE_ALARM_SET); |
| | | if (m_master.isAlarmReportEnable()) { |
| | | m_hsmsPassive.requestAlarmReport(1, alarmId, descText.c_str()); |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | void CModel::clearSoftAlarm(int alarmId, int deviceId, int unitId) |
| | | { |
| | | AlarmManager& alarmManager = AlarmManager::getInstance(); |
| | | alarmManager.clearAlarmByAttributes(alarmId, deviceId, unitId, CToolUnits::getCurrentTimeString()); |
| | | notify(RX_CODE_ALARM_CLEAR); |
| | | if (m_master.isAlarmReportEnable()) { |
| | | const AlarmInfo* info = alarmManager.getAlarmInfoByID(alarmId); |
| | | std::string descText; |
| | | if (info != nullptr) descText = info->strAlarmText; |
| | | m_hsmsPassive.requestAlarmReport(0, alarmId, descText.c_str()); |
| | | } |
| | | } |
| | | |
| | | void CModel::setControlState(ControlState newState) |
| | | { |
| | | const auto prev = m_currentControlState; |
| | | if (newState != m_currentControlState) { |
| | | m_currentControlState = newState; |
| | | // S6F11 (CEID=600): ControlStateChanged |
| | | m_hsmsPassive.withVariableLock([&] { |
| | | m_hsmsPassive.setVariableValue("PreviousControlState", (__int64)static_cast<uint8_t>(prev)); |
| | | m_hsmsPassive.setVariableValue("CurrentControlState", (__int64)static_cast<uint8_t>(m_currentControlState)); |
| | | m_hsmsPassive.requestEventReportSend("ControlStateChanged"); |
| | | }); |
| | | notifyInt(RX_CODE_CONTROL_STATE_CHANGED, static_cast<int>(m_currentControlState)); |
| | | } else { |
| | | // Keep SV in sync even if unchanged/load-time refresh. |
| | | m_hsmsPassive.setVariableValue("CurrentControlState", (__int64)static_cast<uint8_t>(m_currentControlState)); |
| | | } |
| | | } |
| | | |
| | | IObservable* CModel::getObservable() |
| | | { |
| | | if (m_pObservable == nullptr) { |
| | | m_pObservable = RX_AllocaObservable([&](IObservableEmitter* e) -> void { |
| | | m_pObservableEmitter = e; // 保存发射器 |
| | | m_pObservableEmitter = e; // 保存发射器 |
| | | }); |
| | | } |
| | | |
| | |
| | | for (int i = 0; i < 4; i++) { |
| | | m_configuration.getPortParms(i, portEnable, portType, portMode, |
| | | cassetteType, transferMode, autoChangeEnable); |
| | | m_master.setPortType(i, portEnable, portType, portMode, cassetteType, |
| | | m_master.setPortTypeEx(i, portEnable, portType, portMode, cassetteType, |
| | | transferMode, autoChangeEnable); |
| | | |
| | | int seed = m_configuration.getPortCassetteSnSeed(i + 1); |
| | | m_master.setPortCassetteSnSeed(i + 1, seed); |
| | | } |
| | | } |
| | | |
| | | void CModel::setPortType(unsigned int index, SERVO::PortType type) |
| | | { |
| | | m_master.setPortType(index, (int)type); |
| | | m_configuration.setPortType(index, (int)type); |
| | | } |
| | | |
| | | void CModel::setPortCassetteType(unsigned int index, SERVO::CassetteType type) |
| | | { |
| | | m_master.setPortCassetteType(index, type); |
| | | m_configuration.setPortCassetteType(index, (int)type); |
| | | } |
| | | |
| | | void CModel::setPortEnable(unsigned int index, BOOL bEnable) |
| | | { |
| | | m_master.setPortEnable(index, bEnable); |
| | | m_configuration.setPortEnable(index, bEnable); |
| | | } |
| | | |
| | | int CModel::init() |
| | | { |
| | | const ULONGLONG boot_model_begin = GetTickCount64(); |
| | | CString strIniFile; |
| | | CString strUnitId; |
| | | strIniFile.Format(_T("%s\\ServoConfiguration.ini"), (LPTSTR)(LPCTSTR)m_strWorkDir); |
| | | m_configuration.setFilepath((LPTSTR)(LPCTSTR)strIniFile); |
| | | m_configuration.getUnitId(strUnitId); |
| | | |
| | | // 机器型号和软件版本号应从配置中读取,当前先固定值 |
| | | // 机器型号和软件版本号应从配置中读取,当前先固定值 |
| | | CString strModeType = _T("Master"); |
| | | CString strSoftRev = _T("1.0.2"); |
| | | |
| | | |
| | | // CGlassPool |
| | | m_glassPool.initPool(); |
| | | |
| | | // 将 Model 上下文传递给 Master,便于 Master 触发软件级报警等跨层操作 |
| | | m_master.setModelCtx(this); |
| | | |
| | | |
| | | // Log |
| | |
| | | ::CreateDirectory(strLogDir, NULL); |
| | | CLog::GetLog()->SetOnLogCallback([&](int level, const char* pszMessage) -> void { |
| | | notifyTextAndInt(RX_CODE_LOG, pszMessage, level); |
| | | }); |
| | | }); |
| | | CLog::GetLog()->SetAutoAppendTimeString(TRUE); |
| | | CLog::GetLog()->SetOutputTarget(OT_FILE); |
| | | CLog::GetLog()->SetLogsDir(strLogDir); |
| | | CLog::GetLog()->SetEquipmentId((LPTSTR)(LPCTSTR)strUnitId); |
| | | LOGI("\r\n\r\n~~~ Prog Start! ~~~"); |
| | | LOGI("[BOOT][MODEL] init begin"); |
| | | |
| | | |
| | | SECSListener listener; |
| | | listener.onEQOffLine = [&](void* pFrom) -> void { |
| | | LOGI("远程请求OffLine"); |
| | | listener.onEQOffLine = [this](void* pFrom) -> void { |
| | | LOGI("远程请求OffLine"); |
| | | (void)pFrom; |
| | | setControlState(ControlState::OfflineHost); |
| | | }; |
| | | listener.onEQOnLine = [&](void* pFrom) -> void { |
| | | LOGI("远程请求OnLine"); |
| | | listener.onEQOnLine = [this](void* pFrom) -> void { |
| | | LOGI("远程请求OnLine"); |
| | | (void)pFrom; |
| | | // Customer flow: S1F17 RequestOnline defaults to OnlineRemote. |
| | | setControlState(ControlState::OnlineRemote); |
| | | }; |
| | | listener.onCommand = [&](void* pFrom, const char* pszName, std::vector<CommandParameter>& params) -> void { |
| | | listener.onCommand = [this](void* pFrom, const char* pszName, std::vector<CommandParameter>& params) -> void { |
| | | LOGI("onCommand:%s", pszName); |
| | | (void)pFrom; |
| | | for (auto& item : params) { |
| | | LOGI("param:%s,%s", item.szName, item.szValue); |
| | | } |
| | | }; |
| | | listener.onEQConstantRequest = [&](void* pFrom, std::vector<EQConstant>& eqcs) -> void { |
| | | // 在此填充常量值,目前仅是加1后返回 |
| | | for (auto& item : eqcs) { |
| | | sprintf_s(item.szValue, 256, "Test%d", item.id+1); |
| | | |
| | | if (pszName == nullptr) return; |
| | | // S2F41 GoLocal / GoRemote (RCMD) |
| | | if (_strcmpi(pszName, "GoLocal") == 0 || _strcmpi(pszName, "LOCAL") == 0 || _strcmpi(pszName, "GoLOCAL") == 0) { |
| | | setControlState(ControlState::OnlineLocal); |
| | | } |
| | | }; |
| | | listener.onEQConstantSend = [&](void* pFrom, std::vector<EQConstant>& eqcs) -> void { |
| | | // 在此保存和设置机器常量值 |
| | | for (auto& item : eqcs) { |
| | | LOGI("onEQConstantRequest: %d, %s", item.id, item.szValue); |
| | | else if (_strcmpi(pszName, "GoRemote") == 0 || _strcmpi(pszName, "REMOTE") == 0 || _strcmpi(pszName, "GoREMOTE") == 0) { |
| | | setControlState(ControlState::OnlineRemote); |
| | | } |
| | | }; |
| | | listener.onDatetimeSync = [&](void* pFrom, SYSTEMTIME& time) -> void { |
| | |
| | | m_master.enableEventReport(bEnable); |
| | | } |
| | | }; |
| | | listener.onDeletePPID = [&](void* pFrom, const std::vector<std::string>& ppids) -> bool { |
| | | (void)pFrom; |
| | | bool allOk = true; |
| | | std::vector<std::string> targets = ppids; |
| | | if (targets.empty()) { |
| | | // L:0 => delete all PPIDs |
| | | targets = RecipeManager::getInstance().getAllPPID(); |
| | | } |
| | | for (auto& ppid : targets) { |
| | | bool ok = RecipeManager::getInstance().deleteRecipeByPPID(ppid); |
| | | allOk = allOk && ok; |
| | | LOGI("<CModel>DeletePPID: %s, result=%s", ppid.c_str(), ok ? "OK" : "FAIL"); |
| | | } |
| | | return allOk; |
| | | }; |
| | | listener.onEnableDisableAlarmReport = [&](void* pFrom, bool bEnable, unsigned int id) -> void { |
| | | LOGI("onEnableDisableAlarmReport bEnable:%s, id:%d", bEnable ? _T("YES") : _T("NO"), id); |
| | | if (id == 0) { |
| | | m_master.enableAlarmReport(bEnable); |
| | | } |
| | | }; |
| | | listener.onQueryPPIDList = [&](void* pFrom) ->std::vector<std::string> { |
| | | std::vector<std::string> ppids; |
| | | auto temp = RecipeManager::getInstance().getAllPPID(); |
| | | for (auto item : temp) { |
| | | if (item.length() > PPID_NAME_MAX) { |
| | | ppids.push_back(item.substr(0, PPID_NAME_MAX)); |
| | | } |
| | | else { |
| | | ppids.push_back(item); |
| | | } |
| | | } |
| | | return ppids; |
| | | }; |
| | | listener.onCarrierAction = [&](void* pFrom, |
| | | unsigned int DATAID, |
| | | const char* pszCarrierAction, |
| | | const char* pszCarrierId, |
| | | unsigned char PTN, |
| | | std::string& strErrorTxt) -> unsigned int { |
| | | if (PTN < 1 || 4 < PTN) { |
| | | strErrorTxt = "invalid data or argument"; |
| | | return CAACK_3; |
| | | } |
| | | |
| | | const unsigned int portIndex = PTN - 1; |
| | | SERVO::CLoadPort* pLoadPort = (SERVO::CLoadPort*)m_master.getEquipment(EQ_ID_LOADPORT1 + portIndex); |
| | | LOGI("<Model>onCarrierAction %d, %s, %d, %d", DATAID, pszCarrierAction, pszCarrierId, PTN); |
| | | |
| | | if (_strcmpi(pszCarrierAction, "ProceedWithCarrier") == 0) { |
| | | // 文档流程:ProceedWithCarrier 之后设备进入 Check SlotMap(WFH), |
| | | // 真正的“开始”由 ProceedWithSlotMap 决策触发。 |
| | | // 仅当未开启 CompareMapsBeforeProceeding 时,才沿用旧逻辑直接 Start。 |
| | | LOGI("<CModel>ProceedWithCarrier"); |
| | | if (m_master.getControlJob() == nullptr || m_master.isProcessJobsEmpty()) { |
| | | strErrorTxt = "rejected - ControlJob/ProcessJob not ready"; |
| | | LOGW("<CModel>ProceedWithCarrier rejected: no CJ/PJ, port=%d", portIndex + 1); |
| | | return CAACK_5; |
| | | } |
| | | if (pLoadPort == nullptr || !pLoadPort->isCompareMapsBeforeProceeding()) { |
| | | m_master.proceedWithCarrier(portIndex); |
| | | } |
| | | return CAACK_0; |
| | | } |
| | | else if (_strcmpi(pszCarrierAction, "ProceedWithSlotMap") == 0) { |
| | | // TODO(Host协商): |
| | | // 文档中 ProceedWithSlotMap 可能会携带 LotID / PanelIDList / SlotMap 等数据(最多13片)用于格式校验与绑定。 |
| | | // 当前 S3F17 解析结构仅支持 {DATAID, CarrierAction, CarrierID, PTN},尚未实现上述扩展字段的解析/校验。 |
| | | // 未来若客户确认 SECS-II 结构,需要在 CHsmsPassive::replyCarrierAction() 扩展解析并在此处落库/校验。 |
| | | // 仅在 CompareMapsBeforeProceeding 启用(Host 模式)下允许此动作 |
| | | LOGI("<CModel>ProceedWithSlotMap"); |
| | | if (pLoadPort == nullptr || !pLoadPort->isCompareMapsBeforeProceeding()) { |
| | | strErrorTxt = "rejected - SlotMap check disabled"; |
| | | return CAACK_5; |
| | | } |
| | | |
| | | const short scanMap = pLoadPort->getScanCassetteMap(); |
| | | const short downloadMap = pLoadPort->getDownloadCassetteMap(); |
| | | m_hsmsPassive.withVariableLock([&] { |
| | | m_hsmsPassive.setVariableValue("SlotMapScan", scanMap); |
| | | m_hsmsPassive.setVariableValue("SlotMapDownload", downloadMap); |
| | | if (scanMap != downloadMap) { |
| | | m_hsmsPassive.requestEventReportSend_SlotMapVerificationNG(); |
| | | m_hsmsPassive.requestEventReportSend("SlotMapMismatch"); |
| | | } |
| | | else { |
| | | m_hsmsPassive.requestEventReportSend_SlotMapVerificationOK(); |
| | | } |
| | | }); |
| | | |
| | | if (scanMap != downloadMap) { |
| | | strErrorTxt = "rejected - SlotMap mismatch"; |
| | | return CAACK_5; |
| | | } |
| | | |
| | | // Host 确认 SlotMap 后再开始加工/流程 |
| | | m_master.proceedWithCarrier(portIndex); |
| | | return CAACK_0; |
| | | } |
| | | else if (_strcmpi(pszCarrierAction, "CarrierRelease") == 0) { |
| | | LOGI("<CModel>CarrierRelease"); |
| | | m_master.carrierRelease(portIndex); |
| | | return CAACK_0; |
| | | } |
| | | |
| | | strErrorTxt = "rejected - invalid state"; |
| | | return CAACK_5; |
| | | }; |
| | | listener.onPRJobMultiCreate = [&](void* pFrom, std::vector<SERVO::CProcessJob*>& pjs) -> int { |
| | | for (auto p : pjs) { |
| | | LOGI("<Model>onPRJobMultiCreate %s %s", p->id().c_str(), p->recipeSpec().c_str()); |
| | | } |
| | | |
| | | auto rejectAll = [&](uint32_t code, const std::string& msg) -> int { |
| | | LOGW("<Model>onPRJobMultiCreate rejected: %s", msg.c_str()); |
| | | for (auto p : pjs) { |
| | | if (p != nullptr) p->addIssue(code, msg); |
| | | } |
| | | return -1; |
| | | }; |
| | | |
| | | // 单 PJ 模式:只接受 1 条且当前无在制 PJ |
| | | if (pjs.size() != 1) { |
| | | return rejectAll(1200, "Only 1 ProcessJob supported (single-PJ mode)"); |
| | | } |
| | | if (!m_master.isProcessJobsEmpty()) { |
| | | return rejectAll(1201, "ProcessJob exists, cannot create new in single-PJ mode"); |
| | | } |
| | | |
| | | int nRet = m_master.setProcessJobs(pjs); |
| | | auto processJobs = m_master.getProcessJobs(); |
| | | std::vector<SERVO::CVariable> vars; |
| | | for (auto pj : processJobs) { |
| | | SERVO::CVariable var("", "PRJOBID", "A50", "PRJOBID"); |
| | | var.setValue(pj->id().c_str()); |
| | | vars.push_back(var); |
| | | } |
| | | |
| | | m_hsmsPassive.withVariableLock([&] { |
| | | m_hsmsPassive.setVariableValue("PJQueued", vars); |
| | | m_hsmsPassive.requestEventReportSend_PJ_Queued(); |
| | | }); |
| | | return nRet; |
| | | }; |
| | | listener.onControlJobCreate = [&](void* pFrom, SERVO::CControlJob& controlJob) -> int { |
| | | LOGI("<Model>onControlJobCreate %s %d", controlJob.id().c_str(), controlJob.priority()); |
| | | int nRet = m_master.setControlJob(controlJob); |
| | | return nRet; |
| | | }; |
| | | m_hsmsPassive.setListener(listener); |
| | | m_hsmsPassive.setEquipmentModelType((LPTSTR)(LPCTSTR)strModeType); |
| | |
| | | CString strVarialbleFile; |
| | | strVarialbleFile.Format(_T("%s\\VariableList.txt"), (LPTSTR)(LPCTSTR)m_strWorkDir); |
| | | m_hsmsPassive.loadVarialbles((LPTSTR)(LPCTSTR)strVarialbleFile); |
| | | strVarialbleFile.Format(_T("%s\\DataVariableList.txt"), (LPTSTR)(LPCTSTR)m_strWorkDir); |
| | | m_hsmsPassive.loadDataVarialbles((LPTSTR)(LPCTSTR)strVarialbleFile); |
| | | strVarialbleFile.Format(_T("%s\\EquipmentConstantList.txt"), (LPTSTR)(LPCTSTR)m_strWorkDir); |
| | | m_hsmsPassive.loadEquipmentConstants((LPTSTR)(LPCTSTR)strVarialbleFile); |
| | | setControlState(m_currentControlState); |
| | | refreshDerivedSVs(); |
| | | m_hsmsPassive.init(this, "APP", 7000); |
| | | strVarialbleFile.Format(_T("%s\\ReportList.txt"), (LPTSTR)(LPCTSTR)m_strWorkDir); |
| | | m_hsmsPassive.loadReports((LPTSTR)(LPCTSTR)strVarialbleFile); |
| | | m_hsmsPassive.init(this, "APP", 7000); |
| | | strVarialbleFile.Format(_T("%s\\CollectionEventList.txt"), (LPTSTR)(LPCTSTR)m_strWorkDir); |
| | | m_hsmsPassive.loadCollectionEvents((LPTSTR)(LPCTSTR)strVarialbleFile); |
| | | { |
| | | auto events = m_hsmsPassive.getCollectionEvents(); |
| | | std::vector<unsigned int> ceids; |
| | | ceids.reserve(events.size()); |
| | | for (auto e : events) { |
| | | if (e != nullptr) ceids.push_back(e->getEventId()); |
| | | } |
| | | m_master.setAllowedCeids(ceids); |
| | | } |
| | | strVarialbleFile.Format(_T("%s\\HsmsPassive.cache"), (LPTSTR)(LPCTSTR)m_strWorkDir); |
| | | m_hsmsPassive.loadCacheFromFile(strVarialbleFile); |
| | | LOGI("[BOOT][MODEL] HSMS config loaded, cost=%llu ms", |
| | | (unsigned long long)(GetTickCount64() - boot_model_begin)); |
| | | |
| | | |
| | | SERVO::MasterListener masterListener; |
| | | auto formatParamValue = [](const CParam& p) { |
| | | std::ostringstream oss; |
| | | oss.setf(std::ios::fixed); |
| | | oss << std::setprecision(4) << p.getDoubleValue(); |
| | | return oss.str(); |
| | | }; |
| | | masterListener.onMasterStateChanged = [&](void* pMaster, SERVO::MASTERSTATE state) -> void { |
| | | LOGI("<CModel>Master state changed(%d)", (int)state); |
| | | notify(RX_CODE_MASTER_STATE_CHANGED); |
| | | }; |
| | | masterListener.onControlJobChanged = [this](void* pMaster) { |
| | | (void)pMaster; |
| | | this->notifyControlJobChanged(); |
| | | }; |
| | | masterListener.onEqAlive = [&](void* pMaster, SERVO::CEquipment* pEquipment, BOOL bAlive) -> void { |
| | | LOGI("<CModel>Equipment onAlive:%s(%s).", pEquipment->getName().c_str(), |
| | | bAlive ? _T("ON") : _T("OFF")); |
| | |
| | | alarmData.strUnitName = alarmManager.getUnitNameById(alarmData.nDeviceId, alarmData.nUnitId); |
| | | alarmData.strStartTime = CToolUnits::timeToString2(CToolUnits::getTimestamp()); |
| | | alarmData.strEndTime = ""; |
| | | |
| | | alarmData.strDescription = ""; |
| | | |
| | | const AlarmInfo* alarmInfo = alarmManager.getAlarmInfoByID(alarmData.nId); |
| | | alarmData.strDescription = alarmInfo != nullptr ? alarmInfo->strAlarmText : ""; |
| | | if (alarmInfo != nullptr) { |
| | | if (alarmInfo->strDescription.empty()) { |
| | | alarmData.strDescription = alarmInfo->strAlarmText; |
| | | } |
| | | else { |
| | | alarmData.strDescription = alarmInfo->strAlarmText + "," + alarmInfo->strDescription + "."; |
| | | } |
| | | } |
| | | |
| | | |
| | | int nAlarmEventId = 0; |
| | | bool result = alarmManager.addAlarm(alarmData, nAlarmEventId); |
| | |
| | | }; |
| | | masterListener.onEqVcrEventReport = [&](void* pMaster, SERVO::CEquipment* pEquipment, SERVO::CVcrEventReport* pReport) { |
| | | LOGE("<CModel>onEqVcrEventReport."); |
| | | if (pReport != nullptr) { |
| | | m_hsmsPassive.withVariableLock([&] { |
| | | m_hsmsPassive.setVariableValue("VCRPanelID", pReport->getGlassId().c_str()); |
| | | int nRet = m_hsmsPassive.requestEventReportSend_OCR_PanelID_Read(pReport->getVcrResult()); |
| | | if (nRet != ER_NOERROR) { |
| | | LOGE("<CModel>requestEventReportSend_OCR_PanelID_Read failed, ret=%d", nRet); |
| | | } |
| | | }); |
| | | } |
| | | }; |
| | | masterListener.onEqDataChanged = [&](void* pMaster, SERVO::CEquipment* pEquipment, int code) { |
| | | LOGE("<CModel>onEqDataChanged."); |
| | |
| | | }; |
| | | masterListener.onRobotTaskEvent = [&](void* pMaster, SERVO::CRobotTask* pTask, int code) { |
| | | if (pTask == nullptr) { |
| | | LOGE("<CModel>onRobotTaskEvent: 空任务指针,忽略事件 code=%d", code); |
| | | LOGE("<CModel>onRobotTaskEvent: 空任务指针,忽略事件 code=%d", code); |
| | | return; |
| | | } |
| | | |
| | | // 任务描述与 ID 用于日志 |
| | | // 任务描述与 ID 用于日志 |
| | | SERVO::CGlass* pGlass = (SERVO::CGlass*)pTask->getContext(); |
| | | const std::string& strDesc = pTask->getDescription(); |
| | | std::string strClassID; |
| | |
| | | } |
| | | } |
| | | |
| | | // 日志输出与状态处理 |
| | | // 日志输出与状态处理 |
| | | switch (code) { |
| | | case ROBOT_EVENT_CREATE: |
| | | LOGI("<CModel>onRobotTaskEvent: 新任务创建(%s, ClassID=%s).", strDesc.c_str(), strClassID.c_str()); |
| | | LOGI("<CModel>onRobotTaskEvent: 新任务创建(%s, ClassID=%s).", strDesc.c_str(), strClassID.c_str()); |
| | | break; |
| | | case ROBOT_EVENT_FINISH: |
| | | LOGI("<CModel>onRobotTaskEvent: 任务完成(%s, ClassID=%s).", strDesc.c_str(), strClassID.c_str()); |
| | | LOGI("<CModel>onRobotTaskEvent: 任务完成(%s, ClassID=%s).", strDesc.c_str(), strClassID.c_str()); |
| | | break; |
| | | case ROBOT_EVENT_ERROR: |
| | | LOGE("<CModel>onRobotTaskEvent: 任务错误(%s, ClassID=%s).", strDesc.c_str(), strClassID.c_str()); |
| | | LOGE("<CModel>onRobotTaskEvent: 任务错误(%s, ClassID=%s).", strDesc.c_str(), strClassID.c_str()); |
| | | break; |
| | | case ROBOT_EVENT_ABORT: |
| | | LOGE("<CModel>onRobotTaskEvent: 任务停止(%s, ClassID=%s).", strDesc.c_str(), strClassID.c_str()); |
| | | LOGE("<CModel>onRobotTaskEvent: 任务停止(%s, ClassID=%s).", strDesc.c_str(), strClassID.c_str()); |
| | | break; |
| | | case ROBOT_EVENT_RESTORE: |
| | | LOGE("<CModel>onRobotTaskEvent: 任务回撤(%s, ClassID=%s).", strDesc.c_str(), strClassID.c_str()); |
| | | LOGE("<CModel>onRobotTaskEvent: 任务回撤(%s, ClassID=%s).", strDesc.c_str(), strClassID.c_str()); |
| | | break; |
| | | default: |
| | | LOGE("<CModel>onRobotTaskEvent: 未知事件 code=%d, 任务=%s", code, strDesc.c_str()); |
| | | LOGE("<CModel>onRobotTaskEvent: 未知事件 code=%d, 任务=%s", code, strDesc.c_str()); |
| | | break; |
| | | } |
| | | |
| | | // 安全格式化时间 |
| | | // 安全格式化时间 |
| | | auto format_time = [](time_t t) -> std::string { |
| | | if (t <= 0 || t == _I64_MIN || t == _I64_MAX) { |
| | | return ""; |
| | | } |
| | | |
| | | // 使用 localtime_s 确保线程安全 |
| | | // 使用 localtime_s 确保线程安全 |
| | | tm tmBuf{}; |
| | | errno_t err = localtime_s(&tmBuf, &t); |
| | | if (err != 0 || tmBuf.tm_mon < 0 || tmBuf.tm_mon > 11) { |
| | | return ""; |
| | | } |
| | | |
| | | // 格式化时间字符串 |
| | | // 格式化时间字符串 |
| | | char buf[64] = {}; |
| | | strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &tmBuf); |
| | | return std::string(buf); |
| | | }; |
| | | |
| | | // 构造 TransferData 数据结构 |
| | | // 构造 TransferData 数据结构 |
| | | TransferData data; |
| | | data.strClassID = strClassID; |
| | | data.strCreateTime = format_time(pTask->getCreateTime()); |
| | |
| | | data.strEndTime = format_time(pTask->getFinishTime()); |
| | | data.strDescription = pTask->getSimpleDescription(); |
| | | |
| | | // 状态映射 |
| | | // 状态映射 |
| | | static const char* STATUS_STR[] = { |
| | | "Ready", "Running", "Picking", "Picked", "Placing", "Restoring", "Error", "Abort", "Restored", "Completed" |
| | | }; |
| | |
| | | data.strStatus = "Unknown"; |
| | | } |
| | | |
| | | // 写入数据库 |
| | | // 写入数据库 |
| | | if (code == ROBOT_EVENT_FINISH || code == ROBOT_EVENT_ERROR |
| | | || code == ROBOT_EVENT_ABORT || code == ROBOT_EVENT_RESTORE) { |
| | | int nRecordId = 0; |
| | | TransferManager::getInstance().addTransferRecord(data, nRecordId); |
| | | LOGI("<CModel>onRobotTaskEvent: 任务记录已保存,RecordID=%d", nRecordId); |
| | | LOGI("<CModel>onRobotTaskEvent: 任务记录已保存,RecordID=%d", nRecordId); |
| | | } |
| | | notifyPtrAndInt(RX_CODE_EQ_ROBOT_TASK, pTask, nullptr, code); |
| | | |
| | | }; |
| | | masterListener.onJobReceived = [&](void* pMaster, SERVO::CEquipment* pEquipment, int port, SERVO::CJobDataS* pJobDataS) { |
| | | (void)pMaster; |
| | | (void)port; |
| | | if (pEquipment == nullptr || pJobDataS == nullptr) return; |
| | | { |
| | | const std::string& g1 = pJobDataS->getGlass1Id(); |
| | | const std::string& g2 = pJobDataS->getGlass2Id(); |
| | | std::string glassId; |
| | | if (!g1.empty() && !g2.empty()) { |
| | | glassId = g1 + "+" + g2; |
| | | } |
| | | else if (!g1.empty()) { |
| | | glassId = g1; |
| | | } |
| | | else { |
| | | glassId = g2; |
| | | } |
| | | const int slotNo = pJobDataS->getTargetSlotNo(); |
| | | m_hsmsPassive.withVariableLock([&] { |
| | | m_hsmsPassive.setVariableValue("SubEqpName", pEquipment->getName().c_str()); |
| | | m_hsmsPassive.setVariableValue("SubEqpSlot", slotNo); |
| | | m_hsmsPassive.setVariableValue("MaterialId", glassId.c_str()); |
| | | m_hsmsPassive.requestEventReportSend("GlassReceivedJob"); |
| | | }); |
| | | } |
| | | const int eqId = pEquipment->getID(); |
| | | const int recipeId = pJobDataS->getMasterRecipe(); |
| | | std::string recipe = RecipeManager::getInstance().getPPIDById(recipeId); |
| | | if (recipe.empty()) { |
| | | recipe = std::to_string(recipeId); |
| | | } |
| | | const std::string prev = pEquipment->getCurrentRecipe(); |
| | | if (recipe.empty() || recipe == prev) { |
| | | pEquipment->setCurrentRecipe(recipe); |
| | | return; |
| | | } |
| | | pEquipment->setCurrentRecipe(recipe); |
| | | m_hsmsPassive.withVariableLock([&] { |
| | | m_hsmsPassive.setVariableValue("Clock", CToolUnits::getCurrentTimeString().c_str()); |
| | | m_hsmsPassive.setVariableValue("EQPPExecName", recipe.c_str()); |
| | | m_hsmsPassive.setVariableValue("SubEqpName", pEquipment->getName().c_str()); |
| | | const char* recipeVid = nullptr; |
| | | switch (eqId) { |
| | | case EQ_ID_Bonder1: recipeVid = "Bonder1CurrentRecipe"; break; |
| | | case EQ_ID_Bonder2: recipeVid = "Bonder2CurrentRecipe"; break; |
| | | case EQ_ID_VACUUMBAKE: recipeVid = "VacuumBakeCurrentRecipe"; break; |
| | | case EQ_ID_BAKE_COOLING: recipeVid = "BakeCoolingCurrentRecipe"; break; |
| | | case EQ_ID_MEASUREMENT: recipeVid = "MeasurementCurrentRecipe"; break; |
| | | case EQ_ID_EFEM: recipeVid = "EFEMCurrentRecipe"; break; |
| | | default: break; |
| | | } |
| | | if (recipeVid != nullptr) { |
| | | m_hsmsPassive.setVariableValue(recipeVid, recipe.c_str()); |
| | | } |
| | | m_hsmsPassive.requestEventReportSend("RecipeChanged"); |
| | | }); |
| | | }; |
| | | masterListener.onJobSentOut = [&](void* pMaster, SERVO::CEquipment* pEquipment, int port, SERVO::CJobDataS* pJobDataS) { |
| | | (void)pMaster; |
| | | (void)port; |
| | | if (pEquipment == nullptr || pJobDataS == nullptr) return; |
| | | const std::string& g1 = pJobDataS->getGlass1Id(); |
| | | const std::string& g2 = pJobDataS->getGlass2Id(); |
| | | std::string glassId; |
| | | if (!g1.empty() && !g2.empty()) { |
| | | glassId = g1 + "+" + g2; |
| | | } |
| | | else if (!g1.empty()) { |
| | | glassId = g1; |
| | | } |
| | | else { |
| | | glassId = g2; |
| | | } |
| | | const int slotNo = pJobDataS->getSourceSlotNo(); |
| | | m_hsmsPassive.withVariableLock([&] { |
| | | m_hsmsPassive.setVariableValue("SubEqpName", pEquipment->getName().c_str()); |
| | | m_hsmsPassive.setVariableValue("SubEqpSlot", slotNo); |
| | | m_hsmsPassive.setVariableValue("MaterialId", glassId.c_str()); |
| | | m_hsmsPassive.requestEventReportSend("GlassSentOutJob"); |
| | | }); |
| | | }; |
| | | masterListener.onLoadPortStatusChanged = [&] (void* pMaster, SERVO::CEquipment* pEquipment, short status, __int64 data) { |
| | | LOGE("<CModel>onLoadPortStatusChanged. status = %d", status); |
| | | static std::map<int, short> s_prevPortStatus; |
| | | const int eqId = (pEquipment != nullptr) ? pEquipment->getID() : 0; |
| | | const short prevStatus = s_prevPortStatus[eqId]; |
| | | s_prevPortStatus[eqId] = status; |
| | | SERVO::CLoadPort* pLoadPort = dynamic_cast<SERVO::CLoadPort*>(pEquipment); |
| | | |
| | | // Unified PortStateChange event + SV maintenance |
| | | if (pLoadPort != nullptr) { |
| | | const unsigned int portIndex = pLoadPort->getIndex() + 1; |
| | | char stateVid[64] = {0}; |
| | | char modeVid[64] = {0}; |
| | | sprintf_s(stateVid, "PortTransferState_P%u", portIndex); |
| | | sprintf_s(modeVid, "AccessMode_P%u", portIndex); |
| | | m_hsmsPassive.withVariableLock([&] { |
| | | m_hsmsPassive.setVariableValue(stateVid, (__int64)status); |
| | | m_hsmsPassive.setVariableValue(modeVid, (__int64)pLoadPort->getPortMode()); |
| | | m_hsmsPassive.setVariableValue("PortId", pLoadPort->getID()); |
| | | m_hsmsPassive.setVariableValue("PortState", (__int64)status); |
| | | m_hsmsPassive.requestEventReportSend("PortStateChange"); |
| | | }); |
| | | } |
| | | |
| | | if (status == PORT_INUSE) { |
| | | m_hsmsPassive.withVariableLock([&] { |
| | | if (pLoadPort != nullptr) { |
| | | const unsigned int portIndex = pLoadPort->getIndex() + 1; |
| | | char carrierVid[64] = {0}; |
| | | sprintf_s(carrierVid, "CarrierID_P%u", portIndex); |
| | | m_hsmsPassive.setVariableValue(carrierVid, pLoadPort->getCassetteId().c_str()); |
| | | if (prevStatus != PORT_INUSE && pLoadPort->isCompareMapsBeforeProceeding()) { |
| | | // TODO(Host协商): |
| | | // 文档中标明:1-Empty,3-Exist,因此我们可能需要将uint的map转换为list上传 |
| | | m_hsmsPassive.setVariableValue("SlotMap", pLoadPort->getScanCassetteMap()); |
| | | m_hsmsPassive.requestEventReportSend_CheckSlotMap(); |
| | | } |
| | | } |
| | | m_hsmsPassive.requestEventReportSend_CarrierID_Readed(); |
| | | }); |
| | | } |
| | | else if (status == PORT_BLOCKED) { |
| | | SERVO::CLoadPort* pLoadPort = dynamic_cast<SERVO::CLoadPort*>(pEquipment); |
| | | m_hsmsPassive.withVariableLock([&] { |
| | | if (pLoadPort != nullptr) { |
| | | m_hsmsPassive.setVariableValue("PortId", pLoadPort->getID()); |
| | | } |
| | | m_hsmsPassive.requestEventReportSend_Port_Blocked(); |
| | | }); |
| | | } |
| | | else if (status == PORT_LOAD_READY) { |
| | | SERVO::CLoadPort* pLoadPort = dynamic_cast<SERVO::CLoadPort*>(pEquipment); |
| | | m_hsmsPassive.withVariableLock([&] { |
| | | if (pLoadPort != nullptr) { |
| | | m_hsmsPassive.setVariableValue("PortId", pLoadPort->getID()); |
| | | } |
| | | m_hsmsPassive.requestEventReportSend_Port_Load_Ready(); |
| | | }); |
| | | } |
| | | else if (status == PORT_UNLOAD_READY) { |
| | | SERVO::CLoadPort* pLoadPort = dynamic_cast<SERVO::CLoadPort*>(pEquipment); |
| | | m_hsmsPassive.withVariableLock([&] { |
| | | if (pLoadPort != nullptr) { |
| | | m_hsmsPassive.setVariableValue("PortId", pLoadPort->getID()); |
| | | if (prevStatus == PORT_INUSE) { |
| | | m_hsmsPassive.setVariableValue("PortId", pLoadPort->getID()); |
| | | m_hsmsPassive.requestEventReportSend_Port_Ready_To_Release(); |
| | | } |
| | | } |
| | | m_hsmsPassive.requestEventReportSend_Port_Unload_Ready(); |
| | | }); |
| | | } |
| | | else if (status == PORT_EMPTY) { |
| | | SERVO::CLoadPort* pLoadPort = dynamic_cast<SERVO::CLoadPort*>(pEquipment); |
| | | m_hsmsPassive.withVariableLock([&] { |
| | | if (pLoadPort != nullptr) { |
| | | m_hsmsPassive.setVariableValue("PortId", pLoadPort->getID()); |
| | | } |
| | | m_hsmsPassive.requestEventReportSend_LoadPortNotAssoc(); |
| | | }); |
| | | } |
| | | notifyPtr(RX_CODE_LOADPORT_STATUS_CHANGED, pEquipment); |
| | | }; |
| | | masterListener.onProcessStateChanged = [&](void* pMaster, SERVO::CEquipment* pEquipment, int slotNo, SERVO::PROCESS_STATE prevState, SERVO::PROCESS_STATE state) { |
| | | (void)pMaster; |
| | | const int eqId = pEquipment ? pEquipment->getID() : 0; |
| | | |
| | | // 保持同一锁范围内:更新所需 SV 并依次上报,保证 set+send 原子性 |
| | | m_hsmsPassive.withVariableLock([&] { |
| | | // Timestamp VID (Clock, VID=500) for all related reports. |
| | | m_hsmsPassive.setVariableValue("Clock", CToolUnits::getCurrentTimeString().c_str()); |
| | | |
| | | // Common payload VIDs for SubEqp/Unit |
| | | if (pEquipment != nullptr) { |
| | | m_hsmsPassive.setVariableValue("SubEqpName", pEquipment->getName().c_str()); |
| | | } |
| | | m_hsmsPassive.setVariableValue("SubEqpSlot", slotNo); |
| | | |
| | | // ProcessStateChanged (equipment-level): update SVs 700/701, then report CEID=700 |
| | | m_hsmsPassive.setVariableValue("PreviousProcessState", (__int64)prevState); |
| | | m_hsmsPassive.setVariableValue("CurrentProcessState", (__int64)state); |
| | | m_hsmsPassive.requestEventReportSend("ProcessStateChanged"); |
| | | |
| | | // Unit events (per equipment slot) |
| | | static std::map<int, std::map<int, SERVO::PROCESS_STATE>> s_prevUnitState; |
| | | const auto prevUnitState = s_prevUnitState[eqId][slotNo]; |
| | | if (prevUnitState != state) { |
| | | m_hsmsPassive.requestEventReportSend("UnitStateChange"); |
| | | std::string panelId; |
| | | if (pEquipment != nullptr && slotNo > 0) { |
| | | if (auto* pGlass = pEquipment->getGlassFromSlot(slotNo)) { |
| | | panelId = pGlass->getID(); |
| | | } |
| | | } |
| | | if (state == SERVO::PROCESS_STATE::Processing) { |
| | | m_hsmsPassive.setVariableValue("PanelStartID", panelId.c_str()); |
| | | m_hsmsPassive.requestEventReportSend("UnitStart"); |
| | | } |
| | | else if (state == SERVO::PROCESS_STATE::Complete) { |
| | | m_hsmsPassive.setVariableValue("PanelEndID", panelId.c_str()); |
| | | m_hsmsPassive.requestEventReportSend("UnitEnd"); |
| | | } |
| | | s_prevUnitState[eqId][slotNo] = state; |
| | | } |
| | | }); |
| | | }; |
| | | masterListener.onEqStatusChanged = [&](void* pMaster, SERVO::CEquipment* pEquipment, int unitId, int status, int reason) { |
| | | (void)pMaster; |
| | | if (pEquipment == nullptr) return; |
| | | m_hsmsPassive.withVariableLock([&] { |
| | | m_hsmsPassive.setVariableValue("SubEqpName", pEquipment->getName().c_str()); |
| | | m_hsmsPassive.setVariableValue("SubEqpSlot", unitId); |
| | | m_hsmsPassive.setVariableValue("EquipmentStatus", (__int64)status); |
| | | m_hsmsPassive.requestEventReportSend("SubEqpStateChange"); |
| | | }); |
| | | }; |
| | | masterListener.onSVDataReport = [&](void* pMaster, SERVO::CEquipment* pEquipment, const std::vector<CParam>& params) { |
| | | (void)pMaster; |
| | | const int eqId = pEquipment ? pEquipment->getID() : 0; |
| | | |
| | | auto sendSv = [&](const auto& vidMap, const char* evName) { |
| | | const size_t count = (std::min)(params.size(), vidMap.size()); |
| | | m_hsmsPassive.withVariableLock([&] { |
| | | if (pEquipment != nullptr) { |
| | | m_hsmsPassive.setVariableValue("SubEqpName", pEquipment->getName().c_str()); |
| | | } |
| | | m_hsmsPassive.setVariableValue("SubEqpSlot", 0); |
| | | m_hsmsPassive.setVariableValue("Clock", CToolUnits::getCurrentTimeString().c_str()); |
| | | for (size_t idx = 0; idx < count; ++idx) { |
| | | const std::string val = formatParamValue(params[idx]); |
| | | m_hsmsPassive.setVariableValue(std::to_string(vidMap[idx]).c_str(), val.c_str()); |
| | | } |
| | | m_hsmsPassive.requestEventReportSend(evName); |
| | | }); |
| | | }; |
| | | |
| | | if (eqId == EQ_ID_Bonder1 || eqId == EQ_ID_Bonder2) { |
| | | static constexpr std::array<int, 19> vids = { |
| | | 6000,6001,6002,6003,6004,6005,6006,6007,6008,6009, |
| | | 6010,6011,6012,6013,6014,6015,6016,6017,6018 |
| | | }; |
| | | sendSv(vids, "BonderSVData"); |
| | | } |
| | | else if (eqId == EQ_ID_VACUUMBAKE) { |
| | | static constexpr std::array<int, 18> vids = { |
| | | 6200,6201,6202,6203,6204,6205,6206,6207,6208, |
| | | 6209,6210,6211,6212,6213,6214,6215,6216,6217 |
| | | }; |
| | | sendSv(vids, "VacuumBakeSVData"); |
| | | } |
| | | else if (eqId == EQ_ID_BAKE_COOLING) { |
| | | static constexpr std::array<int, 20> vids = { |
| | | 6400,6401,6402,6403,6404,6405,6406,6407,6408,6409, |
| | | 6410,6411,6412,6413,6414,6415,6416,6417,6418,6419 |
| | | }; |
| | | sendSv(vids, "BakeCoolingSVData"); |
| | | } |
| | | else if (eqId == EQ_ID_MEASUREMENT) { |
| | | static constexpr std::array<int, 2> vids = { 6600, 6601 }; |
| | | sendSv(vids, "MeasurementSVData"); |
| | | } |
| | | }; |
| | | masterListener.onProcessDataReport = [&](void* pMaster, SERVO::CEquipment* pEquipment, const std::vector<CParam>& params) { |
| | | (void)pMaster; |
| | | const int eqId = pEquipment ? pEquipment->getID() : 0; |
| | | |
| | | auto sendProcess = [&](const auto& vidMap, const char* evName) { |
| | | const size_t count = (std::min)(params.size(), vidMap.size()); |
| | | m_hsmsPassive.withVariableLock([&] { |
| | | if (pEquipment != nullptr) { |
| | | m_hsmsPassive.setVariableValue("SubEqpName", pEquipment->getName().c_str()); |
| | | } |
| | | m_hsmsPassive.setVariableValue("SubEqpSlot", 0); |
| | | m_hsmsPassive.setVariableValue("Clock", CToolUnits::getCurrentTimeString().c_str()); |
| | | for (size_t idx = 0; idx < count; ++idx) { |
| | | const std::string val = formatParamValue(params[idx]); |
| | | m_hsmsPassive.setVariableValue(std::to_string(vidMap[idx]).c_str(), val.c_str()); |
| | | } |
| | | m_hsmsPassive.requestEventReportSend(evName); |
| | | }); |
| | | }; |
| | | |
| | | if (eqId == EQ_ID_Bonder1 || eqId == EQ_ID_Bonder2) { |
| | | static constexpr std::array<int, 22> vids = { |
| | | 6100,6101,6102,6103,6104,6105,6106,6107,6108,6109,6110, |
| | | 6111,6112,6113,6114,6115,6116,6117,6118,6119,6120,6121 |
| | | }; |
| | | sendProcess(vids, "BonderProcessData"); |
| | | } |
| | | else if (eqId == EQ_ID_VACUUMBAKE) { |
| | | static constexpr std::array<int, 5> vids = { 6300,6301,6302,6303,6304 }; |
| | | sendProcess(vids, "VacuumBakeProcessData"); |
| | | } |
| | | else if (eqId == EQ_ID_BAKE_COOLING) { |
| | | static constexpr std::array<int, 4> vids = { 6500,6501,6502,6503 }; |
| | | sendProcess(vids, "BakeCoolingProcessData"); |
| | | } |
| | | else if (eqId == EQ_ID_MEASUREMENT) { |
| | | static constexpr std::array<int, 4> vids = { 6700,6701,6702,6703 }; |
| | | sendProcess(vids, "MeasurementProcessData"); |
| | | } |
| | | }; |
| | | masterListener.onCTRoundEnd = [&](void* pMaster, int round) { |
| | | m_configuration.setContinuousTransferCount(round); |
| | | }; |
| | | masterListener.onCjStart = [&](void* pMaster, void* pj) { |
| | | m_hsmsPassive.withVariableLock([&] { |
| | | m_hsmsPassive.setVariableValue("CJStartID", ((SERVO::CControlJob*)pj)->id().c_str()); |
| | | m_hsmsPassive.requestEventReportSend_CJ_Start(); |
| | | }); |
| | | }; |
| | | masterListener.onCjEnd = [&](void* pMaster, void* pj) { |
| | | m_hsmsPassive.withVariableLock([&] { |
| | | m_hsmsPassive.setVariableValue("CJEndID", ((SERVO::CControlJob*)pj)->id().c_str()); |
| | | m_hsmsPassive.requestEventReportSend_CJ_End(); |
| | | }); |
| | | |
| | | // 结批,保存ControlJob |
| | | // |
| | | }; |
| | | masterListener.onPjStart = [&](void* pMaster, void* pj) { |
| | | m_hsmsPassive.withVariableLock([&] { |
| | | m_hsmsPassive.setVariableValue("PJStartID", ((SERVO::CProcessJob*)pj)->id().c_str()); |
| | | m_hsmsPassive.requestEventReportSend_PJ_Start(); |
| | | }); |
| | | }; |
| | | masterListener.onPjEnd = [&](void* pMaster, void* pj) { |
| | | m_hsmsPassive.withVariableLock([&] { |
| | | m_hsmsPassive.setVariableValue("PJEndID", ((SERVO::CProcessJob*)pj)->id().c_str()); |
| | | m_hsmsPassive.requestEventReportSend_PJ_End(); |
| | | }); |
| | | }; |
| | | masterListener.onPanelStart = [&](void* pMaster, void* pPanel) { |
| | | m_hsmsPassive.withVariableLock([&] { |
| | | m_hsmsPassive.setVariableValue("PanelStartID", ((SERVO::CGlass*)pPanel)->getID().c_str()); |
| | | m_hsmsPassive.requestEventReportSend_Panel_Start(); |
| | | }); |
| | | }; |
| | | masterListener.onPanelEnd = [&](void* pMaster, void* pPanel) { |
| | | m_hsmsPassive.withVariableLock([&] { |
| | | m_hsmsPassive.setVariableValue("PanelEndID", ((SERVO::CGlass*)pPanel)->getID().c_str()); |
| | | m_hsmsPassive.requestEventReportSend_Panel_End(); |
| | | // Placeholder payload to match log shape: EV_PROCESS_DATA_REPORT can carry a single A-string (may be empty). |
| | | m_hsmsPassive.setVariableValue("ProcessDataReportText", ""); |
| | | m_hsmsPassive.requestEventReportSend_ProcessDataReport(); |
| | | }); |
| | | auto& db = GlassLogDb::Instance(); |
| | | db.insertFromCGlass((*(SERVO::CGlass*)pPanel)); |
| | | SERVO::CGlass* pBuddy = ((SERVO::CGlass*)pPanel)->getBuddy(); |
| | | if (pBuddy != nullptr) { |
| | | db.insertFromCGlass(*pBuddy); |
| | | } |
| | | }; |
| | | m_master.setListener(masterListener); |
| | | m_master.setContinuousTransferCount(m_configuration.getContinuousTransferCount()); |
| | | |
| | | |
| | | // master 设置缓存文件 |
| | | // master 设置缓存文件 |
| | | CString strMasterDataFile; |
| | | strMasterDataFile.Format(_T("%s\\Master.dat"), (LPTSTR)(LPCTSTR)m_strWorkDir); |
| | | m_master.setCacheFilepath((LPTSTR)(LPCTSTR)strMasterDataFile); |
| | | m_master.setCompareMapsBeforeProceeding(m_configuration.isCompareMapsBeforeProceeding()); |
| | | m_master.setJobMode(m_configuration.isJobMode()); |
| | | |
| | | // 加截Job |
| | | strMasterDataFile.Format(_T("%s\\MasterState.dat"), (LPTSTR)(LPCTSTR)m_strWorkDir); |
| | | std::string strPath = std::string((LPTSTR)(LPCTSTR)strMasterDataFile); |
| | | m_master.setStateFile(strPath); |
| | | |
| | | |
| | | // 加载警告信息 |
| | | |
| | | // 加载警告信息 |
| | | AlarmManager& alarmManager = AlarmManager::getInstance(); |
| | | char szBuffer[MAX_PATH]; |
| | | sprintf_s(szBuffer, MAX_PATH, "%s\\AlarmList.csv", (LPTSTR)(LPCTSTR)m_strWorkDir); |
| | | alarmManager.readAlarmFile(szBuffer); |
| | | LOGI("[BOOT][MODEL] Alarm list loaded, cost=%llu ms", |
| | | (unsigned long long)(GetTickCount64() - boot_model_begin)); |
| | | |
| | | |
| | | // Glass数据库 |
| | | strLogDir.Format(_T("%s\\db\\process.db"), (LPTSTR)(LPCTSTR)m_strWorkDir); |
| | | std::string path((LPTSTR)(LPCTSTR)strLogDir); |
| | | GlassLogDb::Init(path); |
| | | |
| | | |
| | | LOGI("[BOOT][MODEL] init finished, total cost=%llu ms", |
| | | (unsigned long long)(GetTickCount64() - boot_model_begin)); |
| | | return 0; |
| | | } |
| | | |
| | | int CModel::term() |
| | | { |
| | | m_configuration.setPortCassetteSnSeed(1, m_master.getPortCassetteSnSeed(1)); |
| | | m_configuration.setPortCassetteSnSeed(2, m_master.getPortCassetteSnSeed(2)); |
| | | m_configuration.setPortCassetteSnSeed(3, m_master.getPortCassetteSnSeed(3)); |
| | | m_configuration.setPortCassetteSnSeed(4, m_master.getPortCassetteSnSeed(4)); |
| | | m_hsmsPassive.saveCache(); |
| | | m_hsmsPassive.term(); |
| | | CLog::GetLog()->SetOnLogCallback(nullptr); |
| | | m_master.term(); |