MQX and time.h

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MQX and time.h

Jump to solution
3,182 Views
CarlFST60L
Senior Contributor II

Would someone be kind enough to share their RTC to Actual Time/Date conversion? Here is some code that works on my PC to convert to date and tim, but the data types are different in MQX along with something else:

 

 

/* a sample program that return local time. */#include <stdio.h>#include <time.h>int main() {    struct tm *ptr;    time_t lt;        lt = time(NULL);       //return system time    printf("time(NULL) = %d\n", lt);    ptr = localtime(&lt);  // return time in the form of tm structure    printf(asctime(ptr));}

 OUTPUT:

time(NULL) = 941830207
Fri Nov  5 14:30:07 1999

 Thanks.

 

 

 

0 Kudos
1 Solution
664 Views
JaimeR
Contributor III

I have used something like:

 

void setTimeFromDate(uint_32 year, uint_32 month, uint_32 day, uint_32 hour,
                       uint_32 minute, uint_32 second, uint_32 millisec){
    TIME_STRUCT  MQX_time;
    DATE_STRUCT  DateStruct;
    RTC_TIME_STRUCT RTC_time;
   
    DateStruct.YEAR = (uint_16)year;
    DateStruct.MONTH = (uint_16)month;
    DateStruct.DAY = (uint_16)day;
    DateStruct.HOUR = (uint_16)hour;
    DateStruct.MINUTE = (uint_16)minute;
    DateStruct.SECOND = (uint_16)second;
    DateStruct.MILLISEC = (uint_16)millisec;
    _time_from_date(&DateStruct, &MQX_time);//Convierte la fecha a tiempo MQX
    _rtc_time_from_mqx_time (&MQX_time, &RTC_time);
    _rtc_set_time (&RTC_time);
}

void getDateFromTime() {
    TIME_STRUCT  MQX_time;
    DATE_STRUCT  DateStruct;
    RTC_TIME_STRUCT RTC_time;
   
    _rtc_get_time (&RTC_time);
    _rtc_time_to_mqx_time ( &RTC_time, &MQX_time);
    _time_to_date(&MQX_time, &DateStruct );

 

}

 

Does that suits your needs? I dont completely understand your problem.

 

Message Edited by Jaime R on 2010-01-28 12:18 AM

View solution in original post

0 Kudos
3 Replies
664 Views
CarlFST60L
Senior Contributor II

I have done some research, and it seems the MSL library needs some modification to get everything working, which seems long and painful to setup as I have not done any of this before...

 

Is there a 'simple' way to do something like this:

 

_rtc_get_time (&time_rtc);      //Get the time from the 52259 RTC

_Convert_RTC_to_TM(&time_rt, &TM_Struct);   //Some custom converter function

chr_ptr = asctime(&TM_Struct);  //Get the time string

 

I really just want to show the date / time for logging, I am not worried about daylight savings, time zones etc as we will use UTC.

Message Edited by CarlFST60L on 2010-01-28 12:00 AM
0 Kudos
665 Views
JaimeR
Contributor III

I have used something like:

 

void setTimeFromDate(uint_32 year, uint_32 month, uint_32 day, uint_32 hour,
                       uint_32 minute, uint_32 second, uint_32 millisec){
    TIME_STRUCT  MQX_time;
    DATE_STRUCT  DateStruct;
    RTC_TIME_STRUCT RTC_time;
   
    DateStruct.YEAR = (uint_16)year;
    DateStruct.MONTH = (uint_16)month;
    DateStruct.DAY = (uint_16)day;
    DateStruct.HOUR = (uint_16)hour;
    DateStruct.MINUTE = (uint_16)minute;
    DateStruct.SECOND = (uint_16)second;
    DateStruct.MILLISEC = (uint_16)millisec;
    _time_from_date(&DateStruct, &MQX_time);//Convierte la fecha a tiempo MQX
    _rtc_time_from_mqx_time (&MQX_time, &RTC_time);
    _rtc_set_time (&RTC_time);
}

void getDateFromTime() {
    TIME_STRUCT  MQX_time;
    DATE_STRUCT  DateStruct;
    RTC_TIME_STRUCT RTC_time;
   
    _rtc_get_time (&RTC_time);
    _rtc_time_to_mqx_time ( &RTC_time, &MQX_time);
    _time_to_date(&MQX_time, &DateStruct );

 

}

 

Does that suits your needs? I dont completely understand your problem.

 

Message Edited by Jaime R on 2010-01-28 12:18 AM
0 Kudos
664 Views
CarlFST60L
Senior Contributor II

Ahhhh, my mistake, I didnt realise that the date function was available from MQX as its not in their example, I assumed we needed to use time.h. Time.h requires the MSL library to be rebuilt and configured to work with your hardware etc... Obviously not required! I should have searched the RM a little better!

 

0 Kudos