is there any C code for GPS
grapple53
Posts: 2
I am more familiar with C++ so i am using the activity board and want to get GPS capabilities for accurate time and location readings. If anyone has any suggestions please let me know i could really use the help.
Comments
// i am getting some nmea text... however, getting error when it prints this line: $GPGGA,024749.000,3944.6649,N,07500.3298,W,1,06,1.1,54.6,M,-34.0,M,
//MY CODE BELOW
/**
* This is the main serial_inout program file.
*/
#include "simpletools.h"
#include "fdserial.h"
#define NONE 0
#define DEC 1
#define HEX 2
#define BIN 3
#define CHR 4
void serout(text_t *ser, int delay, char* string, int type, int val, int end);
void serin(text_t *ser, int wait, void (*function)(), int type, void* value);
void printnewline() {
print("\n");
}
int main(void)
{
int inpin = 3;
int outpin= 2;
int baud = 9600;
int value = 0x55;
text_t *ser = fdserial_open(inpin, outpin, 0, baud);
int number, i;
char location[512];
i=-1;
pause(200);
print("SEROUT/SERIN DEMO\n");
char c;
while(1)
{
//ser = fdserial_open(inpin, outpin, 0, baud);
//serout(ser, 100, "HELLO", 0, value, CR);
//serout(ser, 1, "DEC VAL ", DEC, value, CR);
//serout(ser, 1, "HEX VAL ", HEX, value, CR);
//serout(ser, 1, "BIN VAL ", BIN, value, CR);
//serout(ser, 1, "CHR VAL ", CHR, value, CR);
//print("Enter DEC: ");
// serin(ser, 5000, printnewline, DEC, &value);
// print("Got DEC %d\n", value);
//print("Enter HEX: ");
// serin(ser, 5000, printnewline, HEX, &value);
//print("Got HEX %x\n", value);
//print("Enter BIN: ");
// serin(ser, 5000, printnewline, BIN, &value);
//print("Got BIN %b\n", value);
//http://www.parallax.com/sites/default/files/downloads/28501-PMB-688-v0.1.pdf
//print("Enter CHR: ");
// value="";
serin(ser, 5000, printnewline, CHR, &value);
print("Got Char %c\n", value);
//http://www.parallax.com/sites/default/files/downloads/28506-VPN1513Datasheet.pdf
//c = fdserial_rxChar(ser);
//if(c != -1)
//{
// print("You typed: %c\n", c);
//}
// print("value %c\n",text_t);
if(value =='$')
{
// print("gps: \n");
// do
// {
//i++;
// location = readChar(ser);
//i = i+1;
// print("loc num %d\n" ,i);
//}while(location[i-1]!='\n');//while(location[i-1]!='*');//while(i<512);// while(location!='\n');
i = 0;
location = readChar(ser);
while(location!='*')
{
location = readChar(ser);
i++;
}
// if(charindex("$GPRMC",location)>0)
//{
//print("gps coord");
//}
// location=0;
print("location %s",location);
// return;
pause(100);
}
else
{
// location[] = "";
// print("no $$ \n\n");
serin(ser, 5000, printnewline, CHR, &value);
// text_t *ser = fdserial_open(inpin, outpin, 0, baud);
// print("%s",text_t);
// pause(100);
}
// ser = "";
//serin(ser, 1000, printnewline, CHR, &value);
}
return 0;
}
void serout(text_t *ser, int delay, char* string, int type, int val, int end)
{
int n = 0;
int len = strlen(string);
for(n = 0; n < len; n++) {
writeChar(ser, string[n]);
pause(delay);
}
if(DEC == type) {
writeDec(ser, val);
pause(delay);
writeChar(ser, end);
}
else if(HEX == type) {
writeHex(ser, val);
pause(delay);
writeChar(ser, end);
}
else if(BIN == type) {
writeBin(ser, val);
pause(delay);
writeChar(ser, end);
}
else if(CHR == type) {
writeChar(ser, val);
pause(delay);
writeChar(ser, end);
}
else {
writeChar(ser, end);
}
}
void serin(text_t *ser, int wait, void (*function)(), int type, void* value)
{
//print("dddd\n");
char buf[33]; // big enough for hex, dec, bin, or char
while(--wait > -1) {
if(fdserial_rxReady(ser))
break;
pause(1);
}
if(wait < 0) {
// writeLine(ser, "No input");
//print("nodata \n");
function();
return;
}
readStr(ser, buf, 33);
if(DEC == type) {
sscan(buf, "%d", value);
}
else if(HEX == type) {
sscan(buf, "%x", value);
}
else if(BIN == type) {
sscan(buf, "%b", value);
}
else if(CHR == type) {
sscan(buf, "%c", value);
}
}
What do you mean by "getting error"? Is the above line the output from the program? What where you expecting?
If you use code tags when you post code, it will be much easier for us to read.
[noparse] [/noparse]
The above will show up as:
Without code tags the forum software removes indentations which destroys the formatting of the code.