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.

659 lines
19 KiB

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