|
|
//----------------------------------------------------------------------------
// Dr.Frucht Systems Ltd.
// Copyright � 2000-2017. All Rights Reserved.
// Version 2.0 7/20/2017
// Last modification: 7/20/2017
// PROJECT:
// SUBSYSTEM:
// FILE: LRF_HardwareManager.cpp
// AUTHOR: gagua
// OVERVIEW
// ~~~~~~~~
// Header file of LRF_HardwareManager.cpp
//----------------------------------------------------------------------------
//
#include "LRF_HardwareManager.h"
#define LOG( X ) m_pLog->Log( "HW Manager", this, X )
#define LOG_ERROR( X ) m_pLog->Log( "HW Manager", this, _LOG_ERROR, X )
// Constructor implementation
LRF_HardwareManager::LRF_HardwareManager( config_setting_t *SNode ){ m_pLog = basicLogCollection::getInstance(); m_pSettingsProvider = basicSettingsProvider::getInstance(); if( m_pSettingsProvider ) { m_pSettings = m_pSettingsProvider->getSubNode( SNode, "HARDWARE_MANAGER" ); if( m_pSettingsProvider->isCompromised() ) { m_pSettingsProvider->validate(); }; } else { m_pSettings = NULL; }; m_bInitOK = false; m_bDumpMemoryToDisk = false; m_nFlipEnaFLags = 0; m_nDetectionFilter = 0; m_eSOC = SOC_UNKNOWN;
#ifdef THREADED_FLIP
m_pFlipThreadHandler = NULL; m_bWaitFirstFlip = true; m_bFlipUnlockRequested = false; m_pFlipMutex = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t)); if( m_pFlipMutex != NULL ) { memset( m_pFlipMutex, 0, sizeof(pthread_mutex_t)); pthread_mutexattr_t attrib; pthread_mutexattr_settype( &attrib, PTHREAD_MUTEX_ERRORCHECK ); if( 0 != pthread_mutex_init( m_pFlipMutex, &attrib ) ){ free( m_pFlipMutex ); m_pFlipMutex = NULL; LOG_ERROR("Cannot Create Flip Protector Mutex!"); } else { m_pFlipThreadHandler = (pthread_t *) malloc(sizeof(pthread_t)); if( m_pFlipThreadHandler != NULL ) { memset( m_pFlipThreadHandler, 0, sizeof(pthread_t)); } else { pthread_mutex_destroy(m_pFlipMutex); free(m_pFlipMutex); m_pFlipMutex = NULL; LOG_ERROR("Cannot Allocate Flip Thread!"); }; }; } else { LOG_ERROR("Cannot Allocate Flip Protector Mutex!"); };#endif
#ifdef THREADED_MOTORS_START
m_pMotorCtrlThreadHandler = NULL; m_pMotorCtrlMutex = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t)); if( m_pMotorCtrlMutex != NULL ) { memset( m_pMotorCtrlMutex, 0, sizeof(pthread_mutex_t)); pthread_mutexattr_t attrib; pthread_mutexattr_settype( &attrib, PTHREAD_MUTEX_ERRORCHECK ); if( 0 != pthread_mutex_init( m_pMotorCtrlMutex, &attrib ) ){ free( m_pMotorCtrlMutex ); m_pMotorCtrlMutex = NULL; LOG_ERROR("Cannot Create Motor Ctrl Protector Mutex!"); } else { m_pMotorCtrlThreadHandler = (pthread_t *) malloc(sizeof(pthread_t)); if( m_pMotorCtrlThreadHandler != NULL ) { memset( m_pMotorCtrlThreadHandler, 0, sizeof(pthread_t)); } else { pthread_mutex_destroy(m_pMotorCtrlMutex); free(m_pMotorCtrlMutex); m_pMotorCtrlMutex = NULL; LOG_ERROR("Cannot Allocate Motor Ctrl Thread!"); }; }; } else { LOG_ERROR("Cannot Allocate Motor Ctrl Protector Mutex!"); };#endif
//m_bMotorsViaTGZ = false;
m_pCanBus = NULL; m_pTGZdevice = NULL; memset( &m_sPARAMETERS, 0 ,sizeof( LGS_PARAMETERS ));
m_sPARAMETERS.flags.BaseScanCount = BASE_SCAN_COUNT; m_sPARAMETERS.flags.DetectorsCount = KERNEL_COUNT; m_sPARAMETERS.flags.MirrorScanCount = Q_SCAN_COUNT; m_sPARAMETERS.flags.MirrorsCount = Q_MIRROR_COUNT;
m_vMemoryBlock[0] = NULL; m_vMemoryBlock[1] = NULL; m_vMemoryBlock[2] = NULL; m_vMemoryBlock[3] = NULL; m_pSOC = classSOC::getInstance(); if( m_pSOC!= NULL ) { m_bInitOK = readPercs(); } else { LOG_ERROR( "SOC Control module failure!" ); }; if( m_bInitOK && m_pSettings!= NULL ){ m_bInitOK = create( m_pSettings ); };};
// Destructor implementation
LRF_HardwareManager::~LRF_HardwareManager(){ endService(); if( m_vMemoryBlock[0]!=NULL )free( m_vMemoryBlock[0]); if( m_vMemoryBlock[1]!=NULL )free( m_vMemoryBlock[1]); if( m_vMemoryBlock[2]!=NULL )free( m_vMemoryBlock[2]); if( m_vMemoryBlock[3]!=NULL )free( m_vMemoryBlock[3]); if( m_pTGZdevice ){ LOG( "Deleting TGZ device"); delete( m_pTGZdevice ); }; //ToDo: Check CAN Bus Destructor - Hangs
//ToDo: Delete Threads Mem
if( m_pCanBus ){ LOG( "Deleting CAN bus"); delete( m_pCanBus ); }; LOG( "HW manager - DONE!");};
bool LRF_HardwareManager::readPercs( void ){ int MEM_FD; void *PERC_MMAP; char Buffer[256];
LOG("Reading SOC Percs"); MEM_FD = open( "/dev/mem", O_RDWR | O_SYNC ); if( MEM_FD == -1 ) { sprintf( Buffer, "Memory File Open Failed Error: %s", strerror(errno)); LOG_ERROR( Buffer ); return false; }; PERC_MMAP = mmap( NULL, 0x2000, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_LOCKED, MEM_FD, AM437X_SIGN_ZONE ); close( MEM_FD ); if( PERC_MMAP == MAP_FAILED ) { sprintf( Buffer, "Memory Region Map Failed Error: %s\n", strerror(errno)); LOG_ERROR( Buffer ); return false; }; if( (*((uint32_t *)PERC_MMAP))== AM437X_SIGN_VAL ) { LOG( "Detected AM437x SOC Machine"); m_eSOC = SOC_AM437X; munmap( PERC_MMAP, 0x2000 ); return true; }; munmap( PERC_MMAP, 0x2000 ); MEM_FD = open( "/dev/mem", O_RDWR | O_SYNC ); if( MEM_FD == -1 ) { sprintf( Buffer, "Memory File Open Failed Error: %s", strerror(errno)); LOG_ERROR( Buffer ); return false; }; PERC_MMAP = mmap( NULL, 0x2000, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_LOCKED, MEM_FD, AM355X_SIGN_ZONE ); close( MEM_FD ); if( PERC_MMAP == MAP_FAILED ) { sprintf( Buffer, "Memory Region Map Failed Error: %s\n", strerror(errno)); LOG_ERROR( Buffer ); return false; }; if( (*((volatile uint32_t *)PERC_MMAP))== AM355X_SIGN_VAL ) { LOG( "Detected AM355x SOC Machine"); m_eSOC = SOC_AM335X; munmap( PERC_MMAP, 0x2000 ); return true; }; munmap( PERC_MMAP, 0x2000 ); LOG( "Cannot detect SOC type"); return false;};
bool LRF_HardwareManager::create( config_setting_t *Settings ){ config_setting_t *pSetting; int tVal; char tBuffer[256]; if( Settings != NULL ) { LOG("HW Getting Settings ..."); if( !config_setting_lookup_bool( Settings, HWM_SETTINGS_TH_DUMP, &tVal ) ){ tVal = m_bDumpMemoryToDisk = false; pSetting = config_setting_add( Settings, HWM_SETTINGS_TH_DUMP, CONFIG_TYPE_BOOL ); config_setting_set_bool( pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No TH Memory Dumping defined"); } else { m_bDumpMemoryToDisk = (bool)tVal; sprintf( tBuffer, "TH Memory Dumping Read From Settings: %d", tVal ); LOG( tBuffer ); }; if( !config_setting_lookup_bool( Settings, HWM_SETTINGS_ROLE, &tVal ) ){ tVal = m_sPARAMETERS.flags.isMaster = true; pSetting = config_setting_add( Settings, HWM_SETTINGS_ROLE, CONFIG_TYPE_BOOL ); config_setting_set_bool( pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No role defined"); } else { m_sPARAMETERS.flags.isMaster = (bool)tVal; sprintf( tBuffer, "Role Read From Settings: %d", tVal ); LOG( tBuffer ); }; if( !config_setting_lookup_bool( Settings, HWM_SETTINGS_SUNBIT, &tVal ) ){ tVal = m_sPARAMETERS.flags.Sunbit_filter = false; pSetting = config_setting_add( Settings, HWM_SETTINGS_SUNBIT, CONFIG_TYPE_BOOL ); config_setting_set_bool( pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No SUNBIT action defined - Disabling!"); } else { m_sPARAMETERS.flags.Sunbit_filter = (bool)tVal; sprintf( tBuffer, "SUNBIT Action Read From Settings: %d", tVal ); LOG( tBuffer ); }; if( !config_setting_lookup_bool( Settings, HWM_SETTINGS_LRF_ENABLED, &tVal ) ){ tVal = m_sPARAMETERS.flags.LaserPulsesOn = true; pSetting = config_setting_add( Settings, HWM_SETTINGS_LRF_ENABLED, CONFIG_TYPE_BOOL ); config_setting_set_bool( pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No LRF Enabled"); } else { m_sPARAMETERS.flags.LaserPulsesOn = (bool)tVal; sprintf( tBuffer, "LRF ENA Read From Settings: %d", tVal ); LOG( tBuffer ); }; if( !config_setting_lookup_bool( Settings, HWM_SETTINGS_SIG_SYMULATOR, &tVal ) ){ tVal = m_sPARAMETERS.flags.SignalSimulator = false; pSetting = config_setting_add( Settings, HWM_SETTINGS_SIG_SYMULATOR, CONFIG_TYPE_BOOL ); config_setting_set_bool( pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No Sig Symulator Settings"); } else { m_sPARAMETERS.flags.SignalSimulator = (bool)tVal; sprintf( tBuffer, "Sig Sym Read From Settings: %d", tVal ); LOG( tBuffer ); }; if( !m_sPARAMETERS.flags.SignalSimulator ) { if( !config_setting_lookup_bool( Settings, HWM_SETTINGS_AUTOSTART_ENABLED, &tVal ) ){ tVal = m_sPARAMETERS.flags.AutostartMotors = false; pSetting = config_setting_add( Settings, HWM_SETTINGS_AUTOSTART_ENABLED, CONFIG_TYPE_BOOL ); config_setting_set_bool( pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No Motor Autostart Settings"); } else { m_sPARAMETERS.flags.AutostartMotors = (bool)tVal; if( m_sPARAMETERS.flags.AutostartMotors ) { m_sPARAMETERS.flags.VerticalMotorOn = true; m_sPARAMETERS.flags.HorizontalMotorOn = true; }; sprintf( tBuffer, "AutoStart Read From Settings: %d", tVal ); LOG( tBuffer ); }; if( !m_sPARAMETERS.flags.AutostartMotors ) { if( !config_setting_lookup_bool( Settings, HWM_SETTINGS_CTRL_V_MOTOR, &tVal ) ){ tVal = m_sPARAMETERS.flags.VerticalMotorOn = false; pSetting = config_setting_add( Settings, HWM_SETTINGS_CTRL_V_MOTOR, CONFIG_TYPE_BOOL ); config_setting_set_bool( pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No Vertical Controll"); } else { m_sPARAMETERS.flags.VerticalMotorOn = (bool)tVal; sprintf( tBuffer, "V-M Ctrl Read From Settings: %d", tVal ); LOG( tBuffer ); }; if( !config_setting_lookup_bool( Settings, HWM_SETTINGS_CTRL_H_MOTOR, &tVal ) ){ tVal = m_sPARAMETERS.flags.HorizontalMotorOn = false; pSetting = config_setting_add( Settings, HWM_SETTINGS_CTRL_H_MOTOR, CONFIG_TYPE_BOOL ); config_setting_set_bool( pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No Horizontal Controll"); } else { m_sPARAMETERS.flags.HorizontalMotorOn = (bool)tVal; sprintf( tBuffer, "H-M Ctrl Read From Settings: %d", tVal ); LOG( tBuffer ); }; }; } if (!config_setting_lookup_int(Settings, HWM_SETTINGS_V_MOTOR_SETPOINT, &tVal )){ tVal = m_sPARAMETERS.flags.VerticalFreq = Q_WORK_FREQ; pSetting = config_setting_add(Settings, HWM_SETTINGS_V_MOTOR_SETPOINT, CONFIG_TYPE_INT); config_setting_set_int(pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No Mirror Block Freq"); } else { m_sPARAMETERS.flags.VerticalFreq = tVal; sprintf( tBuffer, "V-M Setpoint Read From Settings: %d", tVal ); LOG( tBuffer ); }; if (!config_setting_lookup_int(Settings, HWM_SETTINGS_H_MOTOR_SETPOINT, &tVal )){ tVal = m_sPARAMETERS.flags.HorizontalFreq = B_WORK_FREQ; pSetting = config_setting_add(Settings, HWM_SETTINGS_H_MOTOR_SETPOINT, CONFIG_TYPE_INT); config_setting_set_int(pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No Base Block Freq"); } else { m_sPARAMETERS.flags.HorizontalFreq = tVal; sprintf( tBuffer, "H-M Setpoint Read From Settings: %d", tVal ); LOG( tBuffer ); }; if (!config_setting_lookup_int(Settings, HWM_SETTINGS_V_PULSES_INTERLEAVE, &tVal )){ tVal = m_sPARAMETERS.flags.QQinterlace = Q_P_INTERLEAVE; pSetting = config_setting_add(Settings, HWM_SETTINGS_V_PULSES_INTERLEAVE, CONFIG_TYPE_INT); config_setting_set_int(pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No Q Pulses per LRF pulse Setting"); } else { m_sPARAMETERS.flags.QQinterlace = tVal; sprintf( tBuffer, "Q-Pulses per LRF pulse Read From Settings: %d", tVal ); LOG( tBuffer ); };
if (!config_setting_lookup_int(Settings, HWM_SETTINGS_TH_OFFSET, &tVal )){ tVal = m_sPARAMETERS.nOffset = SIGNAL_OFFSET; pSetting = config_setting_add(Settings, HWM_SETTINGS_TH_OFFSET, CONFIG_TYPE_INT); config_setting_set_int(pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No TH Offset Setting"); } else { m_sPARAMETERS.nOffset = tVal; sprintf( tBuffer, "TH Offset Read From Settings: %d", tVal ); LOG( tBuffer ); }; if (!config_setting_lookup_int(Settings, HWM_SETTINGS_TH_ORDER, &tVal )){ tVal = m_sPARAMETERS.nOrder = SIGNAL_ORDER; pSetting = config_setting_add(Settings, HWM_SETTINGS_TH_ORDER, CONFIG_TYPE_INT); config_setting_set_int(pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No TH Order Setting"); } else { m_sPARAMETERS.nOrder = tVal;#if defined( STRONG_STAT ) || !defined( THREADED_FLIP )
if( m_sPARAMETERS.nOrder > 7 ) m_sPARAMETERS.nOrder = 7;#endif
sprintf( tBuffer, "TH Order Read From Settings: %d", m_sPARAMETERS.nOrder ); LOG( tBuffer ); }; if (!config_setting_lookup_int(Settings, HWM_SETTINGS_TH_DELTA, &tVal )){ tVal = m_sPARAMETERS.nDelta = SIGNAL_DELTA; pSetting = config_setting_add(Settings, HWM_SETTINGS_TH_DELTA, CONFIG_TYPE_INT); config_setting_set_int(pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No TH Delta Setting"); } else { m_sPARAMETERS.nDelta = tVal;#if !defined( THREADED_FLIP )
if( m_sPARAMETERS.nDelta > 127 ) m_sPARAMETERS.nDelta = 127;#endif
sprintf( tBuffer, "TH Delta Read From Settings: %d", m_sPARAMETERS.nDelta ); LOG( tBuffer ); }; if (!config_setting_lookup_int(Settings, HWM_SETTINGS_TH_FLIP_SIZE, &tVal )){ tVal = m_sPARAMETERS.nFlip = SCANS_TO_FLIP; pSetting = config_setting_add(Settings, HWM_SETTINGS_TH_FLIP_SIZE, CONFIG_TYPE_INT); config_setting_set_int(pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No TH Flip Size Setting"); } else { m_sPARAMETERS.nFlip = tVal; sprintf( tBuffer, "Flip Size Read From Settings: %d", tVal ); LOG( tBuffer ); }; if (!config_setting_lookup_int(Settings, HWM_SETTINGS_TH_GOOD_POINTS, &tVal )){ tVal = m_sPARAMETERS.nGPointSamples = TH_POINT_GOOD; pSetting = config_setting_add(Settings, HWM_SETTINGS_TH_GOOD_POINTS, CONFIG_TYPE_INT); config_setting_set_int(pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No TH Good Points Setting"); } else { m_sPARAMETERS.nGPointSamples = tVal;#if defined( STRONG_STAT ) || !defined( THREADED_FLIP )
if( m_sPARAMETERS.nGPointSamples > 15 ) m_sPARAMETERS.nGPointSamples = 15;#endif
sprintf( tBuffer, "TH Good Points Read From Settings: %d", m_sPARAMETERS.nGPointSamples ); LOG( tBuffer ); }; if( !config_setting_lookup_bool( Settings, HWM_SETTINGS_AUTO_TH_GENERATE, &tVal ) ){ tVal = m_sPARAMETERS.flags.BuildThByCore = true; pSetting = config_setting_add( Settings, HWM_SETTINGS_AUTO_TH_GENERATE, CONFIG_TYPE_BOOL ); config_setting_set_bool( pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No TH Build By Core Setting"); } else { m_sPARAMETERS.flags.BuildThByCore = (bool)tVal; sprintf( tBuffer, "TH Build by Core Read From Settings: %d", tVal ); LOG( tBuffer ); }; if (!config_setting_lookup_int(Settings, HWM_SETTINGS_TH_SPIKE_SIZE, &tVal )){ tVal = m_sPARAMETERS.flags.Spike_TH = 1; pSetting = config_setting_add(Settings, HWM_SETTINGS_TH_SPIKE_SIZE, CONFIG_TYPE_INT); config_setting_set_int(pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No Spike Threshold Setting"); } else { m_sPARAMETERS.flags.Spike_TH = tVal; sprintf( tBuffer, "Spike Threshold Read From Settings: %d", tVal ); LOG( tBuffer ); }; if( !config_setting_lookup_bool( Settings, HWM_SETTINGS_CAN_CONTROL_ENABLE, &tVal ) ){ tVal = m_sPARAMETERS.flags.TGZ_canENA = false; pSetting = config_setting_add( Settings, HWM_SETTINGS_CAN_CONTROL_ENABLE, CONFIG_TYPE_BOOL ); config_setting_set_bool( pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No CAN Enable Setting"); } else { m_sPARAMETERS.flags.TGZ_canENA = (bool)tVal; sprintf( tBuffer, "CAN ENA Read From Settings: %d", tVal ); LOG( tBuffer ); }; if (!config_setting_lookup_int(Settings, HWM_SETTINGS_CAN_BUS_ID, &tVal )){ tVal = m_sPARAMETERS.flags.TGZ_canBus = 1; pSetting = config_setting_add(Settings, HWM_SETTINGS_CAN_BUS_ID, CONFIG_TYPE_INT); config_setting_set_int(pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No CAN Bus ID Setting"); } else { m_sPARAMETERS.flags.TGZ_canBus = tVal; sprintf( tBuffer, "CAN Bus ID Read From Settings: %d", tVal ); LOG( tBuffer ); }; if (!config_setting_lookup_int(Settings, HWM_SETTINGS_CAN_MY_ID, &tVal )){#ifndef TGD_VERSION_2
tVal = m_sPARAMETERS.flags.TGZ_canSRC = 0x200;#else
tVal = m_sPARAMETERS.flags.TGZ_canSRC = 0x300;#endif
pSetting = config_setting_add(Settings, HWM_SETTINGS_CAN_MY_ID, CONFIG_TYPE_INT); config_setting_set_int(pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No CAN My ID Setting"); } else { m_sPARAMETERS.flags.TGZ_canSRC = tVal; sprintf( tBuffer, "CAN My ID Read From Settings: 0x%X", tVal ); LOG( tBuffer ); }; if (!config_setting_lookup_int(Settings, HWM_SETTINGS_CAN_TGZ_ID, &tVal )){#ifndef TGD_VERSION_2
tVal = m_sPARAMETERS.flags.TGZ_canDST = 0x201;#else
tVal = m_sPARAMETERS.flags.TGZ_canDST = 0x301;#endif
pSetting = config_setting_add(Settings, HWM_SETTINGS_CAN_TGZ_ID, CONFIG_TYPE_INT); config_setting_set_int(pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No CAN TGZ ID Setting"); } else { m_sPARAMETERS.flags.TGZ_canDST = tVal; sprintf( tBuffer, "CAN TGZ ID Read From Settings: 0x%X", tVal ); LOG( tBuffer ); };#ifndef TGD_VERSION_2
if (!config_setting_lookup_int(Settings, HWM_SETTINGS_TGZ_DIVIDER, &tVal )){ tVal = m_sPARAMETERS.flags.TGZ_divider = 1; pSetting = config_setting_add(Settings, HWM_SETTINGS_TGZ_DIVIDER, CONFIG_TYPE_INT); config_setting_set_int(pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No TGZ Divider Setting"); } else { m_sPARAMETERS.flags.TGZ_divider = tVal; sprintf( tBuffer, "TGZ Div Read From Settings: %d", tVal ); LOG( tBuffer ); }; if (!config_setting_lookup_int(Settings, HWM_SETTINGS_TGZ_PRF, &tVal )){ tVal = m_sPARAMETERS.flags.TGZ_ParamQ = 35; // 35000 kHz
pSetting = config_setting_add(Settings, HWM_SETTINGS_TGZ_PRF, CONFIG_TYPE_INT); config_setting_set_int(pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No TGZ PRF Setting"); } else { m_sPARAMETERS.flags.TGZ_ParamQ = tVal; sprintf( tBuffer, "TGZ PRF Read From Settings: %d", tVal ); LOG( tBuffer ); }; if (!config_setting_lookup_int(Settings, HWM_SETTINGS_TGZ_RATIO, &tVal )){ tVal = m_sPARAMETERS.flags.TGZ_ParamB = 64; pSetting = config_setting_add(Settings, HWM_SETTINGS_TGZ_RATIO, CONFIG_TYPE_INT); config_setting_set_int(pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No TGZ Ratio Setting"); } else { m_sPARAMETERS.flags.TGZ_ParamB = tVal; sprintf( tBuffer, "TGZ Ratio Read From Settings: %d", tVal ); LOG( tBuffer ); };#else
if (!config_setting_lookup_int(Settings, HWM_SETTINGS_TGZ_MIRROR_SPEED, &tVal )){ tVal = m_sPARAMETERS.flags.TGZ_ParamQ = ( Q_WORK_FREQ >> 2 ); pSetting = config_setting_add(Settings, HWM_SETTINGS_TGZ_MIRROR_SPEED, CONFIG_TYPE_INT); config_setting_set_int(pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No TGZ Mirror Block Speed"); } else { m_sPARAMETERS.flags.TGZ_ParamQ = tVal; sprintf( tBuffer, "TGZ Mirror Block Speed Read From Settings: %d", tVal ); LOG( tBuffer ); }; if (!config_setting_lookup_int(Settings, HWM_SETTINGS_TGZ_BASE_SPEED, &tVal )){ tVal = m_sPARAMETERS.flags.TGZ_ParamB = ( B_WORK_FREQ >> 4 ); pSetting = config_setting_add(Settings, HWM_SETTINGS_TGZ_BASE_SPEED, CONFIG_TYPE_INT); config_setting_set_int(pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No TGZ Base Motor Speed"); } else { m_sPARAMETERS.flags.TGZ_ParamB = tVal; sprintf( tBuffer, "TGZ Base Motor Speed Read From Settings: %d", tVal ); LOG( tBuffer ); };#endif
if (!config_setting_lookup_int(Settings, HWM_SETTINGS_B_SHIFT, &tVal )){ tVal = m_sPARAMETERS.flags.B_shift = 0; pSetting = config_setting_add(Settings, HWM_SETTINGS_B_SHIFT, CONFIG_TYPE_INT); config_setting_set_int(pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No Base Shift Specified"); } else { m_sPARAMETERS.flags.B_shift = tVal; sprintf( tBuffer, "Base Shift Read From Settings: %d", tVal ); LOG( tBuffer ); }; if (!config_setting_lookup_int(Settings, HWM_SETTINGS_Q_SHIFT, &tVal )){ tVal = m_sPARAMETERS.flags.Q_shift = 0; pSetting = config_setting_add(Settings, HWM_SETTINGS_Q_SHIFT, CONFIG_TYPE_INT); config_setting_set_int(pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No Mirror Shift Specified"); } else { m_sPARAMETERS.flags.Q_shift = tVal; sprintf( tBuffer, "Mirror Shift Read From Settings: %d", tVal ); LOG( tBuffer ); }; if( m_pSettingsProvider->isCompromised() ) { LOG("Save Settings"); m_pSettingsProvider->validate(); }; LOG("HW Create(1) Started"); beginService(); LOG("HW Create(1) Done"); }; return m_bInitOK;};
bool LRF_HardwareManager::getHardwareParams( HW_PARAMS &Params ){ memcpy( &Params, &m_sPARAMETERS.flags, sizeof(HW_PARAMS) ); return true;};
bool LRF_HardwareManager::setHardwareParams( PHW_PARAMS Params ){ memcpy( &m_sPARAMETERS.flags, &Params, sizeof(HW_PARAMS) ); return true;};
bool LRF_HardwareManager::getParams( LGS_PARAMETERS &Params ){ memcpy( &Params, &m_sPARAMETERS, sizeof(LGS_PARAMETERS) ); return true;};
bool LRF_HardwareManager::create( HW_PARAMS &HS ){ LOG("HW Create(2) Started"); m_sPARAMETERS.flags.isMaster = HS.isMaster; beginService(); LOG("HW Create(2) Done"); return m_bInitOK;};
void LRF_HardwareManager::beginService( void ){ m_bInitOK = false; if( m_pSOC != NULL ) { LOG("Begin HW init process"); LOG("Stoping all PRU Cores"); if(!m_pSOC->pru_stop(0,0)){ LOG_ERROR("Error Stoping PRU 0 0 Core"); }; if(!m_pSOC->pru_sreset(0,0)){ LOG_ERROR("Error Resetting PRU 0 0 Core"); }; if(!m_pSOC->pru_disable(0,0)){ LOG_ERROR("Error Disabling PRU 0 0 Core"); }; LOG("PRU 0 0 stoped"); if(!m_pSOC->pru_stop(0,1)){ LOG_ERROR("Error Stoping PRU 0 1 Core"); }; if(!m_pSOC->pru_sreset(0,1)){ LOG_ERROR("Error Resetting PRU 0 1 Core"); }; if(!m_pSOC->pru_disable(0,1)){ LOG_ERROR("Error Disabling PRU 0 1 Core"); }; LOG("PRU 0 1 stoped"); if(!m_pSOC->pru_stop(1,0)){ LOG_ERROR("Error Stoping PRU 1 0 Core"); }; if(!m_pSOC->pru_sreset(1,0)){ LOG_ERROR("Error Resetting PRU 1 0 Core"); }; if(!m_pSOC->pru_disable(1,0)){ LOG_ERROR("Error Disabling PRU 1 0 Core"); }; LOG("PRU 1 0 stoped"); if(!m_pSOC->pru_stop(1,1)){ LOG_ERROR("Error Stoping PRU 1 1 Core"); }; if(!m_pSOC->pru_sreset(1,1)){ LOG_ERROR("Error Resetting PRU 1 1 Core"); }; if(!m_pSOC->pru_disable(1,1)){ LOG_ERROR("Error Disabling PRU 1 1 Core"); }; LOG("PRU 1 1 stoped");
if( m_sPARAMETERS.flags.isMaster ) { // If enable TGZ CAN connection
if( m_sPARAMETERS.flags.TGZ_canENA ) { // Init TGZ connection
char tBuf[16]; sprintf( tBuf, "can%d", m_sPARAMETERS.flags.TGZ_canBus ); m_pCanBus = new canBus( tBuf, m_sPARAMETERS.flags.TGZ_canSRC, m_sPARAMETERS.flags.TGZ_canDST );
if( m_pCanBus != NULL ) { LOG("CAN Bus creation success"); m_pTGZdevice = new protocolTGZ( m_pCanBus ); if( m_pTGZdevice == NULL ) { LOG_ERROR("TGZ protocol creation failure"); delete( m_pCanBus ); m_pCanBus = NULL; }else{ LOG("TGZ protocol creation success"); }; } else { LOG_ERROR("CAN Bus creation failure");; }; };
if( m_sPARAMETERS.flags.AutostartMotors ) {#ifndef NO_MOTORS
LOG("Startup Motors"); startMotors();#else
LOG("Startup Motors Disabled by Compilation");#endif
} else { LOG("No Auto Startup Motors"); }; LOG("Loading MASTER set of PRU Modules"); /*
The Order of cores to be loadedd is crucial. The first to load - last to function (Data Acq) that depends on others */ if( !m_pSOC->pru_load( 1, 1, "PRU_1_1.bin", false ) ){ LOG_ERROR("PRU 1 1 Load - FAILURE"); return; }; if( !m_pSOC->pru_load( 1, 0, "PRU_1_0.bin", false ) ){ LOG_ERROR("PRU 1 0 Load - FAILURE"); return; }; if( !m_pSOC->pru_load( 0, 1, "PRU_0_1.bin", true ) ){ LOG_ERROR("PRU 0 1 Load - FAILURE"); return; };#ifdef NO_MOTORS
LOG("Loading simulation of Motors"); if( !m_pSOC->pru_load( 0, 0, "CORE0_NOMO.bin", true ) ){ LOG_ERROR("PRU 0 0 Load - FAILURE"); return; };#else
if( !m_pSOC->pru_load( 0, 0, "PRU_0_0.bin", true ) ){ LOG_ERROR("PRU 0 0 Load - FAILURE"); return; };#endif
// Make Handshake with cores
if( !m_pSOC->setCoreOnLine(3) ){ LOG_ERROR("Core 3 Startup Failure"); m_bInitOK = false; return; }; if( !m_pSOC->setCoreOnLine(2) ){ LOG_ERROR("Core 2 Startup Failure"); m_bInitOK = false; return; }; if( !m_pSOC->setCoreOnLine(1) ){ LOG_ERROR("Core 1 Startup Failure"); m_bInitOK = false; return; }; if( !m_pSOC->setCoreOnLine(0) ){ LOG_ERROR("Core 0 Startup Failure"); m_bInitOK = false; return; };
// Fill Software Info
//
if( NULL != m_pSOC ){ gsSOFT_INFO.FW_CORE1_VER = m_pSOC->getPRU_ID(0); gsSOFT_INFO.FW_CORE1_TYP = m_pSOC->getPRU_TYPE(0); gsSOFT_INFO.FW_CORE2_VER = m_pSOC->getPRU_ID(1); gsSOFT_INFO.FW_CORE2_TYP = m_pSOC->getPRU_TYPE(1); gsSOFT_INFO.FW_CORE3_VER = m_pSOC->getPRU_ID(2); gsSOFT_INFO.FW_CORE3_TYP = m_pSOC->getPRU_TYPE(2); gsSOFT_INFO.FW_CORE4_VER = m_pSOC->getPRU_ID(3); gsSOFT_INFO.FW_CORE4_TYP = m_pSOC->getPRU_TYPE(3); gsSOFT_INFO.DATA_VALID = true; };
// Configure Cores to current Config
// Core 0
if( !m_pSOC->setSunbitMode( m_sPARAMETERS.flags.Sunbit_filter ) ){ LOG_ERROR("Set SUNBIT Mode Failure"); m_bInitOK = false; return; };
if( !m_pSOC->setMotorMonitoringMode( m_sPARAMETERS.flags.VerticalMotorOn , m_sPARAMETERS.flags.HorizontalMotorOn ) ){ LOG_ERROR("Set Motor's Monitor Mode Failure"); m_bInitOK = false; return; };
if( !m_pSOC->setMotorInterleaveMode( m_sPARAMETERS.flags.QQinterlace ) ) { LOG_ERROR("Set Motor's Interleave Mode Failure"); m_bInitOK = false; return; }; if( !m_pSOC->setMotorSetPoints( m_sPARAMETERS.flags.VerticalFreq , m_sPARAMETERS.flags.HorizontalFreq ) ) { LOG_ERROR("Set Motor's Setpoints Failure"); m_bInitOK = false; return; }; if( !m_pSOC->setLrfPulseMode( m_sPARAMETERS.flags.LaserPulsesOn ) ) { LOG_ERROR("Set LRF Pulses Mode Failure"); m_bInitOK = false; return; };
if( !m_pSOC->setSimulationMode( m_sPARAMETERS.flags.SignalSimulator ) ) { LOG_ERROR("Set LRF Simulation Mode Failure"); m_bInitOK = false; return; }; // Core 2
// Set Shifts
if( !m_pSOC->setShifts( m_sPARAMETERS.flags.B_shift, m_sPARAMETERS.flags.Q_shift ) ) { LOG_ERROR("Set B-Q Shifts Failure"); m_bInitOK = false; return; }; // Core 3
m_sCP_Detector.delta = m_sPARAMETERS.nDelta; m_sCP_Detector.flip_size = m_sPARAMETERS.nFlip; m_sCP_Detector.good_points = m_sPARAMETERS.nGPointSamples; m_sCP_Detector.offset = m_sPARAMETERS.nOffset; m_sCP_Detector.order = m_sPARAMETERS.nOrder; m_sCP_Detector.self_build_ena = m_sPARAMETERS.flags.BuildThByCore; m_sCP_Detector.master = m_sPARAMETERS.flags.isMaster;
#ifdef DEBUG
char Buffer[256]; sprintf( Buffer, "Detector[%s] Parameters: Delta[%d] Flip_Size[%d] Good_Points[%d] Order[%d] Offset[%d] TH_Automatic_Build[%d]", ((m_sCP_Detector.master)?"M":"S"), m_sCP_Detector.delta, m_sCP_Detector.flip_size, m_sCP_Detector.good_points, m_sCP_Detector.order, m_sCP_Detector.offset, m_sCP_Detector.self_build_ena ); LOG( Buffer );#endif
if( !m_pSOC->setThCoreParams( &m_sCP_Detector )){ LOG_ERROR("Detection Core Set Params Failure"); m_bInitOK = false; return; }; m_sCS_Detector.h_dencity = 2; m_sCS_Detector.mode = 0; m_sCS_Detector.online = 0; m_sCS_Detector.param_err = 0; m_sCS_Detector.req = 0; m_sCS_Detector.spike_th = m_sPARAMETERS.flags.Spike_TH; m_sCS_Detector.v_dencity = 2; m_sCS_Detector.work_en = 0;#ifdef DEBUG
sprintf( Buffer, "Detector Status: Mode[%d] Spike_TH[%d] V_dencity[%d] H_dencity[%d]", m_sCS_Detector.mode, m_sCS_Detector.spike_th, m_sCS_Detector.v_dencity, m_sCS_Detector.h_dencity ); LOG( Buffer );#endif
if( !m_pSOC->setThCoreStatus( &m_sCS_Detector )){ LOG_ERROR("Detection Core Set Statuses Failure"); m_bInitOK = false; return; }; // If Work is Enabled Enable Detection Work
if( !m_pSOC->setToWork( m_sPARAMETERS.flags.LaserPulsesOn ) ) { LOG_ERROR("Detection Core Enabling Failure"); m_bInitOK = false; return; }; m_bInitOK = true; } else { // Slave Mode
LOG_ERROR("Motors control Disabled by Slave Mode!"); LOG("Loading SLAVE set of PRU Modules"); /*
The Order of cores to be loadedd is crucial. The first to load - last to function (Data Acq) that depends on others */ if( !m_pSOC->pru_load( 1, 1, "PRU_1_1.bin", false ) ){ LOG_ERROR("PRU 1 1 Load - FAILURE"); return; }; if( !m_pSOC->pru_load( 1, 0, "PRU_1_0.bin", false ) ){ LOG_ERROR("PRU 1 0 Load - FAILURE"); return; }; if( !m_pSOC->pru_load( 0, 1, "PRU_0_1.bin", true ) ){ LOG_ERROR("PRU 0 1 Load - FAILURE"); return; }; if( !m_pSOC->pru_load( 0, 0, "PRU_0_0.bin", true ) ){ LOG_ERROR("PRU 0 0 Load - FAILURE"); return; }; // Make Handshake with cores
if( !m_pSOC->setCoreOnLine(3) ){ LOG_ERROR("Core 3 Startup Failure"); m_bInitOK = false; return; }; if( !m_pSOC->setCoreOnLine(2) ){ LOG_ERROR("Core 2 Startup Failure"); m_bInitOK = false; return; }; if( !m_pSOC->setCoreOnLine(1) ){ LOG_ERROR("Core 1 Startup Failure"); m_bInitOK = false; return; }; if( !m_pSOC->setCoreOnLine(0) ){ LOG_ERROR("Core 0 Startup Failure"); m_bInitOK = false; return; }; // Fill Software Info
//
if( NULL != m_pSOC ){ gsSOFT_INFO.FW_CORE1_VER = m_pSOC->getPRU_ID(0); gsSOFT_INFO.FW_CORE2_VER = m_pSOC->getPRU_ID(1); gsSOFT_INFO.FW_CORE3_VER = m_pSOC->getPRU_ID(2); gsSOFT_INFO.FW_CORE4_VER = m_pSOC->getPRU_ID(3); gsSOFT_INFO.DATA_VALID = true; };
// Configure Cores to current Config
// Core 0
if( !m_pSOC->setSunbitMode( m_sPARAMETERS.flags.Sunbit_filter ) ){ LOG_ERROR("Set SUNBIT Mode Failure"); m_bInitOK = false; return; };
if( !m_pSOC->setMotorMonitoringMode( m_sPARAMETERS.flags.VerticalMotorOn , m_sPARAMETERS.flags.HorizontalMotorOn ) ){ LOG_ERROR("Set Motor's Monitor Mode Failure"); m_bInitOK = false; return; };
if( !m_pSOC->setMotorInterleaveMode( m_sPARAMETERS.flags.QQinterlace ) ) { LOG_ERROR("Set Motor's Interleave Mode Failure"); m_bInitOK = false; return; }; if( !m_pSOC->setMotorSetPoints( m_sPARAMETERS.flags.VerticalFreq , m_sPARAMETERS.flags.HorizontalFreq ) ) { LOG_ERROR("Set Motor's Setpoints Failure"); m_bInitOK = false; return; }; if( !m_pSOC->setLrfPulseMode( m_sPARAMETERS.flags.LaserPulsesOn ) ) { LOG_ERROR("Set LRF Pulses Mode Failure"); m_bInitOK = false; return; };
if( !m_pSOC->setSimulationMode( m_sPARAMETERS.flags.SignalSimulator ) ) { LOG_ERROR("Set LRF Simulation Mode Failure"); m_bInitOK = false; return; }; // Core 2
// Set Shifts
if( !m_pSOC->setShifts( m_sPARAMETERS.flags.B_shift, m_sPARAMETERS.flags.Q_shift ) ) { LOG_ERROR("Set B-Q Shifts Failure"); m_bInitOK = false; return; }; // Core 3
m_sCP_Detector.delta = m_sPARAMETERS.nDelta; m_sCP_Detector.flip_size = m_sPARAMETERS.nFlip; m_sCP_Detector.good_points = m_sPARAMETERS.nGPointSamples; m_sCP_Detector.offset = m_sPARAMETERS.nOffset; m_sCP_Detector.order = m_sPARAMETERS.nOrder; m_sCP_Detector.self_build_ena = m_sPARAMETERS.flags.BuildThByCore;#ifdef DEBUG
char Buffer[256]; sprintf( Buffer, "Detector Parameters: Delta[%d] Flip_Size[%d] Good_Points[%d] Order[%d] Offset[%d] TH_Automatic_Build[%d]", m_sCP_Detector.delta, m_sCP_Detector.flip_size, m_sCP_Detector.good_points, m_sCP_Detector.order, m_sCP_Detector.offset, m_sCP_Detector.self_build_ena ); LOG( Buffer );#endif
if( !m_pSOC->setThCoreParams( &m_sCP_Detector )){ LOG_ERROR("Detection Core Set Params Failure"); m_bInitOK = false; return; }; m_sCS_Detector.h_dencity = 2; m_sCS_Detector.mode = 0; m_sCS_Detector.online = 0; m_sCS_Detector.param_err = 0; m_sCS_Detector.req = 0; m_sCS_Detector.spike_th = m_sPARAMETERS.flags.Spike_TH; m_sCS_Detector.v_dencity = 2; m_sCS_Detector.work_en = 0;#ifdef DEBUG
sprintf( Buffer, "Detector Status: Mode[%d] Spike_TH[%d] V_dencity[%d] H_dencity[%d]", m_sCS_Detector.mode, m_sCS_Detector.spike_th, m_sCS_Detector.v_dencity, m_sCS_Detector.h_dencity ); LOG( Buffer );#endif
if( !m_pSOC->setThCoreStatus( &m_sCS_Detector )){ LOG_ERROR("Detection Core Set Statuses Failure"); m_bInitOK = false; return; }; // If Work is Enabled Enable Detection Work
if( !m_pSOC->setToWork( m_sPARAMETERS.flags.LaserPulsesOn ) ) { LOG_ERROR("Detection Core Enabling Failure"); m_bInitOK = false; return; }; memset( m_bTHSteadyCounter, ( m_sCP_Detector.flip_size && 0xFF ), KERNEL_COUNT); m_bInitOK = true; }; };};void LRF_HardwareManager::endService( void ){ if( m_pSOC!=NULL ){ if( m_sPARAMETERS.flags.isMaster ) {#ifndef NO_MOTORS
stopMotors();#endif
} else { }; LOG("Stoping all PRU Cores"); if(!m_pSOC->pru_stop(0,0)){ LOG_ERROR("Error Stoping PRU 0 0 Core"); }; if(!m_pSOC->pru_sreset(0,0)){ LOG_ERROR("Error Resetting PRU 0 0 Core"); }; if(!m_pSOC->pru_disable(0,0)){ LOG_ERROR("Error Disabling PRU 0 0 Core"); }; LOG("PRU 0 0 stoped"); if(!m_pSOC->pru_stop(0,1)){ LOG_ERROR("Error Stoping PRU 0 1 Core"); }; if(!m_pSOC->pru_sreset(0,1)){ LOG_ERROR("Error Resetting PRU 0 1 Core"); }; if(!m_pSOC->pru_disable(0,1)){ LOG_ERROR("Error Disabling PRU 0 1 Core"); }; LOG("PRU 0 1 stoped"); if(!m_pSOC->pru_stop(1,0)){ LOG_ERROR("Error Stoping PRU 1 0 Core"); }; if(!m_pSOC->pru_sreset(1,0)){ LOG_ERROR("Error Resetting PRU 1 0 Core"); }; if(!m_pSOC->pru_disable(1,0)){ LOG_ERROR("Error Disabling PRU 1 0 Core"); }; LOG("PRU 1 0 stoped"); if(!m_pSOC->pru_stop(1,1)){ LOG_ERROR("Error Stoping PRU 1 1 Core"); }; if(!m_pSOC->pru_sreset(1,1)){ LOG_ERROR("Error Resetting PRU 1 1 Core"); }; if(!m_pSOC->pru_disable(1,1)){ LOG_ERROR("Error Disabling PRU 1 1 Core"); }; LOG("PRU 1 1 stoped"); if( !m_pSOC->pru_load( 0, 0, "halt.bin" ) ){ LOG_ERROR("PRU 0 0 HALT - FAILURE"); }; if( !m_pSOC->pru_load( 0, 1, "halt.bin" ) ){ LOG_ERROR("PRU 0 1 HALT - FAILURE"); }; if( !m_pSOC->pru_load( 1, 0, "halt.bin" ) ){ LOG_ERROR("PRU 1 0 HALT - FAILURE"); }; if( !m_pSOC->pru_load( 1, 1, "halt.bin" ) ){ LOG_ERROR("PRU 1 1 HALT - FAILURE"); }; };};#ifdef THREADED_MOTORS_START
void LRF_HardwareManager::performStartMotors( void ){ if( m_sPARAMETERS.flags.TGZ_canENA ) { LOG("Starting TGZ device"); if( m_pTGZdevice!= NULL ) {#ifndef TGD_VERSION_2
m_pTGZdevice->setDivider( m_sPARAMETERS.flags.TGZ_divider ); m_pTGZdevice->setPrfMode( m_sPARAMETERS.flags.TGZ_ParamQ ); m_pTGZdevice->setRatio( m_sPARAMETERS.flags.TGZ_ParamB );#else //TGD_VERSION_2
m_pTGZdevice->setSpeeds( m_sPARAMETERS.flags.TGZ_ParamQ, m_sPARAMETERS.flags.TGZ_ParamB );#endif //TGD_VERSION_2
m_pTGZdevice->setRunMode( true ); m_pTGZdevice->setErrorMode( true );
m_pTGZdevice->startDeviceStateInquiry();
//ToDo: Wait for TGD starts Motors!
//LOG( "Wait Startup TGZ");
//SLEEP(30000); // 30 seconds
//LOG( "Done");
} else { LOG_ERROR("Error TGZ Device object!" ); }; } else { volatile sysPwmss *mV_PWMSS = NULL; volatile sysPwmss *mH_PWMSS = NULL; LOG("StartMotorsProcedure"); if( m_pSOC!=NULL && m_sPARAMETERS.flags.isMaster ){ mV_PWMSS = m_pSOC->getPWMSS_CTRL( 1 ); mH_PWMSS = m_pSOC->getPWMSS_CTRL( 2 ); if( mV_PWMSS!=NULL && mH_PWMSS!=NULL ){ // Disable PWM;
LOG("Disable Motors PWMs"); mV_PWMSS->CLKCONFIG_bit.EPWMCLK_EN = 0; mH_PWMSS->CLKCONFIG_bit.EPWMCLK_EN = 0; while( mV_PWMSS->CLKCONFIG_bit.EPWMCLK_EN == 1 || mH_PWMSS->CLKCONFIG_bit.EPWMCLK_EN == 1 )usleep(5); LOG("Disable Motors PWMs - Done"); // Polarity
mV_PWMSS->ECAP_ECCTL2_bit.APWMPOL = PWM_POLARITY_INVERSE; mH_PWMSS->ECAP_ECCTL2_bit.APWMPOL = PWM_POLARITY_INVERSE;
LOG("Set Motors PWMs Config"); // Set PWM Period
mV_PWMSS->ECAP_CAP3 = VM_WORK_PERIOD; mH_PWMSS->ECAP_CAP3 = HM_WORK_PERIOD; mV_PWMSS->ECAP_CAP1 = VM_WORK_PERIOD; mH_PWMSS->ECAP_CAP1 = HM_WORK_PERIOD; LOG("Set Motors PWMs Period"); // Set Intitial Zeroes DC
mV_PWMSS->ECAP_CAP4 = 1; mH_PWMSS->ECAP_CAP4 = 1; mV_PWMSS->ECAP_CAP2 = 1; mH_PWMSS->ECAP_CAP2 = 1; LOG("Set Motors PWMs DC"); // Config Timer
// Running
//ECCTL1: 0x00008000
//ECCTL2: 0x000006D6
// Stoped
//ECCTL1: 0x00008000
//ECCTL2: 0x000004C6
mV_PWMSS->ECAP_ECCTL1 = 0; mV_PWMSS->ECAP_ECCTL1_bit.FREE_SOFT = 2; mV_PWMSS->ECAP_ECCTL2_bit.TSCTRSTOP = 1; mH_PWMSS->ECAP_ECCTL1 = 0; mH_PWMSS->ECAP_ECCTL1_bit.FREE_SOFT = 2; mH_PWMSS->ECAP_ECCTL2_bit.TSCTRSTOP = 1; // Set APWM mode
mV_PWMSS->ECAP_ECCTL2_bit.CAP_APWM = 1; mH_PWMSS->ECAP_ECCTL2_bit.CAP_APWM = 1; // Set module enable
mV_PWMSS->CLKCONFIG_bit.EPWMCLK_EN = 1; mH_PWMSS->CLKCONFIG_bit.EPWMCLK_EN = 1; LOG("Set Motors PWMs Enabled"); uint32_t index = 0; LOG("Start Motors PWMs Spin Up"); while( index < VM_WORK_DUTY_CYCLE || index < HM_WORK_DUTY_CYCLE ){ if( index < VM_WORK_DUTY_CYCLE ){ mV_PWMSS->ECAP_CAP4 = index; while( mV_PWMSS->ECAP_CAP2 != index )usleep(5); }; if( index < HM_WORK_DUTY_CYCLE ){ mH_PWMSS->ECAP_CAP4 = index; while( mH_PWMSS->ECAP_CAP2 != index )usleep(5); }; usleep( 700 ); //700 microseconds;
index++; }; LOG("Motors PWMs Spin Up Done"); // Set PRU to controll
if( !m_pSOC->setMotorMonitoringMode( m_sPARAMETERS.flags.VerticalMotorOn , m_sPARAMETERS.flags.HorizontalMotorOn ) ){ LOG_ERROR("Set Motor's Monitor Mode Failure"); return; };
if( !m_pSOC->setMotorInterleaveMode( m_sPARAMETERS.flags.QQinterlace ) ) { LOG_ERROR("Set Motor's Interleave Mode Failure"); return; }; if( !m_pSOC->setMotorSetPoints( m_sPARAMETERS.flags.VerticalFreq , m_sPARAMETERS.flags.HorizontalFreq ) ) { LOG_ERROR("Set Motor's Setpoints Failure"); return; }; } else { LOG_ERROR("Cannot get access to PWMSS module"); } }; };};
void LRF_HardwareManager::performStopMotors( void ){ if( m_sPARAMETERS.flags.TGZ_canENA ) { LOG("Stoping TGZ device"); if( m_pTGZdevice != NULL ) { m_pTGZdevice->setRunMode( false ); m_pTGZdevice->setErrorMode( true ); m_pTGZdevice->startDeviceStateInquiry(); } else { LOG_ERROR("Error TGZ Device object!" ); }; } else { if( m_pSOC!=NULL && m_sPARAMETERS.flags.isMaster ){ //if( m_sPARAMETERS.flags.HorizontalMotorOn )
{ volatile sysPwmss *mH_PWMSS = NULL; LOG("Stop Horizontal Motor's PWM"); mH_PWMSS = m_pSOC->getPWMSS_CTRL( 2 ); if( mH_PWMSS!=NULL ){ // Set PWM to 0 timeout 10 msec.
int to = 2000; mH_PWMSS->ECAP_CAP4 = 1; while( ( to-- ) && ( mH_PWMSS->ECAP_CAP2 != 1 ) ) usleep(5); // Turn Off Timer
mH_PWMSS->ECAP_ECCTL2_bit.TSCTRSTOP = 1; // For Security switch Mode to eCap
mH_PWMSS->ECAP_ECCTL2_bit.CAP_APWM = 0; // Disable PWM;
mH_PWMSS->CLKCONFIG_bit.EPWMCLK_EN = 0; LOG("Horizontal Motor's PWM Stoped"); } else { LOG_ERROR("Can not Stop Motors PWMs"); return; }; //m_sPARAMETERS.flags.HorizontalMotorOn = 0;
}; //if( m_sPARAMETERS.flags.VerticalMotorOn )
{ volatile sysPwmss *mV_PWMSS = NULL; LOG("Stop Vertical Motor's PWM"); mV_PWMSS = m_pSOC->getPWMSS_CTRL( 1 ); if( mV_PWMSS!=NULL ){ // Set PWM to 0 timeout 10 msec.
int to = 2000; mV_PWMSS->ECAP_CAP4 = 1; while( ( to-- ) && ( mV_PWMSS->ECAP_CAP2 != 1 ) )usleep(5); // Turn Off Timer
mV_PWMSS->ECAP_ECCTL2_bit.TSCTRSTOP = 1; // For Security switch Mode to eCap
mV_PWMSS->ECAP_ECCTL2_bit.CAP_APWM = 0; // Disable PWM;
mV_PWMSS->CLKCONFIG_bit.EPWMCLK_EN = 0; LOG("Vertical Motor's PWM Stoped"); } else { LOG_ERROR("Can not Stop Motors PWMs"); return; }; //m_sPARAMETERS.flags.VerticalMotorOn = 0;
}; } else { LOG_ERROR("Slave Device Can not Stop Motors PWMs"); return; }; }; // TGZ - PWM
};#endif
bool LRF_HardwareManager::startMotors( bool Auto ){#ifdef THREADED_MOTORS_START
if( m_sPARAMETERS.flags.TGZ_canENA ) { if( !Auto ) { if( m_sPARAMETERS.flags.AutostartMotors == 0 ) { m_sPARAMETERS.flags.AutostartMotors = 1; saveCurrentParameters(); }; }; } else { if( !Auto ) { if( m_sPARAMETERS.flags.AutostartMotors == 0 || m_sPARAMETERS.flags.VerticalMotorOn == 0 || m_sPARAMETERS.flags.HorizontalMotorOn == 0 ) { m_sPARAMETERS.flags.VerticalMotorOn = 1; m_sPARAMETERS.flags.HorizontalMotorOn = 1; m_sPARAMETERS.flags.AutostartMotors = 1; saveCurrentParameters(); }; }; }; if( m_pMotorCtrlMutex != NULL ) { if( 0 == pthread_mutex_trylock( m_pMotorCtrlMutex ) ){ if( 0 != pthread_detach( *m_pMotorCtrlThreadHandler ) ){ LOG_ERROR("Thread Detach Failed!"); pthread_mutex_unlock( m_pMotorCtrlMutex ); }; if( 0 != pthread_create( m_pMotorCtrlThreadHandler, NULL, m_fMotorStartThreadFunction, ( void * ) this ) ) { LOG_ERROR("Thread Creation Faled."); pthread_mutex_unlock( m_pMotorCtrlMutex ); };#ifdef DEBUG
// LOG("TH Flip Thread Started");
#endif
} else {#ifdef DEBUG
// LOG("TH Flip Request Overlapped!");
#endif
}; };#else //THREADED_MOTORS_START
if( m_sPARAMETERS.flags.TGZ_canENA ) { LOG("Starting TGZ device"); if( m_pTGZdevice!= NULL ) { if( !Auto ) { if( m_sPARAMETERS.flags.AutostartMotors == 0 ) { m_sPARAMETERS.flags.AutostartMotors = 1; saveCurrentParameters(); }; };#ifndef TGD_VERSION_2
m_pTGZdevice->setDivider( m_sPARAMETERS.flags.TGZ_divider ); m_pTGZdevice->setPrfMode( m_sPARAMETERS.flags.TGZ_ParamQ ); m_pTGZdevice->setRatio( m_sPARAMETERS.flags.TGZ_ParamB );#else //TGD_VERSION_2
m_pTGZdevice->setSpeeds( m_sPARAMETERS.flags.TGZ_ParamQ, m_sPARAMETERS.flags.TGZ_ParamB );#endif //TGD_VERSION_2
m_pTGZdevice->setRunMode( true ); m_pTGZdevice->setErrorMode( true );
m_pTGZdevice->startDeviceStateInquiry();
//ToDo: Wait for TGD starts Motors!
//LOG( "Wait Startup TGZ");
//SLEEP(30000); // 30 seconds
//LOG( "Done");
} else { LOG_ERROR("Error TGZ Device object!" ); }; } else { volatile sysPwmss *mV_PWMSS = NULL; volatile sysPwmss *mH_PWMSS = NULL; LOG("StartMotorsProcedure"); if( m_pSOC!=NULL && m_sPARAMETERS.flags.isMaster ){ mV_PWMSS = m_pSOC->getPWMSS_CTRL( 1 ); mH_PWMSS = m_pSOC->getPWMSS_CTRL( 2 ); if( mV_PWMSS!=NULL && mH_PWMSS!=NULL ){ // Disable PWM;
LOG("Disable Motors PWMs"); mV_PWMSS->CLKCONFIG_bit.EPWMCLK_EN = 0; mH_PWMSS->CLKCONFIG_bit.EPWMCLK_EN = 0; while( mV_PWMSS->CLKCONFIG_bit.EPWMCLK_EN == 1 || mH_PWMSS->CLKCONFIG_bit.EPWMCLK_EN == 1 )usleep(5); LOG("Disable Motors PWMs - Done"); // Polarity
mV_PWMSS->ECAP_ECCTL2_bit.APWMPOL = PWM_POLARITY_INVERSE; mH_PWMSS->ECAP_ECCTL2_bit.APWMPOL = PWM_POLARITY_INVERSE;
LOG("Set Motors PWMs Config"); // Set PWM Period
mV_PWMSS->ECAP_CAP3 = VM_WORK_PERIOD; mH_PWMSS->ECAP_CAP3 = HM_WORK_PERIOD; mV_PWMSS->ECAP_CAP1 = VM_WORK_PERIOD; mH_PWMSS->ECAP_CAP1 = HM_WORK_PERIOD; LOG("Set Motors PWMs Period"); // Set Intitial Zeroes DC
mV_PWMSS->ECAP_CAP4 = 1; mH_PWMSS->ECAP_CAP4 = 1; mV_PWMSS->ECAP_CAP2 = 1; mH_PWMSS->ECAP_CAP2 = 1; LOG("Set Motors PWMs DC"); // Config Timer
// Running
//ECCTL1: 0x00008000
//ECCTL2: 0x000006D6
// Stoped
//ECCTL1: 0x00008000
//ECCTL2: 0x000004C6
mV_PWMSS->ECAP_ECCTL1 = 0; mV_PWMSS->ECAP_ECCTL1_bit.FREE_SOFT = 2; mV_PWMSS->ECAP_ECCTL2_bit.TSCTRSTOP = 1; mH_PWMSS->ECAP_ECCTL1 = 0; mH_PWMSS->ECAP_ECCTL1_bit.FREE_SOFT = 2; mH_PWMSS->ECAP_ECCTL2_bit.TSCTRSTOP = 1; // Set APWM mode
mV_PWMSS->ECAP_ECCTL2_bit.CAP_APWM = 1; mH_PWMSS->ECAP_ECCTL2_bit.CAP_APWM = 1; // Set module enable
mV_PWMSS->CLKCONFIG_bit.EPWMCLK_EN = 1; mH_PWMSS->CLKCONFIG_bit.EPWMCLK_EN = 1; LOG("Set Motors PWMs Enabled"); uint32_t index = 0; LOG("Start Motors PWMs Spin Up"); while( index < VM_WORK_DUTY_CYCLE || index < HM_WORK_DUTY_CYCLE ){ if( index < VM_WORK_DUTY_CYCLE ){ mV_PWMSS->ECAP_CAP4 = index; while( mV_PWMSS->ECAP_CAP2 != index )usleep(5); }; if( index < HM_WORK_DUTY_CYCLE ){ mH_PWMSS->ECAP_CAP4 = index; while( mH_PWMSS->ECAP_CAP2 != index )usleep(5); }; usleep( 700 ); //700 microseconds;
index++; }; LOG("Motors PWMs Spin Up Done"); // Set PRU to controll
if( !Auto ) { if( m_sPARAMETERS.flags.AutostartMotors == 0 || m_sPARAMETERS.flags.VerticalMotorOn == 0 || m_sPARAMETERS.flags.HorizontalMotorOn == 0 ) { m_sPARAMETERS.flags.VerticalMotorOn = 1; m_sPARAMETERS.flags.HorizontalMotorOn = 1; m_sPARAMETERS.flags.AutostartMotors = 1; saveCurrentParameters(); }; }; if( !m_pSOC->setMotorMonitoringMode( m_sPARAMETERS.flags.VerticalMotorOn , m_sPARAMETERS.flags.HorizontalMotorOn ) ){ LOG_ERROR("Set Motor's Monitor Mode Failure"); return false; };
if( !m_pSOC->setMotorInterleaveMode( m_sPARAMETERS.flags.QQinterlace ) ) { LOG_ERROR("Set Motor's Interleave Mode Failure"); return false; }; if( !m_pSOC->setMotorSetPoints( m_sPARAMETERS.flags.VerticalFreq , m_sPARAMETERS.flags.HorizontalFreq ) ) { LOG_ERROR("Set Motor's Setpoints Failure"); return false; }; } else { LOG_ERROR("Cannot get access to PWMSS module"); } }; };#endif //THREADED_MOTORS_START
return true;};bool LRF_HardwareManager::stopMotors( bool Auto ){#ifdef THREADED_MOTORS_START
if( m_sPARAMETERS.flags.TGZ_canENA ) { if( !Auto ) { if( m_sPARAMETERS.flags.AutostartMotors == 1 ) { m_sPARAMETERS.flags.AutostartMotors = 0; saveCurrentParameters(); }; }; } else { if( !Auto ) { if( m_sPARAMETERS.flags.AutostartMotors == 1 || m_sPARAMETERS.flags.VerticalMotorOn == 1 || m_sPARAMETERS.flags.HorizontalMotorOn == 1 ) { m_sPARAMETERS.flags.VerticalMotorOn = 0; m_sPARAMETERS.flags.HorizontalMotorOn = 0; m_sPARAMETERS.flags.AutostartMotors = 0; saveCurrentParameters(); }; }; }; if( m_pMotorCtrlMutex != NULL ) { if( 0 == pthread_mutex_trylock( m_pMotorCtrlMutex ) ){ if( 0 != pthread_detach( *m_pMotorCtrlThreadHandler ) ){ LOG_ERROR("Thread Detach Failed!"); pthread_mutex_unlock( m_pMotorCtrlMutex ); }; if( 0 != pthread_create( m_pMotorCtrlThreadHandler, NULL, m_fMotorStopThreadFunction, ( void * ) this ) ) { LOG_ERROR("Thread Creation Faled."); pthread_mutex_unlock( m_pMotorCtrlMutex ); };#ifdef DEBUG
// LOG("TH Flip Thread Started");
#endif
} else {#ifdef DEBUG
// LOG("TH Flip Request Overlapped!");
#endif
}; };#else //THREADED_MOTORS_START
if( m_sPARAMETERS.flags.TGZ_canENA ) { LOG("Stoping TGZ device"); if( m_pTGZdevice != NULL ) { if( !Auto ) { if( m_sPARAMETERS.flags.AutostartMotors == 1 ) { m_sPARAMETERS.flags.AutostartMotors = 0; saveCurrentParameters(); }; }; m_pTGZdevice->setRunMode( false ); m_pTGZdevice->setErrorMode( true ); m_pTGZdevice->startDeviceStateInquiry(); } else { LOG_ERROR("Error TGZ Device object!" ); }; } else { if( m_pSOC!=NULL && m_sPARAMETERS.flags.isMaster ){ if( m_sPARAMETERS.flags.HorizontalMotorOn ) { volatile sysPwmss *mH_PWMSS = NULL; LOG("Stop Horizontal Motor's PWM"); mH_PWMSS = m_pSOC->getPWMSS_CTRL( 2 ); if( mH_PWMSS!=NULL ){ // Set PWM to 0 timeout 10 msec.
int to = 2000; mH_PWMSS->ECAP_CAP4 = 1; while( ( to-- ) && ( mH_PWMSS->ECAP_CAP2 != 1 ) ) usleep(5); // Turn Off Timer
mH_PWMSS->ECAP_ECCTL2_bit.TSCTRSTOP = 1; // For Security switch Mode to eCap
mH_PWMSS->ECAP_ECCTL2_bit.CAP_APWM = 0; // Disable PWM;
mH_PWMSS->CLKCONFIG_bit.EPWMCLK_EN = 0; LOG("Horizontal Motor's PWM Stoped"); } else { LOG_ERROR("Can not Stop Motors PWMs"); return false; }; }; if( m_sPARAMETERS.flags.VerticalMotorOn ) { volatile sysPwmss *mV_PWMSS = NULL; LOG("Stop Vertical Motor's PWM"); mV_PWMSS = m_pSOC->getPWMSS_CTRL( 1 ); if( mV_PWMSS!=NULL ){ if( !Auto ) { if( m_sPARAMETERS.flags.AutostartMotors == 1 || m_sPARAMETERS.flags.VerticalMotorOn == 1 || m_sPARAMETERS.flags.HorizontalMotorOn == 1 ) { m_sPARAMETERS.flags.VerticalMotorOn = 0; m_sPARAMETERS.flags.HorizontalMotorOn = 0; m_sPARAMETERS.flags.AutostartMotors = 0; saveCurrentParameters(); }; }; // Set PWM to 0 timeout 10 msec.
int to = 2000; mV_PWMSS->ECAP_CAP4 = 1; while( ( to-- ) && ( mV_PWMSS->ECAP_CAP2 != 1 ) )usleep(5); // Turn Off Timer
mV_PWMSS->ECAP_ECCTL2_bit.TSCTRSTOP = 1; // For Security switch Mode to eCap
mV_PWMSS->ECAP_ECCTL2_bit.CAP_APWM = 0; // Disable PWM;
mV_PWMSS->CLKCONFIG_bit.EPWMCLK_EN = 0; LOG("Vertical Motor's PWM Stoped"); } else { LOG_ERROR("Can not Stop Motors PWMs"); return false; }; }; } else { LOG_ERROR("Slave Device Can not Stop Motors PWMs"); return false; }; }; // TGZ <-> PWM
#endif // THREADED_MOTORS_START
return true;};
static uint32_t nMemoryDumpID = 0;
thresholdNode *LRF_HardwareManager::getWorkingMemory( void ){ if( m_pSOC!= NULL ){ thresholdNode *tNode; thresholdNode *rNode; rNode = tNode = (thresholdNode *) m_pSOC->getTH_MEMORY(); if( m_bDumpMemoryToDisk ) { if( tNode != NULL ) { LOG( "Save Memory Dump!"); FILE *fd; char tName[64]; for( int index = 0; index < KERNEL_COUNT; index++ ) { sprintf( tName, "memdump_%03d-%02d.raw", nMemoryDumpID, index ); fd = fopen(tName, "wb+"); if( fd != NULL ) { uint32_t tSize; tSize = TH_SIZE_NODES; fwrite( &tSize, sizeof(uint32_t), 1, fd ); fwrite( tNode, sizeof(thresholdNode), TH_SIZE_NODES, fd ); fclose(fd); } else { LOG_ERROR( "Mem Dump Failure!"); }; tNode += TH_SIZE_NODES; }; nMemoryDumpID++; }; }; return rNode; }; return NULL;};
int LRF_HardwareManager::getWorkingMemoryID( void ){ return ( nMemoryDumpID - 1 );};
uint32_t *LRF_HardwareManager::getEventMemory( void ){ if( m_pSOC!= NULL ){ return m_pSOC->getEVT_MEMORY(); }; return NULL;};
bool LRF_HardwareManager::getDetectionStatus( DT_STATUS &Status ){ if( m_pSOC!=NULL ){ *((uint32_t*)&m_sCS_Detector) = m_pSOC->getThCoreStatus(); Status = m_sCS_Detector; if( Status.online ) return true; }; return false;};
bool LRF_HardwareManager::getDetectionParams( TH_PARAMS &Params ){ if( m_pSOC!=NULL ){ *((uint32_t*)&m_sCP_Detector) = m_pSOC->getThCoreParams(); Params = m_sCP_Detector; if( m_sCP_Detector.self_build_ena ) { m_nDetectionFilter = 0xFF; }; return true; }; return false;};
bool LRF_HardwareManager::setDetectionParams( TH_PARAMS *Params ){ if(Params == NULL) return false; memcpy( &m_sPARAMETERS, Params, sizeof(LGS_PARAMETERS) ); if( m_pSOC!=NULL ){ // Save into settings
m_sCP_Detector.delta = m_sPARAMETERS.nDelta; m_sCP_Detector.flip_size = m_sPARAMETERS.nFlip; m_sCP_Detector.good_points = m_sPARAMETERS.nGPointSamples; m_sCP_Detector.offset = m_sPARAMETERS.nOffset; m_sCP_Detector.order = m_sPARAMETERS.nOrder; m_sCP_Detector.self_build_ena = m_sPARAMETERS.flags.BuildThByCore; m_sCP_Detector.master = m_sPARAMETERS.flags.isMaster;
#ifdef DEBUG
char Buffer[256]; sprintf( Buffer, "Detector[%s] NEW Parameters: Delta[%d] Flip_Size[%d] Good_Points[%d] Order[%d] Offset[%d] TH_Automatic_Build[%d]", ((m_sCP_Detector.master)?"M":"S"), m_sCP_Detector.delta, m_sCP_Detector.flip_size, m_sCP_Detector.good_points, m_sCP_Detector.order, m_sCP_Detector.offset, m_sCP_Detector.self_build_ena ); LOG( Buffer );#endif
// Apply new Parameters
if(!m_pSOC->setThCoreParams(Params)){ LOG_ERROR("Detection Core Set NEW Params Failure"); return false; }; *((uint32_t*)&m_sCP_Detector) = m_pSOC->getThCoreParams(); saveCurrentParameters(); return true; }; return false;};
#ifdef SIMULATE_FLIPS
static uint32_t pips_counter = 1;#endif
//static uint32_t stam = 0;
bool LRF_HardwareManager::validateCores( void ){ if( !m_bInitOK ) return false;
#ifdef SIMULATE_FLIPS
pips_counter++;#endif
if( m_pSOC != NULL ){ *((uint32_t*)&m_sCS_Motors) = m_pSOC->getMotorStatus(); if( m_sCS_Motors.online ){ bool tErrors = false; if( m_sCS_Motors.param_err ) { LOG_ERROR("Motor Parameter Error!"); tErrors = true; }; if( m_sCS_Motors.h_motor_en && !m_sCS_Motors.h_motor_ok ) { LOG_ERROR("Basis Motor Error!"); tErrors = true; }; if( m_sCS_Motors.v_motor_en && !m_sCS_Motors.v_motor_ok ) { LOG_ERROR("Mirror Block Motor Error!"); tErrors = true; }; if( tErrors )return false; }; *((uint32_t*)&m_sCS_Detector) = m_pSOC->getThCoreStatus(); *((uint32_t*)&m_sCP_Detector) = m_pSOC->getThCoreParams(); if( m_sCP_Detector.self_build_ena ) { m_nDetectionFilter = 0xFF; }; if( m_sCS_Detector.online ) {#ifdef SIMULATE_FLIPS
if( ( pips_counter % 100 ) == 0 ){ LOG("INJECT Flip Request!"); m_pSOC->injectThCoreRequest( CORE3_REQ_FLIP_TH ); };#endif
#ifdef THREADED_FLIP
if( m_bFlipUnlockRequested ){ #ifdef DEBUG
LOG("Unlocking Flip protecting Mutex"); #endif
if( m_pFlipMutex != NULL ){ if( 0 != pthread_mutex_unlock( m_pFlipMutex ) ){ LOG_ERROR("Error Unlocking Flip protecting Mutex!"); }; }; m_bFlipUnlockRequested = false; };#endif
if( m_sCS_Detector.req ) {#ifdef DEBUG
LOG("Detector CORE REQ");#endif
uint32_t mCoreReq; mCoreReq = m_pSOC->getThCoreRequest(); switch( mCoreReq ) { case CORE3_REQ_FLIP_TH:{#ifdef THREADED_FLIP
if( m_pFlipMutex != NULL ) { if( 0 == pthread_mutex_trylock( m_pFlipMutex ) ){ if( !m_bWaitFirstFlip ) { if( 0 != pthread_detach( *m_pFlipThreadHandler ) ){ LOG_ERROR("Thread Detach Failed!"); pthread_mutex_unlock( m_pFlipMutex ); }; } else m_bWaitFirstFlip = false; #ifdef DEBUG
LOG("Build Working Threshold Memories MT Mode!"); #endif
if( 0 != pthread_create( m_pFlipThreadHandler, NULL, m_fFlipThreadFunction, ( void * ) this ) ) { LOG_ERROR("Thread Creation Faled."); pthread_mutex_unlock( m_pFlipMutex ); }; #ifdef DEBUG
LOG("TH Flip Thread Started"); #endif
} else { #ifdef DEBUG
LOG("TH Flip Request Overlapped!"); #endif
}; }#else
#ifdef DEBUG
LOG("Build Working Threshold Memories NT Mode!"); #endif
if( performFlip() ){ #ifdef DEBUG
LOG("CORE REQ Done."); #endif
} else { LOG_ERROR("Building Detector's TH Error!"); };#endif
break; }; case CORE3_REQ_CLEAR_TH:{#ifdef DEBUG
LOG("Clear Threshold Memories");#endif
if( cleanTH(0) ){#ifdef DEBUG
//LOG("CORE REQ Done.");
#endif
} else { LOG_ERROR("Cleanup Detector's TH Error!"); } break; }; default:{ LOG_ERROR("Unrecognized Core Request!"); }; }; m_pSOC->clearThCoreRequest(); }; if( m_sCS_Detector.param_err ) { LOG_ERROR("Detector Parameter Error!"); return false; }; }; return true; } else { LOG_ERROR( "SOC Not Defined!"); }; return false;};
void LRF_HardwareManager::restartService( void ){ m_nFlipEnaFLags = 0; m_nDetectionFilter = 0;};
bool LRF_HardwareManager::reset( bool Hard ){ uint8_t lrfID; m_nFlipEnaFLags = 0; m_nDetectionFilter = 0; if( Hard ){#ifdef DEBUG
LOG("Waiting Till Flip Process is Done");#endif
if( 0 == pthread_mutex_lock( m_pFlipMutex ) ){ if( 0 != pthread_detach( *m_pFlipThreadHandler ) ){ LOG_ERROR("Thread Detach Failed!"); }; };#ifdef DEBUG
LOG("Stoping Cores!");#endif
endService();#ifdef DEBUG
LOG("Begin Reset TH Mems");#endif
// Clear TH + Working TH
for( lrfID = 0; lrfID < ( KERNEL_COUNT << 1 ); lrfID++ ){#ifdef DEBUG
LOG("Cleanup TH");#endif
cleanTH( lrfID );#ifdef DEBUG
LOG("Done Cleanup TH");#endif
};#ifdef DEBUG
LOG("Starting Cores!");#endif
beginService();#ifdef DEBUG
LOG("Core Startup is Done!");#endif
pthread_mutex_unlock( m_pFlipMutex );#ifdef DEBUG
LOG("TH Reset is Done!");#endif
} else {#ifdef DEBUG
LOG("Waiting Till Flip Process is Done");#endif
if( 0 == pthread_mutex_lock( m_pFlipMutex ) ){ if( 0 != pthread_detach( *m_pFlipThreadHandler ) ){ LOG_ERROR("Thread Detach Failed!"); }; };#ifdef DEBUG
LOG("Begin Reset TH Mems");#endif
// Clean Only TH
for( lrfID = 0; lrfID < KERNEL_COUNT; lrfID++ ){#ifdef DEBUG
LOG("Cleanup TH");#endif
cleanTH( lrfID );#ifdef DEBUG
LOG("Done Cleanup TH");#endif
}; pthread_mutex_unlock( m_pFlipMutex );#ifdef DEBUG
LOG("TH Reset is Done!");#endif
}; return true;};
#ifdef THREADED_MOTORS_START
void *LRF_HardwareManager::m_fMotorStartThreadFunction( void *ptr ){ LRF_HardwareManager *me; me = (LRF_HardwareManager*)ptr; me->performStartMotors(); pthread_exit( NULL ); return NULL;};void *LRF_HardwareManager::m_fMotorStopThreadFunction( void *ptr ){ LRF_HardwareManager *me; me = (LRF_HardwareManager*)ptr; me->performStopMotors(); pthread_exit( NULL ); return NULL;};#endif
#ifdef THREADED_FLIP
void *LRF_HardwareManager::m_fFlipThreadFunction( void *ptr ){ LRF_HardwareManager *me; me = (LRF_HardwareManager*)ptr; me->performFlip(); me->m_bFlipUnlockRequested = true; pthread_exit( NULL ); return NULL;};#endif
static uint32_t m_sgnFlipCounter = 0;
#ifdef TH_NEW_FLIP_FUNC
bool LRF_HardwareManager::performFlip( void ){ if( !m_bInitOK ) return false; if( m_pSOC != NULL ){ char Buffer[256];//Used also in Event!!
volatile thresholdNode * th_node[16]; uint32_t LBA_ID; uint8_t LRF_ID; uint32_t cMax; uint32_t cMin; thresholdNode tTN; int32_t cNodeID; int32_t sNodeID; // Start point
bool QAreaOK;
th_node[0] = (volatile thresholdNode *) m_pSOC->getTH_MEMORY();#ifdef DEBUG
sprintf( Buffer, "NF TH pointer is: %p", th_node ); LOG( Buffer );#endif
if( th_node[0] != NULL ){ th_node[1] = th_node[0]+ TH_SIZE_NODES; th_node[2] = th_node[1]+ TH_SIZE_NODES; th_node[3] = th_node[2]+ TH_SIZE_NODES; th_node[4] = th_node[3]+ TH_SIZE_NODES; th_node[5] = th_node[4]+ TH_SIZE_NODES; th_node[6] = th_node[5]+ TH_SIZE_NODES; th_node[7] = th_node[6]+ TH_SIZE_NODES; th_node[8] = th_node[7]+ TH_SIZE_NODES; th_node[9] = th_node[8]+ TH_SIZE_NODES; th_node[10] = th_node[9]+ TH_SIZE_NODES; th_node[11] = th_node[10]+ TH_SIZE_NODES; th_node[12] = th_node[11]+ TH_SIZE_NODES; th_node[13] = th_node[12]+ TH_SIZE_NODES; th_node[14] = th_node[13]+ TH_SIZE_NODES; th_node[15] = th_node[14]+ TH_SIZE_NODES; // Set All TH as full of Good Points
m_nGPointsFlags = m_nKernelFilter; //0xFF
for( LRF_ID = 0; LRF_ID<KERNEL_COUNT; LRF_ID++ ){ //Filter Disabled Kernels
if( ((1 << LRF_ID ) & m_nKernelFilter ) == 0 ) continue; // Begin Scan Threshold
#ifdef DEBUG
sprintf( Buffer, "Building WTH for %dth Kernel", LRF_ID ); LOG( Buffer );#endif
for( LBA_ID = 0; LBA_ID < TH_SIZE_NODES; LBA_ID++ ){ uint32_t LocalStrideX = LBA_ID % TH_LINE_NODES; uint32_t LocalStrideY = LBA_ID / TH_LINE_NODES; // Get Central TH Point
tTN.data = th_node[LRF_ID][LBA_ID].data; // if point was blocked by SunBit
if( tTN.values.sbit ) { tTN.values.sbit = 0; tTN.values.cnt = 0; tTN.values.min = 0; tTN.values.max = 4095; for( int x = -m_sPARAMETERS.nOrder; x < (m_sPARAMETERS.nOrder+1); x++ ) { for( int y = -m_sPARAMETERS.nOrder; y < (m_sPARAMETERS.nOrder+1); y++ ) { int LocalX = LocalStrideX+x; int LocalY = LocalStrideY+y; if( LocalY < 0 ) LocalY += Q_SCAN_COUNT; if( LocalY >= Q_SCAN_COUNT ) LocalY -= Q_SCAN_COUNT; if( LocalX < 0 ) LocalX += M_SCAN_POINTS; if( LocalX >= TH_LINE_NODES ) LocalX -= TH_LINE_NODES; uint32_t CleanID = ( LocalY * TH_LINE_NODES ) + LocalX; th_node[8|LRF_ID][CleanID].data = tTN.data; }; }; continue; }; // if point was measured
#ifdef STRONG_STAT
if( tTN.values.cnt >= m_sPARAMETERS.nGPointSamples ){#else
if( tTN.values.cnt ){#endif
cMax = 0; cMin = 4095; QAreaOK = true; for( int x = -m_sPARAMETERS.nOrder; x < (m_sPARAMETERS.nOrder+1); x++ ) { for( int y = -m_sPARAMETERS.nOrder; y < (m_sPARAMETERS.nOrder+1); y++ ) { int LocalX = LocalStrideX+x; int LocalY = LocalStrideY+y; if( LocalY < 0 ) LocalY += Q_SCAN_COUNT; if( LocalY >= Q_SCAN_COUNT ) LocalY -= Q_SCAN_COUNT; if( LocalX < 0 ) LocalX += M_SCAN_POINTS; if( LocalX >= TH_LINE_NODES ) LocalX -= TH_LINE_NODES; uint32_t TestID = ( LocalY * TH_LINE_NODES ) + LocalX;
tTN.data = th_node[LRF_ID][TestID].data;#ifdef STRONG_STAT
if( tTN.values.cnt >= m_sPARAMETERS.nGPointSamples ){#else
if( tTN.values.cnt ){#endif
if( cMax < tTN.values.max ) cMax = tTN.values.max; if( cMin > tTN.values.min ) cMin = tTN.values.min; } else { QAreaOK = false; break; }; }; if( !QAreaOK ) break; }; if( QAreaOK ){ tTN.values.cnt = 0x0F; tTN.values.min =(cMin>m_sCP_Detector.offset)?cMin-m_sCP_Detector.offset:0; tTN.values.max =(cMax<(4095-m_sCP_Detector.offset))?cMax+m_sCP_Detector.offset:4095; } else { // disable detection of that point
tTN.values.cnt = 0; tTN.values.min = 0; tTN.values.max = 4095;#ifdef STRONG_STAT
// Clear GoodPoint Flags at not complete TH Measurement
// Turn off TH Clean
m_nGPointsFlags &= ~( 1 << LRF_ID );#endif
}; } else { // Not Enought points in values.cnt
// disable detection of that point
tTN.values.cnt = 0;#ifndef TH_JUST_UPDATE_WORKING
tTN.values.min = 0; tTN.values.max = 4095;#endif
// Clear GoodPoint Flags at not measured point
// Turn off TH Clean
m_nGPointsFlags &= ~( 1 << LRF_ID ); };#ifdef TH_JUST_UPDATE_WORKING
// Just Update - Without Remove TH Old Info
if( tTN.values.cnt ){ th_node[8|LRF_ID][LBA_ID].data = tTN.data; };#else
th_node[8|LRF_ID][LBA_ID].data = tTN.data;#endif
}; };#ifdef DEBUG
LOG("Finish Cycle");#endif
#ifdef TH_FORCED_BOOM_CLEAN
for( LRF_ID = 0; LRF_ID < KERNEL_COUNT; LRF_ID++ ){ if( m_nFlipEnaFLags & (1<<LRF_ID) ){ if( m_bTHSteadyCounter[LRF_ID] ){ m_bTHSteadyCounter[LRF_ID] --; } else { #ifdef DEBUG
sprintf( Buffer, "Cleanup TH%d", LRF_ID ); LOG(Buffer); #endif
cleanTH( LRF_ID ); #ifdef DEBUG
sprintf( Buffer, "Done Cleanup TH%d", LRF_ID ); LOG( Buffer ); #endif
m_bTHSteadyCounter[LRF_ID] = m_sCP_Detector.good_points; }; }; };#endif //TH_FORCED_BOOM_CLEAN
// To perform cleaning of Threshold next time
m_nFlipEnaFLags = m_nGPointsFlags; // To Enable Detection
m_nDetectionFilter |= m_nGPointsFlags; m_sgnFlipCounter++;
sprintf( Buffer, "Flip#%d is Done: 0x%X", m_sgnFlipCounter, m_nFlipEnaFLags );#ifdef DEBUG
LOG( Buffer );#endif
if( m_bDumpMemoryToDisk && ( ( m_sgnFlipCounter % 6 ) == 0 ) ) { thresholdNode *tNode; thresholdNode *rNode; rNode = tNode = (thresholdNode *) m_pSOC->getTH_MEMORY(); if( tNode != NULL ) { LOG( "Save Memory Dump!"); FILE *fd; char tName[64]; for( int index = 0; index < KERNEL_COUNT; index++ ) { sprintf( tName, "memdump_%03d-%02d.raw", nMemoryDumpID, index ); fd = fopen(tName, "wb+"); if( fd != NULL ) { uint32_t tSize; tSize = TH_SIZE_NODES; fwrite( &tSize, sizeof(uint32_t), 1, fd ); fwrite( tNode, sizeof(thresholdNode), TH_SIZE_NODES, fd ); fclose(fd); } else { LOG_ERROR( "Mem Dump Failure!"); }; tNode += TH_SIZE_NODES; }; nMemoryDumpID++; }; }; basicEvent *tEvt = createBasicEvent( 0, EVT_CLASS_SENSOR, EVT_FLIP, Buffer, NULL ); if( tEvt != NULL ){ basicEventHeap::getInstance()->broadcast( tEvt ); // Evt utilisation done by EventHeap thread
tEvt = NULL; };#ifdef HIBERNATE_ENABLE
return saveHibernatedTH();#else
return true;#endif
} else { LOG_ERROR("Cannot access TH Memory!"); }; } else { LOG_ERROR("No SOC Object!"); }; return false;};
#else // TH_NEW_FLIP_FUNC == 0
bool LRF_HardwareManager::performFlip( void ){ if( !m_bInitOK ) return false; if( m_pSOC != NULL ){ char Buffer[256];#ifdef TH_PER_MIRROR
volatile thresholdNode *th_node[40];#else
volatile thresholdNode *th_node[16];#endif
uint32_t sampleID; uint8_t lrfID; uint32_t cMax; uint32_t cMin; thresholdNode tTN; int32_t cNodeID; int32_t sNodeID; // Start point
uint8_t QAreaOK; uint8_t i,j;
th_node[0] = (volatile thresholdNode *) m_pSOC->getTH_MEMORY(); th_node[1] = th_node[0]+ TH_SIZE_NODES; th_node[2] = th_node[1]+ TH_SIZE_NODES; th_node[3] = th_node[2]+ TH_SIZE_NODES; th_node[4] = th_node[3]+ TH_SIZE_NODES; th_node[5] = th_node[4]+ TH_SIZE_NODES; th_node[6] = th_node[5]+ TH_SIZE_NODES; th_node[7] = th_node[6]+ TH_SIZE_NODES; th_node[8] = th_node[7]+ TH_SIZE_NODES; th_node[9] = th_node[8]+ TH_SIZE_NODES; th_node[10] = th_node[9]+ TH_SIZE_NODES; th_node[11] = th_node[10]+ TH_SIZE_NODES; th_node[12] = th_node[11]+ TH_SIZE_NODES; th_node[13] = th_node[12]+ TH_SIZE_NODES; th_node[14] = th_node[13]+ TH_SIZE_NODES; th_node[15] = th_node[14]+ TH_SIZE_NODES;#ifdef TH_PER_MIRROR
th_node[16] = th_node[15]+ TH_SIZE_NODES; th_node[17] = th_node[16]+ TH_SIZE_NODES; th_node[18] = th_node[17]+ TH_SIZE_NODES; th_node[19] = th_node[18]+ TH_SIZE_NODES; th_node[20] = th_node[19]+ TH_SIZE_NODES; th_node[21] = th_node[20]+ TH_SIZE_NODES; th_node[22] = th_node[21]+ TH_SIZE_NODES; th_node[23] = th_node[22]+ TH_SIZE_NODES; th_node[24] = th_node[23]+ TH_SIZE_NODES; th_node[25] = th_node[24]+ TH_SIZE_NODES; th_node[26] = th_node[25]+ TH_SIZE_NODES; th_node[27] = th_node[26]+ TH_SIZE_NODES; th_node[28] = th_node[27]+ TH_SIZE_NODES; th_node[29] = th_node[28]+ TH_SIZE_NODES; th_node[30] = th_node[29]+ TH_SIZE_NODES; th_node[31] = th_node[30]+ TH_SIZE_NODES; th_node[32] = th_node[31]+ TH_SIZE_NODES; th_node[33] = th_node[32]+ TH_SIZE_NODES; th_node[34] = th_node[33]+ TH_SIZE_NODES; th_node[35] = th_node[34]+ TH_SIZE_NODES; th_node[36] = th_node[35]+ TH_SIZE_NODES; th_node[37] = th_node[36]+ TH_SIZE_NODES; th_node[38] = th_node[37]+ TH_SIZE_NODES; th_node[39] = th_node[38]+ TH_SIZE_NODES;#endif
sprintf( Buffer, "OF TH pointer is: %p", th_node ); LOG( Buffer ); m_nGPointsFlags = 0xFF;#ifdef DEBUG
//LOG("Performing FLIP in HOST SOC");
#endif
if( th_node != NULL ){#ifdef DEBUG
char tBuffer[128]; sprintf(tBuffer, "Start Cycle order: %d Good Points: %d", m_sPARAMETERS.nOrder, m_sPARAMETERS.nGPointSamples ); LOG( tBuffer );#endif
for( sampleID=0; sampleID < TH_SIZE_NODES; sampleID++ ){ sNodeID = sampleID - ( TH_LINE_NODES + 1 ) * m_sCP_Detector.order;#ifdef TH_PER_MIRROR
for( lrfID = 0; lrfID < KERNEL_COUNT * Q_MIRROR_COUNT; lrfID++ ){#else
for( lrfID = 0; lrfID < KERNEL_COUNT; lrfID++ ){#endif
//Filter Kernel
if( ((1 << lrfID ) & m_nKernelFilter ) == 0 ) continue; // Get Central TH Point
tTN.data = th_node[lrfID][sampleID].data; // if point was measured
//if( tTN.values.cnt >= m_sCP_Detector.good_points ){
#ifdef STRONG_STAT
if( tTN.values.cnt >= m_sPARAMETERS.nGPointSamples ){#else
if( tTN.values.cnt ){#endif
cMax = 0; cMin = 4095; QAreaOK = 1; //for( i = 0; i < (( m_sCP_Detector.order << 1 ) + 1 ); i++ ){
for( i = 0; i < (( m_sPARAMETERS.nOrder << 1 ) + 1 ); i++ ){ cNodeID = sNodeID + ( i * TH_LINE_NODES ); //for( j = 0; j < (( m_sCP_Detector.order << 1 ) + 1 ); j++ ){
for( j = 0; j < (( m_sPARAMETERS.nOrder << 1 ) + 1 ); j++ ){ cNodeID ++; if( cNodeID < 0 ) continue; if( cNodeID < TH_SIZE_NODES ){ tTN.data = th_node[lrfID][cNodeID].data;#ifdef STRONG_STAT
if( tTN.values.cnt >= m_sPARAMETERS.nGPointSamples ){#else
if( tTN.values.cnt ){#endif
if( cMax < tTN.values.max ) cMax = tTN.values.max; if( cMin > tTN.values.min ) cMin = tTN.values.min; } else { QAreaOK = 0; break; }; }; }; if( QAreaOK == 0 ) break; }; if( QAreaOK == 0 ){ // disable detection of that point
tTN.values.cnt = 0; tTN.values.min = 0; tTN.values.max = 4095; } else { tTN.values.cnt = 0x0F; tTN.values.min =(cMin>m_sCP_Detector.offset)?cMin-m_sCP_Detector.offset:0; tTN.values.max =(cMax<(4095-m_sCP_Detector.offset))?cMax+m_sCP_Detector.offset:4095; }; } else { // Not Enought points in values.cnt
// disable detection of that point
tTN.values.cnt = 0;#ifndef TH_JUST_UPDATE_WORKING
tTN.values.min = 0; tTN.values.max = 4095;#endif
// Clear GoodPoint Flags at not measured point
m_nGPointsFlags &=~(1<<lrfID); };#ifdef TH_JUST_UPDATE_WORKING
// Just Update - Without Remove TH Old Info
if( tTN.values.cnt ){#endif
#ifdef TH_PER_MIRROR
th_node[20|( lrfID >> 2 )][sampleID].data = tTN.data;#else
th_node[8|lrfID][sampleID].data = tTN.data;#endif
#ifdef TH_JUST_UPDATE_WORKING
};#endif
}; };#ifdef DEBUG
//LOG("Finish Cycle");
#endif
#ifdef TH_FORCED_BOOM_CLEAN
for( lrfID = 0; lrfID < KERNEL_COUNT; lrfID++ ){ if( m_nFlipEnaFLags & (1<<lrfID) ){#ifdef DEBUG
sprintf( Buffer, "Cleanup TH%d", lrfID ); LOG(Buffer);#endif
cleanTH( lrfID );#ifdef DEBUG
sprintf( Buffer, "Done Cleanup TH%d", lrfID ); LOG( Buffer );#endif
}; };#endif //TH_FORCED_BOOM_CLEAN
// To perform cleaning of Threshold next time
m_nFlipEnaFLags = m_nGPointsFlags; // To Enable Detection
m_nDetectionFilter |= m_nGPointsFlags; m_sgnFlipCounter++; sprintf( Buffer, "Flip#%d is Done: 0x%X", m_sgnFlipCounter, m_nFlipEnaFLags );#ifdef DEBUG
LOG( Buffer );#endif
if( m_bDumpMemoryToDisk && ( ( m_sgnFlipCounter % 6 ) == 0 ) ) { thresholdNode *tNode; thresholdNode *rNode; rNode = tNode = (thresholdNode *) m_pSOC->getTH_MEMORY(); if( tNode != NULL ) { LOG( "Save Memory Dump!"); FILE *fd; char tName[64]; for( int index = 0; index < KERNEL_COUNT; index++ ) { sprintf( tName, "memdump_%03d-%02d.raw", nMemoryDumpID, index ); fd = fopen(tName, "wb+"); if( fd != NULL ) { uint32_t tSize; tSize = TH_SIZE_NODES; fwrite( &tSize, sizeof(uint32_t), 1, fd ); fwrite( tNode, sizeof(thresholdNode), TH_SIZE_NODES, fd ); fclose(fd); } else { LOG_ERROR( "Mem Dump Failure!"); }; tNode += TH_SIZE_NODES; }; nMemoryDumpID++; }; }; basicEvent *tEvt = createBasicEvent( 0, EVT_CLASS_SENSOR, EVT_FLIP, Buffer, NULL ); if( tEvt != NULL ){ basicEventHeap::getInstance()->broadcast( tEvt ); // Evt utilisation done by EventHeap thread
tEvt = NULL; };#ifdef HIBERNATE_ENABLE
return saveHibernatedTH();#else
return true;#endif
} else { LOG_ERROR("Cannot access TH Memory!"); }; }; return false;};#endif //TH_NEW_FLIP_FUNC
#ifdef HIBERNATE_ENABLE
bool LRF_HardwareManager::saveHibernatedTH( CSTR fname ){ FILE *fd; fd = fopen( fname, "wb+" ); if( fd!= NULL) { uint32_t *mem; uint32_t size; mem = m_pSOC->getTH_MEMORY(); if(mem!= NULL) { size = TH_SIZE_NODES << 4; fwrite( &mem, sizeof(mem), 1, fd ); // origin
fwrite( &size, sizeof(size), 1, fd ); // size
fwrite( mem, sizeof(size), size, fd ); // content
} else { LOG_ERROR("Can not access to TH memories during save Hibernate!"); return false; }; fclose( fd ); } else { LOG_ERROR("Can not create Hibernate File!"); return false; }; return true;};bool LRF_HardwareManager::loadHibernatedTH( CSTR fname ){ FILE *fd; fd = fopen( fname, "wb+" ); if( fd!= NULL) { uint32_t *mem; uint32_t *pem; uint32_t size; mem = m_pSOC->getTH_MEMORY(); if(mem!= NULL) { fread( &pem, sizeof(mem), 1, fd ); // origin
fread( &size, sizeof(size), 1, fd ); // size
fread( mem, sizeof(size), size, fd ); // content
} else { LOG_ERROR("Can not access to TH memories during load Hibernate!"); return false; }; fclose( fd ); } else { LOG_ERROR("Can not read Hibernate File!"); return false; }; return true;};#endif
bool LRF_HardwareManager::cleanTH( uint8_t tID ){ if( m_pSOC != NULL ) { uint32_t *thPtr; thPtr = m_pSOC->getTH_MEMORY(); if( thPtr ){ thPtr += ( tID & 0x0F ) * TH_SIZE_NODES; int index = 0; // fl|Max|Min
for(; index < TH_SIZE_NODES; thPtr++, index++ ) *thPtr = 0x00000FFF; return true; }; }; return false;};
void LRF_HardwareManager::saveCurrentParameters( void ){ if( m_pSettings != NULL ) { config_setting_t *pSetting; int tVal; char tBuffer[256]; LOG("HW Saving Settings ..."); if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_TH_DUMP ) ){ tVal = m_bDumpMemoryToDisk; config_setting_set_bool( pSetting, tVal ); m_pSettingsProvider->compromise(); } else { LOG_ERROR( "Error Saving Settings!" ); return; }; if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_ROLE ) ){ tVal = m_sPARAMETERS.flags.isMaster; config_setting_set_bool( pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No role defined"); } else { LOG_ERROR( "Error Saving Settings!" ); return; }; if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_SUNBIT ) ){ tVal = m_sPARAMETERS.flags.Sunbit_filter; config_setting_set_bool( pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No SUNBIT action defined - Disabling!"); } else { LOG_ERROR( "Error Saving Settings!" ); return; }; if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_LRF_ENABLED ) ){ tVal = m_sPARAMETERS.flags.LaserPulsesOn; config_setting_set_bool( pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No LRF Enabled"); } else { LOG_ERROR( "Error Saving Settings!" ); return; }; if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_SIG_SYMULATOR ) ){ tVal = m_sPARAMETERS.flags.SignalSimulator; config_setting_set_bool( pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No Sig Symulator Settings"); } else { LOG_ERROR( "Error Saving Settings!" ); return; }; if( !m_sPARAMETERS.flags.SignalSimulator ) { if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_AUTOSTART_ENABLED ) ){ tVal = m_sPARAMETERS.flags.AutostartMotors; config_setting_set_bool( pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No Motor Autostart Settings"); } else { LOG_ERROR( "Error Saving Settings!" ); return; }; if( !m_sPARAMETERS.flags.AutostartMotors ) { if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_CTRL_V_MOTOR ) ){ tVal = m_sPARAMETERS.flags.VerticalMotorOn; config_setting_set_bool( pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No Vertical Controll"); } else { LOG_ERROR( "Error Saving Settings!" ); return; }; if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_CTRL_H_MOTOR ) ){ tVal = m_sPARAMETERS.flags.HorizontalMotorOn; config_setting_set_bool( pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No Horizontal Controll"); } else { LOG_ERROR( "Error Saving Settings!" ); return; }; }; } if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_V_MOTOR_SETPOINT ) ){ tVal = m_sPARAMETERS.flags.VerticalFreq; config_setting_set_int(pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No Mirror Block Freq"); } else { LOG_ERROR( "Error Saving Settings!" ); return; }; if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_H_MOTOR_SETPOINT ) ){ tVal = m_sPARAMETERS.flags.HorizontalFreq; config_setting_set_int(pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No Base Block Freq"); } else { LOG_ERROR( "Error Saving Settings!" ); return; }; if ( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_V_PULSES_INTERLEAVE ) ){ tVal = m_sPARAMETERS.flags.QQinterlace; config_setting_set_int(pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No Q Pulses per LRF pulse Setting"); } else { LOG_ERROR( "Error Saving Settings!" ); return; }; if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_TH_OFFSET ) ){ tVal = m_sPARAMETERS.nOffset; config_setting_set_int(pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No TH Offset Setting"); } else { LOG_ERROR( "Error Saving Settings!" ); return; }; if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_TH_ORDER ) ){ tVal = m_sPARAMETERS.nOrder; config_setting_set_int(pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No TH Order Setting"); } else { LOG_ERROR( "Error Saving Settings!" ); return; }; if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_TH_DELTA ) ){ tVal = m_sPARAMETERS.nDelta; config_setting_set_int(pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No TH Delta Setting"); } else { LOG_ERROR( "Error Saving Settings!" ); return; }; if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_TH_FLIP_SIZE ) ){ tVal = m_sPARAMETERS.nFlip; config_setting_set_int(pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No TH Flip Size Setting"); } else { LOG_ERROR( "Error Saving Settings!" ); return; }; if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_TH_GOOD_POINTS ) ){ tVal = m_sPARAMETERS.nGPointSamples; config_setting_set_int(pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No TH Good Points Setting"); } else { LOG_ERROR( "Error Saving Settings!" ); return; }; if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_AUTO_TH_GENERATE ) ){ tVal = m_sPARAMETERS.flags.BuildThByCore; config_setting_set_bool( pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No TH Build By Core Setting"); } else { LOG_ERROR( "Error Saving Settings!" ); return; }; if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_TH_SPIKE_SIZE ) ){ tVal = m_sPARAMETERS.flags.Spike_TH; config_setting_set_int(pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No Spike Threshold Setting"); } else { LOG_ERROR( "Error Saving Settings!" ); return; }; if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_CAN_CONTROL_ENABLE ) ){ tVal = m_sPARAMETERS.flags.TGZ_canENA; config_setting_set_bool( pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No CAN Enable Setting"); } else { LOG_ERROR( "Error Saving Settings!" ); return; }; if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_CAN_BUS_ID ) ){ tVal = m_sPARAMETERS.flags.TGZ_canBus; config_setting_set_int(pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No CAN Bus ID Setting"); } else { LOG_ERROR( "Error Saving Settings!" ); return; }; if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_CAN_MY_ID ) ){ tVal = m_sPARAMETERS.flags.TGZ_canSRC; config_setting_set_int(pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No CAN My ID Setting"); } else { LOG_ERROR( "Error Saving Settings!" ); return; }; if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_CAN_TGZ_ID ) ){ tVal = m_sPARAMETERS.flags.TGZ_canDST; config_setting_set_int(pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No CAN TGZ ID Setting"); } else { LOG_ERROR( "Error Saving Settings!" ); return; };#ifndef TGD_VERSION_2
if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_TGZ_DIVIDER ) ){ tVal = m_sPARAMETERS.flags.TGZ_divider; config_setting_set_int(pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No TGZ Divider Setting"); } else { LOG_ERROR( "Error Saving Settings!" ); return; }; if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_TGZ_PRF ) ){ tVal = m_sPARAMETERS.flags.TGZ_ParamQ; config_setting_set_int(pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No TGZ PRF Setting"); } else { LOG_ERROR( "Error Saving Settings!" ); return; }; if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_TGZ_RATIO ) ){ tVal = m_sPARAMETERS.flags.TGZ_ParamB; config_setting_set_int(pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No TGZ Ratio Setting"); } else { LOG_ERROR( "Error Saving Settings!" ); return; };#else
if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_TGZ_MIRROR_SPEED ) ){ tVal = m_sPARAMETERS.flags.TGZ_ParamQ; config_setting_set_int(pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No TGZ Mirror Block Speed"); } else { LOG_ERROR( "Error Saving Settings!" ); return; }; if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_TGZ_BASE_SPEED ) ){ tVal = m_sPARAMETERS.flags.TGZ_ParamB; config_setting_set_int(pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No TGZ Base Motor Speed"); } else { LOG_ERROR( "Error Saving Settings!" ); return; };#endif
if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_B_SHIFT ) ){ tVal = m_sPARAMETERS.flags.B_shift; config_setting_set_int(pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No Base Shift"); } else { LOG_ERROR( "Error Saving Settings!" ); return; }; if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_Q_SHIFT ) ){ tVal = m_sPARAMETERS.flags.Q_shift; config_setting_set_int(pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No Mirror Shift"); } else { LOG_ERROR( "Error Saving Settings!" ); return; }; if( m_pSettingsProvider->isCompromised() ) { LOG("Save Settings"); m_pSettingsProvider->validate(); }; };};
#undef LOG
#undef LOG_ERROR
|