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.

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