Monitor für das Tasterprogramm

Dependents:   19_Taster_BSW_oo 19_Taster_a

Fork of monitor by Temp27

Committer:
rs27
Date:
Fri Aug 08 16:01:41 2014 +0000
Revision:
4:83dbae473d1f
Parent:
3:254f7ffb9b32
Child:
5:9c7606a0be99
98.08.14

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rs27 0:f0fbbfdca478 1
rs27 0:f0fbbfdca478 2 #include <stdarg.h>
rs27 0:f0fbbfdca478 3 #include <ctype.h>
rs27 0:f0fbbfdca478 4 #include "monitor.h"
rs27 1:19313470f629 5 #include "ConfigFile.h"
rs27 1:19313470f629 6 #include "SDFileSystem.h"
rs27 1:19313470f629 7 #include "FATDirHandle.h"
rs27 0:f0fbbfdca478 8
rs27 1:19313470f629 9 extern SDFileSystem sd; // definiert in main
rs27 1:19313470f629 10 extern Serial pc; // definiert in main
rs27 2:e330478fb0b6 11 extern Serial com; // definiert in main
rs27 1:19313470f629 12 extern Buffer <char> buf; // definiert in main
rs27 1:19313470f629 13 extern ConfigFile cfg; // definiert in main
rs27 1:19313470f629 14 extern char value[BUFSIZ]; // definiert in main
rs27 2:e330478fb0b6 15 extern float soll_wert; // definiert in main
rs27 2:e330478fb0b6 16 extern bool t_flag; // definiert in main
rs27 2:e330478fb0b6 17 extern bool f_flag; // definiert in main
rs27 2:e330478fb0b6 18 extern int drops; // definiert in main
rs27 4:83dbae473d1f 19 extern int tropfperiode; // definiert in main
rs27 1:19313470f629 20
rs27 4:83dbae473d1f 21 #define COMMAND_MAX 14
rs27 1:19313470f629 22 #define COMMAND_LEN 7
rs27 0:f0fbbfdca478 23
rs27 4:83dbae473d1f 24 const char command[COMMAND_MAX][COMMAND_LEN] = {"CYCLE","DATE","DEL","DIR","DROPS","DUMP","FILL","GO","HELP","LIST","SET","SOLL","STOPP","TIME"};
rs27 1:19313470f629 25
rs27 1:19313470f629 26 char buffer[100];
rs27 1:19313470f629 27
rs27 1:19313470f629 28 // globale Variablen
rs27 1:19313470f629 29
rs27 1:19313470f629 30 char com_line[COM_LINE_LEN]; // Aktuelle Eingabezeile
rs27 1:19313470f629 31 uint8_t ComLinePtr, ComLineTop; // Cursor Position und Zeilenlänge
rs27 1:19313470f629 32
rs27 1:19313470f629 33 uint8_t cr_flag;
rs27 1:19313470f629 34
rs27 1:19313470f629 35 // uint16_t status[8];
rs27 0:f0fbbfdca478 36
rs27 0:f0fbbfdca478 37 //-----------------------------------------------------------------------------
rs27 1:19313470f629 38 // initialisierung
rs27 0:f0fbbfdca478 39
rs27 1:19313470f629 40 void mon_init(void)
rs27 0:f0fbbfdca478 41 {
rs27 1:19313470f629 42
rs27 0:f0fbbfdca478 43 uint8_t i;
rs27 0:f0fbbfdca478 44
rs27 0:f0fbbfdca478 45 for (i = 0; i < COM_LINE_LEN; com_line[i++] = 0);
rs27 0:f0fbbfdca478 46 ComLinePtr = ComLineTop = 0;
rs27 0:f0fbbfdca478 47 cr_flag = false;
rs27 0:f0fbbfdca478 48
rs27 0:f0fbbfdca478 49 // 0 Kanal ist daktiv
rs27 0:f0fbbfdca478 50 // 1 Rohdaten ausgeben
rs27 0:f0fbbfdca478 51 // 2 Temperaturwert in Float Darstellung
rs27 0:f0fbbfdca478 52
rs27 1:19313470f629 53 /*
rs27 0:f0fbbfdca478 54 status[0] = 2; // Temperaturwerte ausgeben
rs27 0:f0fbbfdca478 55 status[1] = 0;
rs27 0:f0fbbfdca478 56 status[2] = 0;
rs27 0:f0fbbfdca478 57 status[3] = 0;
rs27 0:f0fbbfdca478 58 status[4] = 0;
rs27 0:f0fbbfdca478 59 status[5] = 0;
rs27 0:f0fbbfdca478 60 status[6] = 0;
rs27 0:f0fbbfdca478 61 status[7] = 0;
rs27 1:19313470f629 62 */
rs27 0:f0fbbfdca478 63 }
rs27 0:f0fbbfdca478 64
rs27 0:f0fbbfdca478 65 //-----------------------------------------------------------------------------
rs27 0:f0fbbfdca478 66 // destructor
rs27 0:f0fbbfdca478 67
rs27 1:19313470f629 68 void parser (void)
rs27 0:f0fbbfdca478 69 {
rs27 0:f0fbbfdca478 70 uint8_t i, ch, tch, top, bottom, len;
rs27 0:f0fbbfdca478 71 int8_t res;
rs27 0:f0fbbfdca478 72
rs27 0:f0fbbfdca478 73 // Zuerst wird der erste Buchstabe aus dem Eingabestring mit den ersten
rs27 0:f0fbbfdca478 74 // Buchstaben aus der Befehlstabelle verglichen
rs27 0:f0fbbfdca478 75
rs27 0:f0fbbfdca478 76 bottom = 0; // untere Suchgrenze
rs27 0:f0fbbfdca478 77 top = COMMAND_MAX; // obere Suchgerenze
rs27 0:f0fbbfdca478 78 ch = com_line[0]; // hole erstes Suchzeichen
rs27 0:f0fbbfdca478 79
rs27 0:f0fbbfdca478 80 do
rs27 0:f0fbbfdca478 81 {
rs27 0:f0fbbfdca478 82 i = (top + bottom) >> 1; // suche in der Mitte des Feldes beginnen
rs27 0:f0fbbfdca478 83 tch = command [i][0]; // Vergleichszeichen laden
rs27 0:f0fbbfdca478 84 if (tch == ch) break; // Zeichen gefunden
rs27 0:f0fbbfdca478 85 if (tch > ch) top = i; // nach unten suchen
rs27 0:f0fbbfdca478 86 else bottom = i; // nach oben suchen
rs27 0:f0fbbfdca478 87 if (bottom != 0 && top == bottom + 1) break; // kein Buchstabe gef.
rs27 0:f0fbbfdca478 88
rs27 0:f0fbbfdca478 89 } while (i > 0 && i < COMMAND_MAX - 1);
rs27 0:f0fbbfdca478 90
rs27 0:f0fbbfdca478 91 if (tch != ch)
rs27 0:f0fbbfdca478 92 {
rs27 0:f0fbbfdca478 93 pc.printf("\nParser Kommando nicht gefunden\n");
rs27 0:f0fbbfdca478 94 return; // Kommando nicht gefunden wurde
rs27 0:f0fbbfdca478 95 }
rs27 0:f0fbbfdca478 96
rs27 0:f0fbbfdca478 97 // das erst Wort soll von den Übergabeparametern isoliert werden
rs27 0:f0fbbfdca478 98
rs27 0:f0fbbfdca478 99 for (i = 0; com_line[i] != ' ' && com_line[i] != 0; i++);
rs27 0:f0fbbfdca478 100 len = i;
rs27 0:f0fbbfdca478 101
rs27 0:f0fbbfdca478 102
rs27 0:f0fbbfdca478 103 if (i == 0) return;
rs27 0:f0fbbfdca478 104
rs27 0:f0fbbfdca478 105 // die Übergabparameter ermitteln und in als Indexzeiger in
rs27 0:f0fbbfdca478 106 // 'ComLinePtr' abspeichern
rs27 0:f0fbbfdca478 107
rs27 0:f0fbbfdca478 108 for ( ; com_line[i] == ' ' && com_line[i] != 0; i++);
rs27 0:f0fbbfdca478 109 ComLinePtr = i;
rs27 0:f0fbbfdca478 110
rs27 0:f0fbbfdca478 111 // die binäre Suche nach den restlichen Zeichen wird hier fortgesetzt
rs27 0:f0fbbfdca478 112
rs27 0:f0fbbfdca478 113 do
rs27 0:f0fbbfdca478 114 {
rs27 0:f0fbbfdca478 115 i = (top + bottom) >> 1; // berechnen des Suchplatzes
rs27 0:f0fbbfdca478 116 //printf_P (PSTR("\n\rVergleich 1 com_line = [%s] und Länge = [%d]"),com_line,len);
rs27 0:f0fbbfdca478 117 //strcpy_P (temp, &command[i][0]);
rs27 0:f0fbbfdca478 118 //printf_P (PSTR("\n\rVergleich 2 command[i] = [%s] und Index = [%d]"),temp,i);
rs27 0:f0fbbfdca478 119 res = strncmp(com_line, &command[i][0], len);
rs27 0:f0fbbfdca478 120 //printf_P (PSTR("\n\rVergleich 3 res = [%d]"),res);
rs27 0:f0fbbfdca478 121 if (res == 0) break; // Zeichen gefunden
rs27 0:f0fbbfdca478 122 if (res > 0)
rs27 0:f0fbbfdca478 123 bottom = i; // nach unten suchen
rs27 0:f0fbbfdca478 124 else
rs27 0:f0fbbfdca478 125 top = i; // nach oben suchen
rs27 0:f0fbbfdca478 126 if (bottom != 0 && top == bottom + 1) break;
rs27 0:f0fbbfdca478 127
rs27 0:f0fbbfdca478 128 } while (i > 0 && i < COMMAND_MAX - 1);
rs27 0:f0fbbfdca478 129
rs27 0:f0fbbfdca478 130
rs27 0:f0fbbfdca478 131 if (res)
rs27 0:f0fbbfdca478 132 {
rs27 0:f0fbbfdca478 133 pc.printf("\nParser Kommando nicht gefunden.\n");
rs27 0:f0fbbfdca478 134 }
rs27 0:f0fbbfdca478 135 else
rs27 0:f0fbbfdca478 136 {
rs27 0:f0fbbfdca478 137 pc.printf("\nAufruf von Funktion %d",i);
rs27 0:f0fbbfdca478 138
rs27 0:f0fbbfdca478 139 switch(i) // Programmaufruf
rs27 0:f0fbbfdca478 140 {
rs27 4:83dbae473d1f 141 case 0: cycle(); break;
rs27 4:83dbae473d1f 142 case 1: date(); break;
rs27 4:83dbae473d1f 143 case 2: del(); break;
rs27 4:83dbae473d1f 144 case 3: dir(); break;
rs27 4:83dbae473d1f 145 case 4: func_drops(); break;
rs27 4:83dbae473d1f 146 case 5: dump(); break;
rs27 4:83dbae473d1f 147 case 6: fill(); break;
rs27 4:83dbae473d1f 148 case 7: go(); break;
rs27 4:83dbae473d1f 149 case 8: help(); break;
rs27 4:83dbae473d1f 150 case 9: list(); break;
rs27 4:83dbae473d1f 151 case 10: set(); break;
rs27 4:83dbae473d1f 152 case 11: soll(); break;
rs27 4:83dbae473d1f 153 case 12: stop(); break;
rs27 4:83dbae473d1f 154 case 13: time(); break;
rs27 0:f0fbbfdca478 155 }
rs27 0:f0fbbfdca478 156 }
rs27 0:f0fbbfdca478 157 }
rs27 0:f0fbbfdca478 158
rs27 0:f0fbbfdca478 159
rs27 0:f0fbbfdca478 160
rs27 0:f0fbbfdca478 161 //-----------------------------------------------------------------------------
rs27 0:f0fbbfdca478 162 // eine Zeile aus dem Eingangsbuffer lesen
rs27 0:f0fbbfdca478 163
rs27 1:19313470f629 164 void get_line(void)
rs27 0:f0fbbfdca478 165 {
rs27 0:f0fbbfdca478 166 char ch;
rs27 0:f0fbbfdca478 167 uint8_t i;
rs27 0:f0fbbfdca478 168
rs27 0:f0fbbfdca478 169 get_ch();
rs27 0:f0fbbfdca478 170 if (cr_flag) // Neue Eingabezeile
rs27 0:f0fbbfdca478 171 {
rs27 0:f0fbbfdca478 172 if (com_line[0] != 0)
rs27 0:f0fbbfdca478 173 {
rs27 0:f0fbbfdca478 174 // uart_puts(com_line); // zum Testen => später wird der parcer aufgerufen
rs27 0:f0fbbfdca478 175 // Zeichenkette in Großbuchstaben umwandeln
rs27 0:f0fbbfdca478 176
rs27 0:f0fbbfdca478 177 // printf_P (PSTR("\n monitor "));
rs27 0:f0fbbfdca478 178 for (i = 0; com_line[i] != 0; i++)
rs27 0:f0fbbfdca478 179 {
rs27 0:f0fbbfdca478 180 ch = com_line[i];
rs27 0:f0fbbfdca478 181 ch = toupper(ch); // Nur Großbuchstaben
rs27 0:f0fbbfdca478 182 com_line[i] = ch;
rs27 0:f0fbbfdca478 183 // pc.printf(("\n[%02x] %c"),ch,ch);
rs27 0:f0fbbfdca478 184 if (ch == ' ') i = COM_LINE_LEN;
rs27 0:f0fbbfdca478 185 }
rs27 0:f0fbbfdca478 186 // pc.printf(("\n"));
rs27 0:f0fbbfdca478 187 parser(); // Parcer wird aufgerufen
rs27 0:f0fbbfdca478 188 }
rs27 0:f0fbbfdca478 189
rs27 0:f0fbbfdca478 190 for (i=0; i < COM_LINE_LEN; com_line[i++] = 0);
rs27 0:f0fbbfdca478 191 ComLinePtr = ComLineTop = 0;
rs27 0:f0fbbfdca478 192 cr_flag = 0;
rs27 0:f0fbbfdca478 193 }
rs27 0:f0fbbfdca478 194 }
rs27 0:f0fbbfdca478 195
rs27 0:f0fbbfdca478 196 //-----------------------------------------------------------------------------
rs27 0:f0fbbfdca478 197 // eine Zeichen aus dem Eingangsbuffer lesen
rs27 0:f0fbbfdca478 198
rs27 1:19313470f629 199 void get_ch (void)
rs27 0:f0fbbfdca478 200 {
rs27 0:f0fbbfdca478 201 char ch;
rs27 0:f0fbbfdca478 202
rs27 0:f0fbbfdca478 203 if (!buf.available()) return; // kein Zeichen vorhanden
rs27 0:f0fbbfdca478 204
rs27 0:f0fbbfdca478 205 ch = buf.get(); // hole das Zeichen
rs27 0:f0fbbfdca478 206 // printf("mon_line: %c %02x\n",ch,ch); // nur zum Test
rs27 0:f0fbbfdca478 207
rs27 0:f0fbbfdca478 208 switch(ch)
rs27 0:f0fbbfdca478 209 {
rs27 0:f0fbbfdca478 210 case '\r': // CARRIAGE RETURN
rs27 0:f0fbbfdca478 211 cr_flag = true;
rs27 0:f0fbbfdca478 212 break;
rs27 0:f0fbbfdca478 213
rs27 0:f0fbbfdca478 214 case '\n': // LF empfangen
rs27 0:f0fbbfdca478 215 cr_flag = true;
rs27 0:f0fbbfdca478 216 break;
rs27 0:f0fbbfdca478 217
rs27 0:f0fbbfdca478 218 default: // Normales Zeichen
rs27 0:f0fbbfdca478 219 if (~iscntrl(ch))
rs27 0:f0fbbfdca478 220 {
rs27 0:f0fbbfdca478 221 com_line[ComLinePtr] = ch; // Zeichen einfuegen
rs27 0:f0fbbfdca478 222 ComLinePtr++;
rs27 0:f0fbbfdca478 223 }
rs27 0:f0fbbfdca478 224 break;
rs27 0:f0fbbfdca478 225
rs27 0:f0fbbfdca478 226 } // Ende SWITCH
rs27 0:f0fbbfdca478 227
rs27 0:f0fbbfdca478 228 if (ComLinePtr >= 80) cr_flag = 1; // Zeilenüberlauf ?
rs27 0:f0fbbfdca478 229
rs27 0:f0fbbfdca478 230 }
rs27 0:f0fbbfdca478 231
rs27 0:f0fbbfdca478 232 //-----------------------------------------------------------------------------
rs27 0:f0fbbfdca478 233 // monitor Aufruf
rs27 0:f0fbbfdca478 234
rs27 1:19313470f629 235 void date(void)
rs27 0:f0fbbfdca478 236 {
rs27 0:f0fbbfdca478 237 pc.printf("\nin date");
rs27 0:f0fbbfdca478 238 }
rs27 0:f0fbbfdca478 239
rs27 0:f0fbbfdca478 240 //-----------------------------------------------------------------------------
rs27 0:f0fbbfdca478 241 // monitor Aufruf
rs27 0:f0fbbfdca478 242
rs27 1:19313470f629 243 void dump(void)
rs27 0:f0fbbfdca478 244 {
rs27 0:f0fbbfdca478 245 pc.printf("\nin dump");
rs27 0:f0fbbfdca478 246 }
rs27 0:f0fbbfdca478 247
rs27 0:f0fbbfdca478 248 //-----------------------------------------------------------------------------
rs27 0:f0fbbfdca478 249 // monitor Aufruf
rs27 0:f0fbbfdca478 250
rs27 1:19313470f629 251 void help(void)
rs27 0:f0fbbfdca478 252 {
rs27 0:f0fbbfdca478 253 pc.printf("\n -- help ------------------------");
rs27 2:e330478fb0b6 254 pc.printf("\n go [?,f,F,t,Tl] aktivieren der Heizung oder der Tropfen");
rs27 2:e330478fb0b6 255 pc.printf("\n stop [?,f,F,t,Tl] deaktivieren der Heizung oder der Tropfen");
rs27 0:f0fbbfdca478 256 pc.printf("\n set index [val] Sensor auswaehlen");
rs27 2:e330478fb0b6 257 pc.printf("\n soll[val] Sollwertvorgabe fuer den Temperaturfuehler");
rs27 4:83dbae473d1f 258 pc.printf("\n cycle [val] Zeiteinheit fuer die Messung der Tropfen");
rs27 2:e330478fb0b6 259 pc.printf("\n drops [val] Anzahl der Tropfen pro Zeiteinheit");
rs27 0:f0fbbfdca478 260 pc.printf("\n");
rs27 1:19313470f629 261 pc.printf("\n -- files ------------------------");
rs27 1:19313470f629 262 pc.printf("\n dir >> Dateien anzeigen");
rs27 1:19313470f629 263 pc.printf("\n list name >> den Inhalte einer Datei anzeigen");
rs27 1:19313470f629 264 pc.printf("\n del name >> eine Datei loeschen");
rs27 1:19313470f629 265 pc.printf("\n fill name [zeilen] >> eine Datei anlegen und fuellen");
rs27 1:19313470f629 266 pc.printf("\n");
rs27 0:f0fbbfdca478 267 }
rs27 0:f0fbbfdca478 268
rs27 0:f0fbbfdca478 269 //-----------------------------------------------------------------------------
rs27 0:f0fbbfdca478 270 // monitor Aufruf
rs27 0:f0fbbfdca478 271
rs27 1:19313470f629 272 void set(void)
rs27 0:f0fbbfdca478 273 {
rs27 1:19313470f629 274
rs27 1:19313470f629 275 int n;
rs27 1:19313470f629 276 char name[20], wert[20];
rs27 0:f0fbbfdca478 277
rs27 1:19313470f629 278 n = sscanf(&com_line[ComLinePtr],"%s %s",name,wert);
rs27 0:f0fbbfdca478 279
rs27 0:f0fbbfdca478 280 switch (n)
rs27 0:f0fbbfdca478 281 {
rs27 1:19313470f629 282 case -1: pc.printf("\n list config file");
rs27 1:19313470f629 283
rs27 1:19313470f629 284 cfg.read("/sd/input.cfg");
rs27 1:19313470f629 285
rs27 0:f0fbbfdca478 286 pc.printf("\n Index >> Sonsor 0 bis 7");
rs27 0:f0fbbfdca478 287 pc.printf("\n wert >> 0 = inaktiv, 1 = Rohwerte, 2 = errechneter Wert");
rs27 0:f0fbbfdca478 288 break;
rs27 0:f0fbbfdca478 289
rs27 1:19313470f629 290 case 1: pc.printf("\n list config value");
rs27 1:19313470f629 291
rs27 1:19313470f629 292 cfg.read("/sd/input.cfg");
rs27 1:19313470f629 293
rs27 1:19313470f629 294 if (cfg.getValue(name, &value[0], sizeof(value)))
rs27 1:19313470f629 295 {
rs27 1:19313470f629 296 pc.printf("\n'%s'='%s'", name, value);
rs27 1:19313470f629 297 }
rs27 0:f0fbbfdca478 298 break;
rs27 0:f0fbbfdca478 299
rs27 1:19313470f629 300 case 2: pc.printf("\n'%s' = '%s'",name,wert);
rs27 1:19313470f629 301
rs27 1:19313470f629 302 cfg.setValue(name, wert);
rs27 1:19313470f629 303 cfg.write("/sd/input.cfg");
rs27 1:19313470f629 304
rs27 0:f0fbbfdca478 305 break;
rs27 0:f0fbbfdca478 306 } // end switch
Sven3010 3:254f7ffb9b32 307 pc.printf("\n");
rs27 0:f0fbbfdca478 308 }
rs27 0:f0fbbfdca478 309
rs27 0:f0fbbfdca478 310 //-----------------------------------------------------------------------------
rs27 2:e330478fb0b6 311 // monitor Aufruf soll
rs27 2:e330478fb0b6 312 // mit diesem Befehl wird der Sollwert für den Temperaturfühler vorgegeben
rs27 2:e330478fb0b6 313
rs27 2:e330478fb0b6 314 void soll(void)
rs27 2:e330478fb0b6 315 {
rs27 2:e330478fb0b6 316
rs27 2:e330478fb0b6 317 int n;
rs27 2:e330478fb0b6 318 char wert[20];
rs27 2:e330478fb0b6 319
rs27 2:e330478fb0b6 320 n = sscanf(&com_line[ComLinePtr],"%s",wert);
rs27 2:e330478fb0b6 321
rs27 2:e330478fb0b6 322 switch (n)
rs27 2:e330478fb0b6 323 {
rs27 2:e330478fb0b6 324 case -1: pc.printf("\nSollwert = %f",soll_wert);
rs27 2:e330478fb0b6 325 break;
rs27 2:e330478fb0b6 326
rs27 2:e330478fb0b6 327 case 1:
rs27 2:e330478fb0b6 328
rs27 2:e330478fb0b6 329 cfg.setValue("soll", wert);
rs27 2:e330478fb0b6 330 cfg.write("/sd/input.cfg");
rs27 2:e330478fb0b6 331
rs27 2:e330478fb0b6 332 soll_wert = atof(wert);
rs27 2:e330478fb0b6 333
rs27 2:e330478fb0b6 334 pc.printf("\nneuer Sollwert = %f",soll_wert);
rs27 2:e330478fb0b6 335
rs27 2:e330478fb0b6 336 break;
rs27 2:e330478fb0b6 337
rs27 2:e330478fb0b6 338 } // end switch
Sven3010 3:254f7ffb9b32 339 pc.printf("\n");
rs27 2:e330478fb0b6 340 }
rs27 2:e330478fb0b6 341
rs27 4:83dbae473d1f 342 //-----------------------------------------------------------------------------
rs27 4:83dbae473d1f 343 // monitor Aufruf cycle
rs27 4:83dbae473d1f 344 // mit diesem Befehl wird die Zeit in Sekunden vorgegeben, in der die Tropfenzahl
rs27 4:83dbae473d1f 345 // ausgewertet wird
rs27 4:83dbae473d1f 346
rs27 4:83dbae473d1f 347 void cycle(void)
rs27 4:83dbae473d1f 348 {
rs27 4:83dbae473d1f 349 int n;
rs27 4:83dbae473d1f 350 char wert[20];
rs27 4:83dbae473d1f 351
rs27 4:83dbae473d1f 352 n = sscanf(&com_line[ComLinePtr],"%s",wert);
rs27 4:83dbae473d1f 353
rs27 4:83dbae473d1f 354 switch (n)
rs27 4:83dbae473d1f 355 {
rs27 4:83dbae473d1f 356 case -1: pc.printf("\nZeit der Messung = %d Sekunden",tropfperiode);
rs27 4:83dbae473d1f 357 break;
rs27 4:83dbae473d1f 358
rs27 4:83dbae473d1f 359 case 1:
rs27 4:83dbae473d1f 360
rs27 4:83dbae473d1f 361 cfg.setValue("cycle", wert);
rs27 4:83dbae473d1f 362 cfg.write("/sd/input.cfg");
rs27 4:83dbae473d1f 363
rs27 4:83dbae473d1f 364 tropfperiode = atoi(wert);
rs27 4:83dbae473d1f 365
rs27 4:83dbae473d1f 366 pc.printf("\nneue Zeit der Messung = %d Sekunden",tropfperiode);
rs27 4:83dbae473d1f 367
rs27 4:83dbae473d1f 368 break;
rs27 4:83dbae473d1f 369
rs27 4:83dbae473d1f 370 } // end switch
rs27 4:83dbae473d1f 371
rs27 4:83dbae473d1f 372 pc.printf("\n");
rs27 4:83dbae473d1f 373 }
rs27 4:83dbae473d1f 374
rs27 2:e330478fb0b6 375
rs27 2:e330478fb0b6 376 //-----------------------------------------------------------------------------
rs27 2:e330478fb0b6 377 // monitor Aufruf drops
rs27 2:e330478fb0b6 378 // mit diesem Befehl wird die Anzahl der Tropfen pro Zeiteinheit vorgegeben
rs27 2:e330478fb0b6 379
rs27 2:e330478fb0b6 380 void func_drops(void)
rs27 2:e330478fb0b6 381 {
rs27 2:e330478fb0b6 382
rs27 2:e330478fb0b6 383 int n;
rs27 2:e330478fb0b6 384 char wert[20];
rs27 2:e330478fb0b6 385
rs27 2:e330478fb0b6 386 n = sscanf(&com_line[ComLinePtr],"%s",wert);
rs27 2:e330478fb0b6 387
rs27 2:e330478fb0b6 388 switch (n)
rs27 2:e330478fb0b6 389 {
rs27 2:e330478fb0b6 390 case -1: pc.printf("\nAnzahl Tropfen = %d",drops);
rs27 2:e330478fb0b6 391 break;
rs27 2:e330478fb0b6 392
rs27 2:e330478fb0b6 393 case 1:
rs27 2:e330478fb0b6 394 cfg.setValue("drops", wert);
rs27 2:e330478fb0b6 395 cfg.write("/sd/input.cfg");
rs27 2:e330478fb0b6 396
rs27 2:e330478fb0b6 397 drops = atoi(wert);
rs27 2:e330478fb0b6 398
rs27 2:e330478fb0b6 399 pc.printf("\nneue Anzahl der Tropfen = %d",drops);
rs27 2:e330478fb0b6 400
rs27 2:e330478fb0b6 401 break;
rs27 2:e330478fb0b6 402
rs27 2:e330478fb0b6 403 } // end switch
Sven3010 3:254f7ffb9b32 404 pc.printf("\n");
rs27 2:e330478fb0b6 405 }
rs27 2:e330478fb0b6 406 //-----------------------------------------------------------------------------
rs27 2:e330478fb0b6 407 // monitor Aufruf go
rs27 2:e330478fb0b6 408 // Wird die Heizung oder der Tropfenspender eingeschaltet.
rs27 2:e330478fb0b6 409
rs27 2:e330478fb0b6 410 void go(void)
rs27 2:e330478fb0b6 411 {
rs27 2:e330478fb0b6 412 char ch;
rs27 2:e330478fb0b6 413
Sven3010 3:254f7ffb9b32 414 sscanf(&com_line[ComLinePtr],"%c",&ch);
rs27 2:e330478fb0b6 415
Sven3010 3:254f7ffb9b32 416 switch (ch)
rs27 2:e330478fb0b6 417 {
rs27 2:e330478fb0b6 418
rs27 2:e330478fb0b6 419 case '?':
rs27 2:e330478fb0b6 420 if (t_flag) pc.printf("Temperatur aktiv");
rs27 2:e330478fb0b6 421 else pc.printf("Temperatur inaktiv");
rs27 2:e330478fb0b6 422
rs27 2:e330478fb0b6 423 if (f_flag) pc.printf("Tropfen freigeschaltet");
rs27 2:e330478fb0b6 424 else pc.printf("Tropfen gesperrt");
rs27 2:e330478fb0b6 425
rs27 2:e330478fb0b6 426 break;
rs27 2:e330478fb0b6 427 case 't':
rs27 2:e330478fb0b6 428 case 'T':
rs27 2:e330478fb0b6 429 cfg.setValue("t_flag", "1");
rs27 2:e330478fb0b6 430 cfg.write("/sd/input.cfg");
rs27 2:e330478fb0b6 431
rs27 2:e330478fb0b6 432 t_flag = true;
rs27 2:e330478fb0b6 433 pc.printf("\nTemperatursteuerung ist aktiv");
rs27 2:e330478fb0b6 434
rs27 2:e330478fb0b6 435 break;
rs27 2:e330478fb0b6 436
rs27 2:e330478fb0b6 437 case 'f':
rs27 2:e330478fb0b6 438 case 'F':
rs27 2:e330478fb0b6 439 cfg.setValue("f_flag", "1");
rs27 2:e330478fb0b6 440 cfg.write("/sd/input.cfg");
rs27 2:e330478fb0b6 441
rs27 2:e330478fb0b6 442 f_flag = true;
rs27 2:e330478fb0b6 443 com.putc('1');
rs27 2:e330478fb0b6 444 pc.printf("\nTropfen freigeben");
rs27 2:e330478fb0b6 445
rs27 2:e330478fb0b6 446 break;
rs27 2:e330478fb0b6 447
rs27 4:83dbae473d1f 448 default: pc.printf("\nBefehl go kennt nur die Zeichen ?,t,T,f,F");
rs27 4:83dbae473d1f 449 break;
rs27 2:e330478fb0b6 450
rs27 2:e330478fb0b6 451 } // end switch
Sven3010 3:254f7ffb9b32 452 pc.printf("\n");
rs27 2:e330478fb0b6 453 }
rs27 2:e330478fb0b6 454
rs27 2:e330478fb0b6 455
rs27 2:e330478fb0b6 456 //-----------------------------------------------------------------------------
rs27 2:e330478fb0b6 457 // monitor Aufruf stop
rs27 2:e330478fb0b6 458 // Wird die Heizung oder der Tropfenspender ausgeschaltet.
rs27 2:e330478fb0b6 459
rs27 2:e330478fb0b6 460 void stop(void)
rs27 2:e330478fb0b6 461 {
rs27 2:e330478fb0b6 462 char ch;
rs27 2:e330478fb0b6 463
Sven3010 3:254f7ffb9b32 464 sscanf(&com_line[ComLinePtr],"%c",&ch);
rs27 2:e330478fb0b6 465
Sven3010 3:254f7ffb9b32 466 switch (ch)
rs27 2:e330478fb0b6 467 {
rs27 2:e330478fb0b6 468
rs27 2:e330478fb0b6 469 case '?':
rs27 2:e330478fb0b6 470 if (t_flag) pc.printf("Temperatur aktiviert");
rs27 2:e330478fb0b6 471 else pc.printf("Temperatur deaktiviert");
rs27 2:e330478fb0b6 472
rs27 2:e330478fb0b6 473 if (f_flag) pc.printf("Tropfen freigeschaltet");
rs27 2:e330478fb0b6 474 else pc.printf("Tropfen gesperrt");
rs27 2:e330478fb0b6 475
rs27 2:e330478fb0b6 476 break;
rs27 2:e330478fb0b6 477 case 't':
rs27 2:e330478fb0b6 478 case 'T':
rs27 2:e330478fb0b6 479 cfg.setValue("t_flag", "0");
rs27 2:e330478fb0b6 480 cfg.write("/sd/input.cfg");
rs27 2:e330478fb0b6 481
Sven3010 3:254f7ffb9b32 482 t_flag = false;
rs27 2:e330478fb0b6 483 pc.printf("\nTemperatursteuerung ist deaktiviert");
rs27 2:e330478fb0b6 484
rs27 2:e330478fb0b6 485 break;
rs27 2:e330478fb0b6 486
rs27 2:e330478fb0b6 487 case 'f':
rs27 2:e330478fb0b6 488 case 'F':
rs27 2:e330478fb0b6 489 cfg.setValue("f_flag", "0");
rs27 2:e330478fb0b6 490 cfg.write("/sd/input.cfg");
rs27 2:e330478fb0b6 491
Sven3010 3:254f7ffb9b32 492 f_flag = false;
rs27 2:e330478fb0b6 493 com.putc('9');
rs27 2:e330478fb0b6 494 pc.printf("\nTropfen gesperrt");
rs27 2:e330478fb0b6 495
rs27 2:e330478fb0b6 496 break;
rs27 2:e330478fb0b6 497
rs27 4:83dbae473d1f 498 default:
rs27 4:83dbae473d1f 499 pc.printf("\nBefehl stop kennt nur die Zeichen ?,t,T,f,F '%c' %x", ch, ch);
rs27 4:83dbae473d1f 500 break;
rs27 2:e330478fb0b6 501
rs27 2:e330478fb0b6 502 } // end switch
rs27 4:83dbae473d1f 503
rs27 4:83dbae473d1f 504 pc.printf("\n");
rs27 2:e330478fb0b6 505 }
rs27 2:e330478fb0b6 506 //-----------------------------------------------------------------------------
rs27 0:f0fbbfdca478 507 // monitor Aufruf
rs27 0:f0fbbfdca478 508
rs27 1:19313470f629 509 void time(void)
rs27 0:f0fbbfdca478 510 {
rs27 0:f0fbbfdca478 511 pc.printf("\nin timer");
rs27 0:f0fbbfdca478 512 }
rs27 0:f0fbbfdca478 513
rs27 1:19313470f629 514 //-----------------------------------------------------------------------------
rs27 1:19313470f629 515 // monitor Aufruf dir
rs27 1:19313470f629 516 //
rs27 1:19313470f629 517 // weiter Infos siehe auch
rs27 1:19313470f629 518 // http://elm-chan.org/fsw/ff/00index_e.html
rs27 1:19313470f629 519 //
rs27 1:19313470f629 520 void dir(void)
rs27 1:19313470f629 521 {
rs27 1:19313470f629 522 long size;
rs27 1:19313470f629 523
rs27 1:19313470f629 524 DIR *d;
rs27 1:19313470f629 525 struct dirent *p;
rs27 1:19313470f629 526
rs27 1:19313470f629 527 d = opendir("/sd");
rs27 1:19313470f629 528 if (d != NULL)
rs27 1:19313470f629 529 {
rs27 1:19313470f629 530 while ((p = readdir(d)) != NULL)
rs27 1:19313470f629 531 {
rs27 1:19313470f629 532 sprintf(buffer,"/sd/%s",p->d_name);
rs27 1:19313470f629 533 pc.printf("\n %s", p->d_name);
rs27 1:19313470f629 534 FILE * f = fopen(buffer, "r");
rs27 1:19313470f629 535 fseek(f, 0, SEEK_END); // seek to end of file
rs27 1:19313470f629 536 size = ftell(f); // get current file pointer
rs27 1:19313470f629 537 pc.printf(" %ld bytes ",size);
rs27 1:19313470f629 538
rs27 1:19313470f629 539 time_t fattime = get_fattime();
rs27 1:19313470f629 540 strftime(buffer, 40, "%a,%d %m %Y.%H:%M:%S", localtime(&fattime));
rs27 1:19313470f629 541 pc.printf(" %s ", buffer);
rs27 1:19313470f629 542
rs27 1:19313470f629 543 fclose(f);
rs27 1:19313470f629 544 }
rs27 1:19313470f629 545
rs27 1:19313470f629 546 }
rs27 1:19313470f629 547 else
rs27 1:19313470f629 548 {
rs27 1:19313470f629 549 pc.printf("\nCould not open directory!\n");
rs27 1:19313470f629 550 }
rs27 1:19313470f629 551 closedir(d);
rs27 1:19313470f629 552
rs27 1:19313470f629 553
rs27 1:19313470f629 554 FATFS* fs;
rs27 1:19313470f629 555 DWORD fre_clust;
rs27 1:19313470f629 556 f_getfree("0:",&fre_clust,&fs);
rs27 1:19313470f629 557 const float frs = float(fs->csize)*float(fs->free_clust)
rs27 1:19313470f629 558 #if _MAX_SS != 512
rs27 1:19313470f629 559 *(fs->ssize);
rs27 1:19313470f629 560 #else
rs27 1:19313470f629 561 *512;
rs27 1:19313470f629 562 #endif
rs27 1:19313470f629 563 pc.printf("\n\nfree space = %f GB",frs/1073741824.0);
rs27 1:19313470f629 564
rs27 1:19313470f629 565 pc.printf("\ndone\n");
rs27 1:19313470f629 566 }
rs27 1:19313470f629 567
rs27 1:19313470f629 568 //-----------------------------------------------------------------------------
rs27 1:19313470f629 569 // monitor Aufruf list
rs27 1:19313470f629 570
rs27 1:19313470f629 571 void list(void)
rs27 1:19313470f629 572 {
rs27 1:19313470f629 573 char dname[25];
rs27 1:19313470f629 574 int ch;
rs27 1:19313470f629 575
rs27 1:19313470f629 576 sscanf(&com_line[ComLinePtr],"%s",dname);
rs27 1:19313470f629 577 sprintf(buffer,"/sd/%s",dname);
rs27 1:19313470f629 578 pc.printf("\nlist, file %s \n",buffer);
rs27 1:19313470f629 579 FILE * fp = fopen(buffer, "r");
rs27 1:19313470f629 580 if(fp == NULL)
rs27 1:19313470f629 581 {
rs27 1:19313470f629 582 pc.printf("\nCould not open file for read\n\r");
rs27 1:19313470f629 583 return;
rs27 1:19313470f629 584 }
rs27 1:19313470f629 585
rs27 1:19313470f629 586 // mit fgets werden die Zeile einzeln gelesen, wenn die Länge < 64 Zeichen ist
rs27 1:19313470f629 587
rs27 1:19313470f629 588 while (1) // list src to pc
rs27 1:19313470f629 589 {
rs27 1:19313470f629 590 ch = fgetc(fp); // until src EOF read.
rs27 1:19313470f629 591 if (ch == EOF) break;
rs27 1:19313470f629 592 pc.putc(ch);
rs27 1:19313470f629 593 }
rs27 1:19313470f629 594
rs27 1:19313470f629 595 fclose(fp);
rs27 1:19313470f629 596
rs27 1:19313470f629 597 pc.printf("\ndone\n");
rs27 1:19313470f629 598 }
rs27 1:19313470f629 599
rs27 1:19313470f629 600 //-----------------------------------------------------------------------------
rs27 1:19313470f629 601 // monitor Aufruf del
rs27 1:19313470f629 602
rs27 1:19313470f629 603 void del(void)
rs27 1:19313470f629 604 {
rs27 1:19313470f629 605 char dname[25];
rs27 1:19313470f629 606 char buffer[40];
rs27 1:19313470f629 607
rs27 1:19313470f629 608 sscanf(&com_line[ComLinePtr],"%s",dname);
rs27 1:19313470f629 609 sprintf(buffer,"/sd/%s",dname);
rs27 1:19313470f629 610 pc.printf("\ndelete file %s",buffer);
rs27 1:19313470f629 611 remove(buffer);
rs27 1:19313470f629 612 pc.printf("\ndone");
rs27 1:19313470f629 613 }
rs27 1:19313470f629 614
rs27 1:19313470f629 615 //-----------------------------------------------------------------------------
rs27 1:19313470f629 616 // monitor Aufruf fill
rs27 1:19313470f629 617
rs27 1:19313470f629 618 void fill(void)
rs27 1:19313470f629 619 {
rs27 1:19313470f629 620 char dname[25];
rs27 1:19313470f629 621 char buffer[40];
rs27 1:19313470f629 622 int n = 20;
rs27 1:19313470f629 623
rs27 1:19313470f629 624 sscanf(&com_line[ComLinePtr],"%s %d",dname,&n);
rs27 1:19313470f629 625 sprintf(buffer,"/sd/%s",dname);
rs27 1:19313470f629 626 pc.printf("\nfill file %s \n",buffer);
rs27 1:19313470f629 627 FILE *fp = fopen(buffer, "w");
rs27 1:19313470f629 628 if(fp == NULL)
rs27 1:19313470f629 629 {
rs27 1:19313470f629 630 pc.printf("Could not open file for write\n");
rs27 1:19313470f629 631 }
rs27 1:19313470f629 632 for (int i = 0; i<n; i++)
rs27 1:19313470f629 633 {
rs27 1:19313470f629 634 fprintf(fp, "\nschreibe eine Zeile %d ",i);
rs27 1:19313470f629 635 }
rs27 1:19313470f629 636 fclose(fp);
rs27 1:19313470f629 637 pc.printf("\ndone\n");
rs27 1:19313470f629 638 }
rs27 1:19313470f629 639
rs27 1:19313470f629 640