#include "stdafx.h" #include "CMaster.h" namespace SERVO { CMaster* g_pMaster = NULL; void CALLBACK MasterTimerProc(HWND hWnd, UINT nMsg, UINT nTimerid, DWORD dwTime) { if (g_pMaster != NULL) { g_pMaster->onTimer(nTimerid); } } CMaster::CMaster() { m_listener = {nullptr}; } CMaster::~CMaster() { for (auto item : m_listEquipment) { delete item; } m_listEquipment.clear(); } void CMaster::setListener(MasterListener listener) { m_listener.onEqAlive = listener.onEqAlive; } int CMaster::init() { LOGI("ÕýÔÚ³õʼ»¯..."); // cclink if (m_cclink.Connect(CC_LINK_IE_CONTROL_CHANNEL(1)) != 0) { LOGE("Á¬½ÓCC-Linkʧ°Ü."); return -1; } else { LOGI("Á¬½ÓCC-Link³É¹¦."); BoardVersion version{}; int nRet = m_cclink.GetBoardVersion(version); if (nRet == 0) { LOGI("°æ±¾ÐÅÏ¢£º%s.", version.toString().c_str()); } else { LOGE("»ñÈ¡CC-Link°æ±¾ÐÅϢʧ°Ü."); } BoardStatus status; nRet = m_cclink.GetBoardStatus(status); if (nRet == 0) { LOGI("״̬£º%s.", status.toString().c_str()); } else { LOGE("»ñÈ¡CC-Link״̬ʧ°Ü."); } } // ³õʼ»¯Ìí¼Ó¸÷×ÓÉ豸 { CEFEM* pEquipment = new CEFEM(); pEquipment->setName("EFEM(ROBOT)"); pEquipment->setDescription("EFEM(ROBOT)."); pEquipment->setReadBitBlock(0x4000, 0x45ff); pEquipment->setStation(1, 2); addEquipment(pEquipment); LOGE("ÒÑÌí¼Ó¡°EFEM(ROBOT)¡±."); } /* { CBonder* pBonder = new CBonder(); pBonder->setName("Bonder 1"); pBonder->setDescription("Bonder 1."); pBonder->setReadBitBlock(0x4600, 0x4bff); pBonder->setStation(1, 3); addEquipment(pBonder); LOGE("ÒÑÌí¼Ó¡°Bonder 1¡±."); } */ // ¶¨Ê±Æ÷ g_pMaster = this; SetTimer(NULL, 1, 250, (TIMERPROC)MasterTimerProc); LOGI("³õʼ»¯Íê³É."); return 0; } int CMaster::term() { return 0; } int CMaster::addEquipment(CEquipment* pEquipment) { EquipmentListener listener; listener.onAlive = [&](void* pEquipment, BOOL bAlive) -> void { CEquipment* p = (CEquipment*)pEquipment; if (m_listener.onEqAlive != nullptr) { m_listener.onEqAlive(this, p, bAlive); } }; pEquipment->setListener(listener); m_listEquipment.push_back(pEquipment); return 0; } void CMaster::onTimer(UINT nTimerid) { for (auto item : m_listEquipment) { item->onTimer(nTimerid); } // °´Ò»¶¨ÆµÂÊɨÃèLBÊý¾Ý static int i = 0; i++; if (i % (4 * 1) == 0) { for (auto item : m_listEquipment) { const StationIdentifier& station = item->getStation(); MemoryBlock& block = item->getReadBitBlock(); int nRet = m_cclink.ReadData2(station, (short)block.type, block.start, block.size, block.buffer); if (0 == nRet) { item->onReceiveLBData(block.buffer, block.size); } } } } }