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.

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