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.
 
 
 
 

182 lines
3.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: LgBitCod.cpp
// AUTHOR: Sergey Chizhevskiy
// OVERVIEW
// ~~~~~~~~
// Source file of LgBitCod.cpp
//----------------------------------------------------------------------------
#include "stdafx.h"
#include "..\LgLib\LgBitCod.h"
#include "..\LgLib\Version.h"
// exclude in DOS version
#ifdef _MSC_VER
#include "..\LgLib\LgLogger.h"
#endif
// m_dwMask[n] = 0xFFFFFFUL >> (24 - n)
DWORD CLgBitCode::m_dwMask[25] =
{
0xFFFFFFUL >> 24,
0xFFFFFFUL >> 23,
0xFFFFFFUL >> 22,
0xFFFFFFUL >> 21,
0xFFFFFFUL >> 20,
0xFFFFFFUL >> 19,
0xFFFFFFUL >> 18,
0xFFFFFFUL >> 17,
0xFFFFFFUL >> 16,
0xFFFFFFUL >> 15,
0xFFFFFFUL >> 14,
0xFFFFFFUL >> 13,
0xFFFFFFUL >> 12,
0xFFFFFFUL >> 11,
0xFFFFFFUL >> 10,
0xFFFFFFUL >> 9,
0xFFFFFFUL >> 8,
0xFFFFFFUL >> 7,
0xFFFFFFUL >> 6,
0xFFFFFFUL >> 5,
0xFFFFFFUL >> 4,
0xFFFFFFUL >> 3,
0xFFFFFFUL >> 2,
0xFFFFFFUL >> 1,
0xFFFFFFUL >> 0
};
CLgBitCode::CLgBitCode()
{
m_pBuffer = NULL;
m_nCount = 0;
m_nShift = 0;
}
CLgBitCode::CLgBitCode( void *pBuffer )
{
m_pBuffer = (PBYTE)pBuffer;
m_nCount = 0;
m_nShift = 0;
}
CLgBitCode::~CLgBitCode()
{
}
bool CLgBitCode::Encode8( uint8_t bBits, uint8_t nCount )
{
if( !m_pBuffer )
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgBitCode::Encode8"), _T("m_pBuffer equal NULL") );
// cast to word
uint16_t &wWord = (uint16_t&) m_pBuffer[m_nCount];
// clear upper part of word
wWord &= (uint8_t)m_dwMask[m_nShift];
// add new bits
wWord |= (bBits & (uint8_t)m_dwMask[nCount]) << m_nShift;
// increase bit counter
m_nShift += (uint8_t)nCount;
// check overflow
while( m_nShift > 7 )
{
m_nShift -= 8;
m_nCount++;
}
// return true if number of bits round to 8
return m_nShift == 0;
}
bool CLgBitCode::Decode8( PBYTE pBits, uint8_t nCount )
{
if( !m_pBuffer )
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgBitCode::Decode8"), _T("m_pBuffer equal NULL") );
// cast to word
uint16_t &wWord = (uint16_t&) m_pBuffer[m_nCount];
// extract nessesary bits
*pBits = (uint8_t)( (wWord >> m_nShift) & (uint8_t)m_dwMask[ nCount ] );
// increase bit counter
m_nShift += (uint8_t)nCount;
// check overflow
while( m_nShift > 7 )
{
m_nShift -= 8;
m_nCount++;
}
// return true if number of passed bits round to 8
return m_nShift == 0;
}
bool CLgBitCode::Encode24( DWORD dwBits, uint8_t nCount )
{
if( !m_pBuffer )
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgBitCode::Encode24"), _T("m_pBuffer equal NULL") );
// cast to word
DWORD &dwWord = (DWORD&) m_pBuffer[m_nCount];
// clear upper part of dword
dwWord &= m_dwMask[m_nShift];
// add new bits
dwWord |= (dwBits & m_dwMask[nCount]) << m_nShift;
// increase bit counter
m_nShift += (uint8_t)nCount;
// until overflow
while( m_nShift > 7 )
{
m_nShift -= 8;
m_nCount++;
}
// return true if number of passed bits round to 8
return m_nShift == 0;
}
bool CLgBitCode::Decode24( PDWORD pBits, uint8_t nCount )
{
if( !m_pBuffer )
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgBitCode::Decode24"), _T("m_pBuffer equal NULL") );
// cast to dword
DWORD &dwWord = (DWORD&) m_pBuffer[m_nCount];
// extract nessesary bits
*pBits = (dwWord >> m_nShift) & m_dwMask[ nCount ];
// increase bit counter
m_nShift += (uint8_t)nCount;
// until overflow
while( m_nShift > 7 )
{
m_nShift -= 8;
m_nCount++;
}
// return true if number of passed bits round to 8
return m_nShift == 0;
}
void CLgBitCode::SetBuffer( void* pBuffer )
{
m_pBuffer = (PBYTE)pBuffer;
m_nCount = 0;
m_nShift = 0;
}