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.
1771 lines
58 KiB
1771 lines
58 KiB
#include "objectLGS.h"
|
|
#include "../../gui/controls/OGLRadarWidget.h"
|
|
#include "../../gui/controls/RangeMapWidget.h"
|
|
|
|
#define LOG( X ) m_pLog->Log( (m_bIsMaster?"objectLGS[M]":"objectLGS[S]"), this, X )
|
|
#define LOG_ERROR( X ) m_pLog->Log( (m_bIsMaster?"objectLGS[M]":"objectLGS[S]"), this, _LOG_ERROR, X )
|
|
// Local Funcs
|
|
|
|
inline void make3D( uint32_t sid, float &az, float &el, bool master = true ){
|
|
if( master ){
|
|
el = ( sid / TH_LINE_NODES ) * ( Q_DEGREE_FOV / Q_SCAN_COUNT );
|
|
} else {
|
|
el = ( Q_SCAN_COUNT - ( sid / TH_LINE_NODES ) ) * ( Q_DEGREE_FOV / Q_BLOCK_COUNT );
|
|
};
|
|
az = ( sid % TH_LINE_NODES ) * 360.f / TH_LINE_NODES;
|
|
};
|
|
|
|
objectLGS::objectLGS(config_setting_t *Settings, bool Master) : basicObject(), basicDualThread(), protocolLGS_CLIENT(),
|
|
m_mStatusMutex(),
|
|
m_mPackageMutex(),
|
|
m_mDataMutex(){
|
|
m_pLog = basicLogCollection::getInstance();
|
|
m_pEventHeap = basicEventHeap::getInstance();
|
|
m_eCaps = OC_EVENT_GENERATOR;
|
|
m_eStatus = OS_STATUS_PREBORN;
|
|
m_nBusyCounter = 0;
|
|
m_nIdleCounter = 0;
|
|
m_nIdleTarget = LGS_MAX_IDLE_DELAY;
|
|
m_pThresholdData = NULL;
|
|
m_pRadarWidget = NULL;
|
|
m_pMapWidget = NULL;
|
|
m_bMasksAreLoadded = false;
|
|
m_nFullBorderDataIndex = 0;
|
|
m_bTransportStatus = true;//false;
|
|
m_bIsMaster = Master;
|
|
m_pPosition = new basicPosition();
|
|
m_pLGS_PARAMETERS = (PLGS_PARAMETERS) malloc(sizeof( LGS_PARAMETERS ));
|
|
memset(m_pLGS_PARAMETERS, 0, sizeof( LGS_PARAMETERS ));
|
|
memset(&m_sDeviceSoftNFO, 0, sizeof( SOFTWARE_INFO ));
|
|
m_sDeviceStatus.CurrentOperation = CMD_NONE;
|
|
m_sDeviceStatus.Status = STG_NONE;
|
|
m_sDeviceStatus.ComStatus = STG_REDY;
|
|
m_sDeviceStatus.ErrorOpCode = CMD_NONE;
|
|
m_sDeviceStatus.DoneByPercents = 0;
|
|
m_sDeviceStatus.ErrorOpStatus = SUB_DATA_INTEGRITY_UNKNOWN;
|
|
m_sDeviceStatus.PendingOperation = CMD_NONE;
|
|
m_sDeviceStatus.ProgressIsActive = false;
|
|
if( NULL == Settings ){
|
|
if( m_bIsMaster ) {
|
|
m_pSettings = basicSettingsProvider::getInstance()->getSubNode( Settings, LGS_SETTINGS_NODE_MASTER );
|
|
} else {
|
|
m_pSettings = basicSettingsProvider::getInstance()->getSubNode( Settings, LGS_SETTINGS_NODE_SLAVE );
|
|
};
|
|
} else {
|
|
m_pSettings = Settings;
|
|
};
|
|
m_eWorkMode = CWM_INIT;
|
|
};
|
|
|
|
objectLGS::~objectLGS(){
|
|
m_eStatus = OS_STATUS_DEAD;
|
|
//Kill Threads
|
|
m_mPackageMutex.unlock();
|
|
if (m_bThreadAStatus < TH_ENDED) waitThreadAEnd();
|
|
m_mPackageMutex.unlock();
|
|
if (m_bThreadBStatus < TH_ENDED) waitThreadBEnd();
|
|
// Close Communication Transport
|
|
if( m_pTransport!= NULL ){
|
|
m_pTransport->disconnect();
|
|
};
|
|
if (m_pTransport != NULL){
|
|
delete(m_pTransport);
|
|
};
|
|
//if( m_oProtocol != NULL ){
|
|
// delete( m_oProtocol );
|
|
//};
|
|
if ( m_pLGS_PARAMETERS != NULL) free(m_pLGS_PARAMETERS);
|
|
//OLD THPLACE
|
|
cleanDataTH();
|
|
if( m_pPosition ) delete( m_pPosition );
|
|
if( m_pShadow ) delete( m_pShadow );
|
|
};
|
|
|
|
bool objectLGS::create( void ){
|
|
// Check if Allredy Working
|
|
if ( m_bThreadAStatus > TH_ARMED ){
|
|
if( m_bThreadAStatus == TH_WORKING ) return true;
|
|
return false;
|
|
};
|
|
|
|
if (m_pSettings != NULL) {
|
|
config_setting_t *pSetting;
|
|
int tVal;
|
|
double tLon, tLat, tAlt;
|
|
double tYaw, tRoll, tPitch;
|
|
|
|
m_pShadow = new ShadowMask();
|
|
|
|
if (m_pShadow) m_pShadow->clear();
|
|
|
|
if (!config_setting_lookup_float(m_pSettings, TAG_POSITION_LAT, &tLat)){
|
|
tLat = m_pPosition->getLat();
|
|
pSetting = config_setting_add(m_pSettings, TAG_POSITION_LAT, CONFIG_TYPE_FLOAT);
|
|
config_setting_set_float(pSetting, tLat );
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
if (!config_setting_lookup_float(m_pSettings, TAG_POSITION_LON, &tLon)){
|
|
tLon = m_pPosition->getLon();
|
|
pSetting = config_setting_add(m_pSettings, TAG_POSITION_LON, CONFIG_TYPE_FLOAT);
|
|
config_setting_set_float(pSetting, tLon);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
if (!config_setting_lookup_float(m_pSettings, TAG_POSITION_ALT, &tAlt)){
|
|
tAlt = m_pPosition->getAlt();
|
|
pSetting = config_setting_add(m_pSettings, TAG_POSITION_ALT, CONFIG_TYPE_FLOAT);
|
|
config_setting_set_float(pSetting, tAlt);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
if (!config_setting_lookup_float(m_pSettings, TAG_POSITION_YAW, &tYaw)){
|
|
tYaw = m_pPosition->getRotZ_deg();
|
|
pSetting = config_setting_add(m_pSettings, TAG_POSITION_YAW, CONFIG_TYPE_FLOAT);
|
|
config_setting_set_float(pSetting, tYaw);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
if (!config_setting_lookup_float(m_pSettings, TAG_POSITION_ROLL, &tRoll)){
|
|
tRoll = m_pPosition->getRotY_deg();
|
|
pSetting = config_setting_add(m_pSettings, TAG_POSITION_ROLL, CONFIG_TYPE_FLOAT);
|
|
config_setting_set_float(pSetting, tRoll);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
if (!config_setting_lookup_float(m_pSettings, TAG_POSITION_PITCH, &tPitch)){
|
|
tPitch = m_pPosition->getRotX_deg();
|
|
pSetting = config_setting_add(m_pSettings, TAG_POSITION_PITCH, CONFIG_TYPE_FLOAT);
|
|
config_setting_set_float(pSetting, tPitch);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
m_pPosition->setPositionDeg(tLat, tLon, tAlt, tPitch, tRoll, tYaw );
|
|
|
|
if (!config_setting_lookup_string(m_pSettings, LGS_SET_ADDRESS,(const char**)&m_pHost)){
|
|
m_pHost = "192.168.0.108";
|
|
pSetting = config_setting_add(m_pSettings, LGS_SET_ADDRESS, CONFIG_TYPE_STRING);
|
|
config_setting_set_string(pSetting, m_pHost);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
if (!config_setting_lookup_int(m_pSettings, LGS_SET_PORT, &m_nPort)){
|
|
m_nPort = 2222;
|
|
pSetting = config_setting_add(m_pSettings, LGS_SET_PORT, CONFIG_TYPE_INT);
|
|
config_setting_set_int(pSetting, m_nPort);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
if( basicSettingsProvider::getInstance()->isCompromised() ) basicSettingsProvider::getInstance()->validate();
|
|
|
|
m_pTransport = new clientPort( m_pHost, m_nPort );
|
|
if( m_pTransport!= NULL ){
|
|
//m_oProtocol = new protocolLGS_CLIENT( m_pTransport, 0 );
|
|
//if (m_oProtocol != NULL)
|
|
if( setTransport(m_pTransport))
|
|
if(protocolLGS_CLIENT::create() )
|
|
return basicDualThread::init();
|
|
};
|
|
};
|
|
m_eStatus = OS_STATUS_DEAD;
|
|
return false;
|
|
};
|
|
|
|
bool objectLGS::getDeviceStatus(DEVICE_STATUS &STAT){
|
|
m_mStatusMutex.lock();
|
|
memcpy(&STAT, &m_sDeviceStatus, sizeof(DEVICE_STATUS));
|
|
m_mStatusMutex.unlock();
|
|
return true;
|
|
};
|
|
|
|
void objectLGS::updateSettings(void){
|
|
if( m_pSettings != NULL ){
|
|
config_setting_t *pSetting;
|
|
int tInt;
|
|
double tFloat;
|
|
CSTR tBuff;
|
|
if (config_setting_lookup_float(m_pSettings, TAG_POSITION_LAT, &tFloat)){
|
|
if( tFloat != m_pPosition->getLat() ){
|
|
tFloat = m_pPosition->getLat();
|
|
pSetting = config_setting_lookup(m_pSettings, TAG_POSITION_LAT);
|
|
config_setting_set_float(pSetting, tFloat);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
};
|
|
if (config_setting_lookup_float(m_pSettings, TAG_POSITION_LON, &tFloat)){
|
|
if (tFloat != m_pPosition->getLon()){
|
|
tFloat = m_pPosition->getLon();
|
|
pSetting = config_setting_lookup(m_pSettings, TAG_POSITION_LON);
|
|
config_setting_set_float(pSetting, tFloat);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
};
|
|
if (config_setting_lookup_float(m_pSettings, TAG_POSITION_ALT, &tFloat)){
|
|
if (tFloat != m_pPosition->getAlt()){
|
|
tFloat = m_pPosition->getAlt();
|
|
pSetting = config_setting_lookup(m_pSettings, TAG_POSITION_ALT);
|
|
config_setting_set_float(pSetting, tFloat);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
};
|
|
if (config_setting_lookup_float(m_pSettings, TAG_POSITION_YAW, &tFloat)){
|
|
if (tFloat != m_pPosition->getRotZ_deg()){
|
|
tFloat = m_pPosition->getRotZ_deg();
|
|
pSetting = config_setting_lookup(m_pSettings, TAG_POSITION_YAW);
|
|
config_setting_set_float(pSetting, tFloat);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
};
|
|
if (config_setting_lookup_float(m_pSettings, TAG_POSITION_ROLL, &tFloat)){
|
|
if (tFloat != m_pPosition->getRotY_deg()){
|
|
tFloat = m_pPosition->getRotY_deg();
|
|
pSetting = config_setting_lookup(m_pSettings, TAG_POSITION_ROLL);
|
|
config_setting_set_float(pSetting, tFloat);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
};
|
|
if (config_setting_lookup_float(m_pSettings, TAG_POSITION_PITCH, &tFloat)){
|
|
if (tFloat != m_pPosition->getRotX_deg()){
|
|
tFloat = m_pPosition->getRotX_deg();
|
|
pSetting = config_setting_lookup(m_pSettings, TAG_POSITION_PITCH);
|
|
config_setting_set_float(pSetting, tFloat);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
};
|
|
if (config_setting_lookup_string(m_pSettings, LGS_SET_ADDRESS, (const char**)&tBuff)){
|
|
if (strcmp(m_pHost, tBuff) != 0){
|
|
pSetting = config_setting_lookup(m_pSettings, LGS_SET_ADDRESS);
|
|
config_setting_set_string(pSetting, m_pHost);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
};
|
|
if (config_setting_lookup_int(m_pSettings, LGS_SET_PORT, &tInt)){
|
|
if (m_nPort != tInt){
|
|
pSetting = config_setting_lookup(m_pSettings, LGS_SET_PORT);
|
|
config_setting_set_int(pSetting, m_nPort);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
};
|
|
if (basicSettingsProvider::getInstance()->isCompromised()) basicSettingsProvider::getInstance()->validate();
|
|
};
|
|
};
|
|
|
|
void objectLGS::m_fThreadAProc(void){
|
|
m_bThreadAStatus = TH_WORKING;
|
|
LOG("BackLogic Started");
|
|
while( m_eStatus < OS_STATUS_DEAD && m_bThreadAStatus < TH_ENDED ){
|
|
// First Time Start
|
|
if( m_sDeviceStatus.Status == STG_NONE ){
|
|
if( ( m_bTransportStatus = m_pTransport->getStatus() ) ){
|
|
//handle connection
|
|
m_eStatus = OS_STATUS_ACTIVE;
|
|
m_eWorkMode = CWM_INIT;
|
|
m_mStatusMutex.lock();
|
|
m_sDeviceStatus.Status = STG_CONNECTED;
|
|
m_sDeviceStatus.CurrentOperation = CMD_NONE;
|
|
m_sDeviceStatus.ComStatus = STG_REDY;
|
|
m_bMasksAreLoadded = false;
|
|
if (m_pShadow) m_pShadow->clear();
|
|
|
|
m_mStatusMutex.unlock();
|
|
|
|
basicEvent *tEVT;
|
|
tEVT = createBasicEvent(getID(), EVT_CLASS_SENSOR, EVT_READY, "Device is connected");
|
|
m_pEventHeap->broadcast(tEVT);
|
|
} else {
|
|
//handle no connection
|
|
m_mStatusMutex.lock();
|
|
|
|
m_bMasksAreLoadded = false;
|
|
if (m_pShadow) m_pShadow->clear();
|
|
|
|
m_sDeviceStatus.Status = STG_DISCONNECTED;
|
|
m_sDeviceStatus.CurrentOperation = CMD_NONE;
|
|
m_sDeviceStatus.ComStatus = STG_REDY;
|
|
m_eWorkMode = CWM_INIT;
|
|
m_mStatusMutex.unlock();
|
|
|
|
basicEvent *tEVT;
|
|
//ToDo: Change Device Name!
|
|
tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_ERROR, "Device is Not Connected");
|
|
m_pEventHeap->broadcast( tEVT );
|
|
};
|
|
} else {
|
|
// Checking Transport Status Change
|
|
if ( m_pTransport->getStatus() != m_bTransportStatus ){ // If Communication is Changed
|
|
if( ( m_bTransportStatus = m_pTransport->getStatus() ) ){
|
|
//handle connection
|
|
m_eStatus = OS_STATUS_ACTIVE;
|
|
m_eWorkMode = CWM_INIT;
|
|
m_mStatusMutex.lock();
|
|
m_nBusyCounter = 0;
|
|
m_sDeviceStatus.Status = STG_CONNECTED;
|
|
m_sDeviceStatus.CurrentOperation = CMD_NONE;
|
|
m_bMasksAreLoadded = false;
|
|
if (m_pShadow) m_pShadow->clear();
|
|
|
|
m_sDeviceStatus.ComStatus = STG_REDY;
|
|
m_mStatusMutex.unlock();
|
|
//m_bComIsBusy = false;
|
|
|
|
basicEvent *tEVT;
|
|
if( m_bIsMaster ) {
|
|
tEVT = createBasicEvent(getID(), EVT_CLASS_SENSOR, EVT_READY, "Master Device is connected");
|
|
}else{
|
|
tEVT = createBasicEvent(getID(), EVT_CLASS_SENSOR, EVT_READY, "Slave Device is connected");
|
|
};
|
|
m_pEventHeap->broadcast(tEVT);
|
|
} else {
|
|
//handle no connection
|
|
m_eStatus = OS_STATUS_INIT;
|
|
m_eWorkMode = CWM_INIT;
|
|
m_mStatusMutex.lock();
|
|
m_sDeviceStatus.Status = STG_DISCONNECTED;
|
|
m_sDeviceStatus.CurrentOperation = CMD_NONE;
|
|
m_sDeviceStatus.ComStatus = STG_REDY;
|
|
m_mStatusMutex.unlock();
|
|
//m_bComIsBusy = false;
|
|
|
|
memset(&m_sDeviceSoftNFO, 0, sizeof( SOFTWARE_INFO ));
|
|
|
|
basicEvent *tEVT;
|
|
if( m_bIsMaster ) {
|
|
tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_ERROR, "Master Device is disconnected");
|
|
}else{
|
|
tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_ERROR, "Slave Device is disconnected");
|
|
};
|
|
m_pEventHeap->broadcast( tEVT );
|
|
};
|
|
};
|
|
};
|
|
if( !m_bTransportStatus ){ // Try to Reconnect
|
|
int i = 1000;
|
|
while( (i--) && ( m_eStatus < OS_STATUS_DEAD ) && ( m_bThreadAStatus < TH_ENDED ) ) SLEEP(1);
|
|
//try to connect
|
|
if( m_eStatus < OS_STATUS_DEAD && m_bThreadAStatus < TH_ENDED){
|
|
if( !m_pTransport->reconnect() ) continue;
|
|
} else continue;
|
|
};
|
|
|
|
if( m_eStatus == OS_STATUS_ACTIVE ){
|
|
// Checking Automated commands
|
|
if( comIsIdle() ){
|
|
switch( m_eWorkMode ){
|
|
case CWM_INIT:
|
|
if( getState() ){
|
|
comSetBusy( USE_MUTEX );
|
|
} else {
|
|
completeOperation( false );
|
|
LOG_ERROR("Error INITIAL CMD_GET_STATE!");
|
|
SLEEP(300);
|
|
};
|
|
break;
|
|
case CWM_INITIAL_PARAM:
|
|
if( getParameters() ){
|
|
comSetBusy( USE_MUTEX );
|
|
} else {
|
|
completeOperation( false );
|
|
LOG_ERROR("Error INITIAL CMD_GET_PARAMETERS!");
|
|
SLEEP(300);
|
|
};
|
|
break;
|
|
case CWM_INITIAL_MASKS_INFO:
|
|
if( getShadowInfo() ){
|
|
comSetBusy( USE_MUTEX );
|
|
} else {
|
|
completeOperation( false );
|
|
LOG_ERROR("Error INITIAL CMD_GET_SHADOW_INFO !");
|
|
SLEEP(300);
|
|
};
|
|
break;
|
|
case CWM_INITIAL_MASKS_DATA:
|
|
if( getShadowPoly( m_nCurrentPolyID ) ){
|
|
comSetBusy( USE_MUTEX );
|
|
} else {
|
|
completeOperation( false );
|
|
LOG_ERROR("Error INITIAL CMD_GET_SHADOW_DATA !");
|
|
SLEEP(300);
|
|
};
|
|
break;
|
|
case CWM_BORDER:
|
|
if( getDraw( 0, m_nFullBorderKernelIndex ) ){
|
|
comSetBusy( USE_MUTEX );
|
|
} else {
|
|
completeOperation( false );
|
|
LOG_ERROR("Error Sending CMD_FULL_BORDER!");
|
|
SLEEP( 300 );
|
|
};
|
|
break;
|
|
case CWM_MASK:
|
|
if( setShadowPoly(NULL) ){
|
|
comSetBusy( USE_MUTEX );
|
|
} else {
|
|
completeOperation( false );
|
|
LOG_ERROR("Error Sending CMD_SET_HZ_POLY!");
|
|
SLEEP( 300 );
|
|
};
|
|
break;
|
|
case CWM_PARAMS:
|
|
switch( getOperation() ){
|
|
case CMD_GET_PARAMETERS:
|
|
if( getParameters() ){
|
|
comSetBusy( USE_MUTEX );
|
|
} else {
|
|
completeOperation( false );
|
|
LOG_ERROR("Error Sending CMD_GET_PARAMETERS!");
|
|
SLEEP( 300 );
|
|
};
|
|
break;
|
|
case CMD_SET_PARAMETERS:
|
|
if( setParameters( m_pLGS_PARAMETERS )){
|
|
comSetBusy();
|
|
} else {
|
|
completeOperation( false );
|
|
LOG_ERROR("Error Sending CMD_SET_PARAMETERS!");
|
|
SLEEP( 300 );
|
|
};
|
|
break;
|
|
};
|
|
break;
|
|
case CWM_PINGPONG:
|
|
/******************************** DEFAULT MODE/Start Other Commands *************************************************/
|
|
default:
|
|
switch( getOperation() ){
|
|
case CMD_RESET:
|
|
if( doReset()){
|
|
comSetBusy( USE_MUTEX );
|
|
} else {
|
|
completeOperation( false );
|
|
LOG_ERROR("Error Sending CMD_RESET!");
|
|
SLEEP( 300 );
|
|
};
|
|
break;
|
|
case CMD_FULL_RESET:
|
|
if( doFullReset()){
|
|
comSetBusy( USE_MUTEX );
|
|
} else {
|
|
completeOperation( false );
|
|
LOG_ERROR("Error Sending CMD_FULL_RESET!");
|
|
SLEEP( 300 );
|
|
};
|
|
break;
|
|
case CMD_GET_PARAMETERS:
|
|
case CMD_SET_PARAMETERS: m_eWorkMode = CWM_PARAMS; break;
|
|
case CMD_FULL_BORDER: m_eWorkMode = CWM_BORDER; break;
|
|
case CMD_SET_HZ_POLY: m_eWorkMode = CWM_MASK; break;
|
|
case CMD_DHWM_START_MOTORS:
|
|
if( doStartMotors()){
|
|
comSetBusy( USE_MUTEX );
|
|
} else {
|
|
completeOperation( false );
|
|
LOG_ERROR("Error Sending CMD_DHWM_START_MOTORS!");
|
|
SLEEP( 300 );
|
|
};
|
|
break;
|
|
case CMD_DHWM_STOP_MOTORS:
|
|
if( doStopMotors()){
|
|
comSetBusy( USE_MUTEX );
|
|
} else {
|
|
completeOperation( false );
|
|
LOG_ERROR("Error Sending CMD_DHWM_STOP_MOTORS!");
|
|
SLEEP( 300 );
|
|
};
|
|
break;
|
|
case CMD_SET_HZ_STATUS:
|
|
if (setShadowStatus( m_pShadow->isActive(), 0xFF)){
|
|
comSetBusy(USE_MUTEX);
|
|
} else {
|
|
completeOperation(false);
|
|
LOG_ERROR("Error Sending CMD_DHWM_STOP_MOTORS!");
|
|
SLEEP(300);
|
|
};
|
|
break;
|
|
/******************************** DEFAULT NO Specific Command LOOP ******************************************************/
|
|
default:
|
|
if (m_nIdleCounter < m_nIdleTarget ){ // For 2 Seconds
|
|
m_nIdleCounter++;
|
|
SLEEP( 50 );
|
|
} else {
|
|
m_nIdleCounter = 0;
|
|
if( getState2() ){
|
|
comSetBusy( USE_MUTEX );
|
|
} else {
|
|
completeOperation( false );
|
|
LOG_ERROR("Error Sending CMD_GET_STATE2!");
|
|
SLEEP( 300 );
|
|
};
|
|
};
|
|
break;
|
|
/*********^^^^^^^^^^^^^^^^^^^^^^^ DEFAULT LOOP ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^********************/
|
|
};
|
|
break;
|
|
};
|
|
} else { // Com Is Busy
|
|
// Checking for QUERIES Time Outs
|
|
if( m_nBusyCounter < LGS_TIMEOUT_COUNT ){
|
|
m_nBusyCounter++;
|
|
SLEEP( 100 );
|
|
} else {
|
|
if( m_nBusyCounter == LGS_TIMEOUT_COUNT ){
|
|
m_nBusyCounter = LGS_TIMEOUT_COUNT + 1;
|
|
// Handle device's time out
|
|
basicEvent *tEVT;
|
|
if( m_bIsMaster ) {
|
|
tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_ERROR, "Master Device communication Time Out");
|
|
} else {
|
|
tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_ERROR, "Slave Device communication Time Out");
|
|
};
|
|
m_pEventHeap->broadcast( tEVT );
|
|
//m_bComIsBusy = false;
|
|
LOG_ERROR("Device Disconnected (TO)!");
|
|
// ------
|
|
m_pTransport->disconnect();
|
|
m_mStatusMutex.lock();
|
|
m_sDeviceStatus.CurrentOperation = CMD_NONE;
|
|
m_sDeviceStatus.Status = STG_DISCONNECTED;
|
|
m_sDeviceStatus.ComStatus = STG_REDY;
|
|
m_mStatusMutex.unlock();
|
|
} else SLEEP( 1000 );
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
|
|
thresholdNode *objectLGS::grabDataAccess( void ){
|
|
if( m_mDataMutex.try_lock() ){
|
|
if(( m_pThresholdData != NULL ) && ( m_nFullBorderDataIndex == TH_SIZE_NODES )){
|
|
return m_pThresholdData;
|
|
};
|
|
m_mDataMutex.unlock();
|
|
};
|
|
return NULL;
|
|
};
|
|
|
|
void objectLGS::cleanDataTH( void ){
|
|
m_mDataMutex.lock();
|
|
if( m_pThresholdData != NULL ){
|
|
free( m_pThresholdData );
|
|
m_pThresholdData = NULL;
|
|
m_nFullBorderDataIndex = 0;
|
|
};
|
|
m_mDataMutex.unlock();
|
|
};
|
|
|
|
void objectLGS::releaseDataAccess( void ){
|
|
m_mDataMutex.unlock();
|
|
};
|
|
#ifndef _BABAABBA_
|
|
void objectLGS::m_fThreadBProc(void) {
|
|
m_bThreadBStatus = TH_ENDED;
|
|
};
|
|
|
|
TARGET_DATA *objectLGS::prepareTargetData(CLIENT_EVENT* CE) {
|
|
TARGET_DATA* tVal = NULL;
|
|
if (CE != NULL) {
|
|
tVal = (TARGET_DATA*)malloc(sizeof(TARGET_DATA));
|
|
if (tVal != NULL) {
|
|
systemAnchor* tSystem = systemAnchor::getInstance();
|
|
uint16_t cX, cY;
|
|
//memset(tVal, 0, sizeof(TARGET_DATA));
|
|
tVal->source_position.lat = m_pPosition->getLat();
|
|
tVal->source_position.lon = m_pPosition->getLon();
|
|
tVal->source_position.alt = m_pPosition->getAlt();
|
|
makeXY(CE->th_id, cX, cY, (CE->k_id < 8));
|
|
tVal->local_target.r = 300.0f / 4095.0f * (float)CE->range;
|
|
tVal->local_target.fi = 360.0f - (360.0f / (float)TH_LINE_NODES) * (float)cX;
|
|
tVal->local_target.tetta = 90.0f - (Q_DEGREE_FOV / (float)Q_SCAN_COUNT) * (float)cY + Q_SHIFT_DOWN_FOV;
|
|
//CE->w_cnt * CE->range
|
|
tVal->area = CE->w_cnt * tVal->local_target.r;
|
|
tSystem->convertToSystem(m_pPosition, tVal->local_target, tVal->system_target);
|
|
tSystem->convertToGlobal(m_pPosition, tVal->system_target, tVal->global_target);
|
|
};
|
|
};
|
|
return tVal;
|
|
};
|
|
|
|
bool objectLGS::packetHandler(protocolPackage* Package) {
|
|
U8* pReceivedPackage = NULL;
|
|
size_t nReceivedPackageSize = 0;
|
|
bool bPackageIsArived = false;
|
|
basicEvent* tEVT;
|
|
CLIENT_EVENT* tData;
|
|
if( Package == NULL ) return false;
|
|
pReceivedPackage = Package->m_pData;
|
|
nReceivedPackageSize = Package->m_nSize;
|
|
if (pReceivedPackage != NULL) {
|
|
uint8_t CUR_CMD;
|
|
uint16_t PKG_LEN;
|
|
uint8_t index;
|
|
uint8_t SUB_LEN;
|
|
uint8_t SUB_CMD;
|
|
uint16_t Range;
|
|
uint32_t Angle;
|
|
uint32_t Width;
|
|
bool State;
|
|
uint8_t Status;
|
|
uint8_t Code;
|
|
PKG_LEN = ((pReceivedPackage[SIZE_IDX_A] & 0x7F) << 8) | pReceivedPackage[SIZE_IDX_B];
|
|
CUR_CMD = pReceivedPackage[CMD_IDX];
|
|
SUB_CMD = pReceivedPackage[SUB_CMD_IDX];
|
|
m_nBusyCounter = 0;
|
|
switch (CUR_CMD) {
|
|
case CMD_STATE:
|
|
if (SUB_CMD > WM_INIT) {
|
|
uint8_t* ptr;
|
|
ptr = (uint8_t*)& m_sDeviceSoftNFO;
|
|
for (uint8_t i = 0; i < sizeof(SOFTWARE_INFO); i++) ptr[i] = pReceivedPackage[SUB_CMD_IDX + 1 + i];
|
|
};
|
|
LOG("CMD_STATE");
|
|
completeOperation();
|
|
break;
|
|
case CMD_QUIT:
|
|
break;
|
|
case CMD_RESET:
|
|
LOG("Reset ACK");
|
|
completeOperation();
|
|
break;
|
|
case CMD_FULL_BORDER:
|
|
case CMD_BORDER:
|
|
LOG("CMD_BORDER");
|
|
if (SUB_CMD == BD_ERRORMODE) {
|
|
LOG_ERROR("BOARD DATA ERROR!");
|
|
m_nFullBorderDataIndex = 0;
|
|
completeOperation(false);
|
|
}
|
|
else if (SUB_CMD == BD_NOTREADY) {
|
|
LOG_ERROR("BOARD DATA NOT READY!");
|
|
m_nFullBorderDataIndex = 0;
|
|
completeOperation(false);
|
|
}
|
|
else {
|
|
uint16_t index = 6;
|
|
m_mDataMutex.lock();
|
|
while (index < (nReceivedPackageSize - 7) && m_nFullBorderDataIndex < TH_SIZE_NODES) {
|
|
m_pThresholdData[m_nFullBorderDataIndex].data = pReceivedPackage[index++];
|
|
m_pThresholdData[m_nFullBorderDataIndex].data = (m_pThresholdData[m_nFullBorderDataIndex].data << 8) | pReceivedPackage[index++];
|
|
m_pThresholdData[m_nFullBorderDataIndex].data = (m_pThresholdData[m_nFullBorderDataIndex].data << 8) | pReceivedPackage[index++];
|
|
m_pThresholdData[m_nFullBorderDataIndex].data = (m_pThresholdData[m_nFullBorderDataIndex].data << 8) | pReceivedPackage[index++];
|
|
m_nFullBorderDataIndex++;
|
|
};
|
|
m_mDataMutex.unlock();
|
|
if (m_nFullBorderDataIndex < TH_SIZE_NODES) {
|
|
int proc;
|
|
proc = (int)(100.f * ((float)m_nFullBorderDataIndex / (float)TH_SIZE_NODES));
|
|
setCompelition(proc);
|
|
getDraw(m_nFullBorderDataIndex, m_nFullBorderKernelIndex);
|
|
comSetBusy(USE_MUTEX);
|
|
}
|
|
else {
|
|
LOG("FINISH GET BOARD DATA");
|
|
m_mDataMutex.lock();
|
|
//if( m_pThresholdData!= NULL ){
|
|
// if( m_nFullBorderDataIndex > 0 ){
|
|
// FILE *fd;
|
|
// fd = fopen( "test.raw", "wb");
|
|
// if( fd!= NULL ){
|
|
// fwrite( &m_nFullBorderDataIndex, sizeof(uint32_t), 1, fd );
|
|
// fwrite( m_pThresholdData, sizeof( thresholdNode ), m_nFullBorderDataIndex, fd );
|
|
// fclose( fd );
|
|
// };
|
|
// };
|
|
//};
|
|
m_mDataMutex.unlock();
|
|
//m_pMapWidget->updateRanges( (uint32_t *) m_pThresholdData, m_nFullBorderDataIndex );
|
|
//m_pRadarWidget->updateRanges( (uint32_t *) m_pThresholdData, m_nFullBorderDataIndex );
|
|
completeOperation();
|
|
};
|
|
|
|
};
|
|
break;
|
|
case CMD_GETFILE:
|
|
break;
|
|
case CMD_RESTART:
|
|
break;
|
|
case CMD_GET_PARAMETERS:
|
|
case CMD_PARAMETERS:
|
|
case CMD_SET_PARAMETERS: {
|
|
LOG("Finish Get Params");
|
|
if (SUB_CMD == SUB_DATA_INTEGRITY_VALID) {
|
|
PLGS_PARAMETERS tParam;
|
|
if (m_pLGS_PARAMETERS != NULL) {
|
|
tParam = (PLGS_PARAMETERS)(pReceivedPackage + 6);
|
|
/*
|
|
m_pLGS_PARAMETERS->bSST = tParam->bSST;
|
|
|
|
for( int index = 0; index < 26; index++ )
|
|
m_pLGS_PARAMETERS->flags_binary[index] = tParam->flags_binary[index];
|
|
|
|
m_pLGS_PARAMETERS->nDelta = tParam->nDelta;
|
|
m_pLGS_PARAMETERS->nFlip = tParam->nFlip;
|
|
m_pLGS_PARAMETERS->nGPointSamples = tParam->nGPointSamples;
|
|
m_pLGS_PARAMETERS->nOffset = tParam->nOffset;
|
|
m_pLGS_PARAMETERS->nOrder = tParam->nOrder;
|
|
m_pLGS_PARAMETERS->nSun = tParam->nSun;
|
|
m_pLGS_PARAMETERS->nWidth = tParam->nWidth;
|
|
*/
|
|
memcpy(m_pLGS_PARAMETERS, tParam, sizeof(LGS_PARAMETERS));
|
|
m_bIsMaster = m_pLGS_PARAMETERS->flags.isMaster;
|
|
SLEEP(500);
|
|
completeOperation();
|
|
}
|
|
else completeOperation();
|
|
}
|
|
else {
|
|
LOG_ERROR("Data Integrity Error(on Get Parameters)!");
|
|
completeOperation(false);
|
|
};
|
|
};
|
|
break;
|
|
case CMD_HZ_INFO: {
|
|
LOG("Finish Get HZ INFO");
|
|
m_nDevicePolyCount = pReceivedPackage[6];
|
|
// Clear Existed Masks
|
|
m_pShadow->clear();
|
|
if (m_nDevicePolyCount) {
|
|
m_pShadow->setActive((SUB_CMD > 0));
|
|
}
|
|
else {
|
|
m_pShadow->setActive(false);
|
|
};
|
|
completeOperation();
|
|
};
|
|
break;
|
|
case CMD_SET_HZ_POLY: {
|
|
LOG("Finish Get HZ POLY");
|
|
simplePolygone* tPolygone;
|
|
tPolygone = new simplePolygone();
|
|
if (tPolygone != NULL) {
|
|
tPolygone->count = pReceivedPackage[5];
|
|
tPolygone->color[0] = pReceivedPackage[6];
|
|
tPolygone->color[1] = pReceivedPackage[7];
|
|
tPolygone->color[2] = pReceivedPackage[8];
|
|
#if defined( __linux__ ) && !defined( __GUI__ )
|
|
tPolygone->points = (simplePoint*)malloc(sizeof(simplePoint) * tPolygone->count);
|
|
#else
|
|
tPolygone->points = (QPoint*)malloc(sizeof(QPoint) * tPolygone->count);
|
|
#endif
|
|
if (tPolygone->count && tPolygone->points != NULL) {
|
|
uint16_t x, y;
|
|
int index = 9;
|
|
for (int i = 0; i < tPolygone->count; i++) {
|
|
x = pReceivedPackage[index++];
|
|
x = (x << 8) | pReceivedPackage[index++];
|
|
y = pReceivedPackage[index++];
|
|
y = (y << 8) | pReceivedPackage[index++];
|
|
tPolygone->points[i].setX(x);
|
|
tPolygone->points[i].setY(y);
|
|
};
|
|
m_pShadow->addPoly(tPolygone);
|
|
} else {
|
|
free(tPolygone);
|
|
};
|
|
};
|
|
m_nCurrentPolyID++;
|
|
completeOperation();
|
|
};
|
|
break;
|
|
case CMD_SET_HZ_POLY_ACK: {
|
|
m_nCurrentPolyID = SUB_CMD;
|
|
if (m_nCurrentPolyID < m_pShadow->getPolyCount()) {
|
|
simplePolygone* tPoly;
|
|
tPoly = m_pShadow->getPoly(m_nCurrentPolyID);
|
|
if (tPoly != NULL) {
|
|
setShadowPoly(tPoly);
|
|
comSetBusy(USE_MUTEX);
|
|
} else {
|
|
completeOperation(false);
|
|
};
|
|
} else {
|
|
LOG("Send RayTraces");
|
|
vectorZoneMask VZ;
|
|
if (m_pShadow->getZoneMask(VZ)) {
|
|
if (setShadowTrace(&VZ)) {
|
|
completeOperation();
|
|
} else {
|
|
completeOperation(false);
|
|
};
|
|
} else {
|
|
completeOperation();
|
|
};
|
|
};
|
|
};
|
|
break;
|
|
case CMD_GET_SERIAL_NUMBER:
|
|
break;
|
|
case CMD_SET_ADDRESS:
|
|
break;
|
|
case CMD_GET_SOFTWARE_VERSION:
|
|
break;
|
|
case CMD_UNSUPPORTED:
|
|
break;
|
|
case CMD_SET_COMM_SPEED:
|
|
break;
|
|
case CMD_FULL_RESET:
|
|
LOG("Full Reset ACK");
|
|
completeOperation();
|
|
break;
|
|
case CMD_CAMERA:
|
|
break;
|
|
case CMD_SET_SERIAL_NUMBER:
|
|
break;
|
|
case CMD_BOARDDATA:
|
|
break;
|
|
case CMD_GET_CAMERA_PARAMETERS:
|
|
break;
|
|
case CMD_SET_CAMERA_PARAMETERS:
|
|
break;
|
|
case CMD_RELAY:
|
|
break;
|
|
case CMD_GET_RELAY_PARAMETERS:
|
|
break;
|
|
case CMD_SET_RELAY_PARAMETERS:
|
|
break;
|
|
case CMD_FS_SUB_PACKET:
|
|
break;
|
|
case CMD_STATE_2:
|
|
m_mStatusMutex.lock();
|
|
if (SUB_CMD != m_sDeviceStatus.Status) {
|
|
m_sDeviceStatus.Status = (E_LGS_STAGE)SUB_CMD;
|
|
switch (m_sDeviceStatus.Status) {
|
|
case STG_STUDY: {
|
|
m_mStatusMutex.unlock();
|
|
basicEvent* tEVT;
|
|
tEVT = createBasicEvent(getID(), EVT_CLASS_SENSOR, EVT_STUDY, "Device in STUDY mode");
|
|
m_pEventHeap->broadcast(tEVT);
|
|
break;
|
|
};
|
|
case STG_REDY: {
|
|
m_mStatusMutex.unlock();
|
|
basicEvent* tEVT;
|
|
tEVT = createBasicEvent(getID(), EVT_CLASS_SENSOR, EVT_READY, "Device in DETECTION mode");
|
|
m_pEventHeap->broadcast(tEVT);
|
|
break;
|
|
};
|
|
case STG_BUSY: {
|
|
m_mStatusMutex.unlock();
|
|
basicEvent* tEVT;
|
|
tEVT = createBasicEvent(getID(), EVT_CLASS_SENSOR, EVT_ERROR, "Device in BUSY mode");
|
|
m_pEventHeap->broadcast(tEVT);
|
|
break;
|
|
};
|
|
default: m_mStatusMutex.unlock();
|
|
};
|
|
}
|
|
else m_mStatusMutex.unlock();
|
|
if (pReceivedPackage[DATA_BEGIN_IDX] > 0) {
|
|
uint8_t tCount = 0;
|
|
tCount = pReceivedPackage[DATA_BEGIN_IDX];
|
|
CLIENT_EVENT* tEVT = NULL;
|
|
tEVT = (CLIENT_EVENT*)& pReceivedPackage[DATA_BEGIN_IDX + 1];
|
|
for (uint8_t xindex = 0; xindex < tCount; xindex++) {
|
|
switch (tEVT[xindex].type) {
|
|
case EVT_TARGET_BLACK:
|
|
case EVT_TARGET_WHITE: {
|
|
TARGET_DATA *tData;
|
|
tData = prepareTargetData(tEVT+xindex);
|
|
if(tData != NULL){
|
|
char tBuffer[256];
|
|
basicEvent * bEVT = NULL;
|
|
bool bIsMaster;
|
|
uint8_t bKernelID;
|
|
|
|
bKernelID = tEVT[xindex].k_id & 0x07;
|
|
bIsMaster = !((tEVT[xindex].k_id & 0x08) == 0x08);
|
|
|
|
sprintf(tBuffer, "%s[%d] %s target \tRange: %.2fm. \tAzimuth: %.2f \tElevation: %.2f \tTS: %d@%d W:%.2f",
|
|
(bIsMaster ? "M" : "S"),
|
|
bKernelID,
|
|
((tEVT[xindex].type == EVT_TARGET_WHITE) ? "White" : "Black"),
|
|
tData->local_target.r,
|
|
tData->local_target.fi,
|
|
tData->local_target.tetta,
|
|
tEVT[xindex].uts,
|
|
tEVT[xindex].ums,
|
|
tData->area
|
|
);
|
|
bEVT = createBasicEvent(getID(), EVT_CLASS_SENSOR, (basicEventTypeID)tEVT[xindex].type, tBuffer, tData);
|
|
if (bEVT != NULL) {
|
|
m_pEventHeap->broadcast(bEVT);
|
|
} else {
|
|
free(tData);
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
//set new stage2
|
|
m_nIdleTarget = m_nIdleTarget >> 1;
|
|
if (m_nIdleTarget < LGS_MIN_IDLE_DELAY) m_nIdleTarget = LGS_MIN_IDLE_DELAY;
|
|
//m_oProtocol->getState2();
|
|
//comSetBusy(USE_MUTEX);
|
|
} else {
|
|
m_nIdleTarget = m_nIdleTarget << 1;
|
|
if (m_nIdleTarget > LGS_MAX_IDLE_DELAY) m_nIdleTarget = LGS_MAX_IDLE_DELAY;
|
|
};
|
|
completeOperation();
|
|
break;
|
|
case CMD_GET_WIDTH_TABLE:
|
|
break;
|
|
case CMD_SET_WIDTH_TABLE:
|
|
break;
|
|
case CMD_GET_VOLTAGE:
|
|
break;
|
|
case CMD_GET_VOLTAGE_PARAMETERS:
|
|
break;
|
|
case CMD_SET_VOLTAGE_PARAMETERS:
|
|
break;
|
|
case CMD_GET_HZ_DATA:
|
|
break;
|
|
case CMD_SET_HZ_DATA:
|
|
break;
|
|
case CMD_GET_CALIBRATION_TABLE:
|
|
break;
|
|
case CMD_SET_CALIBRATION_TABLE:
|
|
break;
|
|
case CMD_GET_LRF_DISABLE:
|
|
break;
|
|
case CMD_SET_LRF_DISABLE:
|
|
break;
|
|
case CMD_GET_ZOOM_TABLE:
|
|
break;
|
|
case CMD_SET_ZOOM_TABLE:
|
|
break;
|
|
case CMD_GET_TILT_TABLE:
|
|
break;
|
|
case CMD_SET_TILT_TABLE:
|
|
break;
|
|
case CMD_GET_HZ_ENABLE:
|
|
break;
|
|
case CMD_SET_HZ_ENABLE:
|
|
break;
|
|
case CMD_EVT:
|
|
break;
|
|
case CMD_FLIP_COMPLETE: {
|
|
tEVT = createBasicEvent(getID(), EVT_CLASS_SENSOR, EVT_FLIP, "Flip Complete");
|
|
m_pEventHeap->broadcast(tEVT);
|
|
break;
|
|
};
|
|
case CMD_SCAN_COMPLETE: {
|
|
tEVT = createBasicEvent(getID(), EVT_CLASS_SENSOR, EVT_SCAN, "Scan Complete");
|
|
m_pEventHeap->broadcast(tEVT);
|
|
break;
|
|
};
|
|
case CMD_TARGET: {
|
|
tEVT = createBasicEvent(getID(), EVT_CLASS_SENSOR, EVT_TARGET, "Target");
|
|
m_pEventHeap->broadcast(tEVT);
|
|
break;
|
|
};
|
|
case CMD_TARGET_WW: {
|
|
|
|
tEVT = createBasicEvent(getID(), EVT_CLASS_SENSOR, EVT_TARGET, "Target with Width");
|
|
m_pEventHeap->broadcast(tEVT);
|
|
break;
|
|
};
|
|
case CMD_TARGET_MW: {
|
|
tData = (CLIENT_EVENT*)malloc(sizeof(CLIENT_EVENT));
|
|
if (tData != NULL) {
|
|
/*
|
|
tData->mSampleID = (pReceivedPackage[5] << 24) + (pReceivedPackage[6] << 16) + (pReceivedPackage[7] << 8) + pReceivedPackage[8];
|
|
tData->mInfo = pReceivedPackage[9];
|
|
tData->mRange = (pReceivedPackage[12] << 8) + pReceivedPackage[11];
|
|
tData->mWidth = (pReceivedPackage[12] << 24) + (pReceivedPackage[13] << 16) + (pReceivedPackage[14] << 8) + pReceivedPackage[15];
|
|
//if( m_pMapWidget != NULL ) m_pMapWidget->addTarget(tData->mSampleID );
|
|
//if( m_pRadarWidget != NULL ) m_pRadarWidget->addTarget(tData->mSampleID, tData->mRange, m_bIsMaster );
|
|
tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_TARGET_WHITE, "White Intruder Detection", tData );
|
|
m_pEventHeap->broadcast( tEVT );
|
|
*/
|
|
};
|
|
break;
|
|
};
|
|
case CMD_TARGET_MB: {
|
|
tData = (CLIENT_EVENT*)malloc(sizeof(CLIENT_EVENT));
|
|
if (tData != NULL) {
|
|
/*
|
|
tData->mSampleID = (pReceivedPackage[5] << 24) + (pReceivedPackage[6] << 16) + (pReceivedPackage[7] << 8) + pReceivedPackage[8];
|
|
tData->mInfo = pReceivedPackage[9];
|
|
tData->mRange = (pReceivedPackage[12] << 8) + pReceivedPackage[11];
|
|
tData->mWidth = (pReceivedPackage[12] << 24) + (pReceivedPackage[13] << 16) + (pReceivedPackage[14] << 8) + pReceivedPackage[15];
|
|
//if( m_pMapWidget != NULL ) m_pMapWidget->addTarget(tData->mSampleID, m_bIsMaster );
|
|
//if( m_pRadarWidget != NULL ) m_pRadarWidget->addTarget(tData->mSampleID, tData->mRange, m_bIsMaster );
|
|
tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_TARGET_BLACK, "Target Black", tData );
|
|
m_pEventHeap->broadcast( tEVT );
|
|
*/
|
|
};
|
|
break;
|
|
};
|
|
case CMD_TARGET_ZZ: {
|
|
if (m_eWorkMode == CWM_PINGPONG) {
|
|
tData = (CLIENT_EVENT*)malloc(sizeof(CLIENT_EVENT));
|
|
if (tData != NULL) {
|
|
/*
|
|
char tBuffer[256];
|
|
float fRange, fAzimuth, fElevation;
|
|
int sX, sY, eX, eY, cX, cY;
|
|
for( int index = 0; index < sizeof(CLIENT_EVENT); index++ ){
|
|
((uint8_t*)tData)[index] = pReceivedPackage[5+index];
|
|
};
|
|
|
|
fRange = 300.0 / 4095.0 * tData->mRange;
|
|
makeCds( tData->mStartID, sX, sY, ( tData->mInfo & 0xFF000000 ) > 0 );
|
|
makeCds( tData->mEndID, eX, eY, ( tData->mInfo & 0xFF000000 ) > 0 );
|
|
cX = ((sX+eX)>>1);
|
|
cY = ((sY+eY)>>1);
|
|
fAzimuth = (360.0 / TH_LINE_NODES )*cX;
|
|
fElevation = 90.0 - (90.0/Q_SCAN_COUNT )*cY;
|
|
//if( m_pMapWidget != NULL ) m_pMapWidget->addTarget( makeIds( cX, cY ), m_bIsMaster );
|
|
//if( m_pRadarWidget != NULL ) m_pRadarWidget->addTarget( makeIds( cX, cY ), tData->mRange, m_bIsMaster );
|
|
if( ( tData->mInfo & 0x00FF0000 ) > 0 ){
|
|
sprintf( tBuffer, "[%s]:%.2fm. Azimuth: %.2f Elevation: %.2f",
|
|
(m_bIsMaster?"M":"S"),
|
|
fRange,
|
|
fAzimuth,
|
|
fElevation
|
|
);
|
|
tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_TARGET_WHITE, tBuffer, tData );
|
|
} else {
|
|
sprintf( tBuffer, "[%s]:%.2fm. Azimuth: %.2f Elevation: %.2f",
|
|
(m_bIsMaster?"M":"S"),
|
|
fRange,
|
|
fAzimuth,
|
|
fElevation
|
|
);
|
|
tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_TARGET_BLACK, tBuffer, tData );
|
|
};
|
|
m_pEventHeap->broadcast( tEVT );
|
|
*/
|
|
};
|
|
};
|
|
break;
|
|
};
|
|
default:
|
|
completeOperation(false);
|
|
break;
|
|
};
|
|
free(pReceivedPackage);
|
|
pReceivedPackage = NULL;
|
|
Package->m_pData = NULL;
|
|
nReceivedPackageSize = 0;
|
|
bPackageIsArived = false;
|
|
};
|
|
return true;
|
|
};
|
|
#else //!_BABAABBA_
|
|
void objectLGS::m_fThreadBProc(void){
|
|
U8 *pReceivedPackage = NULL;
|
|
size_t nReceivedPackageSize = 0;
|
|
bool bPackageIsArived = false;
|
|
basicEvent *tEVT;
|
|
CLIENT_EVENT *tData;
|
|
|
|
m_bThreadBStatus = TH_WORKING;
|
|
LOG("EventLogic Started");
|
|
while( m_eStatus < OS_STATUS_DEAD && m_bThreadBStatus < TH_ENDED ){
|
|
bPackageIsArived = m_oProtocol->getPackage( &pReceivedPackage, &nReceivedPackageSize );
|
|
if( !bPackageIsArived ){
|
|
SLEEP( 10 );
|
|
continue;
|
|
} else {
|
|
//pthread_mutex_lock( &m_mPackageMutex );
|
|
if( pReceivedPackage != NULL ) {
|
|
uint8_t CUR_CMD;
|
|
uint16_t PKG_LEN;
|
|
uint8_t index;
|
|
uint8_t SUB_LEN;
|
|
uint8_t SUB_CMD;
|
|
uint16_t Range;
|
|
uint32_t Angle;
|
|
uint32_t Width;
|
|
bool State;
|
|
uint8_t Status;
|
|
uint8_t Code;
|
|
PKG_LEN = ((pReceivedPackage[SIZE_IDX_A] & 0x7F ) << 8 ) | pReceivedPackage[SIZE_IDX_B];
|
|
CUR_CMD = pReceivedPackage[CMD_IDX];
|
|
SUB_CMD = pReceivedPackage[SUB_CMD_IDX];
|
|
m_nBusyCounter = 0;
|
|
switch( CUR_CMD ) {
|
|
case CMD_STATE:
|
|
if( SUB_CMD > WM_INIT ){
|
|
uint8_t *ptr;
|
|
ptr = (uint8_t *) &m_sDeviceSoftNFO;
|
|
for( uint8_t i = 0; i < sizeof(SOFTWARE_INFO); i++ ) ptr[i] = pReceivedPackage[ SUB_CMD_IDX+1+i];
|
|
};
|
|
LOG("CMD_STATE");
|
|
completeOperation();
|
|
break;
|
|
case CMD_QUIT:
|
|
break;
|
|
case CMD_RESET:
|
|
LOG("Reset ACK");
|
|
completeOperation();
|
|
break;
|
|
case CMD_FULL_BORDER:
|
|
case CMD_BORDER:
|
|
LOG("CMD_BORDER");
|
|
if( SUB_CMD == BD_ERRORMODE ){
|
|
LOG_ERROR("BOARD DATA ERROR!");
|
|
m_nFullBorderDataIndex = 0;
|
|
completeOperation( false );
|
|
} else if( SUB_CMD == BD_NOTREADY ){
|
|
LOG_ERROR("BOARD DATA NOT READY!");
|
|
m_nFullBorderDataIndex = 0;
|
|
completeOperation( false );
|
|
} else {
|
|
uint16_t index=6;
|
|
m_mDataMutex.lock();
|
|
while( index < ( nReceivedPackageSize-7 ) && m_nFullBorderDataIndex < TH_SIZE_NODES ){
|
|
m_pThresholdData[m_nFullBorderDataIndex].data = pReceivedPackage[index++];
|
|
m_pThresholdData[m_nFullBorderDataIndex].data = ( m_pThresholdData[m_nFullBorderDataIndex].data << 8 ) | pReceivedPackage[index++];
|
|
m_pThresholdData[m_nFullBorderDataIndex].data = ( m_pThresholdData[m_nFullBorderDataIndex].data << 8 ) | pReceivedPackage[index++];
|
|
m_pThresholdData[m_nFullBorderDataIndex].data = ( m_pThresholdData[m_nFullBorderDataIndex].data << 8 ) | pReceivedPackage[index++];
|
|
m_nFullBorderDataIndex++;
|
|
};
|
|
m_mDataMutex.unlock();
|
|
if( m_nFullBorderDataIndex < TH_SIZE_NODES ){
|
|
int proc;
|
|
proc = (int)(100.f * ( (float)m_nFullBorderDataIndex / (float)TH_SIZE_NODES ) ) ;
|
|
setCompelition( proc );
|
|
m_oProtocol->getDraw( m_nFullBorderDataIndex, m_nFullBorderKernelIndex );
|
|
comSetBusy( USE_MUTEX );
|
|
} else {
|
|
LOG("FINISH GET BOARD DATA");
|
|
m_mDataMutex.lock();
|
|
//if( m_pThresholdData!= NULL ){
|
|
// if( m_nFullBorderDataIndex > 0 ){
|
|
// FILE *fd;
|
|
// fd = fopen( "test.raw", "wb");
|
|
// if( fd!= NULL ){
|
|
// fwrite( &m_nFullBorderDataIndex, sizeof(uint32_t), 1, fd );
|
|
// fwrite( m_pThresholdData, sizeof( thresholdNode ), m_nFullBorderDataIndex, fd );
|
|
// fclose( fd );
|
|
// };
|
|
// };
|
|
//};
|
|
m_mDataMutex.unlock();
|
|
//m_pMapWidget->updateRanges( (uint32_t *) m_pThresholdData, m_nFullBorderDataIndex );
|
|
//m_pRadarWidget->updateRanges( (uint32_t *) m_pThresholdData, m_nFullBorderDataIndex );
|
|
completeOperation();
|
|
};
|
|
|
|
};
|
|
break;
|
|
case CMD_GETFILE:
|
|
break;
|
|
case CMD_RESTART:
|
|
break;
|
|
case CMD_GET_PARAMETERS:
|
|
case CMD_PARAMETERS:
|
|
case CMD_SET_PARAMETERS:{
|
|
LOG("Finish Get Params");
|
|
if( SUB_CMD == SUB_DATA_INTEGRITY_VALID ){
|
|
PLGS_PARAMETERS tParam;
|
|
if( m_pLGS_PARAMETERS != NULL ){
|
|
tParam = (PLGS_PARAMETERS) ( pReceivedPackage + 6 );
|
|
/*
|
|
m_pLGS_PARAMETERS->bSST = tParam->bSST;
|
|
|
|
for( int index = 0; index < 26; index++ )
|
|
m_pLGS_PARAMETERS->flags_binary[index] = tParam->flags_binary[index];
|
|
|
|
m_pLGS_PARAMETERS->nDelta = tParam->nDelta;
|
|
m_pLGS_PARAMETERS->nFlip = tParam->nFlip;
|
|
m_pLGS_PARAMETERS->nGPointSamples = tParam->nGPointSamples;
|
|
m_pLGS_PARAMETERS->nOffset = tParam->nOffset;
|
|
m_pLGS_PARAMETERS->nOrder = tParam->nOrder;
|
|
m_pLGS_PARAMETERS->nSun = tParam->nSun;
|
|
m_pLGS_PARAMETERS->nWidth = tParam->nWidth;
|
|
*/
|
|
memcpy(m_pLGS_PARAMETERS, tParam, sizeof(LGS_PARAMETERS));
|
|
m_bIsMaster = m_pLGS_PARAMETERS->flags.isMaster;
|
|
SLEEP( 500 );
|
|
completeOperation();
|
|
} else completeOperation();
|
|
} else {
|
|
LOG_ERROR("Data Integrity Error(on Get Parameters)!");
|
|
completeOperation( false );
|
|
};
|
|
};
|
|
break;
|
|
case CMD_HZ_INFO:{
|
|
LOG("Finish Get HZ INFO");
|
|
m_nDevicePolyCount = pReceivedPackage[6];
|
|
// Clear Existed Masks
|
|
m_pShadow->clear();
|
|
if( m_nDevicePolyCount ){
|
|
m_pShadow->setActive(( SUB_CMD > 0 ));
|
|
} else {
|
|
m_pShadow->setActive( false );
|
|
};
|
|
completeOperation();
|
|
};
|
|
break;
|
|
case CMD_SET_HZ_POLY:{
|
|
LOG("Finish Get HZ POLY");
|
|
simplePolygone *tPolygone;
|
|
tPolygone = new simplePolygone();
|
|
if( tPolygone!=NULL ){
|
|
tPolygone->count = pReceivedPackage[5];
|
|
tPolygone->color[0] = pReceivedPackage[6];
|
|
tPolygone->color[1] = pReceivedPackage[7];
|
|
tPolygone->color[2] = pReceivedPackage[8];
|
|
#ifdef __linux__
|
|
tPolygone->points = (simplePoint*) malloc( sizeof(simplePoint) * tPolygone->count );
|
|
#else
|
|
tPolygone->points = (QPoint*) malloc( sizeof(QPoint) * tPolygone->count );
|
|
#endif
|
|
if( tPolygone->count && tPolygone->points!= NULL ){
|
|
uint16_t x, y;
|
|
int index = 9;
|
|
for( int i=0; i< tPolygone->count; i++ ){
|
|
x = pReceivedPackage[index++];
|
|
x = ( x << 8 ) | pReceivedPackage[index++];
|
|
y = pReceivedPackage[index++];
|
|
y = ( y << 8 ) | pReceivedPackage[index++];
|
|
tPolygone->points[i].setX(x);
|
|
tPolygone->points[i].setY(y);
|
|
};
|
|
m_pShadow->addPoly( tPolygone );
|
|
} else {
|
|
free( tPolygone );
|
|
};
|
|
};
|
|
m_nCurrentPolyID++;
|
|
completeOperation();
|
|
};
|
|
break;
|
|
case CMD_SET_HZ_POLY_ACK:{
|
|
m_nCurrentPolyID = SUB_CMD;
|
|
if( m_nCurrentPolyID < m_pShadow->getPolyCount() ){
|
|
simplePolygone *tPoly;
|
|
tPoly = m_pShadow->getPoly( m_nCurrentPolyID );
|
|
if (tPoly != NULL){
|
|
m_oProtocol->setShadowPoly(tPoly);
|
|
comSetBusy( USE_MUTEX );
|
|
} else {
|
|
completeOperation( false );
|
|
};
|
|
} else {
|
|
LOG("Send RayTraces");
|
|
vectorZoneMask VZ;
|
|
if( m_pShadow->getZoneMask(VZ) ){
|
|
if( m_oProtocol->setShadowTrace(&VZ) ){
|
|
completeOperation();
|
|
} else {
|
|
completeOperation( false );
|
|
};
|
|
} else {
|
|
completeOperation();
|
|
};
|
|
};
|
|
};
|
|
break;
|
|
case CMD_GET_SERIAL_NUMBER:
|
|
break;
|
|
case CMD_SET_ADDRESS:
|
|
break;
|
|
case CMD_GET_SOFTWARE_VERSION:
|
|
break;
|
|
case CMD_UNSUPPORTED:
|
|
break;
|
|
case CMD_SET_COMM_SPEED:
|
|
break;
|
|
case CMD_FULL_RESET:
|
|
LOG("Full Reset ACK");
|
|
completeOperation();
|
|
break;
|
|
case CMD_CAMERA:
|
|
break;
|
|
case CMD_SET_SERIAL_NUMBER:
|
|
break;
|
|
case CMD_BOARDDATA:
|
|
break;
|
|
case CMD_GET_CAMERA_PARAMETERS:
|
|
break;
|
|
case CMD_SET_CAMERA_PARAMETERS:
|
|
break;
|
|
case CMD_RELAY:
|
|
break;
|
|
case CMD_GET_RELAY_PARAMETERS:
|
|
break;
|
|
case CMD_SET_RELAY_PARAMETERS:
|
|
break;
|
|
case CMD_FS_SUB_PACKET:
|
|
break;
|
|
case CMD_STATE_2:
|
|
m_mStatusMutex.lock();
|
|
if (SUB_CMD != m_sDeviceStatus.Status ){
|
|
m_sDeviceStatus.Status = (E_LGS_STAGE)SUB_CMD;
|
|
switch (m_sDeviceStatus.Status){
|
|
case STG_STUDY:{
|
|
m_mStatusMutex.unlock();
|
|
basicEvent *tEVT;
|
|
tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_STUDY, "Device in STUDY mode");
|
|
m_pEventHeap->broadcast( tEVT );
|
|
break;
|
|
};
|
|
case STG_REDY:{
|
|
m_mStatusMutex.unlock();
|
|
basicEvent *tEVT;
|
|
tEVT = createBasicEvent(getID(), EVT_CLASS_SENSOR, EVT_READY, "Device in DETECTION mode");
|
|
m_pEventHeap->broadcast(tEVT);
|
|
break;
|
|
};
|
|
case STG_BUSY:{
|
|
m_mStatusMutex.unlock();
|
|
basicEvent *tEVT;
|
|
tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_ERROR, "Device in BUSY mode");
|
|
m_pEventHeap->broadcast( tEVT );
|
|
break;
|
|
};
|
|
default: m_mStatusMutex.unlock();
|
|
};
|
|
} else m_mStatusMutex.unlock();
|
|
if( pReceivedPackage[DATA_BEGIN_IDX] > 0 ){
|
|
uint8_t tCount = 0;
|
|
tCount = pReceivedPackage[DATA_BEGIN_IDX];
|
|
CLIENT_EVENT *tEVT = NULL;
|
|
tEVT = (CLIENT_EVENT *) &pReceivedPackage[DATA_BEGIN_IDX+1];
|
|
for( uint8_t xindex = 0; xindex < tCount; xindex ++ ){
|
|
switch( tEVT[xindex].type ){
|
|
case EVT_TARGET_BLACK:
|
|
case EVT_TARGET_WHITE:{
|
|
char tBuffer[256];
|
|
float fRange, fAzimuth, fElevation;
|
|
uint16_t cX, cY;
|
|
bool lMaster;
|
|
uint8_t kid;
|
|
kid = tEVT[xindex].k_id & 0x07;
|
|
lMaster = ((tEVT[xindex].k_id & 0x08) == 0x08 );
|
|
fRange = 300.0 / 4095.0 * tEVT[xindex].range;
|
|
//makeCds( tData->mStartID, sX, sY, m_bIsMaster );
|
|
//makeCds( tData->mEndID, eX, eY, m_bIsMaster );
|
|
//cX = ((sX+eX)>>1);
|
|
//cY = ((sY+eY)>>1);
|
|
makeXY( tEVT[xindex].th_id, cX, cY, m_bIsMaster );
|
|
fAzimuth = 360.0 - (360.0 / TH_LINE_NODES )*cX;
|
|
fElevation = 90.0 - (Q_DEGREE_FOV/Q_SCAN_COUNT )*cY + Q_SHIFT_DOWN_FOV;
|
|
|
|
sprintf( tBuffer, "%s[%d] %s target \tRange: %.2fm. \tAzimuth: %.2f \tElevation: %.2f \tTS: %d@%d W:%d",
|
|
(lMaster?"M":"S"),
|
|
kid,
|
|
((tEVT[xindex].type == EVT_TARGET_WHITE )?"White":"Black"),
|
|
fRange,
|
|
fAzimuth,
|
|
fElevation,
|
|
tEVT[xindex].uts,
|
|
tEVT[xindex].ums,
|
|
tEVT[xindex].w_cnt*tEVT[xindex].range
|
|
);
|
|
basicEvent *bEVT = NULL;
|
|
CLIENT_EVENT *tData = NULL;
|
|
tData = (CLIENT_EVENT *) malloc(sizeof(CLIENT_EVENT));
|
|
if( tData!= NULL ){
|
|
memcpy( tData, &tEVT[xindex], sizeof(CLIENT_EVENT));
|
|
bEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, (basicEventTypeID) tEVT[xindex].type, tBuffer, tData );
|
|
if( bEVT!= NULL ) m_pEventHeap->broadcast( bEVT );
|
|
};
|
|
};
|
|
};
|
|
};
|
|
//set new stage2
|
|
m_nIdleTarget = m_nIdleTarget >> 1;
|
|
if (m_nIdleTarget < LGS_MIN_IDLE_DELAY) m_nIdleTarget = LGS_MIN_IDLE_DELAY;
|
|
//m_oProtocol->getState2();
|
|
//comSetBusy(USE_MUTEX);
|
|
} else {
|
|
m_nIdleTarget = m_nIdleTarget << 1;
|
|
if (m_nIdleTarget > LGS_MAX_IDLE_DELAY) m_nIdleTarget = LGS_MAX_IDLE_DELAY;
|
|
};
|
|
completeOperation();
|
|
break;
|
|
case CMD_GET_WIDTH_TABLE:
|
|
break;
|
|
case CMD_SET_WIDTH_TABLE:
|
|
break;
|
|
case CMD_GET_VOLTAGE:
|
|
break;
|
|
case CMD_GET_VOLTAGE_PARAMETERS:
|
|
break;
|
|
case CMD_SET_VOLTAGE_PARAMETERS:
|
|
break;
|
|
case CMD_GET_HZ_DATA:
|
|
break;
|
|
case CMD_SET_HZ_DATA:
|
|
break;
|
|
case CMD_GET_CALIBRATION_TABLE:
|
|
break;
|
|
case CMD_SET_CALIBRATION_TABLE:
|
|
break;
|
|
case CMD_GET_LRF_DISABLE:
|
|
break;
|
|
case CMD_SET_LRF_DISABLE:
|
|
break;
|
|
case CMD_GET_ZOOM_TABLE:
|
|
break;
|
|
case CMD_SET_ZOOM_TABLE:
|
|
break;
|
|
case CMD_GET_TILT_TABLE:
|
|
break;
|
|
case CMD_SET_TILT_TABLE:
|
|
break;
|
|
case CMD_GET_HZ_ENABLE:
|
|
break;
|
|
case CMD_SET_HZ_ENABLE:
|
|
break;
|
|
case CMD_EVT:
|
|
break;
|
|
case CMD_FLIP_COMPLETE:{
|
|
tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_FLIP, "Flip Complete");
|
|
m_pEventHeap->broadcast( tEVT );
|
|
break;
|
|
};
|
|
case CMD_SCAN_COMPLETE:{
|
|
tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_SCAN, "Scan Complete");
|
|
m_pEventHeap->broadcast( tEVT );
|
|
break;
|
|
};
|
|
case CMD_TARGET:{
|
|
tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_TARGET, "Target");
|
|
m_pEventHeap->broadcast( tEVT );
|
|
break;
|
|
};
|
|
case CMD_TARGET_WW:{
|
|
|
|
tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_TARGET, "Target with Width");
|
|
m_pEventHeap->broadcast( tEVT );
|
|
break;
|
|
};
|
|
case CMD_TARGET_MW:{
|
|
tData = (CLIENT_EVENT*) malloc(sizeof(CLIENT_EVENT));
|
|
if (tData != NULL){
|
|
/*
|
|
tData->mSampleID = (pReceivedPackage[5] << 24) + (pReceivedPackage[6] << 16) + (pReceivedPackage[7] << 8) + pReceivedPackage[8];
|
|
tData->mInfo = pReceivedPackage[9];
|
|
tData->mRange = (pReceivedPackage[12] << 8) + pReceivedPackage[11];
|
|
tData->mWidth = (pReceivedPackage[12] << 24) + (pReceivedPackage[13] << 16) + (pReceivedPackage[14] << 8) + pReceivedPackage[15];
|
|
//if( m_pMapWidget != NULL ) m_pMapWidget->addTarget(tData->mSampleID );
|
|
//if( m_pRadarWidget != NULL ) m_pRadarWidget->addTarget(tData->mSampleID, tData->mRange, m_bIsMaster );
|
|
tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_TARGET_WHITE, "White Intruder Detection", tData );
|
|
m_pEventHeap->broadcast( tEVT );
|
|
*/
|
|
};
|
|
break;
|
|
};
|
|
case CMD_TARGET_MB:{
|
|
tData = (CLIENT_EVENT*) malloc(sizeof(CLIENT_EVENT));
|
|
if (tData != NULL){
|
|
/*
|
|
tData->mSampleID = (pReceivedPackage[5] << 24) + (pReceivedPackage[6] << 16) + (pReceivedPackage[7] << 8) + pReceivedPackage[8];
|
|
tData->mInfo = pReceivedPackage[9];
|
|
tData->mRange = (pReceivedPackage[12] << 8) + pReceivedPackage[11];
|
|
tData->mWidth = (pReceivedPackage[12] << 24) + (pReceivedPackage[13] << 16) + (pReceivedPackage[14] << 8) + pReceivedPackage[15];
|
|
//if( m_pMapWidget != NULL ) m_pMapWidget->addTarget(tData->mSampleID, m_bIsMaster );
|
|
//if( m_pRadarWidget != NULL ) m_pRadarWidget->addTarget(tData->mSampleID, tData->mRange, m_bIsMaster );
|
|
tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_TARGET_BLACK, "Target Black", tData );
|
|
m_pEventHeap->broadcast( tEVT );
|
|
*/
|
|
};
|
|
break;
|
|
};
|
|
case CMD_TARGET_ZZ:{
|
|
if( m_eWorkMode == CWM_PINGPONG ){
|
|
tData = (CLIENT_EVENT*) malloc(sizeof(CLIENT_EVENT));
|
|
if (tData != NULL){
|
|
/*
|
|
char tBuffer[256];
|
|
float fRange, fAzimuth, fElevation;
|
|
int sX, sY, eX, eY, cX, cY;
|
|
for( int index = 0; index < sizeof(CLIENT_EVENT); index++ ){
|
|
((uint8_t*)tData)[index] = pReceivedPackage[5+index];
|
|
};
|
|
|
|
fRange = 300.0 / 4095.0 * tData->mRange;
|
|
makeCds( tData->mStartID, sX, sY, ( tData->mInfo & 0xFF000000 ) > 0 );
|
|
makeCds( tData->mEndID, eX, eY, ( tData->mInfo & 0xFF000000 ) > 0 );
|
|
cX = ((sX+eX)>>1);
|
|
cY = ((sY+eY)>>1);
|
|
fAzimuth = (360.0 / TH_LINE_NODES )*cX;
|
|
fElevation = 90.0 - (90.0/Q_SCAN_COUNT )*cY;
|
|
//if( m_pMapWidget != NULL ) m_pMapWidget->addTarget( makeIds( cX, cY ), m_bIsMaster );
|
|
//if( m_pRadarWidget != NULL ) m_pRadarWidget->addTarget( makeIds( cX, cY ), tData->mRange, m_bIsMaster );
|
|
if( ( tData->mInfo & 0x00FF0000 ) > 0 ){
|
|
sprintf( tBuffer, "[%s]:%.2fm. Azimuth: %.2f Elevation: %.2f",
|
|
(m_bIsMaster?"M":"S"),
|
|
fRange,
|
|
fAzimuth,
|
|
fElevation
|
|
);
|
|
tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_TARGET_WHITE, tBuffer, tData );
|
|
} else {
|
|
sprintf( tBuffer, "[%s]:%.2fm. Azimuth: %.2f Elevation: %.2f",
|
|
(m_bIsMaster?"M":"S"),
|
|
fRange,
|
|
fAzimuth,
|
|
fElevation
|
|
);
|
|
tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_TARGET_BLACK, tBuffer, tData );
|
|
};
|
|
m_pEventHeap->broadcast( tEVT );
|
|
*/
|
|
};
|
|
};
|
|
break;
|
|
};
|
|
default:
|
|
completeOperation( false );
|
|
break;
|
|
};
|
|
free( pReceivedPackage );
|
|
pReceivedPackage = NULL;
|
|
nReceivedPackageSize = 0;
|
|
bPackageIsArived = false;
|
|
};
|
|
};
|
|
};
|
|
};
|
|
#endif //!_BABAABBA_
|
|
bool objectLGS::startGetScanData( uint8_t kID, uint32_t *th_zone ){
|
|
if( getOperation() == CMD_FULL_BORDER ) return true;
|
|
m_mDataMutex.lock();
|
|
if( th_zone == NULL ){
|
|
if( m_pThresholdData != NULL ) free(m_pThresholdData);
|
|
m_pThresholdData = (thresholdNode *) malloc( sizeof(thresholdNode) * TH_SIZE_NODES );
|
|
} else {
|
|
m_pThresholdData = (thresholdNode *) th_zone;
|
|
};
|
|
m_nFullBorderDataIndex = 0;
|
|
m_nFullBorderKernelIndex = kID;
|
|
m_mDataMutex.unlock();
|
|
if( m_pThresholdData!= NULL ){
|
|
LOG("TH Assigned - OK");
|
|
return setOperation( CMD_FULL_BORDER );
|
|
} else {
|
|
LOG_ERROR("TH Assigned - NOK (mem issue)");
|
|
};
|
|
return false;
|
|
};
|
|
|
|
bool objectLGS::startGetParameters( uint32_t timeout ){
|
|
if (CMD_GET_PARAMETERS == getOperation()) return true;
|
|
return setOperation( CMD_GET_PARAMETERS );
|
|
};
|
|
|
|
bool objectLGS::startDeviceReset( bool FullReset ){
|
|
if( FullReset ){
|
|
if (CMD_FULL_RESET == getOperation()) return true;
|
|
return setOperation( CMD_FULL_RESET );
|
|
};
|
|
if (CMD_RESET == getOperation()) return true;
|
|
return setOperation( CMD_RESET );
|
|
};
|
|
|
|
bool objectLGS::setSettings( PLGS_PARAMETERS Params ){
|
|
memcpy( m_pLGS_PARAMETERS, Params, sizeof(LGS_PARAMETERS) );
|
|
// FillUp Default For all sensors params
|
|
m_pLGS_PARAMETERS->flags.DetectorsCount = 8;
|
|
m_pLGS_PARAMETERS->flags.MirrorsCount = 4;
|
|
if( m_bIsMaster ){
|
|
m_pLGS_PARAMETERS->flags.isMaster = 1;
|
|
|
|
} else {
|
|
m_pLGS_PARAMETERS->flags.isMaster = 0;
|
|
m_pLGS_PARAMETERS->flags.AutostartMotors = 0;
|
|
m_pLGS_PARAMETERS->flags.SignalSimulator = 0;
|
|
m_pLGS_PARAMETERS->flags.TGZ_canENA = 0;
|
|
};
|
|
|
|
if (CMD_SET_PARAMETERS == getOperation()) return true;
|
|
return setOperation( CMD_SET_PARAMETERS );
|
|
};
|
|
|
|
bool objectLGS::startUploadMask(void){
|
|
simplePolygone *tPoly;
|
|
m_nCurrentPolyID = 0;
|
|
#ifndef __linux__
|
|
m_pShadow->rasterizeVertexes();
|
|
#endif
|
|
if (setOperation(CMD_SET_HZ_POLY, true)){
|
|
return true;
|
|
};
|
|
return false;
|
|
};
|
|
|
|
bool objectLGS::startStopMotors( void ){
|
|
if (setOperation(CMD_DHWM_STOP_MOTORS, true)){
|
|
return true;
|
|
};
|
|
return false;
|
|
};
|
|
|
|
bool objectLGS::startStartMotors( void ){
|
|
if (setOperation(CMD_DHWM_START_MOTORS, true)){
|
|
return true;
|
|
};
|
|
return false;
|
|
};
|
|
|
|
bool objectLGS::startMasksStatus(bool Active){
|
|
if ( m_pShadow!=NULL ){
|
|
m_pShadow->setActive(Active);
|
|
if (setOperation(CMD_SET_HZ_STATUS, true)){
|
|
return true;
|
|
};
|
|
};
|
|
return false;
|
|
};
|
|
|
|
bool objectLGS::setHost(CSTR Host){
|
|
if( m_pHost != NULL ){
|
|
if (strcmp( m_pHost, Host ) != 0){
|
|
sprintf( m_pHost, "%s", Host );
|
|
m_pTransport->disconnect();
|
|
m_pTransport->connectTo(m_pHost, m_nPort);
|
|
};
|
|
};
|
|
return true;
|
|
};
|
|
|
|
bool objectLGS::setPort(int Port){
|
|
if( m_nPort != Port ){
|
|
m_nPort = Port;
|
|
m_pTransport->disconnect();
|
|
m_pTransport->connectTo(m_pHost, m_nPort);
|
|
};
|
|
return true;
|
|
};
|
|
|
|
bool objectLGS::setOperation( E_LGS_CMD opCode, bool fNOW ){
|
|
m_mStatusMutex.lock();
|
|
if( m_sDeviceStatus.CurrentOperation == CMD_NONE ){
|
|
m_sDeviceStatus.CurrentOperation = opCode;
|
|
} else if( fNOW ){
|
|
m_mStatusMutex.unlock();
|
|
return false;
|
|
} else if( m_sDeviceStatus.PendingOperation == CMD_NONE ){
|
|
m_sDeviceStatus.PendingOperation = opCode;
|
|
} else {
|
|
m_mStatusMutex.unlock();
|
|
return false;
|
|
};
|
|
m_mStatusMutex.unlock();
|
|
return true;
|
|
};
|
|
|
|
bool objectLGS::forceOperation( E_LGS_CMD opCode ){
|
|
m_mStatusMutex.lock();
|
|
m_sDeviceStatus.CurrentOperation = opCode;
|
|
m_mStatusMutex.unlock();
|
|
return true;
|
|
};
|
|
|
|
void objectLGS::setCompelition( uint8_t Perc ){
|
|
m_mStatusMutex.lock();
|
|
m_sDeviceStatus.ProgressIsActive = !( Perc == 0 || Perc > 100 );
|
|
m_sDeviceStatus.DoneByPercents = ( Perc + 100 )% 100;
|
|
m_mStatusMutex.unlock();
|
|
};
|
|
|
|
uint8_t objectLGS::getCompelition(void){
|
|
uint8_t RetVal;
|
|
m_mStatusMutex.lock();
|
|
RetVal = ( m_sDeviceStatus.ProgressIsActive )? m_sDeviceStatus.DoneByPercents : 100;
|
|
m_mStatusMutex.unlock();
|
|
return RetVal;
|
|
};
|
|
|
|
E_LGS_CMD objectLGS::getOperation( void ){
|
|
E_LGS_CMD tVal = CMD_NONE;
|
|
m_mStatusMutex.lock();
|
|
tVal = m_sDeviceStatus.CurrentOperation;
|
|
m_mStatusMutex.unlock();
|
|
return tVal;
|
|
};
|
|
|
|
void objectLGS::promoteOperation( void ){
|
|
m_mStatusMutex.lock();
|
|
m_sDeviceStatus.CurrentOperation = m_sDeviceStatus.PendingOperation;
|
|
m_sDeviceStatus.PendingOperation = CMD_NONE;
|
|
if( m_sDeviceStatus.CurrentOperation == CMD_NONE ){
|
|
m_mStatusMutex.unlock();
|
|
comSetIdle();
|
|
} else {
|
|
m_mStatusMutex.unlock();
|
|
comSetBusy();
|
|
};
|
|
|
|
};
|
|
|
|
void objectLGS::completeOperation( bool success ){
|
|
if( success ){
|
|
setCompelition( 100 );
|
|
m_mStatusMutex.lock();
|
|
m_sDeviceStatus.ErrorOpStatus = SUB_DATA_INTEGRITY_VALID;
|
|
m_sDeviceStatus.ErrorOpCode = CMD_NONE;
|
|
} else {
|
|
setCompelition( 0 );
|
|
m_mStatusMutex.lock();
|
|
m_sDeviceStatus.ErrorOpStatus = SUB_DATA_INTEGRITY_ERROR;
|
|
m_sDeviceStatus.ErrorOpCode = m_sDeviceStatus.CurrentOperation;
|
|
};
|
|
m_sDeviceStatus.CurrentOperation = m_sDeviceStatus.PendingOperation;
|
|
m_sDeviceStatus.PendingOperation = CMD_NONE;
|
|
if( m_sDeviceStatus.CurrentOperation == CMD_NONE ){
|
|
switch(m_eWorkMode){
|
|
case CWM_INIT: {
|
|
if( m_sDeviceSoftNFO.DATA_VALID ){
|
|
m_eWorkMode = CWM_INITIAL_PARAM;
|
|
};
|
|
break;
|
|
};
|
|
case CWM_PINGPONG: break;
|
|
case CWM_BORDER: m_eWorkMode = CWM_PINGPONG; break;
|
|
case CWM_FILE: m_eWorkMode = CWM_PINGPONG; break;
|
|
case CWM_MASK: m_eWorkMode = CWM_PINGPONG; break;
|
|
case CWM_PARAMS: m_eWorkMode = CWM_PINGPONG; break;
|
|
case CWM_INITIAL_PARAM: m_eWorkMode = CWM_INITIAL_MASKS_INFO; break;
|
|
case CWM_INITIAL_MASKS_INFO:
|
|
m_nCurrentPolyID = 0;
|
|
case CWM_INITIAL_MASKS_DATA:
|
|
if( m_nCurrentPolyID < m_nDevicePolyCount ){
|
|
m_eWorkMode = CWM_INITIAL_MASKS_DATA;
|
|
} else {
|
|
m_eWorkMode = CWM_PINGPONG;
|
|
m_bMasksAreLoadded = true;
|
|
};
|
|
break;
|
|
case CWM_ERROR: m_eWorkMode = CWM_PINGPONG; break;
|
|
};
|
|
m_mStatusMutex.unlock();
|
|
comSetIdle();
|
|
} else {
|
|
m_mStatusMutex.unlock();
|
|
comSetBusy();
|
|
};
|
|
|
|
};
|
|
|
|
void objectLGS::cleanOperation( void ){
|
|
m_mStatusMutex.lock();
|
|
m_sDeviceStatus.CurrentOperation = CMD_NONE;
|
|
m_sDeviceStatus.PendingOperation = CMD_NONE;
|
|
m_mStatusMutex.unlock();
|
|
comSetIdle();
|
|
};
|
|
|
|
bool objectLGS::comIsIdle( void ){
|
|
bool tVal = false;
|
|
if( m_mStatusMutex.try_lock() ){
|
|
if( m_sDeviceStatus.ComStatus ) tVal = ( m_sDeviceStatus.ComStatus == STG_REDY );
|
|
m_mStatusMutex.unlock();
|
|
};
|
|
return tVal;
|
|
};
|
|
|
|
void objectLGS::comSetIdle( bool useMutex ){
|
|
if( useMutex ) m_mStatusMutex.lock();
|
|
if( m_sDeviceStatus.ComStatus == STG_BUSY ) m_sDeviceStatus.ComStatus = STG_REDY;
|
|
m_nBusyCounter = 0;
|
|
if( useMutex ) m_mStatusMutex.unlock();
|
|
};
|
|
|
|
void objectLGS::comSetBusy( bool useMutex ){
|
|
if( useMutex ) m_mStatusMutex.lock();
|
|
if( m_sDeviceStatus.ComStatus == STG_REDY ) m_sDeviceStatus.ComStatus = STG_BUSY;
|
|
m_nBusyCounter = 0;
|
|
if( useMutex ) m_mStatusMutex.unlock();
|
|
};
|
|
|
|
#undef LOG
|
|
#undef LOG_ERROR
|