Pedro Campos / Mbed OS SERVOS_V0_3
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers RTC.cpp Source File

RTC.cpp

00001 //
00002 // RUTINAS DE ACCESO AL RELOJ
00003 //
00004 #include "mbed.h"
00005 #include "declaraciones.h"
00006 
00007 extern st_datos_servo datos_servo;       // ESTRUCTURA DE VARIABLES DE ESTADO DEL SERVO DE DIRECCION
00008 
00009 //DigitalOut myled(LED1);
00010 
00011 
00012 
00013 
00014 void getTime() {
00015     time_t timestamp = time(NULL);
00016     printf("Time: %lu\r\n", timestamp);
00017 }
00018     
00019 
00020 time_t asUnixTime(int year, int mon, int mday, int hour, int min, int sec) {
00021     struct tm   t;
00022     t.tm_year = year - 1900;
00023     t.tm_mon =  mon - 1;        // convert to 0 based month
00024     t.tm_mday = mday;
00025     t.tm_hour = hour;
00026     t.tm_min = min;
00027     t.tm_sec = sec;
00028     t.tm_isdst = -1;            // Is Daylight saving time on? 1 = yes, 0 = no, -1 = unknown
00029  
00030     return mktime(&t);          // returns seconds elapsed since January 1, 1970 (begin of the Epoch)
00031 }
00032 
00033 
00034 
00035 void actualizaFechaHoraGPS(float fecha, float hora){
00036 int year, mon, day, hour, min, sec;
00037 
00038 //    printf("fecha:%f hora:%f\r\n", fecha, hora);
00039 
00040     day = (int)(fecha/10000);
00041     mon = (int)((fecha-day*10000)/100);
00042     year = ((int)fecha)%100;
00043     hour = (int)(hora/10000);
00044     min = (int)((hora-hour*10000)/100);
00045     sec = ((int)hora)%100;
00046 
00047 //    printf("%02d-%02d-%02d %02d:%02d:%02d\r\n", day, mon, year, hour, min, sec);
00048 
00049     time_t epoch =  asUnixTime(year+2000, mon, day, hour, min, sec); 
00050 //    printf("epoch:%lu\r\n", epoch);
00051     datos_servo.fecha_hora = epoch-946684800L;
00052 
00053     set_time(epoch);  // Sincroniza con fecha hora del GPS   
00054 
00055 //    set_time(1597521600);  // Set RTC time to Wed, 28 Oct 2009 11:35:37    
00056 
00057 }
00058