/home/daqweb/fgddaq/c8051/Devices/Time.h File Reference


Data Structures

struct  TM

Defines

#define BASE_YEAR   1970
#define START_WDAY   4
#define SECS_PER_MIN   (unsigned long int) 60
#define SECS_PER_HOUR   (unsigned long int)(SECS_PER_MIN*60)
#define SECS_PER_DAY   (unsigned long int)(SECS_PER_HOUR*24)

Functions

void ascTime (char *str, unsigned long int ltime)
void secs_to_tm (unsigned long int t, struct TM *tm)

Define Documentation

#define BASE_YEAR   1970

#define SECS_PER_DAY   (unsigned long int)(SECS_PER_HOUR*24)

#define SECS_PER_HOUR   (unsigned long int)(SECS_PER_MIN*60)

#define SECS_PER_MIN   (unsigned long int) 60

#define START_WDAY   4


Function Documentation

void ascTime ( char *  str,
unsigned long int  ltime 
)

00016                                                   {
00017   char xdata mydate[12], mydate1[10];
00018 
00019   secs_to_tm(ltime, &tm);
00020 // sprintf(mydate, "%.4d-%.2d-%.2d", tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday);
00021   sprintf(mydate, "%.4d-%3s-%.2d", tm.tm_year+1900, month_name[tm.tm_mon], tm.tm_mday);
00022   sprintf(mydate1, " %.2d:%.2d:%.2d", tm.tm_hour, tm.tm_min, tm.tm_sec);
00023   sprintf(str, "%s%s", mydate, mydate1);
00024 }

void secs_to_tm ( unsigned long int  t,
struct TM tm 
)

00028 {
00029         unsigned long int xdata days, rem;
00030         unsigned int xdata y, mon;
00031         days = t / SECS_PER_DAY;
00032         rem = t - (days * SECS_PER_DAY);
00033         tm->tm_hour = rem / SECS_PER_HOUR;
00034         rem -= tm->tm_hour*SECS_PER_HOUR;
00035         tm->tm_min = rem / SECS_PER_MIN;
00036         rem -= tm->tm_min*SECS_PER_MIN;
00037         tm->tm_sec = rem;
00038         tm->tm_wday = (days + START_WDAY) % 7;
00039         y = BASE_YEAR;
00040         while (days >= 365) {
00041                 if ((y % 4) == 0) {
00042                         if (days == 365)
00043                                 break;
00044                         // leap year
00045                         days--;
00046                 }
00047                 days -= 365;
00048                 y++;
00049         }
00050         tm->tm_year = y - 1900;
00051         tm->tm_yday = days;
00052 
00053         // Set correct # of days for feburary 
00054         month_days[1] = ((y % 4) == 0) ? 29 : 28;
00055 
00056         for (mon = 0; mon < 12; mon++) {
00057                 if (days < month_days[mon]) {
00058                         tm->tm_mon = mon;
00059                         break;
00060                 }
00061                 days -= month_days[mon];
00062         }
00063         if (mon == 12)  {
00064                 // PANIC
00065                 days = days + 0;
00066 //                printf ("secs_to_tm:remaining days=%d\n", days);
00067         }
00068 
00069         tm->tm_mday = days + 1;
00070         tm->tm_isdst = 0;
00071         // tm->tm_gmtoff = 0;
00072 }


Generated on 10 Jun 2013 for FGDC8051 by  doxygen 1.4.7