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.2 KiB
108 lines
2.2 KiB
//----------------------------------------------------------------------------
|
|
// Laser Guard Ltd.
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
// Version 1.0 01/01/2000
|
|
// Last modification: 08/10/2003
|
|
// PROJECT:
|
|
// SUBSYSTEM:
|
|
// FILE: PTZVicon.cpp
|
|
// AUTHOR: Sergey Chizhevskiy
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Source file of PTZVicon.cpp
|
|
//----------------------------------------------------------------------------
|
|
#include "stdafx.h"
|
|
|
|
#ifdef __BORLANDC__
|
|
#include "..\LgLib\Comm\PTZVicon.h"
|
|
#else
|
|
#include "PTZVicon.h"
|
|
#endif
|
|
|
|
CProtocolPTZVicon::CProtocolPTZVicon()
|
|
{
|
|
m_pConnection = NULL;
|
|
m_nCount = 0;
|
|
m_pBufferPtr = m_pBuffer;
|
|
m_bAddress = 1;
|
|
}
|
|
|
|
CProtocolPTZVicon::~CProtocolPTZVicon()
|
|
{
|
|
Destroy();
|
|
}
|
|
|
|
BOOL CProtocolPTZVicon::Create( CConnection *pConnection )
|
|
{
|
|
Destroy();
|
|
|
|
m_pConnection = pConnection;
|
|
m_pBufferPtr = m_pBuffer;
|
|
m_nCount = 0;
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CProtocolPTZVicon::Destroy()
|
|
{
|
|
m_pConnection = NULL;
|
|
m_pBufferPtr = m_pBuffer;
|
|
m_nCount = 0;
|
|
}
|
|
|
|
void CProtocolPTZVicon::SetAddress( BYTE bAddress )
|
|
{
|
|
m_bAddress = bAddress;
|
|
}
|
|
|
|
BOOL CProtocolPTZVicon::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 CProtocolPTZVicon::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);
|
|
}
|