#include "stdafx.h" #include "Common.h" #include "Component.h" #include "Log.h" #include "CBonder.h" CComponent::CComponent() { m_pBonder = NULL; m_pChannel1 = NULL; m_nIndex = 0; m_bRunning = FALSE; InitializeCriticalSection(&m_criticalSection); } CComponent::~CComponent() { DeleteCriticalSection(&m_criticalSection); } void CComponent::setBonder(CBonder* pBonder) { m_pBonder = pBonder; } void CComponent::init() { MCL_GetChannel(m_pChannel1, MC_CHANNEL1_NAME); } void CComponent::term() { } int CComponent::run() { m_bRunning = TRUE; return 0; } int CComponent::stop() { m_bRunning = FALSE; return 0; } void CComponent::setName(const char* pszName) { m_strName = pszName; } std::string& CComponent::getName() { return m_strName; } void CComponent::setDescription(const char* pszDescription) { m_strDescription = pszDescription; } std::string& CComponent::getDescription() { return m_strDescription; } void CComponent::setIndex(int index) { m_nIndex = index; } int CComponent::getIndex() { return m_nIndex; } void CComponent::onRecvBroadcast(void* pSender, CIntent* pIntent) { } void CComponent::onData(int id, const void* pData, int size) { } void CComponent::SendBroadcast(CIntent* pIntent) { m_pBonder->sendBroadcast(this, pIntent); } int CComponent::WriteInt(int unitId, int addr, int value) { return m_pBonder->writeInt(unitId, addr, value); } int CComponent::WriteData(MC::SOFT_COMPONENT softComponent, unsigned int addr, const char* pszData, unsigned int length, ONWRITE funOnWrite) { return m_pBonder->writeData(softComponent, addr, pszData, length, funOnWrite); } void CComponent::OnTimer(UINT nTimerid) { } void CComponent::Serialize(CArchive& ar) { } float CComponent::toFloat(const char* pszAddr) { BYTE szBuffer[4]; szBuffer[0] = pszAddr[0]; szBuffer[1] = pszAddr[1]; szBuffer[2] = pszAddr[2]; szBuffer[3] = pszAddr[3]; float f = 0.0; memcpy(&f, szBuffer, 4); return f; }