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.
400 lines
8.2 KiB
400 lines
8.2 KiB
//----------------------------------------------------------------------------
|
|
// Laser Guard Ltd.
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
// Version 1.0 01/01/2000
|
|
// Last modification: 08/10/2003
|
|
// PROJECT:
|
|
// SUBSYSTEM:
|
|
// FILE: kernel_.cpp
|
|
// AUTHOR: Sergey Chizhevskiy
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Source file of kernel_.cpp
|
|
//----------------------------------------------------------------------------
|
|
#include "stdafx.h"
|
|
#include "..\LgLib\Version.h"
|
|
#include "Kernel.h"
|
|
|
|
CKernel::CKernel()
|
|
{
|
|
m_pBoard = NULL;
|
|
m_pShadow = NULL;
|
|
m_pCamera = NULL;
|
|
#ifdef COMM_WITHOUT_INTERRUPTS
|
|
m_pCameraComm = NULL;
|
|
#endif
|
|
m_bRun = TRUE;
|
|
m_nSerialNumber = 0;
|
|
memset( m_pSerialNumber, 0, sizeof(m_pSerialNumber) );
|
|
m_nAddress = 0;
|
|
// init error timing
|
|
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;
|
|
m_LRFDisable.bMaster = m_LRFDisable.bSlave = FALSE;
|
|
#ifndef LGS_DISABLE_FILE_SYSTEM
|
|
// file system
|
|
memset( &m_FileSystemPacket, 0, sizeof(m_FileSystemPacket) );
|
|
#endif
|
|
// prepare software version
|
|
#ifdef LGS_MIRROR
|
|
s_nSoftwareVersion = sprintf( s_pSoftwareVersion, "%s %dM,%s", CLgVersion::GetBuildTimeStr(), LGS_MIRROR,
|
|
#else
|
|
s_nSoftwareVersion = sprintf( s_pSoftwareVersion, "%s %s", CLgVersion::GetBuildTimeStr(),
|
|
#endif
|
|
#ifdef BOARD_A2D_FOUR_SAMPLES
|
|
"4"
|
|
#else
|
|
"1"
|
|
#endif
|
|
#ifdef COMPILE_AS_ANGLES
|
|
",AN"
|
|
#endif
|
|
#ifdef COMPILE_AS_GETFILE
|
|
",GF"
|
|
#endif
|
|
#ifdef DEBUG_BOARD_SET_TEST_BIT
|
|
",B"
|
|
#endif
|
|
#ifdef DEBUG_ENABLE_OLD_BOARD
|
|
",O"
|
|
#endif
|
|
#ifdef DEBUG_ENABLE_SEND_BOARDDATA
|
|
",S"
|
|
#endif
|
|
#ifdef COMM_RS485_PREVENT_ECHO
|
|
",E,ASDFGHJJ,"
|
|
#endif
|
|
#ifdef COMM_WITHOUT_INTERRUPTS
|
|
",I"
|
|
#endif
|
|
#ifdef BOARD_DEFFERED_PROCESSING
|
|
",D"
|
|
#endif
|
|
#ifdef BOARD_SUN_BIT_DISABLE
|
|
",S"
|
|
#endif
|
|
#ifdef LGS_PROTOCOL_TRANSMIT_DELAY
|
|
",T"
|
|
#endif
|
|
#ifdef BOARD_LINEARIZATION_ENABLE
|
|
",L"
|
|
#endif
|
|
#ifdef WATCHDOG_ENABLED
|
|
",W"
|
|
#endif
|
|
#ifdef BOARD_POWER_ENABLE
|
|
",P"
|
|
#endif
|
|
#ifndef EMBEDDED_CAMERA_DISABLED
|
|
",C"
|
|
#endif
|
|
#ifdef EMBEDDED_CAMERA_MIGVAN
|
|
"O"
|
|
#endif
|
|
#ifdef EMBEDDED_CAMERA_MIC
|
|
"M"
|
|
#endif
|
|
#ifdef EMBEDDED_CAMERA_JVC
|
|
"J"
|
|
#endif
|
|
#ifdef EMBEDDED_CAMERA_PHILIPS
|
|
"B"
|
|
#endif
|
|
#ifdef EMBEDDED_CAMERA_VICON
|
|
"V"
|
|
#endif
|
|
#ifdef EMBEDDED_CAMERA_PELCO
|
|
"P"
|
|
#endif
|
|
#ifdef EMBEDDED_CAMERA_HEBRON
|
|
"H"
|
|
#endif
|
|
#ifdef EMBEDDED_CAMERA_AMERICAN_DYNAMICS
|
|
"A"
|
|
#endif
|
|
);
|
|
}
|
|
|
|
CKernel::~CKernel()
|
|
{
|
|
Destroy();
|
|
}
|
|
|
|
BOOL CKernel::Create( CBoard *pBoard, CComm485 *pCommPort, CShadow *pShadow, CComm485 *pCameraComm, CComm485::PORTS nCameraPort )
|
|
{
|
|
Destroy();
|
|
|
|
m_pShadow = pShadow;
|
|
m_pBoard = pBoard;
|
|
m_pComm485 = pCommPort;
|
|
|
|
// create transport protocol
|
|
if( !m_Protocol.Create( pCommPort ) )
|
|
return FALSE;
|
|
|
|
// printf( "protocol created...\n" );
|
|
|
|
// assume that no camera
|
|
LGS::CAMERA_PARAMETERS cp;
|
|
cp.eType = LGS::CAMERA_TYPE_NONE;
|
|
cp.nShift = 0;
|
|
cp.bAuto = FALSE;
|
|
cp.nAutoDelay = 0;
|
|
|
|
// assume that no relay
|
|
LGS::RELAY_PARAMETERS rp;
|
|
rp.bAuto = FALSE;
|
|
rp.nAutoDelay = 0;
|
|
rp.bNormallyClose = FALSE;
|
|
|
|
// no voltage control by default
|
|
LGS::VOLTAGE_PARAMETERS vp;
|
|
vp.bControl = FALSE;
|
|
|
|
// both lasers enabled
|
|
m_LRFDisable.bMaster = FALSE;
|
|
m_LRFDisable.bSlave = FALSE;
|
|
|
|
// load settings
|
|
LoadSettings( (PCHAR)m_pSerialNumber, &m_nSerialNumber, &m_nAddress, &cp, &rp, &vp, &m_LRFDisable );
|
|
|
|
// load user settings
|
|
AUTO_RESET AutoReset;
|
|
BOARD_SETTINGS BoardSettings;
|
|
SWITCHER_SETTINGS SwitcherSettings;
|
|
LoadUserSettings( &AutoReset, &BoardSettings, &SwitcherSettings );
|
|
|
|
// printf( "settings loaded...\n" );
|
|
|
|
m_pCamera = new CCamera;
|
|
|
|
// printf( "camera allocated...\n" );
|
|
|
|
#ifdef COMM_WITHOUT_INTERRUPTS
|
|
m_pCameraComm = pCameraComm;
|
|
#endif
|
|
if( !m_pCamera || !m_pCamera->Create( (LGS::E_CAMERA_TYPE)cp.eType, pCameraComm, nCameraPort, &cp, &SwitcherSettings ) )
|
|
{
|
|
printf( "Can't create camera\n" );
|
|
return FALSE;
|
|
}
|
|
|
|
// printf( "camera created...\nType: %d\n", cp.eType );
|
|
|
|
if( !m_Relay.Create( m_pBoard, &rp ) )
|
|
{
|
|
printf( "Can't create relay\n" );
|
|
return FALSE;
|
|
}
|
|
|
|
// printf( "relay created...\n" );
|
|
|
|
if( !m_Voltage.Create( &vp ) )
|
|
{
|
|
printf( "Can't create voltage control\n" );
|
|
return FALSE;
|
|
}
|
|
// printf( "voltage created...\n" );
|
|
|
|
|
|
|
|
if( !m_Tracker[0].Create( m_LRFDisable.bMaster, m_pCamera, &m_Relay, &m_AutoReset ) )
|
|
return FALSE;
|
|
|
|
// printf( "tracker 1 created...\n" );
|
|
|
|
if( !m_Tracker[1].Create( m_LRFDisable.bSlave, m_pCamera, &m_Relay, &m_AutoReset ) )
|
|
return FALSE;
|
|
|
|
// printf( "tracker 2 created...\n" );
|
|
|
|
|
|
|
|
#ifdef DEBUG_GRAPH_SCREEN_SST
|
|
|
|
m_Tracker[0].SetIndex(0);
|
|
m_Tracker[1].SetIndex(1);
|
|
|
|
#endif
|
|
|
|
|
|
if( !m_Detector[0].Create( m_LRFDisable.bMaster, &m_Tracker[0], pShadow, 0, "init_m.ini" ) )
|
|
return FALSE;
|
|
|
|
// printf( "detector 1 created...\n" );
|
|
|
|
#ifdef LGS_MIRROR
|
|
|
|
if( !m_Detector[1].Create( m_LRFDisable.bSlave, &m_Tracker[0], pShadow, 0, "init_s.ini" ) )
|
|
return FALSE;
|
|
// printf( "detector 2 created...\n" );
|
|
if( !m_Detector[2].Create( m_LRFDisable.bSlave, &m_Tracker[0], pShadow, 0, "init_s.ini" ) )
|
|
return FALSE;
|
|
// printf( "detector 3 created...\n" );
|
|
if( !m_Detector[3].Create( m_LRFDisable.bSlave, &m_Tracker[0], pShadow, 0, "init_s.ini" ) )
|
|
return FALSE;
|
|
// printf( "detector 4 created...\n" );
|
|
|
|
#else
|
|
|
|
if( !m_Detector[1].Create( m_LRFDisable.bSlave, &m_Tracker[1], pShadow, LGS_MAX_DETECTOR_ANGLES / 2, "init_s.ini" ) )
|
|
return FALSE;
|
|
// printf( "detector 2 created...\n" );
|
|
|
|
#endif
|
|
|
|
|
|
if( !m_GetFile.Create() )
|
|
return FALSE;
|
|
|
|
// printf( "get file created...\n" );
|
|
|
|
if( !m_Calibrator[0].Create( "lt0.ini" ) )
|
|
{
|
|
printf( "Can't create linearization filter for master\n" ) ;
|
|
return FALSE;
|
|
}
|
|
|
|
// printf( "calibration 1 created...\n" );
|
|
|
|
if( !m_Calibrator[1].Create( "lt1.ini" ) )
|
|
{
|
|
printf( "Can't create linearization filter for slave\n" ) ;
|
|
return FALSE;
|
|
}
|
|
|
|
// printf( "calibration 2 created...\n" );
|
|
|
|
m_pBoard->Reset();
|
|
/*
|
|
// prepare software version
|
|
#ifdef LGS_MIRROR
|
|
s_nSoftwareVersion = sprintf( s_pSoftwareVersion, "%s %dM,%s,%d", CLgVersion::GetBuildTimeStr(), LGS_MIRROR,
|
|
#else
|
|
s_nSoftwareVersion = sprintf( s_pSoftwareVersion, "%s %s,%d ", CLgVersion::GetBuildTimeStr(),
|
|
#endif
|
|
#ifdef BOARD_A2D_FOUR_SAMPLES
|
|
"4"
|
|
#else
|
|
"1"
|
|
#endif
|
|
#ifdef COMPILE_AS_ANGLES
|
|
",AN"
|
|
#endif
|
|
#ifdef COMPILE_AS_GETFILE
|
|
",GF"
|
|
#endif
|
|
#ifdef DEBUG_BOARD_SET_TEST_BIT
|
|
",B"
|
|
#endif
|
|
#ifdef DEBUG_ENABLE_OLD_BOARD
|
|
",O"
|
|
#endif
|
|
#ifdef DEBUG_ENABLE_SEND_BOARDDATA
|
|
",S"
|
|
#endif
|
|
#ifdef COMM_RS485_PREVENT_ECHO
|
|
",E"
|
|
#endif
|
|
#ifdef COMM_WITHOUT_INTERRUPTS
|
|
",I"
|
|
#endif
|
|
#ifdef BOARD_DEFFERED_PROCESSING
|
|
",D"
|
|
#endif
|
|
#ifdef BOARD_SUN_BIT_DISABLE
|
|
",S"
|
|
#endif
|
|
#ifdef LGS_PROTOCOL_TRANSMIT_DELAY
|
|
",T"
|
|
#endif
|
|
#ifdef BOARD_LINEARIZATION_ENABLE
|
|
",L"
|
|
#endif
|
|
#ifdef WATCHDOG_ENABLED
|
|
",W"
|
|
#endif
|
|
#ifdef BOARD_POWER_ENABLE
|
|
",P"
|
|
#endif
|
|
#ifndef EMBEDDED_CAMERA_DISABLED
|
|
",C"
|
|
#endif
|
|
#ifdef EMBEDDED_CAMERA_MIGVAN
|
|
"O"
|
|
#endif
|
|
#ifdef EMBEDDED_CAMERA_MIC
|
|
"M"
|
|
#endif
|
|
#ifdef EMBEDDED_CAMERA_JVC
|
|
"J"
|
|
#endif
|
|
#ifdef EMBEDDED_CAMERA_PHILIPS
|
|
"B"
|
|
#endif
|
|
#ifdef EMBEDDED_CAMERA_VICON
|
|
"V"
|
|
#endif
|
|
#ifdef EMBEDDED_CAMERA_PELCO
|
|
"P"
|
|
#endif
|
|
#ifdef EMBEDDED_CAMERA_HEBRON
|
|
"H"
|
|
#endif
|
|
#ifdef EMBEDDED_CAMERA_AMERICAN_DYNAMICS
|
|
"A"
|
|
#endif
|
|
, m_pBoard->GetBSN());
|
|
*/
|
|
|
|
#ifdef WATCHDOG_ENABLED
|
|
// start watchdog
|
|
if( !m_WatchDog.Create() )
|
|
{
|
|
printf( "Can't create watchdog\n" ) ;
|
|
return FALSE;
|
|
}
|
|
|
|
// printf( "watchdog created...\n" );
|
|
|
|
#endif
|
|
|
|
#ifdef LGS_MIRROR
|
|
m_bWaitFirstZero = TRUE;
|
|
#endif
|
|
|
|
m_AutoReset.Create( &AutoReset );
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CKernel::Destroy()
|
|
{
|
|
if( m_pCamera )
|
|
{
|
|
delete m_pCamera;
|
|
m_pCamera = NULL;
|
|
}
|
|
#ifdef COMM_WITHOUT_INTERRUPTS
|
|
m_pCameraComm = NULL;
|
|
#endif
|
|
m_GetFile.Destroy();
|
|
m_Protocol.Destroy();
|
|
m_Detector[0].Destroy();
|
|
m_Detector[1].Destroy();
|
|
m_Tracker[0].Destroy();
|
|
m_Tracker[1].Destroy();
|
|
m_Voltage.Destroy();
|
|
m_Relay.Destroy();
|
|
m_Calibrator[0].Destroy();
|
|
m_Calibrator[1].Destroy();
|
|
m_AutoReset.Destroy();
|
|
m_pBoard = NULL;
|
|
m_pShadow = NULL;
|
|
m_bRun = TRUE;
|
|
}
|
|
|