DevicesManager.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #include "stdafx.h"
  2. #include <atlbase.h>
  3. #include "DevicesManager.h"
  4. #pragma warning(push)
  5. #pragma warning(disable:4995)
  6. #pragma warning(pop)
  7. //------------------- CDevicesManager ------------------------
  8. CDevicesManager::CDevicesManager()
  9. {
  10. }
  11. CDevicesManager::~CDevicesManager()
  12. {
  13. ClearUp();
  14. }
  15. void CDevicesManager::ClearUp()
  16. {
  17. for (int i = 0; i < m_Devices.GetSize(); i++)
  18. {
  19. for(int j = 0; j < m_Devices[i]->m_Vars.GetSize(); j++ )
  20. {
  21. MTVERIFY(delete m_Devices[i]->m_Vars[j]);
  22. }
  23. m_Devices[i]->m_Vars.RemoveAll();
  24. MTVERIFY(delete m_Devices[i]);
  25. }
  26. m_Devices.RemoveAll();
  27. }
  28. BOOL CDevicesManager::FindDev(CString strName, int &nDeviceIndex)
  29. {
  30. BOOL bResult = FALSE;
  31. for( int i = 0; i < m_Devices.GetSize(); i++ )
  32. {
  33. if( m_Devices[i]->m_strDeviceName == strName )
  34. {
  35. bResult = TRUE;
  36. nDeviceIndex = i;
  37. break;
  38. }
  39. }
  40. return bResult;
  41. }
  42. BOOL CDevicesManager::FindDevByUid(CString strUid, int &nDeviceIndex)
  43. {
  44. BOOL bResult = FALSE;
  45. for( int i = 0; i < m_Devices.GetSize(); i++ )
  46. {
  47. if( m_Devices[i]->m_strUid.Compare(strUid) == 0 )
  48. {
  49. bResult = TRUE;
  50. nDeviceIndex = i;
  51. //LOG4C((LOG_NOTICE, "nDeviceIndex = %d, devuid = %s", nDeviceIndex, m_Devices[i]->m_strUid));
  52. break;
  53. }
  54. }
  55. return bResult;
  56. }
  57. BOOL CDevicesManager::FindDev(CString strIP, int m_nPort, int &nDeviceIndex)
  58. {
  59. BOOL bResult = FALSE;
  60. for( int i = 0; i < m_Devices.GetSize(); i++ )
  61. {
  62. if( m_Devices[i]->m_strIp == strIP &&
  63. m_Devices[i]->m_iIpport == m_nPort )
  64. {
  65. bResult = TRUE;
  66. nDeviceIndex = i;
  67. break;
  68. }
  69. }
  70. return bResult;
  71. }
  72. BOOL CDevicesManager::FindVar(int nDeviceIndex, int nVarID, int &nVarIndex)
  73. {
  74. BOOL bResult = FALSE;
  75. CDevice* pDevice = m_Devices[nDeviceIndex];
  76. for( int i = 0; i < pDevice->m_Vars.GetSize(); i++ )
  77. {
  78. CBaseVar *pBaseVar = pDevice->m_Vars[i];
  79. if( pBaseVar->m_nVarID == nVarID )
  80. {
  81. bResult = TRUE;
  82. nVarIndex = i;
  83. break;
  84. }
  85. }
  86. return bResult;
  87. }
  88. //声光报警是否在报警状态
  89. bool CDevicesManager::AWA_DoDataISData( CString sDoStatus,int iData )
  90. {
  91. BOOL bResult = FALSE;
  92. CDevice* pDevice=NULL;
  93. for( int i = 0; i < m_Devices.GetSize(); i++ )
  94. {
  95. pDevice = m_Devices[i];
  96. for( int m = 0; m < pDevice->m_Vars.GetSize(); m++ )
  97. {
  98. CBaseVar *pBaseVar = pDevice->m_Vars[m];
  99. if( pBaseVar->m_strName == sDoStatus )
  100. {
  101. if( int(pBaseVar->m_dbData)==iData )
  102. return true;
  103. else
  104. return false;
  105. }
  106. }
  107. }
  108. return bResult;
  109. }
  110. //得到变量是否是报警状态
  111. bool CDevicesManager::AWA_VarIsAlarm( CString sVarName )
  112. {
  113. BOOL bResult = FALSE;
  114. CDevice* pDevice=NULL;
  115. //LOG4C((LOG_NOTICE, "m_Devices.GetSize() = %d",m_Devices.GetSize() ));
  116. for( int i = 0; i < m_Devices.GetSize(); i++ )
  117. {
  118. pDevice = m_Devices[i];
  119. //LOG4C((LOG_NOTICE, "pDevice->m_Vars.GetSize()= %d",pDevice->m_Vars.GetSize() ));
  120. for( int m = 0; m < pDevice->m_Vars.GetSize(); m++ )
  121. {
  122. CBaseVar *pBaseVar = pDevice->m_Vars[m];
  123. if( pBaseVar->m_strName == sVarName )
  124. {
  125. //LOG4C((LOG_NOTICE, "%s ,m_bReserved2=%d,m_nAlarmStatus=%d ",sVarName,pBaseVar->m_bReserved2,pBaseVar->m_nAlarmStatus ));
  126. if( !pBaseVar->m_bReserved2 || pBaseVar->m_nAlarmStatus!=2 )
  127. return false;
  128. else if( pBaseVar->m_nAlarmStatus==2 )
  129. return true;
  130. }
  131. }
  132. }
  133. return bResult;
  134. }