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.

114 lines
3.2 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: LgNetSocketCCC.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of LgNetSocketCCC.cpp
  13. //----------------------------------------------------------------------------
  14. // LgNetSocketCCC.cpp: implementation of the CLgNetSocketCCC class.
  15. //
  16. //////////////////////////////////////////////////////////////////////
  17. #include "stdafx.h"
  18. #include "LgNetSocketCCC.h"
  19. #include "..\..\LgLib\LgPerformanceCounter.h"
  20. //////////////////////////////////////////////////////////////////////
  21. // Construction/Destruction
  22. //////////////////////////////////////////////////////////////////////
  23. CLgNetSocketCCC::CLgNetSocketCCC()
  24. {
  25. }
  26. CLgNetSocketCCC::~CLgNetSocketCCC()
  27. {
  28. Destroy();
  29. // unlink all linked devices
  30. CLgLinkP<CLgNetSocket,CLgNetSocketDevice>::Unlink();
  31. }
  32. BOOL CLgNetSocketCCC::Create( LPCTSTR pCommPort )
  33. {
  34. Destroy();
  35. if( !m_Connection.Create( pCommPort, 1200, 8, EVENPARITY, ONESTOPBIT, CProtocolCCC::COMMAND_SIZE * 10, CProtocolCCC::COMMAND_SIZE * 10 ) )
  36. return FALSE;
  37. if( !m_Protocol.Create( &m_Connection ) )
  38. return FALSE;
  39. if( !CLgNetSocket::Create( &m_Protocol ) )
  40. return FALSE;
  41. return TRUE;
  42. }
  43. void CLgNetSocketCCC::Destroy()
  44. {
  45. CLgNetSocket::Destroy();
  46. m_Protocol.Destroy();
  47. m_Connection.Destroy();
  48. }
  49. BOOL CLgNetSocketCCC::OnTransaction()
  50. {
  51. BOOL bResult = FALSE;
  52. __try
  53. {
  54. // process in spy mode
  55. PBYTE pReadBuffer = NULL;
  56. INT nReadCount = 0;
  57. // read command
  58. if( m_Protocol.Read( &pReadBuffer, &nReadCount, 1000UL, FALSE ) )
  59. {
  60. BYTE pWriteBuffer[ CProtocolCCC::COMMAND_SIZE ];
  61. INT nWriteCount = CProtocolCCC::COMMAND_SIZE;
  62. // perform transaction
  63. if( OnTransactionCCC( pReadBuffer, pWriteBuffer ) )
  64. {
  65. // write back
  66. if( !m_Protocol.Write( pWriteBuffer, nWriteCount, 1000UL, FALSE ) )
  67. {
  68. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgNetSocketCCC::OnTransaction"), _T("m_Protocol.Write for data failed") );
  69. }
  70. else
  71. bResult = TRUE;
  72. }
  73. else
  74. {
  75. // if( !m_Protocol.Write( pReadBuffer, nReadCount, 1000UL, FALSE ) )
  76. // {
  77. // LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgNetSocketCCC::OnTransaction"), _T("m_Protocol.Write for echo failed") );
  78. // }
  79. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_WARNING, this, _T("CLgNetSocketCCC::OnTransaction"), _T("OnTransactionCCC failed on [%02X,%02X]"), pReadBuffer[0], pReadBuffer[1] );
  80. }
  81. }
  82. else
  83. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_WARNING, this, _T("CLgNetSocketCCC::OnTransaction"), _T("Read host command failed") );
  84. if( !bResult )
  85. // accumulate error amount
  86. m_liFailureCount.QuadPart++;
  87. else
  88. // accumulate success amount
  89. m_liSuccessCount.QuadPart++;
  90. }
  91. __except( EXCEPTION_EXECUTE_HANDLER )
  92. {
  93. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgNetSocketCCC::OnTransaction"), _T("Exception 0x%08X"), _exception_code() );
  94. }
  95. // log information
  96. return bResult;
  97. }