1

I'm fiddling with an Arduino project where I've got these structs in my main file:

struct gpsCoord_t {
  long latitude;
  long longitude; 
};

struct track_t {
  char code[4];
  gpsCoord_t bounds[4];
  gpsCoord_t points[4];
};

Next to that I've got a function to dump variables of this type to the serial bus in that same file:

void dumpTrack(track_t track) {
  Serial.print("\nTrack: ");
  Serial.print(track.code);
  Serial.print("\nTrack bounds: ");
  Serial.print("\n- 1 lat: ");
  Serial.print(track.bounds[0].latitude);
  Serial.print("\n- 1 lon: ");
  Serial.print(track.bounds[0].longitude);
}

The compiler produces 2 errors without line numbers from which I believe the first one is caused by the second one:

error: variable or field 'dumpTrack' declared void
error: 'track_t' was not declared in this scope

EDIT here's the complete file:

#include <Wire.h> //I2C library
#include <I2C_eeprom.h>
#include <SoftwareSerial.h>
#include <TinyGPS.h>

I2C_eeprom ee(0x50);

const int baseTrackAddress = 3;
const int trackSize = 68;
const int maxTracks = 480;

int powerOnLED = 2;
int gpsFixLED = 3;
int trackFoundLED = 4;
int errorLED = 6;
int gpsSensor = 7;

TinyGPS gps;
SoftwareSerial nss(gpsSensor, 255);

int calcTrackAddress(int trackId) {
  return (trackId*trackSize) + baseTrackAddress;
}

struct gpsCoord_t {
  long latitude;
  long longitude; 
};

struct track_t {
  char code[4];
  gpsCoord_t bounds[4];
  gpsCoord_t points[4];
};

track_t tracks[maxTracks];

void setup() 
{
  Serial.begin(115200);
  Serial.flush();
  Serial.print("Demo I2C eeprom library ");
  Serial.print(I2C_EEPROM_VERSION);
  Serial.println("\n");

  strcpy(tracks[0].code, "X11");
  tracks[0].bounds[0].latitude = 0;
  tracks[0].bounds[0].longitude = 0;

  tracks[0].points[0].latitude = 0;
  tracks[0].points[0].longitude = 0;

  ee.writeBlock(3, (uint8_t*)&tracks[0], trackSize);
}

void loop() 
{
  Serial.println("\nTEST: 64 byte page boundary writeBlock");
  dumpEEPROM(0, 255);
  while(1);
}

void dumpTrack(track_t track) {
  Serial.print("\nTrack: ");
  Serial.print(track.code);
  Serial.print("\nTrack bounds: ");
  Serial.print("\n- 1 lat: ");
  Serial.print(track.bounds[0].latitude);
  Serial.print("\n- 1 lon: ");
  Serial.print(track.bounds[0].longitude);
}

void readTrack(int trackId) {
  track_t track;
  ee.readBlock(60, (uint8_t*)&track, 10);
}

void readTracks() {

}

void dumpEEPROM(unsigned int addr, unsigned int length)
{
  // block to 10
  addr = addr / 10 * 10;
  length = (length + 9)/10 * 10;

  byte b = ee.readByte(addr); 
  for (int i = 0; i < length; i++) 
  {
    if (addr % 10 == 0)
    {
      Serial.println();
      Serial.print(addr);
      Serial.print(":\t");
    }
    Serial.print(b);
    b = ee.readByte(++addr); 
    Serial.print("  ");
  }
  Serial.println();
}

void ProcessCommand(char* command) {
  //switch(*command==) 
}

char* ReadSerialCommand() {
  int i=0;
  char commandbuffer[100];

  if(Serial.available()){
     delay(100);
     while( Serial.available() && i< 99) {
        commandbuffer[i++] = Serial.read();
     }
     commandbuffer[i++]='\0';
  }

  if(i>0)
    return (char*)commandbuffer; 
  else
    return 0L;
}

When I put the entire dumpTrack function in comment, the errors go away. I've checked a couple of times for a typo but failed to find any.

2
  • Please provide a complete (but minimal) file which has this problem.
    – Mankarse
    Aug 24, 2012 at 6:53
  • The problem is likely on the lines just before dumpTrack.
    – Bo Persson
    Aug 24, 2012 at 7:01

2 Answers 2

1

It seems you are compiling this code as C.

Instead of

struct track_t {
  char code[4];
  gpsCoord_t bounds[4];
  gpsCoord_t points[4];
};

write

typedef struct {
  char code[4];
  gpsCoord_t bounds[4];
  gpsCoord_t points[4];
} track_t;
4
  • 1
    Or keep the definition as it is and refer to the type as struct track_t. Aug 24, 2012 at 7:41
  • @KeithThompson your solution DID work! How do I proceed to mark what as an answer? Aug 24, 2012 at 7:45
  • @SylvainGirard: You can't accept a comment as an answer. To accept an answer, click the check mark next to it. Aug 24, 2012 at 8:01
  • @arrowdodger: I didn't post an answer, just a comment on yours. Your answer is correct; I just expanded on it. (Feel free to edit my comment into your answer if you like.) Aug 24, 2012 at 9:29
0

I suspect somewhere in a header there is a variable called dumpTrack. Why don't you just rename the function to something else?

Also in general it is good to avoid using reserved words as function names; "loop" is not a good choice for a function name.

Edit: the latter is probably the reason for your problem.

1
  • loop is a required function name for Arduino. Aug 24, 2012 at 7:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.