Заменить последнюю строку в текстовом файле SD-карты (gpx) на esp32C++

Программы на C++. Форум разработчиков
Anonymous
Заменить последнюю строку в текстовом файле SD-карты (gpx) на esp32

Сообщение Anonymous »

Я пытаюсь записать gpx-трек с GPS на SD-карту на ESP32. Поскольку я не совсем знаком с c, мне трудно справиться с этой задачей:
каждый раз, когда я записываю в файл новый сегмент дорожки, я хочу сначала удалить закрывающие строки, вот так:
p>

Код: Выделить всё

  if (gpsFixExists && dateIsValid && timeIsValid)
{
if (state.currentGPXFile == "")
{
String filename = "/" + String(state.dateYear) + String(state.dateMonth) + String(state.dateDay) + "_" + String(state.timeHours) + String(state.timeMinutes) + String(state.timeSeconds) + ".gpx";
state.currentGPXFile = filename.c_str();
File gpxFile = SD.open(state.currentGPXFile.c_str(), FILE_WRITE);
// Write GPX header and metadata
gpxFile.println("");
gpxFile.println("");
gpxFile.println("");
gpxFile.println("" + filename + "");
gpxFile.println("Track log generated by Open Rally Computer");
gpxFile.println("");
gpxFile.println("Track Log");
gpxFile.close();
}

// Open the file to append data
File gpxFile = SD.open(state.currentGPXFile.c_str(), FILE_WRITE);
if (gpxFile)
{
// Move to the end of the file, then seek back to overwrite the closing tags
long position = gpxFile.size() - strlen("") - 1; // Adjusted to account for newline characters
gpxFile.seek(position);
// Write the new track point
gpxFile.println("");
gpxFile.println("" + String(state.currentAltitude, 2) + "");
gpxFile.println("" + String(state.dateYear) + "-" + String(state.dateMonth) + "-" + String(state.dateDay) + "T" + String(state.timeHours) + ":" + String(state.timeMinutes) + ":" + String(state.timeSeconds) + "Z");
gpxFile.println("");
// Re-append the closing tags
gpxFile.println("");
gpxFile.close();
}
}

эти две строки неверны:

Код: Выделить всё

      long position = gpxFile.size() - strlen("") - 1; // Adjusted to account for newline characters
gpxFile.seek(position);
как правильно заменить закрывающую линию новым сегментом дорожки?
Большое спасибо!

Подробнее здесь: https://stackoverflow.com/questions/784 ... e-on-esp32

Вернуться в «C++»