Host Engineering Forum
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 25, 2018, 09:01:12 pm

Login with username, password and session length

Pages: [1]
Author Topic: File Handling functions  (Read 101 times)
Posts: 1

« on: May 16, 2018, 10:52:08 am »

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?
Full Member
Posts: 34

« Reply #1 on: May 16, 2018, 03:58:55 pm »

I don't have much experience with the BRX file system but I have a dirty solution for you.  What if you use two files and a pointer/variable to define which one is active?  Log your failures to the active file.  When you are ready to process your re-send log do the following.

  • Truncate the secondary file
  • Mark the secondary file as the active
  • Process your re-sends and log any failures in the new "active" file

Instead of trying to delete from the existing file, build a new one.  The downside would be the additional writes incurred on the flash storage if you experience outages regularly.

Do you have/need a way to prevent an infinite resend loop?  What happens if the connection is good but the data is malformed for some reason?

Finally, in regards to string padding, this was often done back in the day with fixed width DB records.  Just be careful when padding with garbage.  Spaces can be easier to trim off at the server end.
Bit Weenie
Host Moderator
Posts: 2297

« Reply #2 on: May 17, 2018, 03:57:31 pm »

For padding purposes, STRPRINT has a Fill() command:

Fill a String with a Character
Fill(hexadecimal constant, fill length)

"My dog has fleas" Fill(0x20,5) "and so does mine."
This inserts 5 spaces (ASCII 0x20 is a space)

The fill length can be an element (like D42), it doesn't have to be a constant.

Pages: [1]
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM