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.

142 lines
3.3 KiB

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: PTZPelco.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of PTZPelco.cpp
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #ifdef __BORLANDC__
  16. #include "..\LgLib\Comm\PTZChina.h"
  17. #else
  18. #include "PTZChina.h"
  19. #endif
  20. CProtocolPTZChina::CProtocolPTZChina(){
  21. m_pConnection = NULL;
  22. m_nCount = 0;
  23. m_pBufferPtr = m_pBuffer;
  24. m_bAddress = 1;
  25. #ifdef DEBUG_PELCO_PROTO
  26. logFID = NULL;
  27. logFID = fopen( "pelco_china_bin.log", "w" );
  28. #endif
  29. }
  30. CProtocolPTZChina::~CProtocolPTZChina(){
  31. #ifdef DEBUG_PELCO_PROTO
  32. if( logFID ) fclose( logFID );
  33. #endif
  34. Destroy();
  35. }
  36. BOOL CProtocolPTZChina::Create( CConnection *pConnection )
  37. {
  38. Destroy();
  39. m_pConnection = pConnection;
  40. m_pBufferPtr = m_pBuffer;
  41. m_nCount = 0;
  42. return TRUE;
  43. }
  44. void CProtocolPTZChina::Destroy()
  45. {
  46. m_pConnection = NULL;
  47. m_pBufferPtr = m_pBuffer;
  48. m_nCount = 0;
  49. }
  50. void CProtocolPTZChina::SetAddress( BYTE bAddress )
  51. {
  52. m_bAddress = bAddress;
  53. }
  54. BOOL CProtocolPTZChina::Read( PBYTE *ppBuffer, PINT pCount, DWORD dwTimeout, BOOL bHost ){
  55. if( dwTimeout == 0UL ) {
  56. *pCount = 0;
  57. return TRUE;
  58. };
  59. bHost;
  60. BOOL bResult = FALSE;
  61. // copy remaining part
  62. if( ( m_pBuffer != m_pBufferPtr ) && m_nCount )
  63. memcpy( m_pBuffer, m_pBufferPtr, m_nCount );
  64. // try to read command header
  65. if( m_nCount < m_nResponseSize )
  66. {
  67. // read new data
  68. DWORD nCount = m_nResponseSize - m_nCount;
  69. m_nCount += ( m_pConnection->Read( m_pBuffer + m_nCount, nCount, dwTimeout ) );
  70. }
  71. if( m_nCount >= m_nResponseSize ){
  72. #ifdef DEBUG_PELCO_PROTO
  73. if( logFID ){
  74. // prepare data&time
  75. SYSTEMTIME st;
  76. GetLocalTime( &st );
  77. // prepare full string
  78. fprintf( logFID, "[%02d/%02d/%02d %02d:%02d:%02d:%03d]", st.wDay, st.wMonth, st.wYear, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds );
  79. // output
  80. fprintf( logFID, ">" );
  81. for( INT index=0; index < m_nResponseSize; index++ ) fprintf( logFID, "%02X", m_pBufferPtr[index]);
  82. fprintf( logFID, "\r\n" );
  83. };
  84. #endif
  85. // store length
  86. (*pCount) = (INT)m_nResponseSize;
  87. (*ppBuffer) = m_pBufferPtr;
  88. // shift pointers
  89. m_pBufferPtr += m_nResponseSize;
  90. m_nCount -= m_nResponseSize;
  91. // at least one command received
  92. bResult = TRUE;
  93. }
  94. return bResult;
  95. }
  96. BOOL CProtocolPTZChina::Write( PBYTE pBuffer, INT nCount, DWORD dwTimeout, BOOL bHost )
  97. {
  98. bHost;
  99. // validate data length
  100. if( nCount > MAX_COMMAND_SIZE )
  101. return FALSE;
  102. // clear receiver
  103. m_nCount = 0;
  104. m_pBufferPtr = m_pBuffer;
  105. // write data
  106. DWORD dwDataSize = nCount;
  107. #ifdef DEBUG_PELCO_PROTO
  108. if( logFID ){
  109. // prepare data&time
  110. SYSTEMTIME st;
  111. GetLocalTime( &st );
  112. // prepare full string
  113. fprintf( logFID, "[%02d/%02d/%02d %02d:%02d:%02d:%03d]", st.wDay, st.wMonth, st.wYear, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds );
  114. // output
  115. fprintf( logFID, "<" );
  116. for( INT index=0; index < nCount; index++ ) fprintf( logFID, "%02X", pBuffer[index]);
  117. fprintf( logFID, "\r\n" );
  118. };
  119. #endif
  120. return (BOOL)(m_pConnection->Write( pBuffer, dwDataSize, dwTimeout ) == dwDataSize);
  121. }