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.

665 lines
15 KiB

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