| 1 | |
|---|
| 2 | /**************************************************************************** |
|---|
| 3 | * NAME: DMW_SysTime.c |
|---|
| 4 | *---------------------------------------------------------------------------- |
|---|
| 5 | * Copyright (c) 2003 DST Inc. |
|---|
| 6 | *---------------------------------------------------------------------------- |
|---|
| 7 | * CREATED_BY: DIGITAL STREAM Technology Inc. |
|---|
| 8 | * CREATION_DATE: 2003/09/15 |
|---|
| 9 | * AUTHOR: Kyu-hong Park |
|---|
| 10 | * REVISION: Ver 1.001 |
|---|
| 11 | * DATE: |
|---|
| 12 | *---------------------------------------------------------------------------- |
|---|
| 13 | * PURPOSE: |
|---|
| 14 | * - ½Ã½ºÅÛ ½Ã°£°ü·Ã ÇÔ¼ö ¹× ½Ã°£°æ°ú ÃøÁ¤ ÇÔ¼ö ±¸Çö |
|---|
| 15 | *****************************************************************************/ |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | #include "DMW_Platform.h" |
|---|
| 19 | |
|---|
| 20 | #include "DMW_SysTime.h" |
|---|
| 21 | |
|---|
| 22 | //#include <string.h> |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | DHL_MODULE("$stm", 1); |
|---|
| 26 | |
|---|
| 27 | /*------------------------------------------------------------------*/ |
|---|
| 28 | |
|---|
| 29 | #define DONT_USE_C_STD_LIB 1 |
|---|
| 30 | /* |
|---|
| 31 | multi °³¹ß ȯ°æ¿¡¼´Â time() °ú °°Àº stdlib ÇÔ¼ö¸¦ Àý´ë »ç¿ëÇÏ¸é ¾ÈµÈ´Ù. |
|---|
| 32 | */ |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | /*_____ D E F I N I T I O N ________________________________________________*/ |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | #define DEF_TIME_OFFSET 630687600 /* 2000³â 1¿ù1ÀÏ Çѱ¹¿¡¼ÀÇ UTC.. */ |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | /* ¸ðµç API¿¡ »ç¿ëµÇ´Â SysTimeContext¸¦ ÁöÁ¤ÇÏÁö ¾Ê¾ÒÀ»¶§ |
|---|
| 42 | °øÅëÀ¸·Î »ç¿ëµÇ´Â µðÆúÆ® contextÀÌ´Ù. |
|---|
| 43 | */ |
|---|
| 44 | |
|---|
| 45 | SysTimeContext g_DefaultSysTimeContext = |
|---|
| 46 | { |
|---|
| 47 | 0, /* BOOL bTimebaseAdjusted */ |
|---|
| 48 | DEF_TIME_OFFSET, /* int nTimeSystemBase */ |
|---|
| 49 | |
|---|
| 50 | 9, /* int nTimeZone; */ |
|---|
| 51 | 0, /* BOOL bDaylightSavingOn; */ /* 1: use daylight saving , 0: not use daylight saving */ |
|---|
| 52 | |
|---|
| 53 | 13, /* int GPS_UTC_offset; */ |
|---|
| 54 | |
|---|
| 55 | }; |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | /*----------------------------- |
|---|
| 59 | for debugging and testing.. |
|---|
| 60 | */ |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | const char *DayOfWeekString(int n) |
|---|
| 64 | { |
|---|
| 65 | /* n: [0 ~ 6] */ |
|---|
| 66 | char *name[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", }; |
|---|
| 67 | static char err[12]; |
|---|
| 68 | if (n < 0 || n > 6) { |
|---|
| 69 | sprintf(err, "?(%d)", n); |
|---|
| 70 | return err; |
|---|
| 71 | } |
|---|
| 72 | return name[n]; |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | const char *STimeString(STime_t *s, char *buf) |
|---|
| 76 | { |
|---|
| 77 | static char _buf[64]; |
|---|
| 78 | |
|---|
| 79 | if (buf == NULL) buf = _buf; |
|---|
| 80 | |
|---|
| 81 | sprintf(buf, "%d/%d/%d %s %d:%02d:%02d", |
|---|
| 82 | s->year, s->month, s->day, DayOfWeakString(s->wday), s->hour, s->min, s->sec); |
|---|
| 83 | |
|---|
| 84 | return buf; |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | /* |
|---|
| 89 | http://www.leapsecond.com/java/gpsclock.htm |
|---|
| 90 | |
|---|
| 91 | Local time is the date/time reported by your PC (as seen by your web browser). |
|---|
| 92 | If your PC clock is accurate to a second then the other time scales displayed |
|---|
| 93 | above will also be accurate to within one second. |
|---|
| 94 | |
|---|
| 95 | UTC, Coordinated Universal Time, popularly known as GMT (Greenwich Mean Time), |
|---|
| 96 | or Zulu time. Local time differs from UTC by the number of hours of your |
|---|
| 97 | timezone. |
|---|
| 98 | |
|---|
| 99 | GPS, Global Positioning System time, is the atomic time scale implemented by |
|---|
| 100 | the atomic clocks in the GPS ground control stations and the GPS satellites |
|---|
| 101 | themselves. GPS time was zero at 0h 6-Jan-1980 and since it is not perturbed |
|---|
| 102 | by leap seconds GPS is now ahead of UTC by 13 seconds. |
|---|
| 103 | */ |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | #if COMMENT |
|---|
| 108 | ____UTC_Core_____(){} |
|---|
| 109 | #endif |
|---|
| 110 | |
|---|
| 111 | /*====================================================================== |
|---|
| 112 | // ANSI Ç¥ÁØ ÇÔ¼öÀÎ time()Àº ¹®¼»ó UTC timeÀ» ¸®ÅÏÇÏ´Â °ÍÀ¸·Î µÇ¾î ÀÖ´Ù |
|---|
| 113 | // ---- |
|---|
| 114 | // The time function returns the number of seconds elapsed since midnight (00:00:00), |
|---|
| 115 | // January 1, 1970, coordinated universal time, according to the system clock |
|---|
| 116 | // ---- |
|---|
| 117 | // ±×·¯³ª Ç÷§Æû »ó¿¡ RTC°¡ ¾ø±â ¶§¹®¿¡ Àý´ëÀûÀÎ °ªÀº Á¤È®ÇÏÁö ¾Ê´Ù. |
|---|
| 118 | // ±×·¡¼ time()¿¡¼ ¸®ÅϵǴ °ª°úÀÇ Â÷À̸¦ ±â¾ïÇÏ¿© °ªÀ» º¸Á¤ÇÔÀ¸·Î½á |
|---|
| 119 | // Set/Get time ÇÔ¼ö¸¦ ±¸ÇöÇÑ´Ù. |
|---|
| 120 | // |
|---|
| 121 | // Á¤ÀÇ: |
|---|
| 122 | // UTC time = time() + timeSystemBase |
|---|
| 123 | // |
|---|
| 124 | // timeSystemBase = UTC_time_to_set - time() |
|---|
| 125 | // |
|---|
| 126 | // Âü°í |
|---|
| 127 | // ½Ã½ºÅÛ¿¡ RTC°¡ ¾øÀ¸¹Ç·Î ºÎÆÃÈÄ ÃÖÃÊ 1ȸ SetUTCTime()À» ºÒ·¯¼ ½Ã°£º¸Á¤À» |
|---|
| 128 | // ÇØ Áà¾ß¸¸ ÇÑ´Ù. |
|---|
| 129 | // |
|---|
| 130 | */ |
|---|
| 131 | /**************************************************************************** |
|---|
| 132 | Function Name: |
|---|
| 133 | DMW_SetUTCTime |
|---|
| 134 | |
|---|
| 135 | Description: |
|---|
| 136 | UTC Time À¸·Î ½Ã½ºÅÛ ½Ã°£ ¼³Á¤ |
|---|
| 137 | |
|---|
| 138 | Note: |
|---|
| 139 | ½Ã½ºÅÛ ½Ã°£À» º¯°æ°¡´ÉÇÒ ½Ã¿¡´Â ÀÌ ÇÔ¼ö¸¦ ¼öÁ¤ ÇÊ¿ä! |
|---|
| 140 | *****************************************************************************/ |
|---|
| 141 | void DMW_SetUTCTime(SysTimeContext *stc, UINT32 utc) |
|---|
| 142 | { |
|---|
| 143 | if (stc == NULL) stc = &g_DefaultSysTimeContext; |
|---|
| 144 | |
|---|
| 145 | stc->tickTimeAdjusted = DHL_OS_GetMsCount(); |
|---|
| 146 | stc->nTimeSystemBase = utc; |
|---|
| 147 | |
|---|
| 148 | stc->bTimebaseAdjusted = TRUE; |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 151 | |
|---|
| 152 | /**************************************************************************** |
|---|
| 153 | Function Name: |
|---|
| 154 | DMW_GetUTCTime |
|---|
| 155 | |
|---|
| 156 | Description: |
|---|
| 157 | UTC Time ¾ò¾î¿Å |
|---|
| 158 | DMW_SetUTCTime ÀÌ Çѹøµµ È£ÃâµÇÁö ¾Ê¾Ò´Ù¸é À߸øµÈ °ªÀÌ ¸®Å쵃 °ÍÀÌ´Ù. |
|---|
| 159 | |
|---|
| 160 | Note: |
|---|
| 161 | |
|---|
| 162 | *****************************************************************************/ |
|---|
| 163 | STATUS DMW_GetUTCTime(SysTimeContext *stc, UINT32 *utc) |
|---|
| 164 | { |
|---|
| 165 | long int now; |
|---|
| 166 | |
|---|
| 167 | if (stc == NULL) stc = &g_DefaultSysTimeContext; |
|---|
| 168 | |
|---|
| 169 | if (stc->bTimebaseAdjusted == FALSE) { |
|---|
| 170 | if (utc) *utc = 0; |
|---|
| 171 | dprint(0, "!! GetUTCTime: time not initialized\n"); |
|---|
| 172 | |
|---|
| 173 | /* cafrii 050315 add |
|---|
| 174 | // Çѹøµµ ÃʱâÈ (set time)¸¦ ÇÏÁö ¾ÊÀº »óÅ¿¡¼ get timeÀÌ ºÒ¸° °æ¿ìÀÌ´Ù. |
|---|
| 175 | // ¿øÄ¢ÀûÀ¸·Î´Â ¿¡·¯ °ªÀ» ¸®ÅÏÇϰí, caller´Â ÀÌ ¸®ÅϰªÀ» Ç×»ó Ã¼Å©ÇØ¾ß ÇÑ´Ù. |
|---|
| 176 | // ±×·±µ¥ application ¿¡¼ ±×³É °£´ÜÇÏ°Ô set time Çϱâ Àü±îÁö´Â |
|---|
| 177 | // time contextÀÇ µðÆúÆ® °ªÀ» »ç¿ëÇϱ⸦ ¿øÇÏ¸ç ¸®Åϰª ¿¡·¯ üũµµ Àß ÇÏÁö ¾Ê´Â °æ¿ì°¡ ¸¹´Ù. |
|---|
| 178 | // context¿¡ µðÆúÆ® utc timeÀ» ¼³Á¤ÇØ ³õ¾Ò±â ¶§¹®¿¡ ÀÌ °ªÀ» »ç¿ëÇÒ ¼öµµ ÀÖÀ» °Í °°´Ù. |
|---|
| 179 | // |
|---|
| 180 | // ¸®ÅϰªÀº ¿¡·¯·Î ¸®ÅÏÇÏÁö¸¸, utc °ªÀº ´ë·« ºñ½ÁÇÏ°Ô ¼³Á¤Çؼ µ¹·ÁÁÖµµ·Ï ÇÑ´Ù. |
|---|
| 181 | // time(0) Àº ºÎÆÃ ÀÌÈÄ °æ°úµÈ ½Ã°£ (ÃÊ) À̹ǷΠÀÌ °ªÀ» ´õÇØ¼ ¸®ÅÏÇÏÀÚ. |
|---|
| 182 | */ |
|---|
| 183 | |
|---|
| 184 | if (utc) |
|---|
| 185 | *utc = (DHL_OS_GetMsCount()-0)/1000 + stc->nTimeSystemBase; |
|---|
| 186 | |
|---|
| 187 | |
|---|
| 188 | return statusError; /* time not initialized.. */ |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| 191 | |
|---|
| 192 | /* ¸¶Áö¸·À¸·Î SetUTC ÇÑ ÀÌÈÄÀÇ °æ°ú ½Ã°£À» ÀÌ¿ë. */ |
|---|
| 193 | now = stc->nTimeSystemBase + |
|---|
| 194 | (DHL_OS_GetMsCount()-stc->tickTimeAdjusted)/1000; |
|---|
| 195 | |
|---|
| 196 | if (utc) *utc = now; |
|---|
| 197 | |
|---|
| 198 | return statusOK; |
|---|
| 199 | } |
|---|
| 200 | |
|---|
| 201 | |
|---|
| 202 | #if COMMENT |
|---|
| 203 | ____UTC_Conversion_____(){} |
|---|
| 204 | #endif |
|---|
| 205 | |
|---|
| 206 | /**************************************************************************** |
|---|
| 207 | Function Name: |
|---|
| 208 | DMW_ConvertLocalTime2UTC |
|---|
| 209 | |
|---|
| 210 | Description: |
|---|
| 211 | Local TimeÀ» UTC·Î º¯°æÇÔ. |
|---|
| 212 | º¯È¯¿¡´Â ¿©·¯°¡Áö parameter°¡ ÇÊ¿äÇÏ´Ù. (time_zone, µî) |
|---|
| 213 | ex: |
|---|
| 214 | 2004³â 6¿ù 15ÀÏ --> 0x........ |
|---|
| 215 | Note: |
|---|
| 216 | STime_t::wday °ªÀº »ç¿ëµÇÁö ¾Ê´Â´Ù. |
|---|
| 217 | |
|---|
| 218 | °è»ê ¹æ½Ä: |
|---|
| 219 | ¸ÕÀú 1980³â 1¿ù 1ÀÏ 0½Ã ÀÌÈÄ·Î ¸îÃʰ¡ µÇ´ÂÁö °è»êÀ» Çϰí, |
|---|
| 220 | daylight saving °í·ÁÇÏ¿© 3600Ãʸ¦ º¸Á¤Çϰí, |
|---|
| 221 | timezone °í·ÁÇÏ¿© n*3600 Ãʸ¦ º¸Á¤, |
|---|
| 222 | ±×¸®°í ³ª¼ 1980³â 1¿ù 6ÀÏ |
|---|
| 223 | |
|---|
| 224 | cafrii 081008, consider daylight savings. |
|---|
| 225 | |
|---|
| 226 | *****************************************************************************/ |
|---|
| 227 | UINT32 DMW_ConvertLocalTime2UTC(SysTimeContext *stc, STime_t *s) |
|---|
| 228 | { |
|---|
| 229 | UINT32 utc=0; |
|---|
| 230 | int leap; |
|---|
| 231 | UINT32 i, tmp; |
|---|
| 232 | char *msg1; |
|---|
| 233 | |
|---|
| 234 | BOOL bEffectiveDS = FALSE; |
|---|
| 235 | |
|---|
| 236 | UINT32 daytab[2][13] = { |
|---|
| 237 | {365, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, |
|---|
| 238 | {366, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} |
|---|
| 239 | }; |
|---|
| 240 | |
|---|
| 241 | if (stc == NULL) stc = &g_DefaultSysTimeContext; |
|---|
| 242 | |
|---|
| 243 | /* exception handling by hschang, 2004/1/18 */ |
|---|
| 244 | if(s->year<1980 || s->month<1 || s->day<1) { |
|---|
| 245 | dprint(0, "!! ConvertLocalTime2UTC: invalid time, set to 0\n"); |
|---|
| 246 | utc = 0; /* 1980/1/6 00:00:00 */ |
|---|
| 247 | return utc; |
|---|
| 248 | } |
|---|
| 249 | |
|---|
| 250 | if (stc->bDaylightSavingOn) |
|---|
| 251 | { |
|---|
| 252 | bEffectiveDS = stc->DS_status; |
|---|
| 253 | |
|---|
| 254 | if (stc->DS_day_of_month && |
|---|
| 255 | stc->DS_day_of_month == s->day && /* we only consider matched date. */ |
|---|
| 256 | stc->DS_hour <= s->hour) |
|---|
| 257 | { |
|---|
| 258 | bEffectiveDS = bEffectiveDS ? 0 : 1; |
|---|
| 259 | } |
|---|
| 260 | } |
|---|
| 261 | |
|---|
| 262 | tmp = s->year - 1980; /* ´©Àû °è»êÇØ¾ß ÇÒ ¿¬µµ ¼ö */ |
|---|
| 263 | |
|---|
| 264 | for(i=s->year-1; i>=1980; i--) /* ºñ±³°è»ê½Ã ¾à°£ÀÇ È¿À² Áõ´ë¸¦ À§Çؼ °Å²Ù·Î ¼À.. */ |
|---|
| 265 | { |
|---|
| 266 | leap = ((i%4==0)&&(i%100!=0)) || (i%400==0); |
|---|
| 267 | utc += daytab[leap][0]*86400; |
|---|
| 268 | } |
|---|
| 269 | |
|---|
| 270 | leap = (((s->year)%4==0)&&((s->year)%100!=0)) || ((s->year)%400==0); |
|---|
| 271 | tmp = s->month - 1; |
|---|
| 272 | |
|---|
| 273 | for(i=1; i<(tmp+1); i++) |
|---|
| 274 | utc += daytab[leap][i]*86400; |
|---|
| 275 | |
|---|
| 276 | /* ¿ì¸®°¡ ¿øÇÏ´Â ´Þ·Â³¯Â¥ ÀÌ»óÀÇ °ªÀÌ ¿Ã ¼öµµ ÀÖ´Ù. ÀÌÀ¯´Â host¿¡¼ ´Þ·ÂÀ» °¡Áö°í ÀÖÁö ¾ÊÀ¸¹Ç·Î |
|---|
| 277 | // ³¯Â¥¿¡ ´ëÇÑ exception handling (28, 29,30,31º¸´Ù Å«°Í)Àº ÇÏÁö ¸»¾Æ¾ß ÇÑ´Ù. |
|---|
| 278 | // ÇÏÁö¸¸, 0¿¡ ´ëÇÑ exception handlingÀº ¾Õ¿¡¼ ¹Ì¸® ÇÏ¿©¾ß ÇÒ °Í °°´Ù. -hschang- |
|---|
| 279 | */ |
|---|
| 280 | tmp = s->day - 1; |
|---|
| 281 | utc += 86400*tmp; |
|---|
| 282 | utc += s->hour*3600; |
|---|
| 283 | utc += s->min*60; |
|---|
| 284 | utc += s->sec; |
|---|
| 285 | |
|---|
| 286 | /* daylightsaving°ú, timezone º¸Á¤ÇÏ¸é¼ utc °¡ À½ÀÇ °ªÀ¸·Î ³»·Á°¡Áö ¾Êµµ·Ï °¢º°È÷ ÁÖÀÇÇ϶ó!! |
|---|
| 287 | */ |
|---|
| 288 | msg1 = "!! before 1980/1/6 !! reset to 0\n"; |
|---|
| 289 | if (bEffectiveDS) { |
|---|
| 290 | if (utc < 3600) { |
|---|
| 291 | dprint(0, msg1); |
|---|
| 292 | return 0; |
|---|
| 293 | } |
|---|
| 294 | utc -= 3600; |
|---|
| 295 | } |
|---|
| 296 | |
|---|
| 297 | /* cafrii 041005 bugfix |
|---|
| 298 | // timezoneÀÇ °ªÀÌ À½ÀÇ °ªÀÏ ¼ö ÀÖÀ¸¹Ç·Î utc¿Í Á÷Á¢ ºñ±³ÇÏ´Â °ÍÀº ¹®Á¦°¡ µÈ´Ù. |
|---|
| 299 | // ¾ÆÁ÷ 1¿ù1ÀϺÎÅÍ 1¿ù6ÀϱîÁöÀÇ 5ÀÏ °£ÀÇ ¿©À¯ºÐÀÌ ÀÖÀ¸¹Ç·Î ÃÖ´ë +12½Ã°£±îÁö´Â ¹®Á¦ ¾øÀ¸¹Ç·Î |
|---|
| 300 | // ¹Ù·Î '»¬¼À'À» ÇØµµ µÈ´Ù. |
|---|
| 301 | */ |
|---|
| 302 | utc -= stc->nTimeZone*3600; |
|---|
| 303 | |
|---|
| 304 | if (utc < 432000) { /* 1980/1/6 ÀÌÀüÀÇ ½Ã°£ÀÌ´Ù.. ¿¡·¯.. */ |
|---|
| 305 | dprint(0, msg1); |
|---|
| 306 | return 0; |
|---|
| 307 | } |
|---|
| 308 | else { |
|---|
| 309 | utc -= 432000; |
|---|
| 310 | } |
|---|
| 311 | |
|---|
| 312 | return utc; |
|---|
| 313 | } |
|---|
| 314 | |
|---|
| 315 | /**************************************************************************** |
|---|
| 316 | Function Name: |
|---|
| 317 | DMW_ConvertUTC2LocalTime |
|---|
| 318 | |
|---|
| 319 | Description: |
|---|
| 320 | UTC¸¦ Local TimeÀ¸·Î º¯°æÇÔ. |
|---|
| 321 | |
|---|
| 322 | Note: |
|---|
| 323 | |
|---|
| 324 | *****************************************************************************/ |
|---|
| 325 | void DMW_ConvertUTC2LocalTime(SysTimeContext *stc, UINT32 utc_in, STime_t *t) |
|---|
| 326 | { |
|---|
| 327 | STime_t s; |
|---|
| 328 | UINT32 utc = utc_in; |
|---|
| 329 | |
|---|
| 330 | UINT32 daytab[2][13] = { |
|---|
| 331 | {365, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, |
|---|
| 332 | {366, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} |
|---|
| 333 | }; |
|---|
| 334 | int acc_day; |
|---|
| 335 | int i, leap; |
|---|
| 336 | |
|---|
| 337 | if (stc == NULL) stc = &g_DefaultSysTimeContext; |
|---|
| 338 | |
|---|
| 339 | /* timezone ¼³Á¤¿¡ µû¸¥ º¸Á¤À» ÇÑ´Ù. */ |
|---|
| 340 | utc += (stc->nTimeZone * 3600); |
|---|
| 341 | |
|---|
| 342 | /* daylight saving¿¡ µû¸¥ º¸Á¤À» ÇÑ´Ù. */ |
|---|
| 343 | |
|---|
| 344 | /* note: |
|---|
| 345 | À̰÷¿¡´Â trickÀÌ ÀÖ´Ù. |
|---|
| 346 | DS_status°¡ 1À̶ó°í ÇÏ´õ¶óµµ month, day°¡ ÀÏÄ¡ÇÏ¸é µ¿ÀÛ¿©ºÎ°¡ ¹Ý´ë·Î µÇ¾î¾ß ÇÑ´Ù. |
|---|
| 347 | ÇÏÁö¸¸ ½Ã°£ °è»êÀÌ ¿Ï·áµÇ±â Àü±îÁö´Â month, day ÀÏÄ¡ ¿©ºÎ¸¦ ¾Ë ¼ö ¾ø´Ù. |
|---|
| 348 | |
|---|
| 349 | Áï, ½Ã°£ °è»êÀ» ÇÏ·Á¸é daylight saving µ¿ÀÛ ¿©ºÎ°¡ °áÁ¤µÇ¾î¾ß Çϰí, |
|---|
| 350 | µ¿ÀÛ ¿©ºÎ¸¦ °áÁ¤ÇÏ·Á¸é month, dayÀ» ¾Ë¾Æ¾ß ÇÏ´Â chicken & egg ¹®Á¦ÀÌ´Ù. |
|---|
| 351 | |
|---|
| 352 | ÇØ¹ýÀº, ¸ÕÀú month, day ÀÏÄ¡ ¿©ºÎ´Â ½Å°æ¾²Áö ¸»°í DS_status ¸¸À¸·Î °è»êÀ» Çϰí, |
|---|
| 353 | °è»êÈÄ¿¡ month, day°¡ ÀÏÄ¡ÇÏ°Ô µÇ¸é ´Ù½Ã DS_status¸¦ ¹Ù²Ù¾î¼ Çѹø ´õ °è»êÀ» ÇÑ´Ù. |
|---|
| 354 | |
|---|
| 355 | ¾î¶°ÇÑ °æ¿ì¿¡¶óµµ bDaylightSavingOn °¡ falseÀ̸é daylight savingÀº °áÄÚ µ¿ÀÛÇÏÁö ¾Ê´Â´Ù. |
|---|
| 356 | */ |
|---|
| 357 | if (stc->bDaylightSavingOn && stc->DS_status) { |
|---|
| 358 | utc += 3600; |
|---|
| 359 | stc->bDaylightSavingActive = TRUE; |
|---|
| 360 | } |
|---|
| 361 | else |
|---|
| 362 | stc->bDaylightSavingActive = FALSE; |
|---|
| 363 | |
|---|
| 364 | |
|---|
| 365 | |
|---|
| 366 | #if 1 |
|---|
| 367 | /* 1980/1/1 ºÎÅÍ UTCÀÇ ±âÁØÀÎ 1980/1/6 ±îÁöÀÇ ½Ã°£À» ´õÇÑ ´ÙÀ½ |
|---|
| 368 | // 1980³â ºÎÅÍ °è»êÇØ ³ª°¡¸é ÆíÇÏ´Ù. ±×·¯¸é UINT32 wrap-around·Î ÀÎÇÑ ¹ö±×¸¦ ÇÇÇÒ¼ö ÀÖ´Ù. |
|---|
| 369 | */ |
|---|
| 370 | utc += 432000; /* 5Àϰ£ÀÇ ÃÊ */ |
|---|
| 371 | acc_day = -5; |
|---|
| 372 | s.year = 1980; |
|---|
| 373 | s.month = 1; |
|---|
| 374 | s.day = 1; |
|---|
| 375 | s.wday = 2; /* Tuesday: 1980³â 1¿ù 1ÀÏÀº È¿äÀÏ */ |
|---|
| 376 | s.hour = 0; |
|---|
| 377 | s.min = 0; |
|---|
| 378 | s.sec = 0; |
|---|
| 379 | leap = 1; /* 1980³âÀº 4ÀÇ ¹è¼öÀ̹ǷΠÀ±³â.. */ |
|---|
| 380 | #else |
|---|
| 381 | |
|---|
| 382 | /* ÀÌ ¹æ½ÄÀº 1981³â 1¿ù 1ÀÏ 0½Ã¸¦ ±âÁØÀ¸·Î °è»êÇϹǷΠ1980³â 1¿ù 6ÀÏ ºÎÅÍ |
|---|
| 383 | // 1980³â 12¿ù ¸» ±îÁöÀÇ ±¸°£ µ¿¾È¿¡´Â UTC ½Ã°£ º¯È¯À» ¸øÇÏ´Â °áÁ¤ÀûÀÎ ´ÜÁ¡ÀÌ ÀÖ´Ù. |
|---|
| 384 | // »ç¿ëÇÏÁö ¸»µµ·Ï ÇÏÀÚ. |
|---|
| 385 | */ |
|---|
| 386 | if (utc < 31190400) |
|---|
| 387 | dprint(0, "!! utc before 1981/1/1 cannot be used!!\n"); |
|---|
| 388 | |
|---|
| 389 | acc_day=361; |
|---|
| 390 | s.year = 1981; /* 1981/1/1 0:0:0 ¿¡¼ºÎÅÍ °è»êÇØ ³ª°£´Ù */ |
|---|
| 391 | s.month = 1; |
|---|
| 392 | s.day = 1; |
|---|
| 393 | s.wday = 4; /* Thurday */ |
|---|
| 394 | s.hour = 0; |
|---|
| 395 | s.min = 0; |
|---|
| 396 | s.sec = 0; |
|---|
| 397 | utc -= 31190400; /* 1980.1.6~1980.12.31±îÁöÀÇ ÃÊ. */ |
|---|
| 398 | leap = 0; |
|---|
| 399 | #endif |
|---|
| 400 | |
|---|
| 401 | /*while ((stime/(daytab[leap][0]*86400))>0) */ |
|---|
| 402 | |
|---|
| 403 | /* year¸¦ °è»ê */ |
|---|
| 404 | while (utc >= (daytab[leap][0]*86400)) |
|---|
| 405 | { |
|---|
| 406 | utc -= daytab[leap][0]*86400; |
|---|
| 407 | acc_day += daytab[leap][0]; |
|---|
| 408 | s.year ++; |
|---|
| 409 | leap = ((s.year%4==0)&&(s.year%100!=0))||(s.year%400==0); |
|---|
| 410 | } |
|---|
| 411 | |
|---|
| 412 | /* month¸¦ °è»ê */ |
|---|
| 413 | i=1; |
|---|
| 414 | while (utc >= (daytab[leap][i]*86400)) |
|---|
| 415 | { |
|---|
| 416 | utc -= daytab[leap][i]*86400; |
|---|
| 417 | acc_day += daytab[leap][i]; |
|---|
| 418 | s.month ++; |
|---|
| 419 | i++; |
|---|
| 420 | } |
|---|
| 421 | |
|---|
| 422 | s.day += (utc/86400); |
|---|
| 423 | acc_day += (utc/86400); |
|---|
| 424 | utc = utc%86400; |
|---|
| 425 | |
|---|
| 426 | /* s.wday = acc_day%7; */ |
|---|
| 427 | s.wday = (acc_day + 7) % 7; |
|---|
| 428 | /* |
|---|
| 429 | // cafrii 050315 fix |
|---|
| 430 | // acc_dayÀÇ ÃʱⰪÀÌ -5 ºÎÅÍ ½ÃÀÛÇÏ¿© accumulated µÇ¾úÀ¸¹Ç·Î |
|---|
| 431 | // ¾ÆÁ÷ 0 ÀÌÇÏÀÇ °ªÀ¸·Î ³²¾Æ ÀÖÀ» ¼öµµ ÀÖ´Ù. (¹°·Ð À߸øµÈ utc °ªÀÎ °æ¿ìÀÓ) |
|---|
| 432 | // ±×·¡µµ wday¸¦ Á¤È®ÇÏ°Ô ¸®ÅÏÇÒ ¼ö ÀÖµµ·Ï Á¶Á¤À» ÇØÁÖÀÚ. |
|---|
| 433 | */ |
|---|
| 434 | |
|---|
| 435 | s.hour = (utc/3600); |
|---|
| 436 | |
|---|
| 437 | /* cafrii 081008 add. |
|---|
| 438 | // because day and hour is calculated, we can check daylight saving again. |
|---|
| 439 | */ |
|---|
| 440 | if (stc->bDaylightSavingOn && |
|---|
| 441 | stc->DS_day_of_month && |
|---|
| 442 | stc->DS_day_of_month == s.day && |
|---|
| 443 | stc->DS_hour <= s.hour) |
|---|
| 444 | { |
|---|
| 445 | /* ÀÌ ÄÚµå´Â ÀÏÁ¾ÀÇ trickÀÌ´Ù. |
|---|
| 446 | local timeÀ» °è»ê ÇØ º» °á°ú, DS in/out Á¶°Ç¿¡ ºÎÇյǾúÀ¸¹Ç·Î |
|---|
| 447 | ½ÇÁ¦·Î´Â daylight saving µ¿ÀÛ ¿©ºÎ°¡ ¹Ý´ë°¡ µÇ¾î¾ß ÇÑ´Ù. |
|---|
| 448 | ¿¹¸¦ µé¸é, |
|---|
| 449 | DS_status°¡ 0(µ¿ÀÛ¾ÈÇÔ)À̾úÁö¸¸ day¿Í month°¡ ÀÏÄ¡Çϸé DS°¡ µ¿ÀÛÇØ¾ß Çϰí, |
|---|
| 450 | DS_status°¡ 1(µ¿ÀÛ)À̾úÁö¸¸ day¿Í month°¡ ÀÏÄ¡Çϸé DS°¡ µ¿ÀÛÇÏ¸é ¾ÈµÈ´Ù. |
|---|
| 451 | |
|---|
| 452 | ´Ù½Ã °è»êÇØ¾ß ÇÏ´Â ºÒÆíÇÔÀÌ Àִµ¥, Àç±ÍÈ£ÃâÀ» »ç¿ëÇÏ¿© ½±°Ô ÇØ°á °¡´ÉÇÏ´Ù. |
|---|
| 453 | ´Ü ¿ø·¡ »ç¿ëÁßÀÎ stc´Â °Çµå¸®¸é ¾ÈµÇ°í, cloneÀ» Çϳª ¸¸µé¾î¾ß ÇÑ´Ù. |
|---|
| 454 | */ |
|---|
| 455 | SysTimeContext stc_clone = *stc; |
|---|
| 456 | |
|---|
| 457 | /* consider daylight saving in/out condition. |
|---|
| 458 | // re-calculate with modified parameter. |
|---|
| 459 | */ |
|---|
| 460 | stc_clone.DS_status = stc->DS_status ? 0 : 1; |
|---|
| 461 | stc_clone.DS_day_of_month = 0; /* so as not to re-consider again. */ |
|---|
| 462 | /* TIP: DS_day_of_month 󸮸¦ ¾ÈÇØÁÖ¸é ¹«ÇÑ ·çÇÁ¿¡ µé¾î°¥ ¼ö ÀÖ´Ù. ÁÖÀÇ.. */ |
|---|
| 463 | |
|---|
| 464 | DMW_ConvertUTC2LocalTime(&stc_clone, utc_in, t); |
|---|
| 465 | |
|---|
| 466 | /* ½ÇÁ¦·Î daylight savingÀÇ µ¿ÀÛ ¿©ºÎ flag¸¦ °»½Å. */ |
|---|
| 467 | stc->bDaylightSavingActive = stc_clone.DS_status; |
|---|
| 468 | |
|---|
| 469 | return; |
|---|
| 470 | } |
|---|
| 471 | |
|---|
| 472 | utc = utc%3600; |
|---|
| 473 | |
|---|
| 474 | s.min = (utc/60); |
|---|
| 475 | s.sec = utc%60; |
|---|
| 476 | |
|---|
| 477 | if (t) *t = s; |
|---|
| 478 | } |
|---|
| 479 | |
|---|
| 480 | /**************************************************************************** |
|---|
| 481 | Function Name: |
|---|
| 482 | DMW_SetLocalTime |
|---|
| 483 | |
|---|
| 484 | Description: |
|---|
| 485 | Local Time À¸·Î ½Ã½ºÅÛ ½Ã°£ ¼³Á¤ |
|---|
| 486 | |
|---|
| 487 | Note: |
|---|
| 488 | ½Ã½ºÅÛ ½Ã°£À» º¯°æ°¡´ÉÇÒ ½Ã¿¡´Â ÀÌ ÇÔ¼ö¸¦ ¼öÁ¤ ÇÊ¿ä! |
|---|
| 489 | *****************************************************************************/ |
|---|
| 490 | |
|---|
| 491 | void DMW_SetLocalTime(SysTimeContext *stc, STime_t *t) |
|---|
| 492 | { |
|---|
| 493 | UINT32 utc; |
|---|
| 494 | STime_t t2; |
|---|
| 495 | |
|---|
| 496 | utc = DMW_ConvertLocalTime2UTC(stc, t); |
|---|
| 497 | |
|---|
| 498 | DMW_SetUTCTime(stc, utc); |
|---|
| 499 | |
|---|
| 500 | /* verifying.. */ |
|---|
| 501 | DMW_ConvertUTC2LocalTime(stc, utc, &t2); |
|---|
| 502 | |
|---|
| 503 | if (t->wday != t2.wday) { |
|---|
| 504 | /* dprint(2, "SetLocalTime: original wday %d wrong. correct it to %d\n", t->wday, t2.wday); */ |
|---|
| 505 | t->wday = t2.wday; /* wday is newly calculated.. so we copy it! */ |
|---|
| 506 | } |
|---|
| 507 | |
|---|
| 508 | if (memcmp(t, &t2, sizeof(STime_t))) { |
|---|
| 509 | char c1[50], c2[50]; |
|---|
| 510 | dprint(0, "!! conversion err!! %s, %s\n", STimeString(t, c1), STimeString(&t2, c2)); |
|---|
| 511 | } |
|---|
| 512 | } |
|---|
| 513 | |
|---|
| 514 | void DMW_SetLocalTime2(SysTimeContext *stc, int year, int month, int day, int hour, int min, int sec) |
|---|
| 515 | { |
|---|
| 516 | STime_t system_time; |
|---|
| 517 | |
|---|
| 518 | system_time.year = year; |
|---|
| 519 | system_time.month = month; |
|---|
| 520 | system_time.day = day; |
|---|
| 521 | system_time.hour = hour; |
|---|
| 522 | system_time.min = min; |
|---|
| 523 | system_time.sec = sec; |
|---|
| 524 | |
|---|
| 525 | DMW_SetLocalTime(stc, &system_time); |
|---|
| 526 | } |
|---|
| 527 | |
|---|
| 528 | |
|---|
| 529 | /**************************************************************************** |
|---|
| 530 | Function Name: |
|---|
| 531 | DMW_GetLocalTime |
|---|
| 532 | |
|---|
| 533 | Description: |
|---|
| 534 | Local Time ½Ã°¢À» °¡Á®¿È. |
|---|
| 535 | |
|---|
| 536 | Note: |
|---|
| 537 | |
|---|
| 538 | *****************************************************************************/ |
|---|
| 539 | int DMW_GetLocalTime(SysTimeContext *stc, STime_t *sys_time) |
|---|
| 540 | { |
|---|
| 541 | UINT32 utc; |
|---|
| 542 | int err; |
|---|
| 543 | |
|---|
| 544 | if (stc == NULL) stc = &g_DefaultSysTimeContext; |
|---|
| 545 | |
|---|
| 546 | err = DMW_GetUTCTime(stc, &utc); |
|---|
| 547 | |
|---|
| 548 | DMW_ConvertUTC2LocalTime(stc, utc, sys_time); |
|---|
| 549 | |
|---|
| 550 | return err; |
|---|
| 551 | } |
|---|
| 552 | |
|---|
| 553 | |
|---|
| 554 | /**************************************************************************** |
|---|
| 555 | Function Name: |
|---|
| 556 | DMW_ConvertUTC2GPS |
|---|
| 557 | |
|---|
| 558 | Description: |
|---|
| 559 | UTC¸¦ GPS·Î º¯°æÇÔ. |
|---|
| 560 | |
|---|
| 561 | Note: |
|---|
| 562 | |
|---|
| 563 | *****************************************************************************/ |
|---|
| 564 | UINT32 DMW_ConvertUTC2GPS(SysTimeContext *stc, UINT32 UTC) |
|---|
| 565 | { |
|---|
| 566 | if (stc == NULL) stc = &g_DefaultSysTimeContext; |
|---|
| 567 | return (UTC + (UINT32)stc->GPS_UTC_offset); |
|---|
| 568 | } |
|---|
| 569 | |
|---|
| 570 | /**************************************************************************** |
|---|
| 571 | Function Name: |
|---|
| 572 | DMW_ConvertGPS2UTC |
|---|
| 573 | |
|---|
| 574 | Description: |
|---|
| 575 | GPS¸¦ UTC·Î º¯°æÇÔ. |
|---|
| 576 | |
|---|
| 577 | Note: |
|---|
| 578 | |
|---|
| 579 | *****************************************************************************/ |
|---|
| 580 | UINT32 DMW_ConvertGPS2UTC(SysTimeContext *stc, UINT32 GPS) |
|---|
| 581 | { |
|---|
| 582 | if (stc == NULL) stc = &g_DefaultSysTimeContext; |
|---|
| 583 | |
|---|
| 584 | if (GPS < (UINT32)(stc->GPS_UTC_offset)) { /* cafriii 040617 add */ /*ARZHNA, 090618, (UINT32)Ãß°¡ */ |
|---|
| 585 | return 0; /* À½ÀÇ utc °ªÀº Áö¿øÇÏÁö ¾ÊÀ½.. */ |
|---|
| 586 | } |
|---|
| 587 | return (GPS - (UINT32)stc->GPS_UTC_offset); |
|---|
| 588 | } |
|---|
| 589 | |
|---|
| 590 | |
|---|
| 591 | #if COMMENT |
|---|
| 592 | ____Param_Set____(){} |
|---|
| 593 | #endif |
|---|
| 594 | |
|---|
| 595 | /**************************************************************************** |
|---|
| 596 | Function Name: |
|---|
| 597 | void DMW_SetLocalTimeZone(int time_zone) |
|---|
| 598 | |
|---|
| 599 | Description: |
|---|
| 600 | Set Time Zone with Offset Hours |
|---|
| 601 | |
|---|
| 602 | Note: |
|---|
| 603 | time_zone : -12 ~ +12 |
|---|
| 604 | *****************************************************************************/ |
|---|
| 605 | void DMW_SetLocalTimeZone(SysTimeContext *stc, int time_zone) |
|---|
| 606 | { |
|---|
| 607 | if (stc == NULL) stc = &g_DefaultSysTimeContext; |
|---|
| 608 | |
|---|
| 609 | if (time_zone<=12 && time_zone>=-12) |
|---|
| 610 | stc->nTimeZone = time_zone; |
|---|
| 611 | else dprint(0, "!! Time Zone %d out of range\n", time_zone); |
|---|
| 612 | } |
|---|
| 613 | |
|---|
| 614 | /**************************************************************************** |
|---|
| 615 | Function Name: |
|---|
| 616 | int DMW_GetLocalTimeZone(void); |
|---|
| 617 | |
|---|
| 618 | Description: |
|---|
| 619 | Get Time Zone with Offset Hours |
|---|
| 620 | |
|---|
| 621 | Note: |
|---|
| 622 | time_zone : -12 ~ +12 |
|---|
| 623 | *****************************************************************************/ |
|---|
| 624 | int DMW_GetLocalTimeZone(SysTimeContext *stc) |
|---|
| 625 | { |
|---|
| 626 | if (stc == NULL) stc = &g_DefaultSysTimeContext; |
|---|
| 627 | |
|---|
| 628 | return stc->nTimeZone; |
|---|
| 629 | } |
|---|
| 630 | |
|---|
| 631 | /**************************************************************************** |
|---|
| 632 | Function Name: |
|---|
| 633 | void DMW_SetDayLightSaving(char dayLightSavingOn) |
|---|
| 634 | |
|---|
| 635 | Description: |
|---|
| 636 | Day Light Saving Áؼö ¿©ºÎ ¼³Á¤ |
|---|
| 637 | ÁÖÀÇ: Áö±Ý ÇöÀç daylight savingÀ» °Á¦·Î µ¿ÀÛ ½Ã۶ó´Â Àǹ̰¡ ¾Æ´Ï´Ù. |
|---|
| 638 | |
|---|
| 639 | "Áؼö"·Î ¼³Á¤ÇØ ³õÀ¸¸é, daylight savingÀÇ ½ÇÁ¦ µ¿ÀÛÀº |
|---|
| 640 | stc³»ÀÇ DS_status¹× month, day µîÀÇ °ªµé·ÎºÎÅÍ ÀÚµ¿À¸·Î °áÁ¤µÈ´Ù. |
|---|
| 641 | |
|---|
| 642 | Note: |
|---|
| 643 | *****************************************************************************/ |
|---|
| 644 | void DMW_SetDayLightSaving(SysTimeContext *stc, BOOL dayLightSavingOn) |
|---|
| 645 | { |
|---|
| 646 | if (stc == NULL) stc = &g_DefaultSysTimeContext; |
|---|
| 647 | |
|---|
| 648 | stc->bDaylightSavingOn = dayLightSavingOn; |
|---|
| 649 | |
|---|
| 650 | /* daylight saving parameter´Â º¯°æÇÏÁö ¾Ê´Â´Ù. */ |
|---|
| 651 | } |
|---|
| 652 | |
|---|
| 653 | /**************************************************************************** |
|---|
| 654 | Function Name: |
|---|
| 655 | BOOLEAN DMW_GetDayLightSaving(void) |
|---|
| 656 | |
|---|
| 657 | Description: |
|---|
| 658 | Day Light Saving Áؼö ¿©ºÎ ÀÐÀ½. |
|---|
| 659 | ÁÖÀÇ: ½ÇÁ¦·Î daylight saving ÀÌ µ¿ÀÛÇϰí ÀÖ´ÂÁöÀÇ ¿©ºÎ°¡ ¾Æ´Ï´Ù. |
|---|
| 660 | |
|---|
| 661 | Note: |
|---|
| 662 | *****************************************************************************/ |
|---|
| 663 | BOOL DMW_GetDayLightSaving(SysTimeContext *stc) |
|---|
| 664 | { |
|---|
| 665 | if (stc == NULL) stc = &g_DefaultSysTimeContext; |
|---|
| 666 | |
|---|
| 667 | return stc->bDaylightSavingOn; |
|---|
| 668 | } |
|---|
| 669 | |
|---|
| 670 | /**************************************************************************** |
|---|
| 671 | Function Name: |
|---|
| 672 | DMW_SetDayLightSavingParam() / DMW_GetDayLightSavingParam() |
|---|
| 673 | |
|---|
| 674 | Description: |
|---|
| 675 | Day Light Saving parameter ¼³Á¤ ¹× Á¶È¸. |
|---|
| 676 | DS_day_of_month ¹× DS_hour parameter¸¦ °°ÀÌ »ç¿ë. |
|---|
| 677 | |
|---|
| 678 | Note: |
|---|
| 679 | *****************************************************************************/ |
|---|
| 680 | |
|---|
| 681 | void DMW_SetDayLightSavingParam(SysTimeContext *stc, int status, int day, int hour) |
|---|
| 682 | { |
|---|
| 683 | if (stc == NULL) stc = &g_DefaultSysTimeContext; |
|---|
| 684 | |
|---|
| 685 | stc->DS_status = status; |
|---|
| 686 | stc->DS_day_of_month = day; |
|---|
| 687 | stc->DS_hour = hour; |
|---|
| 688 | } |
|---|
| 689 | |
|---|
| 690 | |
|---|
| 691 | void DMW_GetDayLightSavingParam(SysTimeContext *stc, int *pStatus, int *pDay, int *pHour) |
|---|
| 692 | { |
|---|
| 693 | if (stc == NULL) stc = &g_DefaultSysTimeContext; |
|---|
| 694 | |
|---|
| 695 | if (pStatus) *pStatus = stc->DS_status; |
|---|
| 696 | if (pDay) *pDay = stc->DS_day_of_month; |
|---|
| 697 | if (pHour) *pHour = stc->DS_hour; |
|---|
| 698 | } |
|---|
| 699 | |
|---|
| 700 | /**************************************************************************** |
|---|
| 701 | Function Name: |
|---|
| 702 | DMW_CheckDayLightSavingActive() |
|---|
| 703 | |
|---|
| 704 | Description: |
|---|
| 705 | DayLight Saving ÀÌ ÇöÀç µ¿ÀÛ ÁßÀÎÁöÀÇ »óŸ¦ ¸®ÅÏ. |
|---|
| 706 | ½ÇÁ¦·Î ÀÌ ÇÔ¼ö°¡ ÇÊ¿äÇÑ °æ¿ì´Â ¸¹Áö ¾Ê´Ù. |
|---|
| 707 | »ç¿ëÀÚ¿¡°Ô´Â ±×³É ÇöÀç ½Ã°£¸¸ º¸¿©ÁÖ´Â °ÍÀ¸·Î ÃæºÐÇÏ´Ù. |
|---|
| 708 | |
|---|
| 709 | ÁÖÀÇ: |
|---|
| 710 | DMW_ConvertUTC2LocalTime() ½ÇÇà½Ã¿¡ ÀÌ Á¤º¸°¡ Á¤È®ÇÏ°Ô °áÁ¤µÈ´Ù. |
|---|
| 711 | µû¶ó¼ Á¤È®ÇÑ Á¤º¸¸¦ ¾òÀ¸·Á¸é ¸ÕÀú DMW_ConvertUTC2LocalTime()¸¦ È£ÃâÇϰí, |
|---|
| 712 | ¹Ù·Î ÀÌ¾î¼ ÀÌ ÇÔ¼ö¸¦ È£ÃâÇÏ¸é µÈ´Ù. |
|---|
| 713 | |
|---|
| 714 | Note: |
|---|
| 715 | *****************************************************************************/ |
|---|
| 716 | |
|---|
| 717 | BOOL DMW_CheckDayLightSavingActive(SysTimeContext *stc) |
|---|
| 718 | { |
|---|
| 719 | if (stc == NULL) stc = &g_DefaultSysTimeContext; |
|---|
| 720 | return stc->bDaylightSavingActive; |
|---|
| 721 | } |
|---|
| 722 | |
|---|
| 723 | /**************************************************************************** |
|---|
| 724 | Function Name: |
|---|
| 725 | UINT8 DMW_GetGPS_UTC_offset(void) |
|---|
| 726 | |
|---|
| 727 | Description: |
|---|
| 728 | GPS_UTC_offset °ªÀ» ¸®ÅÏ. |
|---|
| 729 | |
|---|
| 730 | Note: |
|---|
| 731 | *****************************************************************************/ |
|---|
| 732 | int DMW_GetGPS_UTC_offset(SysTimeContext *stc) |
|---|
| 733 | { |
|---|
| 734 | if (stc == NULL) stc = &g_DefaultSysTimeContext; |
|---|
| 735 | |
|---|
| 736 | return stc->GPS_UTC_offset; |
|---|
| 737 | } |
|---|
| 738 | |
|---|
| 739 | /**************************************************************************** |
|---|
| 740 | Function Name: |
|---|
| 741 | void DMW_SetGPS_UTC_offset(UINT8 offset) |
|---|
| 742 | |
|---|
| 743 | Description: |
|---|
| 744 | GPS_UTC_offset °ªÀ» ¼³Á¤ÇÔ. |
|---|
| 745 | |
|---|
| 746 | Note: |
|---|
| 747 | *****************************************************************************/ |
|---|
| 748 | void DMW_SetGPS_UTC_offset(SysTimeContext *stc, int offset) |
|---|
| 749 | { |
|---|
| 750 | if (stc == NULL) stc = &g_DefaultSysTimeContext; |
|---|
| 751 | |
|---|
| 752 | stc->GPS_UTC_offset = offset; |
|---|
| 753 | } |
|---|
| 754 | |
|---|
| 755 | |
|---|
| 756 | /* cafrii 050725 add */ |
|---|
| 757 | |
|---|
| 758 | void DMW_InvalidateSysTime(SysTimeContext *stc) |
|---|
| 759 | { |
|---|
| 760 | if (stc) |
|---|
| 761 | stc->bTimebaseAdjusted = FALSE; |
|---|
| 762 | |
|---|
| 763 | /* ÀÌÈÄ GetUTCTime °ú °°Àº ÇÔ¼ö¸¦ ºÎ¸£¸é ¿¡·¯¸¦ ¸®ÅÏÇÒ °ÍÀÓ.. */ |
|---|
| 764 | } |
|---|
| 765 | |
|---|
| 766 | |
|---|
| 767 | |
|---|
| 768 | #if COMMENT |
|---|
| 769 | ____Util____(){} |
|---|
| 770 | #endif |
|---|
| 771 | |
|---|
| 772 | |
|---|
| 773 | /**************************************************************************** |
|---|
| 774 | Function Name: |
|---|
| 775 | STime_t DMW_ChangedTimeInfo(STime_t norm_time, int changed_sec ) |
|---|
| 776 | |
|---|
| 777 | Description: |
|---|
| 778 | º¯ÈµÈ ³¯Â¥/¿äÀÏ/½Ã°£ Á¤º¸¸¦ °¡Á®¿Å |
|---|
| 779 | |
|---|
| 780 | Note: |
|---|
| 781 | |
|---|
| 782 | *****************************************************************************/ |
|---|
| 783 | void DMW_ChangedTimeInfo(STime_t *norm_time, int offset, STime_t *ret_time) |
|---|
| 784 | { |
|---|
| 785 | int utc; |
|---|
| 786 | |
|---|
| 787 | utc = DMW_ConvertLocalTime2UTC(NULL, norm_time); |
|---|
| 788 | DMW_ConvertUTC2LocalTime(NULL, utc + offset, ret_time); |
|---|
| 789 | } |
|---|
| 790 | |
|---|
| 791 | /**************************************************************************** |
|---|
| 792 | Function Name: |
|---|
| 793 | int DMW_GetTimeGap(STime_t start_time, STime_t end_time ) |
|---|
| 794 | |
|---|
| 795 | Description: |
|---|
| 796 | µÎ ½Ã°£Á¤º¸ÀÇ Â÷¿¡ ´ëÇØ Ãʽð£À» ¹ÝȯÇÔ |
|---|
| 797 | |
|---|
| 798 | Note: |
|---|
| 799 | ¸¸¾à end_time ÀÌ start_time º¸´Ù ¾Õ¼± °ú°ÅÀÇ ½Ã°£À̶ó¸é, |
|---|
| 800 | °á°ú°ªÀÌ À½ÀÇ °ªÀÌ µÉ ¼ö ÀÖ´Ù. |
|---|
| 801 | |
|---|
| 802 | µû¶ó¼ ÀÌ ÇÔ¼ö¸¦ ÀÌ¿ëÇØ¼ µÎ ½Ã°£Áß ¾î´À °ÍÀÌ ´õ ¹Ì·¡/°ú°ÅÀÎÁö üũÇÒ ¼öµµ ÀÖ´Ù. |
|---|
| 803 | |
|---|
| 804 | *****************************************************************************/ |
|---|
| 805 | int DMW_GetTimeGap(STime_t *start_time, STime_t *end_time) |
|---|
| 806 | { |
|---|
| 807 | UINT32 utc1, utc2; |
|---|
| 808 | |
|---|
| 809 | utc1 = DMW_ConvertLocalTime2UTC(NULL, start_time); |
|---|
| 810 | utc2 = DMW_ConvertLocalTime2UTC(NULL, end_time); |
|---|
| 811 | |
|---|
| 812 | return (INT32) (utc2 - utc1); |
|---|
| 813 | } |
|---|
| 814 | |
|---|
| 815 | |
|---|
| 816 | |
|---|
| 817 | |
|---|
| 818 | |
|---|
| 819 | |
|---|
| 820 | /*-------------------------------------------------------------------------------------*/ |
|---|
| 821 | |
|---|
| 822 | |
|---|
| 823 | |
|---|
| 824 | #if COMMENT |
|---|
| 825 | ____Test____(){} |
|---|
| 826 | #endif |
|---|
| 827 | |
|---|
| 828 | #if COMMENT |
|---|
| 829 | |
|---|
| 830 | void TestPrintSysTimeContext(SysTimeContext *stc) |
|---|
| 831 | { |
|---|
| 832 | if (stc == NULL) { |
|---|
| 833 | stc = &g_DefaultSysTimeContext; |
|---|
| 834 | dprint(2, " [DefaultSysTimeContext] 0x%x\n", stc); |
|---|
| 835 | } |
|---|
| 836 | dprint(2, " timebase %d\n", stc->nTimeSystemBase); |
|---|
| 837 | dprint(2, " timezone %+d, dst %d\n", stc->nTimeZone, stc->bDaylightSavingOn); |
|---|
| 838 | dprint(2, " GPS_UTC_offset %d\n", stc->GPS_UTC_offset); |
|---|
| 839 | if (stc->bTimebaseAdjusted) |
|---|
| 840 | { |
|---|
| 841 | UINT32 utc; |
|---|
| 842 | utc = DHL_OS_GetMsCount()/1000 + stc->nTimeSystemBase; |
|---|
| 843 | dprint(2, " current utc: %d (0x%x)\n", utc, utc); |
|---|
| 844 | } |
|---|
| 845 | else |
|---|
| 846 | dprint(2, " !! time not initialized..\n"); |
|---|
| 847 | } |
|---|
| 848 | |
|---|
| 849 | |
|---|
| 850 | |
|---|
| 851 | /* ¾Æ·¡ Å×½ºÆ® ÇÔ¼öµéÀº µðÆúÆ® ŸÀÓ ÄÁÅØ½ºÆ® »ó¿¡¼ µ¿ÀÛÇÔ. */ |
|---|
| 852 | |
|---|
| 853 | |
|---|
| 854 | void TestSetLocalTime(int year, int month, int day, int hour, int min, int sec) |
|---|
| 855 | { |
|---|
| 856 | DMW_SetLocalTime2(NULL, year, month, day, hour, min, sec); |
|---|
| 857 | } |
|---|
| 858 | |
|---|
| 859 | void TestPrintCurTime() |
|---|
| 860 | { |
|---|
| 861 | STime_t s; |
|---|
| 862 | UINT32 utc; |
|---|
| 863 | int err; |
|---|
| 864 | |
|---|
| 865 | err = DMW_GetLocalTime(NULL, &s); |
|---|
| 866 | |
|---|
| 867 | DMW_GetUTCTime(NULL, &utc); |
|---|
| 868 | |
|---|
| 869 | /*dprint(2, "%s %d/%d/%d %s %d:%02d:%02d [tz %+d] %s UTC 0x%x\n", err ? "!!err " : "", |
|---|
| 870 | s.year, s.month, s.day, DayOfWeakString(s.wday), s.hour, s.min, s.sec, |
|---|
| 871 | DMW_GetLocalTimeZone(NULL), DMW_GetDayLightSaving(NULL) ? "DS on" : "", utc);*/ |
|---|
| 872 | } |
|---|
| 873 | |
|---|
| 874 | void TestPrintLocalTime() |
|---|
| 875 | { |
|---|
| 876 | TestPrintCurTime(); |
|---|
| 877 | } |
|---|
| 878 | |
|---|
| 879 | |
|---|
| 880 | extern TSD *Dmc_GetCurrentTsd(void); |
|---|
| 881 | |
|---|
| 882 | void TestTimeSync() |
|---|
| 883 | { |
|---|
| 884 | sttSectionPtr_t sttSectPtr; |
|---|
| 885 | int err; |
|---|
| 886 | |
|---|
| 887 | /* STT¸¦ Çϳª ´Ù¿î·Îµå ¹Þ¾Æ¼ System time¿¡ adjustÇÑ´Ù. |
|---|
| 888 | // |
|---|
| 889 | // µðÆúÆ® ÄÁÅØ½ºÆ®¿¡ Àû¿ëÇÑ´Ù. Á¦´ë·Î ÇÏ·Á¸é ÄÁÅØ½ºÆ®¸¦ Çϳª ¸¸µå´Â°Ô ÁÁ°Ú´Ù.. |
|---|
| 890 | // |
|---|
| 891 | // ½ÇÁ¦ Application¿¡¼´Â STT¿¡ discontinuity°¡ ¹ß°ßµÇ¸é ÀÌ·± ÀÛ¾÷À» ÇØÁà¾ß ÇÒ °ÍÀÌ´Ù. |
|---|
| 892 | // 1. ä³ÎÀÌ º¯°æµÇ¾úÀ» ¶§ (ä³Î¸¶´Ù STT ½Ã°èÀÇ ¿ÀÂ÷°¡ ÀÖÀ¸¹Ç·Î..) |
|---|
| 893 | // 2. °°Àº ä³ÎÀε¥ PsiLostPacket °°Àº discontinuity·Î ÃßÁ¤µÇ´Â »óȲ ¹ß»ý½Ã (³ìÈ ½ºÆ®¸²À» Àç»ýÇÑ´ÙµçÁö.. ) |
|---|
| 894 | // 3. ±×¸®°í Àß ¸ð¸£°ÚÀ¸¸é ÁÖ±âÀûÀ¸·Î ÀÌ·¯ÇÑ ±â´ÉÀ» ÇØ ÁÖ´Â°Ô ÁÁ´Ù. (¾à 1ºÐ?) |
|---|
| 895 | */ |
|---|
| 896 | DMW_SetLocalTimeZone(NULL, 9); /* TimeZoneÀº ºÎÆÃ½Ã 1ȸ, ¶Ç´Â »ç¿ëÀÚ°¡ º¯°æÇßÀ»¶§ 1ȸ¸¸ ÇØµµ µÈ´Ù. */ |
|---|
| 897 | |
|---|
| 898 | err = GetSttSection((TSD *)Dmc_GetCurrentTsd(), &sttSectPtr, 1000*3); |
|---|
| 899 | if (err) { |
|---|
| 900 | dprint("TestTimeSync: no STT!!\n"); |
|---|
| 901 | return; |
|---|
| 902 | } |
|---|
| 903 | DMW_SetGPS_UTC_offset(NULL, sttSectPtr->GPS_UTC_offset); |
|---|
| 904 | DMW_SetDayLightSaving(NULL, sttSectPtr->daylight_savings.DS_status); |
|---|
| 905 | DMW_SetUTCTime(NULL, DMW_ConvertGPS2UTC(NULL, sttSectPtr->system_time)); |
|---|
| 906 | |
|---|
| 907 | FreeAtscTable(sttSectPtr); |
|---|
| 908 | |
|---|
| 909 | /* Àû¿ëµÈ »õ ½Ã°£À» Ç¥½Ã.. */ |
|---|
| 910 | /* TestPrintLocalTime(); */ |
|---|
| 911 | TestPrintSysTimeContext(NULL); |
|---|
| 912 | } |
|---|
| 913 | |
|---|
| 914 | /* Å×½ºÆ® ÄÚµå ¿¹: 1Ãʸ¶´Ù ÇöÀç ½Ã°£ Ç¥½Ã |
|---|
| 915 | // |
|---|
| 916 | // DMW_SYS_SetTimer (7710, 1000, TestPrintCurTime, 0, 0) |
|---|
| 917 | // |
|---|
| 918 | // Å×½ºÆ® ÄÚµå ¿¹: 10ºÐ¿¡ Çѹø¾¿ STT sync¸¦ ¼öÇàÇÑ´Ù. |
|---|
| 919 | // |
|---|
| 920 | // DMW_SYS_SetTimer (7711, 10*60*1000, TestTimeSync, 0, 0) |
|---|
| 921 | */ |
|---|
| 922 | |
|---|
| 923 | #endif /* 0 */ |
|---|
| 924 | |
|---|
| 925 | |
|---|
| 926 | |
|---|
| 927 | |
|---|
| 928 | |
|---|
| 929 | |
|---|
| 930 | #if COMMENT |
|---|
| 931 | ______DebugSymbol____(){} |
|---|
| 932 | #endif |
|---|
| 933 | |
|---|
| 934 | |
|---|
| 935 | |
|---|
| 936 | |
|---|
| 937 | |
|---|
| 938 | #if DMW_REGISTER_DEBUG_SYMBOL |
|---|
| 939 | |
|---|
| 940 | static DHL_SymbolTable SysTimeSymbols[] = |
|---|
| 941 | { |
|---|
| 942 | /*---- functions */ |
|---|
| 943 | |
|---|
| 944 | /*---- variables */ |
|---|
| 945 | //DHL_VAR_SYM_ENTRY(g_Trace_bSysTimeDebug), |
|---|
| 946 | 0, |
|---|
| 947 | }; |
|---|
| 948 | |
|---|
| 949 | #endif /* DMW_REGISTER_DEBUG_SYMBOL */ |
|---|
| 950 | |
|---|
| 951 | |
|---|
| 952 | void DMW_RegisterSysTimeSymbols() |
|---|
| 953 | { |
|---|
| 954 | #if DMW_REGISTER_DEBUG_SYMBOL |
|---|
| 955 | DHL_DBG_RegisterSymbols(SysTimeSymbols, DHL_NUMSYMBOLS(SysTimeSymbols)); |
|---|
| 956 | |
|---|
| 957 | #endif |
|---|
| 958 | } |
|---|
| 959 | |
|---|
| 960 | |
|---|
| 961 | |
|---|
| 962 | |
|---|
| 963 | |
|---|
| 964 | |
|---|
| 965 | /* Revision History ///////////////////////////////////////////////////////// |
|---|
| 966 | |
|---|
| 967 | 2.07 2005/3/15 GetUtcTime ¿¡¼ timebaseAdjust µÇÁöµµ ¾ÊÀº »óÅÂÀÏ °æ¿ì |
|---|
| 968 | µðÆúÆ® time °ªÀ» ÀÌ¿ëÇÏ¿© utc ±Ù»çÄ¡¸¦ ¸®ÅÏ |
|---|
| 969 | ConvertLocalTime2UTC ¿¡¼ acc_dayÀÇ ½ÃÀÛ°ªÀÌ -5¶ó¼ utc = 0ÀÏ °æ¿ì¿Í °°Àº |
|---|
| 970 | ¿¡·¯ »óȲ¿¡¼ ¿äÀÏ º¯È¯ÀÌ Àß ¾ÈµÇ´Â ¹®Á¦ ¼öÁ¤ |
|---|
| 971 | |
|---|
| 972 | 2.06 DMW_SYS_XXX Standard ȣȯ API´Â ¸ðµÎ »èÁ¦.. ´õÀÌ»ó Áö¿øÇÏÁö ¾ÊÀ½. |
|---|
| 973 | |
|---|
| 974 | 2.05 2004/12/20 cafrii DMW_SYS_GetCurUtcTime Ãß°¡ (PodIf ¿¡¼ »ç¿ë) |
|---|
| 975 | 2.04 2004/11/02 cafrii DMW_SYS_GetTimeFromGPS ¹ö±× ¼öÁ¤ |
|---|
| 976 | 2.03 2004/10/5 cafrii DMW_ConvertLocalTime2UTC ¿¡¼ À½ÀÇ timezone °í·Á¾ÈÇÑ ¹ö±× |
|---|
| 977 | 2.02 2004/6/17 cafrii DMW_ConvertGPS2UTC: prevent negative utc |
|---|
| 978 | DMW_SYS_GetTimeFromGPS Ãß°¡ ±¸Çö |
|---|
| 979 | 2.01 2004/6/15 cafrii Àüü ±¸Á¶ Á¤¸®, DMW_Timer.c ¿¡ ÀÖ´ø StdAPI¸¦ À̰÷¿¡ Æ÷ÆÃ Á¤¸®.. |
|---|
| 980 | |
|---|
| 981 | ver 2.000 - Date : 2003/10/21 |
|---|
| 982 | WHO : Hyunsik Chang |
|---|
| 983 | To Do : Timer »èÁ¦ ÇÊ¿ä. ¿©±â´Â ½Ã°è¸¸ ÀÖµµ·Ï! |
|---|
| 984 | |
|---|
| 985 | ver 1.001 - Date : 2003/09/15 |
|---|
| 986 | WHO : K.H. Park |
|---|
| 987 | To Do : UTC Time °ü·Ã Ãß°¡ |
|---|
| 988 | |
|---|
| 989 | ver 1.000 - Date : 2003/08/18 |
|---|
| 990 | WHO : K.H. Park |
|---|
| 991 | To Do : ½Ã½ºÅÛ ½Ã°£°ü·Ã ÇÔ¼ö ¹× ½Ã°£°æ°ú ÃøÁ¤ ÇÔ¼ö ±¸Çö |
|---|
| 992 | |
|---|
| 993 | ////////////////////////////////////////////////////////////////////////// */ |
|---|