Duron 发表于 2014-12-9 01:03:37

求助,编译报错,什么原因呢


#include <string.h>
#include <ctype.h>
#include <math.h>
#include <stdlib.h>

int ledPin = 13;                  // LED test pin

int byteGPS = -1;
char linea;
char tmp;
char ew;
char ns;
char av;
float Latitude;
float Longitude;
char comandoGPR = "$GPRMC";
int cont=0;
int bien=0;
int conta=0;
int indices;
void setup() {
LcdInit();
LcdClear();
memset(tmp, 0x0, 10 * sizeof(char));
pinMode(ledPin, OUTPUT);       // Initialize LED pin
//pinMode(rxPin, INPUT);
//pinMode(txPin, OUTPUT);
Serial1.begin(9600);
Serial.begin(115200);
memset(linea, 0x0, 300 * sizeof(char));
}

void loop() {
digitalWrite(ledPin, HIGH);
byteGPS=Serial1.read();         // Read a byte of the serial port
if (byteGPS == -1) {         // See if the port is empty yet
    delay(100);
} else {   // note: there is a potential buffer overflow here!
    linea=byteGPS;      // If there is serial port data, it is put in the buffer
    conta++;                     
    //Serial.write(byteGPS);
    if (byteGPS==13){         // If the received byte is = to 13, end of transmission
      // note: the actual end of transmission is <CR><LF> (i.e. 0x13 0x10)
      digitalWrite(ledPin, LOW);
      cont=0;
      bien=0;
      // The following for loop starts at 1, because this code is clowny and the first byte is the <LF> (0x10) from the previous transmission.
      for (int i=1;i<7;i++){   // Verifies if the received command starts with $GPR
      if (linea==comandoGPR){
          bien++;
      }
      }
      if(bien==6){               // If yes, continue and process the data
      for (int i=0;i<300;i++){
          if (linea==','){    // check for the position of the"," separator
            // note: again, there is a potential buffer overflow here!
            indices=i;
            cont++;
          }
          if (linea=='*'){    // ... and the "*"
            indices=i;
            cont++;
          }
      }
      /*
      Serial.println("");      // ... and write to the serial port
      Serial.println("");
      Serial.println("---------------");
      for (int i=0;i<12;i++){
          switch(i){
            case 0 :Serial.print("Time in UTC (HhMmSs): ");break;
            case 1 :Serial.print("Status (A=OK,V=KO): ");break;
            case 2 :Serial.print("Latitude: ");break;
            case 3 :Serial.print("Direction (N/S): ");break;
            case 4 :Serial.print("Longitude: ");break;
            case 5 :Serial.print("Direction (E/W): ");break;
            case 6 :Serial.print("Velocity in knots: ");break;
            case 7 :Serial.print("Heading in degrees: ");break;
            case 8 :Serial.print("Date UTC (DdMmAa): ");break;
            case 9 :Serial.print("Magnetic degrees: ");break;
            case 10 :Serial.print("(E/W): ");break;
            case 11 :Serial.print("Mode: ");break;
            case 12 :Serial.print("Checksum: ");break;
          }
          for (int j=indices;j<(indices-1);j++){
            Serial.print(linea);
          }
         
          Serial.println("");
      }
      Serial.println("---------------");
      */
      for (int j=indices;j<(indices-1);j++){
          av = linea;
      }
      
      for (int j=indices,k=0;j<(indices-1);j++,k++){
          tmp = linea;
      }
      Latitude = GPSTofloat(tmp);
      memset(tmp, 0x0, 10 * sizeof(char));
      
      for (int j=indices;j<(indices-1);j++){
          ns = linea;
      }
      
      for (int j=indices,k=0;j<(indices-1);j++,k++){
          tmp = linea;
      }
      Longitude = GPSTofloat(tmp);
      memset(tmp, 0x0, 10 * sizeof(char));
      
      for (int j=indices;j<(indices-1);j++){
            ew = linea;
      }
      sprintf(tmp,"%f",Latitude);
      Serial.print(tmp);
      Serial.print(ns);
      Serial.print(",");
      sprintf(tmp,"%f",Longitude);
      Serial.print(tmp);
      Serial.print(ew);
      Serial.println();
      }
      
      conta=0;                  // Reset the buffer
      memset(linea, 0x0, 300 * sizeof(char));
    }
}
}

float GPSTofloat(char[] *gps){
float x = atof(gps);
return floor(x/100) + floor(floor(x)/100-floor(x/100))*5/3 + (x-floor(x))/600000;
}

编译时报错

Arduino: 1.0.6 (Mac OS X), Board: "Arduino Mega 2560 or Mega ADK"
/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega2560 -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=106 -I/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino -I/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/variants/mega /var/folders/p6/xr61pncx78783l_m56dr3brw0000gn/T/build5653185780976774174.tmp/sketch_dec07a.cpp -o /var/folders/p6/xr61pncx78783l_m56dr3brw0000gn/T/build5653185780976774174.tmp/sketch_dec07a.cpp.o
sketch_dec07a:9: error: expected ',' or '...' before '*' token
sketch_dec07a.ino: In function 'void setup()':
sketch_dec07a:22: error: 'LcdInit' was not declared in this scope
sketch_dec07a:23: error: 'LcdClear' was not declared in this scope
sketch_dec07a.ino: In function 'void loop()':
sketch_dec07a.ino:116: warning: format '%f' expects type 'double', but argument 3 has type 'float'
sketch_dec07a.ino:120: warning: format '%f' expects type 'double', but argument 3 has type 'float'
sketch_dec07a.ino: At global scope:
sketch_dec07a:132: error: expected ',' or '...' before '*' token
sketch_dec07a.ino: In function 'float GPSTofloat(char*)':
sketch_dec07a:133: error: 'gps' was not declared in this scope

不明白为什么
error: expected ',' or '...' before '*' token
error: 'gps' was not declared in this scope
页: [1]
查看完整版本: 求助,编译报错,什么原因呢