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.
771 lines
26 KiB
771 lines
26 KiB
/*******************************************************************
|
|
*
|
|
* DESCRIPTION: ARGUS Kernel source
|
|
*
|
|
* AUTHOR: gagua
|
|
*
|
|
* HISTORY:
|
|
*
|
|
* DATE:5/29/2019
|
|
*
|
|
*******************************************************************/
|
|
#include "rgooseKernel.h"
|
|
#include <sys/types.h>
|
|
|
|
#define LOG( X ) m_pLog->Log( "KRNL", this, X )
|
|
|
|
#ifdef DEBUG
|
|
#define LOG_ERROR( X ) {\
|
|
char _tBfrErrMSG2w34[256];\
|
|
sprintf( _tBfrErrMSG2w34, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
|
|
m_pLog->Log( "KRNL", this, _LOG_ERROR, _tBfrErrMSG2w34 );\
|
|
}
|
|
#else
|
|
#define LOG_ERROR( X ) m_pLog->Log( "KRNL", this, _LOG_ERROR, X );
|
|
#endif
|
|
|
|
argusKernel *argusKernel::_instance = NULL;
|
|
|
|
/**
|
|
* Returns the single instance of the object.
|
|
*/
|
|
argusKernel* argusKernel::getInstance( config_setting_t *Settings ) {
|
|
// check if the instance has been created yet
|
|
if( 0 == _instance ){
|
|
// if not, then create it
|
|
_instance = new argusKernel( Settings );
|
|
};
|
|
// return the single instance
|
|
return _instance;
|
|
};
|
|
|
|
argusKernel::argusKernel( config_setting_t *Settings ):basicThread(), basicEventHandler(){
|
|
m_bExitCause = 0;
|
|
m_nServerID = 0;
|
|
m_nSiteID = 0;
|
|
m_pDBC = NULL;
|
|
m_tTimeTSeconds = time( NULL );
|
|
m_pLog = basicLogCollection::getInstance();
|
|
m_pSettings = basicSettingsProvider::getInstance()->getSubNode( Settings, "KERNEL" );
|
|
m_pServiceAnnouncer = NULL;
|
|
m_pEventHeap = NULL;
|
|
m_pOnvifMediaObserver = NULL;
|
|
m_pNodeFactory = NULL;
|
|
m_pModuleFactory = NULL;
|
|
#ifdef SIMULATE_KERNEL_TARGETS
|
|
sprintf( m_cCurrentMission,"" );
|
|
m_bLandingTO = 0;
|
|
m_bJamingTO = 0;
|
|
#endif
|
|
};
|
|
|
|
argusKernel::~argusKernel(){
|
|
#ifdef DEBUG
|
|
LOG("Destructor");
|
|
#endif
|
|
WaitFinish(true);
|
|
if( m_pDBC != NULL ) m_pDBC->unregisterServer( m_nSiteID, m_nServerNodeID );
|
|
#ifdef DEBUG
|
|
LOG("Deleting Components");
|
|
#endif
|
|
if( m_pStreamManager != NULL ) delete( m_pStreamManager );
|
|
|
|
//Last DBC
|
|
if( m_pDBC != NULL ) delete( m_pDBC );
|
|
#ifdef DEBUG
|
|
LOG("Destructor Finished");
|
|
#endif
|
|
};
|
|
|
|
bool argusKernel::create( void ){
|
|
char tBuffer[256];
|
|
if( m_pSettings != NULL ) {
|
|
config_setting_t * pSetting;
|
|
int tVal;
|
|
const char * tBuf;
|
|
//Connect( CSTR DBName, CSTR DBHost, CSTR DBUser, CSTR DBPassword, uint16_t Port = 3300 );
|
|
LOG("Getting Settings ...");
|
|
if( !config_setting_lookup_string( m_pSettings, ARGUS_KERNEL_TAG_SERVER_IDENTITY, &tBuf ) ){
|
|
char * tVar;
|
|
char * tTS;
|
|
tTS = getTStr(NULL);
|
|
tVar = MD5String(tTS);
|
|
free(tTS);
|
|
sprintf( m_sIdentity, tVar );
|
|
pSetting = config_setting_add( m_pSettings, ARGUS_KERNEL_TAG_SERVER_IDENTITY, CONFIG_TYPE_STRING );
|
|
config_setting_set_string( pSetting, tVar );
|
|
free( tVar );
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
LOG("Server Identity not defined - generating new!");
|
|
} else {
|
|
sprintf( m_sIdentity, tBuf );
|
|
sprintf( tBuffer, "Server Identity Read From Settings: %s", tBuf );
|
|
LOG( tBuffer );
|
|
};
|
|
if( !config_setting_lookup_int( m_pSettings, ARGUS_KERNEL_TAG_SITE_ID, &tVal ) ){
|
|
tVal = m_nSiteID = 1;
|
|
pSetting = config_setting_add( m_pSettings, ARGUS_KERNEL_TAG_SITE_ID, CONFIG_TYPE_INT );
|
|
config_setting_set_int( pSetting, tVal );
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
LOG("Site ID not defined - using [1] as number!");
|
|
} else {
|
|
m_nSiteID = tVal;
|
|
sprintf( tBuffer, "Site ID Read From Settings: %d", m_nSiteID );
|
|
LOG( tBuffer );
|
|
};
|
|
} else {
|
|
LOG_ERROR("Failed Read Config Settings!");
|
|
return false;
|
|
};
|
|
|
|
if( m_pDBC == NULL ) {
|
|
LOG("Explicitly Create DBC Object");
|
|
m_pDBC = argusDBC::getInstance( m_pSettings );
|
|
};
|
|
if( m_pDBC == NULL ){
|
|
LOG_ERROR("DBC Object Creation Failure!");
|
|
return false;
|
|
};
|
|
if(!m_pDBC->connect()){
|
|
LOG_ERROR("DBC Connection Failure!");
|
|
SLEEP(5000);
|
|
//ToDO: Set Restart Kernel!
|
|
return false;
|
|
};
|
|
#ifdef DEBUG
|
|
LOG( "Settings Read Done" );
|
|
#endif
|
|
m_pDBC->registerServer( m_nSiteID, m_sIdentity );
|
|
m_nServerID = m_pDBC->getServerID( m_sIdentity );
|
|
m_nServerNodeID = m_pDBC->getServerNode( m_nServerID );
|
|
|
|
DBC_SITE_DATA *tSiteData = m_pDBC->getSiteData( m_nSiteID );
|
|
if( tSiteData ) {
|
|
C3D_WGS84_LOC t;
|
|
t.lat = tSiteData->lat;
|
|
t.lon = tSiteData->lon;
|
|
t.alt = tSiteData->alt;
|
|
m_pSystemAnchor = systemAnchor::getInstance( tSiteData->SH, &t );
|
|
free( tSiteData );
|
|
} else {
|
|
LOG_ERROR("Error Loading Site DATA!");
|
|
};
|
|
//Init Subcomponents
|
|
m_pHardwareManager = argusHardwareManager::getInstance();
|
|
if( m_pHardwareManager!= NULL ) {
|
|
m_pHardwareManager->validate();
|
|
} else {
|
|
LOG_ERROR("Failure to get HardwareManager Instance!");
|
|
return false;
|
|
};
|
|
m_pServiceAnnouncer = new ssdpAnnouncer( m_pSettings );
|
|
if( basicSettingsProvider::getInstance()->isCompromised() ) {
|
|
basicSettingsProvider::getInstance()->validate();
|
|
};
|
|
|
|
m_pEventHeap = basicEventHeap::getInstance();
|
|
|
|
m_pOnvifMediaObserver = onvifMediaObserver::getInstance();
|
|
|
|
m_pNodeFactory = argusNodeFactory::getInstance();
|
|
|
|
m_pModuleFactory = argusModuleFactory::getInstance();
|
|
|
|
//enumerateHardware();
|
|
|
|
|
|
//m_pNodeFactory->setDBC( m_pDBC );
|
|
m_pNodeFactory->loadNodes( m_nSiteID );
|
|
|
|
//m_pModuleFactory->setDBC( m_pDBC ); //m_pDBC->getIPCamRecords( m_vCamRecords );
|
|
m_pModuleFactory->loadModules( m_nSiteID );
|
|
|
|
#ifdef DEBUG
|
|
LOG( "Start SSDP Beacon" );
|
|
#endif
|
|
|
|
if( m_pServiceAnnouncer != NULL ) {
|
|
if( !m_pServiceAnnouncer->init() ){
|
|
delete(m_pServiceAnnouncer);
|
|
m_pServiceAnnouncer = NULL;
|
|
};
|
|
};
|
|
|
|
m_pStreamManager = NULL;//mediaNginxManager::getInstance();
|
|
//if( m_pStreamManager != NULL ) {
|
|
// m_pStreamManager->attachStream("rtsp://gagua:4GetMyID@192.168.0.104:554/Streaming/Channels/101?transportmode=unicast&profile=Profile_1", true, 12, "12918" );
|
|
//};
|
|
/*
|
|
#ifdef DEBUG
|
|
LOG("Init IP Cameras");
|
|
#endif
|
|
if( m_vCamRecords.size() ) {
|
|
ARGUS_Camera *tPtr = NULL;
|
|
for( int i=0; i < m_vCamRecords.size(); i++ ) {
|
|
tPtr = new ARGUS_Camera();
|
|
if( tPtr != NULL ) {
|
|
if( tPtr->create( m_vCamRecords.at(i)->ip, m_vCamRecords.at(i)->username, m_vCamRecords.at(i)->password ) ){
|
|
#ifdef DEBUG
|
|
LOG("Camera Created!");
|
|
#endif
|
|
m_vCameras.push_back( tPtr );
|
|
tPtr = NULL;
|
|
} else {
|
|
LOG_ERROR("Camera Creation Failure!");
|
|
delete( tPtr );
|
|
tPtr = NULL;
|
|
};
|
|
};
|
|
};
|
|
};
|
|
*/
|
|
|
|
#ifdef DEBUG
|
|
LOG("Start OnVIF Discovery");
|
|
#endif
|
|
if( m_pOnvifMediaObserver!= NULL ) {
|
|
m_pOnvifMediaObserver->startDiscovery();
|
|
m_bDiscoveryStarted = true;
|
|
};
|
|
|
|
#ifdef DEBUG
|
|
LOG( "Kernel Trhead is about to be Created" );
|
|
#endif
|
|
if( init() == false ){
|
|
LOG_ERROR("Error in starting Kernel Thread!");
|
|
return false;
|
|
};
|
|
#ifdef DEBUG
|
|
LOG( "Kernel Thread Created" );
|
|
#endif
|
|
/*
|
|
m_pServletWS = new servletWS();
|
|
if( m_pServletWS != NULL ) {
|
|
LOG("ServletWS Created");
|
|
if(m_pServletWS->create(8080)){
|
|
LOG("ServletWS Started");
|
|
//if( ! m_pServletWS->attachChannel("rtsp://gagua:4GetMyID@192.168.0.109:554/Streaming/Channels/101?transportmode=unicast&profile=Profile_1", false ) ){
|
|
// LOG("Error Adding Channel!");
|
|
//} else {
|
|
// LOG("Channel Attached");
|
|
//};
|
|
};
|
|
};
|
|
*/
|
|
#ifdef DEBUG
|
|
sprintf( tBuffer, "Server is registered as id[%d]", m_nServerID );
|
|
LOG( tBuffer );
|
|
#endif
|
|
return true;
|
|
};
|
|
|
|
void argusKernel::WaitFinish( bool Force ){
|
|
if( Force ){
|
|
#ifdef DEBUG
|
|
LOG( "Thread End Forced" );
|
|
#endif
|
|
} else {
|
|
// 3 seconds sleep to settle down processes
|
|
SLEEP(3000);
|
|
};
|
|
waitThreadEnd( Force );
|
|
#ifdef DEBUG
|
|
LOG( "Thread is Detached" );
|
|
#endif
|
|
};
|
|
|
|
/* Main Kernel Thread Procedure */
|
|
void argusKernel::m_fThreadProc( void ){
|
|
char Buffer[CTEXT];
|
|
time_t tTimeTSeconds;
|
|
int lastTSS = 0;
|
|
int lastTMS = 0;
|
|
DBC_EVT_DATA * tEvtPtr;
|
|
pid_t pid = gettid();
|
|
char pidBuf[16];
|
|
sprintf(pidBuf,"KERNEL pid:%d", pid);
|
|
LOG( pidBuf );
|
|
#ifdef SIMULATE_KERNEL_TARGETS
|
|
LOG("SIMULATION ENABLED");
|
|
#endif
|
|
m_bThreadStatus = TH_WORKING;
|
|
while( m_bThreadStatus < TH_ENDED ){
|
|
m_tTimeTSeconds = time( NULL );
|
|
|
|
// Network IP OnVif Discovery
|
|
//*
|
|
if( m_pOnvifMediaObserver!= NULL ){
|
|
if( !m_bDiscoveryStarted ) {
|
|
if((m_tTimeTSeconds%ONVIF_DISCOVERY_INTERVAL)==0){
|
|
#ifdef DEBUG
|
|
LOG("Start OnVIF Discovery");
|
|
#endif
|
|
m_pOnvifMediaObserver->startDiscovery();
|
|
m_bDiscoveryStarted = true;
|
|
};
|
|
} else {
|
|
//*
|
|
if((m_tTimeTSeconds%ONVIF_DISCOVERY_INTERVAL)==ONVIF_DISCOVERY_RESULT_TIME){
|
|
#ifdef DEBUG
|
|
LOG("Validate IP Cameras");
|
|
#endif
|
|
validateCameras();
|
|
m_bDiscoveryStarted = false;
|
|
};
|
|
//*/
|
|
};
|
|
};
|
|
//*/
|
|
//*
|
|
// Web CTRL Event Processing Loop
|
|
if( !m_pDBC->getLastEvents( m_vEvtRecords, lastTSS, lastTMS ) ){
|
|
// Error In DB Access
|
|
m_bThreadStatus = TH_ENDED;
|
|
m_bExitCause = 1;
|
|
continue;
|
|
};
|
|
//*/
|
|
if( m_tTimeTSeconds != tTimeTSeconds ){ // Each Second Process
|
|
tTimeTSeconds = m_tTimeTSeconds;
|
|
if( m_pModuleFactory != NULL ) {
|
|
m_pModuleFactory->validate();
|
|
};
|
|
if( m_pNodeFactory != NULL ) {
|
|
m_pNodeFactory->validate();
|
|
};
|
|
};
|
|
if( m_vEvtRecords.size() > 0 ){
|
|
validateEvents( lastTSS, lastTMS );
|
|
// SLEEP( 2 ); // short loop if had an events
|
|
} else SLEEP( SLEEP_KERNEL_INTERVAL );
|
|
|
|
|
|
#ifdef SIMULATE_KERNEL_TARGETS
|
|
/*
|
|
// Simulate FlyHunter
|
|
if( m_tTimeTSeconds!= m_nEachSec ) {
|
|
m_nEachSec = m_tTimeTSeconds;
|
|
if( m_bLandingTO ) {
|
|
m_bLandingTO--;
|
|
if( m_bLandingTO == 1 ) {
|
|
//Landing
|
|
LOG("Simulate Landing");
|
|
LOG( m_cCurrentMission );
|
|
//Simulate FH Module Event;
|
|
EVENT_CONTAINER *ttt;
|
|
FH_MISSION_DATA * nnn = (FH_MISSION_DATA *) malloc( sizeof(FH_MISSION_DATA));
|
|
if( nnn ){
|
|
nnn->location.lat = 0;
|
|
nnn->location.lon = 0;
|
|
nnn->location.alt = 0;
|
|
sprintf( nnn->missionID, m_cCurrentMission );
|
|
ttt = createBasicEvent( 0, EVT_CLASS_FLY_HUNTER, EVT_FH_LANDED, NULL, nnn );
|
|
if( ttt ) {
|
|
m_pEventHeap->broadcast( ttt );
|
|
} else {
|
|
free( nnn );
|
|
};
|
|
};
|
|
};
|
|
};
|
|
if( m_bJamingTO ) {
|
|
m_bJamingTO--;
|
|
if( m_bJamingTO == 1 ) {
|
|
//Jaming Off
|
|
//Simulate FH Module Event;
|
|
EVENT_CONTAINER *ttt;
|
|
FH_MISSION_DATA * nnn = (FH_MISSION_DATA *) malloc( sizeof(FH_MISSION_DATA));
|
|
if( nnn ){
|
|
nnn->location.lat = 0;
|
|
nnn->location.lon = 0;
|
|
nnn->location.alt = 0;
|
|
sprintf( nnn->missionID, m_cCurrentMission );
|
|
ttt = createBasicEvent( 0, EVT_CLASS_FLY_HUNTER, EVT_FH_JAMER_OFF, NULL, nnn );
|
|
if( ttt ) {
|
|
m_pEventHeap->broadcast( ttt );
|
|
} else {
|
|
free( nnn );
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
*/
|
|
|
|
//Target Simulation To Test Events - Database
|
|
if(( m_tTimeTSeconds%SIMULATE_KERNEL_INTERVAL)==(SIMULATE_KERNEL_INTERVAL>>1)){
|
|
if( m_tTimeTSeconds!= m_nLastSimRun ){
|
|
m_nLastSimRun = m_tTimeTSeconds;
|
|
if( m_pNodeFactory != NULL ) {
|
|
argusNetNode *tNode = m_pNodeFactory->getNode( SIMULATE_KERNEL_NODE_ID );
|
|
if( tNode!= NULL ) {
|
|
tNode->simulateTarget();
|
|
};
|
|
};
|
|
};
|
|
};
|
|
#endif
|
|
};
|
|
};
|
|
|
|
|
|
int argusKernel::isCameraListed( CSTR uid ){
|
|
if( m_vCamRecords.size() ){
|
|
for( int index = 0; index < m_vCamRecords.size(); index++ ){
|
|
if(strstr(m_vCamRecords.at(index)->uuid,uid)!=NULL){
|
|
m_vCamRecords.at(index)->online = true;
|
|
return index;
|
|
};
|
|
};
|
|
} else {
|
|
LOG("No Registered Cameras!");
|
|
};
|
|
return -1;
|
|
};
|
|
|
|
void argusKernel::validateCameras( void ){
|
|
vectorWoWoResults *DiscoverResults = m_pOnvifMediaObserver->getResults();
|
|
if( DiscoverResults->size() > 0 ) {
|
|
for (int index = 0; index < DiscoverResults->size(); index++) {
|
|
char tBuffer[256];
|
|
sprintf( tBuffer,"Found Camwera [%s] %s", DiscoverResults->at(index)->XAddrs, DiscoverResults->at(index)->RefID );
|
|
LOG( tBuffer );
|
|
uint32_t cid = m_pDBC->getCamId( DiscoverResults->at(index)->RefID ); //isCameraListed( DiscoverResults->at(index)->RefID );
|
|
if( cid ) {
|
|
sprintf( tBuffer, "Camera is Listed as %d", cid );
|
|
LOG( tBuffer );
|
|
//if( strstr(DiscoverResults->at(index)->XAddrs,m_vCamRecords.at(cid)->ip)==NULL ) {
|
|
// LOG( DiscoverResults->at(index)->XAddrs );
|
|
m_pDBC->updateIPCam( m_nSiteID, cid, DiscoverResults->at(index)->XAddrs );// DiscoverResults->at(index));
|
|
//};
|
|
} else {
|
|
// Uncknown camera - no checking
|
|
LOG("Camera is Not Listed");
|
|
m_pDBC->addIPCam( m_nSiteID, DiscoverResults->at(index) );
|
|
};
|
|
};
|
|
} else {
|
|
LOG("No Online IP Cameras in Network");
|
|
};
|
|
};
|
|
|
|
void argusKernel::validateEvents( int &lastTSS, int &lastTMS ){
|
|
DBC_EVT_DATA *tPtr = NULL;
|
|
EVENT_CONTAINER *tEvt = NULL;
|
|
if(m_vEvtRecords.size()) {
|
|
lastTSS = m_vEvtRecords.at(m_vEvtRecords.size()-1)->ts_s;
|
|
lastTMS = m_vEvtRecords.at(m_vEvtRecords.size()-1)->ts_ms;
|
|
#ifndef ONE_EVENT_PER_LOOP
|
|
while( m_vEvtRecords.size() ){
|
|
#endif
|
|
tPtr = *m_vEvtRecords.begin();
|
|
if( tPtr != NULL ) {
|
|
if( tEvt != NULL ) {
|
|
m_pEventHeap->broadcast( tEvt );
|
|
};
|
|
free( tPtr );
|
|
};
|
|
m_vEvtRecords.erase( m_vEvtRecords.begin() );
|
|
#ifndef ONE_EVENT_PER_LOOP
|
|
};
|
|
#endif
|
|
};
|
|
};
|
|
|
|
|
|
bool argusKernel::signalEvent( void ){
|
|
if( m_pDBC->getLastEvents( m_vEvtRecords, 0,0 ) ){
|
|
|
|
|
|
|
|
};
|
|
return true;
|
|
};
|
|
|
|
int argusKernel::getNetNodes( ARGUS_NODE_TYPE type, argusNetNode **&RA ){
|
|
RA = NULL;
|
|
int cnt = 0;
|
|
if( m_pNodeFactory != NULL ){
|
|
cnt = m_pNodeFactory->getNodesCount( type );
|
|
if( cnt ) {
|
|
RA = (argusNetNode **) calloc( cnt, sizeof( argusNetNode * ) );
|
|
m_pNodeFactory->fetchNodes(type, RA );
|
|
};
|
|
};
|
|
return cnt;
|
|
};
|
|
|
|
argusNetNode *argusKernel::getNetNode( int id ){
|
|
if( m_pNodeFactory != NULL ){
|
|
return m_pNodeFactory->getNode( id );
|
|
};
|
|
return NULL;
|
|
};
|
|
|
|
int argusKernel::getModules( ARGUS_MODULE_TYPE type, argusKernelModule **&RA ){
|
|
RA = NULL;
|
|
int cnt = 0;
|
|
if( m_pModuleFactory != NULL ){
|
|
cnt = m_pModuleFactory->getModulesCount( type );
|
|
if( cnt ) {
|
|
RA = (argusKernelModule **) calloc( cnt, sizeof( argusKernelModule * ) );
|
|
m_pModuleFactory->fetchModules( type, RA );
|
|
};
|
|
};
|
|
return cnt;
|
|
};
|
|
|
|
argusKernelModule *argusKernel::getModule( int id ){
|
|
if( m_pModuleFactory != NULL ){
|
|
return m_pModuleFactory->getModule( id );
|
|
};
|
|
return NULL;
|
|
};
|
|
|
|
void argusKernel::dispatchEvent( EVENT_CONTAINER *Evt ){
|
|
// Register all events in Database;
|
|
LOG( "New EVENT!!" );
|
|
if( m_pDBC == NULL ) return;
|
|
if( Evt == NULL ) return;
|
|
switch( Evt->m_eClass ) {
|
|
case EVT_CLASS_EXTERNAL_CMD:
|
|
switch( Evt->m_eType ){
|
|
case EVT_FH_JAMER_ON:{
|
|
uint32_t TS_A, TS_B;
|
|
TS_A = Evt->m_UMSTS / 1000;
|
|
TS_B = Evt->m_UMSTS % 1000;
|
|
#ifdef SIMULATE_KERNEL_TARGETS
|
|
m_bJamingTO = SIMULATE_JAMER_TO;
|
|
#endif
|
|
FH_CTRL_DATA * tData = (FH_CTRL_DATA *) Evt->m_pEvtData;
|
|
if( tData ) {
|
|
if( m_pDBC->addEvent(
|
|
0,
|
|
Evt->m_UUID,
|
|
TS_A,
|
|
TS_B,
|
|
EVT_FH_JAMER_ON,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
tData->evtUUID
|
|
) ){
|
|
//Simulate FH Module Event;
|
|
EVENT_CONTAINER *ttt;
|
|
FH_MISSION_DATA * nnn = (FH_MISSION_DATA *) malloc( sizeof(FH_MISSION_DATA));
|
|
if( nnn ){
|
|
nnn->location.lat = 0;
|
|
nnn->location.lon = 0;
|
|
nnn->location.alt = 0;
|
|
sprintf( nnn->missionID, tData->evtUUID );
|
|
ttt = createBasicEvent( 0, EVT_CLASS_FLY_HUNTER, EVT_FH_JAMER_ON, NULL, nnn );
|
|
if( ttt ) {
|
|
m_pEventHeap->broadcast( ttt );
|
|
} else {
|
|
free( nnn );
|
|
};
|
|
};
|
|
};
|
|
free(tData);
|
|
};
|
|
break;
|
|
};
|
|
case EVT_FH_MISSION_END:{
|
|
FH_CTRL_DATA * tData = (FH_CTRL_DATA *) Evt->m_pEvtData;
|
|
if( tData ) {
|
|
//DBC_EVT_DATA * tEVT = m_pDBC->getEventByUUID( tData->targetUUID );
|
|
if( 1 /*tEVT*/ ) {
|
|
uint32_t TS_A, TS_B;
|
|
TS_A = Evt->m_UMSTS / 1000;
|
|
TS_B = Evt->m_UMSTS % 1000;
|
|
if( m_pDBC->addEvent(
|
|
0,
|
|
Evt->m_UUID,
|
|
TS_A,
|
|
TS_B,
|
|
EVT_FH_LANDED,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,//tEVT->lat,
|
|
0,//tEVT->lon,
|
|
0,//tEVT->alt,
|
|
0//tEVT->uuid
|
|
) ){
|
|
//Simulate FH Module Event;
|
|
EVENT_CONTAINER *ttt;
|
|
FH_MISSION_DATA * nnn = (FH_MISSION_DATA *) malloc( sizeof(FH_MISSION_DATA));
|
|
if( nnn ){
|
|
nnn->location.lat = 0;//tEVT->lat;
|
|
nnn->location.lon = 0;//tEVT->lon;
|
|
nnn->location.alt = 0;//tEVT->alt;
|
|
sprintf( nnn->missionID, tData->evtUUID );
|
|
ttt = createBasicEvent( 0, EVT_CLASS_FLY_HUNTER, EVT_FH_LANDED, NULL, nnn );
|
|
if( ttt ) {
|
|
m_pEventHeap->broadcast( ttt );
|
|
} else {
|
|
free( nnn );
|
|
};
|
|
};
|
|
};
|
|
//free( tEVT );
|
|
} else {
|
|
LOG_ERROR("Linked Event Was Not Found!");
|
|
};
|
|
};
|
|
break;
|
|
}
|
|
case EVT_FH_MISSION_BEGIN:{
|
|
FH_CTRL_DATA * tData = (FH_CTRL_DATA *) Evt->m_pEvtData;
|
|
#ifdef SIMULATE_KERNEL_TARGETS
|
|
m_bLandingTO = SIMULATE_LANDING_TO;
|
|
#endif
|
|
if( tData ) {
|
|
#ifdef SIMULATE_KERNEL_TARGETS
|
|
sprintf( m_cCurrentMission, tData->evtUUID );
|
|
#endif
|
|
DBC_EVT_DATA * tEVT = m_pDBC->getEventByUUID( tData->targetUUID );
|
|
if( tEVT ) {
|
|
uint32_t TS_A, TS_B;
|
|
TS_A = Evt->m_UMSTS / 1000;
|
|
TS_B = Evt->m_UMSTS % 1000;
|
|
if( m_pDBC->addEvent(
|
|
0,
|
|
Evt->m_UUID,
|
|
TS_A,
|
|
TS_B,
|
|
EVT_FH_FLY_TO,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
tEVT->lat,
|
|
tEVT->lon,
|
|
tEVT->alt,
|
|
tEVT->uuid
|
|
) ){
|
|
//Simulate FH Module Event;
|
|
EVENT_CONTAINER *ttt;
|
|
FH_MISSION_DATA * nnn = (FH_MISSION_DATA *) malloc( sizeof(FH_MISSION_DATA));
|
|
if( nnn ){
|
|
nnn->location.lat = tEVT->lat;
|
|
nnn->location.lon = tEVT->lon;
|
|
nnn->location.alt = tEVT->alt;
|
|
sprintf( nnn->missionID, tData->evtUUID );
|
|
ttt = createBasicEvent( 0, EVT_CLASS_FLY_HUNTER, EVT_FH_MISSION_BEGIN, NULL, nnn );
|
|
if( ttt ) {
|
|
m_pEventHeap->broadcast( ttt );
|
|
} else {
|
|
free( nnn );
|
|
};
|
|
};
|
|
};
|
|
free( tEVT );
|
|
} else {
|
|
LOG_ERROR("Linked Event Was Not Found!");
|
|
};
|
|
};
|
|
break;
|
|
};
|
|
};
|
|
break;
|
|
case EVT_CLASS_SENSOR_CLD:
|
|
case EVT_CLASS_SENSOR_LGS:
|
|
case EVT_CLASS_SENSOR_LFS:
|
|
case EVT_CLASS_SENSOR_MND:
|
|
case EVT_CLASS_SENSOR_PLS_210:
|
|
case EVT_CLASS_SENSOR_PLS_360:
|
|
case EVT_CLASS_SENSOR_ALS:
|
|
case EVT_CLASS_SENSOR_3D:
|
|
case EVT_CLASS_SENSOR_ACC:
|
|
switch( Evt->m_eType ) {
|
|
case EVT_TARGET_1D:{
|
|
TARGET_DATA *tDATA =(TARGET_DATA *) Evt->m_pEvtData;
|
|
if( tDATA != NULL ) {
|
|
uint32_t TS_A, TS_B;
|
|
TS_A = Evt->m_UMSTS / 1000;
|
|
TS_B = Evt->m_UMSTS % 1000;
|
|
m_pDBC->addEvent(
|
|
Evt->m_nSourceUID,
|
|
Evt->m_UUID,
|
|
TS_A,
|
|
TS_B,
|
|
Evt->m_eType,
|
|
0,
|
|
0,
|
|
0,
|
|
tDATA->local_target.r,
|
|
tDATA->area,
|
|
tDATA->global_target.lat,
|
|
tDATA->global_target.lon,
|
|
tDATA->global_target.alt
|
|
);
|
|
};
|
|
break;
|
|
};
|
|
case EVT_TARGET_2D_BLACK:
|
|
case EVT_TARGET_2D_WHITE:{
|
|
TARGET_DATA *tDATA = (TARGET_DATA *)Evt->m_pEvtData;
|
|
if( tDATA != NULL ) {
|
|
uint32_t TS_A, TS_B;
|
|
TS_A = Evt->m_UMSTS / 1000;
|
|
TS_B = Evt->m_UMSTS % 1000;
|
|
m_pDBC->addEvent(
|
|
Evt->m_nSourceUID,
|
|
Evt->m_UUID,
|
|
TS_A,
|
|
TS_B,
|
|
Evt->m_eType,
|
|
0,
|
|
tDATA->local_target.fi,
|
|
0,
|
|
tDATA->local_target.r,
|
|
tDATA->area,
|
|
tDATA->global_target.lat,
|
|
tDATA->global_target.lon,
|
|
tDATA->global_target.alt
|
|
);
|
|
};
|
|
break;
|
|
};
|
|
case EVT_TARGET_3D_BLACK:
|
|
case EVT_TARGET_3D_WHITE:{
|
|
TARGET_DATA *tDATA = (TARGET_DATA *) Evt->m_pEvtData;
|
|
if( tDATA != NULL ) {
|
|
uint32_t TS_A, TS_B;
|
|
TS_A = Evt->m_UMSTS / 1000;
|
|
TS_B = Evt->m_UMSTS % 1000;
|
|
m_pDBC->addEvent(
|
|
Evt->m_nSourceUID,
|
|
Evt->m_UUID,
|
|
TS_A,
|
|
TS_B,
|
|
Evt->m_eType,
|
|
0,
|
|
tDATA->local_target.fi,
|
|
tDATA->local_target.tetta,
|
|
tDATA->local_target.r,
|
|
tDATA->area,
|
|
tDATA->global_target.lat,
|
|
tDATA->global_target.lon,
|
|
tDATA->global_target.alt
|
|
);
|
|
};
|
|
break;
|
|
};
|
|
};
|
|
break;
|
|
};
|
|
};
|
|
|
|
#undef LOG
|
|
#undef LOG_ERROR
|
|
|