For DOS Protected Mode version of sensor core software
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.

109 lines
2.4 KiB

3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 years ago
​
3 years ago
​
3 years ago
3 years ago
​
​
​
​
3 years ago
​
​
​
3 years ago
​
3 years ago
​
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 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, int16_t& nReadCount, PBYTE pSendBuffer, int16_t& 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::validate( uint64_t nTimer ){
  41. // if Relay in auto mode
  42. if( !m_RelayParameters.bAuto ) return;
  43. #ifdef __RELAY__TEST__BY__TOGGLE__
  44. if( nTimer - m_dwAutoDelayTime < 1000 ) return; // 1 second
  45. m_dwAutoDelayTime = nTimer;
  46. SetRelay( m_bOutput = !m_bOutput );
  47. return;
  48. #endif //__RELAY__TEST__BY__TOGGLE__
  49. // if still old time
  50. if( m_dwAutoDelayTime == nTimer ) return;
  51. // update timeouts
  52. if( m_lAutoDelayTimeout > 0 ){
  53. m_lAutoDelayTimeout -= ( nTimer - m_dwAutoDelayTime );
  54. } else {
  55. // relay off
  56. if( m_bOutput ) SetRelay( m_bOutput = false );
  57. };
  58. // store time
  59. m_dwAutoDelayTime = nTimer;
  60. };
  61. void CRelay::Reset( void ){
  62. // Turn Off Relay
  63. SetRelay( m_bOutput = false );
  64. // set timeout
  65. m_lAutoDelayTimeout = 0;
  66. }
  67. void CRelay::SetRelay( bool bOn ){
  68. #ifdef DEBUG
  69. printf("Set R-Bit\n");
  70. #endif
  71. m_pBoard->SetRelayBit( bOn ? !m_RelayParameters.bNormallyClose : m_RelayParameters.bNormallyClose );
  72. #ifdef DEBUG
  73. printf("Done\n");
  74. #endif
  75. // m_pBoard->SetRelayBit( bOn );
  76. }
  77. void CRelay::OnTarget( int16_t, int16_t )
  78. {
  79. #ifdef __RELAY__TEST__BY__TOGGLE__
  80. return;
  81. #endif
  82. // if Relay in auto mode
  83. if( !m_RelayParameters.bAuto )
  84. return;
  85. // relay on
  86. SetRelay( m_bOutput = true );
  87. // set timeout
  88. m_lAutoDelayTimeout = m_RelayParameters.nAutoDelay * 1000;//18L;
  89. }