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.

108 lines
2.3 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: 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. }
  27. CProtocolPTZPelco::~CProtocolPTZPelco()
  28. {
  29. Destroy();
  30. }
  31. BOOL CProtocolPTZPelco::Create( CConnection *pConnection )
  32. {
  33. Destroy();
  34. m_pConnection = pConnection;
  35. m_pBufferPtr = m_pBuffer;
  36. m_nCount = 0;
  37. return TRUE;
  38. }
  39. void CProtocolPTZPelco::Destroy()
  40. {
  41. m_pConnection = NULL;
  42. m_pBufferPtr = m_pBuffer;
  43. m_nCount = 0;
  44. }
  45. void CProtocolPTZPelco::SetAddress( BYTE bAddress )
  46. {
  47. m_bAddress = bAddress;
  48. }
  49. BOOL CProtocolPTZPelco::Read( PBYTE *ppBuffer, PINT pCount, DWORD dwTimeout, BOOL bHost )
  50. {
  51. bHost;
  52. BOOL bResult = FALSE;
  53. // copy remaining part
  54. if( ( m_pBuffer != m_pBufferPtr ) && m_nCount )
  55. memcpy( m_pBuffer, m_pBufferPtr, m_nCount );
  56. // try to read command header
  57. if( m_nCount < m_nResponseSize )
  58. {
  59. // read new data
  60. DWORD nCount = m_nResponseSize - m_nCount;
  61. m_nCount += ( m_pConnection->Read( m_pBuffer + m_nCount, nCount, dwTimeout ) );
  62. }
  63. if( m_nCount >= m_nResponseSize )
  64. {
  65. // store length
  66. (*pCount) = (INT)m_nResponseSize;
  67. (*ppBuffer) = m_pBufferPtr;
  68. // shift pointers
  69. m_pBufferPtr += m_nResponseSize;
  70. m_nCount -= m_nResponseSize;
  71. // at least one command received
  72. bResult = TRUE;
  73. }
  74. return bResult;
  75. }
  76. BOOL CProtocolPTZPelco::Write( PBYTE pBuffer, INT nCount, DWORD dwTimeout, BOOL bHost )
  77. {
  78. bHost;
  79. // validate data length
  80. if( nCount > MAX_COMMAND_SIZE )
  81. return FALSE;
  82. // clear receiver
  83. m_nCount = 0;
  84. m_pBufferPtr = m_pBuffer;
  85. // write data
  86. DWORD dwDataSize = nCount;
  87. return (BOOL)(m_pConnection->Write( pBuffer, dwDataSize, dwTimeout ) == dwDataSize);
  88. }