Hey all,
Still a little new to all this so any help would be great. I'm making a sketch to parse and store the Longitude and Latitude from my GPS as doubles so i can do math on them later.
The only problem is I'm getting this error :
"In function 'char gps_read()':
error: invalid conversion from 'char*' to 'char' In function 'int gps_decode(char)':
In function 'double get_latitude(int, char)':
In function 'double get_longitude(int, char)':"
Here's the code :
int rxPin = 0;
int txPin = 1;
char GPR[7] = "$GPRMC";
char gps_read();
int gps_decode(char);
double get_latitude(int, char);
double get_longitude(int, char);
void setup() {
char line[300] = "";
pinMode (rxPin, INPUT);
pinMode (txPin, OUTPUT);
Serial.begin(4800);
for (int i=0; i<300; i++) {
line[i] = ' ';
}
}
void loop() {
char a = gps_read();
int b = gps_decode(a);
double x = get_latitude(a, b);
double y = get_longitude(a, b);
Serial.print(x);
Serial.print(y);
}
char gps_read() {
int GPS;
int counta=0;
char line[300] = "";
GPS=Serial.read(); // Read a byte of the serial port
line[counta]=GPS; // If there is serial port data, it is put in the buffer
counta++;
//Serial.print(GPS, BYTE); // Prints out raw GPS data
return line;
}
int gps_decode(char) {
char GPR[7] = "$GPRMC";
int count=0;
int good=0;
for (int i=1;i<7;i++){ // Verifies if the received command starts with $GPR
if (line[i]==GPR[i-1]){
good++;
}
}
if(good==6){ // If yes, continue and process the data
for (int i=0;i<300;i++){
if (line[i]==','){ // check for the position of the "," separator
index[count]=i;
count++;
}
if (line[i]=='*'){ // check for the position of the "*" separator
index[12]=i;
count++;
}
}
}
return index;
}
double get_latitude(int, char) {
int index[13];
char line[300];
double dbl_latitude;
for (int i=0;i<12;i++){
for (int j=index[i];j<(index[i+1]-1);j++){
if (i == 2){ // Latitude
for (int j=index[i];j<(index[i+1]-1);j++){
latitude[y] = line[j+1];
y++; }
dbl_latitude = atof(latitude);
Serial.print("Latitude = ");
Serial.println(dbl_latitude);
break;
}
}
}
return dbl_latitude;
}
double get_longitude(int, char) {
int index[13];
char line[300];
double dbl_longitude;
for (int i=0;i<12;i++){
for (int j=index[i];j<(index[i+1]-1);j++){
if (i == 4){ // Longitude
for (int j=index[i];j<(index[i+1]-1);j++){
longitude[x] = line[j+1];
x++; }
dbl_longitude = atof(longitude);
Serial.print("Longitude = ");
Serial.println(dbl_longitude);
break; //
}
}
}
return dbl_longitude;
}
Thanks,
Cory