Hello community,
I am using the SMARTGPU2 for a GPS data logging project and have come across a bizarre behaviour when trying to log data to a file on the SD card.
The behaviour is that all my GPS data is passed correctly and logged into the file, however it seems to OVERWRITE any existing data stored in the file, rather than APPEND to it. As you can imagine - this isn't great for wanting to keep lots of GPS data strings!
Has anyone experienced this behaviour using the SMARTGPU2 before?
I have looked in the header file for the SmartGPU2 library (attached for reference including the .cpp) and the function to write to the file on the SD card is defined as below:
SDFwriteFile(char[], NUMBEROFBYTES,NUMBEROFBYTES*, WORKSPACEBLOCK); //Bytes to Write, Succesfully Written Bytes, file object # to write bytes
The end result is that the file contains my latest GPS NMEA data passed from my char[] array as expected, but any previous data is overwritten (not good!).
So, in the absence of any parameters to change the write mode to append I started looking through the header for any functions that may help:
FILERESULT SDFopenFile(FILENAME, OPENMODE, WORKSPACEBLOCK); //opens an existing file in READONLY, WRITEONLY or READWRITE mode on the received object # workspace
The code above suggests that I must used READWRITE in order to query the existing data within the file - therefore I am using READWRITE.
SDFsetFilePointer(POINTERPOSITION, WORKSPACEBLOCK); // set/move file pointer of file object # workspace
This seems to suggest that there is a pointer - perhaps I can query the file and set the pointer to the end (and even use ASCII to send a carriage return aka start a new line. Seems to be a bit of a weird way of doing things but maybe this would work?
SDFgetFilePointer(POINTERPOSITION*, WORKSPACEBLOCK); // get file pointer of file object # workspace
I thought that this would be a great way to find the position - however, even in my existing file containing a line of data ii seems to return an empty value. My code shown below for reference (assume all initialisation complete at this point):
char buffer[50]={0};
String pointerpos="Pointer positioned @: ";
long unsigned int pointer=0;
lcd.SDFgetFilePointer(&pointer, WORKSPACE0); // should return pointer position to my pointer variable
pointerpos+=pointer; // Append my long int from pointer to my String pointerpos
pointerpos.toCharArray(buffer, pointerpos.length()); //convert my String to a char array (SMARTGPU2 expects Char array as an input)
lcd.string(10,row,MAX_X_LANDSCAPE,MAX_Y_LANDSCAPE,buffer,0); row+=15; //write my full string out to the screen for debugging.
Or perhaps this would be an alternative method?
SDFreadFile(char[], NUMBEROFBYTES, NUMBEROFBYTES*, WORKSPACEBLOCK); //Bytes to Read, Succesfully Read Bytes, file object # to read bytes from
SDFwriteFile(char[], NUMBEROFBYTES,NUMBEROFBYTES*, WORKSPACEBLOCK);
This could work - I could read the contents of the file to a buffer then manually append my new data to the buffer and write the whole lot? Seems like it may be too memory intensive if I start having thousands of logged lines though?
If you've read this far I certainly appreciate it! Any guidance at this point would be fantastic and many thanks in advance.
SMARTGPU2.cpp (51.8 KB)
SMARTGPU2.h (20.2 KB)