First of all, I will start with what I am trying to do. When I saw that the Do-More BRX's have microSD built in, I decided it would be a perfect medium to implement a new network tolerant data-logging system.
I connect my BRX to the LAN and log to a SQL server via a simple webpage and pull values out of the QueryString on the server side. The server then gives me a simple confirmation that all values are valid and recorded properly.
If I don't get this positive confirmation, the exact GET string plus a delimiter is simply appended to the bottom of the backup text file on the microSD card.
When a value is written successfully (server back online) if the backup file isn't empty, step through it, write the values, and delete the line from the file if it took.
Where I am running into problems is with the available file handling functions. The only function that really does something similar to what I want is the truncate file function. This means I have to start from the bottom of the file, read the last line, then truncate on success.
Unfortunately, there is not a good way of starting from the bottom and working my way up for a variable line length. Is there a way to seek backward from the current position to find the start of the last line? Since my string size varies depending on the exact data, I am basically trying to start at the end, seek backward 1.5x the last line length, and seeking forward to find the end of line from there to find the start position of the last line.
Ideally, I would be able to have an easy box to do the equivalent of the Unix "tail" command, where everything above the current file position is deleted. This should just be a small variation on the already available truncate command.
Am I missing and easer way of doing this? Should I just pad my string with garbage (which the server won't care about) to guarantee the same length of every line?