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.

847 lines
20 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "kernelModuleKafka.h"
  2. // #include "mojoKernel.h"
  3. #include "../data/json/json_tool.h"
  4. #include "../hardware/soc/general/3DLRF.h"
  5. #include <json/reader.h>
  6. #include <json/value.h>
  7. #include <json/writer.h>
  8. #include <strings.h>
  9. #define LOG(X) kernelModule::m_pLog->Log("MOD_KAFKA", this, X)
  10. #ifdef DEBUG
  11. #define LOG_ERROR(X) \
  12. { \
  13. char _tBfrErrMSG2w34[256]; \
  14. sprintf(_tBfrErrMSG2w34, "In file %s[%d] in func:%s %s", __FILE__, __LINE__, __func__, X); \
  15. kernelModule::m_pLog->Log("MOD_KAFKA", this, _LOG_ERROR, _tBfrErrMSG2w34); \
  16. }
  17. #else
  18. #define LOG_ERROR(X) kernelModule::m_pLog->Log("MOD_KAFKA", this, _LOG_ERROR, X);
  19. #endif
  20. kernelModuleKafka::kernelModuleKafka(uint32_t ModuleID) :
  21. kernelModule(ModuleID, KERNEL_MODULE_KAFKA)
  22. {
  23. m_pProtocol = NULL;
  24. m_bConsumerEnabled = false;
  25. m_pEventHeap = basicEventHeap::getInstance();
  26. partition = 0; // RdKafka::Topic::PARTITION_UA;
  27. // start_offset = RdKafka::Topic::OFFSET_END;// OFFSET_BEGINNING;
  28. start_offset = 0; // RdKafka::Topic::OFFSET_BEGINNING;
  29. // start_offset = RdKafka::Topic::OFFSET_STORED;
  30. memset(m_sServerIP, 0, 48);
  31. CSTR TVAL = NULL; // m_pKernel->getServerIp();
  32. if (TVAL)
  33. {
  34. strncpy(m_sServerIP, TVAL, 48);
  35. free(TVAL);
  36. }
  37. else
  38. {
  39. LOG_ERROR("Error Get Argus Server IP!");
  40. strncpy(m_sServerIP, "192.168.0.127", 48);
  41. };
  42. memset(m_sServerName, 0, 48);
  43. TVAL = NULL; // m_pKernel->getServerName();
  44. if (TVAL)
  45. {
  46. strncpy(m_sServerName, TVAL, 48);
  47. free(TVAL);
  48. }
  49. else
  50. {
  51. LOG_ERROR("Error Get Argus Server Name!");
  52. strncpy(m_sServerName, "Argus Server", 48);
  53. };
  54. m_pEvtTemplates = (KAFKA_TEMPLATE ***) calloc(EVT_CLASS_COUNT, sizeof(KAFKA_TEMPLATE **));
  55. if (m_pEvtTemplates != NULL)
  56. {
  57. memset(m_pEvtTemplates, 0, EVT_CLASS_COUNT * sizeof(KAFKA_TEMPLATE **));
  58. }
  59. else
  60. {
  61. LOG_ERROR("EVT Templates Memory Allocation Error!");
  62. }
  63. /*
  64. Do it in Kernel!!
  65. if ( m_pKernel!= NULL ) {
  66. argusHardwareManager *tHWM = m_pKernel->getHardwareManager();
  67. if( tHWM != NULL ) {
  68. DBC_INT_LIST *rIDS = tHWM->requestResourcesByType( ARGUS_HARDWARE_PROVIDER_NETWORK );
  69. if( rIDS != NULL ) {
  70. for( DBC_INT_LIST::iterator idx = rIDS->begin(); idx < rIDS->end(); idx++ ){
  71. argusHardwareResourceNetwork *tRES = (argusHardwareResourceNetwork *) tHWM->requestResource( ARGUS_HARDWARE_PROVIDER_NETWORK, *idx );
  72. if( tRES != NULL ) {
  73. m_pServerIP = tRES->getAddress();
  74. break;
  75. } else {
  76. LOG_ERROR("Cannot Get Resource!");
  77. };
  78. };
  79. delete( rIDS );
  80. } else {
  81. LOG("No Networks Detected!");
  82. m_bEnabled = false;
  83. };
  84. } else {
  85. LOG_ERROR("No HW Manager");
  86. };
  87. } else {
  88. LOG_ERROR("No Kernel");
  89. };
  90. */
  91. }
  92. kernelModuleKafka::~kernelModuleKafka()
  93. {
  94. detachEvents(); // stop event delivery before the members are destroyed (see basicEventHandler.h)
  95. m_bEnabled = false;
  96. waitThreadEnd(true);
  97. if (m_pProtocol != NULL)
  98. {
  99. delete(m_pProtocol);
  100. };
  101. if (m_pEvtTemplates != NULL)
  102. {
  103. for (int i = 0; i < EVT_CLASS_COUNT; i++)
  104. {
  105. if (m_pEvtTemplates[i] != NULL)
  106. {
  107. for (int j = 0; j < EVT_COUNT; j++)
  108. {
  109. if (m_pEvtTemplates[i][j] != NULL)
  110. {
  111. if (m_pEvtTemplates[i][j]->tpl)
  112. {
  113. free(m_pEvtTemplates[i][j]->tpl);
  114. }
  115. free(m_pEvtTemplates[i][j]);
  116. };
  117. };
  118. free(m_pEvtTemplates[i]);
  119. };
  120. };
  121. free(m_pEvtTemplates);
  122. };
  123. }
  124. /* Periodical Job Handler */
  125. void kernelModuleKafka::m_fThreadProc(void)
  126. {
  127. #ifdef SIMULATOR
  128. float sim_Az = 0.f;
  129. float sim_El = 20.f;
  130. float sim_Ran = 80.35f;
  131. float tr_Az_step = 0.3f;
  132. uint32_t src = 128;
  133. #endif
  134. #ifdef DEBUG
  135. LOG("Pereodical Jobs Started");
  136. #endif
  137. m_bThreadStatus = TH_WORKING;
  138. pthread_setname_np(pthread_self(), "moduleKafka");
  139. if (! m_bEnabled)
  140. {
  141. m_bThreadStatus = TH_ENDED;
  142. #ifdef DEBUG
  143. LOG("Module is Disabled!");
  144. #endif
  145. };
  146. while (m_bThreadStatus < TH_ENDED)
  147. {
  148. m_llTicks++; //= getMilliseconds();
  149. if (m_llTicks % 20 == 0)
  150. { // each 2 seconds
  151. #ifdef SIMULATOR
  152. sim_Az += tr_Az_step;
  153. for (int i = 0; i < EVT_CLASS_COUNT; i++)
  154. {
  155. if (m_pEvtTemplates[i] != NULL)
  156. {
  157. for (int j = 0; j < EVT_COUNT; j++)
  158. {
  159. if (m_pEvtTemplates[i][j] != NULL)
  160. {
  161. CSTR tpl;
  162. CSTR ts;
  163. CSTR uuid;
  164. char LON[10];
  165. char LAT[10];
  166. char AZ[10];
  167. char EL[10];
  168. char RN[10];
  169. float lat = 32.906153575029926;
  170. float lon = 35.09629379621815;
  171. sprintf(AZ, "%.3f", sim_Az + (0.6 / RAND_MAX) * rand());
  172. sprintf(EL, "%.3f", sim_El + (0.6 / RAND_MAX) * rand());
  173. sprintf(RN, "%.3f", sim_Ran + (0.6 / RAND_MAX) * rand());
  174. sprintf(LAT, "%.10f", lat + (0.00006 / RAND_MAX) * rand());
  175. sprintf(LON, "%.10f", lon + (0.00006 / RAND_MAX) * rand());
  176. uuid = getUniqID_UUID();
  177. ts = getTimeStamp();
  178. src = i;
  179. tpl = buildTemplate(m_pEvtTemplates[i][j]->tpl, src, ts, uuid, AZ, RN, EL, LAT, LON);
  180. if (tpl)
  181. {
  182. m_pProtocol->issuePost(m_pEvtTemplates[i][j]->topic, tpl, strlen(tpl));
  183. free(tpl);
  184. };
  185. if (uuid)
  186. {
  187. free(uuid);
  188. }
  189. if (ts)
  190. {
  191. free(ts);
  192. }
  193. };
  194. };
  195. };
  196. };
  197. #endif
  198. };
  199. if (m_bConsumerEnabled)
  200. {
  201. for (uint8_t idx = 0; idx < EVT_COUNT; idx++)
  202. {
  203. if (m_pEvtTemplates[EVT_CLASS_EXTERNAL_CMD][idx] != NULL)
  204. {
  205. char BUF[1024];
  206. int len;
  207. if (m_pProtocol->receivePost(m_pEvtTemplates[EVT_CLASS_EXTERNAL_CMD][idx]->topic, partition, start_offset, BUF, len))
  208. {
  209. if (len > 0)
  210. {
  211. start_offset++;
  212. #ifdef DEBUG
  213. char ttt[64];
  214. LOG(" HAVE MESSAGE ");
  215. sprintf(ttt, " MSG Len: %d", len);
  216. LOG(ttt);
  217. #endif
  218. if (len > 0)
  219. {
  220. LOG(BUF);
  221. try
  222. {
  223. Json::Value root;
  224. #ifdef OLD_WAY_JSON
  225. Json::Reader reader;
  226. if (! reader.parse(BUF, root))
  227. {
  228. LOG_ERROR("Error parsing the string");
  229. }
  230. else
  231. {
  232. #else
  233. JSONCPP_STRING err;
  234. Json::CharReaderBuilder builder;
  235. const std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
  236. if (! reader->parse(BUF, BUF + len, &root, &err))
  237. {
  238. LOG_ERROR("Error parsing the string");
  239. LOG_ERROR(err.c_str());
  240. }
  241. else
  242. {
  243. #endif
  244. if (root.size())
  245. {
  246. FH_CTRL_DATA * tData;
  247. basicEventTypeID evtID = EVT_NOINIT;
  248. Json::Value tVal;
  249. tData = (FH_CTRL_DATA *) malloc(sizeof(FH_CTRL_DATA));
  250. if (tData)
  251. {
  252. memset(tData, 0, sizeof(FH_CTRL_DATA));
  253. tVal = root["id"];
  254. if (! tVal.isNull())
  255. {
  256. #ifdef DEBUG
  257. LOG(tVal.asString().c_str());
  258. #endif
  259. sprintf(tData->cmdUUID, "%s", tVal.asString().c_str());
  260. };
  261. tVal = root["action"];
  262. if (! tVal.isNull())
  263. {
  264. #ifdef DEBUG
  265. LOG(tVal.asString().c_str());
  266. #endif
  267. if (strcasecmp(tVal.asString().c_str(), "intercept_target") == 0)
  268. {
  269. evtID = EVT_FH_MISSION_BEGIN;
  270. };
  271. if (strcasecmp(tVal.asString().c_str(), "jam_target") == 0)
  272. {
  273. tData->param = atoi(tVal.asString().c_str() + 10);
  274. if (tData->param == 0)
  275. {
  276. tData->param = FH_DEFAULT_JAMING_TIME;
  277. };
  278. evtID = EVT_FH_JAMING_BEGIN;
  279. };
  280. if (strcasecmp(tVal.asString().c_str(), "cancel") == 0)
  281. {
  282. evtID = EVT_FH_CANCEL_ACTION;
  283. };
  284. };
  285. tVal = root["event_id"];
  286. if (! tVal.isNull())
  287. {
  288. #ifdef DEBUG
  289. LOG(tVal.asString().c_str());
  290. #endif
  291. sprintf(tData->evtUUID, "%s", tVal.asString().c_str());
  292. };
  293. tVal = root["target_id"];
  294. if (! tVal.isNull())
  295. {
  296. #ifdef DEBUG
  297. LOG(tVal.asString().c_str());
  298. #endif
  299. sprintf(tData->targetUUID, "%s", tVal.asString().c_str());
  300. };
  301. if (evtID)
  302. {
  303. EVENT_CONTAINER * tEVT;
  304. tEVT = createBasicEvent(0, EVT_CLASS_EXTERNAL_CMD, evtID, NULL, NULL, tData);
  305. if (tEVT)
  306. {
  307. m_pEventHeap->broadcast(tEVT);
  308. }
  309. else
  310. {
  311. free(tData);
  312. };
  313. }
  314. else
  315. {
  316. free(tData);
  317. };
  318. };
  319. };
  320. };
  321. }
  322. catch (const std::exception & e )
  323. {
  324. LOG_ERROR("EXCEPTION");
  325. };
  326. };
  327. };
  328. };
  329. };
  330. };
  331. };
  332. SLEEP(100);
  333. };
  334. }
  335. bool kernelModuleKafka::startService()
  336. {
  337. if (! m_bEnabled)
  338. {
  339. return false;
  340. }
  341. if (reloadSettings())
  342. {
  343. if (m_pSettings != NULL)
  344. {
  345. m_pProtocol = new protocolKAFKA(m_pSettings);
  346. if (m_pProtocol->init())
  347. {
  348. return init();
  349. };
  350. };
  351. };
  352. return false;
  353. }
  354. bool kernelModuleKafka::stopService(bool force)
  355. {
  356. if ( force ) {
  357. m_bEnabled = false;
  358. waitThreadEnd( force );
  359. } else {
  360. m_bEnabled = !uninit();
  361. };
  362. return true;
  363. }
  364. bool kernelModuleKafka::reloadSettings()
  365. {
  366. if (m_pDBC == NULL)
  367. {
  368. return false;
  369. }
  370. if (! m_bEnabled)
  371. {
  372. return false;
  373. }
  374. m_pSettings = m_pDBC->getSettingsKAFKA(m_nDBAUXID);
  375. if (m_pSettings != NULL)
  376. {
  377. if (m_pEvtTemplates != NULL)
  378. {
  379. // Clear Templates
  380. for (int i = 0; i < EVT_CLASS_COUNT; i++)
  381. {
  382. for (int j = 0; j < EVT_COUNT; j++)
  383. {
  384. if (m_pEvtTemplates[i] != NULL)
  385. {
  386. if (m_pEvtTemplates[i][j] != NULL)
  387. {
  388. if (m_pEvtTemplates[i][j]->tpl)
  389. {
  390. free(m_pEvtTemplates[i][j]->tpl);
  391. }
  392. free(m_pEvtTemplates[i][j]);
  393. m_pEvtTemplates[i][j] = NULL;
  394. };
  395. };
  396. };
  397. free(m_pEvtTemplates[i]);
  398. m_pEvtTemplates[i] = NULL;
  399. };
  400. for (int i = 0; i < EVT_CLASS_COUNT; i++)
  401. {
  402. for (int j = 0; j < EVT_COUNT; j++)
  403. {
  404. KAFKA_TEMPLATE * tT;
  405. tT = m_pDBC->getKafkaTemplateForEvent(m_nDBAUXID, i, j);
  406. if (tT != NULL)
  407. {
  408. if (m_pEvtTemplates[i] == NULL)
  409. {
  410. m_pEvtTemplates[i] = (KAFKA_TEMPLATE **) calloc(EVT_COUNT, sizeof(KAFKA_TEMPLATE *));
  411. memset(m_pEvtTemplates[i], 0, EVT_COUNT * sizeof(KAFKA_TEMPLATE *));
  412. if (i == EVT_CLASS_EXTERNAL_CMD)
  413. {
  414. m_bConsumerEnabled = true;
  415. };
  416. };
  417. m_pEvtTemplates[i][j] = tT;
  418. };
  419. };
  420. };
  421. };
  422. return true;
  423. };
  424. return false;
  425. }
  426. CSTR kernelModuleKafka::buildTemplate(CSTR tpl, uint32_t source_id, CSTR ts, CSTR uuid, CSTR az, CSTR range, CSTR width, CSTR el, CSTR lat, CSTR lon, CSTR alt, CSTR extID, CSTR src_Name, CSTR src_IP, CSTR src_lat, CSTR src_lon, CSTR src_alt,
  427. CSTR src_rot_x, CSTR src_rot_y, CSTR src_rot_z)
  428. {
  429. CSTR ct1, ct2;
  430. char sid[64];
  431. if (tpl)
  432. {
  433. sprintf(sid, "%d", source_id);
  434. ct1 = strReplace(tpl, KAFKA_TPL_SUBST_ID, sid);
  435. if (ct1)
  436. {
  437. ct2 = strReplace(ct1, KAFKA_TPL_SUBST_TS, ts);
  438. if (ct2)
  439. {
  440. free(ct1);
  441. ct1 = ct2;
  442. };
  443. if (uuid)
  444. {
  445. ct2 = strReplace(ct1, KAFKA_TPL_SUBST_UUID, uuid);
  446. if (ct2)
  447. {
  448. free(ct1);
  449. ct1 = ct2;
  450. };
  451. };
  452. if (az)
  453. {
  454. ct2 = strReplace(ct1, KAFKA_TPL_SUBST_AZ, az);
  455. if (ct2)
  456. {
  457. free(ct1);
  458. ct1 = ct2;
  459. };
  460. };
  461. if (range)
  462. {
  463. ct2 = strReplace(ct1, KAFKA_TPL_SUBST_RANGE, range);
  464. if (ct2)
  465. {
  466. free(ct1);
  467. ct1 = ct2;
  468. };
  469. };
  470. if (width)
  471. {
  472. ct2 = strReplace(ct1, KAFKA_TPL_SUBST_WIDTH, width);
  473. if (ct2)
  474. {
  475. free(ct1);
  476. ct1 = ct2;
  477. };
  478. };
  479. if (el)
  480. {
  481. ct2 = strReplace(ct1, KAFKA_TPL_SUBST_EL, el);
  482. if (ct2)
  483. {
  484. free(ct1);
  485. ct1 = ct2;
  486. };
  487. };
  488. if (lat)
  489. {
  490. ct2 = strReplace(ct1, KAFKA_TPL_SUBST_LAT, lat);
  491. if (ct2)
  492. {
  493. free(ct1);
  494. ct1 = ct2;
  495. };
  496. };
  497. if (lon)
  498. {
  499. ct2 = strReplace(ct1, KAFKA_TPL_SUBST_LON, lon);
  500. if (ct2)
  501. {
  502. free(ct1);
  503. ct1 = ct2;
  504. };
  505. };
  506. if (alt)
  507. {
  508. ct2 = strReplace(ct1, KAFKA_TPL_SUBST_ALT, alt);
  509. if (ct2)
  510. {
  511. free(ct1);
  512. ct1 = ct2;
  513. };
  514. };
  515. if (extID)
  516. {
  517. ct2 = strReplace(ct1, KAFKA_TPL_SUBST_EXEVTD, extID);
  518. if (ct2)
  519. {
  520. free(ct1);
  521. ct1 = ct2;
  522. };
  523. };
  524. if (src_Name)
  525. {
  526. ct2 = strReplace(ct1, KAFKA_TPL_SUBST_SRC_NAME, src_Name);
  527. if (ct2)
  528. {
  529. free(ct1);
  530. ct1 = ct2;
  531. };
  532. };
  533. if (src_IP)
  534. {
  535. ct2 = strReplace(ct1, KAFKA_TPL_SUBST_SRC_IP, src_IP);
  536. if (ct2)
  537. {
  538. free(ct1);
  539. ct1 = ct2;
  540. };
  541. };
  542. if (src_lat)
  543. {
  544. ct2 = strReplace(ct1, KAFKA_TPL_SUBST_SRC_LAT, src_lat);
  545. if (ct2)
  546. {
  547. free(ct1);
  548. ct1 = ct2;
  549. };
  550. };
  551. if (src_lon)
  552. {
  553. ct2 = strReplace(ct1, KAFKA_TPL_SUBST_SRC_LON, src_lon);
  554. if (ct2)
  555. {
  556. free(ct1);
  557. ct1 = ct2;
  558. };
  559. };
  560. if (src_alt)
  561. {
  562. ct2 = strReplace(ct1, KAFKA_TPL_SUBST_SRC_ALT, src_alt);
  563. if (ct2)
  564. {
  565. free(ct1);
  566. ct1 = ct2;
  567. };
  568. };
  569. if (src_rot_x)
  570. {
  571. ct2 = strReplace(ct1, KAFKA_TPL_SUBST_SRC_ROT_X, src_rot_x);
  572. if (ct2)
  573. {
  574. free(ct1);
  575. ct1 = ct2;
  576. };
  577. };
  578. if (src_rot_y)
  579. {
  580. ct2 = strReplace(ct1, KAFKA_TPL_SUBST_SRC_ROT_Y, src_rot_y);
  581. if (ct2)
  582. {
  583. free(ct1);
  584. ct1 = ct2;
  585. };
  586. };
  587. if (src_rot_z)
  588. {
  589. ct2 = strReplace(ct1, KAFKA_TPL_SUBST_SRC_ROT_Z, src_rot_z);
  590. if (ct2)
  591. {
  592. free(ct1);
  593. ct1 = ct2;
  594. };
  595. };
  596. // Finalaze Message by System Wide Data
  597. // UUID
  598. CSTR TVAL = getUniqID_UUID();
  599. if (TVAL != NULL)
  600. {
  601. ct2 = strReplace(ct1, KAFKA_TPL_SUBST_MSG_UUID, TVAL);
  602. if (ct2)
  603. {
  604. free(ct1);
  605. ct1 = ct2;
  606. };
  607. free(TVAL);
  608. }
  609. else
  610. {
  611. LOG_ERROR("Error Generate Message UUID!");
  612. };
  613. // Server IP
  614. ct2 = strReplace(ct1, KAFKA_TPL_SUBST_SRV_IP, m_sServerIP);
  615. if (ct2)
  616. {
  617. free(ct1);
  618. ct1 = ct2;
  619. };
  620. // Server Name
  621. ct2 = strReplace(ct1, KAFKA_TPL_SUBST_SRV_NAME, m_sServerName);
  622. if (ct2)
  623. {
  624. free(ct1);
  625. ct1 = ct2;
  626. };
  627. return ct1;
  628. };
  629. }
  630. return NULL;
  631. }
  632. bool kernelModuleKafka::dispatchEvent(EVENT_CONTAINER * Evt)
  633. {
  634. if (Evt == NULL)
  635. {
  636. return false;
  637. }
  638. if (! m_bEnabled)
  639. {
  640. return true;
  641. }
  642. #ifdef DEBUG
  643. char tBuffer[256];
  644. sprintf(tBuffer, "Event Class %d Type %d ", Evt->m_eClass, Evt->m_eType);
  645. LOG(tBuffer);
  646. #endif
  647. if (m_pEvtTemplates[Evt->m_eClass] != NULL)
  648. {
  649. // We have defined Channel for that class Events
  650. // Skip Event Handling by flags
  651. if (! m_bEvtFlags[Evt->m_eType])
  652. {
  653. #ifdef DEBUG
  654. // LOG("Disabled By FLAG!");
  655. #endif
  656. // return;
  657. }
  658. // Hadle Event
  659. CSTR tDATA = NULL;
  660. if (m_pEvtTemplates[Evt->m_eClass][Evt->m_eType] != NULL)
  661. {
  662. switch (Evt->m_eType)
  663. {
  664. case EVT_TARGET_2D_BLACK:
  665. case EVT_TARGET_2D_WHITE:
  666. {
  667. TARGET_DATA * tTARGET = (TARGET_DATA *) Evt->m_pEvtData;
  668. if (tTARGET != NULL)
  669. {
  670. char AZ[10];
  671. char RA[10];
  672. char WID[10];
  673. char LAT[10];
  674. char LON[10];
  675. char ALT[10];
  676. char SLAT[10];
  677. char SLON[10];
  678. char SALT[10];
  679. char SROT_X[10];
  680. char SROT_Y[10];
  681. char SROT_Z[10];
  682. char SNAME[64];
  683. char TS[64];
  684. sprintf(AZ, "%0.3f", tTARGET->local_target.fi);
  685. sprintf(RA, "%0.3f", tTARGET->local_target.r);
  686. sprintf(WID, "%0.3f", tTARGET->area);
  687. sprintf(LAT, "%0.6f", tTARGET->global_target.lat);
  688. sprintf(LON, "%0.6f", tTARGET->global_target.lon);
  689. sprintf(ALT, "%0.6f", tTARGET->global_target.alt);
  690. sprintf(TS, "%04d-%02d-%02dT%02d:%02d:%02d.%03lldZ", Evt->sTS.tm_year + 1900, Evt->sTS.tm_mon + 1, Evt->sTS.tm_mday, Evt->sTS.tm_hour, Evt->sTS.tm_min, Evt->sTS.tm_sec, Evt->m_UMSTS % 1000);
  691. sprintf(SLAT, "%0.6f", tTARGET->source_position.lat);
  692. sprintf(SLON, "%0.6f", tTARGET->source_position.lon);
  693. sprintf(SALT, "%0.6f", tTARGET->source_position.alt);
  694. sprintf(SROT_X, "%0.6f", tTARGET->source_orient.rot_x);
  695. sprintf(SROT_Y, "%0.6f", tTARGET->source_orient.rot_y);
  696. sprintf(SROT_Z, "%0.6f", tTARGET->source_orient.rot_z);
  697. CSTR tN = m_pDBC->getNodeName(Evt->m_nSourceNodeID);
  698. if (tN)
  699. {
  700. strncpy(SNAME, tN, 64);
  701. free(tN);
  702. }
  703. else
  704. {
  705. strncpy(SNAME, "Noname-Laser-Detector", 64);
  706. };
  707. tDATA = buildTemplate(m_pEvtTemplates[Evt->m_eClass][Evt->m_eType]->tpl, Evt->m_nSourceNodeID, TS, Evt->m_UUID, AZ, RA, WID, NULL, LAT, LON, ALT, NULL, SNAME, m_sServerIP, SLAT, SLON, SALT, SROT_X, SROT_Y, SROT_Z);
  708. };
  709. break;
  710. };
  711. case EVT_TARGET_3D_BLACK:
  712. case EVT_TARGET_3D_WHITE:
  713. {
  714. TARGET_DATA * tTARGET = (TARGET_DATA *) Evt->m_pEvtData;
  715. if (tTARGET != NULL)
  716. {
  717. char AZ[10];
  718. char EL[10];
  719. char RA[10];
  720. char WID[10];
  721. char LAT[10];
  722. char LON[10];
  723. char ALT[10];
  724. char SLAT[10];
  725. char SLON[10];
  726. char SALT[10];
  727. char SROT_X[10];
  728. char SROT_Y[10];
  729. char SROT_Z[10];
  730. char SIP[16];
  731. char SNAME[64];
  732. char TS[64];
  733. sprintf(AZ, "%0.3f", tTARGET->local_target.fi);
  734. sprintf(EL, "%0.3f", tTARGET->local_target.tetta);
  735. sprintf(RA, "%0.3f", tTARGET->local_target.r);
  736. sprintf(WID, "%0.3f", tTARGET->area);
  737. sprintf(LAT, "%0.6f", tTARGET->global_target.lat);
  738. sprintf(LON, "%0.6f", tTARGET->global_target.lon);
  739. sprintf(ALT, "%0.6f", tTARGET->global_target.alt);
  740. sprintf(TS, "%04d-%02d-%02dT%02d:%02d:%02d.%03lldZ", Evt->sTS.tm_year + 1900, Evt->sTS.tm_mon + 1, Evt->sTS.tm_mday, Evt->sTS.tm_hour, Evt->sTS.tm_min, Evt->sTS.tm_sec, Evt->m_UMSTS % 1000);
  741. sprintf(SLAT, "%0.6f", tTARGET->source_position.lat);
  742. sprintf(SLON, "%0.6f", tTARGET->source_position.lon);
  743. sprintf(SALT, "%0.6f", tTARGET->source_position.alt);
  744. sprintf(SROT_X, "%0.6f", tTARGET->source_orient.rot_x);
  745. sprintf(SROT_Y, "%0.6f", tTARGET->source_orient.rot_y);
  746. sprintf(SROT_Z, "%0.6f", tTARGET->source_orient.rot_z);
  747. CSTR tN = m_pDBC->getNodeName(Evt->m_nSourceNodeID);
  748. if (tN)
  749. {
  750. strncpy(SNAME, tN, 64);
  751. free(tN);
  752. }
  753. else
  754. {
  755. strncpy(SNAME, "Noname-Laser-Detector", 64);
  756. };
  757. if (0)
  758. {
  759. strncpy(SIP, tN, 16);
  760. free(tN);
  761. }
  762. else
  763. {
  764. strncpy(SIP, "192.168.1.24", 16);
  765. };
  766. tDATA = buildTemplate(m_pEvtTemplates[Evt->m_eClass][Evt->m_eType]->tpl, Evt->m_nSourceNodeID, TS, Evt->m_UUID, AZ, RA, WID, EL, LAT, LON, ALT, NULL, SNAME, SIP, SLAT, SLON, SALT, SROT_X, SROT_Y, SROT_Z);
  767. };
  768. break;
  769. };
  770. case EVT_FH_JAMER_ON:
  771. case EVT_FH_JAMER_OFF:
  772. case EVT_FH_FLY_TO:
  773. case EVT_FH_WAYPOINT:
  774. case EVT_FH_INTERCEPT_OK:
  775. case EVT_FH_INTERCEPT_NOK:
  776. case EVT_FH_BUSY:
  777. case EVT_FH_LANDED:
  778. {
  779. FH_MISSION_DATA * tPOINT = (FH_MISSION_DATA *) Evt->m_pEvtData;
  780. if (tPOINT)
  781. {
  782. char TS[64];
  783. char LAT[10];
  784. char LON[10];
  785. char ALT[10];
  786. sprintf(LAT, "%0.6f", tPOINT->location.lat);
  787. sprintf(LON, "%0.6f", tPOINT->location.lon);
  788. sprintf(ALT, "%0.6f", tPOINT->location.alt);
  789. sprintf(TS, "%04d-%02d-%02dT%02d:%02d:%02d.%03lldZ", Evt->sTS.tm_year + 1900, Evt->sTS.tm_mon + 1, Evt->sTS.tm_mday, Evt->sTS.tm_hour, Evt->sTS.tm_min, Evt->sTS.tm_sec, Evt->m_UMSTS % 1000);
  790. tDATA = buildTemplate(m_pEvtTemplates[Evt->m_eClass][Evt->m_eType]->tpl, Evt->m_nSourceNodeID, TS, Evt->m_UUID, NULL, NULL, NULL, NULL, LAT, LON, ALT, tPOINT->missionID);
  791. };
  792. break;
  793. };
  794. default:
  795. {
  796. break;
  797. };
  798. };
  799. if (tDATA != NULL)
  800. {
  801. #ifdef KAFKA_DUMMY_SEND
  802. LOG(tDATA);
  803. #else
  804. m_pProtocol->issuePost(m_pEvtTemplates[Evt->m_eClass][Evt->m_eType]->topic, tDATA, strlen(tDATA));
  805. #endif
  806. }
  807. else
  808. {
  809. LOG_ERROR("Cant Build Template!");
  810. };
  811. };
  812. };
  813. return true;
  814. }
  815. #undef LOG
  816. #undef LOG_ERROR