Logger using local flash memory and creating a new file every start.

logr.cpp

Committer:
TeaPack_CZ
Date:
2014-05-28
Revision:
3:250e9ea5985b

File content as of revision 3:250e9ea5985b:

#include "logr.h"

Loger::Loger() : local("local")
{
}

void Loger::log_open()
{
    mk_path(get_files());
    _loger = fopen(dst, "w");
}

void Loger::log_int2(int in1, int in2)
{
    fprintf(_loger,"%d,%d,",in1,in2);
    return;
} 

void Loger::log_chr(char save[])
{
    fprintf(_loger,"%s",save);
    log_rn();
}

void Loger::log_rn()
{
    fprintf(_loger,"\r\n");
} 

void Loger::log_close()
{
    fprintf(_loger,"### END FILE ###\r\n");
    fclose(_loger);
}

int Loger::get_files()
{
    int num=0;
    DIR *d = opendir("/local");               // Opens the root directory of the local file system
    struct dirent *p;
    while((p = readdir(d)) != NULL)
    {         // Print the names of the files in the local file system
        num++;
    }
    closedir(d);
    return num;
}

void Loger::mk_path(int nmbr)
{
    sprintf(dst,"/local/logg%02d.txt",nmbr);
}