|
Last updated: 4 November 2007 |
Subject: GPS to Autostar
Sent: Thursday, November 1, 2007 02:00:24
From: John Farrant (johnfarrant@gmail.com)
Hi Mike
Thanks again for all your efforts in maintaining this site.
I thought you might be interested in the following PocketC code which
reads NMEA messages and displays UT time, Latitude, Longtitude and
number of GPS satellites. I run it on a PocketPC via com7 (BlueTooth)
using a Bluetooth enabled GPS receiver. The data is then written out to
a text file which can then be transferred to Autostar using #:St# and
#:Sg#
#include "/pocketc/pcheader.h"
char zz,cc,ccc;
string meade,word1,word2,word3,word4,word5,word6,word7;
string inst[10],reply,all;
string myyear,mymonth,myday;
string local,myhour2,myhour,mymin,mysec,ut;
string latdeg,latmin,longdeg,longmin,lat,long;
int myhour3,status,count;
int wind_event, ret,line,c1;
readchar(string item)
{
int h,m,s,nshandle;
int timedate[10];
c1=0;
ccc="";
word1="";
//$GPGGA,170834,4124.8963,N,08151.6838,W,1,05,1.5,280.2,M,-34.0,M,,,*75
//------,17:08:34,4124'-,N,08151'---,W,1,5 sats,,,,,,,,*75
getlocaltime (timedate);
line=0;
reply="";
all="";
do
{
cc=readbyte(ret);
line++;
if(line>10)
{
putsl("Read error - redo ..");
showconsole();
getc();
quit();
}
}
while(cc!="$")
do
{
cc=readbyte(ret);
all=all+cc;
}
while(cc!=(char)0x0d)
do
{
ccc=strmid(all,c1,1);
word1=word1+ccc;
c1++;
}
while(ccc!=",")
ccc="";
word2="";
do
{
ccc=strmid(all,c1,1);
word2=word2+ccc;
c1++;
}
while(ccc!=",")
ccc="";
word3="";
do
{
ccc=strmid(all,c1,1);
word3=word3+ccc;
c1++;
}
while(ccc!=",")
word4="";
do
{
ccc=strmid(all,c1,1);
word4=word4+ccc;
c1++;
}
while(ccc!=",")
word5="";
do
{
ccc=strmid(all,c1,1);
word5=word5+ccc;
c1++;
}
while(ccc!=",")
word6="";
do
{
ccc=strmid(all,c1,1);
word6=word6+ccc;
c1++;
}
while(ccc!=",")
word7="";
do
{
ccc=strmid(all,c1,1);
word7=word7+ccc;
c1++;
}
while(ccc!=",")
word7="";
do
{
ccc=strmid(all,c1,1);
word7=word7+ccc;
c1++;
}
while(ccc!=",")
myhour=strmid(word2,0,2);
mymin=strmid(word2,2,2);
mysec=strmid(word2,4,2);
word4=strleft(word4,1);
word4=" "+word4;
word6=strleft(word6,1);
word6=" "+word6;
word7=strleft(word7,2);
word7=" "+word7;
latdeg=strmid(word3,0,2);
latmin=strmid(word3,2,2);
longdeg=strmid(word5,0,3);
longmin=strmid(word5,3,2);
lat=latdeg+" "+latmin+"'"+word4;
long=longdeg+" "+longmin+"'"+word6;
ut=myhour+":"+mymin+":"+mysec;
putsl("");
putsl(" © J Farrant 26/10/07");
putsl("");
putsl("GMT: "+ut);
putsl("Latitude: "+lat);
putsl("Longtitude: "+long);
putsl("Sat count: "+word7);
all=ut+","+lat+","+long+",";
DeleteFile("gpsLine.txt");
nshandle = fileopen("gpsLine.txt",0,0x00003002);
filewrite (nshandle,all+(char)0x0a,400);
fileclose(nshandle);
getc();
quit();
reply=strmid(reply,6,6);
myhour=strleft(reply,2);
mymin=strmid(reply,2,2);
mysec=strmid(reply,4,2);
myhour3=myhour;
myhour3=myhour3+2;
myhour2=myhour3;
h=myhour3;
m=mymin;
s=mysec;
timedate[4]=h;
timedate[5]=m;
timedate[6]=s;
setlocaltime (timedate);
getlocaltime (timedate);
local="Local Time "+myhour2+":"+mymin+":"+mysec;
ut="Universal Time "+myhour+":"+mymin+":"+mysec;
putsl(ut);
putsl(local);
getc();
quit();
if(cc=="")
{
if(strmid(reply,17,4)=="1")
reply=reply+" (ON)";
else if(strmid(reply,17,4)=="0")
reply=reply+" (OFF)";
putsl(reply);
showconsole();
}
sleep(200);
return();
}
goodbye()
{
commsetmask(ret,0);
killtimer(1);
serclose();
}
main()
{
BS_3STATE;
settimer(1,200);
ret=seropenex("COM7:",4800,"8N1N",1000);
if(ret==0)
{
alert("Can't open serial port!");
quit();
}
commsetmask(ret,EV_RXCHAR);
showconsole();
//devicesip(1); // Show keyboard
atexit(goodbye); // Prevent crash on exit!
while(count<3)
{
commwait(ret,0);
wind_event=event(1);
sleep(0);
switch(wind_event)
{
case PM_TIMER:
break;
case PM_CHAR:
{
sleep(10);
readchar("Get Time: ");
}
break;
}
}
getc();
quit();
}
Clear skies to all
John Farrant
Go back to the Autostar Information page.
Go back to the ETX Home Page.