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.
 
 
 
 
 
 

132 lines
3.0 KiB

#include "protocolEuropeanGeneral.h"
#include "../../alg/generic/md5.h"
CSTR defenderStatusMode[] = {
"OPERATIONAL",
"DEGRADED"
};
CSTR defenderFaultCode[] = {
"Critical",
"Warning",
"Info"
};
CSTR defenderCategories[] = {
DFSL_CATEGORY_ERROR,
DFSL_CATEGORY_STATUS,
DFSL_CATEGORY_ALARM_2D,
DFSL_CATEGORY_ALARM_3D
};
CSTR defenderTypeDescription[] = {
"Fault Event",
"Status Message",
"Target Detection Event",
"Target Detection Event"
};
CSTR defenderTypeSeverity[] = {
"very-low",
"low",
"medium",
"high",
"very-high"
};
/* Global Time Diff Value to correct Timestamps */
static int g_iTimeDiff = 0;
/**
* number of seconds from 1 Jan. 1601 00:00 to 1 Jan 1970 00:00 UTC
*/
//#define EPOCH_DIFF 11644473600LL
#define UNIX_TimeStamp_2_WINDOWS_FileTime_SHIFT 116444736000000000
#ifdef __linux__
unsigned long long getSHDTimeValue( void ){
unsigned long long tMilliseconds;
struct timeval tData;
struct timezone tTZ;
tMilliseconds = 0;
tTZ.tz_minuteswest = 0;
tTZ.tz_dsttime = 0;
if( gettimeofday( &tData, &tTZ ) == -1 ){
} else {
tMilliseconds = tData.tv_sec;
tMilliseconds = tMilliseconds *1000;
tMilliseconds += tData.tv_usec / 1000;
};
#else
/*
void TimetToFileTime( time_t t, LPFILETIME pft ){
LONGLONG ll = Int32x32To64(t, 10000000) + 116444736000000000;
pft->dwLowDateTime = (DWORD) ll;
pft->dwHighDateTime = ll >>32;
}*/
unsigned __int64 getSHDTimeValue( void ){
unsigned __int64 tMilliseconds;
SYSTEMTIME Ztime;
GetSystemTime(&Ztime);
SystemTimeToFileTime( &Ztime, (FILETIME*) &tMilliseconds );
tMilliseconds -= UNIX_TimeStamp_2_WINDOWS_FileTime_SHIFT;
tMilliseconds = tMilliseconds / 10000;
#endif
tMilliseconds += g_iTimeDiff;
return tMilliseconds;
};
CSTR getSHDTimeStamp( void ){
CSTR RetVal = NULL;
time_t rawtime;
uint32_t msec;
struct tm * ptm = NULL;
time ( &rawtime );
ptm = gmtime ( &rawtime );
msec = getSHDTimeValue() % 1000;
//2019-03-24T12:32:59.670Z
if( ptm != NULL ) {
RetVal = (CSTR) malloc( 128 );
if( RetVal!=NULL ){
sprintf( RetVal, "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ",
(ptm->tm_year+1900),
(ptm->tm_mon+1),
ptm->tm_mday,
ptm->tm_hour,
ptm->tm_min,
ptm->tm_sec,
msec
);
};
};
return RetVal;
};
bool correctSHDTime( int diff ){
#ifdef __linux__
struct timeval tData;
struct timezone tTZ;
tTZ.tz_minuteswest = 0;
tTZ.tz_dsttime = 0;
if( gettimeofday( &tData, &tTZ ) == -1 ){
return false;
} else {
tData.tv_sec += diff / 1000;
tData.tv_usec += ( diff * 1000 ) % 1000000;
};
if( settimeofday( &tData, &tTZ ) == -1 ){
return false;
};
#else
unsigned __int64 tMilliseconds;
SYSTEMTIME Ztime;
GetSystemTime(&Ztime);
SystemTimeToFileTime( &Ztime, (FILETIME*) &tMilliseconds );
tMilliseconds += diff * 10000;
FileTimeToSystemTime( (FILETIME*) &tMilliseconds, &Ztime );
if( 0 == SetSystemTime(&Ztime) ) return false;
#endif
return true;
};