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.

171 lines
4.5 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: LgNetDeviceGPIOLPT.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of LgNetDeviceGPIOLPT.cpp
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "LgNetDeviceGPIOLPT.h"
  16. CLgNetDeviceGPIOLPT::CLgNetDeviceGPIOLPT()
  17. {
  18. }
  19. CLgNetDeviceGPIOLPT::~CLgNetDeviceGPIOLPT()
  20. {
  21. // nessesary to do it, because "vtable" will be cleared before
  22. // parent's destructor will be called
  23. Destroy();
  24. }
  25. BOOL CLgNetDeviceGPIOLPT::Create( LPCTSTR pPort, BOOL bDataOutput )
  26. {
  27. if( !CLgDeviceGPIOLPT::Create( pPort, bDataOutput ) )
  28. return FALSE;
  29. // CLgNetDevice::SetID( 1 );
  30. m_OutMsg.SetSenderID( CLgNetDevice::GetID() );
  31. return CLgThread::Start( FALSE );
  32. }
  33. void CLgNetDeviceGPIOLPT::Destroy()
  34. {
  35. CLgThread::Stop( TRUE );
  36. }
  37. DWORD CLgNetDeviceGPIOLPT::ThreadProc()
  38. {
  39. BOOL bLoop = TRUE;
  40. while( bLoop )
  41. {
  42. // as fast as possible but without overheating :)
  43. switch( ::WaitForSingleObject( CLgThread::GetThreadStopEvent(), 1UL ) )
  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. break;
  80. case CLgDeviceGPIO::CMD_GET_INPUT_ALL:
  81. CmdGetInputAll();
  82. break;
  83. default:
  84. OnEvtCommandError( -1, _T("UNKNOWN COMMAND") );
  85. break;
  86. }
  87. }
  88. }
  89. // call port processing routine
  90. CLgDeviceGPIOLPT::ReadWriteProc();
  91. }
  92. return 0UL;
  93. }
  94. void CLgNetDeviceGPIOLPT::OnEvtGetOutput( INT nOutput, BOOL bOn )
  95. {
  96. m_OutMsg.BuildEvtGetOutput( nOutput, bOn );
  97. SendMessageToParent( m_OutMsg );
  98. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgNetDeviceGPIOLPT::OnEvtGetOutput", "%d,%d", nOutput, bOn );
  99. }
  100. void CLgNetDeviceGPIOLPT::OnEvtSetOutput( INT nOutput, BOOL bOn )
  101. {
  102. m_OutMsg.BuildEvtSetOutput( nOutput, bOn );
  103. SendMessageToParent( m_OutMsg );
  104. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgNetDeviceGPIOLPT::OnEvtSetOutput", "%d,%d", nOutput, bOn );
  105. }
  106. void CLgNetDeviceGPIOLPT::OnEvtGetInput( INT nInput, BOOL bOn )
  107. {
  108. m_OutMsg.BuildEvtGetInput( nInput, bOn );
  109. SendMessageToParent( m_OutMsg );
  110. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgNetDeviceGPIOLPT::OnEvtGetInput", "%d,%d", nInput, bOn );
  111. }
  112. void CLgNetDeviceGPIOLPT::OnEvtInputChange( INT nInput, BOOL bOn )
  113. {
  114. m_OutMsg.BuildEvtInputChange( nInput, bOn );
  115. SendMessageToParent( m_OutMsg );
  116. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgNetDeviceGPIOLPT::OnEvtInputChange", "%d,%d", nInput, bOn );
  117. }
  118. void CLgNetDeviceGPIOLPT::OnEvtGetOutputAll( PGPIO_PINS pPins )
  119. {
  120. m_OutMsg.BuildEvtGetOutputAll( pPins );
  121. SendMessageToParent( m_OutMsg );
  122. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgNetDeviceGPIOLPT::OnEvtGetOutputAll" );
  123. }
  124. void CLgNetDeviceGPIOLPT::OnEvtGetInputAll( PGPIO_PINS pPins )
  125. {
  126. m_OutMsg.BuildEvtGetInputAll( pPins );
  127. SendMessageToParent( m_OutMsg );
  128. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgNetDeviceGPIOLPT::OnEvtGetInputAll" );
  129. }
  130. void CLgNetDeviceGPIOLPT::OnEvtCommandError( INT nCommand, LPCTSTR pFormat, ... )
  131. {
  132. va_list marker;
  133. va_start( marker, pFormat );
  134. m_OutMsg.BuildEvtCommandError( nCommand, pFormat, marker );
  135. va_end( marker );
  136. CLgNetObject::SendMessageToParent( m_OutMsg );
  137. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgNetDeviceGPIOLPT::OnEvtCommandError" );
  138. }