Old fashion design for PC-104
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.
 
 
 
 
 

169 lines
3.8 KiB

//----------------------------------------------------------------------------
// Laser Guard Ltd.
// Copyright © 2000-2002. All Rights Reserved.
// Version 1.0 01/01/2000
// Last modification: 08/10/2003
// PROJECT:
// SUBSYSTEM:
// FILE: SocketPTZ.cpp
// AUTHOR: Sergey Chizhevskiy
// OVERVIEW
// ~~~~~~~~
// Source file of SocketPTZ.cpp
//----------------------------------------------------------------------------
#include "stdafx.h"
#include "SensorArray.h"
#include "SocketPTZ.h"
#include "..\..\LgLib\Version.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
CSocketPTZ::CSocketPTZ()
{
m_nDeviceCount = 0;
m_nDeviceCurrent = 0;
m_nRCount = 0;
m_nWCount = 0;
m_nType = SOCKET_PTZ;
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CSocketPTZ::CSocketPTZ") );
}
CSocketPTZ::~CSocketPTZ()
{
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CSocketPTZ::~CSocketPTZ") );
}
BOOL CSocketPTZ::Create( CSensorArray* pSensorArray, LPCTSTR pPort )
{
m_pSensorArray = pSensorArray;
if( !CSocketRS232::Create( pPort, 4800, 8, NOPARITY, ONESTOPBIT ) )
{
m_pSensorArray->GetEventQueue()->PostEvent( LGS_EVENT_SOCKET_COMMUNICATION, FALSE, m_nType, m_nNumber, RGB( 0xFF, 0, 0 ), "Can't create PTZ line" );
return FALSE;
}
else
m_pSensorArray->GetEventQueue()->PostEvent( LGS_EVENT_SOCKET_COMMUNICATION, TRUE, m_nType, m_nNumber, RGB( 0, 0xFF, 0 ), "PTZ line created" );
return TRUE;
}
BOOL CSocketPTZ::DeviceAttach( CDevicePTZs *pDevice )
{
if( m_nDeviceCount < MAX_DEVICE )
{
for( int i = 0; i < m_nDeviceCount; i++ )
if( m_ppDevice[ i ] == pDevice )
return FALSE;
m_pTime[ m_nDeviceCount ] = 0UL;
m_ppDevice[ m_nDeviceCount++ ] = pDevice;
pDevice->SetSocket( this );
pDevice->SetAddress( m_nDeviceCount );
CSocketRS232::Start();
return TRUE;
}
return FALSE;
}
BOOL CSocketPTZ::DeviceDetach( CDevicePTZs *pDevice )
{
for( int i = 0; i < m_nDeviceCount; i++ )
{
if( m_ppDevice[ i ] == pDevice )
{
pDevice->SetSocket( NULL );
m_ppDevice[ i ] = m_ppDevice[ --m_nDeviceCount ];
if( m_nDeviceCurrent >= m_nDeviceCount )
m_nDeviceCurrent = 0;
return TRUE;
}
}
return FALSE;
}
int CSocketPTZ::OnCommand()
{
BOOL bWait = FALSE;
for( int i = 0; i < m_nDeviceCount; i++ )
{
if( GetTickCount() > m_pTime[ m_nDeviceCurrent ] )
{
BOOL bPause = FALSE;
if( m_ppDevice[ m_nDeviceCurrent ]->GetCommand( m_pBuffer, m_nWCount, m_nRCount, bPause ) )
{
if( !bPause )
{
m_pTime[ m_nDeviceCurrent ] = 0UL;
return CMD_WRITE;
}
else
{
m_pTime[ m_nDeviceCurrent ] = GetTickCount() + m_nRCount; // m_nRCount is pause time
bWait = TRUE;
}
}
else
m_nDeviceCurrent = (m_nDeviceCurrent + 1) % m_nDeviceCount;
}
else
{
m_nDeviceCurrent = (m_nDeviceCurrent + 1) % m_nDeviceCount;
bWait = TRUE;
}
}
if( bWait )
return CMD_PAUSE;
return CMD_STOP;
}
void CSocketPTZ::OnBeforeWrite( LPBYTE pBuffer, DWORD& nCount )
{
::CopyMemory( pBuffer, m_pBuffer, m_nWCount );
nCount = m_nWCount;
::EscapeCommFunction( m_hCommPort, SETRTS );
}
int CSocketPTZ::OnAfterWrite()
{
return CMD_READ;
}
void CSocketPTZ::OnBeforeRead( DWORD& nCount, DWORD& dwTime )
{
nCount = m_nRCount;
dwTime = m_nRCount * 5UL;
::EscapeCommFunction( m_hCommPort, CLRRTS );
}
int CSocketPTZ::OnAfterRead( LPBYTE pBuffer, DWORD nCount )
{
if( m_ppDevice[ m_nDeviceCurrent ]->SetAnswer( pBuffer, nCount ) )
m_nCountSuccess++;
else
m_nCountFailure++;
m_nDeviceCurrent = (m_nDeviceCurrent + 1) % m_nDeviceCount;
return CMD_COMMAND;
}
int CSocketPTZ::OnPause( DWORD &dwTime )
{
dwTime = 1UL;
return CMD_COMMAND;
}