Report
2 years ago.

reading an ini file to load variables at startup & writing a circular logfile

Hi,

Suppose i have the following mbed.ini file:

  1. VAR Company="Name of company" loglevel=100
  2. ARRAYS items=13,18,19

At startup I want to load the Vars and the arrays in the program variables. Is this possible to do? is there any library available?

Second I want to send logging info to a text log file on the local mbed flash. to prevent the file is becoming to big, it has to keep only the last x logging lines. Any help is welcome..

Comment on this question

1 Answer

2 years ago.

I'm assuming that this is using the localFileSystem on an LPC1768.

1) reading the .ini file

I'm not aware of an libraries for parsing that format however it's not too tricky to do. if it's a fixed format (same fields in the same order) then opening the file as read only and using scanf() to extract the values is probably the easiest way to do it. Alternatively if you were to limit it to one value per line then strtok() would give an easy method to split each line into the bit before the = and the bit after. You can then compare the bit before to find out the type of value and perform the appropriate action depending on the result. This wouldn't be order dependent and would cope better with missing/default values.

2) Logging only a certain number of lines.

This is tricky, appending to a file is easy but removing lines from the front is harder without reading the whole thing in and then saving it again with the start missing. Not something you want to do every time you add a line.

Would it be acceptable to alternate between two files? Log 500 lines to file1.txt and then log 100 lines to file2.txt. Once file2.txt is full delete file1.txt and start logging to file1 again. Or alternatively once file2.txt is full delete file1.txt and start logging to file3.txt. This way you always have between 500 and 1000 lines of history but split between two files.


To post an answer, please log in.