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.
3744 lines
114 KiB
3744 lines
114 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 <errno.h>
|
|
#include <mem.h>
|
|
#include <bios.h>
|
|
#include <dos.h>
|
|
#include <dir.h>
|
|
#include <io.h>
|
|
#include <conio.h>
|
|
#include <stdio.h>
|
|
#include <string.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 "CFlir.h"
|
|
#include "CHebron.h"
|
|
|
|
/*!
|
|
Flag to disable error repporting
|
|
default: \b false
|
|
*/
|
|
extern bool g_bShowErrors;
|
|
/*!
|
|
Flag to disable fog error repporting
|
|
default: \b false
|
|
*/
|
|
extern bool g_bHideFogError;
|
|
/*!
|
|
Flag to delay error repporting
|
|
Skeeps error for first 3 times of arival
|
|
default: \b true
|
|
*/
|
|
extern bool g_bDelayErrors;
|
|
/*!
|
|
Flag to enable working
|
|
default: \b false
|
|
*/
|
|
//extern bool m_pBoard->workingEnabled();
|
|
|
|
/*!
|
|
Gets value of BIOS timer counter (1/18 of second)
|
|
*/
|
|
//static DWORD far* g_Timer = (DWORD far*)0x46CL;
|
|
//#ifdef INCLUDE_WINDOWS_DEFINITIONS
|
|
// #define TIMER() *g_Timer
|
|
//#else
|
|
// #define TIMER() (GetTickCount() * 10 / 182)
|
|
//#endif
|
|
|
|
//#define TIMER() ( uclock() * 10 / 182 )
|
|
|
|
/*!
|
|
Buffer for Software Version Text Generation
|
|
*/
|
|
CHAR CKernel::s_pSoftwareVersion[MAX_PATH] = "";
|
|
/*!
|
|
Software Version
|
|
*/
|
|
int16_t CKernel::s_nSoftwareVersion = 0;
|
|
|
|
// Hidding parameters up to 5 bytes (11 Nibbles)
|
|
|
|
|
|
|
|
void CKernel::Reset( bool bFullReset ){
|
|
#ifdef COMPILE_AS_GETFILE
|
|
return;
|
|
#else
|
|
struct ffblk bb;
|
|
|
|
if( bFullReset ) if( findfirst( "restart", &bb , 0 ) != -1 ) return;
|
|
|
|
#ifdef LGS_MIRROR
|
|
m_Detector[ 0 ].Reset( bFullReset );
|
|
#ifndef LGS_MND
|
|
m_Detector[ 1 ].Reset( bFullReset );
|
|
m_Detector[ 2 ].Reset( bFullReset );
|
|
m_Detector[ 3 ].Reset( bFullReset );
|
|
#endif
|
|
m_Tracker[ 0 ].Reset();
|
|
#else
|
|
#ifdef LGS_PLS_1
|
|
m_Detector[ 0 ].Reset( bFullReset );
|
|
m_Tracker[ 0 ].Reset();
|
|
#else
|
|
m_Detector[ 0 ].Reset( bFullReset );
|
|
m_Detector[ 1 ].Reset( bFullReset );
|
|
m_Tracker[ 0 ].Reset();
|
|
m_Tracker[ 1 ].Reset();
|
|
#endif
|
|
#endif
|
|
|
|
m_GetFile.Reset();
|
|
//if (g_UI_Debug){
|
|
// if(bFullReset){
|
|
// printf("\nSW reset issued [full reset]\n");
|
|
// } else {
|
|
// printf("\nSW reset issued [soft reset]\n");
|
|
// };
|
|
//};
|
|
#ifdef DEBUG_GRAPH_SCREEN
|
|
g_Screen.Clear();
|
|
#endif
|
|
// reset error timings
|
|
memset( m_dwTimeErrorOverflowSST, 0, sizeof(m_dwTimeErrorOverflowSST)*4 );
|
|
memset( m_dwTimeErrorOverflow, 0, sizeof(m_dwTimeErrorOverflow)*4 );
|
|
memset( m_dwTimeErrorSun, 0, sizeof(m_dwTimeErrorSun)*4 );
|
|
m_dwTimeErrorDelay_EA = 0UL;
|
|
m_dwTimeErrorDelay_IQ = 0UL;
|
|
m_dwTimePower = 0UL;
|
|
// reset board
|
|
if( bFullReset ){
|
|
#ifdef _NO_RESTART_
|
|
//m_pBoard->Reset();
|
|
#else
|
|
FILE *fd;
|
|
fd = fopen( "restart", "w+" );
|
|
fprintf( fd, "\n" );
|
|
fclose( fd );
|
|
|
|
m_pBoard->EndService();
|
|
m_bRun = false;
|
|
#endif
|
|
} else {
|
|
#ifndef _NO_RESTART_
|
|
//m_pBoard->Reset();
|
|
#endif
|
|
};
|
|
m_Relay.Reset();
|
|
// restart Zero Shift Checker
|
|
m_bWaitFirstZero = true;
|
|
m_nBeforeZeroCounter = 0;
|
|
// Reset AutoReset
|
|
m_AutoReset.Reset();
|
|
m_nInitErrorSkipCounter = 20;
|
|
#endif // !GetFile
|
|
}
|
|
|
|
//SchedulerItem *ScheduleCC;
|
|
|
|
void CKernel::OnISR(){
|
|
#ifndef COMM_WITHOUT_INTERRUPTS
|
|
stopTimerCC();
|
|
unsigned char cFlag;
|
|
cFlag = 0;
|
|
if ( m_pComm485 != NULL ){
|
|
if ( m_pComm485->m_bFollowControlTimer ){
|
|
if ( !m_pComm485->ValidateRTS() ){
|
|
cFlag++; //resetTimerCC();
|
|
};// else {
|
|
// setTimerCC( 0xffffffUL );
|
|
//};
|
|
};
|
|
};
|
|
#ifndef NO_EMBED_CAMERA
|
|
if ( m_pCameraComm != NULL ){
|
|
if ( m_pCameraComm->m_bFollowControlTimer ){
|
|
if( !m_pCameraComm->ValidateRTS() ){
|
|
cFlag++;//resetTimerCC();
|
|
};// else {
|
|
// setTimerCC( 0xffffffUL );
|
|
//};
|
|
};
|
|
};
|
|
#endif
|
|
switch( cFlag ){
|
|
case 0:{
|
|
setTimerCC( 0xffffffUL );
|
|
break;
|
|
};
|
|
case 1:
|
|
case 2:{
|
|
resetTimerCC();
|
|
break;
|
|
};
|
|
};
|
|
#endif
|
|
}
|
|
|
|
|
|
bool CKernel::Run(){
|
|
struct ffblk bb;
|
|
uint8_t *pBuffer;
|
|
int16_t nCount;
|
|
uint8_t nCameraAccessCounter = 0;
|
|
uint8_t nMode = LGS::MODE_DETECTOR;
|
|
bool bRestart = false;
|
|
uint32_t nBoardIrq = 0;
|
|
uint32_t nBoardTimer = TIMER();
|
|
bool bBoardNoIrq = false;
|
|
|
|
#ifndef COMPILE_AS_GETFILE
|
|
bool bFastTimerValid = false;
|
|
#endif
|
|
|
|
#ifdef DEBUG_TARGET_SIMULATOR
|
|
bFireSimulatedTarget = false;
|
|
nSimulatedTargetID = 0;
|
|
#endif
|
|
bool bSetHzDataInProgress = false;
|
|
bool bSetCalibrationTableInProgress = false;
|
|
|
|
bool bPower, bZero, bSun[2];
|
|
uint16_t nRange[2];
|
|
|
|
bool SSTMode = false;
|
|
|
|
m_nBeforeZeroCounter = 0;
|
|
delay(1000);
|
|
#ifdef COMPILE_AS_GETFILE
|
|
uint64_t qwStartTime = TIME_TO_MSEC( TIMER() );
|
|
bool bGetFileRun = false;
|
|
// send human readable information
|
|
{
|
|
CHAR pText[MAX_PATH];
|
|
int16_t nText;
|
|
ARESET_SETTINGS AutoReset;
|
|
BOARD_SETTINGS BoardSettings;
|
|
m_pBoard->getSettings( &BoardSettings );
|
|
m_AutoReset.getSettings( &AutoReset );
|
|
char *tTtTtT;
|
|
switch( m_pBoard->getBoardType() ) {
|
|
case BT_COREMODULE_4DXE: tTtTtT = _T("PC104_4DXE"); break;
|
|
case BT_TRI_M: tTtTtT = _T("TRITRACK_M"); break;
|
|
case BT_VORTEX_SX: tTtTtT = _T("VORTEX86SX"); break;
|
|
case BT_VORTEX_DX: tTtTtT = _T("VORTEX86MX"); break;
|
|
case BT_VORTEX_MX: tTtTtT = _T("VORTEX86DX"); break;
|
|
default: tTtTtT = _T("UNKNOWN");
|
|
};
|
|
nText = sprintf( pText, "BOARD TYPE <%s>\r\n", tTtTtT );
|
|
#ifdef DEBUG
|
|
printf(pText);
|
|
#endif
|
|
m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
|
|
|
|
nText = sprintf( pText, "SOFTWARE VERSION <%s>\r\n", s_pSoftwareVersion );
|
|
#ifdef DEBUG
|
|
printf(pText);
|
|
#endif
|
|
m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
|
|
|
|
nText = sprintf( pText, "ADDRESS <%d>\r\n", m_nAddress );
|
|
#ifdef DEBUG
|
|
printf(pText);
|
|
#endif
|
|
m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
|
|
|
|
nText = sprintf( pText, "SERIAL NUMBER <%s>\r\n", m_pSerialNumber );
|
|
#ifdef DEBUG
|
|
printf(pText);
|
|
#endif
|
|
m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
|
|
|
|
nText = sprintf( pText, "AUTORESET_ENABLE <%d>\r\n", AutoReset.bEnabled );
|
|
#ifdef DEBUG
|
|
printf(pText);
|
|
#endif
|
|
m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
|
|
|
|
nText = sprintf( pText, "AUTORESET_INTERLEAVE <%ld>\r\n", AutoReset.dwInterleave );
|
|
#ifdef DEBUG
|
|
printf(pText);
|
|
#endif
|
|
m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
|
|
|
|
nText = sprintf( pText, "AUTORESET_TIMEOUT <%ld>\r\n", AutoReset.dwTimeout );
|
|
#ifdef DEBUG
|
|
printf(pText);
|
|
#endif
|
|
m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
|
|
|
|
nText = sprintf( pText, "BOARD_TEMPERATURE <%d>\r\n", (int16_t)(CHAR)BoardSettings.nTemperature );
|
|
#ifdef DEBUG
|
|
printf(pText);
|
|
#endif
|
|
m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
|
|
|
|
nText = sprintf( pText, "BOARD_ZEROSHIFT <%d>\r\n", BoardSettings.nZeroShift );
|
|
#ifdef DEBUG
|
|
printf(pText);
|
|
#endif
|
|
m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
|
|
#ifdef LGS_PLS_1
|
|
nText = sprintf( pText, "BOARD_SPEED <%d>\r\n", BoardSettings.nMotorSpeed );
|
|
#ifdef DEBUG
|
|
printf(pText);
|
|
#endif
|
|
m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
|
|
#endif
|
|
#ifdef LGS_MIRROR
|
|
nText = sprintf( pText, "SWITCHER_TABLE <%d,%d,%d>\r\n", SwitcherSettings.pTable[0], SwitcherSettings.pTable[1], SwitcherSettings.pTable[2] );
|
|
#ifdef DEBUG
|
|
printf(pText);
|
|
#endif
|
|
m_pComm485->Write( (PBYTE)pText, nText, 0 ); m_pComm485->Flush();
|
|
#endif
|
|
}
|
|
m_pBoard->BeginService();
|
|
nBoardTimer = qwStartTime = g_qwStartupTime = TIME_TO_MSEC( TIMER() );
|
|
#else // No Get File
|
|
//m_pBoard->Reset();// ??
|
|
m_pBoard->BeginService();
|
|
nBoardTimer = g_qwStartupTime = TIME_TO_MSEC( TIMER() );
|
|
#endif
|
|
|
|
|
|
// update settings
|
|
//AUTO_RESET AutoReset;
|
|
//BOARD_SETTINGS BoardSettings;
|
|
//SWITCHER_SETTINGS SwitcherSettings;
|
|
//LoadUserSettings( &AutoReset, &BoardSettings, &SwitcherSettings, m_pComm485, m_pCameraComm );
|
|
//SaveUserSettings( &AutoReset, &BoardSettings, &SwitcherSettings, m_pComm485, m_pCameraComm );
|
|
m_nInitErrorSkipCounter = 20;
|
|
m_bWaitFirstZero = true;
|
|
|
|
#ifdef DEBUG_ENABLE_SEND_BOARDDATA
|
|
if( g_bBoardReceiverMode ) DoSendBoardData( 0 );
|
|
#endif
|
|
|
|
while( m_bRun ){
|
|
uint64_t cMilliseconds = TIME_TO_MSEC( TIMER() );
|
|
//m_dwGlobalCycles++;
|
|
#ifndef INCLUDE_WINDOWS_DEFINITIONS
|
|
Sleep(0);
|
|
#endif
|
|
|
|
#ifdef WATCHDOG_ENABLED
|
|
// update watchdog timer
|
|
if( g_bWatchDogEnable ) m_WatchDog.Update( cMilliseconds );
|
|
#endif
|
|
|
|
#ifdef COMPILE_AS_GETFILE
|
|
if( !bGetFileRun ){
|
|
if( ( cMilliseconds - qwStartTime ) > LGS_GETFILE_WAIT_TIME ) m_bRun = false;
|
|
} else {
|
|
qwStartTime = cMilliseconds;
|
|
};
|
|
#else // !COMPILE_AS_GETFILE
|
|
// clear zero flag
|
|
#ifndef NO_EMBED_CAMERA
|
|
bool bInvalidateCamera = false;
|
|
#endif
|
|
// check fast timer
|
|
static uint64_t qwSlowTime = 0;
|
|
if( !bFastTimerValid ){
|
|
if( cMilliseconds != qwSlowTime ){
|
|
qwSlowTime = cMilliseconds << 1; // was 3
|
|
#ifndef NO_EMBED_CAMERA
|
|
bInvalidateCamera = true;
|
|
#endif
|
|
};
|
|
}
|
|
#ifndef NO_EMBED_CAMERA
|
|
else bInvalidateCamera = true;
|
|
#endif
|
|
#endif
|
|
|
|
|
|
// perform work depend on work mode
|
|
switch( nMode ){
|
|
case LGS::MODE_BORDER:
|
|
case LGS::MODE_DETECTOR:
|
|
#ifdef BOARD_NO_RESPONCE_COUNT_INIT
|
|
if( m_nBoardNoRespoceCount < 1 ){
|
|
#ifdef DEBUG_BOARD_PRINT_NO_IRQ
|
|
printf("No Responce From Board!!\n");
|
|
#endif
|
|
m_nBoardNoRespoceCount = BOARD_NO_RESPONCE_COUNT_INIT;
|
|
// Restart Software
|
|
#ifdef RESTART_PC_BY_WATCHDOG
|
|
outportb( NEW_WDT_ADDRESS, 0xAA ); // Try To restart Board
|
|
#ifdef WATCHDOG_ENABLED
|
|
CWatchDog WatchDog;
|
|
WatchDog.Create();
|
|
while(1);
|
|
#else
|
|
delay( 3000 );
|
|
Reset( true );
|
|
continue;
|
|
|
|
#endif
|
|
#else
|
|
Reset( true );
|
|
continue;
|
|
#endif
|
|
};
|
|
#endif
|
|
|
|
//#ifndef COMPILE_AS_GETFILE
|
|
#ifdef COMPILE_AS_GETFILE______
|
|
k;qkw;ekq
|
|
// check Serial Number
|
|
if( !m_pBoard->workingEnabled() ){
|
|
bBoardNoIrq = true;
|
|
// fast timer is not valid
|
|
bFastTimerValid = false;
|
|
#ifdef BOARD_NO_RESPONCE_COUNT_INIT
|
|
if( m_nBoardNoRespoceCount ){
|
|
m_nBoardNoRespoceCount--;
|
|
};
|
|
#else
|
|
Reset( true );
|
|
#endif
|
|
};
|
|
#endif // GETFILE
|
|
|
|
|
|
// check IRQ
|
|
if( ( cMilliseconds - nBoardTimer ) > NO_IRQ_DETECTION_TIME ){
|
|
if( !nBoardIrq ){
|
|
#ifndef COMPILE_AS_GETFILE
|
|
#ifdef DEBUG_BOARD_PRINT_NO_IRQ
|
|
printf( "NO IRQ RESET\n" );
|
|
#endif
|
|
//m_pBoard->Reset();
|
|
|
|
// fast timer is not valid
|
|
bFastTimerValid = false;
|
|
#ifdef BOARD_NO_RESPONCE_COUNT_INIT
|
|
if( m_nBoardNoRespoceCount ) m_nBoardNoRespoceCount--;
|
|
#else
|
|
Reset( true );
|
|
#endif
|
|
#endif //GetFILE
|
|
bBoardNoIrq = true;
|
|
};
|
|
nBoardTimer = cMilliseconds;
|
|
nBoardIrq = 0;
|
|
};
|
|
|
|
if( m_pBoard->workingEnabled() ) {
|
|
#ifdef COMPILE_AS_GETFILE
|
|
#ifdef BOARD_NO_RESPONCE_COUNT_INIT
|
|
m_nBoardNoRespoceCount = BOARD_NO_RESPONCE_COUNT_INIT;
|
|
#endif
|
|
nBoardTimer = cMilliseconds;
|
|
nBoardIrq++;
|
|
#else
|
|
// check board
|
|
uint8_t RetVal;
|
|
bool bDataConsumed;
|
|
bDataConsumed = false;
|
|
while ( (( RetVal = m_pBoard->GetData( &bZero, bSun, nRange, &bPower ) ) > 0 ) ){
|
|
#ifdef WATCHDOG_ENABLED
|
|
if( g_bWatchDogEnable ) m_WatchDog.Update( cMilliseconds );
|
|
#endif
|
|
if( RetVal == 2 ){
|
|
#ifdef ALS_300__
|
|
if( m_nBoardNoRespoceCount ){
|
|
m_nBoardNoRespoceCount--;
|
|
m_pBoard->AsyncReset();
|
|
Reset( false );
|
|
};
|
|
#else
|
|
Reset( true );
|
|
#endif
|
|
continue;
|
|
};
|
|
|
|
bDataConsumed = true;
|
|
|
|
#ifdef BOARD_NO_RESPONCE_COUNT_INIT
|
|
m_nBoardNoRespoceCount = BOARD_NO_RESPONCE_COUNT_INIT;
|
|
#endif
|
|
nBoardTimer = cMilliseconds;
|
|
nBoardIrq++;
|
|
|
|
#ifndef RANGE_16BIT
|
|
// perform linearization
|
|
nRange[0] = m_Calibrator[0].Calibrate( nRange[0] );
|
|
#ifdef LGS_MIRROR // Doublefication of LGS data for LFS
|
|
#ifndef LGS_MND
|
|
nRange[1] = nRange[0];
|
|
//nRange[1] = m_Calibrator[0].Calibrate( nRange[0] );
|
|
#endif
|
|
#else
|
|
#ifndef LGS_PLS_1
|
|
nRange[1] = m_Calibrator[1].Calibrate( nRange[1] );
|
|
#endif
|
|
#endif
|
|
#endif //16 bit
|
|
// update voltage state
|
|
m_Voltage.Invalidate( bPower );
|
|
|
|
// fast timer is valid
|
|
bFastTimerValid = true;
|
|
|
|
#ifdef DEBUG_BOARD_SET_TEST_BIT
|
|
m_pBoard->SetTestBit( true );
|
|
#endif
|
|
|
|
#ifdef LGS_MIRROR
|
|
if( m_bWaitFirstZero && bZero ){
|
|
m_Detector[ 0 ].ResetAngles();
|
|
#ifndef LGS_MND
|
|
m_Detector[ 1 ].ResetAngles();
|
|
m_Detector[ 2 ].ResetAngles();
|
|
m_Detector[ 3 ].ResetAngles();
|
|
#endif
|
|
m_Tracker[ 0 ].Reset();
|
|
|
|
//m_nDetector = m_nAngle = 0;
|
|
#ifdef DEBUG_BOARD_PRINT_NO_IRQ
|
|
printf("Before Zero: %d ang. Zero Shift: %d ang.\n", m_nBeforeZeroCounter, m_pBoard->getZeroShift() );
|
|
#endif
|
|
//if( findfirst( "restart", &bb , 0 ) != -1 )
|
|
unlink( "restart" );
|
|
m_bWaitFirstZero = false;
|
|
};
|
|
|
|
if( !m_bWaitFirstZero ){ // Accepting Data
|
|
if( bZero ){ // If Zero Angle
|
|
#ifdef DEBUG_BOARD_PRINT_NO_IRQ
|
|
printf( "Real Zero: %d D:%d\n", m_nAngle, m_nDetector );
|
|
#endif
|
|
m_nDetector = m_nAngle = 0;
|
|
m_dwGlobalCycles = 0UL;
|
|
#ifndef LGS_MND
|
|
if( m_Detector[ 3 ].IsSSTPassed() ){
|
|
SSTMode = true;
|
|
} else {
|
|
SSTMode = false;
|
|
};
|
|
#else
|
|
SSTMode = false;
|
|
#endif
|
|
} else { // If Any Other Angle
|
|
#ifndef LGS_MND
|
|
#ifdef LGS_REDUCED_PRF
|
|
m_nAngle += LGS_PRF_REDUCE_RATIO;
|
|
m_dwGlobalCycles += LGS_PRF_REDUCE_RATIO;
|
|
if( m_nAngle > ( LGS_MAX_DETECTOR_ANGLES - LGS_PRF_REDUCE_RATIO ) ){ // Change Detector (Mirror)
|
|
#else
|
|
m_nAngle ++;
|
|
m_dwGlobalCycles ++;
|
|
if( m_nAngle > ( LGS_MAX_DETECTOR_ANGLES - 1 ) ){ // Change Detector (Mirror)
|
|
#endif
|
|
|
|
#ifdef DEBUG_BOARD_PRINT_NO_IRQ
|
|
printf( "Virtual Zero: %d D:%d ", m_nAngle, m_nDetector );
|
|
#endif
|
|
if( m_Detector[ m_nDetector ].IsSSTPassed() ) SSTMode = true;
|
|
m_nDetector ++;
|
|
if ( m_nDetector > 3 ) m_nDetector = 0;
|
|
m_nAngle = 0;
|
|
bZero = true;
|
|
};
|
|
#else
|
|
#ifdef LGS_REDUCED_PRF
|
|
m_nAngle += LGS_PRF_REDUCE_RATIO;
|
|
m_dwGlobalCycles += LGS_PRF_REDUCE_RATIO;
|
|
#else
|
|
m_nAngle ++;
|
|
m_dwGlobalCycles ++;
|
|
#endif
|
|
#endif
|
|
};
|
|
} else { // Board Zero Shift Counter
|
|
#ifdef LGS_REDUCED_PRF
|
|
m_nBeforeZeroCounter += LGS_PRF_REDUCE_RATIO;
|
|
#else
|
|
m_nBeforeZeroCounter++;
|
|
#endif
|
|
};
|
|
|
|
#ifdef DEBUG_NO_TARGET_DELAYING
|
|
SSTMode = false;
|
|
#endif
|
|
|
|
if( !m_bWaitFirstZero ){
|
|
|
|
#ifdef LGS_REDUCED_PRF
|
|
m_Tracker[ 0 ].Invalidate();
|
|
for( int i = 0; i< LGS_PRF_REDUCE_RATIO; i++ ) {
|
|
m_Detector[ m_nDetector ].Invalidate( bZero, bSun[0], nRange[0], true, SSTMode );
|
|
if( bZero ) {
|
|
bZero = false;
|
|
};
|
|
};
|
|
#else
|
|
m_Tracker[ 0 ].Invalidate();
|
|
m_Detector[ m_nDetector ].Invalidate( bZero, bSun[0], nRange[0], true, SSTMode );
|
|
#endif
|
|
};
|
|
#else // No LGS_MIRROR !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
#if defined( LGS_PLS_1 ) // PLS
|
|
|
|
if( m_bWaitFirstZero && bZero ) {
|
|
m_bWaitFirstZero = false;
|
|
m_Detector[ 0 ].ResetAngles();
|
|
m_Tracker[ 0 ].Reset();
|
|
unlink( "restart" );
|
|
};
|
|
|
|
if( !m_bWaitFirstZero ){
|
|
m_Tracker[0].Invalidate();
|
|
#ifdef LGS_REDUCED_PRF
|
|
for( int i = 0; i< LGS_PRF_REDUCE_RATIO; i++ ){
|
|
m_Detector[0].Invalidate( bZero, bSun[0], nRange[0], true );
|
|
bZero = 0;
|
|
};
|
|
#else
|
|
m_Detector[0].Invalidate( bZero, bSun[0], nRange[0], true );
|
|
#endif
|
|
} else { // Board Zero Shift Counter
|
|
#ifdef LGS_REDUCED_PRF
|
|
m_nBeforeZeroCounter += LGS_PRF_REDUCE_RATIO;
|
|
#else
|
|
m_nBeforeZeroCounter++;
|
|
#endif
|
|
};
|
|
|
|
#else // ALS
|
|
if( m_bWaitFirstZero && bZero ) {
|
|
/*if( ( m_nBeforeZeroCounter >0 ) && ( m_nBeforeZeroCounter != m_pBoard->getZeroShift() ) ){ //Check if Zero Shift is Valid
|
|
m_pBoard->AsyncReset();
|
|
m_nBeforeZeroCounter = 0;
|
|
} else {
|
|
m_bWaitFirstZero = false;
|
|
};*/
|
|
#ifdef DEBUG
|
|
printf("First Zero Reached!\n");
|
|
#endif
|
|
m_bWaitFirstZero = false;
|
|
m_Detector[ 0 ].ResetAngles();
|
|
m_Tracker[ 0 ].Reset();
|
|
m_Detector[ 1 ].ResetAngles();
|
|
m_Tracker[ 1 ].Reset();
|
|
#ifdef ALS_300
|
|
m_nSkeepCounter=0;
|
|
#endif
|
|
if( findfirst( "restart", &bb , 0 ) != -1 ) unlink( "restart" );
|
|
};
|
|
|
|
if( !m_bWaitFirstZero ){
|
|
m_Detector[0].Invalidate( bZero, bSun[0], nRange[0], m_Detector[1].IsAllowFlip(), false );
|
|
} else { // Board Zero Shift Counter
|
|
m_nBeforeZeroCounter++;
|
|
};
|
|
#ifdef ALS_300
|
|
//if( m_nSkeepCounter == 0 )
|
|
#endif
|
|
m_Tracker[0].Invalidate();
|
|
|
|
if( !m_bWaitFirstZero ){
|
|
m_Detector[1].Invalidate( bZero, bSun[1], nRange[1], m_Detector[0].IsAllowFlip(), false );
|
|
};
|
|
#ifdef ALS_300
|
|
//if( m_nSkeepCounter == 0 )
|
|
#endif
|
|
m_Tracker[1].Invalidate();
|
|
#ifdef ALS_300
|
|
m_nSkeepCounter++;
|
|
if( m_nSkeepCounter == LGS_BOARDSAMPLE_RATIO ) m_nSkeepCounter = 0;
|
|
#endif
|
|
#endif // ALS-PLS
|
|
#endif // No LGS_MIRROR !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
#ifndef NO_EMBED_CAMERA
|
|
bInvalidateCamera = true;
|
|
#endif
|
|
if( m_pBoard->getBoardWM()!= WM_DMA_WORK ) break;// From While
|
|
};// Get Data While
|
|
if( !bDataConsumed ) {
|
|
if( nBoardTimer != cMilliseconds ) {
|
|
nBoardTimer == cMilliseconds;
|
|
#ifdef BOARD_NO_RESPONCE_COUNT_INIT
|
|
if( m_nBoardNoRespoceCount ){
|
|
m_nBoardNoRespoceCount--;
|
|
} else {
|
|
bBoardNoIrq = true;
|
|
m_nBoardNoRespoceCount = BOARD_NO_RESPONCE_COUNT_INIT;
|
|
m_pBoard->Reset();
|
|
//m_pBoard->BeginService();
|
|
//Reset( true );
|
|
};
|
|
#endif
|
|
};
|
|
};
|
|
#endif //!COMPILE_AS_GETFILE
|
|
|
|
};// m_pBoard->workingEnabled() == true
|
|
|
|
#ifndef COMPILE_AS_GETFILE
|
|
#ifdef COMM_WITHOUT_INTERRUPTS
|
|
m_pComm485->Validate();
|
|
#endif
|
|
#ifndef NO_EMBED_CAMERA
|
|
nCameraAccessCounter++;
|
|
if( bInvalidateCamera && ( ( nCameraAccessCounter % 123 ) == 6 ) ){
|
|
nCameraAccessCounter = 0;
|
|
#ifdef COMM_WITHOUT_INTERRUPTS
|
|
m_pCameraComm->Validate();
|
|
#endif
|
|
// process camera commands
|
|
m_pCamera->Invalidate( dwSlowTime, m_pBoard->GetTimer(), bFastTimerValid );
|
|
bInvalidateCamera = false;
|
|
};
|
|
#endif
|
|
#endif
|
|
break;
|
|
default:
|
|
case LGS::MODE_FILESYSTEM:
|
|
case LGS::MODE_GETFILE:
|
|
#ifndef COMPILE_AS_GETFILE
|
|
if( m_pBoard->GetData( &bZero, bSun, nRange, &bPower ) ){
|
|
#ifndef RANGE_16BIT
|
|
// perform linearization
|
|
nRange[0] = m_Calibrator[0].Calibrate( nRange[0] );
|
|
#if !defined( LGS_PLS_1 ) && !defined( LGS_MND )
|
|
nRange[1] = m_Calibrator[1].Calibrate( nRange[1] );
|
|
#endif
|
|
#endif // 16 bit
|
|
// update voltage state
|
|
m_Voltage.Invalidate( bPower );
|
|
|
|
#ifndef EMBEDDED_CAMERA_DISABLE
|
|
bInvalidateCamera = true;
|
|
#endif
|
|
nBoardIrq++;
|
|
#ifndef COMPILE_AS_GETFILE
|
|
// fast timer is valid
|
|
bFastTimerValid = true;
|
|
#endif
|
|
};
|
|
#endif // !COMPILE_AS_GETFILE
|
|
break;
|
|
}
|
|
|
|
// try to work in windows - disable Board->GetTimer();
|
|
#ifndef INCLUDE_WINDOWS_DEFINITIONS
|
|
bFastTimerValid = false;
|
|
#endif
|
|
|
|
#ifndef EMBEDDED_CAMERA_DISABLE
|
|
#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
|
|
#ifndef NO_EMBED_CAMERA
|
|
// process camera commands
|
|
m_pCamera->Invalidate( dwSlowTime, m_pBoard->GetTimer(), bFastTimerValid );
|
|
#endif
|
|
#ifdef DEBUG_BOARD_SET_TEST_BIT_2
|
|
m_pBoard->SetTestBit2( false );
|
|
#endif
|
|
bInvalidateCamera = false;
|
|
};
|
|
|
|
// process relay commands
|
|
if ( m_pBoard->workingEnabled() ) m_Relay.Invalidate( m_pBoard->GetTimer(), cMilliseconds );
|
|
#else
|
|
m_Relay.Invalidate( m_pBoard->GetTimer(), cMilliseconds );
|
|
#endif
|
|
#endif
|
|
|
|
//process communication commands
|
|
#ifdef COMM_WITHOUT_INTERRUPTS
|
|
m_pComm485->Validate();
|
|
#ifndef EMBEDDED_CAMERA_DISABLE
|
|
#ifndef NO_EMBED_CAMERA
|
|
m_pCameraComm->Validate();
|
|
#endif
|
|
#endif
|
|
#endif
|
|
|
|
// auto reset
|
|
if( m_AutoReset.IsNeedToReset() ){
|
|
#ifdef INFINITE_SAF_STUDY
|
|
m_Detector[0].StartLearningCycle();
|
|
#else
|
|
nMode = LGS::MODE_DETECTOR;
|
|
//Reset( false );
|
|
// reset IRQ checking
|
|
nBoardIrq = 0;
|
|
nBoardTimer = cMilliseconds;
|
|
m_nBeforeZeroCounter = 0;
|
|
|
|
bRestart = true;
|
|
Reset( true );
|
|
#endif
|
|
};
|
|
// check for new commands from host
|
|
if( m_Protocol.Read( &pBuffer, &nCount, 0, false ) ){
|
|
// check address
|
|
uint8_t bAddress = 0;
|
|
if( nCount && ( (m_nAddress == *pBuffer) || (LGS_EXCLUSIVE_ADDRESS == *pBuffer) ) )
|
|
{
|
|
// store address
|
|
bAddress = *pBuffer;
|
|
|
|
// update pointers
|
|
nCount--;
|
|
pBuffer++;
|
|
// check remainig count
|
|
if( nCount )
|
|
{
|
|
uint8_t pSendBuffer[1024];
|
|
PBYTE pSendBufferPtr = pSendBuffer;
|
|
int16_t nSendCount = 2;
|
|
|
|
// set address
|
|
*pSendBufferPtr++ = bAddress;
|
|
|
|
uint8_t 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;
|
|
Reset( true );
|
|
}
|
|
|
|
// get command from buffer
|
|
switch( bHostCommand )
|
|
{
|
|
case LGS::CMD_CAMERA:
|
|
// build CMD_MODE command
|
|
*pSendBufferPtr++ = LGS::CMD_CAMERA;
|
|
// process command
|
|
#if !defined(EMBEDDED_CAMERA_DISABLE) && !defined(NO_EMBED_CAMERA)
|
|
m_pCamera->OnProtocolLgsCameraCommand( pBuffer, nCount, pSendBufferPtr, nSendCount );
|
|
#else
|
|
LGS::CAMERA_DATA OutData;
|
|
// lgs has no camera busy
|
|
OutData.nCommand = LGS::CMD_CAMERA_ERROR;
|
|
OutData.error.errID = LGS::CAMERA_ERROR_NO_CAMERA;
|
|
nSendCount += LGS::BuildEvtCamera( pSendBufferPtr, &OutData );
|
|
#endif
|
|
// write command
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
|
|
break;
|
|
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;
|
|
uint8_t 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:
|
|
case LGS::MODE_FILESYSTEM_EXT:
|
|
m_Detector[0].BorderEnable( nNewMode == LGS::MODE_BORDER );
|
|
#if !defined( LGS_PLS_1 ) && !defined( LGS_MND )
|
|
m_Detector[1].BorderEnable( nNewMode == LGS::MODE_BORDER );
|
|
#endif
|
|
#ifdef LGS_MIRROR
|
|
#ifndef LGS_MND
|
|
m_Detector[2].BorderEnable( nNewMode == LGS::MODE_BORDER );
|
|
m_Detector[3].BorderEnable( nNewMode == LGS::MODE_BORDER );
|
|
#endif
|
|
#endif
|
|
#ifdef COMPILE_AS_GETFILE
|
|
bGetFileRun = false;
|
|
qwStartTime = cMilliseconds;
|
|
#endif
|
|
break;
|
|
#ifdef DEBUG_ENABLE_SEND_BOARDDATA
|
|
case LGS::MODE_SENDBOARDDATA1:
|
|
DoSendBoardData( 0 );
|
|
Reset( true );
|
|
//m_bRun = false;
|
|
continue;
|
|
break;
|
|
case LGS::MODE_SENDBOARDDATA2:
|
|
DoSendBoardData( 1 );
|
|
Reset( true );
|
|
//m_bRun = false;
|
|
continue;
|
|
break;
|
|
case LGS::MODE_SENDBOARDDATA3:
|
|
DoSendBoardData( 2 );
|
|
Reset( true );
|
|
//m_bRun = false;
|
|
continue;
|
|
break;
|
|
case LGS::MODE_SENDBOARDDATA4:
|
|
DoSendBoardData( 3 );
|
|
Reset( true );
|
|
//m_bRun = false;
|
|
continue;
|
|
break;
|
|
#endif
|
|
}
|
|
|
|
// reset after switching mode
|
|
if( nMode != LGS::MODE_BORDER && anMode != LGS::MODE_DETECTOR ) Reset( false );
|
|
|
|
// store new mode
|
|
nMode = nNewMode;
|
|
|
|
// reset IRQ checking
|
|
nBoardIrq = 0;
|
|
nBoardTimer = cMilliseconds;
|
|
}
|
|
}
|
|
break;
|
|
|
|
case LGS::CMD_BORDER:
|
|
{
|
|
// get command parameters
|
|
uint8_t bError;
|
|
uint16_t 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{
|
|
#if !defined( LGS_PLS_1 ) && !defined( LGS_MND )
|
|
uint8_t bError = ( (!m_Detector[0].GetBorderRange( nAngle, &nRange0 )) ||
|
|
(!m_Detector[1].GetBorderRange( nAngle, &nRange1 )) ) ? LGS::BD_NOTREADY : 0;
|
|
#else
|
|
#ifdef INFINITE_SAF_STUDY
|
|
uint8_t bError = ( (!m_Detector[0].GetBorderRange( nAngle, &nRange0, true )) ||
|
|
(!m_Detector[0].GetBorderRange( nAngle, &nRange1, false )) ) ? LGS::BD_NOTREADY : 0;
|
|
#else
|
|
uint8_t bError = ( (!m_Detector[0].GetBorderRange( nAngle, &nRange0 )) ) ? LGS::BD_NOTREADY : 0;
|
|
#endif
|
|
#endif
|
|
if( bError ){
|
|
nSendCount += LGS::BuildBorder( pSendBufferPtr, bError, 0, 0, 0 );
|
|
}else
|
|
#ifdef RANGE_16BIT
|
|
//nSendCount += LGS::BuildBorder( pSendBufferPtr, 0, nAngle, (uint16_t)ceil(((float)nRange0)/ 11.12f), (uint16_t)ceil(((float)nRange1)/ 11.12f) );
|
|
{
|
|
uint16_t nR0,nR1;
|
|
//nRange0 = nAngle;
|
|
//nR0 = (uint16_t)(((float)nRange0)/ 11.12 + 1 );
|
|
nR0 = (uint16_t)(( 2048L * nRange0 )/ 22237 + 1 );
|
|
nR1 = (uint16_t)(( 2048L * nRange1 )/ 22237 + 1 );
|
|
nSendCount += LGS::BuildBorder( pSendBufferPtr, 0, nAngle, nR0, nR1 );
|
|
//nSendCount += LGS::BuildBorder( pSendBufferPtr, 0, nAngle, nRange0>>3, nRange1>>3 );
|
|
};
|
|
#else
|
|
nSendCount += LGS::BuildBorder( pSendBufferPtr, 0, nAngle, nRange0 >> 1, nRange1 >> 1 );
|
|
#endif
|
|
}
|
|
// 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{
|
|
#ifdef LGS_MIRROR
|
|
#ifdef LGS_MND
|
|
{
|
|
int i = 0;
|
|
#else
|
|
for( int i = 0; i < 4; i++ ){
|
|
#endif
|
|
#else
|
|
#ifndef LGS_PLS_1
|
|
for( int i = 0; i < 2; i++ ){
|
|
#else
|
|
{
|
|
int i = 0;
|
|
#endif
|
|
#endif
|
|
CDetector *pDetector = &m_Detector[i];
|
|
CTracker *pTracker = &m_Tracker[i];
|
|
uint8_t bDevice = ( i % 2 ) ? LGS::ID_DEVICE1 : LGS::ID_DEVICE0;
|
|
|
|
// assume that no errors
|
|
uint8_t bErrorMask = LGS::ER_NONE;
|
|
int16_t nErrorAngle = 0;
|
|
// check for tracker overflow
|
|
if( ( m_dwTimeErrorOverflow[i] < cMilliseconds ) && pTracker->GetLastErrorOverflow() )
|
|
{
|
|
m_dwTimeErrorOverflow[i] = cMilliseconds + LGS_COMM_ERROR_SEND_PERIOD;
|
|
bErrorMask |= LGS::ER_OVERFLOW;
|
|
}
|
|
// check for tracker scan to scan overflow
|
|
if( ( m_dwTimeErrorOverflowSST[i] < cMilliseconds ) && pTracker->GetLastErrorOverflowSST() )
|
|
{
|
|
m_dwTimeErrorOverflowSST[i] = cMilliseconds + LGS_COMM_ERROR_SEND_PERIOD;
|
|
bErrorMask |= LGS::ER_SSTOVERFLOW;
|
|
}
|
|
// check for detector sun errors
|
|
if( ( m_dwTimeErrorSun[i] < cMilliseconds ) && pDetector->GetLastErrorSun() )
|
|
{
|
|
m_dwTimeErrorSun[i] = cMilliseconds + LGS_COMM_ERROR_SEND_PERIOD;
|
|
bErrorMask |= LGS::ER_SUNBIT;
|
|
}
|
|
|
|
// check for detector angle errors
|
|
if( pDetector->GetLastErrorAngle() )
|
|
{
|
|
nErrorAngle = pDetector->GetLastErrorAngleValue();
|
|
if( ( nErrorAngle > 0 && nErrorAngle < LGS_REAL_DETECTOR_ANGLES - 5 ) || g_bDelayErrors == false ){
|
|
bErrorMask |= LGS::ER_ANGLE;
|
|
nErrorAngle = ( i + 1 ) * 10000 + nErrorAngle;
|
|
};
|
|
}
|
|
// check for kernel error
|
|
if( bBoardNoIrq )
|
|
{
|
|
bErrorMask |= LGS::ER_NOIRQ;
|
|
#ifndef RESTART_ON_NO_IRQ
|
|
bBoardNoIrq = false;//Moved to end of send message to issue EXIT
|
|
#endif
|
|
}
|
|
// if error exist
|
|
if( bErrorMask ){
|
|
nSendCount += LGS::BuildError( pSendBufferPtr, bDevice, bErrorMask, nErrorAngle );
|
|
//if( g_UI_Debug ){
|
|
// printf("Error Message Issued [%d]\n", bErrorMask );
|
|
//};
|
|
}
|
|
// place target information
|
|
CTracker::TARGET target;
|
|
while( ( pTracker->GetTarget( &target ) && m_pBoard->workingEnabled()
|
|
#ifdef DEBUG_TARGET_SIMULATOR
|
|
) || bFireSimulatedTarget
|
|
#else
|
|
)
|
|
#endif
|
|
){
|
|
|
|
#ifdef DEBUG_TARGET_SIMULATOR
|
|
if( bFireSimulatedTarget ){
|
|
target.bType = LGS::TT_NORMAL;
|
|
target.nRange = 200;
|
|
target.nAngle = ( 3000* nSimulatedTargetID )/360 ;
|
|
target.nWidth = m_dwGlobalCycles;//nSimulatedTargetID;
|
|
bFireSimulatedTarget = false;
|
|
};
|
|
#endif
|
|
|
|
#ifdef LGS_MIRROR
|
|
#ifdef LGS_STEPPER
|
|
#ifdef LGS_TEST_SEND_TARGET_WIDTH
|
|
nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, ( target.nAngle << 1 ) / LGS_PRF_REDUCE_RATIO, target.nRange, target.nWidth );
|
|
#else
|
|
nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, ( target.nAngle << 1 ) / LGS_PRF_REDUCE_RATIO, target.nRange );
|
|
#endif
|
|
#else
|
|
#ifdef LGS_MND
|
|
#ifdef LGS_TEST_SEND_TARGET_WIDTH
|
|
nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, target.nAngle << 2, target.nRange, target.nWidth << 2 );
|
|
#else
|
|
nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, target.nAngle << 2, target.nRange );
|
|
#endif
|
|
#else
|
|
#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
|
|
#endif
|
|
#endif
|
|
#else
|
|
#ifdef LGS_PLS_1
|
|
#ifdef LGS_TEST_SEND_TARGET_WIDTH
|
|
nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, target.nAngle / LGS_PRF_REDUCE_RATIO, target.nRange, target.nWidth );
|
|
#else
|
|
nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, target.nAngle / LGS_PRF_REDUCE_RATIO, target.nRange );
|
|
#endif
|
|
#else
|
|
#ifdef ALS_300_Z
|
|
#ifdef LGS_TEST_SEND_TARGET_WIDTH
|
|
nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, target.nAngle / LGS_BOARDSAMPLE_RATIO, target.nRange, target.nWidth );
|
|
#else
|
|
nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, target.nAngle / LGS_BOARDSAMPLE_RATIO, target.nRange );
|
|
#endif
|
|
#else
|
|
#ifdef RANGE_16BIT
|
|
uint16_t nR0;
|
|
nR0 = (uint16_t)(( 2048L * target.nRange )/ 22237 + 1 );
|
|
#ifdef LGS_TEST_SEND_TARGET_WIDTH
|
|
nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, target.nAngle, nR0, target.nWidth );
|
|
#else
|
|
nSendCount += LGS::BuildTarget( pSendBufferPtr, bDevice, target.bType, target.nAngle, nR0 );
|
|
#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
|
|
#endif
|
|
#endif
|
|
#endif
|
|
|
|
|
|
if( nSendCount >= 20 )
|
|
break;
|
|
}
|
|
|
|
if( nSendCount >= 20 )
|
|
break;
|
|
}
|
|
}
|
|
#ifndef EMBEDDED_CAMERA_DISABLE
|
|
#ifndef NO_EMBED_CAMERA
|
|
// add camera tags
|
|
m_pCamera->OnProtocolLgsStateCommand( pSendBufferPtr, nSendCount );
|
|
#endif
|
|
#endif
|
|
// write command
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
|
|
#ifdef RESTART_ON_NO_IRQ
|
|
if( bBoardNoIrq ) {
|
|
m_bRun = false;
|
|
};
|
|
#endif
|
|
}
|
|
break;
|
|
|
|
case LGS::CMD_STATE_2:
|
|
// prepare response
|
|
OnCmdState2( pBuffer, nCount, pSendBufferPtr, nSendCount, nMode, bBoardNoIrq );
|
|
// write command
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
|
|
#ifdef RESTART_ON_NO_IRQ
|
|
if( bBoardNoIrq ) {
|
|
m_bRun = false;
|
|
};
|
|
#endif
|
|
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;
|
|
#ifndef NO_EMBED_CAMERA
|
|
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 = cMilliseconds;
|
|
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 );
|
|
//m_bRun = false;
|
|
// reset IRQ checking
|
|
nBoardIrq = 0;
|
|
nBoardTimer = cMilliseconds;
|
|
break;
|
|
#endif //! NO_EMBED_CAMERA
|
|
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 );
|
|
//m_bRun = false;
|
|
// reset IRQ checking
|
|
nBoardIrq = 0;
|
|
nBoardTimer = cMilliseconds;
|
|
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 );
|
|
//m_bRun = false;
|
|
// reset IRQ checking
|
|
nBoardIrq = 0;
|
|
nBoardTimer = cMilliseconds;
|
|
#ifdef LGS_MIRROR
|
|
bRestart = true;
|
|
//m_bRun = false;
|
|
Reset( true );
|
|
#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 = cMilliseconds;
|
|
// set data finished correctly
|
|
bSetHzDataInProgress = false;
|
|
//Restart After Aply Mask
|
|
bRestart = true;
|
|
Reset( true );
|
|
//
|
|
}
|
|
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:
|
|
{
|
|
int16_t nDevice = 0;
|
|
bool bPendingSave = OnCmdSetCalibrationTable( pBuffer, nCount, pSendBufferPtr, nSendCount, nDevice );
|
|
// write command
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
|
|
#ifndef RANGE_16BIT
|
|
// 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 );
|
|
//m_bRun = false;
|
|
// reset IRQ checking
|
|
nBoardIrq = 0;
|
|
nBoardTimer = cMilliseconds;
|
|
// set data finished correctly
|
|
bSetCalibrationTableInProgress = false;
|
|
}
|
|
else
|
|
bSetCalibrationTableInProgress = true;
|
|
#endif // 16 bit
|
|
}
|
|
break;
|
|
|
|
case LGS::CMD_QUIT:
|
|
*pSendBufferPtr++ = LGS::CMD_QUIT;
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
|
|
#ifndef COMPILE_AS_GETFILE
|
|
#ifdef STORE_FIRST_SAF
|
|
if( g_bSAFFileEnable ){
|
|
|
|
m_Detector[ 0 ].save_current_SAF();
|
|
};
|
|
#endif
|
|
#endif
|
|
Reset( true );
|
|
break;
|
|
|
|
case LGS::CMD_RESTART:
|
|
*pSendBufferPtr++ = LGS::CMD_RESTART;
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
|
|
//#ifdef INFINITE_SAF_STUDY
|
|
// m_Detector[0].StartLearningCycle();
|
|
//#else
|
|
bRestart = true;
|
|
#ifndef COMPILE_AS_GETFILE
|
|
#ifdef STORE_FIRST_SAF
|
|
if( g_bSAFFileEnable ){
|
|
m_Detector[ 0 ].save_current_SAF();
|
|
};
|
|
#endif
|
|
#endif
|
|
Reset( true );
|
|
//#endif
|
|
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;
|
|
#ifdef DETECTION_MULTI_PROFILES
|
|
case LGS::CMD_GET_ACTIVE_PROFILE:
|
|
// reply command
|
|
*pSendBufferPtr++ = LGS::CMD_GET_ACTIVE_PROFILE;
|
|
// reply data
|
|
nSendCount += LGS::BuildCmdGetActiveProfile( pSendBufferPtr, getActiveDetectionProfile() );
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
|
|
break;
|
|
case LGS::CMD_SET_ACTIVE_PROFILE:
|
|
//ToDo ...
|
|
//printf( "Set Active Profile %d\n",(uint8_t)pBuffer[0] );
|
|
if ( setActiveDetectionProfile( pBuffer[0] ) ){
|
|
bRestart = true;
|
|
//m_bRun = false;
|
|
Reset( true );
|
|
};
|
|
*pSendBufferPtr++ = LGS::CMD_SET_ACTIVE_PROFILE;
|
|
//data
|
|
//nSendCount += LGS::BuildCmdGetActiveProfile( pSendBufferPtr, getActiveDetectionProfile() );
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
|
|
break;
|
|
#endif
|
|
#ifndef EMBEDDED_CAMERA_DISABLE
|
|
#ifndef NO_EMBED_CAMERA
|
|
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;
|
|
Reset( true );
|
|
}
|
|
break;
|
|
#endif
|
|
#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
|
|
#ifndef NO_EMBED_CAMERA
|
|
SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, &m_pCamera->GetParameters(), &m_Relay.GetParameters(), &vp, &m_LRFDisable );
|
|
#else
|
|
SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, NULL, &m_Relay.GetParameters(), &vp, &m_LRFDisable );
|
|
#endif
|
|
// update voltage prameters
|
|
m_Voltage.SetParameters( &vp );
|
|
// reset after file operation
|
|
Reset( true );
|
|
//m_bRun = false;
|
|
// reset IRQ checking
|
|
nBoardIrq = 0;
|
|
nBoardTimer = cMilliseconds;
|
|
}
|
|
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
|
|
#ifndef NO_EMBED_CAMERA
|
|
SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, &m_pCamera->GetParameters(), &rp, &m_Voltage.GetParameters(), &m_LRFDisable );
|
|
#else
|
|
SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, NULL, &rp, &m_Voltage.GetParameters(), &m_LRFDisable );
|
|
#endif
|
|
// update relay parameters
|
|
m_Relay.SetParameters( &rp );
|
|
// reset after file operation
|
|
//m_bRun = false;
|
|
Reset( true );
|
|
// reset IRQ checking
|
|
nBoardIrq = 0;
|
|
nBoardTimer = cMilliseconds;
|
|
}
|
|
break;
|
|
|
|
case LGS::CMD_SET_ADDRESS:
|
|
{
|
|
// reply command
|
|
*pSendBufferPtr++ = LGS::CMD_SET_ADDRESS;
|
|
// parse parameters
|
|
uint8_t pSerialNumber[MAX_PATH];
|
|
uint8_t 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
|
|
#ifndef NO_EMBED_CAMERA
|
|
SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, &m_pCamera->GetParameters(), &m_Relay.GetParameters(), &m_Voltage.GetParameters(), &m_LRFDisable );
|
|
#else
|
|
SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, NULL, &m_Relay.GetParameters(), &m_Voltage.GetParameters(), &m_LRFDisable );
|
|
#endif
|
|
// reset after file operation
|
|
//m_bRun = false;
|
|
Reset( true );
|
|
// reset IRQ checking
|
|
nBoardIrq = 0;
|
|
nBoardTimer = cMilliseconds;
|
|
}
|
|
}
|
|
break;
|
|
|
|
case LGS::CMD_SET_COMM_SPEED:
|
|
{
|
|
// reply command
|
|
*pSendBufferPtr++ = LGS::CMD_SET_COMM_SPEED;
|
|
// parse parameters
|
|
int32_t 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
|
|
//m_bRun = false;
|
|
Reset( true );
|
|
// reset IRQ checking
|
|
nBoardIrq = 0;
|
|
nBoardTimer = cMilliseconds;
|
|
}
|
|
}
|
|
break;
|
|
|
|
case LGS::CMD_PARAMETERS:
|
|
{
|
|
// reply command
|
|
*pSendBufferPtr++ = LGS::CMD_PARAMETERS;
|
|
// parse input command
|
|
uint8_t bSet, nDevice;
|
|
LGS::LGS_PARAMETERS parameters;
|
|
LGS::GetParameters( pBuffer, &bSet, &nDevice, ¶meters );
|
|
// return parameters
|
|
if( bSet )
|
|
{
|
|
#if defined( LGS_PLS_1 ) || defined( LGS_MND )
|
|
if( nDevice == 0 ) m_Detector[ nDevice ].SetParameters( ¶meters );
|
|
#else
|
|
#ifdef LGS_MIRROR
|
|
m_Detector[ ( nDevice ) % 4 ].SetParameters( ¶meters );
|
|
m_Detector[ ( nDevice + 2 ) % 4 ].SetParameters( ¶meters );
|
|
#endif
|
|
m_Detector[ nDevice ].SetParameters( ¶meters );
|
|
|
|
#endif
|
|
nSendCount += LGS::BuildCmdSetParameters( pSendBufferPtr, nDevice, ¶meters );
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
|
|
// reset after file operation
|
|
//m_bRun = false;
|
|
Reset( true );
|
|
// reset IRQ checking
|
|
nBoardIrq = 0;
|
|
nBoardTimer = cMilliseconds;
|
|
}
|
|
else
|
|
{
|
|
#if defined( LGS_PLS_1 ) || defined( LGS_MND )
|
|
if( nDevice == 0 ) m_Detector[ nDevice ].GetParameters( ¶meters );// Set only as Master Device
|
|
#else
|
|
m_Detector[ nDevice ].GetParameters( ¶meters );
|
|
#endif
|
|
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 );
|
|
#ifdef INFINITE_SAF_STUDY
|
|
m_Detector[0].StartLearningCycle();
|
|
#else
|
|
nMode = LGS::MODE_DETECTOR;
|
|
#ifndef COMPILE_AS_GETFILE
|
|
#ifdef STORE_FIRST_SAF
|
|
if( g_bSAFFileEnable ){
|
|
m_Detector[0].save_current_SAF();
|
|
};
|
|
#endif
|
|
#endif
|
|
Reset( false );
|
|
#endif
|
|
m_nBeforeZeroCounter = 0;
|
|
// reset IRQ checking
|
|
nBoardIrq = 0;
|
|
nBoardTimer = cMilliseconds;
|
|
#ifdef LGS_MIRROR // ??
|
|
bRestart = true;
|
|
Reset( true );
|
|
#endif
|
|
break;
|
|
|
|
case LGS::CMD_FULL_RESET:
|
|
//if( g_dwStartupTime == 0 ) break;
|
|
if( ( g_qwStartupTime - cMilliseconds ) < 3000 ) break; // No Reset In First 3 Seconds
|
|
*pSendBufferPtr++ = LGS::CMD_FULL_RESET;
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
|
|
nMode = LGS::MODE_DETECTOR;
|
|
#ifndef COMPILE_AS_GETFILE
|
|
#ifdef STORE_FIRST_SAF
|
|
if( g_bSAFFileEnable ){
|
|
m_Detector[ 0 ].save_current_SAF();
|
|
};
|
|
#endif
|
|
#endif
|
|
bRestart = true;
|
|
Reset( true );
|
|
break;
|
|
|
|
case LGS::CMD_FULL_BORDER:
|
|
{
|
|
*pSendBufferPtr++ = LGS::CMD_FULL_BORDER;
|
|
|
|
// read command data
|
|
uint16_t nAngle;
|
|
LGS::GetCmdFullBorder( pBuffer, &nAngle );
|
|
|
|
// prepare answer
|
|
uint16_t nRange1 = 0;
|
|
uint16_t nRange2 = 0;
|
|
#ifndef LGS_PLS_1
|
|
#ifdef LGS_MIRROR
|
|
#ifdef LGS_MND
|
|
#ifdef INFINITE_SAF_STUDY
|
|
bool bReady = m_Detector[0].GetFullBorderRange( nAngle, &nRange1, true ) &&
|
|
m_Detector[0].GetFullBorderRange( nAngle, &nRange2, false );
|
|
#else
|
|
bool bReady = m_Detector[0].GetFullBorderRange( nAngle, &nRange1 );
|
|
nRange2 = nRange1;
|
|
#endif
|
|
#else
|
|
uint16_t nRange3 = 0;
|
|
uint16_t nRange4 = 0;
|
|
|
|
bool bReady = m_Detector[3].GetFullBorderRange( nAngle, &nRange4 ) &&
|
|
m_Detector[2].GetFullBorderRange( nAngle, &nRange3 ) &&
|
|
m_Detector[1].GetFullBorderRange( nAngle, &nRange2 ) &&
|
|
m_Detector[0].GetFullBorderRange( nAngle, &nRange1 );
|
|
if( bReady ){
|
|
if( nRange1 > nRange2 ){
|
|
int16_t TRange;
|
|
TRange = nRange1;
|
|
nRange1 = nRange2;
|
|
nRange2 = TRange;
|
|
};
|
|
if( nRange1 > nRange3 ){
|
|
int16_t TRange;
|
|
TRange = nRange1;
|
|
nRange1 = nRange3;
|
|
nRange3 = TRange;
|
|
};
|
|
if( nRange1 > nRange4 ){
|
|
int16_t TRange;
|
|
TRange = nRange1;
|
|
nRange1 = nRange4;
|
|
nRange4 = TRange;
|
|
};
|
|
if( nRange2 < nRange3 ){
|
|
nRange2 = nRange3;
|
|
};
|
|
if( nRange2 < nRange4 ){
|
|
nRange2 = nRange4;
|
|
};
|
|
};
|
|
#endif
|
|
#else
|
|
bool bReady = m_Detector[1].GetFullBorderRange( nAngle, &nRange2 ) &&
|
|
m_Detector[0].GetFullBorderRange( nAngle, &nRange1 );
|
|
#endif
|
|
#else // ndef PLS1
|
|
|
|
#ifdef INFINITE_SAF_STUDY
|
|
bool bReady = m_Detector[0].GetFullBorderRange( nAngle, &nRange1, true ) &&
|
|
m_Detector[0].GetFullBorderRange( nAngle, &nRange2, false );
|
|
#else
|
|
bool bReady = m_Detector[0].GetFullBorderRange( nAngle, &nRange1 );
|
|
#endif
|
|
|
|
|
|
#endif // ndef PLS_1
|
|
if( bReady )
|
|
#ifdef RANGE_16BIT
|
|
//nSendCount += LGS::BuildEvtFullBorder( pSendBufferPtr, true, nAngle, nRange1 >> 5 , nRange2 >> 5 );
|
|
//nSendCount += LGS::BuildEvtFullBorder( pSendBufferPtr, true, nAngle, nRange1 >> 3 , nRange2 >> 3 );
|
|
//nSendCount += LGS::BuildEvtFullBorder( pSendBufferPtr, true, nAngle, (uint16_t)ceil( ((float)nRange1)/ 11.12f), (uint16_t)ceil( ((float)nRange2)/ 11.12f) );
|
|
{
|
|
uint16_t nR0,nR1;
|
|
//nRange1 = nAngle;
|
|
//nR0 = (uint16_t)(((float)nRange1)/ 11.12 + 1 );
|
|
nR0 = (uint16_t)(( 2048L * nRange1 )/ 22237 + 1 );
|
|
nR1 = (uint16_t)(( 2048L * nRange2 )/ 22237 + 1 );
|
|
nSendCount += LGS::BuildEvtFullBorder( pSendBufferPtr, true, nAngle, nR0, nR1 );
|
|
}
|
|
#else
|
|
nSendCount += LGS::BuildEvtFullBorder( pSendBufferPtr, true, nAngle, nRange1, nRange2 );
|
|
#endif
|
|
else
|
|
#ifndef LGS_PLS_1
|
|
#ifdef LGS_MND
|
|
nSendCount += LGS::BuildEvtFullBorder( pSendBufferPtr, false, nAngle, 0, 0 );
|
|
#else
|
|
// use percent from detector 2 because it always comes later
|
|
nSendCount += LGS::BuildEvtFullBorder( pSendBufferPtr, false, nRange2, 0, 0 );
|
|
#endif
|
|
#else
|
|
nSendCount += LGS::BuildEvtFullBorder( pSendBufferPtr, false, nAngle, 0, 0 );
|
|
#endif
|
|
|
|
// write back
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
|
|
}
|
|
break;
|
|
|
|
case LGS::CMD_GETFILE:
|
|
{
|
|
// build CMD_GETFILE command
|
|
*pSendBufferPtr++ = LGS::CMD_GETFILE;
|
|
#ifdef COMPILE_AS_GETFILE
|
|
if( nMode != LGS::MODE_GETFILE ){
|
|
bGetFileRun = true;
|
|
nMode = LGS::MODE_GETFILE;
|
|
};
|
|
{
|
|
|
|
#else
|
|
if( nMode != LGS::MODE_GETFILE ){
|
|
nSendCount += LGS::BuildGetFile( pSendBufferPtr, LGS::GF_ERRORMODE, 0, 0, 0 );
|
|
} else {
|
|
#endif
|
|
// get command parameters
|
|
uint8_t bError, bOperation, pData[100];
|
|
int16_t 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 answer
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
|
|
}
|
|
break;
|
|
|
|
#ifndef LGS_DISABLE_FILE_SYSTEM
|
|
case LGS::CMD_FS_SUB_PACKET: {
|
|
if( nMode != LGS::MODE_GETFILE ){
|
|
*pSendBufferPtr++ = LGS::CMD_UNSUPPORTED;
|
|
} else {
|
|
bool bAction;
|
|
PFS_DATA tPtr;
|
|
uint16_t tSize;
|
|
|
|
*pSendBufferPtr++ = LGS::CMD_FS_SUB_PACKET;
|
|
nSendCount ++;
|
|
m_pFSHelper->consume_data( pBuffer, bAction );
|
|
if( bAction ){
|
|
m_pFSHelper->do_action();
|
|
};
|
|
m_pFSHelper->output_data( tPtr, tSize );
|
|
if( tSize ){
|
|
memcpy( pSendBufferPtr, tPtr, tSize );
|
|
pSendBufferPtr += tSize;
|
|
nSendCount += tSize-1;
|
|
} else {
|
|
LGS::FS_DATA_EX OutFsData;
|
|
OutFsData.nCommand = LGS::FS_CMD_SEND_EVT;
|
|
OutFsData.sendevt.nError = LGS::FS_ERROR_OPERATION;
|
|
OutFsData.sendevt.nOrder = 0;
|
|
nSendCount += LGS::BuildFSSubPacket( pSendBufferPtr, &OutFsData );
|
|
};
|
|
};
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
|
|
break;
|
|
}
|
|
#endif
|
|
default:
|
|
//printf("CMD_UNSUPPORTED[0x%02X]\n", bHostCommand );
|
|
*pSendBufferPtr++ = LGS::CMD_UNSUPPORTED;
|
|
m_Protocol.Write( pSendBuffer, nSendCount, 0, false );
|
|
break;
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
#ifdef COMPILE_AS_GETFILE
|
|
//bRestart;
|
|
return false;
|
|
#else
|
|
return bRestart;
|
|
#endif
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef COMPILE_3DSCANER
|
|
#ifdef COMPILE_RTSCANER___
|
|
// DoSendBoardData For RealTime Scanner
|
|
bool CKernel::DoSendBoardData( int16_t 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];
|
|
int16_t nRange[2];
|
|
uint8_t pData[ ( LGS_MAX_SEND_BOARDDATA_PART * 13 ) + 10 ];
|
|
CLgBitCode Encoder( pData );
|
|
int16_t 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
|
|
uint8_t 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 );
|
|
|
|
delay(1);
|
|
|
|
// 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
|
|
//DWORD CTimer = m_pBoard->GetTimer();
|
|
//while( CTimer == m_pBoard->GetTimer() ); // delay 1/6000 sec
|
|
|
|
}
|
|
|
|
return true;
|
|
};
|
|
#else
|
|
#ifdef DEBUG_ENABLE_SEND_BOARDDATA
|
|
/* Old Procedure 060512
|
|
bool CKernel::DoSendBoardData( int16_t nDevice ){
|
|
#ifndef LGS_MIRROR
|
|
#ifdef LGS_PLS_1
|
|
nDevice = 0;
|
|
#else
|
|
nDevice = nDevice % 2;
|
|
#endif
|
|
#endif
|
|
if( !m_pComm485->SetParameters( LGS_SEND_BOARDDATA_BAUDRATE, 8L, CComm485::_NOPARITY ) )
|
|
return false;
|
|
|
|
DWORD nBoardIrq = 0;
|
|
DWORD nBoardTimer = TIMER();
|
|
bool bPower, bZero, bSun[2], Reading, Writing;
|
|
|
|
DWORD Buffer[LGS_MAX_DETECTOR_ANGLES];
|
|
uint16_t CPointer = 0;
|
|
uint16_t OPointer = 0;
|
|
uint16_t CAngle = 0;
|
|
|
|
int16_t nRange[2];
|
|
uint8_t pData[ ( LGS_MAX_SEND_BOARDDATA_PART * 13 ) + 10 ];
|
|
CLgBitCode Encoder( pData );
|
|
int16_t nPart = 0;
|
|
bool WaitFZ;
|
|
|
|
Reading = false;
|
|
Writing = false;
|
|
WaitFZ = true;
|
|
//nDevice = ( (nDevice == 0 || nDevice == 1) ? nDevice : 0 );
|
|
while( m_bRun ){
|
|
#ifdef WATCHDOG_ENABLED
|
|
// update watchdog timer
|
|
m_WatchDog.Update( TIMER() );
|
|
#endif
|
|
if( ( ( TIMER() ) - nBoardTimer ) > 36UL ){
|
|
if( !nBoardIrq ){
|
|
#ifdef DEBUG_BOARD_PRINT_NO_IRQ
|
|
printf( "NO IRQ %04x\n", m_pBoard->ReadNewBoard() );
|
|
#endif
|
|
// reset board
|
|
if( g_UI_Debug ){
|
|
printf( "NO IRQ RESET\n" );
|
|
};
|
|
m_pBoard->AsyncReset();
|
|
WaitFZ = true;
|
|
Reading = false;
|
|
Writing = false;
|
|
};
|
|
nBoardTimer = TIMER();
|
|
nBoardIrq = 0;
|
|
}
|
|
// check board
|
|
uint8_t RetVal;
|
|
|
|
if( !Writing )
|
|
|
|
while( ( RetVal = m_pBoard->GetData( &bZero, bSun, nRange, &bPower ) ) > 0 ){
|
|
if( RetVal == 2 ){
|
|
#ifdef DEBUG_BOARD_PRINT_NO_IRQ
|
|
printf("DMA Transfers Overlaped\n");
|
|
#endif
|
|
// -----------------------
|
|
m_pBoard->AsyncReset();
|
|
WaitFZ = true;
|
|
Reading = false;
|
|
Writing = false;
|
|
break;
|
|
};
|
|
// perform linearization
|
|
nRange[0] = m_Calibrator[0].Calibrate( nRange[0] );
|
|
#ifdef LGS_MIRROR
|
|
nRange[1] = nRange[0];
|
|
#else
|
|
#ifndef LGS_PLS_1
|
|
nRange[1] = nRange[0];
|
|
#else
|
|
nRange[1] = m_Calibrator[1].Calibrate( nRange[1] );
|
|
#endif
|
|
#endif
|
|
// update voltage state
|
|
m_Voltage.Invalidate( bPower );
|
|
|
|
// increase IRQ counter
|
|
nBoardTimer = TIMER();
|
|
nBoardIrq++;
|
|
if( bZero && WaitFZ ){
|
|
WaitFZ = false;
|
|
Writing = false;
|
|
};
|
|
if( !WaitFZ ){
|
|
if( bZero ){
|
|
CPointer = 0;
|
|
CAngle = 0;
|
|
if( !Writing ) Reading = true;
|
|
} else {
|
|
CAngle++;
|
|
};
|
|
};
|
|
if( Reading ){
|
|
if( CAngle >= ( LGS_MAX_DETECTOR_ANGLES * nDevice ) ){
|
|
bZero = (( CAngle % LGS_MAX_DETECTOR_ANGLES ) == 0 );
|
|
//nRange[nDevice]
|
|
Buffer[CPointer] = (DWORD)( nRange[nDevice] | ( bSun[nDevice] ? 1 << 11 : 0 ) | ( bZero ? 1 << 12 : 0 ) );
|
|
CPointer++;
|
|
if( CPointer == LGS_MAX_DETECTOR_ANGLES ){
|
|
Reading = false;
|
|
Writing = true;
|
|
OPointer = 0;
|
|
};
|
|
};
|
|
};
|
|
};
|
|
if( Writing ){
|
|
// increase IRQ counter
|
|
nBoardTimer = TIMER();
|
|
nBoardIrq++;
|
|
|
|
// add next 13 bits of data
|
|
DWORD dwData = Buffer[OPointer];//(DWORD)( nRange[nDevice] | ( bSun[nDevice] ? 1 << 11 : 0 ) | ( bZero ? 1 << 12 : 0 ) );
|
|
OPointer++;
|
|
#ifdef LGS_MIRROR
|
|
if( OPointer == 916 ){ //
|
|
#else
|
|
#ifdef LGS_PLS_1
|
|
if( OPointer == LGS_MAX_DETECTOR_ANGLES ){ // Test like LGS ...
|
|
#else
|
|
if( OPointer == LGS_MAX_DETECTOR_ANGLES ){
|
|
#endif
|
|
#endif
|
|
Writing = false;
|
|
//WaitFZ = true;
|
|
continue;
|
|
};
|
|
if( Encoder.Encode24( dwData, 13 ) ){
|
|
// increase part number
|
|
nPart++;
|
|
// if number raw parts meets max parts
|
|
if( nPart >= LGS_MAX_SEND_BOARDDATA_PART ){
|
|
// prepare check sum in 14th byte of packet
|
|
uint8_t 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 );
|
|
delay(4);
|
|
// reset part
|
|
nPart = 0;
|
|
|
|
// zero memory
|
|
memset( pData, 0, (LGS_MAX_SEND_BOARDDATA_PART * 13) + 1 );
|
|
#ifdef COMM_WITHOUT_INTERRUPTS
|
|
m_pComm485->Invalidate();
|
|
//m_pCameraComm->Invalidate();
|
|
#endif
|
|
}
|
|
// restart encoder
|
|
Encoder.SetBuffer( pData + ( nPart * 13 ) );
|
|
};
|
|
};
|
|
};
|
|
return true;
|
|
} */
|
|
// Regular DoSendBoardData ... PLS LGS ALS LFS
|
|
bool CKernel::DoSendBoardData( int16_t nDevice ){
|
|
#ifndef LGS_MIRROR
|
|
#ifdef LGS_PLS_1
|
|
nDevice = 0;
|
|
#else
|
|
nDevice = nDevice % 2;
|
|
#endif
|
|
#else
|
|
nDevice = nDevice % 4;
|
|
#endif
|
|
if( !m_pComm485->SetParameters( LGS_SEND_BOARDDATA_BAUDRATE, 8L, CComm485::_NOPARITY ) )
|
|
return false;
|
|
|
|
DWORD nBoardIrq = 0;
|
|
DWORD nBoardTimer = TIMER();
|
|
bool bPower, bZero, bSun[2], Reading, Writing;
|
|
uint16_t SentScanCounter = 0;
|
|
//DWORD Buffer[LGS_MAX_DETECTOR_ANGLES];
|
|
|
|
uint16_t far *Buffer[2];//[LGS_MAX_DETECTOR_ANGLES];
|
|
Buffer[0] = (uint16_t far *) farmalloc( sizeof( uint16_t ) *LGS_MAX_DETECTOR_ANGLES );
|
|
if( Buffer[0] == NULL ) return false;
|
|
Buffer[1] = (uint16_t far *) farmalloc( sizeof( uint16_t ) *LGS_MAX_DETECTOR_ANGLES );
|
|
if( Buffer[0] == NULL ){
|
|
free( Buffer[0] );
|
|
return false;
|
|
};
|
|
uint16_t CPointer = 0;
|
|
uint16_t OPointer = 0;
|
|
uint16_t CAngle = 0;
|
|
|
|
uint16_t nRange[2];
|
|
#ifdef LGS_BOARDSAMPLE_RATIO
|
|
int16_t nRBuffer[LGS_BOARDSAMPLE_RATIO][2];
|
|
#endif
|
|
uint8_t pData[ ( LGS_MAX_SEND_BOARDDATA_PART * 13 ) + 1 ];
|
|
CLgBitCode Encoder( pData );
|
|
int16_t nPart = 0;
|
|
bool WaitFZ;
|
|
bool tbZero;
|
|
bool tbSun;
|
|
char CoBuffer[20];
|
|
DWORD cnt;
|
|
uint8_t bCOutputArray, bCInputArray;
|
|
|
|
cnt = 0;
|
|
tbZero = false;
|
|
tbSun = false;
|
|
Reading = false;
|
|
Writing = false;
|
|
WaitFZ = true;
|
|
bCOutputArray = 0;
|
|
bCInputArray = 0;
|
|
//nDevice = ( (nDevice == 0 || nDevice == 1) ? nDevice : 1 );
|
|
|
|
//Wait till start
|
|
//cnt = m_pComm485->ReadWithWait( CoBuffer, 2, 36 ); //2 seconds in measurements of 1\18
|
|
//if( strcmp( CoBuffer, "AA" )!= 0 ) m_bRun = false;
|
|
//if( cnt == 0 ) m_bRun = false;
|
|
//delay( 3 );
|
|
|
|
// Start Empty Encoder
|
|
memset( pData, 0, ( LGS_MAX_SEND_BOARDDATA_PART * 13 ) + 1 );
|
|
Encoder.SetBuffer( pData );
|
|
while( m_bRun ){
|
|
#ifdef WATCHDOG_ENABLED
|
|
if( g_bWatchDogEnable ){
|
|
// update watchdog timer
|
|
m_WatchDog.Update( TIMER() );
|
|
};
|
|
#endif
|
|
#ifdef BOARD_LAZY_INIT
|
|
if( ( ( TIMER() ) - nBoardTimer ) > 300UL ){
|
|
#else
|
|
if( ( ( TIMER() ) - nBoardTimer ) > 136UL ){
|
|
#endif
|
|
if( !nBoardIrq ){
|
|
#ifdef DEBUG_BOARD_PRINT_NO_IRQ
|
|
printf( "NO IRQ %04x\n", m_pBoard->ReadNewBoard() );
|
|
#endif
|
|
m_pBoard->AsyncReset();
|
|
WaitFZ = true;
|
|
Reading = false;
|
|
Writing = false;
|
|
};
|
|
nBoardTimer = TIMER();
|
|
nBoardIrq = 0;
|
|
}
|
|
// check board
|
|
uint8_t RetVal;
|
|
|
|
while( ( RetVal = m_pBoard->GetData( &bZero, bSun, nRange, &bPower ) ) > 0 ){
|
|
if( RetVal == 2 ){
|
|
#ifdef DEBUG_BOARD_PRINT_NO_IRQ
|
|
printf("DMA Transfers Overlaped\n");
|
|
#endif
|
|
// -----------------------
|
|
m_pBoard->AsyncReset();
|
|
WaitFZ = true;
|
|
Reading = false;
|
|
Writing = false;
|
|
break;
|
|
};
|
|
#ifdef RANGE_16BIT
|
|
|
|
#else
|
|
// perform linearization
|
|
nRange[0] = m_Calibrator[0].Calibrate( nRange[0] );
|
|
#ifdef LGS_MIRROR
|
|
nRange[1] = nRange[0];
|
|
#else
|
|
#ifdef LGS_PLS_1
|
|
nRange[1] = nRange[0];
|
|
#else
|
|
nRange[1] = m_Calibrator[1].Calibrate( nRange[1] );
|
|
#endif
|
|
#endif
|
|
#endif //16 bit
|
|
// update voltage state
|
|
m_Voltage.Invalidate( bPower );
|
|
|
|
// increase IRQ counter
|
|
nBoardTimer = TIMER();
|
|
nBoardIrq++;
|
|
//if(!Writing ){
|
|
//if( bZero && WaitFZ ){
|
|
// WaitFZ = false;
|
|
//Writing = false;
|
|
//};
|
|
if( !Reading && WaitFZ ){
|
|
if( bZero ){
|
|
CPointer = 0;
|
|
CAngle = 0;
|
|
Reading = true;
|
|
WaitFZ = false;
|
|
};
|
|
};
|
|
|
|
if( Reading ){
|
|
CAngle++;
|
|
#ifdef LGS_MIRROR
|
|
if( CAngle >= ( LGS_MAX_DETECTOR_ANGLES * nDevice ) )
|
|
#endif
|
|
{
|
|
#ifdef ALS_300
|
|
if( CAngle % 3 == 0 ){
|
|
if( bZero ) tbZero = true; //= ( CAngle == 3 ); // First Measure
|
|
if( bSun[nDevice] ) tbSun = true;
|
|
Buffer[bCInputArray][CPointer] += nRange[nDevice];
|
|
Buffer[bCInputArray][CPointer] = Buffer[bCInputArray][CPointer] / 3;
|
|
Buffer[bCInputArray][CPointer] |= (uint16_t)( ( bSun[nDevice] ? 1 << 11 : 0 ) | ( tbZero ? 1 << 12 : 0 ) );
|
|
CPointer++;
|
|
tbZero = false;
|
|
tbSun = false;
|
|
if( CPointer < LGS_MAX_DETECTOR_ANGLES ){
|
|
Buffer[bCInputArray][CPointer] = 0;
|
|
} else {
|
|
Buffer[bCInputArray][0] = 0;
|
|
};
|
|
} else {
|
|
Buffer[bCInputArray][CPointer] += nRange[nDevice];
|
|
if( bZero ) tbZero = true;
|
|
if( bSun[nDevice] ) tbSun = true;
|
|
continue;
|
|
};
|
|
#else
|
|
bZero = (( CAngle % LGS_MAX_DETECTOR_ANGLES ) == 0 );
|
|
Buffer[bCInputArray][CPointer] = (uint16_t)( nRange[nDevice] | ( bSun[nDevice] ? 1 << 11 : 0 ) | ( bZero ? 1 << 12 : 0 ) );
|
|
CPointer++;
|
|
#endif
|
|
|
|
#if defined( LGS_REDUCED_PRF )
|
|
if( CPointer == (LGS_MAX_DETECTOR_ANGLES / LGS_PRF_REDUCE_RATIO) ){
|
|
#else
|
|
if( CPointer == LGS_MAX_DETECTOR_ANGLES ){
|
|
#endif
|
|
bCInputArray = ( bCInputArray )? 0:1 ;
|
|
if( bCInputArray == bCOutputArray ){
|
|
Reading = false;
|
|
};
|
|
Writing = true;
|
|
CPointer = 0;
|
|
//OPointer = 0;
|
|
};
|
|
};
|
|
};
|
|
//};
|
|
};
|
|
if( Writing ){
|
|
|
|
#ifdef LGS_MIRROR
|
|
if( OPointer < 920 ){ //
|
|
#else
|
|
#ifdef LGS_PLS_1
|
|
#ifdef LGS_PLS_200
|
|
if( OPointer < LGS_MAX_DETECTOR_ANGLES ){ // Test like LGS ...
|
|
#else
|
|
if( OPointer < LGS_MAX_DETECTOR_ANGLES ){ // Test like LGS ...
|
|
#endif
|
|
#else
|
|
if( OPointer < LGS_MAX_DETECTOR_ANGLES ){
|
|
#endif
|
|
#endif
|
|
// add next 13 bits of data
|
|
#if defined( LGS_REDUCED_PRF )
|
|
DWORD dwData;
|
|
if( LGS_PRF_REDUCE_RATIO > 1 ){
|
|
if( ( Buffer[bCOutputArray][(OPointer / LGS_PRF_REDUCE_RATIO)] & (1<<12) ) && (( OPointer % LGS_PRF_REDUCE_RATIO ) != 0)){
|
|
Buffer[bCOutputArray][(OPointer / LGS_PRF_REDUCE_RATIO)] = Buffer[bCOutputArray][(OPointer / LGS_PRF_REDUCE_RATIO)] & ( ~(1<<12) );
|
|
};
|
|
dwData = Buffer[bCOutputArray][(OPointer / LGS_PRF_REDUCE_RATIO )];
|
|
} else {
|
|
dwData = Buffer[bCOutputArray][OPointer];
|
|
};
|
|
#else
|
|
DWORD dwData = (DWORD) Buffer[bCOutputArray][OPointer];
|
|
#endif
|
|
OPointer++;
|
|
if( Encoder.Encode24( dwData, 13 ) ){
|
|
// increase part number
|
|
nPart++;
|
|
// if number raw parts meets max parts
|
|
if( nPart >= LGS_MAX_SEND_BOARDDATA_PART ){
|
|
// prepare check sum in 14th byte of packet
|
|
uint8_t 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 );
|
|
// Wait till all data is sent
|
|
m_pComm485->Flush();
|
|
cnt = 0;
|
|
//long cTT = TIMER();
|
|
//while( cnt==0 && cTT - TIMER() < 180 ){
|
|
// Read 1 Bytes from Line
|
|
// cnt = m_pComm485->ReadWithWait( CoBuffer, 1, 36 ); //2 seconds in measurements of 1\18
|
|
// if( cnt == 0 ) m_bRun = false;
|
|
// if( bCheckSum != CoBuffer[0] ) m_bRun = false;
|
|
//};
|
|
//delay(2);
|
|
// reset part
|
|
nPart = 0;
|
|
// zero memory
|
|
memset( pData, 0, ( LGS_MAX_SEND_BOARDDATA_PART * 13 ) + 1 );
|
|
#ifdef COMM_WITHOUT_INTERRUPTS
|
|
m_pComm485->Invalidate();
|
|
//m_pCameraComm->Invalidate();
|
|
#endif
|
|
};
|
|
// restart encoder
|
|
Encoder.SetBuffer( pData + ( nPart * 13 ) );
|
|
};
|
|
} else {
|
|
bCOutputArray = ( bCOutputArray )? 0: 1;
|
|
if( bCOutputArray == bCInputArray ){
|
|
Writing = false;
|
|
WaitFZ = true;
|
|
};
|
|
OPointer = 0;
|
|
SentScanCounter ++;
|
|
#ifndef SENDBOARDDATA_INF
|
|
if( SentScanCounter > 500 ){
|
|
//while(1);
|
|
return true;
|
|
};
|
|
#endif
|
|
};
|
|
};
|
|
};
|
|
return true;
|
|
}
|
|
#endif
|
|
|
|
#endif //COMPILE_RTSCANER
|
|
|
|
#else //COMPILE_3DSCANER
|
|
|
|
// DoSendBoardData For 3D Scanner
|
|
bool CKernel::DoSendBoardData( int16_t nDevice ){
|
|
#ifndef LGS_MIRROR
|
|
#ifdef LGS_PLS_1
|
|
nDevice = 0;
|
|
#else
|
|
nDevice = nDevice % 2;
|
|
#endif
|
|
#else
|
|
nDevice = nDevice % 4;
|
|
#endif
|
|
if( !m_pComm485->SetParameters( LGS_SEND_BOARDDATA_BAUDRATE, 8L, CComm485::_NOPARITY ) )
|
|
return false;
|
|
|
|
DWORD nBoardIrq = 0;
|
|
DWORD nBoardTimer = TIMER();
|
|
bool bPower, bZero, bSun[2], Reading, Writing;
|
|
|
|
//DWORD Buffer[LGS_MAX_DETECTOR_ANGLES];
|
|
uint16_t Buffer[LGS_MAX_DETECTOR_ANGLES];
|
|
uint16_t CPointer = 0;
|
|
uint16_t OPointer = 0;
|
|
uint16_t CAngle = 0;
|
|
|
|
int16_t nRange[2];
|
|
uint8_t pData[ ( LGS_MAX_SEND_BOARDDATA_PART * 13 ) + 10 ];
|
|
CLgBitCode Encoder( pData );
|
|
int16_t nPart = 0;
|
|
bool WaitFZ;
|
|
|
|
Reading = false;
|
|
Writing = false;
|
|
WaitFZ = true;
|
|
//nDevice = ( (nDevice == 0 || nDevice == 1) ? nDevice : 0 );
|
|
while( m_bRun ){
|
|
#ifdef WATCHDOG_ENABLED
|
|
if( g_bWatchDogEnable ){
|
|
// update watchdog timer
|
|
m_WatchDog.Update( TIMER() );
|
|
};
|
|
#endif
|
|
if( ( ( TIMER() ) - nBoardTimer ) > 36UL ){
|
|
if( !nBoardIrq ){
|
|
#ifdef DEBUG_BOARD_PRINT_NO_IRQ
|
|
printf( "NO IRQ %04x\n", m_pBoard->ReadNewBoard() );
|
|
#endif
|
|
// reset board
|
|
m_pBoard->AsyncReset();
|
|
WaitFZ = true;
|
|
Reading = false;
|
|
Writing = false;
|
|
};
|
|
nBoardTimer = TIMER();
|
|
nBoardIrq = 0;
|
|
}
|
|
// check board
|
|
uint8_t RetVal;
|
|
|
|
while( ( RetVal = m_pBoard->GetData( &bZero, bSun, nRange, &bPower ) ) > 0 ){
|
|
if( RetVal == 2 ){
|
|
#ifdef DEBUG_BOARD_PRINT_NO_IRQ
|
|
printf("DMA Transfers Overlaped\n");
|
|
#endif
|
|
// -----------------------
|
|
m_pBoard->AsyncReset();
|
|
WaitFZ = true;
|
|
Reading = false;
|
|
Writing = false;
|
|
break;
|
|
};
|
|
// perform linearization
|
|
nRange[0] = m_Calibrator[0].Calibrate( nRange[0] );
|
|
#ifdef LGS_MIRROR
|
|
nRange[1] = nRange[0];
|
|
#else
|
|
#ifndef LGS_PLS_1
|
|
nRange[1] = nRange[0];
|
|
#else
|
|
nRange[1] = m_Calibrator[1].Calibrate( nRange[1] );
|
|
#endif
|
|
#endif
|
|
// update voltage state
|
|
m_Voltage.Invalidate( bPower );
|
|
|
|
// increase IRQ counter
|
|
nBoardTimer = TIMER();
|
|
nBoardIrq++;
|
|
if(!Writing ){
|
|
if( bZero && WaitFZ ){
|
|
WaitFZ = false;
|
|
Writing = false;
|
|
};
|
|
if( !WaitFZ ){
|
|
if( bZero ){
|
|
CPointer = 0;
|
|
CAngle = 0;
|
|
Reading = true;
|
|
} else {
|
|
CAngle++;
|
|
};
|
|
};
|
|
if( Reading ){
|
|
if( CAngle >= ( LGS_MAX_DETECTOR_ANGLES * nDevice ) ){
|
|
bZero = (( CAngle % LGS_MAX_DETECTOR_ANGLES ) == 0 );
|
|
//nRange[nDevice]
|
|
//Buffer[CPointer] = (DWORD)( nRange[nDevice] | ( bSun[nDevice] ? 1 << 11 : 0 ) | ( bZero ? 1 << 12 : 0 ) );
|
|
Buffer[CPointer] = (uint16_t)( nRange[nDevice] | ( bSun[nDevice] ? 1 << 11 : 0 ) | ( bZero ? 1 << 12 : 0 ) );
|
|
CPointer++;
|
|
if( CPointer == LGS_MAX_DETECTOR_ANGLES ){
|
|
Reading = false;
|
|
Writing = true;
|
|
OPointer = 0;
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
if( Writing ){
|
|
// increase IRQ counter
|
|
nBoardTimer = TIMER();
|
|
nBoardIrq++;
|
|
|
|
// add next 13 bits of data
|
|
#ifdef LGS_PLS_200
|
|
DWORD dwData;
|
|
if( LGS_PRF_REDUCE_RATIO > 1 ){
|
|
if( ( Buffer[(OPointer >> 1)] & (1<<12) ) && (( OPointer % 2 ) != 0)){
|
|
Buffer[(OPointer >> 1)] = Buffer[(OPointer >> 1)] & ( ~(1<<12) );
|
|
};
|
|
dwData = Buffer[(OPointer >> 1)];
|
|
} else {
|
|
dwData = Buffer[OPointer];
|
|
};
|
|
#else
|
|
DWORD dwData = Buffer[OPointer];
|
|
#endif
|
|
OPointer++;
|
|
#ifdef LGS_MIRROR
|
|
if( OPointer == 916 ){ //
|
|
#else
|
|
#ifdef LGS_PLS_1
|
|
#ifdef LGS_PLS_200
|
|
if( OPointer == LGS_MAX_DETECTOR_ANGLES ){ // Test like LGS ...
|
|
#else
|
|
if( OPointer == LGS_MAX_DETECTOR_ANGLES ){ // Test like LGS ...
|
|
#endif
|
|
#else
|
|
if( OPointer == LGS_MAX_DETECTOR_ANGLES ){
|
|
#endif
|
|
#endif
|
|
Writing = false;
|
|
//WaitFZ = true;
|
|
continue;
|
|
};
|
|
if( Encoder.Encode24( dwData, 13 ) ){
|
|
// increase part number
|
|
nPart++;
|
|
// if number raw parts meets max parts
|
|
if( nPart >= LGS_MAX_SEND_BOARDDATA_PART ){
|
|
// prepare check sum in 14th byte of packet
|
|
uint8_t 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 );
|
|
delay( 2 );
|
|
// reset part
|
|
nPart = 0;
|
|
|
|
// zero memory
|
|
memset( pData, 0, (LGS_MAX_SEND_BOARDDATA_PART * 13) + 1 );
|
|
#ifdef COMM_WITHOUT_INTERRUPTS
|
|
m_pComm485->Invalidate();
|
|
//m_pCameraComm->Invalidate();
|
|
#endif
|
|
}
|
|
// restart encoder
|
|
Encoder.SetBuffer( pData + ( nPart * 13 ) );
|
|
};
|
|
};
|
|
};
|
|
return true;
|
|
}
|
|
|
|
#endif
|
|
/////////////////////// FILE SYSTEM REQUESTS HANDLERS //////////////////////////
|
|
#ifndef LGS_DISABLE_FILE_SYSTEM
|
|
/*
|
|
LG_FS_RESULT CKernel::DoOpenFile( PLG_FS_PATH pName ){
|
|
if( m_pFSFileHandle != NULL ) fclose( m_pFSFileHandle );
|
|
m_pFSFileHandle = fopen( pName->pBuffer, "rb" );
|
|
if( m_pFSFileHandle == NULL ) return LG_FS_RESULT_ERROR_NOT_IMPLEMENTED;
|
|
return LG_FS_RESULT_SUCCESS;
|
|
};
|
|
|
|
LG_FS_RESULT CKernel::DoReadFile( PBYTE pRead, uint8_t bSize, PBYTE pBuffer ){
|
|
if( m_pFSFileHandle == NULL ) return LG_FS_RESULT_ERROR_NOT_IMPLEMENTED;
|
|
*pRead = fread( pBuffer, 1, bSize, m_pFSFileHandle );
|
|
return LG_FS_RESULT_SUCCESS;
|
|
};
|
|
|
|
LG_FS_RESULT CKernel::DoCloseFile( void ){
|
|
if( m_pFSFileHandle == NULL ) return LG_FS_RESULT_ERROR_NOT_IMPLEMENTED;
|
|
fclose( m_pFSFileHandle );
|
|
return LG_FS_RESULT_SUCCESS;
|
|
};
|
|
|
|
LG_FS_RESULT CKernel::DoGetCurrentDirectory( PLG_FS_PATH pPath ){
|
|
if( getcwd( pPath->pBuffer, 256 )!= NULL ){
|
|
pPath->pBuffer[255]=(char)0;
|
|
|
|
// sprintf( pPath->pBuffer, "KOKO256" );
|
|
pPath->nSize = strlen( pPath->pBuffer );
|
|
return LG_FS_RESULT_SUCCESS;
|
|
};
|
|
pPath->pBuffer[0]=(char)0;
|
|
pPath->nSize = 0;
|
|
return LG_FS_RESULT_ERROR_NOT_IMPLEMENTED;
|
|
};
|
|
|
|
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
|
|
|
|
|
|
void CKernel::OnCmdState2( PBYTE &pReadBufferPtr, int16_t &nReadCount, PBYTE &pSendBufferPtr, int16_t &nSendCount, uint8_t &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;
|
|
}
|
|
|
|
uint8_t bRequestType = LGS::S2_RT_TARGET_POLAR;
|
|
if( nReadCount )
|
|
nReadCount -= LGS::GetCmdState2( pReadBufferPtr, &bRequestType );
|
|
// flags
|
|
uint8_t bFlags = 0;
|
|
#ifndef NO_LIC
|
|
// If Work is Disabled then ...
|
|
/*
|
|
if (! m_pBoard->workingEnabled() ){
|
|
int16_t nErrorAngle = 2222;
|
|
if ( ( TIMER() - m_dwTimeErrorDelay_EA ) > MSEC_TO_TIME( 2000UL ) ) {
|
|
nSendCount += LGS::BuildEvtState2ErrorAngle( pSendBufferPtr, nErrorAngle );
|
|
m_dwTimeErrorDelay_EA = TIMER();
|
|
};
|
|
if( m_nInitErrorSkipCounter ) m_nInitErrorSkipCounter --;
|
|
};
|
|
*/
|
|
#endif
|
|
|
|
// check for ANGLE and ZERO MARK errors
|
|
#ifdef LGS_MIRROR
|
|
if( g_bShowErrors ){
|
|
for( int16_t i = 0; i < 4; i++){
|
|
if( m_Detector[i].GetLastErrorAngle() ){
|
|
int16_t nErrorAngle = m_Detector[i].GetLastErrorAngleValue();
|
|
if( ( nErrorAngle == 1111 || nErrorAngle == 387 || nErrorAngle == 1112 || nErrorAngle == 386 ) && m_pBoard->workingEnabled() ){
|
|
// Trying to fixup Certificate trouble
|
|
m_bRun = false; // Error Sending SN to Board -> Restart
|
|
};
|
|
if ( ( ( TIMER() - m_dwTimeErrorDelay_EA ) < MSEC_TO_TIME( 200UL ) ) || !g_bDelayErrors ) {
|
|
if ( ( m_nInitErrorSkipCounter == 0 ) || !g_bDelayErrors ){
|
|
if( nErrorAngle == -1 ){
|
|
bFlags |= LGS::S2_ITF_ERROR_NO_ZERO_MARK;
|
|
} else {
|
|
if( ( nErrorAngle == 1111 || nErrorAngle == 387 || nErrorAngle == 1112 || nErrorAngle == 386 ) && m_pBoard->workingEnabled() ){
|
|
if( g_bShowErrors ){
|
|
// Because of ZeroShift the ErrorAngle must be corrected to 1111 after getting 387
|
|
nErrorAngle = 1111;
|
|
nSendCount += LGS::BuildEvtState2ErrorAngle( pSendBufferPtr, nErrorAngle );
|
|
};
|
|
//m_bRun = false; // Error Sending SN to Board -> Restart
|
|
} else if( ( nErrorAngle > 0 ) && ( nErrorAngle < ( LGS_REAL_DETECTOR_ANGLES - 5 ) ) ){
|
|
if( g_bShowErrors ){
|
|
nErrorAngle += (i+1)*10000;
|
|
nSendCount += LGS::BuildEvtState2ErrorAngle( pSendBufferPtr, nErrorAngle );
|
|
};
|
|
};
|
|
};
|
|
m_nInitErrorSkipCounter = DEFAULT_INIT_SKIP_ERROR;
|
|
} else m_nInitErrorSkipCounter --;
|
|
};
|
|
m_dwTimeErrorDelay_EA = TIMER();
|
|
};
|
|
};
|
|
};
|
|
#else//!LGS_MIRROR
|
|
if( g_bShowErrors && m_Detector[0].GetLastErrorAngle() ){
|
|
int16_t nErrorAngle = m_Detector[0].GetLastErrorAngleValue();
|
|
if ( ( ( TIMER() - m_dwTimeErrorDelay_EA ) < MSEC_TO_TIME( 200UL ) ) || !g_bDelayErrors ) {
|
|
if ( ( m_nInitErrorSkipCounter == 0 ) || !g_bDelayErrors ){
|
|
if( nErrorAngle == -1 ){
|
|
bFlags |= LGS::S2_ITF_ERROR_NO_ZERO_MARK;
|
|
} else {
|
|
/* if( ( nErrorAngle == 1111 ) && m_pBoard->workingEnabled() ){
|
|
m_bRun = false; // Error Sending SN to Board -> Restart
|
|
} else */
|
|
if( ( nErrorAngle > 0 ) && ( nErrorAngle < ( LGS_REAL_DETECTOR_ANGLES - 5 ) ) ){
|
|
nSendCount += LGS::BuildEvtState2ErrorAngle( pSendBufferPtr, nErrorAngle );
|
|
};
|
|
};
|
|
m_nInitErrorSkipCounter = DEFAULT_INIT_SKIP_ERROR;
|
|
} else m_nInitErrorSkipCounter --;
|
|
};
|
|
m_dwTimeErrorDelay_EA = TIMER();
|
|
};
|
|
#endif
|
|
|
|
// check for NO IRQ
|
|
if( g_bShowErrors && bBoardNoIrq ) {
|
|
//if ( ( ( TIMER() - m_dwTimeErrorDelay_IQ ) < 200UL ) || !g_bDelayErrors ) {
|
|
// if ( ( m_nInitErrorSkipCounter == 0 ) || !g_bDelayErrors ){
|
|
bFlags |= LGS::S2_ITF_ERROR_NO_IRQ;
|
|
//m_nInitErrorSkipCounter = DEFAULT_INIT_SKIP_ERROR;
|
|
//printf("Error Sent\n");
|
|
// } else {
|
|
// m_nInitErrorSkipCounter --;
|
|
// //printf("Decreased Init Skip Value [%d]\n",m_nInitErrorSkipCounter);
|
|
// };
|
|
// };
|
|
//m_dwTimeErrorDelay_IQ = TIMER();
|
|
// clear no irq flag
|
|
#ifndef RESTART_ON_NO_IRQ
|
|
bBoardNoIrq = false;
|
|
#endif
|
|
};
|
|
|
|
// check for POWER changes
|
|
if( g_bShowErrors ) m_Voltage.OnProtocolLgsState2Command( bFlags );
|
|
|
|
#ifndef EMBEDDED_CAMERA_DISABLE
|
|
#ifndef NO_EMBED_CAMERA
|
|
// add camera flags
|
|
m_pCamera->OnProtocolLgsState2Command( bFlags );
|
|
#endif
|
|
#endif
|
|
|
|
// apply flags
|
|
if( bFlags ) nSendCount += LGS::BuildEvtState2Flags( pSendBufferPtr, bFlags );
|
|
|
|
/* Old Sergey's 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 */
|
|
#ifdef LGS_MIRROR
|
|
for( int i = 0; i < 4; i++ ){
|
|
CDetector *pDetector = &m_Detector[i];
|
|
CTracker *pTracker = &m_Tracker[0];
|
|
#else //!LGS_MIRROR
|
|
#ifdef LGS_PLS_1
|
|
{
|
|
int i = 0;
|
|
#else
|
|
for( int i = 0; i < 2; i++ ){
|
|
#endif
|
|
CDetector *pDetector = &m_Detector[i];
|
|
CTracker *pTracker = &m_Tracker[i];
|
|
#endif
|
|
|
|
// assume that no errors
|
|
uint8_t 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 )
|
|
#ifndef NO_LIC
|
|
&& m_pBoard->workingEnabled()
|
|
#endif
|
|
#ifdef DEBUG_TARGET_SIMULATOR
|
|
) || bFireSimulatedTarget
|
|
#else
|
|
)
|
|
#endif
|
|
)
|
|
{
|
|
#ifdef DEBUG_TARGET_SIMULATOR
|
|
if( bFireSimulatedTarget ){
|
|
target.bType = LGS::TT_NORMAL;
|
|
target.nRange = 200;
|
|
target.nAngle = ( 3000* nSimulatedTargetID )/360 ;//145; GP2Y0A700K
|
|
target.nWidth = nSimulatedTargetValue;
|
|
bFireSimulatedTarget = false;
|
|
};
|
|
#endif
|
|
|
|
uint8_t 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
|
|
#ifdef LGS_MND
|
|
const double a2r = asin(1.0) * 4.0 / ( LGS_MAX_DETECTOR_ANGLES << 2 );
|
|
double a = ( target.nAngle << 2 ) * a2r;
|
|
#else
|
|
const double a2r = asin(1.0) * 4.0 / ( LGS_MAX_DETECTOR_ANGLES << 2 );
|
|
double a = ( target.nAngle << 1 ) * a2r;
|
|
#endif
|
|
#else //LGS_MIRROR
|
|
const double a2r = asin(1.0) * 4.0 / LGS_MAX_DETECTOR_ANGLES;
|
|
double a = ( target.nAngle ) * a2r;
|
|
#endif
|
|
|
|
#ifdef ALS_300_BM
|
|
target.nAngle = ( int16_t ) (( target.nAngle * 6000.0f ) / 20000.0f ); //Convert Angle from 20000 to 6000
|
|
#endif
|
|
|
|
int16_t x = target.nRange * cos( a );
|
|
int16_t y = target.nRange * sin( a );
|
|
#if defined( LGS_MIRROR ) || defined( LGS_MND )
|
|
#ifdef LGS_MND
|
|
nSendCount += ((bRequestType&LGS::S2_RW_MASK)==LGS::S2_RW_ENABLE) ?
|
|
LGS::BuildEvtState2TargetDekartW( pSendBufferPtr, i, bType, x, y, target.nWidth << 2 ) :
|
|
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 ) :
|
|
LGS::BuildEvtState2TargetDekart( pSendBufferPtr, i, bType, x, y );
|
|
#endif
|
|
#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 ALS_300_BM
|
|
target.nAngle = ( int16_t ) (( target.nAngle * 6000.0f ) / 20000.0f ); //Convert Angle from 20000 to 6000
|
|
#endif
|
|
|
|
#ifdef LGS_MIRROR
|
|
#ifdef LGS_MND
|
|
nSendCount += ((bRequestType&LGS::S2_RW_MASK)==LGS::S2_RW_ENABLE) ?
|
|
LGS::BuildEvtState2TargetPolarW( pSendBufferPtr, i, bType, target.nAngle << 2, target.nRange, target.nWidth << 2 ) : // ? Wx2 ??
|
|
LGS::BuildEvtState2TargetPolar( pSendBufferPtr, i, bType, target.nAngle << 2, target.nRange );
|
|
#else
|
|
nSendCount += ((bRequestType&LGS::S2_RW_MASK)==LGS::S2_RW_ENABLE) ?
|
|
LGS::BuildEvtState2TargetPolarW( pSendBufferPtr, i, bType, target.nAngle << 1, target.nRange, target.nWidth )://<< 1 ) : // ? Wx2 ??
|
|
LGS::BuildEvtState2TargetPolar( pSendBufferPtr, i, bType, target.nAngle << 1, target.nRange );
|
|
#endif
|
|
#else // !LGS_MIRROR
|
|
#ifdef LGS_REDUCED_PRF
|
|
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 );
|
|
#else
|
|
#ifdef __ALS_300 //(target.nAngle<<2)/5
|
|
nSendCount += ((bRequestType&LGS::S2_RW_MASK)==LGS::S2_RW_ENABLE) ?
|
|
LGS::BuildEvtState2TargetPolarW( pSendBufferPtr, i, bType, target.nAngle, target.nRange/3, target.nWidth ) :
|
|
LGS::BuildEvtState2TargetPolar( pSendBufferPtr, i, bType, target.nAngle, target.nRange/3 );
|
|
#else
|
|
// ALS_300_BM
|
|
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
|
|
#endif
|
|
#endif
|
|
};
|
|
break;
|
|
case LGS::TT_FLIP:
|
|
nSendCount += LGS::BuildEvtState2Flip( pSendBufferPtr, i, target.nAngle );
|
|
break;
|
|
|
|
case LGS::TT_BLIND:
|
|
if( ( target.nAngle < LGS_BLIND_TYPE_FAR_FOG_ENTER ) && ( !g_bShowErrors || g_bHideFogError ) ) 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;
|
|
case LGS_BLIND_TYPE_FAR_FOG_ENTER:
|
|
nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_START | LGS::S2_ITB_FAR_FOG );
|
|
break;
|
|
case LGS_BLIND_TYPE_FAR_FOG_EXIT:
|
|
nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_STOP | LGS::S2_ITB_FAR_FOG );
|
|
break;
|
|
case LGS_BLIND_TYPE_NEAR_FOG_ENTER:
|
|
nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_START | LGS::S2_ITB_NEAR_FOG );
|
|
break;
|
|
case LGS_BLIND_TYPE_NEAR_FOG_EXIT:
|
|
nSendCount += LGS::BuildEvtState2Blind( pSendBufferPtr, i, LGS::S2_ITB_STOP | LGS::S2_ITB_NEAR_FOG );
|
|
break;
|
|
}
|
|
break;
|
|
// case LGS::TT_CAMERA:
|
|
// break;
|
|
// case LGS::TT_TEST:
|
|
// break;
|
|
}
|
|
|
|
if( nSendCount >= 20 )
|
|
break;
|
|
}
|
|
#ifndef LGS_PLS_1
|
|
if( nSendCount >= 20 ) break;
|
|
#endif
|
|
}
|
|
}
|
|
|
|
void CKernel::OnCmdGetWidthTable( PBYTE& pReadBufferPtr, int16_t& nReadCount, PBYTE& pSendBufferPtr, int16_t& 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( int16_t 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, int16_t& nReadCount, PBYTE& pSendBufferPtr, int16_t& 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( int16_t 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, int16_t& nReadCount, PBYTE& pSendBufferPtr, int16_t& nSendCount )
|
|
{
|
|
// unused variables
|
|
pReadBufferPtr; nReadCount;
|
|
|
|
// build CMD_GET_WIDHT_TABLE command
|
|
*pSendBufferPtr++ = LGS::CMD_GET_ZOOM_TABLE;
|
|
#ifndef NO_EMBED_CAMERA
|
|
// write command
|
|
nSendCount += LGS::BuildZoomTable( pSendBufferPtr, &m_pCamera->GetZoomTable() );
|
|
#else
|
|
nSendCount += LGS::BuildZoomTable( pSendBufferPtr, NULL );
|
|
#endif
|
|
}
|
|
|
|
void CKernel::OnCmdSetZoomTable( PBYTE& pReadBufferPtr, int16_t& nReadCount, PBYTE& pSendBufferPtr, int16_t& nSendCount )
|
|
{
|
|
// build CMD_SET_WIDHT_TABLE command
|
|
*pSendBufferPtr++ = LGS::CMD_SET_ZOOM_TABLE;
|
|
|
|
#ifndef NO_EMBED_CAMERA
|
|
// read table
|
|
nReadCount -= LGS::GetZoomTable( pReadBufferPtr, &m_pCamera->GetZoomTable() );
|
|
|
|
// write command
|
|
nSendCount += LGS::BuildZoomTable( pSendBufferPtr, &m_pCamera->GetZoomTable() );
|
|
#else
|
|
// write command
|
|
nSendCount += LGS::BuildZoomTable( pSendBufferPtr, NULL );
|
|
#endif
|
|
}
|
|
|
|
void CKernel::OnCmdGetTiltTable( PBYTE& pReadBufferPtr, int16_t& nReadCount, PBYTE& pSendBufferPtr, int16_t& nSendCount )
|
|
{
|
|
// unused variables
|
|
pReadBufferPtr; nReadCount;
|
|
|
|
// build CMD_GET_WIDHT_TABLE command
|
|
*pSendBufferPtr++ = LGS::CMD_GET_TILT_TABLE;
|
|
#ifndef NO_EMBED_CAMERA
|
|
// write command
|
|
nSendCount += LGS::BuildTiltTable( pSendBufferPtr, &m_pCamera->GetTiltTable() );
|
|
#else
|
|
nSendCount += LGS::BuildTiltTable( pSendBufferPtr, NULL );
|
|
#endif
|
|
}
|
|
|
|
void CKernel::OnCmdSetTiltTable( PBYTE& pReadBufferPtr, int16_t& nReadCount, PBYTE& pSendBufferPtr, int16_t& nSendCount )
|
|
{
|
|
// build CMD_SET_WIDHT_TABLE command
|
|
*pSendBufferPtr++ = LGS::CMD_SET_TILT_TABLE;
|
|
|
|
#ifndef NO_EMBED_CAMERA
|
|
// read table
|
|
nReadCount -= LGS::GetTiltTable( pReadBufferPtr, &m_pCamera->GetTiltTable() );
|
|
|
|
// write command
|
|
nSendCount += LGS::BuildTiltTable( pSendBufferPtr, &m_pCamera->GetTiltTable() );
|
|
#else
|
|
// write command
|
|
nSendCount += LGS::BuildTiltTable( pSendBufferPtr, NULL );
|
|
#endif
|
|
}
|
|
|
|
void CKernel::OnCmdGetCalibrationTable( PBYTE& pReadBufferPtr, int16_t& nReadCount, PBYTE& pSendBufferPtr, int16_t& nSendCount )
|
|
{
|
|
// read table
|
|
uint8_t nDevice = *pReadBufferPtr++;
|
|
nReadCount --;
|
|
|
|
// build CMD_GET_LINEARIZATION_TABLE command
|
|
*pSendBufferPtr++ = LGS::CMD_GET_CALIBRATION_TABLE;
|
|
*pSendBufferPtr++ = nDevice;
|
|
nSendCount++;
|
|
#ifndef RANGE_16BIT
|
|
// process command
|
|
m_Calibrator[nDevice?1:0].OnCmdGetCalibrationTable( pReadBufferPtr, nReadCount, pSendBufferPtr, nSendCount );
|
|
#endif // 16 bit
|
|
}
|
|
|
|
bool CKernel::OnCmdSetCalibrationTable( PBYTE& pReadBufferPtr, int16_t& nReadCount, PBYTE& pSendBufferPtr, int16_t& nSendCount, int16_t& nDevice )
|
|
{
|
|
// read table
|
|
nDevice = *pReadBufferPtr++;
|
|
nReadCount --;
|
|
|
|
// build CMD_SET_LINEARIZATION_TABLE command
|
|
*pSendBufferPtr++ = LGS::CMD_SET_CALIBRATION_TABLE;
|
|
*pSendBufferPtr++ = nDevice;
|
|
nSendCount++;
|
|
#ifndef RANGE_16BIT
|
|
// process command
|
|
return m_Calibrator[nDevice?1:0].OnCmdSetCalibrationTable( pReadBufferPtr, nReadCount, pSendBufferPtr, nSendCount );
|
|
#endif // 16 bit
|
|
}
|
|
|
|
void CKernel::OnCmdGetLrfDisable( PBYTE& pReadBufferPtr, int16_t& nReadCount, PBYTE& pSendBufferPtr, int16_t& 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, int16_t& nReadCount, PBYTE& pSendBufferPtr, int16_t& nSendCount )
|
|
{
|
|
// read table
|
|
nReadCount -= LGS::GetLRFDisable( pReadBufferPtr, &m_LRFDisable );
|
|
#ifndef NO_EMBED_CAMERA
|
|
// store serial number
|
|
SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, &m_pCamera->GetParameters(), &m_Relay.GetParameters(), &m_Voltage.GetParameters(), &m_LRFDisable );
|
|
#else
|
|
SaveSettings( (PCHAR)m_pSerialNumber, m_nAddress, NULL, &m_Relay.GetParameters(), &m_Voltage.GetParameters(), &m_LRFDisable );
|
|
#endif
|
|
// 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_BOARD_SPEED,
|
|
ST_BOARD_HID,
|
|
|
|
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,
|
|
|
|
ST_NO_BLACK_TARGET_DETECTION,
|
|
ST_JUST_MOVING_TARGETS_DETECTION,
|
|
ST_JUST_MOVING_RADIAL_PARAM,
|
|
ST_JUST_MOVING_DISTANCE_PARAM,
|
|
ST_BLIND_ST_ANGLE,
|
|
ST_BLIND_ED_ANGLE,
|
|
ST_BLIND_ST_RANGE,
|
|
ST_BLIND_ED_RANGE,
|
|
ST_BLIND_WIDTH,
|
|
ST_BLIND_DEPTH,
|
|
ST_BLIND_ANGLE,
|
|
ST_BLIND_RANGE
|
|
#ifdef STORE_FIRST_SAF
|
|
,ST_FREEZ_FIRST_SAF
|
|
,ST_SAF_FILE_ENABLE
|
|
#endif
|
|
}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" },
|
|
{ "BOARD_SPEED" },
|
|
{ "RUN_DIR" },
|
|
|
|
{ "SWITCHER_TABLE" },
|
|
{ "SWITCHER_REPLY_TIMEOUT" },
|
|
{ "SWITCHER_COMMAND_TIMEOUT" },
|
|
{ "SWITCHER_AUTO_MODE" },
|
|
{ "SWITCHER_AUTO_ENTER_TIMEOUT" },
|
|
{ "SWITCHER_AUTO_SWITCH_TIMEOUT" },
|
|
|
|
{ "NO_BLACK_TARGETS" },
|
|
{ "JUST_MOVING_TARGETS" },
|
|
{ "JUST_MOVING_RADIAL" },
|
|
{ "JUST_MOVING_DISTANCE" },
|
|
|
|
{ "BLIND_ZONE_START_ANGLE" },
|
|
{ "BLIND_ZONE_END_ANGLE" },
|
|
{ "BLIND_ZONE_START_RANGE" },
|
|
{ "BLIND_ZONE_END_RANGE" },
|
|
{ "BLIND_ZONE_WIDTH" },
|
|
{ "BLIND_ZONE_DEPTH" },
|
|
{ "BLIND_ZONE_ANGLE" },
|
|
{ "BLIND_ZONE_RANGE" }
|
|
#ifdef STORE_FIRST_SAF
|
|
,{ "FREEZ_FIRST_TH" }
|
|
,( "SAVE_FIRST_TH" )
|
|
#endif
|
|
};
|
|
|
|
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( int16_t 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;
|
|
#ifndef NO_EMBED_CAMERA
|
|
case ST_CAMERA_TYPE: pCameraParameters->eType = (LGS::E_CAMERA_TYPE)atoi( pTemp ); break;
|
|
case ST_CAMERA_SHIFT: pCameraParameters->nShift = (uint16_t)atoi( pTemp ); break;
|
|
case ST_CAMERA_AUTO: pCameraParameters->bAuto = (bool)atoi( pTemp ); break;
|
|
case ST_CAMERA_DELAY: pCameraParameters->nAutoDelay = (uint16_t)atoi( pTemp ); break;
|
|
#endif
|
|
case ST_RELAY_NC: pRelayParameters->bNormallyClose = (uint16_t)atoi( pTemp ); break;
|
|
case ST_RELAY_AUTO: pRelayParameters->bAuto = (bool)atoi( pTemp ); break;
|
|
case ST_RELAY_DELAY: pRelayParameters->nAutoDelay = (uint16_t)atoi( pTemp ); break;
|
|
case ST_VOLTAGE_CONTROL: pVoltageParameters->bControl = (bool)atoi( pTemp ); break;
|
|
case ST_MASTER_DISABLED: if( pLRFDisable ) pLRFDisable->bMaster = (bool)atoi( pTemp ); break;
|
|
#ifndef LGS_PLS_1
|
|
case ST_SLAVE_DISABLED: if( pLRFDisable ) pLRFDisable->bSlave = (bool)atoi( pTemp ); break;
|
|
#else
|
|
#ifdef INFINITE_SAF_STUDY
|
|
case ST_SLAVE_DISABLED: if( pLRFDisable ) pLRFDisable->bSlave = (bool)atoi( pTemp ); break;
|
|
#else
|
|
case ST_SLAVE_DISABLED: if( pLRFDisable ) pLRFDisable->bSlave = true; break;
|
|
#endif
|
|
#endif
|
|
case ST_NO_BLACK_TARGET_DETECTION: g_bNoBlackTargets = (bool)atoi( pTemp ); break;
|
|
case ST_JUST_MOVING_TARGETS_DETECTION: m_nMovingRadialFilter = (uint8_t)atoi( pTemp ); m_nMovingDistanceFilter=m_nMovingRadialFilter; break;
|
|
case ST_JUST_MOVING_RADIAL_PARAM: m_nMovingRadialFilter = (uint8_t)atoi( pTemp ); break;
|
|
case ST_JUST_MOVING_DISTANCE_PARAM: m_nMovingDistanceFilter = (uint8_t)atoi( pTemp ); break;
|
|
case ST_BLIND_ST_ANGLE:m_nBZSAngleFilter = atoi( pTemp ); break;
|
|
case ST_BLIND_ED_ANGLE:m_nBZEAngleFilter = atoi( pTemp ); break;
|
|
case ST_BLIND_ST_RANGE:m_nBZSRangeFilter = atoi( pTemp ); break;
|
|
case ST_BLIND_ED_RANGE:m_nBZERangeFilter = atoi( pTemp ); break;
|
|
#ifdef STORE_FIRST_SAF
|
|
case ST_FREEZ_FIRST_SAF:g_bSAFFreezEnable = atoi( pTemp ); break;
|
|
case ST_SAF_FILE_ENABLE:g_bSAFFileEnable = atoi( pTemp ); break;
|
|
#endif
|
|
}
|
|
}
|
|
fclose( pFile );
|
|
return true;
|
|
}
|
|
|
|
bool CKernel::SaveSettings( LPCTSTR pSerialNumber, int16_t 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 );
|
|
if( pCameraParameters ) {
|
|
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 );
|
|
if( pLRFDisable ) fprintf( pFile, pFormatInt, m_pSetting[ST_MASTER_DISABLED], pLRFDisable->bMaster );
|
|
#ifndef LFS_PLS_1
|
|
if( pLRFDisable ) fprintf( pFile, pFormatInt, m_pSetting[ST_SLAVE_DISABLED], pLRFDisable->bSlave );
|
|
#else
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_SLAVE_DISABLED], true );
|
|
#endif
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_NO_BLACK_TARGET_DETECTION], g_bNoBlackTargets );
|
|
if( m_nMovingRadialFilter == m_nMovingDistanceFilter ){
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_JUST_MOVING_TARGETS_DETECTION], m_nMovingDistanceFilter );
|
|
} else {
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_JUST_MOVING_RADIAL_PARAM], m_nMovingRadialFilter );
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_JUST_MOVING_DISTANCE_PARAM], m_nMovingDistanceFilter );
|
|
};
|
|
#ifdef STORE_FIRST_SAF
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_FREEZ_FIRST_SAF], g_bSAFFreezEnable );
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_SAF_FILE_ENABLE], g_bSAFFileEnable );
|
|
#endif
|
|
fclose( pFile );
|
|
|
|
return true;
|
|
}
|
|
|
|
bool CKernel::LoadUserSettings( ARESET_SETTINGS *pAutoReset, BOARD_SETTINGS *pBoard, SWITCHER_SETTINGS *pSwitcher, CComm485 *pCommPort, CComm485 *pCameraComm ){
|
|
|
|
int16_t tWidth = 0;
|
|
int16_t tDepth = 0;
|
|
int16_t tAngle = 0;
|
|
int16_t tRange = 0;
|
|
|
|
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 = 1;
|
|
pBoard->nEncoderSteps = 6;
|
|
pBoard->nGearRatio = 61;
|
|
|
|
#if defined( LGS_PLS_1 ) || defined( LGS_STEPPER ) || defined( LGS_MND )
|
|
// Stepping Motor Speed
|
|
// 4280 = 8sps
|
|
// 2140 = 4sps
|
|
// 1070 = 2sps
|
|
// 535 = 1sps
|
|
pBoard->nMotorSpeed = 4;//535;
|
|
#endif
|
|
// pBoard->nMaxRange = 2048;
|
|
m_nMovingRadialFilter = 0;
|
|
m_nMovingDistanceFilter = 0;
|
|
m_nBZSAngleFilter = 0;
|
|
m_nBZEAngleFilter = 0;
|
|
m_nBZSRangeFilter = 0;
|
|
m_nBZERangeFilter = 0;
|
|
// read serial number
|
|
#ifdef LGS_MIRROR
|
|
#if defined( LGS_STEPPER ) || defined( LGS_FOD )
|
|
#ifdef LGS_FOD
|
|
FILE *pFile = fopen( "FOD.INI", "rt" ); // FOD
|
|
#else
|
|
FILE *pFile = fopen( "LFSS.INI", "rt" ); // LFSS
|
|
#endif
|
|
#else
|
|
#ifdef LGS_MND
|
|
FILE *pFile = fopen( "MND.INI", "rt" ); // MND
|
|
#else
|
|
FILE *pFile = fopen( "USER.INI", "rt" ); // LFS
|
|
#endif
|
|
#endif
|
|
#else
|
|
#ifdef LGS_PLS_1
|
|
FILE *pFile = fopen( "PLS.INI", "rt" ); // PLS
|
|
#else
|
|
FILE *pFile = fopen( "USER.INI", "rt" ); // ALS
|
|
#endif
|
|
#endif
|
|
if( !pFile )
|
|
return false;
|
|
|
|
CHAR pLine[MAX_PATH];
|
|
while( fgets( pLine, MAX_PATH, pFile ) )
|
|
{
|
|
SETTING_TYPE eType = ST_NONE;
|
|
PCHAR pTemp = NULL;
|
|
//printf( "%s", pLine );
|
|
for( int16_t 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;
|
|
#if defined( LGS_PLS_1 ) || defined( LGS_STEPPER ) || defined( LGS_MND )
|
|
case ST_BOARD_SPEED: pBoard->nMotorSpeed = atoi( pTemp ); break;
|
|
#endif
|
|
// case ST_BOARD_MAXRANGE: pBoard->nMaxRange = atoi( pTemp ); break;
|
|
case ST_NO_BLACK_TARGET_DETECTION: g_bNoBlackTargets = (bool)atoi( pTemp ); break;
|
|
#ifdef STORE_FIRST_SAF
|
|
case ST_FREEZ_FIRST_SAF:g_bSAFFreezEnable = atoi( pTemp ); break;
|
|
case ST_SAF_FILE_ENABLE:g_bSAFFileEnable = atoi( pTemp ); break;
|
|
#endif
|
|
case ST_JUST_MOVING_TARGETS_DETECTION: m_nMovingRadialFilter = (uint8_t)atoi( pTemp ); m_nMovingDistanceFilter=m_nMovingRadialFilter; break;
|
|
case ST_JUST_MOVING_RADIAL_PARAM: m_nMovingRadialFilter = (uint8_t)atoi( pTemp ); break;
|
|
case ST_JUST_MOVING_DISTANCE_PARAM: m_nMovingDistanceFilter = (uint8_t)atoi( pTemp ); break;
|
|
case ST_BLIND_ST_ANGLE:m_nBZSAngleFilter = atoi( pTemp ); break;
|
|
case ST_BLIND_ED_ANGLE:m_nBZEAngleFilter = atoi( pTemp ); break;
|
|
case ST_BLIND_ST_RANGE:m_nBZSRangeFilter = atoi( pTemp ); break;
|
|
case ST_BLIND_ED_RANGE:m_nBZERangeFilter = atoi( pTemp ); break;
|
|
case ST_BLIND_WIDTH:tWidth = atoi( pTemp ); break;
|
|
case ST_BLIND_DEPTH:tDepth = atoi( pTemp ); break;
|
|
case ST_BLIND_ANGLE:tAngle = atoi( pTemp ); break;
|
|
case ST_BLIND_RANGE:tRange = atoi( pTemp ); break;
|
|
#ifdef LGS_MIRROR
|
|
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;
|
|
#endif
|
|
}
|
|
}
|
|
#if defined( LGS_REDUCED_PRF )
|
|
if( pBoard->nMotorSpeed < 1 ) pBoard->nMotorSpeed = 1;
|
|
if( pBoard->nMotorSpeed == 3 ) pBoard->nMotorSpeed = 2;
|
|
#if defined( LGS_STEPPER ) || defined( LGS_MND )
|
|
if( pBoard->nMotorSpeed > 4 ) pBoard->nMotorSpeed = 4;
|
|
#else
|
|
if( pBoard->nMotorSpeed == 5 ) pBoard->nMotorSpeed = 4;
|
|
if( pBoard->nMotorSpeed == 7 ) pBoard->nMotorSpeed = 6;
|
|
if( pBoard->nMotorSpeed == 9 ) pBoard->nMotorSpeed = 8;
|
|
if( pBoard->nMotorSpeed == 10 ) pBoard->nMotorSpeed = 8;
|
|
if( pBoard->nMotorSpeed == 11 ) pBoard->nMotorSpeed = 12;
|
|
if( pBoard->nMotorSpeed > 12 ) pBoard->nMotorSpeed = 12;
|
|
#endif
|
|
#if defined( LGS_MND )
|
|
LGS_PRF_REDUCE_RATIO = 1;
|
|
#else
|
|
if( pBoard->nMotorSpeed > 2 ){
|
|
LGS_PRF_REDUCE_RATIO = pBoard->nMotorSpeed >> 1;
|
|
} else {
|
|
LGS_PRF_REDUCE_RATIO = 1;
|
|
};
|
|
#endif
|
|
#endif
|
|
if( tWidth && tDepth ){
|
|
m_nBZSAngleFilter = tAngle - tWidth/2;
|
|
m_nBZEAngleFilter = ( tAngle + tWidth/2 ) % LGS_MAX_DETECTOR_ANGLES;
|
|
m_nBZSRangeFilter = tRange - tDepth/2;
|
|
m_nBZERangeFilter = tRange + tDepth/2;
|
|
};
|
|
fclose( pFile );
|
|
return true;
|
|
};
|
|
|
|
bool CKernel::SaveUserSettings( ARESET_SETTINGS *pAutoReset, BOARD_SETTINGS *pBoard, SWITCHER_SETTINGS *pSwitcher, CComm485 *pCommPort, CComm485 *pCameraComm ){
|
|
|
|
#ifdef LGS_MIRROR
|
|
#if defined( LGS_STEPPER ) || defined( LGS_FOD )
|
|
#ifdef LGS_FOD
|
|
FILE *pFile = fopen( "FOD.INI", "wt" ); // FOD
|
|
#else
|
|
FILE *pFile = fopen( "LFSS.INI", "wt" ); // LFSS
|
|
#endif
|
|
#else
|
|
#ifdef LGS_MND
|
|
FILE *pFile = fopen( "MND.INI", "wt" ); // MND
|
|
#else
|
|
FILE *pFile = fopen( "USER.INI", "wt" ); // LFS
|
|
#endif
|
|
#endif
|
|
#else
|
|
#ifdef LGS_PLS_1
|
|
FILE *pFile = fopen( "PLS.INI", "wt" ); // PLS
|
|
#else
|
|
FILE *pFile = fopen( "USER.INI", "wt" ); // ALS
|
|
#endif
|
|
#endif
|
|
|
|
if( !pFile )
|
|
return false;
|
|
|
|
LPCTSTR pFormatInt = "%s=%d\n";
|
|
LPCTSTR pFormatDWORD = "%s=%lu\n";
|
|
LPCTSTR pFormatArr = "%s=%d,%d,%d\n";
|
|
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_AUTORESET_ENABLE], (int16_t)pAutoReset->bEnabled );
|
|
fprintf( pFile, pFormatDWORD, m_pSetting[ST_AUTORESET_INTERLEAVE], pAutoReset->dwInterleave );
|
|
fprintf( pFile, pFormatDWORD, m_pSetting[ST_AUTORESET_TIMEOUT], pAutoReset->dwTimeout );
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_TEMPERATURE], (int16_t)(CHAR)pBoard->nTemperature );
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_ZEROSHIFT], (int16_t)pBoard->nZeroShift );
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_ENCODERSTEPS], (int16_t)pBoard->nEncoderSteps );
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_GEARRATIO], (int16_t)pBoard->nGearRatio );
|
|
#if defined( LGS_PLS_1 ) || defined( LGS_STEPPER ) || defined( LGS_MND )
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_SPEED], (int16_t)pBoard->nMotorSpeed );
|
|
#endif
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_NO_BLACK_TARGET_DETECTION], g_bNoBlackTargets );
|
|
if( m_nMovingRadialFilter == m_nMovingDistanceFilter ){
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_JUST_MOVING_TARGETS_DETECTION], m_nMovingDistanceFilter );
|
|
} else {
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_JUST_MOVING_RADIAL_PARAM], m_nMovingRadialFilter );
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_JUST_MOVING_DISTANCE_PARAM], m_nMovingDistanceFilter );
|
|
};
|
|
if( m_nBZSAngleFilter != m_nBZEAngleFilter ){
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_BLIND_ST_ANGLE], m_nBZSAngleFilter );
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_BLIND_ED_ANGLE], m_nBZEAngleFilter );
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_BLIND_ST_RANGE], m_nBZSRangeFilter );
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_BLIND_ED_RANGE], m_nBZERangeFilter );
|
|
};
|
|
#ifdef LGS_MIRROR
|
|
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 );
|
|
#endif
|
|
#ifdef STORE_FIRST_SAF
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_FREEZ_FIRST_SAF], g_bSAFFreezEnable );
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_SAF_FILE_ENABLE], g_bSAFFileEnable );
|
|
#endif
|
|
fclose( pFile );
|
|
|
|
return true;
|
|
}
|
|
|
|
bool CKernel::LoadFSSettings( ARESET_SETTINGS *pAutoReset, BOARD_SETTINGS *pBoard, SWITCHER_SETTINGS *pSwitcher, CComm485 *pCommPort, CComm485 *pCameraComm ){
|
|
// read serial number
|
|
FILE *pFile = fopen( "PARAMS.INI", "rt" );
|
|
if( !pFile ) return false;
|
|
//printf("PARAMS.ini found reading params\n");
|
|
CHAR pLine[MAX_PATH];
|
|
while( fgets( pLine, MAX_PATH, pFile ) ){
|
|
SETTING_TYPE eType = ST_NONE;
|
|
PCHAR pTemp = NULL;
|
|
for( int16_t 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_BOARD_HID: pBoard->nHID = atoi( pTemp ); break;
|
|
}
|
|
}
|
|
fclose( pFile );
|
|
return true;
|
|
};
|
|
|
|
bool CKernel::SaveFSSettings( ARESET_SETTINGS *pAutoReset, BOARD_SETTINGS *pBoard, SWITCHER_SETTINGS *pSwitcher, CComm485 *pCommPort, CComm485 *pCameraComm ){
|
|
FILE *pFile = fopen( "PARAMS.INI", "wt" );
|
|
if( !pFile )
|
|
return false;
|
|
|
|
LPCTSTR pFormatInt = "%s=%d\n";
|
|
LPCTSTR pFormatArr = "%s=%d,%d,%d\n";
|
|
LPCTSTR pFormatDWORD = "%s=%lu\n";
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_AUTORESET_ENABLE], (int16_t)pAutoReset->bEnabled );
|
|
fprintf( pFile, pFormatDWORD, m_pSetting[ST_AUTORESET_INTERLEAVE], pAutoReset->dwInterleave );
|
|
fprintf( pFile, pFormatDWORD, m_pSetting[ST_AUTORESET_TIMEOUT], pAutoReset->dwTimeout );
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_TEMPERATURE], (int16_t)(CHAR)pBoard->nTemperature );
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_ZEROSHIFT], (int16_t)pBoard->nZeroShift );
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_ENCODERSTEPS], (int16_t)pBoard->nEncoderSteps );
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_GEARRATIO], (int16_t)pBoard->nGearRatio );
|
|
#ifdef LGS_PLS_1
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_SPEED], (int16_t)pBoard->nMotorSpeed );
|
|
#endif
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_BOARD_HID], (int16_t)pBoard->nHID );
|
|
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 );
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_NO_BLACK_TARGET_DETECTION], g_bNoBlackTargets );
|
|
#ifdef STORE_FIRST_SAF
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_FREEZ_FIRST_SAF], g_bSAFFreezEnable );
|
|
fprintf( pFile, pFormatInt, m_pSetting[ST_SAF_FILE_ENABLE], g_bSAFFileEnable );
|
|
#endif
|
|
fclose( pFile );
|
|
|
|
return true;
|
|
}
|