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.

175 lines
4.8 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: LgNetDeviceGPIOPCI1762.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of LgNetDeviceGPIOPCI1762.cpp
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "LgNetDeviceGPIOPCI1762.h"
  16. CLgNetDeviceGPIOPCI1762::CLgNetDeviceGPIOPCI1762()
  17. {
  18. }
  19. CLgNetDeviceGPIOPCI1762::~CLgNetDeviceGPIOPCI1762()
  20. {
  21. // nessesary to do it, because "vtable" will be cleared before
  22. // parent's destructor will be called
  23. Destroy();
  24. }
  25. BOOL CLgNetDeviceGPIOPCI1762::Create( INT nDevice )
  26. {
  27. if( !CLgDeviceGPIOPCI1762::Create( nDevice ) )
  28. return FALSE;
  29. // CLgNetDevice::SetID( 1 );
  30. m_OutMsg.SetSenderID( CLgNetDevice::GetID() );
  31. return CLgThread::Start( FALSE );
  32. }
  33. void CLgNetDeviceGPIOPCI1762::Destroy()
  34. {
  35. CLgThread::Stop( TRUE );
  36. }
  37. DWORD CLgNetDeviceGPIOPCI1762::ThreadProc()
  38. {
  39. BOOL bLoop = TRUE;
  40. while( bLoop )
  41. {
  42. // as fast as possible but without overheating :)
  43. switch( ::WaitForSingleObject( CLgThread::GetThreadStopEvent(), 0UL ) )
  44. {
  45. default:
  46. case WAIT_FAILED:
  47. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgNetDeviceGPIOCOM::ThreadProc"), _T("WaitForSingleObject failed with 0x%08X"), ::GetLastError() );
  48. case WAIT_OBJECT_0:
  49. bLoop = FALSE;
  50. continue;
  51. case WAIT_TIMEOUT:
  52. break;
  53. }
  54. // check input command
  55. if( CLgDevice::IsReadyForCmd() && CLgNetDevice::PopMessage( m_InMsg ) )
  56. {
  57. m_OutMsg.SetDistinationID( m_InMsg.GetSenderID() );
  58. // depend on command
  59. BYTE bCommand;
  60. if( m_InMsg.GetCommand( &bCommand ) )
  61. {
  62. CLgDeviceGPIO::GPIO_PIN pin;
  63. switch( bCommand )
  64. {
  65. case CLgDeviceGPIO::CMD_GET_OUTPUT:
  66. if( m_InMsg.GetOutput( &pin ) )
  67. CmdGetOutput( pin.nIndex );
  68. break;
  69. case CLgDeviceGPIO::CMD_GET_OUTPUT_ALL:
  70. CmdGetOutputAll();
  71. break;
  72. case CLgDeviceGPIO::CMD_SET_OUTPUT:
  73. if( m_InMsg.GetOutput( &pin ) )
  74. CmdSetOutput( pin.nIndex, pin.bOn );
  75. break;
  76. case CLgDeviceGPIO::CMD_GET_INPUT:
  77. if( m_InMsg.GetInput( &pin ) )
  78. CmdGetInput( pin.nIndex );
  79. else
  80. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgNetDeviceGPIOPCI1762::ThreadProc"), _T("m_InMsg.GetInput failed") );
  81. break;
  82. case CLgDeviceGPIO::CMD_GET_INPUT_ALL:
  83. CmdGetInputAll();
  84. break;
  85. default:
  86. OnEvtCommandError( -1, _T("UNKNOWN COMMAND") );
  87. break;
  88. }
  89. }
  90. }
  91. // call port processing routine
  92. ReadWriteProc( 1UL );
  93. }
  94. return 0UL;
  95. }
  96. void CLgNetDeviceGPIOPCI1762::OnEvtGetOutput( INT nOutput, BOOL bOn )
  97. {
  98. m_OutMsg.BuildEvtGetOutput( nOutput, bOn );
  99. SendMessageToParent( m_OutMsg );
  100. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgNetDeviceGPIOPCI1762::OnEvtGetOutput", "%d,%d", nOutput, bOn );
  101. }
  102. void CLgNetDeviceGPIOPCI1762::OnEvtSetOutput( INT nOutput, BOOL bOn )
  103. {
  104. m_OutMsg.BuildEvtSetOutput( nOutput, bOn );
  105. SendMessageToParent( m_OutMsg );
  106. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgNetDeviceGPIOPCI1762::OnEvtSetOutput", "%d,%d", nOutput, bOn );
  107. }
  108. void CLgNetDeviceGPIOPCI1762::OnEvtGetInput( INT nInput, BOOL bOn )
  109. {
  110. m_OutMsg.BuildEvtGetInput( nInput, bOn );
  111. SendMessageToParent( m_OutMsg );
  112. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgNetDeviceGPIOPCI1762::OnEvtGetInput", "%d,%d", nInput, bOn );
  113. }
  114. void CLgNetDeviceGPIOPCI1762::OnEvtInputChange( INT nInput, BOOL bOn )
  115. {
  116. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgNetDeviceGPIOPCI1762::OnEvtInputChange", "%d,%d", nInput, bOn );
  117. m_OutMsg.BuildEvtInputChange( nInput, bOn );
  118. if( !SendMessageToParent( m_OutMsg ) )
  119. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, "CLgNetDeviceGPIOPCI1762::OnEvtInputChange", "Cant' send event" );
  120. }
  121. void CLgNetDeviceGPIOPCI1762::OnEvtGetOutputAll( PGPIO_PINS pPins )
  122. {
  123. m_OutMsg.BuildEvtGetOutputAll( pPins );
  124. SendMessageToParent( m_OutMsg );
  125. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgNetDeviceGPIOPCI1762::OnEvtGetOutputAll" );
  126. }
  127. void CLgNetDeviceGPIOPCI1762::OnEvtGetInputAll( PGPIO_PINS pPins )
  128. {
  129. m_OutMsg.BuildEvtGetInputAll( pPins );
  130. SendMessageToParent( m_OutMsg );
  131. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgNetDeviceGPIOPCI1762::OnEvtGetInputAll" );
  132. }
  133. void CLgNetDeviceGPIOPCI1762::OnEvtCommandError( INT nCommand, LPCTSTR pFormat, ... )
  134. {
  135. va_list marker;
  136. va_start( marker, pFormat );
  137. m_OutMsg.BuildEvtCommandError( nCommand, pFormat, marker );
  138. va_end( marker );
  139. CLgNetObject::SendMessageToParent( m_OutMsg );
  140. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgNetDeviceGPIOPCI1762::OnEvtCommandError" );
  141. }