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.
127 lines
2.7 KiB
127 lines
2.7 KiB
//----------------------------------------------------------------------------
|
|
// Laser Guard Ltd.
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
// Version 1.0 01/01/2000
|
|
// Last modification: 08/10/2003
|
|
// PROJECT:
|
|
// SUBSYSTEM:
|
|
// FILE: PTZPG3AD.cpp
|
|
// AUTHOR: Sergey Chizhevskiy
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Source file of PTZPG3AD.cpp
|
|
//----------------------------------------------------------------------------
|
|
#include "stdafx.h"
|
|
|
|
#ifdef __BORLANDC__
|
|
#include "..\LgLib\Comm\PTZAD.h"
|
|
#else
|
|
#include "PTZAD.h"
|
|
#endif
|
|
|
|
CProtocolPTZAmericanDynamics::CProtocolPTZAmericanDynamics()
|
|
{
|
|
m_pConnection = NULL;
|
|
m_nCount = 0;
|
|
m_bAddress = 0;
|
|
m_eReadType = READ_TYPE_ACK;
|
|
}
|
|
|
|
CProtocolPTZAmericanDynamics::~CProtocolPTZAmericanDynamics()
|
|
{
|
|
Destroy();
|
|
}
|
|
|
|
BOOL CProtocolPTZAmericanDynamics::Create( CConnection *pConnection )
|
|
{
|
|
Destroy();
|
|
|
|
m_pConnection = pConnection;
|
|
m_nCount = 0;
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CProtocolPTZAmericanDynamics::Destroy()
|
|
{
|
|
m_pConnection = NULL;
|
|
m_nCount = 0;
|
|
}
|
|
|
|
void CProtocolPTZAmericanDynamics::SetAddress( BYTE bAddress )
|
|
{
|
|
m_bAddress = bAddress;
|
|
}
|
|
|
|
BOOL CProtocolPTZAmericanDynamics::Read( PBYTE *ppBuffer, PINT pCount, DWORD dwTimeout, BOOL bHost )
|
|
{
|
|
bHost;
|
|
|
|
switch( m_eReadType )
|
|
{
|
|
case READ_TYPE_ACK:
|
|
if( !m_pConnection->Read( m_pBuffer, 1, dwTimeout ) )
|
|
return FALSE;
|
|
|
|
if( m_pBuffer[0] == m_bAddress )
|
|
{
|
|
(*pCount) = 1;
|
|
(*ppBuffer) = m_pBuffer;
|
|
return TRUE;
|
|
}
|
|
break;
|
|
|
|
case READ_TYPE_POSITION:
|
|
|
|
while( TRUE )
|
|
{
|
|
if( m_nCount < 2 )
|
|
m_nCount += m_pConnection->Read( m_pBuffer + m_nCount, 2 - m_nCount, dwTimeout );
|
|
|
|
if( m_nCount < 2 )
|
|
return FALSE;
|
|
|
|
if( m_pBuffer[0] != m_bAddress || m_pBuffer[1] != m_bAddress )
|
|
{
|
|
memmove( m_pBuffer, m_pBuffer+1, --m_nCount );
|
|
continue;
|
|
}
|
|
|
|
m_nCount += ( m_pConnection->Read( m_pBuffer + m_nCount, 13 - m_nCount, dwTimeout ) );
|
|
if( m_nCount < 13 )
|
|
return FALSE;
|
|
|
|
BYTE bCheckSum = PTZ_AMERICAN_DYNAMICS::GetCheckSum( m_pBuffer+1, 12 );
|
|
if( m_pBuffer[12] != bCheckSum )
|
|
{
|
|
memmove( m_pBuffer, m_pBuffer+1, --m_nCount );
|
|
continue;
|
|
}
|
|
|
|
break;
|
|
}
|
|
|
|
m_nCount = 0;
|
|
(*pCount) = 13;
|
|
(*ppBuffer) = m_pBuffer;
|
|
return TRUE;
|
|
}
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
BOOL CProtocolPTZAmericanDynamics::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;
|
|
|
|
// write data
|
|
DWORD dwDataSize = nCount;
|
|
return (BOOL)(m_pConnection->Write( pBuffer, dwDataSize, dwTimeout ) == dwDataSize);
|
|
}
|