Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 25, 2024, 09:57:04 21:57


Login with username, password and session length


Pages: [1]
Print
Author Topic: How to Change the GPS UTC Time Sentence Format to Indian Time??  (Read 4522 times)
0 Members and 1 Guest are viewing this topic.
xpress_embedo
Active Member
***
Offline Offline

Posts: 173

Thank You
-Given: 122
-Receive: 254


« on: June 13, 2013, 09:41:45 09:41 »

Hello!!! Everyone i am using a GPS Module to track location of my Device and also obtaining the time and date information from the GPS Module.
 
I sent this command to GPS Module to get this $GPRMC sentence.

$PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29

The checksum is calculated by using this site:-
http://www.hhhh.org/wiml/proj/nmeaxor.html

and my GPS Module is receiving Proper Commands and hence giving only this sentence as output
$GPRMC,001225,A,2832.1834,N,08101.0536,W,12,25,251 211,1.2,E,A*03

But my Problem is that i need India's time and Date not the UTC Time and Date.
For me to add 5:30 manually to the UTC time is very tough task and i am implementing that, which is going to become very long code.
I want to know, is it possible that my GPS Module will give Indian Time not UTC time, is it possible.

Please help me and if there is not any such way then please share an algorithm to easily easily add 5:30 to my time and date.


Posted on: June 13, 2013, 08:20:43 08:20 - Automerged

Previously i am using the Wrong Approach (Algorithm) for Implementing this in my Code.
Now Changed my Algorithm to Add 5:30 in my Code and is working fine.
Please Check if anyone find any bug, i am sharing my code:-

Code:

#include<p18f8722.h>
void main()
{
unsigned char Time_Data[] = "233000"; //23Hour 58Min 25 Seconds
unsigned char Date_Data[] = "280215"; //13 June 2013

unsigned char GPS_Date,GPS_Month,GPS_Year,GPS_Hour,GPS_Min,GPS_Sec;

unsigned char temp;

GPS_Date = (Date_Data[0]^0x30)*10 + (Date_Data[1]^0x30);
GPS_Month = (Date_Data[2]^0x30)*10 + (Date_Data[3]^0x30);
GPS_Year = (Date_Data[4]^0x30)*10 + (Date_Data[5]^0x30);

GPS_Hour = (Time_Data[0]^0x30)*10 + (Time_Data[1]^0x30);
GPS_Min = (Time_Data[2]^0x30)*10 + (Time_Data[3]^0x30);
GPS_Sec = (Time_Data[4]^0x30)*10 + (Time_Data[5]^0x30);

//Adding 30 Minutes
temp = GPS_Min + 30;
if(temp < 60)
{
GPS_Min = GPS_Min+30;
}
else
{
GPS_Min = temp - 60;
if(GPS_Hour < 23)
{
GPS_Hour = GPS_Hour+1;
}
else
{
GPS_Hour = 0;
switch(GPS_Month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
if(GPS_Date < 31)
{
GPS_Date = GPS_Date+1;
}
else
{
GPS_Date = 1;
if(GPS_Month < 12)
GPS_Month = GPS_Month+1;
else
{
GPS_Month = 1;
GPS_Year = GPS_Year+1;
}
}
break;

case 4:
case 6:
case 9:
case 11:
if(GPS_Date < 30)
{
GPS_Date = GPS_Date+1;
}
else
{
GPS_Date = 1;
if(GPS_Month < 12)
GPS_Month = GPS_Month+1;
else
{
GPS_Month = 1;
GPS_Year = GPS_Year+1;
}
}
break;

case 2:
temp = GPS_Year%4;
if(temp==0)
{
if(GPS_Date < 29)
{
GPS_Date = GPS_Date+1;
}
else
{
GPS_Date = 1;
if(GPS_Month < 12)
GPS_Month = GPS_Month+1;
else
{
GPS_Month = 1;
GPS_Year = GPS_Year+1;
}
}
}
else
{
if(GPS_Date < 28)
{
GPS_Date = GPS_Date+1;
}
else
{
GPS_Date = 1;
if(GPS_Month < 12)
GPS_Month = GPS_Month+1;
else
{
GPS_Month = 1;
GPS_Year = GPS_Year+1;
}
}
}
break;
}
}
}

//Now Time to Add 5 Hours
temp = GPS_Hour + 5;
if(temp < 23)
{
GPS_Hour = GPS_Hour+5;
}
else
{
GPS_Hour = temp - 24;
switch(GPS_Month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
if(GPS_Date < 31)
{
GPS_Date = GPS_Date+1;
}
else
{
GPS_Date = 1;
if(GPS_Month < 12)
GPS_Month = GPS_Month+1;
else
{
GPS_Month = 1;
GPS_Year = GPS_Year+1;
}
}
break;

case 4:
case 6:
case 9:
case 11:
if(GPS_Date < 30)
{
GPS_Date = GPS_Date+1;
}
else
{
GPS_Date = 1;
if(GPS_Month < 12)
GPS_Month = GPS_Month+1;
else
{
GPS_Month = 1;
GPS_Year = GPS_Year+1;
}
}
break;

case 2:
temp = GPS_Year%4;
if(temp==0)
{
if(GPS_Date < 29)
{
GPS_Date = GPS_Date+1;
}
else
{
GPS_Date = 1;
if(GPS_Month < 12)
GPS_Month = GPS_Month+1;
else
{
GPS_Month = 1;
GPS_Year = GPS_Year+1;
}
}
}
else
{
if(GPS_Date < 28)
{
GPS_Date = GPS_Date+1;
}
else
{
GPS_Date = 1;
if(GPS_Month < 12)
GPS_Month = GPS_Month+1;
else
{
GPS_Month = 1;
GPS_Year = GPS_Year+1;
}
}
}
break;
}
}
while(1);

}

Logged
gan_canny
Junior Member
**
Offline Offline

Posts: 89

Thank You
-Given: 101
-Receive: 26


« Reply #1 on: June 13, 2013, 02:00:03 14:00 »

Well a GPS is nearly always only going to give you UTC values. Conversion to local time is messy since the Roman calendar of days months and years with 30 31 and 28 or 29 day months  plus leap years is arbitrary form a math point of view. Next we have the Babylonian base 60 of secs minutes and hours. Even UTC with its Grenwich meridian origin for the time has this messy notation for date and time. The mess is an accident of history and the code just has to deal with it. Maybe a future generation will move to Startrek's star datetime.
Logged
xpress_embedo
Active Member
***
Offline Offline

Posts: 173

Thank You
-Given: 122
-Receive: 254


« Reply #2 on: June 13, 2013, 03:46:54 15:46 »

hello!! gan_canny

I had solved my problem by adding 5:30 to my code and i had also checked everything you are talking about.

Quote
Conversion to local time is messy since the Roman calendar of days months and years with 30 31 and 28 or 29 day months  plus leap years is arbitrary form a math point of view.

The code written had a small flaw, i am putting correct code, which is working fine after debugging.

Code:
#include<p18f8722.h>
void main()
{
unsigned char Time_Data[] = "233000"; //23Hour 58Min 25 Seconds
unsigned char Date_Data[] = "280215"; //13 June 2013

unsigned char GPS_Date,GPS_Month,GPS_Year,GPS_Hour,GPS_Min,GPS_Sec;

unsigned char temp;

GPS_Date = (Date_Data[0]^0x30)*10 + (Date_Data[1]^0x30);
GPS_Month = (Date_Data[2]^0x30)*10 + (Date_Data[3]^0x30);
GPS_Year = (Date_Data[4]^0x30)*10 + (Date_Data[5]^0x30);

GPS_Hour = (Time_Data[0]^0x30)*10 + (Time_Data[1]^0x30);
GPS_Min = (Time_Data[2]^0x30)*10 + (Time_Data[3]^0x30);
GPS_Sec = (Time_Data[4]^0x30)*10 + (Time_Data[5]^0x30);

//Adding 30 Minutes
temp = GPS_Min + 30;
if(temp < 60)
{
GPS_Min = GPS_Min+30;
}
else
{
GPS_Min = temp - 60;
if(GPS_Hour < 24)
{
GPS_Hour = GPS_Hour+1;
}
else
{
GPS_Hour = 0;
switch(GPS_Month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
if(GPS_Date < 31)
{
GPS_Date = GPS_Date+1;
}
else
{
GPS_Date = 1;
if(GPS_Month < 12)
GPS_Month = GPS_Month+1;
else
{
GPS_Month = 1;
GPS_Year = GPS_Year+1;
}
}
break;

case 4:
case 6:
case 9:
case 11:
if(GPS_Date < 30)
{
GPS_Date = GPS_Date+1;
}
else
{
GPS_Date = 1;
if(GPS_Month < 12)
GPS_Month = GPS_Month+1;
else
{
GPS_Month = 1;
GPS_Year = GPS_Year+1;
}
}
break;

case 2:
temp = GPS_Year%4;
if(temp==0)
{
if(GPS_Date < 29)
{
GPS_Date = GPS_Date+1;
}
else
{
GPS_Date = 1;
if(GPS_Month < 12)
GPS_Month = GPS_Month+1;
else
{
GPS_Month = 1;
GPS_Year = GPS_Year+1;
}
}
}
else
{
if(GPS_Date < 28)
{
GPS_Date = GPS_Date+1;
}
else
{
GPS_Date = 1;
if(GPS_Month < 12)
GPS_Month = GPS_Month+1;
else
{
GPS_Month = 1;
GPS_Year = GPS_Year+1;
}
}
}
break;
}
}
}

//Now Time to Add 5 Hours
temp = GPS_Hour + 5;
if(temp < 24)
{
GPS_Hour = GPS_Hour+5;
}
else
{
GPS_Hour = temp - 24;
switch(GPS_Month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
if(GPS_Date < 31)
{
GPS_Date = GPS_Date+1;
}
else
{
GPS_Date = 1;
if(GPS_Month < 12)
GPS_Month = GPS_Month+1;
else
{
GPS_Month = 1;
GPS_Year = GPS_Year+1;
}
}
break;

case 4:
case 6:
case 9:
case 11:
if(GPS_Date < 30)
{
GPS_Date = GPS_Date+1;
}
else
{
GPS_Date = 1;
if(GPS_Month < 12)
GPS_Month = GPS_Month+1;
else
{
GPS_Month = 1;
GPS_Year = GPS_Year+1;
}
}
break;

case 2:
temp = GPS_Year%4;
if(temp==0)
{
if(GPS_Date < 29)
{
GPS_Date = GPS_Date+1;
}
else
{
GPS_Date = 1;
if(GPS_Month < 12)
GPS_Month = GPS_Month+1;
else
{
GPS_Month = 1;
GPS_Year = GPS_Year+1;
}
}
}
else
{
if(GPS_Date < 28)
{
GPS_Date = GPS_Date+1;
}
else
{
GPS_Date = 1;
if(GPS_Month < 12)
GPS_Month = GPS_Month+1;
else
{
GPS_Month = 1;
GPS_Year = GPS_Year+1;
}
}
}
break;
}
}
while(1);

}

This code is working fine, one can add any value to UTC time, to obtain time of any location.
Logged
bigtoy
Active Member
***
Offline Offline

Posts: 238

Thank You
-Given: 337
-Receive: 297


« Reply #3 on: June 18, 2013, 05:24:58 05:24 »

That's some interesting code you posted. I understand your main focus is getting it to work for UTC+5:30.  Does this code also work for negative UTC offsets? For example New York is UTC - 5.
Logged
xpress_embedo
Active Member
***
Offline Offline

Posts: 173

Thank You
-Given: 122
-Receive: 254


« Reply #4 on: August 17, 2013, 03:53:01 15:53 »

I had just added 30 minutes and 5 hrs.
Code is simple.

If you will look at it you will understand it properly.
I had just combine the ASCII Characters to form a proper date, time.
By this technique one can increment and decrement date and time easily.

For negative offset, change all unsigned char to char and subtract the time where i had added.
Not tested but should work.
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC