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.

770 lines
21 KiB

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