каждый раз, когда я записываю в файл новый сегмент дорожки, я хочу сначала удалить закрывающие строки, вот так:
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