123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- #include "stdafx.h"
- #include <atlbase.h>
- #include "DevicesManager.h"
- #pragma warning(push)
- #pragma warning(disable:4995)
- #pragma warning(pop)
- //------------------- CDevicesManager ------------------------
- CDevicesManager::CDevicesManager()
- {
- }
- CDevicesManager::~CDevicesManager()
- {
- ClearUp();
- }
- void CDevicesManager::ClearUp()
- {
- for (int i = 0; i < m_Devices.GetSize(); i++)
- {
- for(int j = 0; j < m_Devices[i]->m_Vars.GetSize(); j++ )
- {
- MTVERIFY(delete m_Devices[i]->m_Vars[j]);
- }
- m_Devices[i]->m_Vars.RemoveAll();
- MTVERIFY(delete m_Devices[i]);
- }
- m_Devices.RemoveAll();
- }
- BOOL CDevicesManager::FindDev(CString strName, int &nDeviceIndex)
- {
- BOOL bResult = FALSE;
- for( int i = 0; i < m_Devices.GetSize(); i++ )
- {
- if( m_Devices[i]->m_strDeviceName == strName )
- {
- bResult = TRUE;
- nDeviceIndex = i;
- break;
- }
- }
- return bResult;
- }
- BOOL CDevicesManager::FindDevByUid(CString strUid, int &nDeviceIndex)
- {
- BOOL bResult = FALSE;
- for( int i = 0; i < m_Devices.GetSize(); i++ )
- {
- if( m_Devices[i]->m_strUid.Compare(strUid) == 0 )
- {
- bResult = TRUE;
- nDeviceIndex = i;
- //LOG4C((LOG_NOTICE, "nDeviceIndex = %d, devuid = %s", nDeviceIndex, m_Devices[i]->m_strUid));
- break;
- }
- }
- return bResult;
- }
- BOOL CDevicesManager::FindDev(CString strIP, int m_nPort, int &nDeviceIndex)
- {
- BOOL bResult = FALSE;
- for( int i = 0; i < m_Devices.GetSize(); i++ )
- {
- if( m_Devices[i]->m_strIp == strIP &&
- m_Devices[i]->m_iIpport == m_nPort )
- {
- bResult = TRUE;
- nDeviceIndex = i;
- break;
- }
- }
- return bResult;
- }
- BOOL CDevicesManager::FindVar(int nDeviceIndex, int nVarID, int &nVarIndex)
- {
- BOOL bResult = FALSE;
- CDevice* pDevice = m_Devices[nDeviceIndex];
- for( int i = 0; i < pDevice->m_Vars.GetSize(); i++ )
- {
- CBaseVar *pBaseVar = pDevice->m_Vars[i];
- if( pBaseVar->m_nVarID == nVarID )
- {
- bResult = TRUE;
- nVarIndex = i;
- break;
- }
- }
- return bResult;
- }
- //声光报警是否在报警状态
- bool CDevicesManager::AWA_DoDataISData( CString sDoStatus,int iData )
- {
- BOOL bResult = FALSE;
- CDevice* pDevice=NULL;
- for( int i = 0; i < m_Devices.GetSize(); i++ )
- {
- pDevice = m_Devices[i];
-
- for( int m = 0; m < pDevice->m_Vars.GetSize(); m++ )
- {
- CBaseVar *pBaseVar = pDevice->m_Vars[m];
- if( pBaseVar->m_strName == sDoStatus )
- {
- if( int(pBaseVar->m_dbData)==iData )
- return true;
- else
- return false;
- }
- }
- }
- return bResult;
- }
- //得到变量是否是报警状态
- bool CDevicesManager::AWA_VarIsAlarm( CString sVarName )
- {
- BOOL bResult = FALSE;
- CDevice* pDevice=NULL;
- //LOG4C((LOG_NOTICE, "m_Devices.GetSize() = %d",m_Devices.GetSize() ));
- for( int i = 0; i < m_Devices.GetSize(); i++ )
- {
- pDevice = m_Devices[i];
- //LOG4C((LOG_NOTICE, "pDevice->m_Vars.GetSize()= %d",pDevice->m_Vars.GetSize() ));
- for( int m = 0; m < pDevice->m_Vars.GetSize(); m++ )
- {
- CBaseVar *pBaseVar = pDevice->m_Vars[m];
- if( pBaseVar->m_strName == sVarName )
- {
- //LOG4C((LOG_NOTICE, "%s ,m_bReserved2=%d,m_nAlarmStatus=%d ",sVarName,pBaseVar->m_bReserved2,pBaseVar->m_nAlarmStatus ));
- if( !pBaseVar->m_bReserved2 || pBaseVar->m_nAlarmStatus!=2 )
- return false;
- else if( pBaseVar->m_nAlarmStatus==2 )
- return true;
- }
- }
- }
- return bResult;
- }
|