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.
 
 
 
 

143 lines
3.3 KiB

//----------------------------------------------------------------------------
// 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\PTZChina.h"
#else
#include "PTZChina.h"
#endif
CProtocolPTZChina::CProtocolPTZChina(){
m_pConnection = NULL;
m_nCount = 0;
m_pBufferPtr = m_pBuffer;
m_bAddress = 1;
#ifdef DEBUG_PELCO_PROTO
logFID = NULL;
logFID = fopen( "pelco_china_bin.log", "w" );
#endif
}
CProtocolPTZChina::~CProtocolPTZChina(){
#ifdef DEBUG_PELCO_PROTO
if( logFID ) fclose( logFID );
#endif
Destroy();
}
BOOL CProtocolPTZChina::Create( CConnection *pConnection )
{
Destroy();
m_pConnection = pConnection;
m_pBufferPtr = m_pBuffer;
m_nCount = 0;
return TRUE;
}
void CProtocolPTZChina::Destroy()
{
m_pConnection = NULL;
m_pBufferPtr = m_pBuffer;
m_nCount = 0;
}
void CProtocolPTZChina::SetAddress( BYTE bAddress )
{
m_bAddress = bAddress;
}
BOOL CProtocolPTZChina::Read( PBYTE *ppBuffer, PINT pCount, DWORD dwTimeout, BOOL bHost ){
if( dwTimeout == 0UL ) {
*pCount = 0;
return TRUE;
};
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 ){
#ifdef DEBUG_PELCO_PROTO
if( logFID ){
// prepare data&time
SYSTEMTIME st;
GetLocalTime( &st );
// prepare full string
fprintf( logFID, "[%02d/%02d/%02d %02d:%02d:%02d:%03d]", st.wDay, st.wMonth, st.wYear, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds );
// output
fprintf( logFID, ">" );
for( INT index=0; index < m_nResponseSize; index++ ) fprintf( logFID, "%02X", m_pBufferPtr[index]);
fprintf( logFID, "\r\n" );
};
#endif
// 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 CProtocolPTZChina::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;
#ifdef DEBUG_PELCO_PROTO
if( logFID ){
// prepare data&time
SYSTEMTIME st;
GetLocalTime( &st );
// prepare full string
fprintf( logFID, "[%02d/%02d/%02d %02d:%02d:%02d:%03d]", st.wDay, st.wMonth, st.wYear, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds );
// output
fprintf( logFID, "<" );
for( INT index=0; index < nCount; index++ ) fprintf( logFID, "%02X", pBuffer[index]);
fprintf( logFID, "\r\n" );
};
#endif
return (BOOL)(m_pConnection->Write( pBuffer, dwDataSize, dwTimeout ) == dwDataSize);
}