//---------------------------------------------------------------------------- // Laser Guard Ltd. // Copyright © 2000-2002. All Rights Reserved. // Version 1.0 01/01/2000 // Last modification: 08/10/2003 // PROJECT: // SUBSYSTEM: // FILE: DeviceLGSs.cpp // AUTHOR: Sergey Chizhevskiy // OVERVIEW // ~~~~~~~~ // Source file of DeviceLGSs.cpp //---------------------------------------------------------------------------- #include "stdafx.h" #include "SensorLGS.h" #include "DeviceLGSs.h" #include "..\..\LgLib\Comm\Connect.h" #include "..\..\LgLib\Version.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif CDeviceLGSs::CDeviceLGSs() { m_bEnable = FALSE; m_nCount = 0; m_bNeedReset = FALSE; m_bNeedRestart = FALSE; LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CDeviceLGSs::CDeviceLGSs") ); } CDeviceLGSs::~CDeviceLGSs() { LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CDeviceLGSs::~CDeviceLGSs") ); } DWORD CDeviceLGSs::CompleteIO( CConnection *pConnection ) { if( !pConnection ) return FALSE; BYTE pBuffer[10]; DWORD dwCount = pConnection->Read( pBuffer, 8 - m_nCount, 500UL ); BOOL bCommandReceived = FALSE; for( DWORD i = 0; i < dwCount; i++ ) { if( m_nCount < 8 ) { m_pBuffer[ m_nCount++ ] = pBuffer[ i ]; } else { ::MoveMemory( m_pBuffer, m_pBuffer+1, 7 ); m_pBuffer[ 7 ] = pBuffer[i]; } if( m_nCount == 8 ) { if( m_pBuffer[ 7 ] == 0 ) { char command; int angle, range; if( sscanf( (LPSTR)m_pBuffer, "%c%03d%03d", &command, &angle, &range ) == 3 ) { switch( command ) { case 'a': m_pSensor->PostTarget( 0, LGS::TT_NORMAL, (double)angle, ((double)range)/5.12 ); break; case 'b': m_pSensor->PostTarget( 1, LGS::TT_NORMAL, (double)angle, ((double)range)/5.12 ); break; case 'f': m_pSensor->PostTarget( 0, LGS::TT_WIDE, (double)angle, ((double)range)/5.12 ); break; case 'w': m_pSensor->PostTarget( 0, LGS::TT_WIDE, (double)angle, ((double)range)/5.12 ); break; } } m_nCount = 0; bCommandReceived = TRUE; // packet has been read break; } else { ::MoveMemory( m_pBuffer, m_pBuffer + 1, 7 ); m_nCount --; } } } // read new commands LGSEVENT event; while( m_Queue.Pop( event ) ) { switch( event.id ) { case LGSC_RESET: m_bNeedReset = TRUE; break; case LGSC_RESTART: m_bNeedRestart = TRUE; break; case LGSC_ENABLE: m_bEnable = event.bEnable; break; } } if( bCommandReceived ) { if( m_bNeedRestart ) { m_bNeedRestart = FALSE; pConnection->Write( (PBYTE)"qqq", 3, 200 ); } else if( m_bNeedReset ) { m_bNeedReset = FALSE; // needs to be done for LGS Sleep( 10 ); pConnection->Write( (PBYTE)"rrr", 3, 200 ); m_pSensor->PostReset(); } } return TRUE; }