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.
1858 lines
58 KiB
1858 lines
58 KiB
//----------------------------------------------------------------------------
|
|
// Laser Guard Ltd.
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
// Version 1.0 01/01/2000
|
|
// Last modification: 17/11/2003
|
|
// PROJECT:
|
|
// SUBSYSTEM:
|
|
// FILE: KERNEL.CPP
|
|
// AUTHOR: Sergey Chizhevskiy
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Source file of KERNEL.CPP
|
|
//----------------------------------------------------------------------------
|
|
#include "StdAfx.h"
|
|
#include <stdio.h>
|
|
#include "kernel.h"
|
|
#include "..\lglib\comm\lgsm.h"
|
|
#include "..\lglib\lgbitcod.h"
|
|
#include "..\lglib\version.h"
|
|
#include "screen.h"
|
|
#include "Camera.h"
|
|
#include "CMigPTZ.h"
|
|
#include "CMicPTZ.h"
|
|
#include "CPG3AD.h"
|
|
#include "CTKS576.h"
|
|
#include "CVicon.h"
|
|
#include "CPelco.h"
|
|
#include "CHebron.h"
|
|
|
|
static DWORD far* g_Timer = (DWORD far*)0x46CL;
|
|
CHAR CKernel::s_pSoftwareVersion[MAX_PATH] = "";
|
|
INT CKernel::s_nSoftwareVersion = 0;
|
|
|
|
#ifdef INCLUDE_WINDOWS_DEFINITIONS
|
|
#define TIMER() *g_Timer
|
|
#else
|
|
#define TIMER() (GetTickCount() * 10 / 182)
|
|
#endif
|
|
|
|
void CKernel::Reset( BOOL bFullReset )
|
|
{
|
|
m_Detector[0].Reset( bFullReset );
|
|
m_Detector[1].Reset( bFullReset );
|
|
m_GetFile.Reset();
|
|
#ifdef DEBUG_GRAPH_SCREEN
|
|
g_Screen.Clear();
|
|
#endif
|
|
// reset error timings
|
|
memset( m_dwTimeErrorOverflowSST, 0, sizeof(m_dwTimeErrorOverflowSST) );
|
|
memset( m_dwTimeErrorOverflow, 0, sizeof(m_dwTimeErrorOverflow) );
|
|
memset( m_dwTimeErrorSun, 0, sizeof(m_dwTimeErrorSun) );
|
|
m_dwTimePower = 0UL;
|
|
|
|
// reset board
|
|
m_pBoard->Reset();
|
|
}
|
|
|
|
BOOL CKernel::Run()
|
|
{
|
|
BYTE *pBuffer;
|
|
INT nCount;
|
|
BYTE nMode = LGS::MODE_DETECTOR;
|
|
BOOL bRestart = FALSE;
|
|
|
|
DWORD nBoardIrq = 0;
|
|
DWORD nBoardTimer = TIMER();
|
|
BOOL bBoardNoIrq = FALSE;
|
|
|
|
#ifndef COMPILE_AS_GETFILE
|
|
BOOL bFastTimerValid = FALSE;
|
|
#endif
|
|
|
|
BOOL bSetHzDataInProgress = FALSE;
|
|
BOOL bSetCalibrationTableInProgress = FALSE;
|
|
|
|
BOOL bPower, bZero, bSun[2];
|
|
INT nRange[2];
|
|
|
|
#ifdef COMPILE_AS_GETFILE
|
|
DWORD dwStartTime = TIMER();
|
|
BOOL bGetFileRun = FALSE;
|
|
// send human readable information
|
|
{
|
|
// load user settings
|
|
AUTO_RESET AutoReset;
|
|
BOARD_SETTINGS BoardSettings;
|
|
SWITCHER_SETTINGS SwitcherSettings;
|
|
CKernel::LoadUserSettings( &AutoReset, &BoardSettings, &SwitcherSettings );
|
|
|
|
CHAR pText[MAX_PATH];
|
|
INT nText;
|
|
|
|
nText = sprintf( pText, "SOFTWARE VERSION <%s>\r\n", s_pSoftwareVersion );
|
|
m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
|
|
|
|
nText = sprintf( pText, "ADDRESS <%d>\r\n", m_nAddress );
|
|
m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
|
|
|
|
nText = sprintf( pText, "SERIAL NUMBER <%s>\r\n", m_pSerialNumber );
|
|
m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
|
|
|
|
nText = sprintf( pText, "AUTORESET_ENABLE <%d>\r\n", AutoReset.bEnabled );
|
|
m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
|
|
|
|
nText = sprintf( pText, "AUTORESET_INTERLEAVE <%ld>\r\n", AutoReset.dwInterleave );
|
|
m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
|
|
|
|
nText = sprintf( pText, "AUTORESET_TIMEOUT <%ld>\r\n", AutoReset.dwTimeout );
|
|
m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
|
|
|
|
nText = sprintf( pText, "BOARD_TEMPERATURE <%d>\r\n", (INT)(CHAR)BoardSettings.nTemperature );
|
|
m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
|
|
|
|
nText = sprintf( pText, "BOARD_ZEROSHIFT <%d>\r\n", BoardSettings.nZeroShift );
|
|
m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
|
|
|
|
nText = sprintf( pText, "SWITCHER_TABLE <%d,%d,%d>\r\n", SwitcherSettings.pTable[0], SwitcherSettings.pTable[1], SwitcherSettings.pTable[2] );
|
|
m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
|
|
}
|
|
#endif
|
|
|
|
// update settings
|
|
AUTO_RESET AutoReset;
|
|
BOARD_SETTINGS BoardSettings;
|
|
SWITCHER_SETTINGS SwitcherSettings;
|
|
LoadUserSettings( &AutoReset, &BoardSettings, &SwitcherSettings );
|
|
SaveUserSettings( &AutoReset, &BoardSettings, &SwitcherSettings);
|
|
|
|
while( m_bRun )
|
|
{
|
|
#ifndef INCLUDE_WINDOWS_DEFINITIONS
|
|
Sleep(0);
|
|
#endif
|
|
|
|
#ifdef WATCHDOG_ENABLED
|
|
// update watchdog timer
|
|
m_WatchDog.Update( TIMER() );
|
|
#endif
|
|
|
|
#ifdef COMPILE_AS_GETFILE
|
|
if( !bGetFileRun )
|
|
{
|
|
if( ( (TIMER()) - dwStartTime ) > LGS_GETFILE_WAIT_TIME )
|
|
{
|
|
// quit
|
|
m_bRun = FALSE;
|
|
}
|
|
}
|
|
#endif
|
|
|
|
#ifndef COMPILE_AS_GETFILE
|
|
// clear zero flag
|
|
BOOL bInvalidateCamera = FALSE;
|
|
|
|
// check fast timer
|
|
static DWORD dwSlowTime = 0;
|
|
if( !bFastTimerValid )
|
|
{
|
|
if( TIMER() != dwSlowTime )
|
|
{
|
|
dwSlowTime = TIMER();
|
|
bInvalidateCamera = TRUE;
|
|
}
|
|
}
|
|
#endif
|
|
|
|
// perform work depend on work mode
|
|
switch( nMode )
|
|
{
|
|
case LGS::MODE_BORDER:
|
|
case LGS::MODE_DETECTOR:
|
|
// check IRQ
|
|
if( ( (TIMER()) - nBoardTimer ) > 18UL )
|
|
{
|
|
if( !nBoardIrq )
|
|
{
|
|
bBoardNoIrq = TRUE;
|
|
#ifdef DEBUG_BOARD_PRINT_NO_IRQ
|
|
printf( "NO IRQ %04x\n", m_pBoard->ReadNewBoard() );
|
|
#endif
|
|
// reset board
|
|
m_pBoard->Reset();
|
|
|
|
#ifndef COMPILE_AS_GETFILE
|
|
// fast timer is not valid
|
|
bFastTimerValid = FALSE;
|
|
#endif
|
|
}
|
|
nBoardTimer = TIMER();
|
|
nBoardIrq = 0;
|
|
}
|
|
// check board
|
|
if( m_pBoard->GetData( &bZero, bSun, nRange, &bPower ) )
|
|
{
|
|
// perform linearization
|
|
nRange[0] = m_Calibrator[0].Calibrate( nRange[0] );
|
|
nRange[1] = m_Calibrator[1].Calibrate( nRange[1] );
|
|
|
|
// update voltage state
|
|
m_Voltage.Invalidate( bPower );
|
|
|
|
nBoardIrq++;
|
|
|
|
#ifndef COMPILE_AS_GETFILE
|
|
// fast timer is valid
|
|
bFastTimerValid = TRUE;
|
|
#endif
|
|
|
|
#ifdef DEBUG_BOARD_SET_TEST_BIT
|
|
m_pBoard->SetTestBit( TRUE );
|
|
#endif
|
|
|
|
#ifdef LGS_MIRROR
|
|
if( m_bWaitFirstZero && bZero )
|
|
{
|
|
m_bWaitFirstZero = FALSE;
|
|
m_nDetector = 0;
|
|
}
|
|
|
|
if( !m_bWaitFirstZero )
|
|
{
|
|
if( bZero )
|
|
m_nDetector = m_nAngle = 0;
|
|
else
|
|
{
|
|
m_nAngle++;
|
|
if( m_nAngle == LGS_MAX_DETECTOR_ANGLES )
|
|
{
|
|
m_nDetector = 1 - m_nDetector;
|
|
m_nAngle = 0;
|
|
bZero = TRUE;
|
|
}
|
|
}
|
|
|
|
m_Tracker[0].Invalidate();
|
|
#ifdef COMM_WITHOUT_INTERRUPTS
|
|
m_pComm485->Invalidate();
|
|
m_pCameraComm->Invalidate();
|
|
#endif
|
|
m_Detector[m_nDetector].Invalidate( bZero, bSun[0], nRange[0], TRUE );
|
|
}
|
|
#else
|
|
m_Tracker[0].Invalidate();
|
|
#ifdef COMM_WITHOUT_INTERRUPTS
|
|
m_pComm485->Invalidate();
|
|
m_pCameraComm->Invalidate();
|
|
#endif
|
|
m_Tracker[1].Invalidate();
|
|
#ifdef COMM_WITHOUT_INTERRUPTS
|
|
m_pComm485->Invalidate();
|
|
m_pCameraComm->Invalidate();
|
|
#endif
|
|
m_Detector[0].Invalidate( bZero, bSun[0], nRange[0], m_Detector[1].IsAllowFlip() );
|
|
#ifdef COMM_WITHOUT_INTERRUPTS
|
|
m_pComm485->Invalidate();
|
|
m_pCameraComm->Invalidate();
|
|
#endif
|
|
m_Detector[1].Invalidate( bZero, bSun[1], nRange[1], m_Detector[0].IsAllowFlip() );
|
|
#endif
|
|
|
|
#ifdef DEBUG_BOARD_SET_TEST_BIT
|
|
m_pBoard->SetTestBit( FALSE );
|
|
#endif
|
|
#ifndef COMPILE_AS_GETFILE
|
|
bInvalidateCamera = TRUE;
|
|
#endif
|
|
}
|
|
break;
|
|
|
|
default:
|
|
case LGS::MODE_FILESYSTEM:
|
|
case LGS::MODE_GETFILE:
|
|
if( m_pBoard->GetData( &bZero, bSun, nRange, &bPower ) )
|
|
{
|
|
// perform linearization
|
|
nRange[0] = m_Calibrator[0].Calibrate( nRange[0] );
|
|
nRange[1] = m_Calibrator[1].Calibrate( nRange[1] );
|
|
|
|
// update voltage state
|
|
m_Voltage.Invalidate( bPower );
|
|
|
|
#ifndef COMPILE_AS_GETFILE
|
|
bInvalidateCamera = TRUE;
|
|
#endif
|
|
nBoardIrq++;
|
|
|
|
#ifndef COMPILE_AS_GETFILE
|
|
// fast timer is valid
|
|
bFastTimerValid = TRUE;
|
|
#endif
|
|
}
|
|
break;
|
|
}
|
|
|
|
// try to work in windows
|
|
#ifndef INCLUDE_WINDOWS_DEFINITIONS
|
|
bFastTimerValid = FALSE;
|
|
#endif
|
|
|
|
#ifndef COMPILE_AS_GETFILE
|
|
// process camera commands
|
|
if( bInvalidateCamera )
|
|
{
|
|
#ifdef COMM_WITHOUT_INTERRUPTS
|
|
m_pComm485->Invalidate();
|
|
m_pCameraComm->Invalidate();
|
|
#endif
|
|
|
|
#ifdef DEBUG_BOARD_SET_TEST_BIT_2
|
|
m_pBoard->SetTestBit2( TRUE );
|
|
#endif
|
|
|
|
// process camera commands
|
|
m_pCamera->Invalidate( TIMER(), m_pBoard->GetTimer(), bFastTimerValid );
|
|
|
|
#ifdef DEBUG_BOARD_SET_TEST_BIT_2
|
|
m_pBoard->SetTestBit2( FALSE );
|
|
#endif
|
|
}
|
|
|
|
// process relay commands
|
|
m_Relay.Invalidate( m_pBoard->GetTimer(), TIMER() );
|
|
#endif
|
|
|
|
//process communication commands
|
|
#ifdef COMM_WITHOUT_INTERRUPTS
|
|
m_pComm485->Invalidate();
|
|
m_pCameraComm->Invalidate();
|
|
#endif
|
|
|
|
// auto reset
|
|
if( m_AutoReset.IsNeedToReset() )
|
|
{
|
|
bRestart = TRUE;
|
|
m_bRun = FALSE;
|
|
}
|
|
|
|
// check for new commands from host
|
|
if( m_Protocol.Read( &pBuffer, &nCount, 0, FALSE ) )
|
|
{
|
|
// check address
|
|
BYTE bAddress = 0;
|
|
if( nCount && ( (m_nAddress == *pBuffer) || (LGS_EXCLUSIVE_ADDRESS == *pBuffer) ) )
|
|
{
|
|
// store address
|
|
bAddress = *pBuffer;
|
|
|
|
// update pointers
|
|
nCount--;
|
|
pBuffer++;
|
|
// check remainig count
|
|
if( nCount )
|
|
{
|
|
BYTE pSendBuffer[1024];
|
|
PBYTE pSendBufferPtr = pSendBuffer;
|
|
int nSendCount = 2;
|
|
|
|
// set address
|
|
*pSendBufferPtr++ = bAddress;
|
|
|
|
BYTE bHostCommand = *pBuffer++;
|
|
|
|
// Restart if set hz data was not finished correctly
|
|
if( ( bSetHzDataInProgress && bHostCommand != LGS::CMD_SET_HZ_DATA ) ||
|
|
( bSetCalibrationTableInProgress && bHostCommand != LGS::CMD_SET_CALIBRATION_TABLE ) )
|
|
{
|
|
bRestart = TRUE;
|
|
m_bRun = FALSE;
|
|
}
|
|
|
|
// get command from buffer
|
|
switch( bHostCommand )
|
|
{
|
|
#ifndef EMBEDDED_CAMERA_DISABLE
|
|
case LGS::CMD_CAMERA:
|
|
// build CMD_MODE command
|
|
*pSendBufferPtr++ = LGS::CMD_CAMERA;
|
|
// process command
|
|
m_pCamera->OnProtocolLgsCameraCommand( pBuffer, nCount, pSendBufferPtr, nSendCount );
|
|
// write command
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
break;
|
|
#endif
|
|
case LGS::CMD_RELAY:
|
|
// build CMD_MODE command
|
|
*pSendBufferPtr++ = LGS::CMD_RELAY;
|
|
// process command
|
|
m_Relay.OnProtocolLgsRelayCommand( pBuffer, nCount, pSendBufferPtr, nSendCount );
|
|
// write command
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
break;
|
|
|
|
case LGS::CMD_MODE:
|
|
{
|
|
// get command parameters
|
|
BOOL bSetMode = FALSE;
|
|
BYTE nNewMode = nMode;
|
|
LGS::GetMode( pBuffer, &bSetMode, &nNewMode );
|
|
// build CMD_MODE command
|
|
*pSendBufferPtr++ = LGS::CMD_MODE;
|
|
nSendCount += LGS::BuildMode( pSendBufferPtr, FALSE, nMode );
|
|
// write command
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
// if needs to switch mode
|
|
if( bSetMode && nMode != nNewMode )
|
|
{
|
|
switch( nNewMode )
|
|
{
|
|
case LGS::MODE_GETFILE:
|
|
#ifdef COMPILE_AS_GETFILE
|
|
bGetFileRun = TRUE;
|
|
#endif
|
|
break;
|
|
|
|
case LGS::MODE_BORDER:
|
|
case LGS::MODE_DETECTOR:
|
|
case LGS::MODE_FILESYSTEM:
|
|
m_Detector[0].BorderEnable( nNewMode == LGS::MODE_BORDER );
|
|
m_Detector[1].BorderEnable( nNewMode == LGS::MODE_BORDER );
|
|
#ifdef COMPILE_AS_GETFILE
|
|
bGetFileRun = FALSE;
|
|
dwStartTime = TIMER();
|
|
#endif
|
|
break;
|
|
#ifdef DEBUG_ENABLE_SEND_BOARDDATA
|
|
case LGS::MODE_SENDBOARDDATA1:
|
|
case LGS::MODE_SENDBOARDDATA2:
|
|
DoSendBoardData( nNewMode - LGS::MODE_SENDBOARDDATA1 );
|
|
break;
|
|
#endif
|
|
}
|
|
|
|
// reset after switching mode
|
|
if( nMode != LGS::MODE_BORDER && nMode != LGS::MODE_DETECTOR )
|
|
Reset( TRUE );
|
|
|
|
// store new mode
|
|
nMode = nNewMode;
|
|
|
|
// reset IRQ checking
|
|
nBoardIrq = 0;
|
|
nBoardTimer = TIMER();
|
|
}
|
|
}
|
|
break;
|
|
|
|
case LGS::CMD_BORDER:
|
|
{
|
|
// get command parameters
|
|
BYTE bError;
|
|
INT nAngle, nRange0, nRange1;
|
|
LGS::GetBorder( pBuffer, &bError, &nAngle, &nRange0, &nRange1 );
|
|
// build CMD_BORDER command
|
|
*pSendBufferPtr++ = LGS::CMD_BORDER;
|
|
if( nMode != LGS::MODE_BORDER )
|
|
nSendCount += LGS::BuildBorder( pSendBufferPtr, LGS::BD_ERRORMODE, 0, 0, 0 );
|
|
else
|
|
{
|
|
|
|
BYTE bError = ( (!m_Detector[0].GetBorderRange( nAngle, &nRange0 )) ||
|
|
(!m_Detector[1].GetBorderRange( nAngle, &nRange1 )) ) ? LGS::BD_NOTREADY : 0;
|
|
if( bError )
|
|
nSendCount += LGS::BuildBorder( pSendBufferPtr, bError, 0, 0, 0 );
|
|
else
|
|
nSendCount += LGS::BuildBorder( pSendBufferPtr, 0, nAngle, nRange0 >> 1, nRange1 >> 1 );
|
|
}
|
|
// write command
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
}
|
|
break;
|
|
|
|
case LGS::CMD_STATE:
|
|
{
|
|
// build CMD_STATE command
|
|
*pSendBufferPtr++ = LGS::CMD_STATE;
|
|
if( nMode != LGS::MODE_DETECTOR )
|
|
nSendCount += LGS::BuildError( pSendBufferPtr, 0, LGS::ER_MODE, 0 );
|
|
else
|
|
{
|
|
for( int i = 0; i < 2; i++ )
|
|
{
|
|
CDetector *pDetector = m_Detector + i;
|
|
#ifdef LGS_MIRROR
|
|
CTracker *pTracker = m_Tracker + 0;
|
|
#else
|
|
CTracker *pTracker = m_Tracker + i;
|
|
#endif
|
|
BYTE bDevice = i ? LGS::ID_DEVICE1 : LGS::ID_DEVICE0;
|
|
|
|
// assume that no errors
|
|
BYTE bErrorMask = LGS::ER_NONE;
|
|
INT nErrorAngle = 0;
|
|
// check for tracker overflow
|
|
if( ( m_dwTimeErrorOverflow[i] < TIMER() ) && pTracker->GetLastErrorOverflow() )
|
|
{
|
|
m_dwTimeErrorOverflow[i] = TIMER() + LGS_COMM_ERROR_SEND_PERIOD;
|
|
bErrorMask |= LGS::ER_OVERFLOW;
|
|
}
|
|
// check for tracker scan to scan overflow
|
|
if( ( m_dwTimeErrorOverflowSST[i] < TIMER() ) && pTracker->GetLastErrorOverflowSST() )
|
|
{
|
|
m_dwTimeErrorOverflowSST[i] = TIMER() + LGS_COMM_ERROR_SEND_PERIOD;
|
|
bErrorMask |= LGS::ER_SSTOVERFLOW;
|
|
}
|
|
// check for detector sun errors
|
|
if( ( m_dwTimeErrorSun[i] < TIMER() ) && pDetector->GetLastErrorSun() )
|
|
{
|
|
m_dwTimeErrorSun[i] = TIMER() + LGS_COMM_ERROR_SEND_PERIOD;
|
|
bErrorMask |= LGS::ER_SUNBIT;
|
|
}
|
|
// check for detector angle errors
|
|
if( pDetector->GetLastErrorAngle() )
|
|
{
|
|
bErrorMask |= LGS::ER_ANGLE;
|
|
nErrorAngle = pDetector->GetLastErrorAngleValue();
|
|
}
|
|
// check for kernel error
|
|
if( bBoardNoIrq )
|
|
{
|
|
bErrorMask |= LGS::ER_NOIRQ;
|
|
bBoardNoIrq = FALSE;
|
|
}
|
|
// if error exist
|
|
if( bErrorMask )
|
|
nSendCount += LGS::BuildError( pSendBufferPtr, bDevice, bErrorMask, nErrorAngle );
|
|
// place target information
|
|
CTracker::TARGET target;
|
|
while( pTracker->GetTarget( &target ) )
|
|
{
|
|
#ifdef LGS_MIRROR
|
|
|
|
#ifdef LGS_TEST_SEND_TARGET_WIDTH
|
|
nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, target.nAngle << 1, target.nRange, target.nWidth );
|
|
#else
|
|
nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, target.nAngle << 1, target.nRange );
|
|
#endif
|
|
|
|
#else
|
|
|
|
#ifdef LGS_TEST_SEND_TARGET_WIDTH
|
|
nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, target.nAngle, target.nRange, target.nWidth );
|
|
#else
|
|
nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, target.nAngle, target.nRange );
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
if( nSendCount >= 20 )
|
|
break;
|
|
}
|
|
|
|
if( nSendCount >= 20 )
|
|
break;
|
|
}
|
|
}
|
|
#ifndef EMBEDDED_CAMERA_DISABLE
|
|
// add camera tags
|
|
m_pCamera->OnProtocolLgsStateCommand( pSendBufferPtr, nSendCount );
|
|
#endif
|
|
// write command
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
}
|
|
break;
|
|
|
|
case LGS::CMD_STATE_2:
|
|
// prepare response
|
|
OnCmdState2( pBuffer, nCount, pSendBufferPtr, nSendCount, nMode, bBoardNoIrq );
|
|
// write command
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
break;
|
|
|
|
case LGS::CMD_GET_WIDTH_TABLE:
|
|
// prepare response
|
|
OnCmdGetWidthTable( pBuffer, nCount, pSendBufferPtr, nSendCount );
|
|
// write command
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
break;
|
|
|
|
case LGS::CMD_SET_WIDTH_TABLE:
|
|
// prepare response
|
|
OnCmdSetWidthTable( pBuffer, nCount, pSendBufferPtr, nSendCount );
|
|
// write command
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
break;
|
|
|
|
case LGS::CMD_GET_ZOOM_TABLE:
|
|
// prepare response
|
|
OnCmdGetZoomTable( pBuffer, nCount, pSendBufferPtr, nSendCount );
|
|
// write command
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
break;
|
|
|
|
case LGS::CMD_SET_ZOOM_TABLE:
|
|
// prepare response
|
|
OnCmdSetZoomTable( pBuffer, nCount, pSendBufferPtr, nSendCount );
|
|
// write command
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
// update camera settings
|
|
m_pCamera->SaveZoomTable();
|
|
// reset after file operation
|
|
Reset( TRUE );
|
|
// reset IRQ checking
|
|
nBoardIrq = 0;
|
|
nBoardTimer = TIMER();
|
|
break;
|
|
|
|
case LGS::CMD_GET_TILT_TABLE:
|
|
// prepare response
|
|
OnCmdGetTiltTable( pBuffer, nCount, pSendBufferPtr, nSendCount );
|
|
// write command
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
break;
|
|
|
|
case LGS::CMD_SET_TILT_TABLE:
|
|
// prepare response
|
|
OnCmdSetTiltTable( pBuffer, nCount, pSendBufferPtr, nSendCount );
|
|
// write command
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
// update camera settings
|
|
m_pCamera->SaveTiltTable();
|
|
// reset after file operation
|
|
Reset( TRUE );
|
|
// reset IRQ checking
|
|
nBoardIrq = 0;
|
|
nBoardTimer = TIMER();
|
|
break;
|
|
|
|
case LGS::CMD_GET_LRF_DISABLE:
|
|
// prepare response
|
|
OnCmdGetLrfDisable( pBuffer, nCount, pSendBufferPtr, nSendCount );
|
|
// write command
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
break;
|
|
|
|
case LGS::CMD_SET_LRF_DISABLE:
|
|
// prepare response
|
|
OnCmdSetLrfDisable( pBuffer, nCount, pSendBufferPtr, nSendCount );
|
|
// write command
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
// reset after file operation
|
|
Reset( TRUE );
|
|
// reset IRQ checking
|
|
nBoardIrq = 0;
|
|
nBoardTimer = TIMER();
|
|
break;
|
|
|
|
case LGS::CMD_GET_HZ_DATA:
|
|
m_pShadow->OnCmdGetHzData( pBuffer, nCount, pSendBufferPtr, nSendCount );
|
|
// write command
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
break;
|
|
|
|
case LGS::CMD_SET_HZ_DATA:
|
|
{
|
|
BOOL bPendingSave = m_pShadow->OnCmdSetHzData( pBuffer, nCount, pSendBufferPtr, nSendCount );
|
|
// write command
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
// save
|
|
if( bPendingSave )
|
|
{
|
|
// save data
|
|
m_pShadow->Save();
|
|
// reset after file operation
|
|
Reset( TRUE );
|
|
// reset IRQ checking
|
|
nBoardIrq = 0;
|
|
nBoardTimer = TIMER();
|
|
#ifdef LGS_MIRROR
|
|
bRestart = TRUE;
|
|
m_bRun = FALSE;
|
|
#endif
|
|
}
|
|
}
|
|
break;
|
|
|
|
case LGS::CMD_GET_HZ_ENABLE:
|
|
m_pShadow->OnCmdGetHzEnable( pBuffer, nCount, pSendBufferPtr, nSendCount );
|
|
// write command
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
break;
|
|
|
|
case LGS::CMD_SET_HZ_ENABLE:
|
|
{
|
|
BOOL bPendingSave = m_pShadow->OnCmdSetHzEnable( pBuffer, nCount, pSendBufferPtr, nSendCount );
|
|
// write command
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
// save
|
|
if( bPendingSave )
|
|
{
|
|
// save data
|
|
m_pShadow->Save();
|
|
// reset after file operation
|
|
Reset( TRUE );
|
|
// reset IRQ checking
|
|
nBoardIrq = 0;
|
|
nBoardTimer = TIMER();
|
|
// set data finished correctly
|
|
bSetHzDataInProgress = FALSE;
|
|
}
|
|
else
|
|
bSetHzDataInProgress = TRUE;
|
|
}
|
|
break;
|
|
|
|
case LGS::CMD_GET_CALIBRATION_TABLE:
|
|
OnCmdGetCalibrationTable( pBuffer, nCount, pSendBufferPtr, nSendCount );
|
|
// write command
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
break;
|
|
|
|
case LGS::CMD_SET_CALIBRATION_TABLE:
|
|
{
|
|
INT nDevice = 0;
|
|
BOOL bPendingSave = OnCmdSetCalibrationTable( pBuffer, nCount, pSendBufferPtr, nSendCount, nDevice );
|
|
// write command
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
// save
|
|
if( bPendingSave )
|
|
{
|
|
// save data
|
|
switch( nDevice )
|
|
{
|
|
case 0: m_Calibrator[nDevice].Save( "lt0.ini" ); break;
|
|
case 1: m_Calibrator[nDevice].Save( "lt1.ini" ); break;
|
|
}
|
|
// reset after file operation
|
|
Reset( TRUE );
|
|
// reset IRQ checking
|
|
nBoardIrq = 0;
|
|
nBoardTimer = TIMER();
|
|
// set data finished correctly
|
|
bSetCalibrationTableInProgress = FALSE;
|
|
}
|
|
else
|
|
bSetCalibrationTableInProgress = TRUE;
|
|
}
|
|
break;
|
|
|
|
case LGS::CMD_QUIT:
|
|
*pSendBufferPtr++ = LGS::CMD_QUIT;
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
m_bRun = FALSE;
|
|
break;
|
|
|
|
case LGS::CMD_RESTART:
|
|
*pSendBufferPtr++ = LGS::CMD_RESTART;
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
bRestart = TRUE;
|
|
m_bRun = FALSE;
|
|
break;
|
|
|
|
case LGS::CMD_GET_SERIAL_NUMBER:
|
|
// reply command
|
|
*pSendBufferPtr++ = LGS::CMD_GET_SERIAL_NUMBER;
|
|
// reply data
|
|
nSendCount += LGS::BuildSerialNumber( pSendBufferPtr, m_nAddress, m_nSerialNumber, m_pSerialNumber );
|
|
// write into port
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
break;
|
|
|
|
case LGS::CMD_GET_SOFTWARE_VERSION:
|
|
// reply command
|
|
*pSendBufferPtr++ = LGS::CMD_GET_SOFTWARE_VERSION;
|
|
// reply data
|
|
nSendCount += LGS::BuildSoftwareVersion( pSendBufferPtr, (PBYTE)s_pSoftwareVersion, s_nSoftwareVersion );
|
|
// write into port
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
break;
|
|
|
|
case LGS::CMD_GET_VOLTAGE:
|
|
// reply command
|
|
*pSendBufferPtr++ = LGS::CMD_GET_VOLTAGE;
|
|
// reply data
|
|
nSendCount += LGS::BuildEvtVoltage( pSendBufferPtr, m_Voltage.GetVoltage() );
|
|
// write into port
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
break;
|
|
|
|
#ifndef EMBEDDED_CAMERA_DISABLE
|
|
case LGS::CMD_GET_CAMERA_PARAMETERS:
|
|
{
|
|
// reply command
|
|
*pSendBufferPtr++ = LGS::CMD_GET_CAMERA_PARAMETERS;
|
|
// reply data
|
|
nSendCount += LGS::BuildCameraParameters( pSendBufferPtr, &m_pCamera->GetParameters() );
|
|
// write into port
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
}
|
|
break;
|
|
|
|
case LGS::CMD_SET_CAMERA_PARAMETERS:
|
|
{
|
|
LGS::CAMERA_PARAMETERS cp;
|
|
LGS::GetCameraParameters( pBuffer, &cp );
|
|
// reply command
|
|
*pSendBufferPtr++ = LGS::CMD_SET_CAMERA_PARAMETERS;
|
|
// reply data
|
|
nSendCount += LGS::BuildCameraParameters( pSendBufferPtr, &cp );
|
|
// write into port
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
// store serial number
|
|
SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, &cp, &m_Relay.GetParameters(), &m_Voltage.GetParameters(), &m_LRFDisable );
|
|
// restart program
|
|
m_bRun = FALSE;
|
|
}
|
|
break;
|
|
#endif
|
|
|
|
case LGS::CMD_GET_VOLTAGE_PARAMETERS:
|
|
{
|
|
// reply command
|
|
*pSendBufferPtr++ = LGS::CMD_GET_VOLTAGE_PARAMETERS;
|
|
// reply data
|
|
nSendCount += LGS::BuildVoltageParameters( pSendBufferPtr, &m_Voltage.GetParameters() );
|
|
// write into port
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
}
|
|
break;
|
|
|
|
case LGS::CMD_SET_VOLTAGE_PARAMETERS:
|
|
{
|
|
LGS::VOLTAGE_PARAMETERS vp;
|
|
// store voltage parameters
|
|
LGS::GetVoltageParameters( pBuffer, &vp );
|
|
// reply command
|
|
*pSendBufferPtr++ = LGS::CMD_SET_VOLTAGE_PARAMETERS;
|
|
// reply data
|
|
nSendCount += LGS::BuildVoltageParameters( pSendBufferPtr, &vp );
|
|
// write into port
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
// store serial number
|
|
SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, &m_pCamera->GetParameters(), &m_Relay.GetParameters(), &vp, &m_LRFDisable );
|
|
// update voltage prameters
|
|
m_Voltage.SetParameters( &vp );
|
|
// reset after file operation
|
|
Reset( TRUE );
|
|
// reset IRQ checking
|
|
nBoardIrq = 0;
|
|
nBoardTimer = TIMER();
|
|
}
|
|
break;
|
|
|
|
case LGS::CMD_GET_RELAY_PARAMETERS:
|
|
{
|
|
// reply command
|
|
*pSendBufferPtr++ = LGS::CMD_GET_RELAY_PARAMETERS;
|
|
// reply data
|
|
nSendCount += LGS::BuildRelayParameters( pSendBufferPtr, &m_Relay.GetParameters() );
|
|
// write into port
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
}
|
|
break;
|
|
|
|
case LGS::CMD_SET_RELAY_PARAMETERS:
|
|
{
|
|
LGS::RELAY_PARAMETERS rp;
|
|
LGS::GetRelayParameters( pBuffer, &rp );
|
|
// reply command
|
|
*pSendBufferPtr++ = LGS::CMD_SET_RELAY_PARAMETERS;
|
|
// reply data
|
|
nSendCount += LGS::BuildRelayParameters( pSendBufferPtr, &rp );
|
|
// write into port
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
// store serial number
|
|
SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, &m_pCamera->GetParameters(), &rp, &m_Voltage.GetParameters(), &m_LRFDisable );
|
|
// update relay parameters
|
|
m_Relay.SetParameters( &rp );
|
|
// reset after file operation
|
|
Reset( TRUE );
|
|
// reset IRQ checking
|
|
nBoardIrq = 0;
|
|
nBoardTimer = TIMER();
|
|
}
|
|
break;
|
|
|
|
case LGS::CMD_SET_ADDRESS:
|
|
{
|
|
// reply command
|
|
*pSendBufferPtr++ = LGS::CMD_SET_ADDRESS;
|
|
// parse parameters
|
|
BYTE pSerialNumber[MAX_PATH];
|
|
BYTE nAddress, nCount;
|
|
LGS::GetAddress( pBuffer, &nAddress, &nCount, pSerialNumber );
|
|
// only if serial number is equal
|
|
if( (nCount == m_nSerialNumber) && !memcmp( pSerialNumber, m_pSerialNumber, m_nSerialNumber ) )
|
|
{
|
|
// change address
|
|
m_nAddress = nAddress;
|
|
// prepare answer message
|
|
nSendCount += LGS::BuildAddress( pSendBufferPtr, m_nAddress, m_nSerialNumber, m_pSerialNumber );
|
|
// send reply
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
// store serial number
|
|
SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, &m_pCamera->GetParameters(), &m_Relay.GetParameters(), &m_Voltage.GetParameters(), &m_LRFDisable );
|
|
// reset after file operation
|
|
Reset( TRUE );
|
|
// reset IRQ checking
|
|
nBoardIrq = 0;
|
|
nBoardTimer = TIMER();
|
|
}
|
|
}
|
|
break;
|
|
|
|
case LGS::CMD_SET_COMM_SPEED:
|
|
{
|
|
// reply command
|
|
*pSendBufferPtr++ = LGS::CMD_SET_COMM_SPEED;
|
|
// parse parameters
|
|
LONG nSpeed;
|
|
LGS::GetCommSpeed( pBuffer, &nSpeed );
|
|
// prepare answer message
|
|
nSendCount += LGS::BuildCommSpeed( pSendBufferPtr, nSpeed );
|
|
// send reply
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
// reinitialize communication if nessessary
|
|
#ifndef COMPILE_AS_GETFILE
|
|
if( m_pComm485->GetBaudRate() != nSpeed )
|
|
#endif
|
|
{
|
|
if( !m_pComm485->SetParameters( nSpeed, 8L, CComm485::_NOPARITY ) )
|
|
return FALSE;
|
|
|
|
// store new comm speed
|
|
FILE *pFile = fopen( "SERIAL.INI", "wt" );
|
|
if( pFile )
|
|
{
|
|
fprintf( pFile, "%ld\n", nSpeed );
|
|
fclose( pFile );
|
|
}
|
|
// reset after file operation
|
|
Reset( TRUE );
|
|
// reset IRQ checking
|
|
nBoardIrq = 0;
|
|
nBoardTimer = TIMER();
|
|
}
|
|
}
|
|
break;
|
|
|
|
case LGS::CMD_PARAMETERS:
|
|
{
|
|
// reply command
|
|
*pSendBufferPtr++ = LGS::CMD_PARAMETERS;
|
|
// parse input command
|
|
BYTE bSet, nDevice;
|
|
LGS::LGS_PARAMETERS parameters;
|
|
LGS::GetParameters( pBuffer, &bSet, &nDevice, ¶meters );
|
|
// return parameters
|
|
if( bSet )
|
|
{
|
|
m_Detector[ nDevice ].SetParameters( ¶meters );
|
|
nSendCount += LGS::BuildCmdSetParameters( pSendBufferPtr, nDevice, ¶meters );
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
// reset after file operation
|
|
Reset( TRUE );
|
|
// reset IRQ checking
|
|
nBoardIrq = 0;
|
|
nBoardTimer = TIMER();
|
|
}
|
|
else
|
|
{
|
|
m_Detector[ nDevice ].GetParameters( ¶meters );
|
|
nSendCount += LGS::BuildCmdSetParameters( pSendBufferPtr, nDevice, ¶meters );
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
}
|
|
}
|
|
break;
|
|
|
|
case LGS::CMD_RESET:
|
|
*pSendBufferPtr++ = LGS::CMD_RESET;
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
nMode = LGS::MODE_DETECTOR;
|
|
Reset( FALSE );
|
|
// reset IRQ checking
|
|
nBoardIrq = 0;
|
|
nBoardTimer = TIMER();
|
|
#ifdef LGS_MIRROR
|
|
bRestart = TRUE;
|
|
m_bRun = FALSE;
|
|
#endif
|
|
break;
|
|
|
|
case LGS::CMD_FULL_RESET:
|
|
*pSendBufferPtr++ = LGS::CMD_FULL_RESET;
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
nMode = LGS::MODE_DETECTOR;
|
|
Reset( TRUE );
|
|
// reset IRQ checking
|
|
nBoardIrq = 0;
|
|
nBoardTimer = TIMER();
|
|
#ifdef LGS_MIRROR
|
|
bRestart = TRUE;
|
|
m_bRun = FALSE;
|
|
#endif
|
|
break;
|
|
|
|
case LGS::CMD_FULL_BORDER:
|
|
{
|
|
*pSendBufferPtr++ = LGS::CMD_FULL_BORDER;
|
|
|
|
// read command data
|
|
INT nAngle;
|
|
LGS::GetCmdFullBorder( pBuffer, &nAngle );
|
|
|
|
// prepare answer
|
|
INT nRange1 = 0;
|
|
INT nRange2 = 0;
|
|
BOOL bReady = m_Detector[1].GetFullBorderRange( nAngle, &nRange2 ) &&
|
|
m_Detector[0].GetFullBorderRange( nAngle, &nRange1 );
|
|
if( bReady )
|
|
nSendCount += LGS::BuildEvtFullBorder( pSendBufferPtr, TRUE, nAngle, nRange1, nRange2 );
|
|
else
|
|
// use percent from detector 2 because it always comes later
|
|
nSendCount += LGS::BuildEvtFullBorder( pSendBufferPtr, FALSE, nRange2, 0, 0 );
|
|
|
|
// write back
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
}
|
|
break;
|
|
|
|
case LGS::CMD_GETFILE:
|
|
{
|
|
// build CMD_GETFILE command
|
|
*pSendBufferPtr++ = LGS::CMD_GETFILE;
|
|
if( nMode != LGS::MODE_GETFILE )
|
|
{
|
|
nSendCount += LGS::BuildGetFile( pSendBufferPtr, LGS::GF_ERRORMODE, 0, 0, 0 );
|
|
}
|
|
else
|
|
{
|
|
// get command parameters
|
|
BYTE bError, bOperation, pData[100];
|
|
INT nData;
|
|
LGS::GetGetFile( pBuffer, &bError, &bOperation, pData, &nData );
|
|
// perform command
|
|
if( m_GetFile.OnCommand( bOperation, pData, nData ) )
|
|
nSendCount += LGS::BuildGetFile( pSendBufferPtr, 0, ( bOperation & LGS::GF_OP_INDEX ) | LGS::GF_OP_OK, NULL, 0 );
|
|
else
|
|
nSendCount += LGS::BuildGetFile( pSendBufferPtr, LGS::GF_ERRORFILE, bOperation, NULL, 0 );
|
|
}
|
|
// write unswer
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
}
|
|
break;
|
|
|
|
#ifndef LGS_DISABLE_FILE_SYSTEM
|
|
case LGS::CMD_FS_SUB_PACKET:
|
|
{
|
|
// get incoming sub packet
|
|
LGS::FS_DATA_EX InFsData;
|
|
LGS::GetFSSubPacket( pBuffer, &InFsData );
|
|
switch( InFsData.nCommand )
|
|
{
|
|
case LGS::FS_CMD_SEND_CMD:
|
|
// build CMD_GETFILE command
|
|
*pSendBufferPtr++ = LGS::CMD_FS_SUB_PACKET;
|
|
if( nMode != LGS::MODE_FILESYSTEM )
|
|
{
|
|
LGS::FS_DATA_EX OutFsData;
|
|
OutFsData.nCommand = LGS::FS_CMD_SEND_EVT;
|
|
OutFsData.sendevt.nError = LGS::FS_ERROR_MODE;
|
|
OutFsData.sendevt.nOrder = InFsData.sendcmd.nOrder;
|
|
nSendCount += LGS::BuildFSSubPacket( pSendBufferPtr, &OutFsData );
|
|
}
|
|
else
|
|
{
|
|
// perform action
|
|
memcpy( ((PBYTE)&m_FileSystemPacket) + InFsData.sendcmd.nPosition, InFsData.sendcmd.pSubBuffer, InFsData.sendcmd.nSubSize );
|
|
|
|
// if last sub packet of packet
|
|
if( InFsData.sendcmd.nLast )
|
|
{
|
|
LG_FS_PACKET_EX PacketEx;
|
|
memcpy( &PacketEx, &m_FileSystemPacket, sizeof( m_FileSystemPacket ) );
|
|
memset( &m_FileSystemPacket, 0, sizeof( m_FileSystemPacket ) );
|
|
CLgFileSystemServer::OnPacket( &PacketEx, &m_FileSystemPacket );
|
|
}
|
|
|
|
// prepare response
|
|
LGS::FS_DATA_EX OutFsData;
|
|
OutFsData.nCommand = LGS::FS_CMD_SEND_EVT;
|
|
OutFsData.sendevt.nError = LGS::FS_ERROR_SUCCESS;
|
|
OutFsData.sendevt.nOrder = InFsData.sendcmd.nOrder;
|
|
nSendCount += LGS::BuildFSSubPacket( pSendBufferPtr, &OutFsData );
|
|
}
|
|
// write unswer
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
break;
|
|
case LGS::FS_CMD_RECEIVE_CMD:
|
|
// build CMD_GETFILE command
|
|
*pSendBufferPtr++ = LGS::CMD_FS_SUB_PACKET;
|
|
if( nMode != LGS::MODE_FILESYSTEM )
|
|
{
|
|
LGS::FS_DATA_EX OutFsData;
|
|
OutFsData.nCommand = LGS::FS_CMD_RECEIVE_EVT;
|
|
OutFsData.receiveevt.nError = LGS::FS_ERROR_MODE;
|
|
OutFsData.receiveevt.nOrder = InFsData.receivecmd.nOrder;
|
|
nSendCount += LGS::BuildFSSubPacket( pSendBufferPtr, &OutFsData );
|
|
}
|
|
else
|
|
{
|
|
// prepare sub packet
|
|
LGS::FS_DATA_EX OutFsData;
|
|
OutFsData.nCommand = LGS::FS_CMD_RECEIVE_EVT;
|
|
OutFsData.receiveevt.nError = LGS::FS_ERROR_SUCCESS;
|
|
OutFsData.receiveevt.nOrder = InFsData.receivecmd.nOrder;
|
|
OutFsData.receiveevt.nLast = ( m_FileSystemPacket.nSize - InFsData.receivecmd.nPosition ) <= 30;
|
|
OutFsData.receiveevt.nPosition = InFsData.receivecmd.nPosition;
|
|
OutFsData.receiveevt.nSubSize = OutFsData.receiveevt.nLast ? ( m_FileSystemPacket.nSize - InFsData.receivecmd.nPosition ) : 30;
|
|
memcpy( OutFsData.receiveevt.pSubBuffer, ((PBYTE)&m_FileSystemPacket) + InFsData.receivecmd.nPosition, OutFsData.receiveevt.nSubSize );
|
|
nSendCount += LGS::BuildFSSubPacket( pSendBufferPtr, &OutFsData );
|
|
}
|
|
// write unswer
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
break;
|
|
default:
|
|
// command is wrong!!!
|
|
*pSendBufferPtr++ = LGS::CMD_UNSUPPORTED;
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
break;
|
|
}
|
|
}
|
|
break;
|
|
#endif
|
|
default:
|
|
*pSendBufferPtr++ = LGS::CMD_UNSUPPORTED;
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, FALSE );
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#ifdef COMPILE_AS_GETFILE
|
|
bRestart;
|
|
return FALSE;
|
|
#else
|
|
return bRestart;
|
|
#endif
|
|
}
|
|
|
|
#ifdef DEBUG_ENABLE_SEND_BOARDDATA
|
|
BOOL CKernel::DoSendBoardData( INT nDevice )
|
|
{
|
|
if( !m_pComm485->SetParameters( LGS_SEND_BOARDDATA_BAUDRATE, 8L, CComm485::_NOPARITY ) )
|
|
return FALSE;
|
|
|
|
DWORD nBoardIrq = 0;
|
|
DWORD nBoardTimer = TIMER();
|
|
BOOL bPower, bZero, bSun[2];
|
|
INT nRange[2];
|
|
BYTE pData[ ( LGS_MAX_SEND_BOARDDATA_PART * 13 ) + 10 ];
|
|
CLgBitCode Encoder( pData );
|
|
INT nPart = 0;
|
|
nDevice = ( (nDevice == 0 || nDevice == 1) ? nDevice : 0 );
|
|
while( m_bRun )
|
|
{
|
|
#ifdef WATCHDOG_ENABLED
|
|
// update watchdog timer
|
|
m_WatchDog.Update( TIMER() );
|
|
#endif
|
|
|
|
// check timer
|
|
if( ( (TIMER()) - nBoardTimer ) > 18UL )
|
|
{
|
|
if( !nBoardIrq )
|
|
{
|
|
#ifdef DEBUG_BOARD_PRINT_NO_IRQ
|
|
printf( "NO IRQ %04x\n", m_pBoard->ReadNewBoard() );
|
|
#endif
|
|
// reset board
|
|
m_pBoard->Reset();
|
|
}
|
|
nBoardTimer = TIMER();
|
|
nBoardIrq = 0;
|
|
}
|
|
// get new data
|
|
if( m_pBoard->GetData( &bZero, bSun, nRange, &bPower ) )
|
|
{
|
|
// increase IRQ counter
|
|
nBoardIrq++;
|
|
|
|
// add next 13 bits of data
|
|
DWORD dwData = (DWORD)( nRange[nDevice] | ( bSun[nDevice] ? 1 << 11 : 0 ) | ( bZero ? 1 << 12 : 0 ) );
|
|
if( Encoder.Encode24( dwData, 13 ) )
|
|
{
|
|
// increase part number
|
|
nPart++;
|
|
|
|
// if numbe rof partes exeed max partes
|
|
if( nPart >= LGS_MAX_SEND_BOARDDATA_PART )
|
|
{
|
|
// prepare check sum in 14th byte of packet
|
|
BYTE bCheckSum = 0;
|
|
for( int i = 0; i < (LGS_MAX_SEND_BOARDDATA_PART * 13); i++ )
|
|
bCheckSum += pData[i];
|
|
pData[LGS_MAX_SEND_BOARDDATA_PART * 13] = bCheckSum;
|
|
|
|
// write into stream
|
|
m_pComm485->Write( pData, (LGS_MAX_SEND_BOARDDATA_PART * 13) + 1, 0 );
|
|
|
|
// reset part
|
|
nPart = 0;
|
|
|
|
// zero memory
|
|
memset( pData, 0, (LGS_MAX_SEND_BOARDDATA_PART * 13) + 1 );
|
|
}
|
|
|
|
// restart encoder
|
|
Encoder.SetBuffer( pData + ( nPart * 13 ) );
|
|
}
|
|
}
|
|
#ifdef COMM_WITHOUT_INTERRUPTS
|
|
m_pComm485->Invalidate();
|
|
m_pCameraComm->Invalidate();
|
|
#endif
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
#endif
|
|
|
|
/////////////////////// FILE SYSTEM REQUESTS HANDLERS //////////////////////////
|
|
#ifndef LGS_DISABLE_FILE_SYSTEM
|
|
struct ffblk g_ffBlock;
|
|
LG_FS_RESULT CKernel::DoFindFirst( PDWORD pHandle, PLG_FS_PATH pPath, PLG_FS_FIND_DATA pFindData )
|
|
{
|
|
// add termination 0
|
|
TCHAR pPathWithNull[MAX_PATH];
|
|
memcpy( pPathWithNull, pPath->pBuffer, pPath->nSize );
|
|
pPathWithNull[ pPath->nSize ] = 0;
|
|
|
|
// open find first
|
|
if( findfirst( pPathWithNull, &g_ffBlock, FA_RDONLY | FA_HIDDEN | FA_SYSTEM | FA_DIREC | FA_ARCH ) == 0 )
|
|
{
|
|
g_ffBlock.ff_attrib;
|
|
pFindData->dwFileAttributes = ( ( g_ffBlock.ff_attrib & FA_RDONLY ) ? LG_FS_FA_READONLY : 0 ) |
|
|
( ( g_ffBlock.ff_attrib & FA_HIDDEN ) ? LG_FS_FA_HIDDEN : 0 ) |
|
|
( ( g_ffBlock.ff_attrib & FA_SYSTEM ) ? LG_FS_FA_SYSTEM : 0 ) |
|
|
( ( g_ffBlock.ff_attrib & FA_DIREC ) ? LG_FS_FA_DIRECTORY : 0 ) |
|
|
( ( g_ffBlock.ff_attrib & FA_ARCH ) ? LG_FS_FA_ARCHIVE : 0 ) ;
|
|
pFindData->dwFileSizeHigh = 0;
|
|
pFindData->dwFileSizeLow = g_ffBlock.ff_fsize;
|
|
pFindData->Name.nSize = strlen( g_ffBlock.ff_name ) + 1;
|
|
memcpy( pFindData->Name.pBuffer, g_ffBlock.ff_name, pFindData->Name.nSize );
|
|
*pHandle = 0;
|
|
return LG_FS_RESULT_SUCCESS;
|
|
}
|
|
|
|
*pHandle = LG_FS_INVALID_HANDLE;
|
|
return LG_FS_RESULT_ERROR_NO_MORE_FILES;
|
|
}
|
|
LG_FS_RESULT CKernel::DoFindNext( DWORD dwHandle, PLG_FS_FIND_DATA pFindData )
|
|
{
|
|
dwHandle;
|
|
|
|
// open find first
|
|
if( findnext( &g_ffBlock ) == 0 )
|
|
{
|
|
pFindData->dwFileAttributes = ( ( g_ffBlock.ff_attrib & FA_RDONLY ) ? LG_FS_FA_READONLY : 0 ) |
|
|
( ( g_ffBlock.ff_attrib & FA_HIDDEN ) ? LG_FS_FA_HIDDEN : 0 ) |
|
|
( ( g_ffBlock.ff_attrib & FA_SYSTEM ) ? LG_FS_FA_SYSTEM : 0 ) |
|
|
( ( g_ffBlock.ff_attrib & FA_DIREC ) ? LG_FS_FA_DIRECTORY : 0 ) |
|
|
( ( g_ffBlock.ff_attrib & FA_ARCH ) ? LG_FS_FA_ARCHIVE : 0 ) ;
|
|
pFindData->dwFileSizeHigh = 0;
|
|
pFindData->dwFileSizeLow = g_ffBlock.ff_fsize;
|
|
pFindData->Name.nSize = strlen( g_ffBlock.ff_name ) + 1;
|
|
memcpy( pFindData->Name.pBuffer, g_ffBlock.ff_name, pFindData->Name.nSize );
|
|
return LG_FS_RESULT_SUCCESS;
|
|
}
|
|
|
|
return LG_FS_RESULT_ERROR_NO_MORE_FILES;
|
|
}
|
|
LG_FS_RESULT CKernel::DoFindClose( DWORD dwHandle )
|
|
{
|
|
dwHandle;
|
|
|
|
return LG_FS_RESULT_SUCCESS;
|
|
}
|
|
|
|
#endif
|
|
|
|
extern BOOL g_bShowErrors;
|
|
|
|
void CKernel::OnCmdState2( PBYTE& pReadBufferPtr, INT& nReadCount, PBYTE& pSendBufferPtr, INT& nSendCount, BYTE& nMode, BOOL& bBoardNoIrq )
|
|
{
|
|
// build CMD_STATE_2 command
|
|
*pSendBufferPtr++ = LGS::CMD_STATE_2;
|
|
|
|
// if mode is wrong
|
|
if( nMode != LGS::MODE_DETECTOR )
|
|
{
|
|
// build reply
|
|
nSendCount += LGS::BuildEvtState2Flags( pSendBufferPtr, LGS::S2_ITF_ERROR_MODE );
|
|
return;
|
|
}
|
|
|
|
BYTE bRequestType = LGS::S2_RT_TARGET_POLAR;
|
|
if( nReadCount )
|
|
nReadCount -= LGS::GetCmdState2( pReadBufferPtr, &bRequestType );
|
|
|
|
// flags
|
|
BYTE bFlags = 0;
|
|
|
|
// check for ANGLE and ZERO MARK errors
|
|
if( g_bShowErrors && m_Detector[0].GetLastErrorAngle() )
|
|
{
|
|
INT nErrorAngle = m_Detector[0].GetLastErrorAngleValue();
|
|
if( nErrorAngle == -1 )
|
|
bFlags |= LGS::S2_ITF_ERROR_NO_ZERO_MARK;
|
|
else
|
|
nSendCount += LGS::BuildEvtState2ErrorAngle( pSendBufferPtr, nErrorAngle );
|
|
}
|
|
|
|
// check for NO IRQ
|
|
if( g_bShowErrors && bBoardNoIrq )
|
|
{
|
|
bFlags |= LGS::S2_ITF_ERROR_NO_IRQ;
|
|
// clear no irq flag
|
|
bBoardNoIrq = FALSE;
|
|
}
|
|
|
|
// check for POWER changes
|
|
if( g_bShowErrors )
|
|
m_Voltage.OnProtocolLgsState2Command( bFlags );
|
|
|
|
#ifndef EMBEDDED_CAMERA_DISABLE
|
|
// add camera flags
|
|
m_pCamera->OnProtocolLgsState2Command( bFlags );
|
|
#endif
|
|
|
|
// apply flags
|
|
if( bFlags )
|
|
nSendCount += LGS::BuildEvtState2Flags( pSendBufferPtr, bFlags );
|
|
|
|
for( int i = 0; i < 2; i++ )
|
|
{
|
|
CDetector *pDetector = m_Detector + i;
|
|
#ifdef LGS_MIRROR
|
|
CTracker *pTracker = m_Tracker + 0;
|
|
#else
|
|
CTracker *pTracker = m_Tracker + i;
|
|
#endif
|
|
|
|
// assume that no errors
|
|
BYTE bDeviceFlags = 0;
|
|
// check for tracker overflow
|
|
if( ( m_dwTimeErrorOverflow[i] < TIMER() ) && pTracker->GetLastErrorOverflow() )
|
|
{
|
|
m_dwTimeErrorOverflow[i] = TIMER() + LGS_COMM_ERROR_SEND_PERIOD;
|
|
bDeviceFlags |= LGS::S2_ITDF_ERROR_OVERFLOW;
|
|
}
|
|
// check for tracker scan to scan overflow
|
|
if( ( m_dwTimeErrorOverflowSST[i] < TIMER() ) && pTracker->GetLastErrorOverflowSST() )
|
|
{
|
|
m_dwTimeErrorOverflowSST[i] = TIMER() + LGS_COMM_ERROR_SEND_PERIOD;
|
|
bDeviceFlags |= LGS::S2_ITDF_ERROR_SST_OVERFLOW;
|
|
}
|
|
// check for detector sun errors
|
|
if( ( m_dwTimeErrorSun[i] < TIMER() ) && pDetector->GetLastErrorSun() )
|
|
{
|
|
m_dwTimeErrorSun[i] = TIMER() + LGS_COMM_ERROR_SEND_PERIOD;
|
|
bDeviceFlags |= LGS::S2_ITDF_ERROR_SUN;
|
|
}
|
|
// apply device flags
|
|
if( g_bShowErrors && bDeviceFlags )
|
|
nSendCount += LGS::BuildEvtState2DeviceFlags( pSendBufferPtr, i, bDeviceFlags );
|
|
|
|
// place target information
|
|
CTracker::TARGET target;
|
|
while( pTracker->GetTarget( &target ) )
|
|
{
|
|
BYTE bType;
|
|
switch( target.bType )
|
|
{
|
|
case LGS::TT_WIDE:
|
|
case LGS::TT_NORMAL:
|
|
bType = ( target.bType == LGS::TT_NORMAL ) ? LGS::S2_ITT_NORMAL : LGS::S2_ITT_WIDE;
|
|
if( ( bRequestType & LGS::S2_RT_TARGET_MASK ) == LGS::S2_RT_TARGET_DEKART )
|
|
{
|
|
#ifdef LGS_MIRROR
|
|
const double a2r = asin(1.0) * 4.0 / ( LGS_MAX_DETECTOR_ANGLES << 2 );
|
|
double a = ( target.nAngle << 1 ) * a2r;
|
|
#else
|
|
const double a2r = asin(1.0) * 4.0 / LGS_MAX_DETECTOR_ANGLES;
|
|
double a = target.nAngle * a2r;
|
|
#endif
|
|
|
|
INT x = target.nRange * cos( a );
|
|
INT y = target.nRange * sin( a );
|
|
#ifdef LGS_MIRROR
|
|
nSendCount += ((bRequestType&LGS::S2_RW_MASK)==LGS::S2_RW_ENABLE) ?
|
|
LGS::BuildEvtState2TargetDekartW( pSendBufferPtr, i, bType, x, y, target.nWidth ) :
|
|
LGS::BuildEvtState2TargetDekart( pSendBufferPtr, i, bType, x, y );
|
|
#else
|
|
nSendCount += ((bRequestType&LGS::S2_RW_MASK)==LGS::S2_RW_ENABLE) ?
|
|
LGS::BuildEvtState2TargetDekartW( pSendBufferPtr, i, bType, x, y, target.nWidth << 1 ) :
|
|
LGS::BuildEvtState2TargetDekart( pSendBufferPtr, i, bType, x, y );
|
|
#endif
|
|
}
|
|
else
|
|
#ifdef LGS_MIRROR
|
|
nSendCount += ((bRequestType&LGS::S2_RW_MASK)==LGS::S2_RW_ENABLE) ?
|
|
LGS::BuildEvtState2TargetPolarW( pSendBufferPtr, i, bType, target.nAngle << 1, target.nRange, target.nWidth << 1 ) :
|
|
LGS::BuildEvtState2TargetPolar( pSendBufferPtr, i, bType, target.nAngle << 1, target.nRange );
|
|
#else
|
|
nSendCount += ((bRequestType&LGS::S2_RW_MASK)==LGS::S2_RW_ENABLE) ?
|
|
LGS::BuildEvtState2TargetPolarW( pSendBufferPtr, i, bType, target.nAngle, target.nRange, target.nWidth ) :
|
|
LGS::BuildEvtState2TargetPolar( pSendBufferPtr, i, bType, target.nAngle, target.nRange );
|
|
#endif
|
|
break;
|
|
case LGS::TT_FLIP:
|
|
nSendCount += LGS::BuildEvtState2Flip( pSendBufferPtr, i, target.nAngle );
|
|
break;
|
|
|
|
case LGS::TT_BLIND:
|
|
if( !g_bShowErrors )
|
|
break;
|
|
|
|
switch( target.nAngle )
|
|
{
|
|
case LGS_BLIND_TYPE_MR_ENTER:
|
|
nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_START | LGS::S2_ITB_MEDIUM_RANGE );
|
|
break;
|
|
case LGS_BLIND_TYPE_MR_EXIT:
|
|
nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_STOP | LGS::S2_ITB_MEDIUM_RANGE );
|
|
break;
|
|
case LGS_BLIND_TYPE_180_DEGRESE_ENTER:
|
|
nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_START | LGS::S2_ITB_180_DEGREE );
|
|
break;
|
|
case LGS_BLIND_TYPE_180_DEGRESE_EXIT:
|
|
nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_STOP | LGS::S2_ITB_180_DEGREE );
|
|
break;
|
|
case LGS_BLIND_TYPE_FS_ENTER:
|
|
nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_START | LGS::S2_ITB_FOG_SPIKES );
|
|
break;
|
|
case LGS_BLIND_TYPE_FS_EXIT:
|
|
nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_STOP | LGS::S2_ITB_FOG_SPIKES );
|
|
break;
|
|
case LGS_BLIND_TYPE_PD_ENTER:
|
|
nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_START | LGS::S2_ITB_PD );
|
|
break;
|
|
case LGS_BLIND_TYPE_PD_EXIT:
|
|
nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_STOP | LGS::S2_ITB_PD );
|
|
break;
|
|
}
|
|
break;
|
|
// case LGS::TT_CAMERA:
|
|
// break;
|
|
// case LGS::TT_TEST:
|
|
// break;
|
|
}
|
|
|
|
if( nSendCount >= 20 )
|
|
break;
|
|
}
|
|
|
|
if( nSendCount >= 20 )
|
|
break;
|
|
}
|
|
}
|
|
|
|
void CKernel::OnCmdGetWidthTable( PBYTE& pReadBufferPtr, INT& nReadCount, PBYTE& pSendBufferPtr, INT& nSendCount )
|
|
{
|
|
// unused variables
|
|
pReadBufferPtr; nReadCount;
|
|
|
|
// build CMD_GET_WIDHT_TABLE command
|
|
*pSendBufferPtr++ = LGS::CMD_GET_WIDTH_TABLE;
|
|
|
|
PLONG pNativeTable = m_Detector[0].GetFilterWidth()->GetTable();
|
|
|
|
// prepare table
|
|
LGS::WIDTH_TABLE table;
|
|
table.nCount = LGS::WIDTH_TABLE_SIZE;
|
|
for( INT i = 0; i < LGS::WIDTH_TABLE_SIZE; i++ )
|
|
table.pTable[i] = ( pNativeTable[i] * 100L ) >> 7;
|
|
|
|
// write command
|
|
nSendCount += LGS::BuildEvtGetWidthTable( pSendBufferPtr, &table );
|
|
}
|
|
|
|
void CKernel::OnCmdSetWidthTable( PBYTE& pReadBufferPtr, INT& nReadCount, PBYTE& pSendBufferPtr, INT& nSendCount )
|
|
{
|
|
// build CMD_SET_WIDHT_TABLE command
|
|
*pSendBufferPtr++ = LGS::CMD_SET_WIDTH_TABLE;
|
|
|
|
// read table
|
|
LGS::WIDTH_TABLE table;
|
|
nReadCount -= LGS::GetCmdSetWidthTable( pReadBufferPtr, &table );
|
|
|
|
FILE *pFile = fopen( "width.ini", "wt" );
|
|
if( pFile )
|
|
{
|
|
for( INT i = 0; i < table.nCount; i++ )
|
|
fprintf( pFile, "%d ", table.pTable[i] );
|
|
fclose( pFile );
|
|
}
|
|
|
|
// write command
|
|
nSendCount += LGS::BuildEvtSetWidthTable( pSendBufferPtr, &table );
|
|
|
|
// restart program
|
|
m_bRun = FALSE;
|
|
}
|
|
|
|
void CKernel::OnCmdGetZoomTable( PBYTE& pReadBufferPtr, INT& nReadCount, PBYTE& pSendBufferPtr, INT& nSendCount )
|
|
{
|
|
// unused variables
|
|
pReadBufferPtr; nReadCount;
|
|
|
|
// build CMD_GET_WIDHT_TABLE command
|
|
*pSendBufferPtr++ = LGS::CMD_GET_ZOOM_TABLE;
|
|
|
|
// write command
|
|
nSendCount += LGS::BuildZoomTable( pSendBufferPtr, &m_pCamera->GetZoomTable() );
|
|
}
|
|
|
|
void CKernel::OnCmdSetZoomTable( PBYTE& pReadBufferPtr, INT& nReadCount, PBYTE& pSendBufferPtr, INT& nSendCount )
|
|
{
|
|
// build CMD_SET_WIDHT_TABLE command
|
|
*pSendBufferPtr++ = LGS::CMD_SET_ZOOM_TABLE;
|
|
|
|
// read table
|
|
nReadCount -= LGS::GetZoomTable( pReadBufferPtr, &m_pCamera->GetZoomTable() );
|
|
|
|
// write command
|
|
nSendCount += LGS::BuildZoomTable( pSendBufferPtr, &m_pCamera->GetZoomTable() );
|
|
}
|
|
|
|
void CKernel::OnCmdGetTiltTable( PBYTE& pReadBufferPtr, INT& nReadCount, PBYTE& pSendBufferPtr, INT& nSendCount )
|
|
{
|
|
// unused variables
|
|
pReadBufferPtr; nReadCount;
|
|
|
|
// build CMD_GET_WIDHT_TABLE command
|
|
*pSendBufferPtr++ = LGS::CMD_GET_TILT_TABLE;
|
|
|
|
// write command
|
|
nSendCount += LGS::BuildTiltTable( pSendBufferPtr, &m_pCamera->GetTiltTable() );
|
|
}
|
|
|
|
void CKernel::OnCmdSetTiltTable( PBYTE& pReadBufferPtr, INT& nReadCount, PBYTE& pSendBufferPtr, INT& nSendCount )
|
|
{
|
|
// build CMD_SET_WIDHT_TABLE command
|
|
*pSendBufferPtr++ = LGS::CMD_SET_TILT_TABLE;
|
|
|
|
// read table
|
|
nReadCount -= LGS::GetTiltTable( pReadBufferPtr, &m_pCamera->GetTiltTable() );
|
|
|
|
// write command
|
|
nSendCount += LGS::BuildTiltTable( pSendBufferPtr, &m_pCamera->GetTiltTable() );
|
|
}
|
|
|
|
void CKernel::OnCmdGetCalibrationTable( PBYTE& pReadBufferPtr, INT& nReadCount, PBYTE& pSendBufferPtr, INT& nSendCount )
|
|
{
|
|
// read table
|
|
BYTE nDevice = *pReadBufferPtr++;
|
|
nReadCount --;
|
|
|
|
// build CMD_GET_LINEARIZATION_TABLE command
|
|
*pSendBufferPtr++ = LGS::CMD_GET_CALIBRATION_TABLE;
|
|
*pSendBufferPtr++ = nDevice;
|
|
nSendCount++;
|
|
|
|
// process command
|
|
m_Calibrator[nDevice?1:0].OnCmdGetCalibrationTable( pReadBufferPtr, nReadCount, pSendBufferPtr, nSendCount );
|
|
}
|
|
|
|
BOOL CKernel::OnCmdSetCalibrationTable( PBYTE& pReadBufferPtr, INT& nReadCount, PBYTE& pSendBufferPtr, INT& nSendCount, INT& nDevice )
|
|
{
|
|
// read table
|
|
nDevice = *pReadBufferPtr++;
|
|
nReadCount --;
|
|
|
|
// build CMD_SET_LINEARIZATION_TABLE command
|
|
*pSendBufferPtr++ = LGS::CMD_SET_CALIBRATION_TABLE;
|
|
*pSendBufferPtr++ = nDevice;
|
|
nSendCount++;
|
|
|
|
// process command
|
|
return m_Calibrator[nDevice?1:0].OnCmdSetCalibrationTable( pReadBufferPtr, nReadCount, pSendBufferPtr, nSendCount );
|
|
}
|
|
|
|
void CKernel::OnCmdGetLrfDisable( PBYTE& pReadBufferPtr, INT& nReadCount, PBYTE& pSendBufferPtr, INT& nSendCount )
|
|
{
|
|
// unused variables
|
|
pReadBufferPtr; nReadCount;
|
|
|
|
// build CMD_GET_LRF_DISABLE command
|
|
*pSendBufferPtr++ = LGS::CMD_GET_LRF_DISABLE;
|
|
|
|
// write command
|
|
nSendCount += LGS::BuildLRFDisable( pSendBufferPtr, &m_LRFDisable );
|
|
}
|
|
|
|
void CKernel::OnCmdSetLrfDisable( PBYTE& pReadBufferPtr, INT& nReadCount, PBYTE& pSendBufferPtr, INT& nSendCount )
|
|
{
|
|
// read table
|
|
nReadCount -= LGS::GetLRFDisable( pReadBufferPtr, &m_LRFDisable );
|
|
|
|
// store serial number
|
|
SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, &m_pCamera->GetParameters(), &m_Relay.GetParameters(), &m_Voltage.GetParameters(), &m_LRFDisable );
|
|
|
|
// build CMD_SET_LRF_DISABLE command
|
|
*pSendBufferPtr++ = LGS::CMD_SET_LRF_DISABLE;
|
|
|
|
// write command
|
|
nSendCount += LGS::BuildLRFDisable( pSendBufferPtr, &m_LRFDisable );
|
|
|
|
// restart program
|
|
m_bRun = FALSE;
|
|
}
|
|
|
|
typedef enum SETTING_TYPE
|
|
{
|
|
ST_NONE = -1,
|
|
ST_SN = 0,
|
|
ST_ADDRESS,
|
|
ST_CAMERA_TYPE,
|
|
ST_CAMERA_SHIFT,
|
|
ST_CAMERA_AUTO,
|
|
ST_CAMERA_DELAY,
|
|
ST_RELAY_NC,
|
|
ST_RELAY_AUTO,
|
|
ST_RELAY_DELAY,
|
|
ST_VOLTAGE_CONTROL,
|
|
ST_MASTER_DISABLED,
|
|
ST_SLAVE_DISABLED,
|
|
|
|
ST_AUTORESET_ENABLE,
|
|
ST_AUTORESET_INTERLEAVE,
|
|
ST_AUTORESET_TIMEOUT,
|
|
|
|
ST_BOARD_TEMPERATURE,
|
|
ST_BOARD_ZEROSHIFT,
|
|
ST_BOARD_ENCODERSTEPS,
|
|
ST_BOARD_GEARRATIO,
|
|
ST_BOARD_MAXRANGE,
|
|
|
|
ST_SWITCHER_TABLE,
|
|
ST_SWITCHER_REPLY_TIMEOUT,
|
|
ST_SWITCHER_COMMAND_TIMEOUT,
|
|
ST_SWITCHER_AUTO_MODE,
|
|
ST_SWITCHER_AUTO_ENTER_TIMEOUT,
|
|
ST_SWITCHER_AUTO_SWITCH_TIMEOUT,
|
|
}SETTING_TYPE;
|
|
|
|
LPCTSTR m_pSetting[] =
|
|
{
|
|
{ "SN" },
|
|
{ "ADDRESS" },
|
|
{ "CAMERA_TYPE" },
|
|
{ "CAMERA_SHIFT" },
|
|
{ "CAMERA_AUTO" },
|
|
{ "CAMERA_DELAY" },
|
|
{ "RELAY_NC" },
|
|
{ "RELAY_AUTO" },
|
|
{ "RELAY_DELAY" },
|
|
{ "VOLTAGE_CONTROL" },
|
|
{ "MASTER_DISABLED" },
|
|
{ "SLAVE_DISABLED" },
|
|
|
|
{ "AUTORESET_ENABLE" },
|
|
{ "AUTORESET_INTERLEAVE" },
|
|
{ "AUTORESET_TIMEOUT" },
|
|
|
|
{ "BOARD_TEMPERATURE" },
|
|
{ "BOARD_ZEROSHIFT" },
|
|
{ "BOARD_ENCODERSTEPS" },
|
|
{ "BOARD_GEARRATIO" },
|
|
{ "BOARD_MAXRANGE" },
|
|
|
|
{ "SWITCHER_TABLE" },
|
|
{ "SWITCHER_REPLY_TIMEOUT" },
|
|
{ "SWITCHER_COMMAND_TIMEOUT" },
|
|
{ "SWITCHER_AUTO_MODE" },
|
|
{ "SWITCHER_AUTO_ENTER_TIMEOUT" },
|
|
{ "SWITCHER_AUTO_SWITCH_TIMEOUT" }
|
|
};
|
|
|
|
BOOL CKernel::LoadSettings( LPTSTR pSerialNumber, PBYTE pSerialNumberSize, PBYTE pAddress, LGS::PCAMERA_PARAMETERS pCameraParameters, LGS::PRELAY_PARAMETERS pRelayParameters, LGS::PVOLTAGE_PARAMETERS pVoltageParameters, LGS::PLRF_DISABLE pLRFDisable )
|
|
{
|
|
// read serial number
|
|
FILE *pFile = fopen( "SN.INI", "rt" );
|
|
if( !pFile )
|
|
{
|
|
// fill with default sn
|
|
*pSerialNumberSize = 14;
|
|
memcpy( pSerialNumber, "NOSERIALNUMBER", *pSerialNumberSize );
|
|
return FALSE;
|
|
}
|
|
|
|
CHAR pLine[MAX_PATH];
|
|
while( fgets( pLine, MAX_PATH, pFile ) )
|
|
{
|
|
SETTING_TYPE eType = ST_NONE;
|
|
PCHAR pTemp = NULL;
|
|
for( INT i = 0; i < sizeof( m_pSetting ) / sizeof( *m_pSetting ); i++ )
|
|
{
|
|
pTemp = strstr( pLine, m_pSetting[i] );
|
|
if( pTemp )
|
|
{
|
|
eType = (SETTING_TYPE)i;
|
|
pTemp = strstr( pTemp, "=" );
|
|
if( pTemp )
|
|
pTemp = strtok( pTemp + 1, " \t\n\r" );
|
|
break;
|
|
}
|
|
}
|
|
|
|
if( eType == ST_NONE || !pTemp )
|
|
continue;
|
|
|
|
switch( eType )
|
|
{
|
|
case ST_SN: *pSerialNumberSize = strlen( pTemp ); memcpy( pSerialNumber, pTemp, *pSerialNumberSize ); break;
|
|
case ST_ADDRESS: *pAddress = atoi( pTemp ); break;
|
|
case ST_CAMERA_TYPE: pCameraParameters->eType = (LGS::E_CAMERA_TYPE)atoi( pTemp ); break;
|
|
case ST_CAMERA_SHIFT: pCameraParameters->nShift = (WORD)atoi( pTemp ); break;
|
|
case ST_CAMERA_AUTO: pCameraParameters->bAuto = (BOOL)atoi( pTemp ); break;
|
|
case ST_CAMERA_DELAY: pCameraParameters->nAutoDelay = (WORD)atoi( pTemp ); break;
|
|
case ST_RELAY_NC: pRelayParameters->bNormallyClose = (WORD)atoi( pTemp ); break;
|
|
case ST_RELAY_AUTO: pRelayParameters->bAuto = (BOOL)atoi( pTemp ); break;
|
|
case ST_RELAY_DELAY: pRelayParameters->nAutoDelay = (WORD)atoi( pTemp ); break;
|
|
case ST_VOLTAGE_CONTROL: pVoltageParameters->bControl = (BOOL)atoi( pTemp ); break;
|
|
case ST_MASTER_DISABLED: pLRFDisable->bMaster = (BOOL)atoi( pTemp ); break;
|
|
case ST_SLAVE_DISABLED: pLRFDisable->bSlave = (BOOL)atoi( pTemp ); break;
|
|
}
|
|
}
|
|
|
|
fclose( pFile );
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL CKernel::SaveSettings( LPCTSTR pSerialNumber, INT nAddress, LGS::PCAMERA_PARAMETERS pCameraParameters, LGS::PRELAY_PARAMETERS pRelayParameters, LGS::PVOLTAGE_PARAMETERS pVoltageParameters, LGS::PLRF_DISABLE pLRFDisable )
|
|
{
|
|
FILE *pFile = fopen( "SN.INI", "wt" );
|
|
if( !pFile )
|
|
return FALSE;
|
|
|
|
LPCTSTR pFormatStr = "%s = %s\n";
|
|
LPCTSTR pFormatInt = "%s = %d\n";
|
|
|
|
fprintf( pFile, pFormatStr, m_pSetting[ST_SN], pSerialNumber );
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_ADDRESS], nAddress );
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_CAMERA_TYPE], pCameraParameters->eType );
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_CAMERA_SHIFT], pCameraParameters->nShift );
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_CAMERA_AUTO], pCameraParameters->bAuto );
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_CAMERA_DELAY], pCameraParameters->nAutoDelay );
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_RELAY_AUTO], pRelayParameters->bAuto );
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_RELAY_DELAY], pRelayParameters->nAutoDelay );
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_RELAY_NC], pRelayParameters->bNormallyClose );
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_VOLTAGE_CONTROL], pVoltageParameters->bControl );
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_MASTER_DISABLED], pLRFDisable->bMaster );
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_SLAVE_DISABLED], pLRFDisable->bSlave );
|
|
fclose( pFile );
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL CKernel::LoadUserSettings( AUTO_RESET *pAutoReset, BOARD_SETTINGS *pBoard, SWITCHER_SETTINGS *pSwitcher )
|
|
{
|
|
pSwitcher->pTable[0] = LGS_MIRROR_ANGLE_OF_VIEW * 1 / 4;
|
|
pSwitcher->pTable[1] = LGS_MIRROR_ANGLE_OF_VIEW * 2 / 4;
|
|
pSwitcher->pTable[2] = LGS_MIRROR_ANGLE_OF_VIEW * 3 / 4;
|
|
pSwitcher->nReplyTimeout = 100L;
|
|
pSwitcher->nCommandTimeout = 500L;
|
|
pSwitcher->nAutoMode = 0;
|
|
pSwitcher->nAutoEnterTimeout = 60;
|
|
pSwitcher->nAutoSwitchTimeout = 3;
|
|
|
|
pAutoReset->bEnabled = FALSE;
|
|
pAutoReset->dwInterleave = 2000UL;
|
|
pAutoReset->dwTimeout = 60000UL;
|
|
|
|
pBoard->nZeroShift = 0;
|
|
pBoard->nTemperature = 20;
|
|
pBoard->nEncoderSteps = 6;
|
|
pBoard->nGearRatio = 61;
|
|
// pBoard->nMaxRange = 2048;
|
|
|
|
// read serial number
|
|
FILE *pFile = fopen( "USER.INI", "rt" );
|
|
if( !pFile )
|
|
return FALSE;
|
|
|
|
CHAR pLine[MAX_PATH];
|
|
while( fgets( pLine, MAX_PATH, pFile ) )
|
|
{
|
|
SETTING_TYPE eType = ST_NONE;
|
|
PCHAR pTemp = NULL;
|
|
for( INT i = 0; i < sizeof( m_pSetting ) / sizeof( *m_pSetting ); i++ )
|
|
{
|
|
pTemp = strstr( pLine, m_pSetting[i] );
|
|
if( pTemp )
|
|
{
|
|
eType = (SETTING_TYPE)i;
|
|
pTemp = strstr( pTemp, "=" );
|
|
if( pTemp )
|
|
pTemp = strtok( pTemp + 1, " \t\n\r" );
|
|
break;
|
|
}
|
|
}
|
|
|
|
if( eType == ST_NONE || !pTemp )
|
|
continue;
|
|
|
|
switch( eType )
|
|
{
|
|
case ST_AUTORESET_ENABLE: pAutoReset->bEnabled = (BOOL)atoi( pTemp ); break;
|
|
case ST_AUTORESET_INTERLEAVE: pAutoReset->dwInterleave = atol( pTemp ); break;
|
|
case ST_AUTORESET_TIMEOUT: pAutoReset->dwTimeout = atol( pTemp ); break;
|
|
case ST_BOARD_TEMPERATURE: pBoard->nTemperature = atoi( pTemp ); break;
|
|
case ST_BOARD_ZEROSHIFT: pBoard->nZeroShift = atoi( pTemp ); break;
|
|
case ST_BOARD_ENCODERSTEPS: pBoard->nEncoderSteps = atoi( pTemp ); break;
|
|
case ST_BOARD_GEARRATIO: pBoard->nGearRatio = atoi( pTemp ); break;
|
|
// case ST_BOARD_MAXRANGE: pBoard->nMaxRange = atoi( pTemp ); break;
|
|
case ST_SWITCHER_TABLE: sscanf( pTemp, "%d,%d,%d", pSwitcher->pTable + 0, pSwitcher->pTable + 1, pSwitcher->pTable + 2 );
|
|
case ST_SWITCHER_REPLY_TIMEOUT: pSwitcher->nReplyTimeout = atol( pTemp ); break;
|
|
case ST_SWITCHER_COMMAND_TIMEOUT: pSwitcher->nCommandTimeout = atol( pTemp ); break;
|
|
case ST_SWITCHER_AUTO_MODE: pSwitcher->nAutoMode = atoi( pTemp ); break;
|
|
case ST_SWITCHER_AUTO_ENTER_TIMEOUT: pSwitcher->nAutoEnterTimeout = atoi( pTemp ); break;
|
|
case ST_SWITCHER_AUTO_SWITCH_TIMEOUT: pSwitcher->nAutoSwitchTimeout = atoi( pTemp ); break;
|
|
}
|
|
}
|
|
|
|
fclose( pFile );
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL CKernel::SaveUserSettings( AUTO_RESET *pAutoReset, BOARD_SETTINGS *pBoard, SWITCHER_SETTINGS *pSwitcher )
|
|
{
|
|
FILE *pFile = fopen( "USER.INI", "wt" );
|
|
if( !pFile )
|
|
return FALSE;
|
|
|
|
LPCTSTR pFormatInt = "%s=%d\n";
|
|
LPCTSTR pFormatArr = "%s=%d,%d,%d\n";
|
|
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_AUTORESET_ENABLE], (INT)pAutoReset->bEnabled );
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_AUTORESET_INTERLEAVE], (INT)pAutoReset->dwInterleave );
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_AUTORESET_TIMEOUT], (INT)pAutoReset->dwTimeout );
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_TEMPERATURE], (INT)(CHAR)pBoard->nTemperature );
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_ZEROSHIFT], (INT)pBoard->nZeroShift );
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_ENCODERSTEPS], (INT)pBoard->nEncoderSteps );
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_GEARRATIO], (INT)pBoard->nGearRatio );
|
|
fprintf( pFile, pFormatArr, m_pSetting[ST_SWITCHER_TABLE], pSwitcher->pTable[0], pSwitcher->pTable[1], pSwitcher->pTable[2] );
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_SWITCHER_REPLY_TIMEOUT], pSwitcher->nReplyTimeout );
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_SWITCHER_COMMAND_TIMEOUT], pSwitcher->nCommandTimeout );
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_SWITCHER_AUTO_MODE], pSwitcher->nAutoMode );
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_SWITCHER_AUTO_ENTER_TIMEOUT], pSwitcher->nAutoEnterTimeout );
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_SWITCHER_AUTO_SWITCH_TIMEOUT], pSwitcher->nAutoSwitchTimeout );
|
|
|
|
fclose( pFile );
|
|
|
|
return TRUE;
|
|
}
|