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.

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