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.

797 lines
18 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "protocolDefender.h"
  2. #include "../../alg/generic/md5.h"
  3. #include "../json/json_tool.h"
  4. #include <json/reader.h>
  5. #include <json/value.h>
  6. #include <json/writer.h>
  7. #include <strings.h>
  8. #define LOG(X) m_pLog->Log("Defender", this, X)
  9. #define LOGS(X) basicLogCollection::getInstance()->Log("Defender", NULL, X)
  10. #define LOG_ERROR(X) m_pLog->Log("Defender", this, _LOG_ERROR, X)
  11. CSTR protocolDefender::buildURL(CSTR templ, int dim, CSTR devID)
  12. {
  13. CSTR RetVal;
  14. RetVal = (CSTR) malloc(256);
  15. if (RetVal != NULL)
  16. {
  17. if (m_bUseSSL)
  18. {
  19. sprintf(RetVal, "https://%s:%d%s", m_pServerIP, m_nServerPort, m_pAccessURL);
  20. }
  21. else
  22. {
  23. sprintf(RetVal, "http://%s:%d%s", m_pServerIP, m_nServerPort, m_pAccessURL);
  24. };
  25. };
  26. return RetVal;
  27. }
  28. /* Default Constructor */
  29. protocolDefender::protocolDefender(config_setting_t * Settings) :
  30. protocolHTTP(basicSettingsProvider::getInstance()->getSubNode(Settings, "DEFENDER_CONNECTION"))
  31. {
  32. m_pLog = basicLogCollection::getInstance();
  33. m_bMitigationStatus = false;
  34. m_pSettings = basicSettingsProvider::getInstance()->getSubNode(Settings, "DEFENDER_CONNECTION");
  35. m_pScannerName = (CSTR) malloc(OS_SCANNER_NAME_SIZE);
  36. if (m_pScannerName == NULL)
  37. {
  38. return;
  39. }
  40. memset(m_pScannerName, 0, OS_SCANNER_NAME_SIZE);
  41. m_pServerIP = (CSTR) malloc(OS_CEP_ADDRESS_SIZE);
  42. if (m_pServerIP == NULL)
  43. {
  44. return;
  45. }
  46. memset(m_pServerIP, 0, OS_CEP_ADDRESS_SIZE);
  47. m_pAccessURL = (CSTR) malloc(CTEXT);
  48. if (m_pAccessURL == NULL)
  49. {
  50. return;
  51. }
  52. memset(m_pAccessURL, 0, CTEXT);
  53. m_bCurrentStatus = false;
  54. if (m_pSettings != NULL)
  55. {
  56. int intVar;
  57. double floatVar;
  58. config_setting_t * pSetting;
  59. if (Settings != NULL)
  60. {
  61. m_bEnabled = true;
  62. }
  63. else
  64. {
  65. if (! config_setting_lookup_bool(m_pSettings, "ENABLE", &intVar))
  66. {
  67. intVar = m_bEnabled = false;
  68. LOG("PROTOCOL DISABLED[default]");
  69. pSetting = config_setting_add(m_pSettings, "ENABLE", CONFIG_TYPE_BOOL);
  70. config_setting_set_bool(pSetting, intVar);
  71. basicSettingsProvider::getInstance()->compromise();
  72. }
  73. else
  74. {
  75. m_bEnabled = (bool) intVar;
  76. };
  77. };
  78. if (m_bEnabled)
  79. {
  80. if (! config_setting_lookup_float(m_pSettings, "LOCATION_LON", &floatVar))
  81. {
  82. m_fLon = floatVar = 35.0938962;
  83. pSetting = config_setting_add(m_pSettings, "LOCATION_LON", CONFIG_TYPE_FLOAT);
  84. config_setting_set_float(pSetting, floatVar);
  85. basicSettingsProvider::getInstance()->compromise();
  86. }
  87. else
  88. {
  89. m_fLon = floatVar;
  90. };
  91. if (! config_setting_lookup_float(m_pSettings, "LOCATION_LAT", &floatVar))
  92. {
  93. m_fLat = floatVar = 32.904208;
  94. pSetting = config_setting_add(m_pSettings, "LOCATION_LAT", CONFIG_TYPE_FLOAT);
  95. config_setting_set_float(pSetting, floatVar);
  96. basicSettingsProvider::getInstance()->compromise();
  97. }
  98. else
  99. {
  100. m_fLat = floatVar;
  101. };
  102. if (! config_setting_lookup_bool(m_pSettings, "USE_SSL", &intVar))
  103. {
  104. intVar = m_bUseSSL = false;
  105. LOG("PROTOCOL DISABLED[default]");
  106. pSetting = config_setting_add(m_pSettings, "USE_SSL", CONFIG_TYPE_BOOL);
  107. config_setting_set_bool(pSetting, intVar);
  108. basicSettingsProvider::getInstance()->compromise();
  109. }
  110. else
  111. {
  112. m_bUseSSL = (bool) intVar;
  113. };
  114. if (! config_setting_lookup_string(m_pSettings, "SCANNER_NAME", (const char **) &m_pScannerName))
  115. {
  116. strncpy(m_pScannerName, "LRF_2D_001", 64);
  117. LOG(m_pScannerName);
  118. pSetting = config_setting_add(m_pSettings, "SCANNER_NAME", CONFIG_TYPE_STRING);
  119. config_setting_set_string(pSetting, m_pScannerName);
  120. basicSettingsProvider::getInstance()->compromise();
  121. };
  122. if (! config_setting_lookup_int(m_pSettings, "SCANNER_DIMENTIONS", &m_nScannerDimentions))
  123. {
  124. m_nScannerDimentions = 2;
  125. pSetting = config_setting_add(m_pSettings, "SCANNER_DIMENTIONS", CONFIG_TYPE_INT);
  126. config_setting_set_int(pSetting, m_nScannerDimentions);
  127. basicSettingsProvider::getInstance()->compromise();
  128. };
  129. if (! config_setting_lookup_string(m_pSettings, "CEP_IP_ADDRESS", (const char **) &m_pServerIP))
  130. {
  131. strncpy(m_pServerIP, "192.168.200.204", 16);
  132. LOG(m_pServerIP);
  133. pSetting = config_setting_add(m_pSettings, "CEP_IP_ADDRESS", CONFIG_TYPE_STRING);
  134. config_setting_set_string(pSetting, m_pServerIP);
  135. basicSettingsProvider::getInstance()->compromise();
  136. };
  137. LOG(m_pServerIP);
  138. if (! config_setting_lookup_int(m_pSettings, "CEP_IP_PORT", &m_nServerPort))
  139. {
  140. m_nServerPort = 80;
  141. pSetting = config_setting_add(m_pSettings, "CEP_IP_PORT", CONFIG_TYPE_INT);
  142. config_setting_set_int(pSetting, m_nServerPort);
  143. basicSettingsProvider::getInstance()->compromise();
  144. };
  145. if (! config_setting_lookup_string(m_pSettings, "ACCESS_URL", (const char **) &m_pAccessURL))
  146. {
  147. strncpy(m_pAccessURL, DFSL_DEFENDER_DEFAULT_URL, CTEXT);
  148. pSetting = config_setting_add(m_pSettings, "ACCESS_URL", CONFIG_TYPE_STRING);
  149. config_setting_set_string(pSetting, m_pAccessURL);
  150. basicSettingsProvider::getInstance()->compromise();
  151. };
  152. LOG(m_pAccessURL);
  153. };
  154. basicSettingsProvider::getInstance()->validate();
  155. };
  156. }
  157. /*
  158. 1.2 GHz
  159. Number of Cores
  160. Quad-Core
  161. Type
  162. Tegra 3
  163. Processor Number
  164. T30SL
  165. Manufacturer
  166. NVIDIA
  167. Verify that you have the following installed on your system
  168. Ubuntu 16.04 LTS (with GCC 5.4)
  169. NVIDIA Display Driver ver. 375
  170. NVIDIA VideoSDK 7.1
  171. cuDNN 6 & TensorRT 2.1
  172. NVIDIA CUDA 8.0
  173. Download the DeepStream 1.0 tar file (below)
  174. Extract the package at the location of your choice
  175. Follow the usage instructions from the Deepstream_User_guide.pdf in the downloaded package.
  176. */
  177. protocolDefender::~protocolDefender()
  178. {
  179. if (m_pScannerName != NULL)
  180. {
  181. free(m_pScannerName);
  182. }
  183. if (m_pServerIP != NULL)
  184. {
  185. free(m_pServerIP);
  186. }
  187. if (m_pAccessURL != NULL)
  188. {
  189. free(m_pAccessURL);
  190. }
  191. }
  192. void protocolDefender::setScannerName(CSTR Name)
  193. {
  194. sprintf(m_pScannerName, "%s", Name);
  195. }
  196. void protocolDefender::setProtocolType(bool DeviceIs3D)
  197. {
  198. if (DeviceIs3D)
  199. {
  200. m_nScannerDimentions = 3;
  201. }
  202. else
  203. {
  204. m_nScannerDimentions = 2;
  205. };
  206. }
  207. CSTR protocolDefender::assembleStatusData(bool StatusOK)
  208. {
  209. CSTR RetVal = NULL;
  210. CSTR TIME_STAMP;
  211. CSTR tSRC;
  212. CSTR tTARGET;
  213. CSTR tID;
  214. RetVal = (CSTR) malloc(CLOG);
  215. if (RetVal != NULL)
  216. {
  217. TIME_STAMP = getTimeStamp();
  218. if (TIME_STAMP != NULL)
  219. {
  220. tTARGET = (CSTR) malloc(128);
  221. if (tTARGET != NULL)
  222. {
  223. tSRC = (CSTR) malloc(128);
  224. if (tSRC)
  225. {
  226. tID = (CSTR) malloc(64);
  227. if (tID != NULL)
  228. {
  229. sprintf(tID, "%s", MD5String(TIME_STAMP));
  230. sprintf(tSRC, DFSL_SENSOR_SOURCE_DTO, DFSL_HARDWARE_TYPE, DFRL_PROVIDER_ID, m_pScannerName);
  231. sprintf(tTARGET, DFSL_STATUS_DTO, TIME_STAMP, defenderStatusMode[((StatusOK) ? 1 : 0)]);
  232. sprintf(RetVal, PACKAGE_SE_STATUS_DATA_ELEMENT, defenderTypeDescription[DC_STATUS], TIME_STAMP, tSRC, "DFSL_LIDAR_SENSOR_STATUS", DFSL_DATA_TYPE_STATUS, tID, tTARGET);
  233. free(tID);
  234. free(tSRC);
  235. free(tTARGET);
  236. free(TIME_STAMP);
  237. }
  238. else
  239. {
  240. free(tSRC);
  241. free(tTARGET);
  242. free(TIME_STAMP);
  243. free(RetVal);
  244. }
  245. }
  246. else
  247. {
  248. free(tTARGET);
  249. free(TIME_STAMP);
  250. free(RetVal);
  251. };
  252. }
  253. else
  254. {
  255. free(TIME_STAMP);
  256. free(RetVal);
  257. };
  258. }
  259. else
  260. {
  261. free(RetVal);
  262. RetVal = NULL;
  263. };
  264. };
  265. return RetVal;
  266. }
  267. CSTR protocolDefender::assembleFaultData(uint8_t Code, CSTR Desc)
  268. {
  269. CSTR RetVal;
  270. CSTR TIME_STAMP;
  271. CSTR tSRC;
  272. CSTR tTARGET;
  273. CSTR tID;
  274. RetVal = (CSTR) malloc(CLOG);
  275. if (RetVal != NULL)
  276. {
  277. TIME_STAMP = getTimeStamp();
  278. if (TIME_STAMP != NULL)
  279. {
  280. tTARGET = (CSTR) malloc(128);
  281. if (tTARGET != NULL)
  282. {
  283. tSRC = (CSTR) malloc(128);
  284. if (tSRC)
  285. {
  286. tID = (CSTR) malloc(64);
  287. if (tID != NULL)
  288. {
  289. sprintf(tID, "%s", MD5String(TIME_STAMP));
  290. sprintf(tSRC, DFSL_SENSOR_SOURCE_DTO, DFSL_HARDWARE_TYPE, DFRL_PROVIDER_ID, m_pScannerName);
  291. sprintf(tTARGET, DFSL_ERROR_DTO, TIME_STAMP, Code, Desc);
  292. sprintf(RetVal, PACKAGE_SE_STATUS_DATA_ELEMENT, Desc, TIME_STAMP, tSRC, "DFSL_LIDARE_SENSOR_FAULT_DATA", DFSL_DATA_TYPE_ERROR, tID, tTARGET);
  293. free(tID);
  294. free(tSRC);
  295. free(tTARGET);
  296. free(TIME_STAMP);
  297. }
  298. else
  299. {
  300. free(tSRC);
  301. free(tTARGET);
  302. free(TIME_STAMP);
  303. free(RetVal);
  304. }
  305. }
  306. else
  307. {
  308. free(tTARGET);
  309. free(TIME_STAMP);
  310. free(RetVal);
  311. };
  312. }
  313. else
  314. {
  315. free(TIME_STAMP);
  316. free(RetVal);
  317. };
  318. }
  319. else
  320. {
  321. free(RetVal);
  322. RetVal = NULL;
  323. };
  324. };
  325. return RetVal;
  326. }
  327. CSTR protocolDefender::assembleTargetData(int targetID, int Range, int Width, int Azimuth, int Elevation)
  328. {
  329. CSTR RetVal;
  330. CSTR TIME_STAMP;
  331. CSTR tSRC;
  332. CSTR tTARGET;
  333. CSTR tID;
  334. RetVal = (CSTR) malloc(CLOG);
  335. if (RetVal != NULL)
  336. {
  337. TIME_STAMP = getTimeStamp();
  338. if (TIME_STAMP != NULL)
  339. {
  340. tTARGET = (CSTR) malloc(128);
  341. if (tTARGET != NULL)
  342. {
  343. tSRC = (CSTR) malloc(128);
  344. if (tSRC)
  345. {
  346. tID = (CSTR) malloc(64);
  347. if (tID != NULL)
  348. {
  349. sprintf(tID, "%s", MD5String(TIME_STAMP));
  350. sprintf(tSRC, DFSL_SENSOR_SOURCE_DTO, DFSL_HARDWARE_TYPE, DFRL_PROVIDER_ID, m_pScannerName);
  351. if (m_nScannerDimentions > 2)
  352. {
  353. sprintf(tTARGET, DFSL_3D_TARGET_DTO, Azimuth, Elevation, Range);
  354. }
  355. else
  356. {
  357. sprintf(tTARGET, DFSL_2D_TARGET_DTO, Azimuth, Range, Width);
  358. };
  359. sprintf(RetVal, PACKAGE_SE_TARGET_DATA_ELEMENT, defenderTypeDescription[DC_ALARM], TIME_STAMP, tSRC, "DFSL_TARGET_DATA", DFSL_DATA_TYPE_TARGET, tID, tTARGET);
  360. free(tID);
  361. free(tSRC);
  362. free(tTARGET);
  363. free(TIME_STAMP);
  364. }
  365. else
  366. {
  367. free(tSRC);
  368. free(tTARGET);
  369. free(TIME_STAMP);
  370. free(RetVal);
  371. }
  372. }
  373. else
  374. {
  375. free(tTARGET);
  376. free(TIME_STAMP);
  377. free(RetVal);
  378. };
  379. }
  380. else
  381. {
  382. free(TIME_STAMP);
  383. free(RetVal);
  384. };
  385. }
  386. else
  387. {
  388. free(RetVal);
  389. RetVal = NULL;
  390. };
  391. };
  392. return RetVal;
  393. }
  394. static uint32_t DEFENDER_MESSAGE_ID = 0;
  395. size_t protocolDefender::assembleDefenderJSON(CSTR Buffer, defenderCategoryTypes Type, uint8_t Severity, CSTR Location, CSTR Data)
  396. {
  397. char tBuffer[CLOG];
  398. size_t RetVal;
  399. CSTR tBuf;
  400. RetVal = 0;
  401. tBuf = getTimeStamp();
  402. DEFENDER_MESSAGE_ID++;
  403. // memset( tBuffer, 0, CLOG );
  404. if (tBuf != NULL)
  405. {
  406. // char ID[64];
  407. switch (Type)
  408. {
  409. case DC_STATUS: Severity = 0; break;
  410. case DC_ERROR : Severity = 2; break;
  411. case DC_ALARM : Severity = 4; break;
  412. default : Severity = 2;
  413. };
  414. // sprintf( ID, "%s", MD5String( tBuf ) );
  415. if ((m_nScannerDimentions > 2) && (Type == DC_ALARM))
  416. {
  417. Type = DC_ALARM_3D;
  418. }
  419. sprintf(tBuffer, DFSL_SE_ENVELOPE,
  420. // DEFENDER_MESSAGE_ID,
  421. defenderCategories[Type], defenderTypeSeverity[Severity], tBuf, tBuf, Location, Data);
  422. RetVal = strlen(tBuffer);
  423. memcpy(Buffer, tBuffer, RetVal);
  424. Buffer[RetVal] = (char) 0;
  425. free(tBuf);
  426. };
  427. return RetVal;
  428. }
  429. bool protocolDefender::buildStatusPackage(unsigned char * Buffer, int & BufferSize, bool Status)
  430. {
  431. if (Buffer != NULL)
  432. {
  433. CSTR tBuf;
  434. tBuf = assembleStatusData(Status);
  435. #ifdef DEBUG
  436. // LOG(tBuf);
  437. #endif
  438. if (tBuf != NULL)
  439. {
  440. char DFSL_LOCATION[256];
  441. sprintf(DFSL_LOCATION, DFSL_LOCATION_DTO, m_fLon, m_fLat);
  442. BufferSize = assembleDefenderJSON((CSTR) Buffer, DC_STATUS, (Status) ? 0 : 2, DFSL_LOCATION, tBuf);
  443. #ifdef DEBUG
  444. LOG((CSTR) Buffer);
  445. #endif
  446. free(tBuf);
  447. return true;
  448. }
  449. };
  450. return false;
  451. }
  452. bool protocolDefender::buildFaultPackage(unsigned char * Buffer, int & BufferSize, unsigned char Type, CSTR Description)
  453. {
  454. if (Buffer != NULL)
  455. {
  456. CSTR tBuf;
  457. tBuf = assembleFaultData(Type, Description);
  458. if (tBuf != NULL)
  459. {
  460. char DFSL_LOCATION[256];
  461. sprintf(DFSL_LOCATION, DFSL_LOCATION_DTO, m_fLon, m_fLat);
  462. BufferSize = assembleDefenderJSON((CSTR) Buffer, DC_ERROR, 3, DFSL_LOCATION, tBuf);
  463. free(tBuf);
  464. return true;
  465. };
  466. };
  467. return false;
  468. }
  469. bool protocolDefender::buildEvent2DPackage(unsigned char * Buffer, int & BufferSize, CSTR msgUID, int targetID, float Angle, float Range, float Width)
  470. {
  471. if (Buffer != NULL)
  472. {
  473. CSTR tBuf;
  474. tBuf = assembleTargetData(targetID, Range, Width, Angle, 0);
  475. if (tBuf != NULL)
  476. {
  477. char DFSL_LOCATION[256];
  478. sprintf(DFSL_LOCATION, DFSL_LOCATION_DTO, m_fLon, m_fLat);
  479. BufferSize = assembleDefenderJSON((CSTR) Buffer, DC_ALARM, 3, DFSL_LOCATION, tBuf);
  480. free(tBuf);
  481. return true;
  482. };
  483. };
  484. return false;
  485. }
  486. bool protocolDefender::buildEvent3DPackage(unsigned char * Buffer, int & BufferSize, CSTR msgUID, int targetID, float Angle1, float Angle2, float Range)
  487. {
  488. if (Buffer != NULL)
  489. {
  490. CSTR tBuf;
  491. tBuf = assembleTargetData(targetID, Range, 0, Angle1, Angle2);
  492. #ifdef DEBUG
  493. // LOG(tBuf);
  494. #endif
  495. if (tBuf != NULL)
  496. {
  497. char DFSL_LOCATION[256];
  498. sprintf(DFSL_LOCATION, DFSL_LOCATION_DTO, m_fLon, m_fLat);
  499. BufferSize = assembleDefenderJSON((CSTR) Buffer, DC_ALARM, 3, DFSL_LOCATION, tBuf);
  500. #ifdef DEBUG
  501. LOG((CSTR) Buffer);
  502. #endif
  503. free(tBuf);
  504. return true;
  505. };
  506. };
  507. return false;
  508. }
  509. bool protocolDefender::buildClockSyncPackage(unsigned char * Buffer, int & BufferSize)
  510. {
  511. /*if( Buffer!= NULL ){
  512. CSTR tBuf;
  513. tBuf = getSHTimeStamp();
  514. if( tBuf != NULL ){
  515. sprintf(
  516. ((char *)(Buffer+BufferSize)),
  517. PACKAGE_ENVELOPE_TEMPLATE_CLOCKSYNC,
  518. tBuf
  519. );
  520. BufferSize = strlen( (char *)Buffer );
  521. free( tBuf );
  522. return true;
  523. };
  524. };*/
  525. return false;
  526. }
  527. bool protocolDefender::buildCallBackPackage(unsigned char * Buffer, int & BufferSize, CSTR CallBackPath)
  528. {
  529. /*if( Buffer!= NULL ){
  530. sprintf(
  531. ((char *)(Buffer+BufferSize)),
  532. PACKAGE_ENVELOPE_TEMPLATE_REG_CALL,
  533. CallBackPath
  534. );
  535. BufferSize = strlen( (char *)Buffer );
  536. return true;
  537. };*/
  538. return false;
  539. }
  540. bool protocolDefender::Alarm2D(float Angle, float Range, float Width, int ID)
  541. {
  542. bool RetVal = false;
  543. char Buffer[1024];
  544. int BufferSize = 0;
  545. CSTR URL;
  546. CSTR UID;
  547. if (! m_bEnabled)
  548. {
  549. return false;
  550. }
  551. UID = getUniqID_MD5();
  552. if (UID != NULL)
  553. {
  554. URL = buildURL(SERVICE_URL_TEMPLATE_EVENT, m_nScannerDimentions, m_pScannerName);
  555. #ifdef DEBUG
  556. LOG(URL);
  557. #endif
  558. RetVal = buildEvent2DPackage((unsigned char *) Buffer, BufferSize, UID, ID, Angle, Range, Width);
  559. if (URL != NULL)
  560. {
  561. RetVal = issuePost(URL, Buffer, BufferSize);
  562. free(URL);
  563. };
  564. free(UID);
  565. };
  566. return RetVal;
  567. }
  568. bool protocolDefender::Alarm3D(float Angle1, float Angle2, float Range, int ID)
  569. {
  570. bool RetVal = false;
  571. char Buffer[1024];
  572. int BufferSize = 0;
  573. CSTR URL;
  574. CSTR UID;
  575. if (! m_bEnabled)
  576. {
  577. return false;
  578. }
  579. UID = getUniqID_MD5();
  580. if (UID != NULL)
  581. {
  582. URL = buildURL(SERVICE_URL_TEMPLATE_EVENT, m_nScannerDimentions, m_pScannerName);
  583. #ifdef DEBUG
  584. LOG(URL);
  585. #endif
  586. RetVal = buildEvent3DPackage((unsigned char *) Buffer, BufferSize, UID, ID, Angle1, Angle2, Range);
  587. if (URL != NULL)
  588. {
  589. RetVal = issuePost(URL, Buffer, BufferSize);
  590. free(URL);
  591. };
  592. free(UID);
  593. };
  594. return RetVal;
  595. }
  596. bool protocolDefender::VisibilityChanged(bool Worsened)
  597. {
  598. bool RetVal = false;
  599. char Buffer[1024];
  600. int BufferSize = 0;
  601. CSTR URL;
  602. if (! m_bEnabled)
  603. {
  604. return false;
  605. }
  606. URL = buildURL(SERVICE_URL_TEMPLATE_STATUS, m_nScannerDimentions, m_pScannerName);
  607. #ifdef DEBUG
  608. LOG(URL);
  609. #endif
  610. RetVal = buildStatusPackage((unsigned char *) Buffer, BufferSize, ! Worsened);
  611. if (URL != NULL)
  612. {
  613. RetVal = issuePost(URL, Buffer, BufferSize);
  614. free(URL);
  615. };
  616. return RetVal;
  617. }
  618. bool protocolDefender::StatusUpdate(void)
  619. {
  620. bool RetVal = false;
  621. char Buffer[1024];
  622. int BufferSize = 0;
  623. CSTR URL;
  624. if (! m_bEnabled)
  625. {
  626. return false;
  627. }
  628. URL = buildURL(SERVICE_URL_TEMPLATE_STATUS, m_nScannerDimentions, m_pScannerName);
  629. #ifdef DEBUG
  630. LOG(URL);
  631. #endif
  632. RetVal = buildStatusPackage((unsigned char *) Buffer, BufferSize, m_bCurrentStatus);
  633. if (URL != NULL)
  634. {
  635. RetVal = issuePost(URL, Buffer, BufferSize);
  636. free(URL);
  637. };
  638. return RetVal;
  639. }
  640. bool protocolDefender::ErrorReporting(int lvl, CSTR Descr)
  641. {
  642. bool RetVal = false;
  643. char Buffer[1024];
  644. int BufferSize = 0;
  645. CSTR URL;
  646. if (! m_bEnabled)
  647. {
  648. return false;
  649. }
  650. URL = buildURL(SERVICE_URL_TEMPLATE_FAULT, m_nScannerDimentions, m_pScannerName);
  651. #ifdef DEBUG
  652. LOG(URL);
  653. #endif
  654. RetVal = buildFaultPackage((unsigned char *) Buffer, BufferSize, lvl, Descr);
  655. if (URL != NULL)
  656. {
  657. RetVal = issuePost(URL, Buffer, BufferSize);
  658. free(URL);
  659. };
  660. return RetVal;
  661. }
  662. bool protocolDefender::StartTimeSynch(void)
  663. {
  664. bool RetVal = false;
  665. // LOG("TimeSYnc");
  666. /*char Buffer[1024];
  667. int BufferSize = 0;
  668. CSTR URL = NULL;
  669. URL = buildURL( SERVICE_URL_TEMPLATE_CLOCKSYNC, m_nScannerDimentions, m_pScannerName );
  670. RetVal = buildClockSyncPackage(( unsigned char *) Buffer, BufferSize );
  671. if( URL != NULL ){
  672. RetVal = issuePost( URL, Buffer, BufferSize );
  673. free( URL );
  674. };*/
  675. return RetVal;
  676. }
  677. bool protocolDefender::packetHandler(protocolPackage * Package)
  678. {
  679. // LOG("PACKET HANDLER");
  680. if (! m_bEnabled)
  681. {
  682. return false;
  683. }
  684. if (Package == NULL)
  685. {
  686. return false;
  687. }
  688. if (Package->m_nSize == 0)
  689. {
  690. return false;
  691. }
  692. if (Package->m_pData == NULL)
  693. {
  694. return false;
  695. }
  696. if (Package->m_nCode != 200)
  697. {
  698. return false;
  699. }
  700. try
  701. {
  702. Json::Value root;
  703. #ifdef OLD_WAY_JSON
  704. Json::Reader reader;
  705. if (! reader.parse((char *) Package->m_pData, root))
  706. {
  707. LOG_ERROR("Error parsing the string");
  708. return true;
  709. };
  710. #else
  711. JSONCPP_STRING err;
  712. Json::CharReaderBuilder builder;
  713. const std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
  714. if (! reader->parse((char *) Package->m_pData, (char *) Package->m_pData + Package->m_nSize, &root, &err))
  715. {
  716. LOG_ERROR("Error parsing the string");
  717. LOG_ERROR(err.c_str());
  718. return true;
  719. };
  720. #endif
  721. if (root.size())
  722. {
  723. Json::Value tVal;
  724. tVal = root["mitigation"]["parameters"]["cmd"];
  725. if (! tVal.isNull())
  726. {
  727. #ifdef DEBUG
  728. LOG("MITIGATION MESSAGE!");
  729. #endif
  730. if (strcasecmp(tVal.asString().c_str(), "ARM") == 0)
  731. {
  732. #ifdef DEBUG
  733. LOG("ARM!");
  734. #endif
  735. m_bMitigationStatus = true;
  736. };
  737. if (strcasecmp(tVal.asString().c_str(), "DISARM") == 0)
  738. {
  739. #ifdef DEBUG
  740. LOG("DISARM!");
  741. #endif
  742. m_bMitigationStatus = false;
  743. };
  744. };
  745. };
  746. }
  747. catch (exception e)
  748. {
  749. };
  750. return true;
  751. }
  752. #undef LOG
  753. #undef LOG_ERROR