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.

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