00001
00002
00003
00004 #include <global_msg.h>
00005 #include <time.h>
00006 #include <stdio.h>
00007 #include <string.h>
00008 #include <stdlib.h>
00009
00010
00011
00012 double DTStringToTime( const char * p_datestring )
00013 {
00014 struct tm _timestruct;
00015
00016 time_t _epochtime;
00017
00018 char _wrk[5];
00019
00020 strncpy( _wrk, p_datestring, 4 );
00021 _wrk[4] = '\0';
00022 _timestruct.tm_year = atoi(_wrk) - 1900;
00023
00024 strncpy( _wrk, p_datestring + 4, 2 );
00025 _wrk[2] = '\0';
00026 _timestruct.tm_mon = atoi(_wrk) - 1;
00027
00028 strncpy( _wrk, p_datestring + 6, 2 );
00029 _wrk[2] = '\0';
00030 _timestruct.tm_mday = atoi(_wrk);
00031
00032 strncpy( _wrk, p_datestring + 8, 2 );
00033 _wrk[2] = '\0';
00034 _timestruct.tm_hour = atoi(_wrk);
00035
00036 strncpy( _wrk, p_datestring + 10, 2 );
00037 _wrk[2] = '\0';
00038 _timestruct.tm_min = atoi(_wrk);
00039
00040 strncpy( _wrk, p_datestring + 12, 2 );
00041 _wrk[2] = '\0';
00042 _timestruct.tm_sec = atoi(_wrk);
00043
00044 _timestruct.tm_isdst = -1;
00045
00046 _epochtime = mktime(&_timestruct);
00047
00048
00049 strncpy( _wrk, p_datestring + 15, 3 );
00050 _wrk[3] = '\0';
00051
00052 return (double)_epochtime + atof(_wrk) / 1000.0;
00053 }
00054
00055
00056
00057 int TimeToDTString( const double p_time, char * p_buffer )
00058 {
00059 time_t _ltime = (int)p_time;
00060
00061 struct tm * _tmptr;
00062
00063 if ( p_buffer == NULL )
00064 {
00065 return GLOBAL_MSG_NULL;
00066 }
00067
00068 _tmptr = gmtime( &_ltime );
00069
00070 sprintf( p_buffer
00071 , "%04d%02d%02d%02d%02d%02d.%03d"
00072 , _tmptr->tm_year + 1900
00073 , _tmptr->tm_mon + 1
00074 , _tmptr->tm_mday
00075 , _tmptr->tm_hour
00076 , _tmptr->tm_min
00077 , _tmptr->tm_sec
00078 , ((int)( p_time * 1000 )) % 1000
00079 );
00080
00081 return GLOBAL_MSG_SUCCESS;
00082 }
00083
00084
00085
00086
00087 GLOBAL_MSG_STATUS EncodeAuthor( MSG_LOGO p_logo
00088 , char * r_buffer
00089 )
00090 {
00091 if ( r_buffer == NULL )
00092 {
00093 return GLOBAL_MSG_NULL;
00094 }
00095 sprintf( r_buffer
00096 , "%03u%03u%03u"
00097 , p_logo.type
00098 , p_logo.mod
00099 , p_logo.instid
00100 );
00101
00102 return GLOBAL_MSG_SUCCESS;
00103 }
00104
00105
00106
00107 GLOBAL_MSG_STATUS DecodeAuthor( MSG_LOGO * p_logo
00108 , char * r_buffer
00109 )
00110 {
00111 char _wrk[4];
00112 short _value;
00113
00114 if ( r_buffer == NULL )
00115 {
00116 return GLOBAL_MSG_NULL;
00117 }
00118
00119 if ( strlen( r_buffer ) != 9 )
00120 {
00121 return GLOBAL_MSG_BADPARAM;
00122 }
00123
00124 strncpy( _wrk, r_buffer, 3 );
00125 _wrk[3] = '\0';
00126
00127 if ( (_value = atoi(_wrk)) == 0 )
00128 {
00129 return GLOBAL_MSG_FORMATERROR;
00130 }
00131
00132 p_logo->type = (unsigned char)_value;
00133
00134
00135 strncpy( _wrk, r_buffer + 3, 3 );
00136 _wrk[3] = '\0';
00137
00138 if ( (_value = atoi(_wrk)) == 0 )
00139 {
00140 return GLOBAL_MSG_FORMATERROR;
00141 }
00142
00143 p_logo->mod = (unsigned char)_value;
00144
00145
00146 strncpy( _wrk, r_buffer + 6, 3 );
00147 _wrk[3] = '\0';
00148
00149 if ( (_value = atoi(_wrk)) == 0 )
00150 {
00151 return GLOBAL_MSG_FORMATERROR;
00152 }
00153
00154 p_logo->instid = (unsigned char)_value;
00155
00156 return GLOBAL_MSG_SUCCESS;
00157 }
00158
00159
00160 const char * GetGlobalAmpTypeName( AMPLITUDE_TYPE p_type )
00161 {
00162 if ( p_type < 0 || AMPTYPE_COUNT <= p_type )
00163 {
00164 return AMPLITUDE_NAMES[AMPTYPE_NONE];
00165 }
00166 return AMPLITUDE_NAMES[p_type];
00167 }
00168
00169
00170