To read a log file

From ThaiEasyElecWiki
Jump to: navigation, search

There are 3 functions to be used to read a log file.

date_t log_get_date_before(unsigned char date_before) //get the date before today
int log_open_read(date_t date) //open a log file to read, return 0 on success
int log_goto_line(unsigned long _line) //goto line from opening log file and save to sd_buffer, return 0 on success
int log_readln(void) //read line and save to sd_buffer, return 0 on success


Since log files are named according to dates. There are 2 methods provided to open the target file.

1. To read the log file of a particular day (the exact date is known), simply use log_open_read.

For example, to read the log file of 14 Feb 2012:

date_t x;
x.date = 14;
x.month = 2;
x.year = 2012;
if (log_open_read(x) == 0){
   ...

2. If you want to read recent log files, for example, log file of today, yesterday or even 2 or more days ago. Just use log_get_date_before before using log_open_read.

For example, to read today's log file:

if (log_open_read(log_get_date_before(0)) == 0){
   ...

To read yesterday's log file:

if (log_open_read(log_get_date_before(1)) == 0){
   ...

You can put n between 0-255 in the function to read the log file of n days before today.


After using log_open_read, you can use log_readln continuously to read lines until it returns -1. Or you can jump to a particular line using log_goto_line. Remember that after using log_readln, data is written to sd_buffer.

Personal tools
Namespaces
Variants
Actions
Navigation
Articles and Tutorials
Shortcut (mini SUN7)
Toolbox