time_t get_rtc_time(void) { struct tm tm; time_t t; unsigned int year,v; // if(!clk_invalid) { v = inl(REG_TOY_READ0); year = inl(REG_TOY_READ1); tm.tm_sec = (v>>4)&0x3f; tm.tm_min = (v>>10)&0x3f; tm.tm_hour = (v>>16)&0x1f; tm.tm_wday = 0; tm.tm_mday = (v>>21)&0x1f; tm.tm_mon = ((v>>26)&0xf) - 1; tm.tm_year = year - 1900; if(tm.tm_year < 50)tm.tm_year += 100; tm.tm_isdst = tm.tm_gmtoff = 0; t = gmmktime(&tm); // } // else // { // t = 957960000; /* Wed May 10 14:00:00 2000 :-) */ // } return(t); }
// Return the value of time in seconds since the Epoch static time_t time(time_t *timer) { time_t t; struct tm tmbuff; SYSTEMTIME st; // Retrive current system date time as UTC GetSystemTime(&st); // Build tm struct based on SYSTEMTIME values tmbuff.tm_year = st.wYear - TM_YEAR_BASE; tmbuff.tm_mon = st.wMonth - 1; // wMonth value 1-12 tmbuff.tm_mday = st.wDay; tmbuff.tm_hour = st.wHour; tmbuff.tm_min = st.wMinute; tmbuff.tm_sec = st.wSecond; tmbuff.tm_isdst = 0; // always 0 for UTC time tmbuff.tm_wday = st.wDayOfWeek; tmbuff.tm_yday = 0; // Convert tm struct to time_t t = gmmktime(&tmbuff); // Assign time value if (timer != NULL) { *timer = t; } return t; }
static void proc_gps_gpx(struct gpsfile *gpsf, void (*gpsproc)(struct nmea_pointinfo *,void *), void *data) { static xmlSAXHandler myhandler={ .initialized = 1, .startElement = mystarthandler, .endElement = myendhandler, .characters = mycharacters }; gpsf->gpsproc=gpsproc; gpsf->gpsproc_data=data; if (!gpsf->ctxt) { gpsf->ctxt = xmlCreatePushParserCtxt(&myhandler, gpsf, gpsf->buf,gpsf->bufpos, "gpxfile"); } else { xmlParseChunk(gpsf->ctxt,gpsf->buf,gpsf->bufpos,0); } gpsf->bufpos=0; } static void proc_gps_nmea(struct gpsfile *gpsf, void (*gpsproc)(struct nmea_pointinfo *,void *), void *data) { char *endp; if (!strncmp(gpsf->buf,"<?xml",5)) { gpsf->handling_procedure=proc_gps_gpx; proc_gps_gpx(gpsf,gpsproc,data); return; } while ((endp=memchr(gpsf->buf,'\n',gpsf->bufpos))) { int readlen; *endp=0; /* printf("gps line: %s ENDLINE\n",gpsf->buf); */ if (strstr(gpsf->buf,"<?xml")) { *endp='\n'; gpsf->handling_procedure=proc_gps_gpx; proc_gps_gpx(gpsf,gpsproc,data); return; } if (strncmp(gpsf->buf,"$GPRMC",6)==0) { char *fields[13]; int numfields=my_split(gpsf->buf,fields,",",13); if (((numfields == 13)||(numfields == 12))&&(strlen(fields[3])>3)) { struct tm tm; time_t t; gpsf->curpoint.lat=to_seconds(fields[3]); gpsf->curpoint.lon=to_seconds(fields[5]); if ((fields[4])[0] == 'S') gpsf->curpoint.lat=-gpsf->curpoint.lat; if ((fields[6])[0] == 'W') gpsf->curpoint.lon=-gpsf->curpoint.lon; memset(&tm,0,sizeof(tm)); sscanf(fields[1],"%02d%02d%02d",&tm.tm_hour,&tm.tm_min,&tm.tm_sec); sscanf(fields[9],"%02d%02d%02d",&tm.tm_mday,&tm.tm_mon,&tm.tm_year); tm.tm_mon--; if (tm.tm_year<70) tm.tm_year+=100; t=gmmktime(&tm); /* t=tm-tz */ gpsf->curpoint.time=t; gpsf->curpoint.start_new=gpsf->first?1:0; if ((gpsf->curpoint.time-gpsf->last_fix)>20) { gpsf->curpoint.start_new=1; } gpsf->last_fix=t; gpsf->curpoint.speed=atof(fields[7]); if (strlen(fields[8])) gpsf->curpoint.heading=atof(fields[8]); else gpsf->curpoint.heading=INVALID_HEADING; gpsf->curpoint.state=(numfields==13)?((fields[12])[0]):'?'; gpsproc(&gpsf->curpoint,data); gpsf->first=0; } } else if (!strncmp(gpsf->buf,"$GPGGA",6)) { char *fields[15]; int numfields=my_split(gpsf->buf,fields,",",15); if (numfields>8) gpsf->curpoint.hdop=10.0*atof(fields[8]); } endp++; readlen=endp-gpsf->buf; if (readlen != gpsf->bufpos) memmove(gpsf->buf,endp,gpsf->bufpos-readlen); gpsf->bufpos-=readlen; } }