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

6 years ago
​
​
​
​
​
​
​
​
​
​
​
6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
6 years ago
​
​
​
​
​
6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
6 years ago
​
​
​
6 years ago
​
​
​
​
​
​
​
6 years ago
​
​
​
​
6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
6 years ago
​
​
​
​
​
​
​
​
​
​
6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
6 years ago
​
​
​
​
6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
6 years ago
​
​
  1. /*******************************************************************
  2. *
  3. * DESCRIPTION: ARGUS Kernel source
  4. *
  5. * AUTHOR: gagua
  6. *
  7. * HISTORY:
  8. *
  9. * DATE:5/29/2019
  10. *
  11. *******************************************************************/
  12. #include "rgooseKernel.h"
  13. #include <sys/types.h>
  14. #define LOG( X ) m_pLog->Log( "KRNL", this, X )
  15. #ifdef DEBUG
  16. #define LOG_ERROR( X ) {\
  17. char _tBfrErrMSG2w34[256];\
  18. sprintf( _tBfrErrMSG2w34, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
  19. m_pLog->Log( "KRNL", this, _LOG_ERROR, _tBfrErrMSG2w34 );\
  20. }
  21. #else
  22. #define LOG_ERROR( X ) m_pLog->Log( "KRNL", this, _LOG_ERROR, X );
  23. #endif
  24. argusKernel *argusKernel::_instance = NULL;
  25. /**
  26. * Returns the single instance of the object.
  27. */
  28. argusKernel* argusKernel::getInstance( config_setting_t *Settings ) {
  29. // check if the instance has been created yet
  30. if( 0 == _instance ){
  31. // if not, then create it
  32. _instance = new argusKernel( Settings );
  33. };
  34. // return the single instance
  35. return _instance;
  36. };
  37. argusKernel::argusKernel( config_setting_t *Settings ):basicThread(), basicEventHandler(){
  38. m_bExitCause = 0;
  39. m_nServerID = 0;
  40. m_nSiteID = 0;
  41. m_pDBC = NULL;
  42. m_tTimeTSeconds = time( NULL );
  43. m_pLog = basicLogCollection::getInstance();
  44. m_pSettings = basicSettingsProvider::getInstance()->getSubNode( Settings, "KERNEL" );
  45. m_pServiceAnnouncer = NULL;
  46. m_pEventHeap = NULL;
  47. m_pOnvifMediaObserver = NULL;
  48. m_pNodeFactory = NULL;
  49. m_pModuleFactory = NULL;
  50. #ifdef SIMULATE_KERNEL_TARGETS
  51. sprintf( m_cCurrentMission,"" );
  52. m_bLandingTO = 0;
  53. m_bJamingTO = 0;
  54. #endif
  55. };
  56. argusKernel::~argusKernel(){
  57. #ifdef DEBUG
  58. LOG("Destructor");
  59. #endif
  60. WaitFinish(true);
  61. if( m_pDBC != NULL ) m_pDBC->unregisterServer( m_nSiteID, m_nServerNodeID );
  62. #ifdef DEBUG
  63. LOG("Deleting Components");
  64. #endif
  65. if( m_pStreamManager != NULL ) delete( m_pStreamManager );
  66. //Last DBC
  67. if( m_pDBC != NULL ) delete( m_pDBC );
  68. #ifdef DEBUG
  69. LOG("Destructor Finished");
  70. #endif
  71. };
  72. bool argusKernel::create( void ){
  73. char tBuffer[256];
  74. if( m_pSettings != NULL ) {
  75. config_setting_t * pSetting;
  76. int tVal;
  77. const char * tBuf;
  78. //Connect( CSTR DBName, CSTR DBHost, CSTR DBUser, CSTR DBPassword, uint16_t Port = 3300 );
  79. LOG("Getting Settings ...");
  80. if( !config_setting_lookup_string( m_pSettings, ARGUS_KERNEL_TAG_SERVER_IDENTITY, &tBuf ) ){
  81. char * tVar;
  82. char * tTS;
  83. tTS = getTStr(NULL);
  84. tVar = MD5String(tTS);
  85. free(tTS);
  86. sprintf( m_sIdentity, tVar );
  87. pSetting = config_setting_add( m_pSettings, ARGUS_KERNEL_TAG_SERVER_IDENTITY, CONFIG_TYPE_STRING );
  88. config_setting_set_string( pSetting, tVar );
  89. free( tVar );
  90. basicSettingsProvider::getInstance()->compromise();
  91. LOG("Server Identity not defined - generating new!");
  92. } else {
  93. sprintf( m_sIdentity, tBuf );
  94. sprintf( tBuffer, "Server Identity Read From Settings: %s", tBuf );
  95. LOG( tBuffer );
  96. };
  97. if( !config_setting_lookup_int( m_pSettings, ARGUS_KERNEL_TAG_SITE_ID, &tVal ) ){
  98. tVal = m_nSiteID = 1;
  99. pSetting = config_setting_add( m_pSettings, ARGUS_KERNEL_TAG_SITE_ID, CONFIG_TYPE_INT );
  100. config_setting_set_int( pSetting, tVal );
  101. basicSettingsProvider::getInstance()->compromise();
  102. LOG("Site ID not defined - using [1] as number!");
  103. } else {
  104. m_nSiteID = tVal;
  105. sprintf( tBuffer, "Site ID Read From Settings: %d", m_nSiteID );
  106. LOG( tBuffer );
  107. };
  108. } else {
  109. LOG_ERROR("Failed Read Config Settings!");
  110. return false;
  111. };
  112. if( m_pDBC == NULL ) {
  113. LOG("Explicitly Create DBC Object");
  114. m_pDBC = argusDBC::getInstance( m_pSettings );
  115. };
  116. if( m_pDBC == NULL ){
  117. LOG_ERROR("DBC Object Creation Failure!");
  118. return false;
  119. };
  120. if(!m_pDBC->connect()){
  121. LOG_ERROR("DBC Connection Failure!");
  122. SLEEP(5000);
  123. //ToDO: Set Restart Kernel!
  124. return false;
  125. };
  126. #ifdef DEBUG
  127. LOG( "Settings Read Done" );
  128. #endif
  129. m_pDBC->registerServer( m_nSiteID, m_sIdentity );
  130. m_nServerID = m_pDBC->getServerID( m_sIdentity );
  131. m_nServerNodeID = m_pDBC->getServerNode( m_nServerID );
  132. DBC_SITE_DATA *tSiteData = m_pDBC->getSiteData( m_nSiteID );
  133. if( tSiteData ) {
  134. C3D_WGS84_LOC t;
  135. t.lat = tSiteData->lat;
  136. t.lon = tSiteData->lon;
  137. t.alt = tSiteData->alt;
  138. m_pSystemAnchor = systemAnchor::getInstance( tSiteData->SH, &t );
  139. free( tSiteData );
  140. } else {
  141. LOG_ERROR("Error Loading Site DATA!");
  142. };
  143. //Init Subcomponents
  144. m_pHardwareManager = argusHardwareManager::getInstance();
  145. if( m_pHardwareManager!= NULL ) {
  146. m_pHardwareManager->validate();
  147. } else {
  148. LOG_ERROR("Failure to get HardwareManager Instance!");
  149. return false;
  150. };
  151. m_pServiceAnnouncer = new ssdpAnnouncer( m_pSettings );
  152. if( basicSettingsProvider::getInstance()->isCompromised() ) {
  153. basicSettingsProvider::getInstance()->validate();
  154. };
  155. m_pEventHeap = basicEventHeap::getInstance();
  156. m_pOnvifMediaObserver = onvifMediaObserver::getInstance();
  157. m_pNodeFactory = argusNodeFactory::getInstance();
  158. m_pModuleFactory = argusModuleFactory::getInstance();
  159. //enumerateHardware();
  160. //m_pNodeFactory->setDBC( m_pDBC );
  161. m_pNodeFactory->loadNodes( m_nSiteID );
  162. //m_pModuleFactory->setDBC( m_pDBC ); //m_pDBC->getIPCamRecords( m_vCamRecords );
  163. m_pModuleFactory->loadModules( m_nSiteID );
  164. #ifdef DEBUG
  165. LOG( "Start SSDP Beacon" );
  166. #endif
  167. if( m_pServiceAnnouncer != NULL ) {
  168. if( !m_pServiceAnnouncer->init() ){
  169. delete(m_pServiceAnnouncer);
  170. m_pServiceAnnouncer = NULL;
  171. };
  172. };
  173. m_pStreamManager = NULL;//mediaNginxManager::getInstance();
  174. //if( m_pStreamManager != NULL ) {
  175. // m_pStreamManager->attachStream("rtsp://gagua:4GetMyID@192.168.0.104:554/Streaming/Channels/101?transportmode=unicast&profile=Profile_1", true, 12, "12918" );
  176. //};
  177. /*
  178. #ifdef DEBUG
  179. LOG("Init IP Cameras");
  180. #endif
  181. if( m_vCamRecords.size() ) {
  182. ARGUS_Camera *tPtr = NULL;
  183. for( int i=0; i < m_vCamRecords.size(); i++ ) {
  184. tPtr = new ARGUS_Camera();
  185. if( tPtr != NULL ) {
  186. if( tPtr->create( m_vCamRecords.at(i)->ip, m_vCamRecords.at(i)->username, m_vCamRecords.at(i)->password ) ){
  187. #ifdef DEBUG
  188. LOG("Camera Created!");
  189. #endif
  190. m_vCameras.push_back( tPtr );
  191. tPtr = NULL;
  192. } else {
  193. LOG_ERROR("Camera Creation Failure!");
  194. delete( tPtr );
  195. tPtr = NULL;
  196. };
  197. };
  198. };
  199. };
  200. */
  201. #ifdef DEBUG
  202. LOG("Start OnVIF Discovery");
  203. #endif
  204. if( m_pOnvifMediaObserver!= NULL ) {
  205. m_pOnvifMediaObserver->startDiscovery();
  206. m_bDiscoveryStarted = true;
  207. };
  208. #ifdef DEBUG
  209. LOG( "Kernel Trhead is about to be Created" );
  210. #endif
  211. if( init() == false ){
  212. LOG_ERROR("Error in starting Kernel Thread!");
  213. return false;
  214. };
  215. #ifdef DEBUG
  216. LOG( "Kernel Thread Created" );
  217. #endif
  218. /*
  219. m_pServletWS = new servletWS();
  220. if( m_pServletWS != NULL ) {
  221. LOG("ServletWS Created");
  222. if(m_pServletWS->create(8080)){
  223. LOG("ServletWS Started");
  224. //if( ! m_pServletWS->attachChannel("rtsp://gagua:4GetMyID@192.168.0.109:554/Streaming/Channels/101?transportmode=unicast&profile=Profile_1", false ) ){
  225. // LOG("Error Adding Channel!");
  226. //} else {
  227. // LOG("Channel Attached");
  228. //};
  229. };
  230. };
  231. */
  232. #ifdef DEBUG
  233. sprintf( tBuffer, "Server is registered as id[%d]", m_nServerID );
  234. LOG( tBuffer );
  235. #endif
  236. return true;
  237. };
  238. void argusKernel::WaitFinish( bool Force ){
  239. if( Force ){
  240. #ifdef DEBUG
  241. LOG( "Thread End Forced" );
  242. #endif
  243. } else {
  244. // 3 seconds sleep to settle down processes
  245. SLEEP(3000);
  246. };
  247. waitThreadEnd( Force );
  248. #ifdef DEBUG
  249. LOG( "Thread is Detached" );
  250. #endif
  251. };
  252. /* Main Kernel Thread Procedure */
  253. void argusKernel::m_fThreadProc( void ){
  254. char Buffer[CTEXT];
  255. time_t tTimeTSeconds;
  256. int lastTSS = 0;
  257. int lastTMS = 0;
  258. DBC_EVT_DATA * tEvtPtr;
  259. pid_t pid = gettid();
  260. char pidBuf[16];
  261. sprintf(pidBuf,"KERNEL pid:%d", pid);
  262. LOG( pidBuf );
  263. #ifdef SIMULATE_KERNEL_TARGETS
  264. LOG("SIMULATION ENABLED");
  265. #endif
  266. m_bThreadStatus = TH_WORKING;
  267. while( m_bThreadStatus < TH_ENDED ){
  268. m_tTimeTSeconds = time( NULL );
  269. // Network IP OnVif Discovery
  270. //*
  271. if( m_pOnvifMediaObserver!= NULL ){
  272. if( !m_bDiscoveryStarted ) {
  273. if((m_tTimeTSeconds%ONVIF_DISCOVERY_INTERVAL)==0){
  274. #ifdef DEBUG
  275. LOG("Start OnVIF Discovery");
  276. #endif
  277. m_pOnvifMediaObserver->startDiscovery();
  278. m_bDiscoveryStarted = true;
  279. };
  280. } else {
  281. //*
  282. if((m_tTimeTSeconds%ONVIF_DISCOVERY_INTERVAL)==ONVIF_DISCOVERY_RESULT_TIME){
  283. #ifdef DEBUG
  284. LOG("Validate IP Cameras");
  285. #endif
  286. validateCameras();
  287. m_bDiscoveryStarted = false;
  288. };
  289. //*/
  290. };
  291. };
  292. //*/
  293. //*
  294. // Web CTRL Event Processing Loop
  295. if( !m_pDBC->getLastEvents( m_vEvtRecords, lastTSS, lastTMS ) ){
  296. // Error In DB Access
  297. m_bThreadStatus = TH_ENDED;
  298. m_bExitCause = 1;
  299. continue;
  300. };
  301. //*/
  302. if( m_tTimeTSeconds != tTimeTSeconds ){ // Each Second Process
  303. tTimeTSeconds = m_tTimeTSeconds;
  304. if( m_pModuleFactory != NULL ) {
  305. m_pModuleFactory->validate();
  306. };
  307. if( m_pNodeFactory != NULL ) {
  308. m_pNodeFactory->validate();
  309. };
  310. };
  311. if( m_vEvtRecords.size() > 0 ){
  312. validateEvents( lastTSS, lastTMS );
  313. // SLEEP( 2 ); // short loop if had an events
  314. } else SLEEP( SLEEP_KERNEL_INTERVAL );
  315. #ifdef SIMULATE_KERNEL_TARGETS
  316. /*
  317. // Simulate FlyHunter
  318. if( m_tTimeTSeconds!= m_nEachSec ) {
  319. m_nEachSec = m_tTimeTSeconds;
  320. if( m_bLandingTO ) {
  321. m_bLandingTO--;
  322. if( m_bLandingTO == 1 ) {
  323. //Landing
  324. LOG("Simulate Landing");
  325. LOG( m_cCurrentMission );
  326. //Simulate FH Module Event;
  327. EVENT_CONTAINER *ttt;
  328. FH_MISSION_DATA * nnn = (FH_MISSION_DATA *) malloc( sizeof(FH_MISSION_DATA));
  329. if( nnn ){
  330. nnn->location.lat = 0;
  331. nnn->location.lon = 0;
  332. nnn->location.alt = 0;
  333. sprintf( nnn->missionID, m_cCurrentMission );
  334. ttt = createBasicEvent( 0, EVT_CLASS_FLY_HUNTER, EVT_FH_LANDED, NULL, nnn );
  335. if( ttt ) {
  336. m_pEventHeap->broadcast( ttt );
  337. } else {
  338. free( nnn );
  339. };
  340. };
  341. };
  342. };
  343. if( m_bJamingTO ) {
  344. m_bJamingTO--;
  345. if( m_bJamingTO == 1 ) {
  346. //Jaming Off
  347. //Simulate FH Module Event;
  348. EVENT_CONTAINER *ttt;
  349. FH_MISSION_DATA * nnn = (FH_MISSION_DATA *) malloc( sizeof(FH_MISSION_DATA));
  350. if( nnn ){
  351. nnn->location.lat = 0;
  352. nnn->location.lon = 0;
  353. nnn->location.alt = 0;
  354. sprintf( nnn->missionID, m_cCurrentMission );
  355. ttt = createBasicEvent( 0, EVT_CLASS_FLY_HUNTER, EVT_FH_JAMER_OFF, NULL, nnn );
  356. if( ttt ) {
  357. m_pEventHeap->broadcast( ttt );
  358. } else {
  359. free( nnn );
  360. };
  361. };
  362. };
  363. };
  364. };
  365. */
  366. //Target Simulation To Test Events - Database
  367. if(( m_tTimeTSeconds%SIMULATE_KERNEL_INTERVAL)==(SIMULATE_KERNEL_INTERVAL>>1)){
  368. if( m_tTimeTSeconds!= m_nLastSimRun ){
  369. m_nLastSimRun = m_tTimeTSeconds;
  370. if( m_pNodeFactory != NULL ) {
  371. argusNetNode *tNode = m_pNodeFactory->getNode( SIMULATE_KERNEL_NODE_ID );
  372. if( tNode!= NULL ) {
  373. tNode->simulateTarget();
  374. };
  375. };
  376. };
  377. };
  378. #endif
  379. };
  380. };
  381. int argusKernel::isCameraListed( CSTR uid ){
  382. if( m_vCamRecords.size() ){
  383. for( int index = 0; index < m_vCamRecords.size(); index++ ){
  384. if(strstr(m_vCamRecords.at(index)->uuid,uid)!=NULL){
  385. m_vCamRecords.at(index)->online = true;
  386. return index;
  387. };
  388. };
  389. } else {
  390. LOG("No Registered Cameras!");
  391. };
  392. return -1;
  393. };
  394. void argusKernel::validateCameras( void ){
  395. vectorWoWoResults *DiscoverResults = m_pOnvifMediaObserver->getResults();
  396. if( DiscoverResults->size() > 0 ) {
  397. for (int index = 0; index < DiscoverResults->size(); index++) {
  398. char tBuffer[256];
  399. sprintf( tBuffer,"Found Camwera [%s] %s", DiscoverResults->at(index)->XAddrs, DiscoverResults->at(index)->RefID );
  400. LOG( tBuffer );
  401. uint32_t cid = m_pDBC->getCamId( DiscoverResults->at(index)->RefID ); //isCameraListed( DiscoverResults->at(index)->RefID );
  402. if( cid ) {
  403. sprintf( tBuffer, "Camera is Listed as %d", cid );
  404. LOG( tBuffer );
  405. //if( strstr(DiscoverResults->at(index)->XAddrs,m_vCamRecords.at(cid)->ip)==NULL ) {
  406. // LOG( DiscoverResults->at(index)->XAddrs );
  407. m_pDBC->updateIPCam( m_nSiteID, cid, DiscoverResults->at(index)->XAddrs );// DiscoverResults->at(index));
  408. //};
  409. } else {
  410. // Uncknown camera - no checking
  411. LOG("Camera is Not Listed");
  412. m_pDBC->addIPCam( m_nSiteID, DiscoverResults->at(index) );
  413. };
  414. };
  415. } else {
  416. LOG("No Online IP Cameras in Network");
  417. };
  418. };
  419. void argusKernel::validateEvents( int &lastTSS, int &lastTMS ){
  420. DBC_EVT_DATA *tPtr = NULL;
  421. EVENT_CONTAINER *tEvt = NULL;
  422. if(m_vEvtRecords.size()) {
  423. lastTSS = m_vEvtRecords.at(m_vEvtRecords.size()-1)->ts_s;
  424. lastTMS = m_vEvtRecords.at(m_vEvtRecords.size()-1)->ts_ms;
  425. #ifndef ONE_EVENT_PER_LOOP
  426. while( m_vEvtRecords.size() ){
  427. #endif
  428. tPtr = *m_vEvtRecords.begin();
  429. if( tPtr != NULL ) {
  430. if( tEvt != NULL ) {
  431. m_pEventHeap->broadcast( tEvt );
  432. };
  433. free( tPtr );
  434. };
  435. m_vEvtRecords.erase( m_vEvtRecords.begin() );
  436. #ifndef ONE_EVENT_PER_LOOP
  437. };
  438. #endif
  439. };
  440. };
  441. bool argusKernel::signalEvent( void ){
  442. if( m_pDBC->getLastEvents( m_vEvtRecords, 0,0 ) ){
  443. };
  444. return true;
  445. };
  446. int argusKernel::getNetNodes( ARGUS_NODE_TYPE type, argusNetNode **&RA ){
  447. RA = NULL;
  448. int cnt = 0;
  449. if( m_pNodeFactory != NULL ){
  450. cnt = m_pNodeFactory->getNodesCount( type );
  451. if( cnt ) {
  452. RA = (argusNetNode **) calloc( cnt, sizeof( argusNetNode * ) );
  453. m_pNodeFactory->fetchNodes(type, RA );
  454. };
  455. };
  456. return cnt;
  457. };
  458. argusNetNode *argusKernel::getNetNode( int id ){
  459. if( m_pNodeFactory != NULL ){
  460. return m_pNodeFactory->getNode( id );
  461. };
  462. return NULL;
  463. };
  464. int argusKernel::getModules( ARGUS_MODULE_TYPE type, argusKernelModule **&RA ){
  465. RA = NULL;
  466. int cnt = 0;
  467. if( m_pModuleFactory != NULL ){
  468. cnt = m_pModuleFactory->getModulesCount( type );
  469. if( cnt ) {
  470. RA = (argusKernelModule **) calloc( cnt, sizeof( argusKernelModule * ) );
  471. m_pModuleFactory->fetchModules( type, RA );
  472. };
  473. };
  474. return cnt;
  475. };
  476. argusKernelModule *argusKernel::getModule( int id ){
  477. if( m_pModuleFactory != NULL ){
  478. return m_pModuleFactory->getModule( id );
  479. };
  480. return NULL;
  481. };
  482. void argusKernel::dispatchEvent( EVENT_CONTAINER *Evt ){
  483. // Register all events in Database;
  484. LOG( "New EVENT!!" );
  485. if( m_pDBC == NULL ) return;
  486. if( Evt == NULL ) return;
  487. switch( Evt->m_eClass ) {
  488. case EVT_CLASS_EXTERNAL_CMD:
  489. switch( Evt->m_eType ){
  490. case EVT_FH_JAMER_ON:{
  491. uint32_t TS_A, TS_B;
  492. TS_A = Evt->m_UMSTS / 1000;
  493. TS_B = Evt->m_UMSTS % 1000;
  494. #ifdef SIMULATE_KERNEL_TARGETS
  495. m_bJamingTO = SIMULATE_JAMER_TO;
  496. #endif
  497. FH_CTRL_DATA * tData = (FH_CTRL_DATA *) Evt->m_pEvtData;
  498. if( tData ) {
  499. if( m_pDBC->addEvent(
  500. 0,
  501. Evt->m_UUID,
  502. TS_A,
  503. TS_B,
  504. EVT_FH_JAMER_ON,
  505. 0,
  506. 0,
  507. 0,
  508. 0,
  509. 0,
  510. 0,
  511. 0,
  512. 0,
  513. tData->evtUUID
  514. ) ){
  515. //Simulate FH Module Event;
  516. EVENT_CONTAINER *ttt;
  517. FH_MISSION_DATA * nnn = (FH_MISSION_DATA *) malloc( sizeof(FH_MISSION_DATA));
  518. if( nnn ){
  519. nnn->location.lat = 0;
  520. nnn->location.lon = 0;
  521. nnn->location.alt = 0;
  522. sprintf( nnn->missionID, tData->evtUUID );
  523. ttt = createBasicEvent( 0, EVT_CLASS_FLY_HUNTER, EVT_FH_JAMER_ON, NULL, nnn );
  524. if( ttt ) {
  525. m_pEventHeap->broadcast( ttt );
  526. } else {
  527. free( nnn );
  528. };
  529. };
  530. };
  531. free(tData);
  532. };
  533. break;
  534. };
  535. case EVT_FH_MISSION_END:{
  536. FH_CTRL_DATA * tData = (FH_CTRL_DATA *) Evt->m_pEvtData;
  537. if( tData ) {
  538. //DBC_EVT_DATA * tEVT = m_pDBC->getEventByUUID( tData->targetUUID );
  539. if( 1 /*tEVT*/ ) {
  540. uint32_t TS_A, TS_B;
  541. TS_A = Evt->m_UMSTS / 1000;
  542. TS_B = Evt->m_UMSTS % 1000;
  543. if( m_pDBC->addEvent(
  544. 0,
  545. Evt->m_UUID,
  546. TS_A,
  547. TS_B,
  548. EVT_FH_LANDED,
  549. 0,
  550. 0,
  551. 0,
  552. 0,
  553. 0,
  554. 0,//tEVT->lat,
  555. 0,//tEVT->lon,
  556. 0,//tEVT->alt,
  557. 0//tEVT->uuid
  558. ) ){
  559. //Simulate FH Module Event;
  560. EVENT_CONTAINER *ttt;
  561. FH_MISSION_DATA * nnn = (FH_MISSION_DATA *) malloc( sizeof(FH_MISSION_DATA));
  562. if( nnn ){
  563. nnn->location.lat = 0;//tEVT->lat;
  564. nnn->location.lon = 0;//tEVT->lon;
  565. nnn->location.alt = 0;//tEVT->alt;
  566. sprintf( nnn->missionID, tData->evtUUID );
  567. ttt = createBasicEvent( 0, EVT_CLASS_FLY_HUNTER, EVT_FH_LANDED, NULL, nnn );
  568. if( ttt ) {
  569. m_pEventHeap->broadcast( ttt );
  570. } else {
  571. free( nnn );
  572. };
  573. };
  574. };
  575. //free( tEVT );
  576. } else {
  577. LOG_ERROR("Linked Event Was Not Found!");
  578. };
  579. };
  580. break;
  581. }
  582. case EVT_FH_MISSION_BEGIN:{
  583. FH_CTRL_DATA * tData = (FH_CTRL_DATA *) Evt->m_pEvtData;
  584. #ifdef SIMULATE_KERNEL_TARGETS
  585. m_bLandingTO = SIMULATE_LANDING_TO;
  586. #endif
  587. if( tData ) {
  588. #ifdef SIMULATE_KERNEL_TARGETS
  589. sprintf( m_cCurrentMission, tData->evtUUID );
  590. #endif
  591. DBC_EVT_DATA * tEVT = m_pDBC->getEventByUUID( tData->targetUUID );
  592. if( tEVT ) {
  593. uint32_t TS_A, TS_B;
  594. TS_A = Evt->m_UMSTS / 1000;
  595. TS_B = Evt->m_UMSTS % 1000;
  596. if( m_pDBC->addEvent(
  597. 0,
  598. Evt->m_UUID,
  599. TS_A,
  600. TS_B,
  601. EVT_FH_FLY_TO,
  602. 0,
  603. 0,
  604. 0,
  605. 0,
  606. 0,
  607. tEVT->lat,
  608. tEVT->lon,
  609. tEVT->alt,
  610. tEVT->uuid
  611. ) ){
  612. //Simulate FH Module Event;
  613. EVENT_CONTAINER *ttt;
  614. FH_MISSION_DATA * nnn = (FH_MISSION_DATA *) malloc( sizeof(FH_MISSION_DATA));
  615. if( nnn ){
  616. nnn->location.lat = tEVT->lat;
  617. nnn->location.lon = tEVT->lon;
  618. nnn->location.alt = tEVT->alt;
  619. sprintf( nnn->missionID, tData->evtUUID );
  620. ttt = createBasicEvent( 0, EVT_CLASS_FLY_HUNTER, EVT_FH_MISSION_BEGIN, NULL, nnn );
  621. if( ttt ) {
  622. m_pEventHeap->broadcast( ttt );
  623. } else {
  624. free( nnn );
  625. };
  626. };
  627. };
  628. free( tEVT );
  629. } else {
  630. LOG_ERROR("Linked Event Was Not Found!");
  631. };
  632. };
  633. break;
  634. };
  635. };
  636. break;
  637. case EVT_CLASS_SENSOR_CLD:
  638. case EVT_CLASS_SENSOR_LGS:
  639. case EVT_CLASS_SENSOR_LFS:
  640. case EVT_CLASS_SENSOR_MND:
  641. case EVT_CLASS_SENSOR_PLS_210:
  642. case EVT_CLASS_SENSOR_PLS_360:
  643. case EVT_CLASS_SENSOR_ALS:
  644. case EVT_CLASS_SENSOR_3D:
  645. case EVT_CLASS_SENSOR_ACC:
  646. switch( Evt->m_eType ) {
  647. case EVT_TARGET_1D:{
  648. TARGET_DATA *tDATA =(TARGET_DATA *) Evt->m_pEvtData;
  649. if( tDATA != NULL ) {
  650. uint32_t TS_A, TS_B;
  651. TS_A = Evt->m_UMSTS / 1000;
  652. TS_B = Evt->m_UMSTS % 1000;
  653. m_pDBC->addEvent(
  654. Evt->m_nSourceUID,
  655. Evt->m_UUID,
  656. TS_A,
  657. TS_B,
  658. Evt->m_eType,
  659. 0,
  660. 0,
  661. 0,
  662. tDATA->local_target.r,
  663. tDATA->area,
  664. tDATA->global_target.lat,
  665. tDATA->global_target.lon,
  666. tDATA->global_target.alt
  667. );
  668. };
  669. break;
  670. };
  671. case EVT_TARGET_2D_BLACK:
  672. case EVT_TARGET_2D_WHITE:{
  673. TARGET_DATA *tDATA = (TARGET_DATA *)Evt->m_pEvtData;
  674. if( tDATA != NULL ) {
  675. uint32_t TS_A, TS_B;
  676. TS_A = Evt->m_UMSTS / 1000;
  677. TS_B = Evt->m_UMSTS % 1000;
  678. m_pDBC->addEvent(
  679. Evt->m_nSourceUID,
  680. Evt->m_UUID,
  681. TS_A,
  682. TS_B,
  683. Evt->m_eType,
  684. 0,
  685. tDATA->local_target.fi,
  686. 0,
  687. tDATA->local_target.r,
  688. tDATA->area,
  689. tDATA->global_target.lat,
  690. tDATA->global_target.lon,
  691. tDATA->global_target.alt
  692. );
  693. };
  694. break;
  695. };
  696. case EVT_TARGET_3D_BLACK:
  697. case EVT_TARGET_3D_WHITE:{
  698. TARGET_DATA *tDATA = (TARGET_DATA *) Evt->m_pEvtData;
  699. if( tDATA != NULL ) {
  700. uint32_t TS_A, TS_B;
  701. TS_A = Evt->m_UMSTS / 1000;
  702. TS_B = Evt->m_UMSTS % 1000;
  703. m_pDBC->addEvent(
  704. Evt->m_nSourceUID,
  705. Evt->m_UUID,
  706. TS_A,
  707. TS_B,
  708. Evt->m_eType,
  709. 0,
  710. tDATA->local_target.fi,
  711. tDATA->local_target.tetta,
  712. tDATA->local_target.r,
  713. tDATA->area,
  714. tDATA->global_target.lat,
  715. tDATA->global_target.lon,
  716. tDATA->global_target.alt
  717. );
  718. };
  719. break;
  720. };
  721. };
  722. break;
  723. };
  724. };
  725. #undef LOG
  726. #undef LOG_ERROR