簡體   English   中英

錯誤:“track_t”未在此范圍內聲明

[英]error: 'track_t' was not declared in this scope

我正在擺弄一個 Arduino 項目,我的主文件中有這些結構:

struct gpsCoord_t {
  long latitude;
  long longitude; 
};

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

接下來,我有一個函數可以將這種類型的變量轉儲到同一個文件中的串行總線:

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);
}

編譯器產生 2 個沒有行號的錯誤,我相信第一個錯誤是由第二個錯誤引起的:

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

編輯這里是完整的文件:

#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;
}

當我將整個 dumpTrack 函數放在評論中時,錯誤就會消失。 我已經檢查了幾次是否有錯別字,但沒有找到。

您似乎將此代碼編譯為 C。

代替

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

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

我懷疑標題中的某個地方有一個名為 dumpTrack 的變量。 為什么不直接將函數重命名為其他名稱?

此外,通常最好避免使用保留字作為函數名; “循環”不是函數名稱的好選擇。

編輯:后者可能是您的問題的原因。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM