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

Files at this revision

API Documentation at this revision

Comitter:
TeaPack_CZ
Date:
Tue Jun 10 21:41:52 2014 +0000
Parent:
3:250e9ea5985b
Commit message:
Simplified version of data logger.

Changed in this revision

logger.cpp Show annotated file Show diff for this revision Revisions of this file
logger.h Show annotated file Show diff for this revision Revisions of this file
logr.cpp Show diff for this revision Revisions of this file
logr.h Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/logger.cpp	Tue Jun 10 21:41:52 2014 +0000
@@ -0,0 +1,47 @@
+#include "loger.h"
+
+Logger::Logger() : local("local")
+{
+}
+
+void Logger::open()
+{
+    mk_path(get_files());
+    _loger = fopen(dst, "w");
+} 
+
+void Logger::save(char save[])
+{
+    fprintf(_loger,"%s",save);
+    nl();
+}
+
+void Logger::nl()
+{
+    fprintf(_logger,"\r\n");
+} 
+
+void Logger::close()
+{
+    fprintf(_logger,"### END FILE ###\r\n");
+    fclose(_logger);
+}
+
+int Logger::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)
+    {
+        num++;
+    }
+    closedir(d);
+    return num;
+}
+
+void Loger::mk_path(int nmbr)
+{
+    sprintf(dst,"/local/log%02d.txt",nmbr);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/logger.h	Tue Jun 10 21:41:52 2014 +0000
@@ -0,0 +1,58 @@
+/** Simple data logger using local flash memory.
+ *  Every start it creates a new file LOGnn.TXT, where nn stands for number of files.
+ *  Counting files on /local is based on an example code of LocalFileSystem class.
+ *  Every msg will be saved on a new line.
+ *
+ *                                      Writen by: Jan Crha (TeaPack_CZ), 2014
+ *
+ *
+ *  Example:
+ *  @code
+ *  #include "mbed.h"
+ *  #include "logger.h"
+ *  
+ *  Logger logg();
+ *  char bfr[127];
+ *  
+ *  int i=1;
+ *  char ch='L';
+ *  float f=1.1;
+ *
+ *  int main(){
+ *      logg.open();
+ *      sprintf(bfr,"format your msg as you wish, %d,%c,%f",i,ch,f);
+ *      logg.save(bfr);
+ *      logg.close();
+ *  }
+ *  @endcode
+ */
+
+#include "mbed.h"
+
+class Logger {
+public:
+    /** Class constructor */
+    Logger();
+    
+    /** Opening function */
+    void open();
+    
+    /** Closing function */
+    void close();
+    
+    /** Function for adding a new line to log */
+    void nl();
+    
+    /** Function for logging data */
+    void save(char[]);
+    
+private:
+
+    LocalFileSystem local;
+    FILE * _logger;
+    int get_files();
+    void mk_path(int);
+    char dst[30];
+    
+};
+
--- a/logr.cpp	Wed May 28 07:01:24 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,53 +0,0 @@
-#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);
-}
-
--- a/logr.h	Wed May 28 07:01:24 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,22 +0,0 @@
-#include "mbed.h"
-
-class Loger {
-    
-public:
-    Loger();
-    void log_open();
-    void log_close();
-    void log_int2(int,int);
-    void log_rn();
-    void log_chr(char[]);
-    
-private:
-    LocalFileSystem local;
-    FILE * _loger;
-    int get_files();
-    void mk_path(int);
-    char dst[30];
-    float time;
-    
-};
-