//---------------------------------------------------------------------------- // Laser Guard Ltd. // Copyright © 2000-2002. All Rights Reserved. // Version 1.0 01/01/2000 // Last modification: 08/10/2003 // PROJECT: // SUBSYSTEM: // FILE: PTZPelco.cpp // AUTHOR: Sergey Chizhevskiy // OVERVIEW // ~~~~~~~~ // Source file of PTZPelco.cpp //---------------------------------------------------------------------------- #include "stdafx.h" #ifdef __BORLANDC__ #include "..\LgLib\Comm\PTZPelco.h" #else #include "PTZPelco.h" #endif CProtocolPTZPelco::CProtocolPTZPelco() { m_pConnection = NULL; m_nCount = 0; m_pBufferPtr = m_pBuffer; m_bAddress = 1; } CProtocolPTZPelco::~CProtocolPTZPelco() { Destroy(); } BOOL CProtocolPTZPelco::Create( CConnection *pConnection ) { Destroy(); m_pConnection = pConnection; m_pBufferPtr = m_pBuffer; m_nCount = 0; return TRUE; } void CProtocolPTZPelco::Destroy() { m_pConnection = NULL; m_pBufferPtr = m_pBuffer; m_nCount = 0; } void CProtocolPTZPelco::SetAddress( BYTE bAddress ) { m_bAddress = bAddress; } BOOL CProtocolPTZPelco::Read( PBYTE *ppBuffer, PINT pCount, DWORD dwTimeout, BOOL bHost ) { bHost; BOOL bResult = FALSE; // copy remaining part if( ( m_pBuffer != m_pBufferPtr ) && m_nCount ) memcpy( m_pBuffer, m_pBufferPtr, m_nCount ); // try to read command header if( m_nCount < m_nResponseSize ) { // read new data DWORD nCount = m_nResponseSize - m_nCount; m_nCount += ( m_pConnection->Read( m_pBuffer + m_nCount, nCount, dwTimeout ) ); } if( m_nCount >= m_nResponseSize ) { // store length (*pCount) = (INT)m_nResponseSize; (*ppBuffer) = m_pBufferPtr; // shift pointers m_pBufferPtr += m_nResponseSize; m_nCount -= m_nResponseSize; // at least one command received bResult = TRUE; } return bResult; } BOOL CProtocolPTZPelco::Write( PBYTE pBuffer, INT nCount, DWORD dwTimeout, BOOL bHost ) { bHost; // validate data length if( nCount > MAX_COMMAND_SIZE ) return FALSE; // clear receiver m_nCount = 0; m_pBufferPtr = m_pBuffer; // write data DWORD dwDataSize = nCount; return (BOOL)(m_pConnection->Write( pBuffer, dwDataSize, dwTimeout ) == dwDataSize); }