| | |
| | | #include "CMaster.h" |
| | | #include <future> |
| | | #include <vector> |
| | | #include <algorithm> |
| | | #include "RecipeManager.h" |
| | | #include <fstream> |
| | | #include "SerializeUtil.h" |
| | | #include "CServoUtilsTool.h" |
| | | #include "AlarmManager.h" |
| | | #include "ToolUnits.h" |
| | | #include "Model.h" |
| | | |
| | | |
| | | namespace SERVO { |
| | |
| | | m_ullStartTime = 0; |
| | | m_ullRunTime = 0; |
| | | m_state = MASTERSTATE::READY; |
| | | m_curveMode = CurveMode::Production; |
| | | m_pActiveRobotTask = nullptr; |
| | | m_nLastError = ER_CODE_NOERROR; |
| | | m_isCompareMapsBeforeProceeding = FALSE; |
| | |
| | | m_nContinuousWorkingPort = 0; |
| | | m_nContinuousWorkingSlot = 0; |
| | | m_pControlJob = nullptr; |
| | | m_bPauseAlarmRaised = false; |
| | | m_pModelCtx = nullptr; |
| | | m_nTestFlag = 0; |
| | | InitializeCriticalSection(&m_criticalSection); |
| | | } |
| | |
| | | m_hEventDispatchThreadExit[1] = nullptr; |
| | | } |
| | | |
| | | |
| | | DeleteCriticalSection(&m_criticalSection); |
| | | } |
| | | |
| | | void CMaster::setListener(MasterListener listener) |
| | | { |
| | | m_listener = listener; |
| | | } |
| | | |
| | | void CMaster::setModelCtx(CModel* pModel) |
| | | { |
| | | m_pModelCtx = pModel; |
| | | } |
| | | |
| | | CRobotTask* CMaster::getActiveRobotTask() |
| | |
| | | |
| | | int CMaster::init() |
| | | { |
| | | const ULONGLONG boot_master_begin = GetTickCount64(); |
| | | LOGI("<Master>正在初始化..."); |
| | | LOGI("[BOOT][MASTER] init begin"); |
| | | |
| | | |
| | | // cclink |
| | | if (m_cclink.Connect(CC_LINK_IE_CONTROL_CHANNEL(1)) != 0) { |
| | | const ULONGLONG boot_cclink_begin = GetTickCount64(); |
| | | const int cc_ret = m_cclink.Connect(CC_LINK_IE_CONTROL_CHANNEL(1)); |
| | | LOGI("[BOOT][MASTER] CC-Link connect ret=%d, cost=%llu ms", |
| | | cc_ret, |
| | | (unsigned long long)(GetTickCount64() - boot_cclink_begin)); |
| | | if (cc_ret != 0) { |
| | | LOGE("连接CC-Link失败."); |
| | | } |
| | | else { |
| | |
| | | |
| | | |
| | | // 读缓存数据 |
| | | const ULONGLONG boot_cache_begin = GetTickCount64(); |
| | | const ULONGLONG boot_read_begin = GetTickCount64(); |
| | | readCache(); |
| | | LOGI("[BOOT][MASTER] readCache finished, cost=%llu ms", (unsigned long long)(GetTickCount64() - boot_read_begin)); |
| | | |
| | | const ULONGLONG boot_state_begin = GetTickCount64(); |
| | | loadState(); |
| | | LOGI("[BOOT][MASTER] loadState finished, cost=%llu ms", (unsigned long long)(GetTickCount64() - boot_state_begin)); |
| | | if (m_listener.onControlJobChanged) { |
| | | notifyControlJobChanged(); |
| | | } |
| | | |
| | | LOGI("[BOOT][MASTER] cache/state loaded, cost=%llu ms (since init %llu ms)", |
| | | (unsigned long long)(GetTickCount64() - boot_cache_begin), |
| | | (unsigned long long)(GetTickCount64() - boot_master_begin)); |
| | | |
| | | |
| | | // 定时器 |
| | |
| | | |
| | | |
| | | LOGI("<Master>初始化完成."); |
| | | LOGI("[BOOT][MASTER] init finished, total cost=%llu ms", |
| | | (unsigned long long)(GetTickCount64() - boot_master_begin)); |
| | | return 0; |
| | | } |
| | | |
| | | void CMaster::setCurveMode(CurveMode mode) |
| | | { |
| | | if (m_curveMode == mode) { |
| | | return; |
| | | } |
| | | m_curveMode = mode; |
| | | if (m_pCollector != nullptr) { |
| | | const uint32_t mids[] = { |
| | | MID_Bonder1, MID_Bonder2, |
| | | MID_VacuumBakeA, MID_VacuumBakeB, |
| | | MID_BakeCoolingA, MID_BakeCoolingB |
| | | }; |
| | | for (uint32_t mid : mids) { |
| | | if (mode == CurveMode::EmptyChamber) { |
| | | m_pCollector->batchStart(mid, "EMPTY_CHAMBER", 30 * 60 * 1000ULL); // 空腔模式:启动采样批次 |
| | | } |
| | | else { |
| | | m_pCollector->batchStop(mid); |
| | | m_pCollector->buffersClear(mid); // 切回生产模式,清掉空腔数据 |
| | | } |
| | | } |
| | | } |
| | | LOGI("<Master>CurveMode=%s", mode == CurveMode::EmptyChamber ? "EmptyChamber" : "Production"); |
| | | } |
| | | |
| | | CurveMode CMaster::getCurveMode() const |
| | | { |
| | | return m_curveMode; |
| | | } |
| | | |
| | | int CMaster::term() |
| | |
| | | } |
| | | m_listEquipment.clear(); |
| | | |
| | | // release manual-remove buffer before glass pool is torn down |
| | | for (auto* pGlass : m_bufGlass) { |
| | | if (pGlass != nullptr) { |
| | | pGlass->release(); |
| | | } |
| | | } |
| | | m_bufGlass.clear(); |
| | | |
| | | if (m_pCollector != nullptr) { |
| | | m_pCollector->stopLoop(); |
| | |
| | | m_pActiveRobotTask->place(); |
| | | } |
| | | unlock(); // 等当前任务完成或中止后继续 |
| | | continue; |
| | | } |
| | | |
| | | // 5.5) 暂停状态检查:若 CJ 或在制 PJ 处于 Paused,暂缓调度新的搬送 |
| | | bool pausedByEvent = false; |
| | | if (m_pControlJob != nullptr && m_pControlJob->state() == CJState::Paused) { |
| | | pausedByEvent = true; |
| | | } |
| | | for (auto pj : m_inProcesJobs) { |
| | | if (pj != nullptr && pj->state() == PJState::Paused) { |
| | | pausedByEvent = true; |
| | | break; |
| | | } |
| | | } |
| | | if (!pausedByEvent && m_bPauseAlarmRaised) { |
| | | if (m_pModelCtx != nullptr) { |
| | | m_pModelCtx->clearSoftAlarm(ALID_SOFTWARE_PAUSE_EVENT, 0, 0); |
| | | } |
| | | else { |
| | | AlarmManager& alarmManager = AlarmManager::getInstance(); |
| | | alarmManager.clearAlarmByAttributes(ALID_SOFTWARE_PAUSE_EVENT, 0, 0, CToolUnits::getCurrentTimeString()); |
| | | } |
| | | m_bPauseAlarmRaised = false; |
| | | } |
| | | if (pausedByEvent) { |
| | | LOGI("<Master>调度暂停:ControlJob/ProcessJob 处于 Paused 状态(可能由 PauseEvent 触发)"); |
| | | unlock(); |
| | | continue; |
| | | } |
| | | |
| | |
| | | unlock(); |
| | | } |
| | | }; |
| | | listener.onProcessStateChanged = [&](void* pEquipment, int slotNo, PROCESS_STATE state) -> void { |
| | | listener.onProcessStateChanged = [&](void* pEquipment, int slotNo, PROCESS_STATE prevState, PROCESS_STATE state) -> void { |
| | | ASSERT(1 <= slotNo && slotNo <= 8); |
| | | int eqid = ((CEquipment*)pEquipment)->getID(); |
| | | CGlass* pGlass = ((CEquipment*)pEquipment)->getGlassFromSlot(slotNo); |
| | |
| | | if (pGlass != nullptr) { |
| | | m_pCollector->batchStop(SlotToMid(eqid, slotNo)); |
| | | } |
| | | } |
| | | |
| | | if (m_listener.onProcessStateChanged != nullptr) { |
| | | m_listener.onProcessStateChanged(this, (CEquipment*)pEquipment, slotNo, prevState, state); |
| | | } |
| | | }; |
| | | listener.onProcessDataReport = [&](void* pEquipment, const std::vector<CParam>& params) { |
| | | if (m_listener.onProcessDataReport != nullptr) { |
| | | m_listener.onProcessDataReport(this, (CEquipment*)pEquipment, params); |
| | | } |
| | | }; |
| | | listener.onMapMismatch = [&](void* pEquipment, short scanMap, short downMap) { |
| | |
| | | } |
| | | }; |
| | | listener.onSVDataReport = [&](void* pEquipment, void* pData) { |
| | | const bool allowSvLog = |
| | | (m_state == MASTERSTATE::RUNNING || |
| | | m_state == MASTERSTATE::RUNNING_CONTINUOUS_TRANSFER || |
| | | m_state == MASTERSTATE::RUNNING_BATCH || |
| | | m_state == MASTERSTATE::STARTING); |
| | | const bool allowCurve = allowSvLog || (m_curveMode == CurveMode::EmptyChamber); |
| | | if (!allowCurve) { |
| | | return; |
| | | } |
| | | CSVData* pSVData = (CSVData*)pData; |
| | | auto rawData = pSVData->getSVRawData(); |
| | | std::vector<CParam> params; |
| | |
| | | int paramIndex = mapping.first; |
| | | int channel = mapping.second; |
| | | |
| | | if (paramIndex < params.size() && channel - 1 < vacuumbakeTypes.size()) { |
| | | if (paramIndex < params.size()) { |
| | | auto& param = params.at(paramIndex); |
| | | double value = param.getDoubleValue(); |
| | | const std::string& dataType = vacuumbakeTypes[channel - 1]; |
| | | const std::string& paramName = param.getName(); |
| | | const char slotTag = !paramName.empty() ? paramName[0] : '\0'; |
| | | const int typeIndex = (slotTag == 'B') ? (channel - 8) : (channel - 1); |
| | | if (typeIndex < 0 || typeIndex >= (int)vacuumbakeTypes.size()) { |
| | | continue; |
| | | } |
| | | const int pushChannel = typeIndex + 1; |
| | | const std::string& dataType = vacuumbakeTypes[typeIndex]; |
| | | |
| | | if (m_pCollector != nullptr) { |
| | | if (slotTag == 'A') |
| | | m_pCollector->buffersPush(SlotToMid(eqid, 1), channel, ts, value); |
| | | m_pCollector->buffersPush(SlotToMid(eqid, 1), pushChannel, ts, value); |
| | | else if (slotTag == 'B') |
| | | m_pCollector->buffersPush(SlotToMid(eqid, 2), channel, ts, value); |
| | | m_pCollector->buffersPush(SlotToMid(eqid, 2), pushChannel, ts, value); |
| | | } |
| | | |
| | | // 根据腔体前缀写入对应 Slot 的玻璃 |
| | |
| | | int paramIndex = mapping.first; |
| | | int channel = mapping.second; |
| | | |
| | | if (paramIndex < params.size() && channel - 1 < coolingTypes.size()) { |
| | | if (paramIndex < params.size()) { |
| | | auto& param = params.at(paramIndex); |
| | | double value = param.getDoubleValue(); |
| | | const std::string& dataType = coolingTypes[channel - 1]; |
| | | const std::string& paramName = param.getName(); |
| | | const char slotTag = !paramName.empty() ? paramName[0] : '\0'; |
| | | const bool paramIsBake = paramName.find("烘烤") != std::string::npos; |
| | | const bool paramIsCooling = paramName.find("冷却") != std::string::npos; |
| | | const int typeIndex = (slotTag == 'B') ? (channel - 7) : (channel - 1); |
| | | if (typeIndex < 0 || typeIndex >= (int)coolingTypes.size()) { |
| | | continue; |
| | | } |
| | | const int pushChannel = typeIndex + 1; |
| | | const std::string& dataType = coolingTypes[typeIndex]; |
| | | |
| | | if (m_pCollector != nullptr && paramIsBake) { |
| | | if (slotTag == 'A') |
| | | m_pCollector->buffersPush(SlotToMid(eqid, 1), channel, ts, value); |
| | | m_pCollector->buffersPush(SlotToMid(eqid, 1), pushChannel, ts, value); |
| | | else if (slotTag == 'B') |
| | | m_pCollector->buffersPush(SlotToMid(eqid, 3), channel, ts, value); |
| | | m_pCollector->buffersPush(SlotToMid(eqid, 3), pushChannel, ts, value); |
| | | } |
| | | |
| | | if (!dataType.empty()) { |
| | |
| | | strOut.append(szBuffer); |
| | | } |
| | | LOGD("<CMaster-%s>SVDataReport:%s", ((CEquipment*)pEquipment)->getName().c_str(), strOut.c_str()); |
| | | |
| | | if (m_listener.onSVDataReport != nullptr) { |
| | | m_listener.onSVDataReport(this, (CEquipment*)pEquipment, params); |
| | | } |
| | | }; |
| | | listener.onPanelDataReport = [&](void* pEquipment, void* pContext) { |
| | | LOGD("<CMaster-%s>onPanelDataReport", ((CEquipment*)pEquipment)->getName().c_str()); |
| | |
| | | } |
| | | } |
| | | |
| | | }; |
| | | listener.onReceivedJob = [&](void* pEquipment, int port, CJobDataS* pJobDataS) { |
| | | if (m_listener.onJobReceived != nullptr) { |
| | | m_listener.onJobReceived(this, (CEquipment*)pEquipment, port, pJobDataS); |
| | | } |
| | | }; |
| | | listener.onSentOutJob = [&](void* pEquipment, int port, CJobDataS* pJobDataS) { |
| | | if (m_listener.onJobSentOut != nullptr) { |
| | | m_listener.onJobSentOut(this, (CEquipment*)pEquipment, port, pJobDataS); |
| | | } |
| | | }; |
| | | listener.onEqStatusChanged = [&](void* pEquipment, int unitId, int status, int reason) { |
| | | if (m_listener.onEqStatusChanged != nullptr) { |
| | | m_listener.onEqStatusChanged(this, (CEquipment*)pEquipment, unitId, status, reason); |
| | | } |
| | | }; |
| | | pEquipment->setListener(listener); |
| | | pEquipment->setCcLink(&m_cclink); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | // 模拟测试(无机器联机时用于联调 EAP) |
| | | // 读取 test.ini(当前目录或 exe 同目录) |
| | | { |
| | | struct SimCfg { |
| | | bool enabled{ false }; |
| | | DWORD intervalMs{ 5000 }; |
| | | int step{ 0 }; |
| | | }; |
| | | auto loadCfg = [&]() -> SimCfg { |
| | | SimCfg cfg; |
| | | |
| | | // Try INI: current dir, then exe dir |
| | | char iniPath[MAX_PATH] = { 0 }; |
| | | strcpy_s(iniPath, "test.ini"); |
| | | auto readIni = [&](const char* path) -> bool { |
| | | const UINT en = GetPrivateProfileIntA("SimEap", "Enabled", 0, path); |
| | | if (en == 0) return false; // treat as missing/disabled |
| | | cfg.enabled = (en != 0); |
| | | cfg.intervalMs = (DWORD)GetPrivateProfileIntA("SimEap", "IntervalMs", 5000, path); |
| | | cfg.intervalMs = max(500u, cfg.intervalMs); |
| | | cfg.step = (int)GetPrivateProfileIntA("SimEap", "Step", 0, path); |
| | | return true; |
| | | }; |
| | | if (!readIni(iniPath)) { |
| | | char exePath[MAX_PATH] = { 0 }; |
| | | GetModuleFileNameA(NULL, exePath, MAX_PATH); |
| | | char* lastSlash = strrchr(exePath, '\\'); |
| | | if (lastSlash != nullptr) { |
| | | *(lastSlash + 1) = '\0'; |
| | | strcat_s(exePath, "test.ini"); |
| | | readIni(exePath); |
| | | } |
| | | } |
| | | return cfg; |
| | | }; |
| | | |
| | | const SimCfg cfg = loadCfg(); |
| | | if (cfg.enabled) { |
| | | static DWORD lastTick = 0; |
| | | static int lastExecutedStep = -1; |
| | | static bool inited = false; |
| | | static SERVO::CGlass simGlass; |
| | | static SERVO::CVcrEventReport simVcr; |
| | | static SERVO::CProcessJob simPj("PJ1001"); |
| | | static SERVO::CControlJob simCj("CJ5007"); |
| | | |
| | | if (!inited) { |
| | | inited = true; |
| | | simGlass.setID("SIM_PANEL_001"); |
| | | simVcr.getGlassId() = "SIM_PANEL_001"; |
| | | } |
| | | |
| | | DWORD now = GetTickCount(); |
| | | if (lastTick == 0) lastTick = now; |
| | | if ((now - lastTick) < cfg.intervalMs) { |
| | | return; |
| | | } |
| | | lastTick = now; |
| | | |
| | | // 单步触发:每个 Step 只执行一次;你手动修改 ini 的 Step 值后会再次触发 |
| | | const int step = cfg.step; |
| | | if (step <= 0 || step == lastExecutedStep) { |
| | | return; |
| | | } |
| | | lastExecutedStep = step; |
| | | |
| | | // 取一个 LoadPort 作为模拟目标 |
| | | SERVO::CLoadPort* pLpEq = (SERVO::CLoadPort*)getEquipment(EQ_ID_LOADPORT1); |
| | | |
| | | auto fireLoadPortStatus = [&](short status) { |
| | | pLpEq->simulateSetCassetteId("Test-Cassette-001"); |
| | | if (m_listener.onLoadPortStatusChanged != nullptr && pLpEq != nullptr) { |
| | | m_listener.onLoadPortStatusChanged(this, pLpEq, status, 0); |
| | | } |
| | | }; |
| | | auto fireProcessState = [&](SERVO::CEquipment* pEq, int slotNo, SERVO::PROCESS_STATE st) { |
| | | // Drive equipment state so listeners receive prev/current states consistently. |
| | | if (pEq != nullptr) { |
| | | pEq->fireSetProcessState(slotNo, st); |
| | | } |
| | | }; |
| | | |
| | | LOGI("<Master>SIM_EAP single-step=%d", step); |
| | | switch (step) { |
| | | // ===== 业务流程步骤(1~23)===== |
| | | case 1: // E87_06 Material Arrived(TransferBlock) -> Port Blocked |
| | | fireLoadPortStatus(PORT_BLOCKED); |
| | | break; |
| | | case 2: // E87_03 CarrierID Readed -> Port InUse |
| | | fireLoadPortStatus(PORT_INUSE); |
| | | break; |
| | | case 3: // S1F3 Query CJ Space (Host->EQ) - wait host |
| | | LOGI("<Master>SIM_EAP step3: wait host S1F3"); |
| | | break; |
| | | case 4: // S16F21 Query PJ Space (Host->EQ) - wait host |
| | | LOGI("<Master>SIM_EAP step4: wait host S16F21"); |
| | | break; |
| | | case 5: // S7F19 Query PPID List (Host->EQ) - wait host |
| | | LOGI("<Master>SIM_EAP step5: wait host S7F19"); |
| | | break; |
| | | case 6: // S3F17 ProceedWithCarrier (Host->EQ) - wait host |
| | | LOGI("<Master>SIM_EAP step6: wait host S3F17 ProceedWithCarrier"); |
| | | break; |
| | | case 7: // E87_14 Check SlotMap (设备上报/进入 WFH) - 由 PORT_INUSE 内部触发 |
| | | fireLoadPortStatus(PORT_INUSE); |
| | | break; |
| | | case 8: // S3F17 ProceedWithSlotMap (Host->EQ) - wait host |
| | | LOGI("<Master>SIM_EAP step8: wait host S3F17 ProceedWithSlotMap"); |
| | | break; |
| | | case 9: // SlotMap Verify OK (本项目在收到 ProceedWithSlotMap 后上报) - wait host |
| | | LOGI("<Master>SIM_EAP step9: wait host ProceedWithSlotMap to trigger VerifyOK"); |
| | | break; |
| | | case 10: // Create PJ (Host->EQ) - wait host |
| | | LOGI("<Master>SIM_EAP step10: wait host S16F15 CreateMultiPJ"); |
| | | break; |
| | | case 11: // PJ Queued(本项目在创建 PJ 后上报) - wait host |
| | | LOGI("<Master>SIM_EAP step11: wait host CreateMultiPJ to trigger PJ_Queued"); |
| | | break; |
| | | case 12: // Create CJ (Host->EQ) - wait host |
| | | LOGI("<Master>SIM_EAP step12: wait host S14F9 CreateCJ"); |
| | | break; |
| | | case 13: // CJ Start |
| | | if (m_listener.onCjStart != nullptr) m_listener.onCjStart(this, &simCj); |
| | | break; |
| | | case 14: // PJ Start |
| | | if (m_listener.onPjStart != nullptr) m_listener.onPjStart(this, &simPj); |
| | | break; |
| | | case 15: // OCR |
| | | if (m_listener.onEqVcrEventReport != nullptr && pLpEq != nullptr) { |
| | | m_listener.onEqVcrEventReport(this, pLpEq, &simVcr); |
| | | } |
| | | break; |
| | | case 16: // Panel Start |
| | | if (m_listener.onPanelStart != nullptr) m_listener.onPanelStart(this, &simGlass); |
| | | // 同时触发一次子机台开始(示例:Bonder1, slot 1) |
| | | fireProcessState(getEquipment(EQ_ID_Bonder1), 1, SERVO::PROCESS_STATE::Processing); |
| | | break; |
| | | case 17: // Panel End |
| | | // 同时触发一次子机台结束(示例:Bonder1, slot 1) |
| | | fireProcessState(getEquipment(EQ_ID_Bonder1), 1, SERVO::PROCESS_STATE::Complete); |
| | | if (m_listener.onPanelEnd != nullptr) m_listener.onPanelEnd(this, &simGlass); |
| | | break; |
| | | case 18: // PJ End |
| | | if (m_listener.onPjEnd != nullptr) m_listener.onPjEnd(this, &simPj); |
| | | break; |
| | | case 19: // CJ End |
| | | if (m_listener.onCjEnd != nullptr) m_listener.onCjEnd(this, &simCj); |
| | | break; |
| | | case 20: // Ready to Release (Port Unload Ready; with prev INUSE will also trigger ReadyToRelease) |
| | | fireLoadPortStatus(PORT_UNLOAD_READY); |
| | | break; |
| | | case 21: // CarrierRelease (Host->EQ) - optional / wait host |
| | | LOGI("<Master>SIM_EAP step21: wait host S3F17 CarrierRelease"); |
| | | break; |
| | | case 22: // Ready to Unload |
| | | fireLoadPortStatus(PORT_UNLOAD_READY); |
| | | break; |
| | | case 23: // Material Removed (and ReadyToLoad) |
| | | fireLoadPortStatus(PORT_LOAD_READY); |
| | | fireLoadPortStatus(PORT_EMPTY); // will also raise LoadPortNotAssoc via Model |
| | | break; |
| | | case 24: { // 模拟 SV Data(示例:Bonder1) |
| | | SERVO::CEquipment* pEq = getEquipment(EQ_ID_Bonder1); |
| | | if (pEq != nullptr && m_listener.onSVDataReport != nullptr) { |
| | | static int counter = 0; |
| | | ++counter; |
| | | std::vector<CParam> params; |
| | | params.emplace_back("MockSV_Temp", "1", "C", 25 + (counter % 5)); |
| | | params.emplace_back("MockSV_Pressure", "2", "kPa", 100 + (counter % 3)); |
| | | params.emplace_back("MockSV_Speed", "3", "mm/s", 50 + (counter % 7)); |
| | | m_listener.onSVDataReport(this, pEq, params); |
| | | LOGI("<Master>SIM_EAP step24: mock SVData (Bonder1), params=%zu", params.size()); |
| | | } |
| | | break; |
| | | } |
| | | case 25: { // 模拟 Process Data(示例:Bonder1) |
| | | SERVO::CEquipment* pEq = getEquipment(EQ_ID_Bonder1); |
| | | if (pEq != nullptr && m_listener.onProcessDataReport != nullptr) { |
| | | static int counter = 0; |
| | | ++counter; |
| | | std::vector<CParam> params; |
| | | params.emplace_back("MockProc_CycleTime", "1", "s", 30 + (counter % 4)); |
| | | params.emplace_back("MockProc_MaxTemp", "2", "C", 200 + (counter % 6)); |
| | | params.emplace_back("MockProc_Result", "3", "", (counter % 2) ? 1 : 0); |
| | | m_listener.onProcessDataReport(this, pEq, params); |
| | | LOGI("<Master>SIM_EAP step25: mock ProcessData (Bonder1), params=%zu", params.size()); |
| | | } |
| | | break; |
| | | } |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | // 模拟测试 |
| | |
| | | } |
| | | m_processJobs = temp; |
| | | |
| | | // 重置各端口 DownloadMap(Host/本地勾选的期望加工槽位) |
| | | for (int i = 0; i < 4; i++) { |
| | | auto* pPort = (CLoadPort*)getEquipment(EQ_ID_LOADPORT1 + i); |
| | | if (pPort != nullptr) { |
| | | pPort->setDownloadCassetteMap(0); |
| | | } |
| | | } |
| | | |
| | | |
| | | // 更新context |
| | | std::vector<uint8_t> newSlots; |
| | | std::vector<void*> newContexts; |
| | | for (auto pj : m_processJobs) { |
| | | for (auto& c : pj->carriers()) { |
| | | auto pPort = getPortWithCarrierId(c.carrierId); |
| | | if (pPort == nullptr) continue; |
| | | |
| | | short downloadMap = 0; |
| | | for (auto s : c.slots) { |
| | | if (s >= 1 && s <= 8) { |
| | | downloadMap |= (short)(1 << (s - 1)); |
| | | } |
| | | } |
| | | pPort->setDownloadCassetteMap((short)(pPort->getDownloadCassetteMap() | downloadMap)); |
| | | |
| | | std::vector<uint8_t> newSlots; |
| | | std::vector<void*> newContexts; |
| | | for (auto s : c.slots) { |
| | | auto pGlass = pPort->getGlassFromSlot(s); |
| | | if (pGlass == nullptr) continue; |
| | |
| | | |
| | | |
| | | this->saveState(); |
| | | if (m_listener.onControlJobChanged) { |
| | | notifyControlJobChanged(); |
| | | } |
| | | |
| | | return (int)m_processJobs.size(); |
| | | } |
| | |
| | | } |
| | | m_pControlJob->setPJs(temps); |
| | | this->saveState(); |
| | | if (m_listener.onControlJobChanged) { |
| | | notifyControlJobChanged(); |
| | | } |
| | | |
| | | |
| | | return 0; |
| | |
| | | |
| | | bool CMaster::ceidDefined(uint32_t ceid) const |
| | | { |
| | | return true; |
| | | if (m_allowedCeids.empty()) return true; // backward compatible: treat as all allowed when not configured |
| | | return m_allowedCeids.find(ceid) != m_allowedCeids.end(); |
| | | } |
| | | |
| | | bool CMaster::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; // fallback |
| | | |
| | | 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; |
| | | alarmData.strStartTime = CToolUnits::timeToString2(CToolUnits::getTimestamp()); |
| | | alarmData.strEndTime = ""; |
| | | alarmData.strDescription = descText; |
| | | |
| | | int nAlarmEventId = 0; |
| | | return alarmManager.addAlarm(alarmData, nAlarmEventId); |
| | | } |
| | | |
| | | void CMaster::handleCollectionEvent(uint32_t ceid) |
| | | { |
| | | // 遍历当前 PJ,命中 pauseEvents 时可在此扩展暂停动作 |
| | | bool pausedAny = false; |
| | | for (auto pj : m_processJobs) { |
| | | if (pj == nullptr) continue; |
| | | const auto& pauseList = pj->pauseEvents(); |
| | | if (std::find(pauseList.begin(), pauseList.end(), ceid) != pauseList.end()) { |
| | | LOGW("<Master>PauseEvent hit: CEID=%u, PJ=%s, state=%d", ceid, pj->id().c_str(), (int)pj->state()); |
| | | if (pj->pause()) { |
| | | LOGI("<Master>PJ paused by CEID=%u", ceid); |
| | | pausedAny = true; |
| | | } |
| | | if (m_pControlJob != nullptr && m_pControlJob->state() == CJState::Executing) { |
| | | if (m_pControlJob->pause()) { |
| | | LOGI("<Master>ControlJob paused by CEID=%u", ceid); |
| | | pausedAny = true; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | if (pausedAny && m_listener.onControlJobChanged) { |
| | | // 通知应用层刷新 UI/按钮状态 |
| | | notifyControlJobChanged(); |
| | | } |
| | | if (pausedAny && !m_bPauseAlarmRaised) { |
| | | std::string desc = CToolUnits::formatString("<PauseEvent CEID=%u>", ceid); |
| | | bool raised = false; |
| | | if (m_pModelCtx != nullptr) { |
| | | raised = m_pModelCtx->raiseSoftAlarm(ALID_SOFTWARE_PAUSE_EVENT, desc); |
| | | } |
| | | else { |
| | | raised = raiseSoftAlarm(ALID_SOFTWARE_PAUSE_EVENT, desc); |
| | | } |
| | | if (raised) { |
| | | LOGI("<Master>PauseEvent soft alarm raised, CEID=%u", ceid); |
| | | m_bPauseAlarmRaised = true; |
| | | } |
| | | } |
| | | } |
| | | |
| | | void CMaster::setAllowedCeids(const std::vector<unsigned int>& ceids) |
| | | { |
| | | m_allowedCeids.clear(); |
| | | m_allowedCeids.reserve(ceids.size()); |
| | | for (auto id : ceids) { |
| | | m_allowedCeids.insert(id); |
| | | } |
| | | } |
| | | |
| | | bool CMaster::saveState() const |
| | |
| | | |
| | | |
| | | saveState(); |
| | | if (m_listener.onControlJobChanged) { |
| | | notifyControlJobChanged(); |
| | | } |
| | | |
| | | return true; |
| | | } |
| | |
| | | item->abort(description); |
| | | } |
| | | m_pControlJob->abort(description); |
| | | |
| | | // 先上报一次状态变化(便于 PrJobAbort 触发) |
| | | if (m_listener.onControlJobChanged) { |
| | | notifyControlJobChanged(); |
| | | } |
| | | |
| | | |
| | | // 释放Job相关 |
| | |
| | | |
| | | |
| | | saveState(); |
| | | if (m_listener.onControlJobChanged) { |
| | | notifyControlJobChanged(); |
| | | } |
| | | |
| | | return true; |
| | | } |
| | |
| | | if (pSlot == nullptr) return false; |
| | | |
| | | CGlass* pGlass = (CGlass*)pSlot->getContext(); |
| | | if (pGlass == nullptr) return false; |
| | | |
| | | // Buffer 上限为 1:新搬出时丢弃旧的 |
| | | if (!m_bufGlass.empty()) { |
| | | for (auto* oldGlass : m_bufGlass) { |
| | | if (oldGlass != nullptr) oldGlass->release(); |
| | | } |
| | | m_bufGlass.clear(); |
| | | } |
| | | m_bufGlass.push_back(pGlass); |
| | | pGlass->addRef(); |
| | | pSlot->setContext(nullptr); |
| | |
| | | auto& dataTypes = CServoUtilsTool::getEqDataTypes(); |
| | | auto& bonderTypes = dataTypes[MID_Bonder1]; |
| | | for (size_t i = 0; i < bonderTypes.size(); ++i) { |
| | | m_pCollector->buffersSetChannelName(MID_Bonder1, i + 1, bonderTypes[i].c_str()); |
| | | m_pCollector->buffersSetChannelName(MID_Bonder2, i + 1, bonderTypes[i].c_str()); |
| | | m_pCollector->buffersSetChannelName(MID_Bonder1, (UINT)i + 1, bonderTypes[(UINT)i].c_str()); |
| | | m_pCollector->buffersSetChannelName(MID_Bonder2, (UINT)i + 1, bonderTypes[(UINT)i].c_str()); |
| | | } |
| | | |
| | | auto& vacuumbakeTypes = dataTypes[MID_VacuumBakeA]; |
| | | for (size_t i = 0; i < vacuumbakeTypes.size(); ++i) { |
| | | m_pCollector->buffersSetChannelName(MID_VacuumBakeA, i + 1, vacuumbakeTypes[i].c_str()); |
| | | m_pCollector->buffersSetChannelName(MID_VacuumBakeB, i + 1, vacuumbakeTypes[i].c_str()); |
| | | m_pCollector->buffersSetChannelName(MID_VacuumBakeA, (UINT)i + 1, vacuumbakeTypes[(UINT)i].c_str()); |
| | | m_pCollector->buffersSetChannelName(MID_VacuumBakeB, (UINT)i + 1, vacuumbakeTypes[(UINT)i].c_str()); |
| | | } |
| | | |
| | | auto& coolingTypes = dataTypes[MID_BakeCoolingA]; |
| | |
| | | m_pCollector->buffersSetChannelName(MID_BakeCoolingA, i + 1, coolingTypes[i].c_str()); |
| | | m_pCollector->buffersSetChannelName(MID_BakeCoolingB, i + 1, coolingTypes[i].c_str()); |
| | | } |
| | | |
| | | if (m_curveMode == CurveMode::EmptyChamber) { |
| | | const uint32_t mids[] = { |
| | | MID_Bonder1, MID_Bonder2, |
| | | MID_VacuumBakeA, MID_VacuumBakeB, |
| | | MID_BakeCoolingA, MID_BakeCoolingB |
| | | }; |
| | | for (uint32_t mid : mids) { |
| | | m_pCollector->batchStart(mid, "EMPTY_CHAMBER", 10 * 60 * 1000ULL); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |