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.

180 lines
5.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: DevicePCI1762.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of DevicePCI1762.cpp
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "ObjectFactory.h"
  16. #include "DevicePCI1762.h"
  17. #include "..\..\LgLib\Version.h"
  18. CDevicePCI1762::CDevicePCI1762()
  19. {
  20. SetDeviceType( OFNS::DT_PCI_1762 );
  21. CDeviceDI::SetCount( 16 );
  22. CDeviceDO::SetCount( 16 );
  23. for( INT i = 0; i < 16; i++ )
  24. {
  25. OUTPUT_STATE state;
  26. state.bOn = FALSE;
  27. state.bFirstTime = TRUE;
  28. if( !m_OutputState.Add( state ) )
  29. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CDevicePCI1762::CDevicePCI1762"), _T("Can't add output state") );
  30. }
  31. ObjectToParentLinkSP::Link( &m_MsgSink );
  32. m_MsgSink.ObjectToChildLinkP::Link( this );
  33. m_Msg.SetDistinationID( GetID() );
  34. m_Msg.SetSenderID( m_MsgSink.GetID() );
  35. m_Msg.BuildCmdGetInputAll();
  36. PushMessage( m_Msg );
  37. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CDevicePCI1762::CDevicePCI1762") );
  38. }
  39. CDevicePCI1762::~CDevicePCI1762()
  40. {
  41. ObjectToParentLinkSP::Unlink();
  42. CLgNetDeviceGPIOPCI1762::Destroy();
  43. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CDevicePCI1762::~CDevicePCI1762") );
  44. }
  45. BOOL CDevicePCI1762::ReadWriteProc( DWORD dwTimeout )
  46. {
  47. BOOL bResult = CLgNetDeviceGPIOPCI1762::ReadWriteProc( dwTimeout );
  48. LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CDevicePCI1762::ReadWriteProc") );
  49. CLgNetMessageGPIO InMsg;
  50. while( m_MsgSink.PopMessage( InMsg ) )
  51. {
  52. BYTE bCommand;
  53. if( !InMsg.GetCommand( &bCommand ) )
  54. {
  55. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CDevicePCI1762::ReadWriteProc"), _T("InMsg.GetCommand failed") );
  56. continue;
  57. }
  58. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_ERROR, this, _T("CDevicePCI1762::ReadWriteProc"), _T("received event") );
  59. CLgDeviceGPIO::GPIO_PIN pinDI;
  60. CLgDeviceGPIO::PGPIO_PINS pPinsDI;
  61. CLgDeviceGPIO::GPIO_PIN pin;
  62. switch( bCommand )
  63. {
  64. case CLgDeviceGPIO::EVT_SET_OUTPUT:
  65. if( !InMsg.GetOutput( &pin ) )
  66. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CDevicePCI1762::ReadWriteProc"), _T("InMsg.GetOutput failed") );
  67. else
  68. {
  69. if( pin.nIndex < 0 || pin.nIndex >= m_OutputState.GetCount() )
  70. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CDevicePCI1762::ReadWriteProc"), _T("CLgDeviceGPIO::EVT_SET_OUTPUT: pin index is %d"), pin.nIndex );
  71. else
  72. {
  73. m_OutputState[pin.nIndex].bOn = pin.bOn;
  74. m_OutputState[pin.nIndex].bFirstTime = FALSE;
  75. }
  76. }
  77. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CDevicePCI1762::ReadWriteProc"), _T("received EVT_SET_OUTPUT") );
  78. break;
  79. case CLgDeviceGPIO::EVT_GET_OUTPUT:
  80. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CDevicePCI1762::ReadWriteProc"), _T("received EVT_GET_OUTPUT") );
  81. break;
  82. case CLgDeviceGPIO::EVT_GET_OUTPUT_ALL:
  83. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CDevicePCI1762::ReadWriteProc"), _T("received EVT_GET_OUTPUT_ALL") );
  84. break;
  85. case CLgDeviceGPIO::EVT_GET_INPUT:
  86. if( InMsg.GetInput( &pinDI ) )
  87. CDeviceDI::SetBit( pinDI.nIndex, pinDI.bOn );
  88. break;
  89. case CLgDeviceGPIO::EVT_GET_INPUT_ALL:
  90. {
  91. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CDevicePCI1762::ReadWriteProc"), _T("received CLgDeviceGPIO::EVT_GET_INPUT_ALL") );
  92. if( ( pPinsDI = InMsg.GetInputPins() ) )
  93. for( INT i = 0; i < pPinsDI->nCount; i++ )
  94. CDeviceDI::SetBit( pPinsDI->pPin[i].nIndex, pPinsDI->pPin[i].bOn );
  95. }
  96. break;
  97. case CLgDeviceGPIO::EVT_INPUT_CHANGE:
  98. {
  99. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CDevicePCI1762::ReadWriteProc"), _T("received CLgDeviceGPIO::EVT_INPUT_CHANGE") );
  100. if( InMsg.GetInput( &pinDI ) )
  101. CDeviceDI::SetBit( pinDI.nIndex, pinDI.bOn );
  102. }
  103. break;
  104. default:
  105. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CDevicePCI1762::ReadWriteProc"), _T("received unknown command") );
  106. break;
  107. }
  108. }
  109. m_Msg.SetDistinationID( GetID() );
  110. m_Msg.SetSenderID( m_MsgSink.GetID() );
  111. DDOEVENT ddoe;
  112. while( CDeviceDO::m_Queue.Pop( ddoe ) )
  113. {
  114. switch( ddoe.id )
  115. {
  116. case DDOC_GET_STATE:
  117. if( !m_Msg.BuildCmdGetOutputAll() )
  118. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CDevicePCI1762::ReadWriteProc"), _T("m_Msg.BuildCmdGetOutputAll failed") );
  119. else
  120. PushMessage( m_Msg );
  121. break;
  122. case DDOC_SET_SWITCH:
  123. if( ddoe.nBit < 0 || ddoe.nBit >= m_OutputState.GetCount() )
  124. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CDevicePCI1762::ReadWriteProc"), _T("DDOC_SET_SWITCH: pin index is %d"), ddoe.nBit );
  125. else
  126. if( m_OutputState[ddoe.nBit].bFirstTime || m_OutputState[ddoe.nBit].bOn != ddoe.bOn )
  127. {
  128. if( !m_Msg.BuildCmdSetOutput( ddoe.nBit, ddoe.bOn ) )
  129. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CDevicePCI1762::ReadWriteProc"), _T("m_Msg.BuildCmdSetOutput failed") );
  130. else
  131. PushMessage( m_Msg );
  132. }
  133. break;
  134. }
  135. }
  136. DDIEVENT ddie;
  137. while( CDeviceDI::m_Queue.Pop( ddie ) )
  138. {
  139. switch( ddie.id )
  140. {
  141. case DDIC_GET_STATE:
  142. if( !m_Msg.BuildCmdGetInputAll() )
  143. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CDevicePCI1762::ReadWriteProc"), _T("m_Msg.BuildCmdGetInputAll failed") );
  144. else
  145. PushMessage( m_Msg );
  146. break;
  147. case DDIC_ENABLE:
  148. break;
  149. }
  150. }
  151. return bResult;
  152. }