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.

107 lines
2.4 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: RELAY.CPP
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of RELAY.CPP
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "relay.h"
  16. void CRelay::OnProtocolLgsRelayCommand( PBYTE pReadBuffer, INT& nReadCount, PBYTE pSendBuffer, INT& nSendCount )
  17. {
  18. // input command parsing
  19. LGS::RELAY_DATA InData;
  20. // translate Relay command
  21. nReadCount -= LGS::GetCmdRelay( pReadBuffer, &InData );
  22. // prepare output Relay data
  23. LGS::RELAY_DATA OutData;
  24. // depend on command
  25. switch( InData.nCommand )
  26. {
  27. case LGS::CMD_RELAY_GET:
  28. break;
  29. case LGS::CMD_RELAY_SET:
  30. m_bOutput = InData.bOutput;
  31. SetRelay( InData.nCommand );
  32. break;
  33. }
  34. // send reply
  35. OutData.nCommand = InData.nCommand;
  36. OutData.bOutput = m_bOutput;
  37. nSendCount += LGS::BuildEvtRelay( pSendBuffer, &OutData );
  38. }
  39. //#define __RELAY__TEST__BY__TOGGLE__
  40. void CRelay::Invalidate( WORD nFastTimer, DWORD nSlowTimer )
  41. {
  42. // don't use fast timer
  43. nFastTimer;
  44. // if Relay in auto mode
  45. if( !m_RelayParameters.bAuto )
  46. return;
  47. #ifdef __RELAY__TEST__BY__TOGGLE__
  48. if( nSlowTimer - m_dwAutoDelayTime < 18 )
  49. return;
  50. m_dwAutoDelayTime = nSlowTimer;
  51. SetRelay( m_bOutput = !m_bOutput );
  52. return;
  53. #endif //__RELAY__TEST__BY__TOGGLE__
  54. // if still old time
  55. if( m_dwAutoDelayTime == nSlowTimer )
  56. return;
  57. // update timeouts
  58. if( m_lAutoDelayTimeout > 0 )
  59. {
  60. m_lAutoDelayTimeout -= (LONG)(nSlowTimer - m_dwAutoDelayTime);
  61. }
  62. else
  63. {
  64. // relay off
  65. if( m_bOutput )
  66. SetRelay( m_bOutput = FALSE );
  67. }
  68. // store time
  69. m_dwAutoDelayTime = nSlowTimer;
  70. }
  71. void CRelay::SetRelay( BOOL bOn )
  72. {
  73. m_pBoard->SetRelayBit( bOn ? !m_RelayParameters.bNormallyClose : m_RelayParameters.bNormallyClose );
  74. // m_pBoard->SetRelayBit( bOn );
  75. }
  76. void CRelay::OnTarget( INT, INT )
  77. {
  78. #ifdef __RELAY__TEST__BY__TOGGLE__
  79. return;
  80. #endif
  81. // if Relay in auto mode
  82. if( !m_RelayParameters.bAuto )
  83. return;
  84. // relay on
  85. SetRelay( m_bOutput = TRUE );
  86. // set timeout
  87. m_lAutoDelayTimeout = m_RelayParameters.nAutoDelay * 18L;
  88. }