Monitor für das Tasterprogramm

Dependents:   19_Taster_BSW_oo 19_Taster_a

Fork of monitor by Temp27

Committer:
mauchcontrols
Date:
Tue Aug 18 14:38:41 2015 +0000
Revision:
9:7bd52cbe4782
Parent:
8:99a94e782c8a
OUT 1 ?nderung f?r BSW Nottaster

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 8:99a94e782c8a 4 #include <stdio.h>
rs27 8:99a94e782c8a 5 #include <string.h>
rs27 8:99a94e782c8a 6 #include <stdlib.h>
rs27 8:99a94e782c8a 7 #include "mbed.h"
rs27 8:99a94e782c8a 8 #include "main.h"
rs27 0:f0fbbfdca478 9 #include "monitor.h"
rs27 8:99a94e782c8a 10 #include "FreescaleIAP.h"
rs27 0:f0fbbfdca478 11
rs27 8:99a94e782c8a 12 extern "C" void mbed_reset();
rs27 1:19313470f629 13
rs27 8:99a94e782c8a 14 extern MODSERIAL pc;
rs27 1:19313470f629 15
mauchcontrols 9:7bd52cbe4782 16 extern DigitalOut OUT1; // Summer
rs27 8:99a94e782c8a 17 extern DigitalOut OUT2; // LED Rot
rs27 8:99a94e782c8a 18 extern DigitalOut OUT3; // LED Grün
rs27 8:99a94e782c8a 19 extern DigitalOut OUT4; // LED Gelb
mauchcontrols 9:7bd52cbe4782 20 extern DigitalOut OUT5; // nicht belegt
rs27 8:99a94e782c8a 21 extern DigitalOut OUT6; // Relais
rs27 0:f0fbbfdca478 22
rs27 1:19313470f629 23
rs27 8:99a94e782c8a 24 extern DigitalIn IN1; // nicht belegt
rs27 8:99a94e782c8a 25 extern DigitalIn IN2; // nicht belegt
rs27 8:99a94e782c8a 26 extern DigitalIn IN3; // Signalstation, Öffner => null im Ruheezustand ?
rs27 8:99a94e782c8a 27 extern DigitalIn IN4; // Sabotageschalter, nach Zeichnung müsste 1 der Ruhezustand sein => null ist Ruhezustand ?
rs27 8:99a94e782c8a 28 extern DigitalIn IN5; // Notaus, Öffner gegen GND => 0 ist der Ruhezustand
rs27 8:99a94e782c8a 29
rs27 8:99a94e782c8a 30 // test von variablen
rs27 8:99a94e782c8a 31
rs27 8:99a94e782c8a 32 int i = 0;
rs27 8:99a94e782c8a 33
rs27 8:99a94e782c8a 34 #define COMMAND_MAX 9
rs27 8:99a94e782c8a 35 #define COMMAND_LEN 7
rs27 8:99a94e782c8a 36 const char command[COMMAND_MAX][COMMAND_LEN] = {"DATE","DUMP","FLASH","HELP","IN","OUT","RESET","RGB","TIME"};
rs27 0:f0fbbfdca478 37
rs27 0:f0fbbfdca478 38 //-----------------------------------------------------------------------------
rs27 0:f0fbbfdca478 39 // destructor
rs27 0:f0fbbfdca478 40
rs27 8:99a94e782c8a 41 monitor::monitor(void)
rs27 0:f0fbbfdca478 42 {
rs27 8:99a94e782c8a 43 uint8_t i;
rs27 8:99a94e782c8a 44
rs27 8:99a94e782c8a 45 for (i = 0; i < COM_LINE_LEN; com_line[i++] = 0);
rs27 8:99a94e782c8a 46 ComLinePtr = ComLineTop = 0;
rs27 8:99a94e782c8a 47 cr_flag = false;
rs27 8:99a94e782c8a 48 }
rs27 8:99a94e782c8a 49
rs27 8:99a94e782c8a 50 //-------------------------------------------------------------------------------
rs27 8:99a94e782c8a 51 // _atoi
rs27 8:99a94e782c8a 52 //
rs27 8:99a94e782c8a 53 uint8_t monitor::_atoi(char c)
rs27 8:99a94e782c8a 54 {
rs27 8:99a94e782c8a 55 if ((c >= '0') && (c <= '9')) return (c - '0');
rs27 8:99a94e782c8a 56 if ((c >= 'a') && (c <= 'f')) return ((c - 'a') + 10);
rs27 8:99a94e782c8a 57 if ((c >= 'A') && (c <= 'F')) return ((c - 'A') + 10);
rs27 8:99a94e782c8a 58 return 0;
rs27 8:99a94e782c8a 59 }
rs27 8:99a94e782c8a 60
rs27 8:99a94e782c8a 61
rs27 8:99a94e782c8a 62 //-----------------------------------------------------------------------------
rs27 8:99a94e782c8a 63 // parser
rs27 0:f0fbbfdca478 64
rs27 8:99a94e782c8a 65 /*-------------------------------------------------------------------------*/
rs27 8:99a94e782c8a 66 /* */
rs27 8:99a94e782c8a 67 /* Synopsis : void parser (void) */
rs27 8:99a94e782c8a 68 /* */
rs27 8:99a94e782c8a 69 /* Funktion : */
rs27 8:99a94e782c8a 70 /* */
rs27 8:99a94e782c8a 71 /* Analysiert das Kommando und springt die entsprechende Routine aus der */
rs27 8:99a94e782c8a 72 /* Kommandotabelle an. Die Kommandos mssen in der Tabelle alphabetisch */
rs27 8:99a94e782c8a 73 /* sortiert sein. Der Index in der Kommandotabelle entspricht dem in der */
rs27 8:99a94e782c8a 74 /* Sprungtabelle. Die Suche nach dem Buchstaben beginnt beim Ersten mit- */
rs27 8:99a94e782c8a 75 /* tels der bin„ren Suche. Alle restlichen Zeichen werden durch String- */
rs27 8:99a94e782c8a 76 /* vergleiche nach der gleichen Methode ermittelt. */
rs27 8:99a94e782c8a 77 /* */
rs27 8:99a94e782c8a 78 /*-------------------------------------------------------------------------*/
rs27 0:f0fbbfdca478 79
rs27 8:99a94e782c8a 80 void monitor::parser (char p_line[])
rs27 8:99a94e782c8a 81 {
rs27 8:99a94e782c8a 82 char ch, tch;
rs27 8:99a94e782c8a 83 uint8_t i, top, bottom, len;
rs27 8:99a94e782c8a 84 int res;
rs27 8:99a94e782c8a 85
rs27 8:99a94e782c8a 86 // die Eingabe in Großbuchstaben umwandeln
rs27 8:99a94e782c8a 87
rs27 8:99a94e782c8a 88 for (i = 0; !(com_line[i] == 0 || com_line[i] == ' '); i++)
rs27 8:99a94e782c8a 89 com_line[i] = toupper (com_line[i]);
rs27 8:99a94e782c8a 90
rs27 8:99a94e782c8a 91 /* Zuerst wird der erste Buchstabe aus dem Eingabestring mit den ersten */
rs27 8:99a94e782c8a 92 /* Buchstaben aus der Befehlstabelle verglichen */
rs27 8:99a94e782c8a 93
rs27 8:99a94e782c8a 94 bottom = 0; /* untere Suchgrenze */
rs27 8:99a94e782c8a 95 tch = 0;
rs27 8:99a94e782c8a 96 top = COMMAND_MAX; /* obere Suchgerenze */
rs27 8:99a94e782c8a 97 ComLinePtr = 0; /* Parameterübergabe auf 0 setzen */
rs27 8:99a94e782c8a 98 ch = p_line[0]; /* hole erstes Suchzeichen */
rs27 0:f0fbbfdca478 99
rs27 0:f0fbbfdca478 100 do
rs27 0:f0fbbfdca478 101 {
rs27 8:99a94e782c8a 102 i = (top + bottom) >> 1; /* suche in der Mitte des Feldes beginnen */
rs27 8:99a94e782c8a 103 tch = (char) command [i][0]; /* Vergleichszeichen laden */
rs27 8:99a94e782c8a 104 if (tch == ch) break; /* Zeichen gefunden */
rs27 8:99a94e782c8a 105 if (tch > ch) top = i; /* nach unten suchen */
rs27 8:99a94e782c8a 106 else bottom = i; /* nach oben suchen */
rs27 8:99a94e782c8a 107 if (bottom != 0 && top == bottom + 1) break; /* kein Buchstabe gef. */
rs27 0:f0fbbfdca478 108
rs27 0:f0fbbfdca478 109 } while (i > 0 && i < COMMAND_MAX - 1);
rs27 0:f0fbbfdca478 110
rs27 0:f0fbbfdca478 111 if (tch != ch)
rs27 0:f0fbbfdca478 112 {
rs27 8:99a94e782c8a 113 pc.printf("\nParser, Kommando nicht gefunden\n");
rs27 8:99a94e782c8a 114 return; /* Kommando nicht gefunden wurde */
rs27 0:f0fbbfdca478 115 }
rs27 0:f0fbbfdca478 116
rs27 8:99a94e782c8a 117 /* das erst Wort soll von den Übergabeparametern isoliert werden */
rs27 0:f0fbbfdca478 118
rs27 8:99a94e782c8a 119 for (i = 0; p_line[i] != ' ' && p_line[i] != 0; i++);
rs27 0:f0fbbfdca478 120 len = i;
rs27 0:f0fbbfdca478 121
rs27 0:f0fbbfdca478 122
rs27 0:f0fbbfdca478 123 if (i == 0) return;
rs27 0:f0fbbfdca478 124
rs27 8:99a94e782c8a 125 /* die Übergabparameter ermitteln und in als Indexzeiger in */
rs27 8:99a94e782c8a 126 /* 'ComLinePtr' abspeichern */
rs27 0:f0fbbfdca478 127
rs27 8:99a94e782c8a 128 for ( ; p_line[i] == ' ' && p_line[i] != 0; i++);
rs27 0:f0fbbfdca478 129 ComLinePtr = i;
rs27 8:99a94e782c8a 130
rs27 8:99a94e782c8a 131
rs27 8:99a94e782c8a 132 /* die binäre Suche nach den restlichen Zeichen wird hier fortgesetzt */
rs27 0:f0fbbfdca478 133
rs27 0:f0fbbfdca478 134 do
rs27 0:f0fbbfdca478 135 {
rs27 8:99a94e782c8a 136 i = (top + bottom) >> 1; /* berechnen des Suchplatzes */
rs27 8:99a94e782c8a 137 // pc.printf("\nVergleich [%d] com_line [%s] command [%s] Länge [%d]",i,com_line, &command[i][0],len);
rs27 8:99a94e782c8a 138 res = strncmp(p_line, &command[i][0], len);
rs27 8:99a94e782c8a 139 // pc.printf("\nErgebnis res = [%d]",res);
rs27 8:99a94e782c8a 140 if (res == 0) break; /* Zeichen gefunden */
rs27 8:99a94e782c8a 141 if (res > 0)
rs27 8:99a94e782c8a 142 bottom = i; /* nach unten suchen */
rs27 8:99a94e782c8a 143 else
rs27 8:99a94e782c8a 144 top = i; /* nach oben suchen */
rs27 8:99a94e782c8a 145 if (bottom != 0 && top == bottom + 1) break;
rs27 0:f0fbbfdca478 146
rs27 0:f0fbbfdca478 147 } while (i > 0 && i < COMMAND_MAX - 1);
rs27 0:f0fbbfdca478 148
rs27 0:f0fbbfdca478 149
rs27 0:f0fbbfdca478 150 if (res)
rs27 0:f0fbbfdca478 151 {
rs27 8:99a94e782c8a 152 pc.printf("\nParser, Kommando nicht gefunden.\n");
rs27 0:f0fbbfdca478 153 }
rs27 0:f0fbbfdca478 154 else
rs27 0:f0fbbfdca478 155 {
rs27 8:99a94e782c8a 156 // "DATE","DUMP","HELP","RESET","RGB","TIME"
rs27 8:99a94e782c8a 157 // pc.printf("\nAufruf von Funktion %d",i);
rs27 8:99a94e782c8a 158 switch (i) // Programmaufruf
rs27 8:99a94e782c8a 159 {
rs27 8:99a94e782c8a 160 case 0: mdate(); break;
rs27 8:99a94e782c8a 161 case 1: dump(); break;
rs27 8:99a94e782c8a 162 case 2: flash(); break;
rs27 8:99a94e782c8a 163 case 3: help(); break;
rs27 8:99a94e782c8a 164 case 4: in(); break;
rs27 8:99a94e782c8a 165 case 5: out(); break;
rs27 8:99a94e782c8a 166 case 6: soft_reset(); break;
rs27 8:99a94e782c8a 167 case 7: rgb(); break;
rs27 8:99a94e782c8a 168 case 8: mtime(); break;
rs27 8:99a94e782c8a 169 }
rs27 8:99a94e782c8a 170
rs27 0:f0fbbfdca478 171 }
rs27 0:f0fbbfdca478 172 }
rs27 0:f0fbbfdca478 173
rs27 0:f0fbbfdca478 174
rs27 0:f0fbbfdca478 175 //-----------------------------------------------------------------------------
rs27 0:f0fbbfdca478 176 // eine Zeile aus dem Eingangsbuffer lesen
rs27 0:f0fbbfdca478 177
rs27 8:99a94e782c8a 178 void monitor::get_line(void)
rs27 0:f0fbbfdca478 179 {
rs27 8:99a94e782c8a 180 // char ch;
rs27 8:99a94e782c8a 181 uint8_t i;
rs27 8:99a94e782c8a 182
rs27 8:99a94e782c8a 183 get_ch();
rs27 8:99a94e782c8a 184 if (cr_flag) // Neue Eingabezeile
rs27 8:99a94e782c8a 185 {
rs27 8:99a94e782c8a 186 if (com_line[0] != 0)
rs27 0:f0fbbfdca478 187 {
rs27 8:99a94e782c8a 188 // uart_puts(com_line); // zum Testen => später wird der parcer aufgerufen
rs27 8:99a94e782c8a 189 parser(&com_line[0]); // Parcer wird aufgerufen
rs27 8:99a94e782c8a 190 }
rs27 0:f0fbbfdca478 191
rs27 8:99a94e782c8a 192 for (i=0; i < COM_LINE_LEN; com_line[i++] = 0);
rs27 8:99a94e782c8a 193 ComLinePtr = ComLineTop = 0;
rs27 8:99a94e782c8a 194 cr_flag = 0; // Parcer wird aufgerufen
rs27 8:99a94e782c8a 195 }
rs27 0:f0fbbfdca478 196 }
rs27 0:f0fbbfdca478 197
rs27 0:f0fbbfdca478 198 //-----------------------------------------------------------------------------
rs27 0:f0fbbfdca478 199 // eine Zeichen aus dem Eingangsbuffer lesen
rs27 0:f0fbbfdca478 200
rs27 8:99a94e782c8a 201 void monitor::get_ch (void)
rs27 0:f0fbbfdca478 202 {
rs27 8:99a94e782c8a 203 char ch;
rs27 0:f0fbbfdca478 204
rs27 8:99a94e782c8a 205 if (!pc.readable()) return; // kein Zeichen vorhanden
rs27 0:f0fbbfdca478 206
rs27 8:99a94e782c8a 207 ch = pc.getc(); // hole das Zeichen
rs27 0:f0fbbfdca478 208 // printf("mon_line: %c %02x\n",ch,ch); // nur zum Test
rs27 8:99a94e782c8a 209
rs27 0:f0fbbfdca478 210 switch(ch)
rs27 0:f0fbbfdca478 211 {
rs27 0:f0fbbfdca478 212 case '\r': // CARRIAGE RETURN
rs27 8:99a94e782c8a 213 cr_flag = true;
rs27 8:99a94e782c8a 214 break;
rs27 0:f0fbbfdca478 215
rs27 0:f0fbbfdca478 216 case '\n': // LF empfangen
rs27 8:99a94e782c8a 217 cr_flag = true;
rs27 8:99a94e782c8a 218 break;
rs27 0:f0fbbfdca478 219
rs27 0:f0fbbfdca478 220 default: // Normales Zeichen
rs27 8:99a94e782c8a 221 if (~iscntrl(ch))
rs27 8:99a94e782c8a 222 {
rs27 8:99a94e782c8a 223 com_line[ComLinePtr] = ch; // Zeichen einfuegen
rs27 8:99a94e782c8a 224 ComLinePtr++;
rs27 8:99a94e782c8a 225 }
rs27 8:99a94e782c8a 226 break;
rs27 0:f0fbbfdca478 227
rs27 0:f0fbbfdca478 228 } // Ende SWITCH
rs27 8:99a94e782c8a 229
rs27 8:99a94e782c8a 230 if (ComLinePtr >= 80) cr_flag = 1; // Zeilenüberlauf ?
rs27 0:f0fbbfdca478 231
rs27 0:f0fbbfdca478 232 }
rs27 0:f0fbbfdca478 233
rs27 0:f0fbbfdca478 234 //-----------------------------------------------------------------------------
rs27 0:f0fbbfdca478 235 // monitor Aufruf
rs27 0:f0fbbfdca478 236
rs27 8:99a94e782c8a 237 void monitor::mdate(void)
rs27 0:f0fbbfdca478 238 {
rs27 8:99a94e782c8a 239 int day, month, year, n;
rs27 8:99a94e782c8a 240
rs27 8:99a94e782c8a 241 n = 0;
rs27 8:99a94e782c8a 242 day = 0;
rs27 8:99a94e782c8a 243 month = 0;
rs27 8:99a94e782c8a 244 year = 0;
rs27 8:99a94e782c8a 245
rs27 8:99a94e782c8a 246 n = sscanf(&com_line[ComLinePtr],"%d %d %d",&day, &month, &year);
rs27 8:99a94e782c8a 247
rs27 8:99a94e782c8a 248 // seconds = time(NULL);
rs27 8:99a94e782c8a 249
rs27 8:99a94e782c8a 250 struct tm t, *tp;
rs27 8:99a94e782c8a 251 time_t seconds = time(NULL);
rs27 8:99a94e782c8a 252 tp = localtime(&seconds);
rs27 8:99a94e782c8a 253 t = *tp;
rs27 8:99a94e782c8a 254
rs27 8:99a94e782c8a 255 switch (n)
rs27 8:99a94e782c8a 256 {
rs27 8:99a94e782c8a 257 case -1 : // keine Zeichenübergabe
rs27 8:99a94e782c8a 258 case 0 : // keine Zeichenübergabe
rs27 8:99a94e782c8a 259
rs27 8:99a94e782c8a 260 pc.printf("\ndate %02d.%02d.%04d",t.tm_mday, t.tm_mon + 1, t.tm_year + 1900);
rs27 8:99a94e782c8a 261 break;
rs27 8:99a94e782c8a 262
rs27 8:99a94e782c8a 263 case 1 : // day
rs27 8:99a94e782c8a 264 case 2 : // month
rs27 8:99a94e782c8a 265 case 3 : // year
rs27 8:99a94e782c8a 266
rs27 8:99a94e782c8a 267 if (day > 31) day = 31;
rs27 8:99a94e782c8a 268 if (day < 1) day = 1;
rs27 8:99a94e782c8a 269
rs27 8:99a94e782c8a 270 if (month > 12) month = 12;
rs27 8:99a94e782c8a 271 if (month < 0) month = 0;
rs27 8:99a94e782c8a 272
rs27 8:99a94e782c8a 273 if (year > 2053) year = 2053;
rs27 8:99a94e782c8a 274 if (year < 2013) year = 2013;
rs27 8:99a94e782c8a 275
rs27 8:99a94e782c8a 276 // setup time structure for Wed, 11 April 2013 5:00:00
rs27 8:99a94e782c8a 277 // t.tm_sec = sek; // 0-59
rs27 8:99a94e782c8a 278 // t.tm_min = min; // 0-59
rs27 8:99a94e782c8a 279 // t.tm_hour = std; // 0-23
rs27 8:99a94e782c8a 280 t.tm_mday = day; // 1-31
rs27 8:99a94e782c8a 281 t.tm_mon = (month - 1); // 0-11 >> prüfen warum 0 bis 11 ???
rs27 8:99a94e782c8a 282 t.tm_year = (year - 1900); // year since 1900
rs27 8:99a94e782c8a 283
rs27 8:99a94e782c8a 284 // Set RTC time today
rs27 8:99a94e782c8a 285 set_time(mktime(&t));
rs27 8:99a94e782c8a 286
rs27 8:99a94e782c8a 287 pc.printf("\nnew date %02d.%02d.%04d",t.tm_mday, t.tm_mon+1, t.tm_year + 1900);
rs27 8:99a94e782c8a 288 break;
rs27 8:99a94e782c8a 289 } // end while
rs27 8:99a94e782c8a 290
rs27 0:f0fbbfdca478 291 }
rs27 0:f0fbbfdca478 292
rs27 8:99a94e782c8a 293 void monitor::flash()
rs27 0:f0fbbfdca478 294 {
rs27 8:99a94e782c8a 295 int n, address, val;
rs27 8:99a94e782c8a 296 uint8_t _val;
rs27 8:99a94e782c8a 297
rs27 8:99a94e782c8a 298 address = 0;
rs27 8:99a94e782c8a 299 val = 0;
rs27 8:99a94e782c8a 300 char *p;
rs27 8:99a94e782c8a 301
rs27 8:99a94e782c8a 302 n = sscanf(&com_line[ComLinePtr],"%d %d", &address, &val);
rs27 8:99a94e782c8a 303
rs27 8:99a94e782c8a 304 // Abfrage der Eingabe
rs27 8:99a94e782c8a 305
rs27 8:99a94e782c8a 306 if ((n == -1) || (n == 0))
rs27 8:99a94e782c8a 307 {
rs27 8:99a94e782c8a 308 pc.printf("\nder letzte Speicherblock wird fuer Variablen verwendet");
rs27 8:99a94e782c8a 309 pc.printf("\n flash adr [value]");
rs27 8:99a94e782c8a 310 pc.printf("\n adr ist die Adresse im ausgewaehlten Block");
rs27 8:99a94e782c8a 311 pc.printf("\n value ist der Wert der als INT abgespeichert wird");
rs27 8:99a94e782c8a 312 pc.printf("\n bei der Adresse -1 wird der flash Speicher geloescht");
rs27 8:99a94e782c8a 313 pc.printf("\n");
rs27 8:99a94e782c8a 314 }
rs27 8:99a94e782c8a 315
rs27 8:99a94e782c8a 316 if (n == 1)
rs27 8:99a94e782c8a 317 {
rs27 8:99a94e782c8a 318 if (address == -1)
rs27 8:99a94e782c8a 319 {
rs27 8:99a94e782c8a 320 address = 0x1fc00;
rs27 8:99a94e782c8a 321 //Erase sectors of 4096 bytes
rs27 8:99a94e782c8a 322 pc.printf("\nflash erace");
rs27 8:99a94e782c8a 323 erase_sector(address);
rs27 8:99a94e782c8a 324 return;
rs27 8:99a94e782c8a 325 }
rs27 8:99a94e782c8a 326
rs27 8:99a94e782c8a 327 address += 0x1fc00;
rs27 8:99a94e782c8a 328 p = (char*)address;
rs27 8:99a94e782c8a 329 pc.printf("\nflash data = %d oder 0x%02x",*p);
rs27 8:99a94e782c8a 330 }
rs27 8:99a94e782c8a 331
rs27 8:99a94e782c8a 332 if (n == 2)
rs27 8:99a94e782c8a 333 {
rs27 8:99a94e782c8a 334 address += 0x1fc00;
rs27 8:99a94e782c8a 335 _val = (uint8_t) val;
rs27 8:99a94e782c8a 336 if (program_flash(address, (char*)&_val, 4) != 0) {// 1 bytes
rs27 8:99a94e782c8a 337 pc.printf("\nData Write Error!");
rs27 8:99a94e782c8a 338 } else {
rs27 8:99a94e782c8a 339 pc.printf("\nData Write Success!");
rs27 8:99a94e782c8a 340 }
rs27 8:99a94e782c8a 341 }
rs27 0:f0fbbfdca478 342 }
rs27 0:f0fbbfdca478 343
rs27 0:f0fbbfdca478 344 //-----------------------------------------------------------------------------
rs27 0:f0fbbfdca478 345 // monitor Aufruf
rs27 0:f0fbbfdca478 346
rs27 8:99a94e782c8a 347 void monitor::dump(void)
rs27 0:f0fbbfdca478 348 {
rs27 8:99a94e782c8a 349 char c, szBuf[17];
rs27 8:99a94e782c8a 350 //uint16_t lOutLen;
rs27 8:99a94e782c8a 351 unsigned int lSize, n;
rs27 8:99a94e782c8a 352 unsigned long adr;
rs27 8:99a94e782c8a 353
rs27 8:99a94e782c8a 354 char *p;
rs27 8:99a94e782c8a 355
rs27 8:99a94e782c8a 356
rs27 8:99a94e782c8a 357 adr = 0x1fc00; // letzter Block
rs27 8:99a94e782c8a 358 lSize = 100;
rs27 8:99a94e782c8a 359
rs27 8:99a94e782c8a 360 n = sscanf((char *)&com_line[ComLinePtr],"%lx %u",&adr, &lSize);
rs27 8:99a94e782c8a 361
rs27 8:99a94e782c8a 362 pc.printf( "\ndump from 0x%08X for %d bytes", adr, lSize );
rs27 8:99a94e782c8a 363
rs27 8:99a94e782c8a 364 p = (char *)adr;
rs27 8:99a94e782c8a 365
rs27 8:99a94e782c8a 366 for ( int i = 0; i < lSize; i++, p++, n++ )
rs27 8:99a94e782c8a 367 {
rs27 8:99a94e782c8a 368 if ( !(i % 16) )
rs27 8:99a94e782c8a 369 {
rs27 8:99a94e782c8a 370 if (i > 0) pc.printf(" %s",szBuf);
rs27 8:99a94e782c8a 371
rs27 8:99a94e782c8a 372 for (n = 0; n < 16; n++) szBuf[n] = ' ';
rs27 8:99a94e782c8a 373 szBuf[16] = 0; // nullterminierter String
rs27 8:99a94e782c8a 374
rs27 8:99a94e782c8a 375 n = 0;
rs27 8:99a94e782c8a 376
rs27 8:99a94e782c8a 377 pc.printf( "\r\n 0x%08X :", (unsigned int)p );
rs27 8:99a94e782c8a 378 }
rs27 8:99a94e782c8a 379
rs27 8:99a94e782c8a 380 c = *p;
rs27 8:99a94e782c8a 381 if ((c >= 0x30) && (c <= 128))szBuf[n] = c;
rs27 8:99a94e782c8a 382 else szBuf[n] = '.';
rs27 8:99a94e782c8a 383
rs27 8:99a94e782c8a 384 pc.printf( " %02x", c );
rs27 8:99a94e782c8a 385 }
rs27 8:99a94e782c8a 386
rs27 8:99a94e782c8a 387 pc.printf( "\r\n" );
rs27 8:99a94e782c8a 388
rs27 8:99a94e782c8a 389 }
rs27 8:99a94e782c8a 390
rs27 8:99a94e782c8a 391
rs27 8:99a94e782c8a 392 //-----------------------------------------------------------------------------
rs27 8:99a94e782c8a 393 // monitor Aufruf
rs27 8:99a94e782c8a 394
rs27 8:99a94e782c8a 395 void monitor::help(void)
rs27 8:99a94e782c8a 396 {
rs27 8:99a94e782c8a 397 pc.printf("\n -- help ------------------------");
rs27 8:99a94e782c8a 398 pc.printf("\n date dd mm jjjj >> Datum abfragen / setzen");
rs27 8:99a94e782c8a 399 pc.printf("\n dump Speicherbereich ausgeben");
rs27 8:99a94e782c8a 400 pc.printf("\n flash Speicherbereich letzter Block fuer Variablen");
rs27 8:99a94e782c8a 401 pc.printf("\n in Lesen und Anzeigen der digitalen Eingaenge");
rs27 8:99a94e782c8a 402 pc.printf("\n out [x] [y] [t] Schalten der Ausgaenge ");
rs27 8:99a94e782c8a 403 pc.printf("\n rgb Testen der LED's ");
rs27 8:99a94e782c8a 404 pc.printf("\n reset Soft Reset ausfuehren ");
rs27 8:99a94e782c8a 405 pc.printf("\n time hh mm ss >> Zeit abfragen / setzen");
rs27 8:99a94e782c8a 406 pc.printf("\n");
rs27 0:f0fbbfdca478 407 }
rs27 0:f0fbbfdca478 408
rs27 0:f0fbbfdca478 409 //-----------------------------------------------------------------------------
rs27 0:f0fbbfdca478 410 // monitor Aufruf
rs27 0:f0fbbfdca478 411
rs27 8:99a94e782c8a 412 void monitor::mtime(void)
rs27 0:f0fbbfdca478 413 {
rs27 8:99a94e782c8a 414 int std,min,sek, n;
rs27 0:f0fbbfdca478 415
rs27 8:99a94e782c8a 416 std = 0;
rs27 8:99a94e782c8a 417 min = 0;
rs27 8:99a94e782c8a 418 sek = 0;
Sven3010 7:f5bfddb84d63 419
rs27 8:99a94e782c8a 420 n = sscanf(&com_line[ComLinePtr],"%d %d %d",&std, &min, &sek);
Sven3010 7:f5bfddb84d63 421
rs27 8:99a94e782c8a 422 struct tm t, *tp;
rs27 8:99a94e782c8a 423 time_t seconds = time(NULL);
rs27 8:99a94e782c8a 424 tp = localtime(&seconds);
rs27 8:99a94e782c8a 425 t = *tp;
rs27 2:e330478fb0b6 426
rs27 2:e330478fb0b6 427 switch (n)
rs27 2:e330478fb0b6 428 {
rs27 8:99a94e782c8a 429 case -1 : // keine Zeichenübergabe
rs27 8:99a94e782c8a 430 case 0 : // keine Zeichenübergabe
rs27 8:99a94e782c8a 431
rs27 8:99a94e782c8a 432 pc.printf("\ntime %02d:%02d:%02d", t.tm_hour, t.tm_min, t.tm_sec);
rs27 2:e330478fb0b6 433 break;
rs27 8:99a94e782c8a 434
rs27 8:99a94e782c8a 435 case 1 : // std
rs27 8:99a94e782c8a 436 case 2 : // min
rs27 8:99a94e782c8a 437 case 3 : // sek
rs27 8:99a94e782c8a 438
rs27 8:99a94e782c8a 439
rs27 8:99a94e782c8a 440 if (sek > 59) sek = 59;
rs27 8:99a94e782c8a 441 if (sek < 0) sek = 0;
rs27 8:99a94e782c8a 442
rs27 8:99a94e782c8a 443 if (min > 59) min = 59;
rs27 8:99a94e782c8a 444 if (min < 0) min = 0;
rs27 2:e330478fb0b6 445
rs27 8:99a94e782c8a 446 if (std > 23) std = 23;
rs27 8:99a94e782c8a 447 if (std < 0) std = 0;
rs27 2:e330478fb0b6 448
rs27 8:99a94e782c8a 449 // setup time structure for Wed, 11 April 2013 5:00:00
rs27 8:99a94e782c8a 450 t.tm_sec = sek; // 0-59
rs27 8:99a94e782c8a 451 t.tm_min = min; // 0-59
rs27 8:99a94e782c8a 452 t.tm_hour = std; // 0-23
rs27 8:99a94e782c8a 453 // t.tm_mday = 23; // 1-31
rs27 8:99a94e782c8a 454 // t.tm_mon = 6; // 0-11
rs27 8:99a94e782c8a 455 // t.tm_year = 113; // year since 1900
rs27 8:99a94e782c8a 456
rs27 8:99a94e782c8a 457 // Set RTC time today
rs27 8:99a94e782c8a 458 set_time(mktime(&t));
rs27 8:99a94e782c8a 459
rs27 8:99a94e782c8a 460 pc.printf("\nnew time %02d:%02d:%02d", t.tm_hour, t.tm_min, t.tm_sec);
rs27 8:99a94e782c8a 461 break;
rs27 8:99a94e782c8a 462 }
rs27 2:e330478fb0b6 463 }
rs27 8:99a94e782c8a 464
rs27 8:99a94e782c8a 465 //------------------------------------------------------------------------
rs27 8:99a94e782c8a 466 // ein RESET ausführen
rs27 8:99a94e782c8a 467
rs27 8:99a94e782c8a 468 void monitor::soft_reset(void)
rs27 8:99a94e782c8a 469 {
rs27 8:99a94e782c8a 470 pc.printf("\nauf WDT Reset warten");
rs27 8:99a94e782c8a 471 // mbed_reset();
rs27 8:99a94e782c8a 472 while(1); // auf watchdog warten
rs27 8:99a94e782c8a 473 }
rs27 8:99a94e782c8a 474
rs27 8:99a94e782c8a 475 //------------------------------------------------------------------------
rs27 8:99a94e782c8a 476 // die LED's testen
rs27 8:99a94e782c8a 477 //
rs27 8:99a94e782c8a 478 // DigitalOut OUT2; // LED Rot
rs27 8:99a94e782c8a 479 // DigitalOut OUT3; // LED Grün
rs27 8:99a94e782c8a 480 // DigitalOut OUT4; // LED Gelb
rs27 8:99a94e782c8a 481 //
rs27 2:e330478fb0b6 482
rs27 8:99a94e782c8a 483 void monitor::rgb(void)
rs27 2:e330478fb0b6 484 {
rs27 8:99a94e782c8a 485 bool out2, out3, out4;
rs27 8:99a94e782c8a 486
rs27 8:99a94e782c8a 487 pc.printf("\nLED TEST");
rs27 8:99a94e782c8a 488 out2 = OUT2;
rs27 8:99a94e782c8a 489 out3 = OUT3;
rs27 8:99a94e782c8a 490 out4 = OUT4;
rs27 8:99a94e782c8a 491
rs27 8:99a94e782c8a 492 OUT2 = LED_AUS;
rs27 8:99a94e782c8a 493 OUT3 = LED_EIN;
rs27 8:99a94e782c8a 494 OUT4 = LED_AUS;
rs27 8:99a94e782c8a 495
rs27 8:99a94e782c8a 496 pc.printf("\n gruene LED an");
rs27 8:99a94e782c8a 497 wait(1);
rs27 2:e330478fb0b6 498
rs27 8:99a94e782c8a 499 OUT2 = LED_AUS;
rs27 8:99a94e782c8a 500 OUT3 = LED_AUS;
rs27 8:99a94e782c8a 501 OUT4 = LED_EIN;
rs27 8:99a94e782c8a 502
rs27 8:99a94e782c8a 503 pc.printf("\n gelbe LED an");
rs27 8:99a94e782c8a 504 wait(1);
rs27 8:99a94e782c8a 505
rs27 8:99a94e782c8a 506 OUT2 = LED_EIN;
rs27 8:99a94e782c8a 507 OUT3 = LED_AUS;
rs27 8:99a94e782c8a 508 OUT4 = LED_AUS;
rs27 8:99a94e782c8a 509
rs27 8:99a94e782c8a 510 pc.printf("\n rote LED an");
rs27 8:99a94e782c8a 511 wait(1);
rs27 8:99a94e782c8a 512
rs27 8:99a94e782c8a 513 OUT2 = out2;
rs27 8:99a94e782c8a 514 OUT3 = out3;
rs27 8:99a94e782c8a 515 OUT4 = out4;
rs27 8:99a94e782c8a 516
rs27 8:99a94e782c8a 517 }
rs27 8:99a94e782c8a 518
rs27 8:99a94e782c8a 519 //------------------------------------------------------------------------
rs27 8:99a94e782c8a 520 // die Ausgänge 1 bis 5 ansteuern ( für eine Sekunge aktiv schalten
rs27 8:99a94e782c8a 521 //
rs27 8:99a94e782c8a 522 // DigitalOut OUT1; // nicht belegt lo aktiv
rs27 8:99a94e782c8a 523 // DigitalOut OUT2; // LED Rot lo aktiv
rs27 8:99a94e782c8a 524 // DigitalOut OUT3; // LED Grün lo aktiv
rs27 8:99a94e782c8a 525 // DigitalOut OUT4; // LED Gelb lo aktiv
rs27 8:99a94e782c8a 526 // DigitalOut OUT5; // Summer hi aktiv
rs27 8:99a94e782c8a 527 // DigitalOut OUT6; // Relais lo aktiv
rs27 8:99a94e782c8a 528 //
rs27 8:99a94e782c8a 529
rs27 2:e330478fb0b6 530
rs27 8:99a94e782c8a 531 void monitor::out(void)
rs27 8:99a94e782c8a 532 {
rs27 8:99a94e782c8a 533 int n, x, y;
rs27 8:99a94e782c8a 534 bool out;
rs27 8:99a94e782c8a 535 float w_zeit;
rs27 8:99a94e782c8a 536
rs27 8:99a94e782c8a 537 x = 1;
rs27 8:99a94e782c8a 538 y = 0;
rs27 8:99a94e782c8a 539 w_zeit = 10;
rs27 8:99a94e782c8a 540
rs27 8:99a94e782c8a 541 n = sscanf(&com_line[ComLinePtr],"%d %d %f", &x, &y, &w_zeit);
rs27 8:99a94e782c8a 542
rs27 8:99a94e782c8a 543 // Abfrage der Eingabe
rs27 8:99a94e782c8a 544
rs27 8:99a94e782c8a 545 if ((n == -1) || (n == 0))
rs27 8:99a94e782c8a 546 {
rs27 8:99a94e782c8a 547 pc.printf("\ntest der digitalen Ausgaenge");
rs27 8:99a94e782c8a 548 pc.printf("\n out x y t");
rs27 8:99a94e782c8a 549 pc.printf("\n x ist die Nummer des Ausgangs 1 bis 5");
rs27 8:99a94e782c8a 550 pc.printf("\n y ist der Schaltzustand 0 oder 1");
rs27 8:99a94e782c8a 551 pc.printf("\n t ist die Zeit in Sekunden 0 bis 1000");
rs27 8:99a94e782c8a 552 pc.printf("\n");
mauchcontrols 9:7bd52cbe4782 553 pc.printf("\n Ausgang 1 (Summer) = %d",(uint8_t)OUT1);
rs27 8:99a94e782c8a 554 pc.printf("\n Ausgang 2 (LED rot ) = %d",(uint8_t)OUT2);
rs27 8:99a94e782c8a 555 pc.printf("\n Ausgang 3 (LED gruen ) = %d",(uint8_t)OUT3);
rs27 8:99a94e782c8a 556 pc.printf("\n Ausgang 4 (LED gelb ) = %d",(uint8_t)OUT4);
mauchcontrols 9:7bd52cbe4782 557 pc.printf("\n Ausgang 5 (nicht belegt ) = %d",(uint8_t)OUT5);
rs27 8:99a94e782c8a 558 pc.printf("\n Ausgang 6 (Relais ) = %d",(uint8_t)OUT6);
rs27 8:99a94e782c8a 559 }
rs27 8:99a94e782c8a 560
rs27 8:99a94e782c8a 561 // Auswerten auf gültige Eingaben
rs27 8:99a94e782c8a 562 if (!((x > 0) && (x <=6)))
rs27 8:99a94e782c8a 563 {
rs27 8:99a94e782c8a 564 pc.printf("\nFuer x bitte nur Werte von 1 bis 6 eingeben [x = %d]\n",x);
rs27 8:99a94e782c8a 565 return;
rs27 8:99a94e782c8a 566 }
rs27 8:99a94e782c8a 567
rs27 8:99a94e782c8a 568
rs27 8:99a94e782c8a 569 if (!((y == 0) || (y == 1)))
rs27 8:99a94e782c8a 570 {
rs27 8:99a94e782c8a 571 pc.printf("\nFuer y bitte nur Werte von 0 oder 1 eingeben [y = %d]",y);
rs27 8:99a94e782c8a 572 return;
rs27 8:99a94e782c8a 573 }
rs27 8:99a94e782c8a 574
rs27 8:99a94e782c8a 575
rs27 8:99a94e782c8a 576 if ((w_zeit <= 0) || (w_zeit > 1000))
rs27 8:99a94e782c8a 577 {
rs27 8:99a94e782c8a 578 pc.printf("\nFuer w_zeit bitte nur Werte von 0 oder 1000 eingeben [w_zeit = %f]",w_zeit);
rs27 8:99a94e782c8a 579 return;
rs27 8:99a94e782c8a 580 }
rs27 8:99a94e782c8a 581
rs27 8:99a94e782c8a 582 // Ausgänge schalten
rs27 2:e330478fb0b6 583
rs27 8:99a94e782c8a 584 switch(x)
rs27 8:99a94e782c8a 585 {
rs27 8:99a94e782c8a 586 case 1:
rs27 8:99a94e782c8a 587 pc.printf("\n OOU1 auf %d schalten, Wartezeit %0.1f",y,w_zeit);
rs27 8:99a94e782c8a 588 out = OUT1;
rs27 8:99a94e782c8a 589 OUT1 = (bool)y;
rs27 8:99a94e782c8a 590 wait(w_zeit);
rs27 8:99a94e782c8a 591 OUT1 = out;
rs27 8:99a94e782c8a 592 break;
rs27 8:99a94e782c8a 593 case 2:
rs27 8:99a94e782c8a 594 pc.printf("\n OOU2 auf %d schalten, Wartezeit %0.1f",y,w_zeit);
rs27 8:99a94e782c8a 595 out = OUT2;
rs27 8:99a94e782c8a 596 OUT2 = (bool)y;
rs27 8:99a94e782c8a 597 wait(w_zeit);
rs27 8:99a94e782c8a 598 OUT2 = out;
rs27 8:99a94e782c8a 599 break;
rs27 8:99a94e782c8a 600 case 3:
rs27 8:99a94e782c8a 601 pc.printf("\n OOU3 auf %d schalten, Wartezeit %0.1f",y,w_zeit);
rs27 8:99a94e782c8a 602 out = OUT3;
rs27 8:99a94e782c8a 603 OUT3 = (bool)y;
rs27 8:99a94e782c8a 604 wait(w_zeit);
rs27 8:99a94e782c8a 605 OUT3 = out;
rs27 8:99a94e782c8a 606 break;
rs27 8:99a94e782c8a 607 case 4:
rs27 8:99a94e782c8a 608 pc.printf("\n OOU4 auf %d schalten, Wartezeit %0.1f",y,w_zeit);
rs27 8:99a94e782c8a 609 out = OUT4;
rs27 8:99a94e782c8a 610 OUT4 = (bool)y;
rs27 8:99a94e782c8a 611 wait(w_zeit);
rs27 8:99a94e782c8a 612 OUT4 = out;
rs27 8:99a94e782c8a 613 break;
rs27 8:99a94e782c8a 614 case 5:
rs27 8:99a94e782c8a 615 pc.printf("\n OOU5 auf %d schalten, Wartezeit %0.1f",y,w_zeit);
rs27 8:99a94e782c8a 616 out = OUT5;
rs27 8:99a94e782c8a 617 OUT5 = (bool)y;
rs27 8:99a94e782c8a 618 wait(w_zeit);
rs27 8:99a94e782c8a 619 OUT5 = out;
rs27 8:99a94e782c8a 620 break;
rs27 8:99a94e782c8a 621 case 6:
rs27 8:99a94e782c8a 622 pc.printf("\n Relais auf %d schalten, Wartezeit %0.1f",y,w_zeit);
rs27 8:99a94e782c8a 623 out = OUT6;
rs27 8:99a94e782c8a 624 OUT6 = (bool)y;
rs27 8:99a94e782c8a 625 wait(w_zeit);
rs27 8:99a94e782c8a 626 OUT6 = out;
rs27 8:99a94e782c8a 627 break;
rs27 8:99a94e782c8a 628 } // end switch
rs27 8:99a94e782c8a 629
rs27 8:99a94e782c8a 630
rs27 8:99a94e782c8a 631 pc.printf("\n done \n");
rs27 8:99a94e782c8a 632
rs27 8:99a94e782c8a 633 }
rs27 8:99a94e782c8a 634
rs27 8:99a94e782c8a 635 //------------------------------------------------------------------------
rs27 8:99a94e782c8a 636 // Lesen und Anzeigen der Eingänge
rs27 8:99a94e782c8a 637 //
rs27 8:99a94e782c8a 638 // DigitalIn IN1; // nicht belegt
rs27 8:99a94e782c8a 639 // DigitalIn IN2; // nicht belegt
rs27 8:99a94e782c8a 640 // DigitalIn IN3; // Signalstation, Öffner => null im Ruheezustand ?
rs27 8:99a94e782c8a 641 // DigitalIn IN4; // Sabotageschalter, nach Zeichnung müsste 1 der Ruhezustand sein => null ist Ruhezustand ?
rs27 8:99a94e782c8a 642 // DigitalIn IN5; // Notaus, Öffner gegen GND => 0 ist der Ruhezustand
rs27 8:99a94e782c8a 643 //
rs27 8:99a94e782c8a 644
rs27 8:99a94e782c8a 645 void monitor::in(void)
rs27 8:99a94e782c8a 646 {
rs27 8:99a94e782c8a 647 pc.printf("\nLesen und Anzeigen der digitalen Eingaenge");
rs27 8:99a94e782c8a 648 pc.printf("\n");
rs27 8:99a94e782c8a 649 pc.printf("\n Eingang 1 (nicht belegt ) = %d Schaltpegel 24V offener Eingang = 0",(uint8_t)IN1);
rs27 8:99a94e782c8a 650 pc.printf("\n Eingang 2 (nicht belegt ) = %d Schaltpegel 24V offener Eingang = 0",(uint8_t)IN2);
rs27 8:99a94e782c8a 651 pc.printf("\n Eingang 3 (Signalstation ) = %d Schaltpegel 24V offener Eingang = 0",(uint8_t)IN3);
rs27 8:99a94e782c8a 652 pc.printf("\n Eingang 4 (Sabotageschalter ) = %d schaltet gegen GND offener Eingang = 1",(uint8_t)IN4);
rs27 8:99a94e782c8a 653 pc.printf("\n Eingang 5 (Notaus ) = %d schaltet gegen GND offener Eingang = 1",(uint8_t)IN5);
Sven3010 3:254f7ffb9b32 654 pc.printf("\n");
rs27 2:e330478fb0b6 655 }
rs27 2:e330478fb0b6 656