View previous topic :: View next topic |
Author |
Message |
mabd
Joined: 17 Jan 2005 Posts: 8
|
Unix time |
Posted: Tue Jan 13, 2009 11:09 am |
|
|
Does CCS have any built-in functions to convert a gps dato to Unix time?
Thanks |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
mabd
Joined: 17 Jan 2005 Posts: 8
|
Unix time |
Posted: Wed Jan 14, 2009 1:46 am |
|
|
When I search this topic appear this messsage:
No topics or posts met your search criteria
It's necessary to Search for any terms or use query as entered
http://www.ccsinfo.com/forum/viewtopic.php?t=36475&highlight=unix
In this topic he wants to convert a unix time stamp to something usable. I want to do otherwise -> convert a gps date to unix time stamp. I haven't found any function that do this.
Is there any function that do this?
Thanks |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jan 14, 2009 1:59 am |
|
|
The search worked for me. I found 28 matches.
But anyway, post the format of the "gps date". Post an example of it. |
|
|
mabd
Joined: 17 Jan 2005 Posts: 8
|
unix time |
Posted: Wed Jan 14, 2009 4:29 am |
|
|
Gps date:
In the GPRMC Gps NMEA sentence we have the date:
6 characters: 131009 (day/month/year)
And in the GPGGA we have the hour:
6 characters: 110515 (hour/minute/second)
Then I create an struct_tm fecha with this members:
fecha.tm_sec=15
fecha.tm_min=5
fecha.tm_hour=11
fecha.tm_mday=13
fecha.tm_mon=1
fecha.tm_year=2009
I think that the function to convert this date to unixtime is mktime(struct_tm * timeT) in rtctimer.c
Please could you send me an example?.
Thanks |
|
|
Ttelmah Guest
|
|
Posted: Wed Jan 14, 2009 8:44 am |
|
|
The 'odds' are that few people will be using Unix time 'locally' in any CCS application.
However the arithmetic is pretty basic. Do a search on the USNO site, for 'Julian date formula'. This gives a formula that returns a Julian day number using basic integer arithmetic, from a given Gregorian month/day/year, with the correct allowances for leap years etc..
Now Unix times, are simply a count in seconds from Jan 1st 1970, with a few assumptions (that can lead to 'oddities', especially when going the other way). The primary one is 86400 seconds per day.
If you calculate the Julian day number, then subtract the one (precalculate this) for the Unix start time, multiply the result by 86400, then add the seconds, minutes*60, and hours*3600 (remember to ensure that you cast all integers 'up' to int32 before performing the arithmetic), you get the Unix time.
You should be able to generate the value in about 10 minutes work.
Best Wishes |
|
|
|