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.

131 lines
3.0 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "protocolEuropeanGeneral.h"
  2. #include "../../alg/generic/md5.h"
  3. CSTR defenderStatusMode[] = {
  4. "OPERATIONAL",
  5. "DEGRADED"
  6. };
  7. CSTR defenderFaultCode[] = {
  8. "Critical",
  9. "Warning",
  10. "Info"
  11. };
  12. CSTR defenderCategories[] = {
  13. DFSL_CATEGORY_ERROR,
  14. DFSL_CATEGORY_STATUS,
  15. DFSL_CATEGORY_ALARM_2D,
  16. DFSL_CATEGORY_ALARM_3D
  17. };
  18. CSTR defenderTypeDescription[] = {
  19. "Fault Event",
  20. "Status Message",
  21. "Target Detection Event",
  22. "Target Detection Event"
  23. };
  24. CSTR defenderTypeSeverity[] = {
  25. "very-low",
  26. "low",
  27. "medium",
  28. "high",
  29. "very-high"
  30. };
  31. /* Global Time Diff Value to correct Timestamps */
  32. static int g_iTimeDiff = 0;
  33. /**
  34. * number of seconds from 1 Jan. 1601 00:00 to 1 Jan 1970 00:00 UTC
  35. */
  36. //#define EPOCH_DIFF 11644473600LL
  37. #define UNIX_TimeStamp_2_WINDOWS_FileTime_SHIFT 116444736000000000
  38. #ifdef __linux__
  39. unsigned long long getSHDTimeValue( void ){
  40. unsigned long long tMilliseconds;
  41. struct timeval tData;
  42. struct timezone tTZ;
  43. tMilliseconds = 0;
  44. tTZ.tz_minuteswest = 0;
  45. tTZ.tz_dsttime = 0;
  46. if( gettimeofday( &tData, &tTZ ) == -1 ){
  47. } else {
  48. tMilliseconds = tData.tv_sec;
  49. tMilliseconds = tMilliseconds *1000;
  50. tMilliseconds += tData.tv_usec / 1000;
  51. };
  52. #else
  53. /*
  54. void TimetToFileTime( time_t t, LPFILETIME pft ){
  55. LONGLONG ll = Int32x32To64(t, 10000000) + 116444736000000000;
  56. pft->dwLowDateTime = (DWORD) ll;
  57. pft->dwHighDateTime = ll >>32;
  58. }*/
  59. unsigned __int64 getSHDTimeValue( void ){
  60. unsigned __int64 tMilliseconds;
  61. SYSTEMTIME Ztime;
  62. GetSystemTime(&Ztime);
  63. SystemTimeToFileTime( &Ztime, (FILETIME*) &tMilliseconds );
  64. tMilliseconds -= UNIX_TimeStamp_2_WINDOWS_FileTime_SHIFT;
  65. tMilliseconds = tMilliseconds / 10000;
  66. #endif
  67. tMilliseconds += g_iTimeDiff;
  68. return tMilliseconds;
  69. };
  70. CSTR getSHDTimeStamp( void ){
  71. CSTR RetVal = NULL;
  72. time_t rawtime;
  73. uint32_t msec;
  74. struct tm * ptm = NULL;
  75. time ( &rawtime );
  76. ptm = gmtime ( &rawtime );
  77. msec = getSHDTimeValue() % 1000;
  78. //2019-03-24T12:32:59.670Z
  79. if( ptm != NULL ) {
  80. RetVal = (CSTR) malloc( 128 );
  81. if( RetVal!=NULL ){
  82. sprintf( RetVal, "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ",
  83. (ptm->tm_year+1900),
  84. (ptm->tm_mon+1),
  85. ptm->tm_mday,
  86. ptm->tm_hour,
  87. ptm->tm_min,
  88. ptm->tm_sec,
  89. msec
  90. );
  91. };
  92. };
  93. return RetVal;
  94. };
  95. bool correctSHDTime( int diff ){
  96. #ifdef __linux__
  97. struct timeval tData;
  98. struct timezone tTZ;
  99. tTZ.tz_minuteswest = 0;
  100. tTZ.tz_dsttime = 0;
  101. if( gettimeofday( &tData, &tTZ ) == -1 ){
  102. return false;
  103. } else {
  104. tData.tv_sec += diff / 1000;
  105. tData.tv_usec += ( diff * 1000 ) % 1000000;
  106. };
  107. if( settimeofday( &tData, &tTZ ) == -1 ){
  108. return false;
  109. };
  110. #else
  111. unsigned __int64 tMilliseconds;
  112. SYSTEMTIME Ztime;
  113. GetSystemTime(&Ztime);
  114. SystemTimeToFileTime( &Ztime, (FILETIME*) &tMilliseconds );
  115. tMilliseconds += diff * 10000;
  116. FileTimeToSystemTime( (FILETIME*) &tMilliseconds, &Ztime );
  117. if( 0 == SetSystemTime(&Ztime) ) return false;
  118. #endif
  119. return true;
  120. };