| | |
| | | #include "Model.h" |
| | | #include "Log.h" |
| | | #include "ToolUnits.h" |
| | | #include "Alarm.h" |
| | | #include "EQState.h" |
| | | |
| | | |
| | | CModel* g_pModel = NULL; |
| | |
| | | void CModel::setWorkDir(const char* pszWorkDir) |
| | | { |
| | | m_strWorkDir = pszWorkDir; |
| | | m_bonder.setWorkDir(pszWorkDir); |
| | | } |
| | | |
| | | int CModel::init() |
| | |
| | | LOGI("\r\n\r\n~~~ Prog Start! ~~~"); |
| | | |
| | | |
| | | // 创建Servo |
| | | // ??Servo |
| | | BEQ_CreateEquipment(m_pEquipment, "BLBonder"); |
| | | ASSERT(m_pEquipment); |
| | | BEQ::EquipmentListener listener; |
| | | listener.onConnected = [&](void* pEiuipment, const char* pszAddr, int port) -> void { |
| | | LOGI("<EquipmentListener>连接进入(%s:%d).", pszAddr, port); |
| | | LOGI("<EquipmentListener>????(%s:%d).", pszAddr, port); |
| | | notifyPtr(RX_CODE_EQ_STATE_CHANGED, pEiuipment); |
| | | }; |
| | | listener.onDisconnected = [&](void* pEiuipment, const char* pszAddr, int port) -> void { |
| | | LOGI("<EquipmentListener>连接断开(%s:%d).", pszAddr, port); |
| | | LOGI("<EquipmentListener>????(%s:%d).", pszAddr, port); |
| | | notifyPtr(RX_CODE_EQ_STATE_CHANGED, pEiuipment); |
| | | }; |
| | | // 注意此处还有几个回调函数未处理 |
| | | // ??????????????? |
| | | m_pEquipment->setEquipmentListener(listener); |
| | | |
| | | |
| | | m_pObservable = RX_AllocaObservable([&](IObservableEmitter* e) -> void { |
| | | m_pObservableEmitter = e; // 保存发射器 |
| | | m_pObservableEmitter = e; // ????? |
| | | }); |
| | | |
| | | |
| | |
| | | g_pModel = this; |
| | | |
| | | |
| | | BondListener bonderListener; |
| | | bonderListener.onStateChanged = [&](void* pFrom, int state) -> void { |
| | | notifyInt(RX_CODE_BONDER_STATE_CHANGED, state); |
| | | }; |
| | | bonderListener.onPlcStateChanged = [&](void* pFrom, int state) -> void { |
| | | PLCSTATE ps = (PLCSTATE)state; |
| | | if (ps == PLCSTATE::CONNECTED) { |
| | | notifyPtrAndInt(RX_CODE_PLC1_CONNECTTD, pFrom, 0, state); |
| | | } |
| | | else if (ps == PLCSTATE::DISCONNECTED) { |
| | | notifyPtrAndInt(RX_CODE_PLC1_DISCONNECTTD, pFrom, 0, state); |
| | | } |
| | | }; |
| | | bonderListener.onEfemStateChanged = [&](void* pFrom, const char* pszAddr, int port, int state) -> void { |
| | | if (m_pObservableEmitter != NULL) { |
| | | IAny* pAny = RX_AllocaAny(); |
| | | if (pAny != NULL) { |
| | | pAny->addRef(); |
| | | pAny->setCode(RX_CODE_EFEM_STATUS_CHANGED); |
| | | pAny->setStringValue("addr", pszAddr); |
| | | pAny->setIntValue("port", port); |
| | | pAny->setIntValue("state", state); |
| | | m_pObservableEmitter->onNext(pAny); |
| | | pAny->release(); |
| | | } |
| | | } |
| | | }; |
| | | bonderListener.onRecvBroadcast = [&](void* pFrom, void* p) -> void { |
| | | CComponent* pSender = (CComponent*)pFrom; |
| | | CIntent* pIntent = (CIntent*)p; |
| | | int code = pIntent->getCode(); |
| | | if (code == BC_CODE_DATA1_MATERIAL_RECEIVED) { |
| | | notifyPtr(RX_CODE_DATA1_MATERIAL_RECEIVED, pSender); |
| | | } |
| | | else if (code == BC_CODE_DATA1_BEGIN_SAMPLING) { |
| | | notifyPtr(RX_CODE_DATA1_BEGIN_SAMPLING, pSender); |
| | | } |
| | | else if (code == BC_CODE_DATA1_UPDATE) { |
| | | notifyPtr(RX_CODE_DATA1_UPDATE, pSender); |
| | | } |
| | | else if (code == BC_CODE_DATA1_END_SAMPLING) { |
| | | notifyPtr(RX_CODE_DATA1_END_SAMPLING, pSender); |
| | | } |
| | | else if (code == BC_CODE_DATA1_MATERIAL_REMOVED) { |
| | | std::string strError; |
| | | CPanel* pPanel = (CPanel*)pIntent->getContext(); |
| | | pPanel->addRef(); |
| | | savePanel(pPanel, pSender); |
| | | m_sqlite.insertPanel(pPanel, strError); |
| | | notifyPtr(RX_CODE_DATA1_MATERIAL_REMOVEED, pSender); |
| | | notifyObj(RX_CODE_PANEL_COMPLATE, pPanel); |
| | | pPanel->release(); |
| | | } |
| | | else if (code == BC_CODE_ALARM_EVENT) { |
| | | CAlarm* pAlarm = (CAlarm*)pIntent->getContext(); |
| | | pAlarm->addRef(); |
| | | notifyObjAndPtr(RX_CODE_ALARM_EVENT, pAlarm, pSender); |
| | | pAlarm->release(); |
| | | } |
| | | else if (code == BC_CODE_EQSTATE_EVENT) { |
| | | CEQState* pState = (CEQState*)pIntent->getContext(); |
| | | pState->addRef(); |
| | | notifyObjAndPtr(RX_CODE_EQSTATE_EVENT, pState, pSender); |
| | | pState->release(); |
| | | } |
| | | }; |
| | | m_bonder.setListener(bonderListener); |
| | | m_bonder.init(); |
| | | |
| | | |
| | | return 0; |
| | | } |
| | | |
| | | int CModel::term() |
| | | { |
| | | m_bonder.save(); |
| | | m_bonder.term(); |
| | | m_sqlite.term(); |
| | | |
| | | CLog::GetLog()->SetOnLogCallback(nullptr); |
| | | return 0; |
| | | } |
| | |
| | | void CModel::onTimer(UINT nTimerid) |
| | | { |
| | | |
| | | } |
| | | } |
| | | |
| | | int CModel::savePanel(CPanel* pPanel, CComponent* pComponent) |
| | | { |
| | | int year, month, day; |
| | | pPanel->getReceivedTime(year, month, day); |
| | | CString strDir, strFilepath; |
| | | strDir.Format("%s\\%d\\%d\\%d", (LPTSTR)(LPCTSTR)m_strDataDir, year, month, day); |
| | | CToolUnits::createDir((LPTSTR)(LPCTSTR)strDir); |
| | | strFilepath.Format("%s\\%s.csv", (LPTSTR)(LPCTSTR)strDir, pPanel->getQRCode().c_str()); |
| | | |
| | | CStdioFile file; |
| | | if (!file.Open(strFilepath, CFile::modeCreate | CFile::modeWrite)) { |
| | | return -1; |
| | | } |
| | | |
| | | // ???? |
| | | // ??, id,??????,?????? |
| | | CString strLine; |
| | | file.WriteString("# ??\n"); |
| | | strLine.Format(_T("??,%s\n"), pComponent->getName().c_str()); |
| | | file.WriteString(strLine); |
| | | strLine.Format(_T("id,%s\n"), pPanel->getQRCode().c_str()); |
| | | file.WriteString(strLine); |
| | | strLine.Format(_T("????,%s\n"), |
| | | CToolUnits::timeToString3(pPanel->getReceivedTime()).c_str()); |
| | | file.WriteString(strLine); |
| | | strLine.Format(_T("??????,%s\n"), |
| | | CToolUnits::timeToString3(pPanel->getBeginSamplingTime()).c_str()); |
| | | file.WriteString(strLine); |
| | | strLine.Format(_T("??????,%s\n"), |
| | | CToolUnits::timeToString3(pPanel->getEndSamplingTime()).c_str()); |
| | | file.WriteString(strLine); |
| | | strLine.Format(_T("????,%s\n"), |
| | | CToolUnits::timeToString3(pPanel->getRemovedTime()).c_str()); |
| | | file.WriteString(strLine); |
| | | strLine.Format(_T("Recipe name,%s\n"), pPanel->getRecipeName().c_str()); |
| | | file.WriteString(strLine); |
| | | strLine.Format(_T("??????,%f\n"), pPanel->getAir1()); |
| | | file.WriteString(strLine); |
| | | strLine.Format(_T("???????,%f\n"), pPanel->getAir2()); |
| | | file.WriteString(strLine); |
| | | strLine.Format(_T("?????,%f\n"), pPanel->getAir3()); |
| | | file.WriteString(strLine); |
| | | strLine.Format(_T("?????,%d\n"), pPanel->getPre1()); |
| | | file.WriteString(strLine); |
| | | strLine.Format(_T("?????,%f\n"), pPanel->getTmp1()); |
| | | file.WriteString(strLine); |
| | | strLine.Format(_T("?????,%f\n"), pPanel->getTmp2()); |
| | | file.WriteString(strLine); |
| | | file.WriteString("\n"); |
| | | |
| | | |
| | | // ??? |
| | | file.WriteString("# ??\n"); |
| | | file.WriteString("?,?????(?),?????(?),?????1(?),?????2(?),?????3(?),?????4(?),?????5(?),?????1(?),?????2(?),?????3(?),?????4(?),?????5(?),????(Pa),????1(Kg),????2(Kg),????3(Kg),????4(Kg),????5(Kg)\n"); |
| | | UNITDATA1 dataMax = pPanel->getMathData(IMAX); |
| | | strLine.Format(_T("???,%.01f,%.01f,%.01f,%.01f,%.01f,%.01f,%.01f,%.01f,%.01f,%.01f,%.03f,%.01f,%.01f,%.01f,%.01f,%.01f,%.01f,%.01f\n"), |
| | | dataMax.temp[0], dataMax.temp[1], |
| | | dataMax.temp[2], dataMax.temp[3], dataMax.temp[4], dataMax.temp[5], dataMax.temp[6], |
| | | dataMax.temp[7], dataMax.temp[8], dataMax.temp[9], dataMax.temp[10], dataMax.temp[11], |
| | | dataMax.vacuum, |
| | | dataMax.pressure[0], dataMax.pressure[1], dataMax.pressure[2], |
| | | dataMax.pressure[3], dataMax.pressure[4]); |
| | | file.WriteString(strLine); |
| | | |
| | | UNITDATA1 dataMin = pPanel->getMathData(IMIN); |
| | | strLine.Format(_T("???,%.01f,%.01f,%.01f,%.01f,%.01f,%.01f,%.01f,%.01f,%.01f,%.01f,%.03f,%.01f,%.01f,%.01f,%.01f,%.01f,%.01f,%.01f\n"), |
| | | dataMin.temp[0], dataMin.temp[1], |
| | | dataMin.temp[2], dataMin.temp[3], dataMin.temp[4], dataMin.temp[5], dataMin.temp[6], |
| | | dataMin.temp[7], dataMin.temp[8], dataMin.temp[9], dataMin.temp[10], dataMin.temp[11], |
| | | dataMin.vacuum, |
| | | dataMin.pressure[0], dataMin.pressure[1], dataMin.pressure[2], |
| | | dataMin.pressure[3], dataMin.pressure[4]); |
| | | file.WriteString(strLine); |
| | | |
| | | UNITDATA1 dataAve = pPanel->getMathData(IAVE); |
| | | strLine.Format(_T("???,%.01f,%.01f,%.01f,%.01f,%.01f,%.01f,%.01f,%.01f,%.01f,%.01f,%.03f,%.01f,%.01f,%.01f,%.01f,%.01f,%.01f,%.01f\n"), |
| | | dataAve.temp[0], dataAve.temp[1], |
| | | dataAve.temp[2], dataAve.temp[3], dataAve.temp[4], dataAve.temp[5], dataAve.temp[6], |
| | | dataAve.temp[7], dataAve.temp[8], dataAve.temp[9], dataAve.temp[10], dataAve.temp[11], |
| | | dataAve.vacuum, |
| | | dataAve.pressure[0], dataAve.pressure[1], dataAve.pressure[2], |
| | | dataAve.pressure[3], dataAve.pressure[4]); |
| | | file.WriteString(strLine); |
| | | file.WriteString("\n"); |
| | | |
| | | |
| | | // ??? |
| | | file.WriteString("# ???\n"); |
| | | file.WriteString("??,?????(?),?????(?),?????1(?),?????2(?),?????3(?),?????4(?),?????5(?),?????1(?),?????2(?),?????3(?),?????4(?),?????5(?),????(Pa),????1(Kg),????2(Kg),????3(Kg),????4(Kg),????5(Kg)\n"); |
| | | std::vector<UNITDATA1> datas; |
| | | pPanel->getDatas(datas); |
| | | for (auto item : datas) { |
| | | strLine.Format(_T("%s,%.01f,%.01f,%.01f,%.01f,%.01f,%.01f,%.01f,%.01f,%.01f,%.01f,%.03f,%.01f,%.01f,%.01f,%.01f,%.01f,%.01f,%.01f\n"), |
| | | CToolUnits::timeToString3(item.time).c_str(), |
| | | item.temp[0], item.temp[1], |
| | | item.temp[2], item.temp[3], item.temp[4], item.temp[5], item.temp[6], |
| | | item.temp[7], item.temp[8], item.temp[9], item.temp[10], item.temp[11], |
| | | item.vacuum, |
| | | item.pressure[0], item.pressure[1], item.pressure[2], |
| | | item.pressure[3], item.pressure[4]); |
| | | file.WriteString(strLine); |
| | | } |
| | | |
| | | |
| | | file.Close(); |
| | | |
| | | return 0; |
| | | } |