monitor
Dependents: 09_PT1000 10_PT1000 11_PT1000
Revision 1:19313470f629, committed 2014-07-28
- Comitter:
- rs27
- Date:
- Mon Jul 28 14:36:32 2014 +0000
- Parent:
- 0:f0fbbfdca478
- Commit message:
- 10 PT1000 monitor
Changed in this revision
monitor.cpp | Show annotated file Show diff for this revision Revisions of this file |
monitor.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/monitor.cpp Sat Jul 26 07:27:20 2014 +0000 +++ b/monitor.cpp Mon Jul 28 14:36:32 2014 +0000 @@ -2,19 +2,38 @@ #include <stdarg.h> #include <ctype.h> #include "monitor.h" +#include "ConfigFile.h" +#include "SDFileSystem.h" +#include "FATDirHandle.h" -extern Serial pc; -extern Buffer <char> buf; +extern SDFileSystem sd; // definiert in main +extern Serial pc; // definiert in main +extern Buffer <char> buf; // definiert in main +extern ConfigFile cfg; // definiert in main +extern char value[BUFSIZ]; // definiert in main + +#define COMMAND_MAX 9 +#define COMMAND_LEN 7 -#define COMMAND_MAX 5 -#define COMMAND_LEN 7 -const char command[COMMAND_MAX][COMMAND_LEN] = {"DATE","DUMP","HELP","SET","TIME"}; +const char command[COMMAND_MAX][COMMAND_LEN] = {"DATE","DEL","DIR","DUMP","FILL","HELP","LIST","SET","TIME"}; + +char buffer[100]; + +// globale Variablen + +char com_line[COM_LINE_LEN]; // Aktuelle Eingabezeile +uint8_t ComLinePtr, ComLineTop; // Cursor Position und Zeilenlänge + +uint8_t cr_flag; + +// uint16_t status[8]; //----------------------------------------------------------------------------- -// destructor +// initialisierung -monitor::monitor(void) +void mon_init(void) { + uint8_t i; for (i = 0; i < COM_LINE_LEN; com_line[i++] = 0); @@ -25,6 +44,7 @@ // 1 Rohdaten ausgeben // 2 Temperaturwert in Float Darstellung + /* status[0] = 2; // Temperaturwerte ausgeben status[1] = 0; status[2] = 0; @@ -33,13 +53,13 @@ status[5] = 0; status[6] = 0; status[7] = 0; - + */ } //----------------------------------------------------------------------------- // destructor -void monitor::parser (void) +void parser (void) { uint8_t i, ch, tch, top, bottom, len; int8_t res; @@ -112,11 +132,16 @@ switch(i) // Programmaufruf { - case 0: date(); break; - case 1: dump(); break; - case 2: help(); break; - case 3: set(); break; - case 4: time(); break; + case 0: date(); break; + case 1: del(); break; + case 2: dir(); break; + case 3: dump(); break; + case 4: fill(); break; + case 5: help(); break; + case 6: list(); break; + case 7: set(); break; + case 8: time(); break; + } } } @@ -126,7 +151,7 @@ //----------------------------------------------------------------------------- // eine Zeile aus dem Eingangsbuffer lesen -void monitor::get_line(void) +void get_line(void) { char ch; uint8_t i; @@ -161,7 +186,7 @@ //----------------------------------------------------------------------------- // eine Zeichen aus dem Eingangsbuffer lesen -void monitor::get_ch (void) +void get_ch (void) { char ch; @@ -197,7 +222,7 @@ //----------------------------------------------------------------------------- // monitor Aufruf -void monitor::date(void) +void date(void) { pc.printf("\nin date"); } @@ -205,7 +230,7 @@ //----------------------------------------------------------------------------- // monitor Aufruf -void monitor::dump(void) +void dump(void) { pc.printf("\nin dump"); } @@ -213,43 +238,192 @@ //----------------------------------------------------------------------------- // monitor Aufruf -void monitor::help(void) +void help(void) { pc.printf("\n -- help ------------------------"); pc.printf("\n set index [val] Sensor auswaehlen"); pc.printf("\n"); + pc.printf("\n -- files ------------------------"); + pc.printf("\n dir >> Dateien anzeigen"); + pc.printf("\n list name >> den Inhalte einer Datei anzeigen"); + pc.printf("\n del name >> eine Datei loeschen"); + pc.printf("\n fill name [zeilen] >> eine Datei anlegen und fuellen"); + pc.printf("\n"); } //----------------------------------------------------------------------------- // monitor Aufruf -void monitor::set(void) +void set(void) { - int n, pos, val; + + int n; + char name[20], wert[20]; - n = sscanf(&com_line[ComLinePtr],"%d %d",&pos,&val); + n = sscanf(&com_line[ComLinePtr],"%s %s",name,wert); switch (n) { - case -1: pc.printf("\nbitte index [wert] angeben"); + case -1: pc.printf("\n list config file"); + + cfg.read("/sd/input.cfg"); + pc.printf("\n Index >> Sonsor 0 bis 7"); pc.printf("\n wert >> 0 = inaktiv, 1 = Rohwerte, 2 = errechneter Wert"); break; - case 1: pc.printf("\nread status[%d] = %d",pos,status[pos]); + case 1: pc.printf("\n list config value"); + + cfg.read("/sd/input.cfg"); + + if (cfg.getValue(name, &value[0], sizeof(value))) + { + pc.printf("\n'%s'='%s'", name, value); + } break; - case 2: status[pos] = val; - pc.printf("\nset status[%d] = %d",pos,status[pos]); + case 2: pc.printf("\n'%s' = '%s'",name,wert); + + cfg.setValue(name, wert); + cfg.write("/sd/input.cfg"); + break; } // end switch + } //----------------------------------------------------------------------------- // monitor Aufruf -void monitor::time(void) +void time(void) { pc.printf("\nin timer"); } +//----------------------------------------------------------------------------- +// monitor Aufruf dir +// +// weiter Infos siehe auch +// http://elm-chan.org/fsw/ff/00index_e.html +// +void dir(void) +{ + long size; + + DIR *d; + struct dirent *p; + + d = opendir("/sd"); + if (d != NULL) + { + while ((p = readdir(d)) != NULL) + { + sprintf(buffer,"/sd/%s",p->d_name); + pc.printf("\n %s", p->d_name); + FILE * f = fopen(buffer, "r"); + fseek(f, 0, SEEK_END); // seek to end of file + size = ftell(f); // get current file pointer + pc.printf(" %ld bytes ",size); + + time_t fattime = get_fattime(); + strftime(buffer, 40, "%a,%d %m %Y.%H:%M:%S", localtime(&fattime)); + pc.printf(" %s ", buffer); + + fclose(f); + } + + } + else + { + pc.printf("\nCould not open directory!\n"); + } + closedir(d); + + + FATFS* fs; + DWORD fre_clust; + f_getfree("0:",&fre_clust,&fs); + const float frs = float(fs->csize)*float(fs->free_clust) + #if _MAX_SS != 512 + *(fs->ssize); + #else + *512; + #endif + pc.printf("\n\nfree space = %f GB",frs/1073741824.0); + + pc.printf("\ndone\n"); +} + +//----------------------------------------------------------------------------- +// monitor Aufruf list + +void list(void) +{ + char dname[25]; + int ch; + + sscanf(&com_line[ComLinePtr],"%s",dname); + sprintf(buffer,"/sd/%s",dname); + pc.printf("\nlist, file %s \n",buffer); + FILE * fp = fopen(buffer, "r"); + if(fp == NULL) + { + pc.printf("\nCould not open file for read\n\r"); + return; + } + + // mit fgets werden die Zeile einzeln gelesen, wenn die Länge < 64 Zeichen ist + + while (1) // list src to pc + { + ch = fgetc(fp); // until src EOF read. + if (ch == EOF) break; + pc.putc(ch); + } + + fclose(fp); + + pc.printf("\ndone\n"); +} + +//----------------------------------------------------------------------------- +// monitor Aufruf del + +void del(void) +{ + char dname[25]; + char buffer[40]; + + sscanf(&com_line[ComLinePtr],"%s",dname); + sprintf(buffer,"/sd/%s",dname); + pc.printf("\ndelete file %s",buffer); + remove(buffer); + pc.printf("\ndone"); +} + +//----------------------------------------------------------------------------- +// monitor Aufruf fill + +void fill(void) +{ + char dname[25]; + char buffer[40]; + int n = 20; + + sscanf(&com_line[ComLinePtr],"%s %d",dname,&n); + sprintf(buffer,"/sd/%s",dname); + pc.printf("\nfill file %s \n",buffer); + FILE *fp = fopen(buffer, "w"); + if(fp == NULL) + { + pc.printf("Could not open file for write\n"); + } + for (int i = 0; i<n; i++) + { + fprintf(fp, "\nschreibe eine Zeile %d ",i); + } + fclose(fp); + pc.printf("\ndone\n"); +} + +
--- a/monitor.h Sat Jul 26 07:27:20 2014 +0000 +++ b/monitor.h Mon Jul 28 14:36:32 2014 +0000 @@ -1,3 +1,6 @@ + +#ifndef MONITOR_H +#define MONITOR_H #include <string.h> #include "mbed.h" @@ -5,28 +8,20 @@ #define COM_LINE_LEN 100 -class monitor -{ - private: - - - public: - - char com_line[COM_LINE_LEN]; // Aktuelle Eingabezeile - uint8_t ComLinePtr, ComLineTop; // Cursor Position und Zeilenlänge - - uint8_t cr_flag; - - uint16_t status[8]; - - monitor(void); - void parser (void); - void get_line(void); - void get_ch (void); - - void date(void); - void dump(void); - void help(void); - void set(void); - void time(void); - }; \ No newline at end of file + void mon_init(void); + + void parser (void); + void get_line(void); + void get_ch (void); + + void date(void); + void dump(void); + void help(void); + void set(void); + void time(void); + void dir(void); + void list(void); + void del(void); + void fill(void); + +#endif \ No newline at end of file