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.
 
 
 
 

132 lines
2.9 KiB

//----------------------------------------------------------------------------
// Laser Guard Ltd.
// Copyright © 2000-2002. All Rights Reserved.
// Version 1.0 01/01/2000
// Last modification: 08/10/2003
// PROJECT:
// SUBSYSTEM:
// FILE: ProtocolCCC.cpp
// AUTHOR: Sergey Chizhevskiy
// OVERVIEW
// ~~~~~~~~
// Source file of ProtocolCCC.cpp
//----------------------------------------------------------------------------
// ProtocolCCC.cpp: implementation of the CProtocolCCC class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "ProtocolCCC.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CProtocolCCC::CProtocolCCC()
{
m_pConnection = NULL;
m_nCount = 0;
m_pBufferPtr = m_pBuffer;
}
CProtocolCCC::~CProtocolCCC()
{
Destroy();
}
BOOL CProtocolCCC::Create( CConnection *pConnection )
{
Destroy();
m_pConnection = pConnection;
m_pBufferPtr = m_pBuffer;
m_nCount = 0;
return TRUE;
}
void CProtocolCCC::Destroy()
{
m_pConnection = NULL;
m_pBufferPtr = m_pBuffer;
m_nCount = 0;
}
BOOL CProtocolCCC::Read( PBYTE *ppBuffer, PINT pCount, DWORD dwTimeout, BOOL bHost )
{
BOOL bResult = FALSE;
// copy remaining part
if( m_pBuffer != m_pBufferPtr )
memcpy( m_pBuffer, m_pBufferPtr, m_nCount );
// read data
while( TRUE )
{
if( m_nCount < COMMAND_SIZE )
{
// try to read address byte
m_nCount += m_pConnection->Read( m_pBuffer + m_nCount, COMMAND_SIZE - m_nCount, dwTimeout );
if( m_nCount < COMMAND_SIZE )
{
break;
}
}
// check address tag
if( ( m_pBuffer[ ADDRESS_POS ] & ADDRESS_TAG ) == ADDRESS_TAG &&
( m_pBuffer[ DATA_POS ] & ADDRESS_TAG ) != ADDRESS_TAG &&
( m_pBuffer[ DATA_POS ] & DATA_TAG ) == DATA_TAG )
{
break;
}
else
memmove( m_pBuffer, m_pBuffer + 1, --m_nCount );
}
// initialize pointer
m_pBufferPtr = m_pBuffer;
// parse input bytes
while( m_nCount >= COMMAND_SIZE )
{
// check address tag
if( ( m_pBufferPtr[ ADDRESS_POS ] & ADDRESS_TAG ) == ADDRESS_TAG &&
( m_pBufferPtr[ DATA_POS ] & ADDRESS_TAG ) != ADDRESS_TAG &&
( m_pBufferPtr[ DATA_POS ] & DATA_TAG ) == DATA_TAG )
{
// store length
*pCount = 2;
*ppBuffer = m_pBufferPtr;
// at least one command received
bResult = TRUE;
// shift pointers
m_pBufferPtr += 2;
m_nCount -= 2;
}
else
{
// shift pointers
m_pBufferPtr ++;
m_nCount --;
}
}
return bResult;
}
BOOL CProtocolCCC::Write( PBYTE pBuffer, INT nCount, DWORD dwTimeout, BOOL bHost )
{
// validate data length
if( nCount > COMMAND_SIZE )
return FALSE;
// clear receiver
m_nCount = 0;
m_pBufferPtr = m_pBuffer;
// make pointer to write buffer
return m_pConnection->Write( pBuffer, nCount, dwTimeout ) == (DWORD)nCount;
}