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.
266 lines
5.6 KiB
266 lines
5.6 KiB
//----------------------------------------------------------------------------
|
|
// Laser Guard Ltd.
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
// Version 1.0 19/04/2000
|
|
// Last modification: 05/02/2003
|
|
// Project Intruder Position Indicator
|
|
// SUBSYSTEM: Alarm
|
|
// FILE: Alarm.cpp
|
|
// AUTHOR: Chizhevskiy Sergey
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Source file for implemenation of class CAlarm
|
|
//----------------------------------------------------------------------------
|
|
|
|
#include "StdAfx.h"
|
|
#include "Alarm.h"
|
|
#include <ConIO.h>
|
|
#include "..\..\LgLib\Version.h"
|
|
|
|
CAlarm::CAlarm()
|
|
{
|
|
// m_fEnabled = FALSE;
|
|
// return;
|
|
m_dwVersion = ::GetVersion();
|
|
m_fEnabled = TRUE;
|
|
Outp( BEEPER_SET_TIMER_CHANNEL_PORT, 0XB6 );
|
|
Outp( BEEPER_SET_FREQUENCY_PORT, 1500 );
|
|
Outp( BEEPER_SET_FREQUENCY_PORT, 1500 >> 8 );
|
|
m_BeeperOff = Inp( BEEPER_PPI_PORT );
|
|
m_BeeperOn = m_BeeperOff | 3 ;
|
|
Outp( BEEPER_PPI_PORT, m_BeeperOff );
|
|
|
|
DWORD dwThreadID;
|
|
|
|
m_hEventClose = ::CreateEvent( NULL, FALSE, FALSE, NULL );
|
|
|
|
m_hEventBeep = ::CreateEvent( NULL, FALSE, FALSE, NULL );
|
|
m_hEventAlarm = ::CreateEvent( NULL, TRUE, FALSE, NULL );
|
|
m_hThreadBeep = ::CreateThread( NULL, 0, ThreadProcAlarmBeep, this, 0, &dwThreadID );
|
|
|
|
m_hEventWave = ::CreateEvent( NULL, FALSE, FALSE, NULL );
|
|
m_hThreadWave = ::CreateThread( NULL, 0, ThreadProcAlarmWave, this, 0, &dwThreadID );
|
|
}
|
|
|
|
CAlarm::~CAlarm()
|
|
{
|
|
if( m_hThreadBeep )
|
|
{
|
|
::ResetEvent( m_hEventAlarm );
|
|
::ResetEvent( m_hEventBeep );
|
|
::SetEvent( m_hEventClose );
|
|
::WaitForSingleObject( m_hThreadBeep, 1000UL );
|
|
::CloseHandle( m_hThreadBeep );
|
|
}
|
|
if( m_hThreadWave )
|
|
{
|
|
::ResetEvent( m_hEventWave );
|
|
::SetEvent( m_hEventClose );
|
|
::WaitForSingleObject( m_hThreadWave, 1000UL );
|
|
::CloseHandle( m_hThreadWave );
|
|
}
|
|
if( m_hEventClose )
|
|
{
|
|
::CloseHandle( m_hEventClose );
|
|
}
|
|
if( m_hEventBeep )
|
|
{
|
|
::CloseHandle( m_hEventBeep );
|
|
}
|
|
if( m_hEventAlarm )
|
|
{
|
|
::CloseHandle( m_hEventAlarm );
|
|
}
|
|
if( m_hEventWave )
|
|
{
|
|
::CloseHandle( m_hEventWave );
|
|
}
|
|
Outp( BEEPER_PPI_PORT, m_BeeperOff );
|
|
}
|
|
|
|
void CAlarm::Enable( BOOL fEnable )
|
|
{
|
|
return;
|
|
|
|
if( fEnable )
|
|
m_fEnabled = TRUE;
|
|
else
|
|
{
|
|
if( m_fEnabled )
|
|
{
|
|
AlarmEnd();
|
|
WaveStop();
|
|
}
|
|
m_fEnabled = FALSE;
|
|
}
|
|
}
|
|
|
|
void CAlarm::Beep()
|
|
{
|
|
if( m_fEnabled )
|
|
{
|
|
if( m_hThreadBeep )
|
|
::SetEvent( m_hEventBeep );
|
|
else
|
|
{
|
|
Outp( BEEPER_PPI_PORT, m_BeeperOn );
|
|
::Sleep( 20 );
|
|
Outp( BEEPER_PPI_PORT, m_BeeperOff );
|
|
}
|
|
}
|
|
}
|
|
|
|
void CAlarm::AlarmBegin()
|
|
{
|
|
if( m_fEnabled )
|
|
{
|
|
if( m_hThreadBeep )
|
|
::SetEvent( m_hEventAlarm );
|
|
else
|
|
Outp( BEEPER_PPI_PORT, m_BeeperOn );
|
|
}
|
|
}
|
|
|
|
void CAlarm::AlarmEnd()
|
|
{
|
|
if( m_hThreadBeep )
|
|
::ResetEvent( m_hEventAlarm );
|
|
else
|
|
Outp( BEEPER_PPI_PORT, m_BeeperOff );
|
|
}
|
|
|
|
DWORD CAlarm::ThreadProcBeep()
|
|
{
|
|
__try
|
|
{
|
|
HANDLE phEvent[] = { m_hEventClose, m_hEventAlarm, m_hEventBeep };
|
|
BOOL bVoice = TRUE;
|
|
while(TRUE)
|
|
{
|
|
switch( ::WaitForMultipleObjects( 3, phEvent, FALSE, INFINITE ) )
|
|
{
|
|
case WAIT_OBJECT_0+0: goto THREAD_EXIT;
|
|
case WAIT_OBJECT_0+1:
|
|
if( bVoice )
|
|
{
|
|
Outp( BEEPER_SET_FREQUENCY_PORT, 1500 );
|
|
Outp( BEEPER_SET_FREQUENCY_PORT, 1500 >> 8 );
|
|
bVoice = FALSE;
|
|
}
|
|
else
|
|
{
|
|
Outp( BEEPER_SET_FREQUENCY_PORT, 500 );
|
|
Outp( BEEPER_SET_FREQUENCY_PORT, 500 >> 8 );
|
|
bVoice = TRUE;
|
|
}
|
|
Outp( BEEPER_PPI_PORT, m_BeeperOn );
|
|
if( ::WaitForSingleObject( m_hEventClose, 100 ) == WAIT_OBJECT_0 ) goto THREAD_EXIT;
|
|
Outp( BEEPER_PPI_PORT, m_BeeperOff );
|
|
break;
|
|
case WAIT_OBJECT_0+2:
|
|
Outp( BEEPER_PPI_PORT, m_BeeperOn );
|
|
if( ::WaitForSingleObject( m_hEventClose, 20 ) == WAIT_OBJECT_0 ) goto THREAD_EXIT;
|
|
Outp( BEEPER_PPI_PORT, m_BeeperOff );
|
|
break;
|
|
}
|
|
}
|
|
THREAD_EXIT:
|
|
Outp( BEEPER_PPI_PORT, m_BeeperOff );
|
|
}
|
|
__except(1)
|
|
{
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CAlarm::ThreadProcBeep"), "CAlarm::ThreadProcBeep" );
|
|
}
|
|
return 0UL;
|
|
}
|
|
|
|
DWORD CAlarm::ThreadProcWave()
|
|
{
|
|
return 0;
|
|
|
|
BOOL bResult = FALSE;
|
|
|
|
__try
|
|
{
|
|
HANDLE phEvent[] = { m_hEventClose, m_hEventWave };
|
|
while(TRUE)
|
|
{
|
|
LPCTSTR pFileName;
|
|
switch( ::WaitForMultipleObjects( 2, phEvent, FALSE, INFINITE ) )
|
|
{
|
|
case WAIT_OBJECT_0+0: goto THREAD_EXIT;
|
|
case WAIT_OBJECT_0+1:
|
|
__try
|
|
{
|
|
bResult = m_WaveQueue.GetMessage( pFileName );
|
|
}
|
|
__except( 1 )
|
|
{
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CAlarm::ThreadProcWave"), "m_WaveQueue.GetMessage" );
|
|
}
|
|
|
|
if( bResult )
|
|
{
|
|
__try
|
|
{
|
|
sndPlaySound( pFileName, SND_SYNC | SND_NODEFAULT );
|
|
}
|
|
__except( 1 )
|
|
{
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CAlarm::ThreadProcWave"), "sndPlaySound" );
|
|
}
|
|
|
|
::SetEvent( m_hEventWave );
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
__except(1)
|
|
{
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CAlarm::ThreadProcWave"), "CAlarm::ThreadProcWave" );
|
|
}
|
|
THREAD_EXIT:
|
|
return 0UL;
|
|
}
|
|
|
|
INT CAlarm::Outp(WORD port, INT databyte)
|
|
{
|
|
if( m_dwVersion & 0x80000000 )
|
|
return _outp( port, databyte );
|
|
return 0;
|
|
}
|
|
|
|
int CAlarm::Inp(WORD port)
|
|
{
|
|
if( m_dwVersion & 0x80000000 )
|
|
return _inp( port );
|
|
return 0;
|
|
}
|
|
|
|
void CAlarm::WaveStart( LPCTSTR *ppFileNames, int nCount, BOOL bStopPrev )
|
|
{
|
|
return;
|
|
|
|
if( m_fEnabled )
|
|
{
|
|
if( bStopPrev )
|
|
WaveStop();
|
|
|
|
if( m_WaveQueue.IsEmpty() )
|
|
{
|
|
for( int i = 0; i < nCount; i++ )
|
|
m_WaveQueue.PostMessage( ppFileNames[i] );
|
|
::SetEvent( m_hEventWave );
|
|
}
|
|
}
|
|
}
|
|
|
|
void CAlarm::WaveStop()
|
|
{
|
|
return;
|
|
|
|
sndPlaySound( NULL, SND_NODEFAULT );
|
|
m_WaveQueue.Clear();
|
|
}
|