Old fashion design for PC-104
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
2.7 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 01/01/2000
  5. // Last modification: 08/10/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: LgsBR.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of LgsBR.cpp
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "LgsBR.h"
  16. #include "..\LgLib\Version.h"
  17. #ifdef _DEBUG
  18. #undef THIS_FILE
  19. static char THIS_FILE[]=__FILE__;
  20. #define new DEBUG_NEW
  21. #endif
  22. CLgsBR::CLgsBR()
  23. {
  24. m_hEventGetChannelProperties = NULL;
  25. m_pChannelProperties = NULL;
  26. m_nChannelCount = 0;
  27. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLgsBR::CLgsBR" );
  28. }
  29. CLgsBR::~CLgsBR()
  30. {
  31. Destroy();
  32. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLgsBR::~CLgsBR" );
  33. }
  34. BOOL CLgsBR::OnRemoteBRChannelConnect( INT nChannel, BOOL bResult )
  35. {
  36. return TRUE;
  37. }
  38. BOOL CLgsBR::OnRemoteBRGetChannelProperties( INT nChannelCount, LG_TCP_PACKET_BOARD_RECEIVER::PCHANNEL_PROPERTIES pProperties )
  39. {
  40. INT nSize = sizeof(LG_TCP_PACKET_BOARD_RECEIVER::CHANNEL_PROPERTIES) * nChannelCount;
  41. m_pChannelProperties = (LG_TCP_PACKET_BOARD_RECEIVER::PCHANNEL_PROPERTIES)realloc( m_pChannelProperties, nSize );
  42. if( !m_pChannelProperties )
  43. return FALSE;
  44. // story data
  45. m_nChannelCount = nChannelCount;
  46. memcpy( m_pChannelProperties, pProperties, nSize );
  47. // notify about completion
  48. return SetEvent(m_hEventGetChannelProperties);
  49. }
  50. BOOL CLgsBR::Create()
  51. {
  52. // initialize event object
  53. if( !m_hEventGetChannelProperties )
  54. m_hEventGetChannelProperties = ::CreateEvent( NULL, FALSE, FALSE, NULL );
  55. // test event object
  56. if( !m_hEventGetChannelProperties )
  57. return FALSE;
  58. // reset event
  59. ::ResetEvent( m_hEventGetChannelProperties );
  60. return TRUE;
  61. }
  62. void CLgsBR::Destroy()
  63. {
  64. // delete event
  65. if( m_hEventGetChannelProperties )
  66. {
  67. ::CloseHandle( m_hEventGetChannelProperties );
  68. m_hEventGetChannelProperties = NULL;
  69. }
  70. // delete stored data
  71. if( m_pChannelProperties )
  72. {
  73. free( m_pChannelProperties );
  74. m_pChannelProperties = NULL;
  75. }
  76. }
  77. BOOL CLgsBR::EnumPorts( DWORD Level, LPBYTE pPorts, DWORD cbBuf, LPDWORD pcbNeeded, LPDWORD pcReturned, DWORD dwTimeout )
  78. {
  79. // channel count
  80. m_nChannelCount = 0;
  81. // reset notification event
  82. ResetEvent( m_hEventGetChannelProperties );
  83. // acquare server
  84. if( !DoRemoteBRGetChannelProperties() )
  85. return FALSE;
  86. // if answer don't returned in requested time
  87. if( ::WaitForSingleObject( m_hEventGetChannelProperties, dwTimeout ) != WAIT_OBJECT_0 )
  88. return FALSE;
  89. // prepare info
  90. return TRUE;
  91. }