Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mon by
mon.cpp
00001 00002 //--------------------------------------------------------------------------- 00003 // Modul...: MON.CPP 00004 // Chip....: iox.mini 00005 // 00006 //--------------------------------------------------------------------------- 00007 // Author..: Reinhold Schäfer 00008 // Date....: 2016.01.23 00009 // http....: //www.microsps.net 00010 //--------------------------------------------------------------------------- 00011 #include <stdarg.h> 00012 #include <ctype.h> 00013 #include "mbed.h" 00014 #include "mon.h" 00015 #include "MODSERIAL.h" 00016 #include "timer0.h" 00017 00018 extern MODSERIAL pc; // definiert in main 00019 extern timer0 down_timer; // Timer für Zeitsteuerung, definiert in main 00020 00021 extern DigitalOut out1; 00022 extern DigitalOut out2; 00023 extern DigitalOut out3; 00024 extern DigitalOut out4; 00025 00026 #define COMMAND_MAX 5 00027 #define COMMAND_LEN 7 00028 // "DUMP","HELP","SET","TIME"}; 00029 const char command[COMMAND_MAX][COMMAND_LEN] = {"DUMP","HELP","SET","TIME"}; 00030 00031 //----------------------------------------------------------------------------- 00032 // constructor 00033 00034 monitor::monitor(void) 00035 { 00036 uint8_t i; 00037 00038 for (i = 0; i < MON_LINE_LEN; mon_line[i++] = 0); 00039 MonLinePtr = 0; 00040 } 00041 00042 //--------------------------------------------------------------------------- 00043 // 00044 // Function name : PARSER 00045 // 00046 // Returns : none 00047 // 00048 // Parameters : none 00049 // 00050 // Purpose : wertet die Eingangszeile aus und verzweigt zum gewünschten 00051 // Programm 00052 // 00053 //--------------------------------------------------------------------------- 00054 void monitor::parser (void) 00055 { 00056 uint8_t i, ch, tch, top, bottom, len; 00057 int8_t res; 00058 00059 // Zuerst wird der erste Buchstabe aus dem Eingabestring mit den ersten 00060 // Buchstaben aus der Befehlstabelle verglichen 00061 00062 bottom = 0; // untere Suchgrenze 00063 top = COMMAND_MAX; // obere Suchgerenze 00064 ch = mon_line[0]; // hole erstes Suchzeichen 00065 00066 do 00067 { 00068 i = (top + bottom) >> 1; // suche in der Mitte des Feldes beginnen 00069 tch = command [i][0]; // Vergleichszeichen laden 00070 if (tch == ch) break; // Zeichen gefunden 00071 if (tch > ch) top = i; // nach unten suchen 00072 else bottom = i; // nach oben suchen 00073 if (bottom != 0 && top == bottom + 1) break; // kein Buchstabe gef. 00074 00075 } while (i > 0 && i < COMMAND_MAX - 1); 00076 00077 if (tch != ch) 00078 { 00079 pc.printf("\nParser Kommando nicht gefunden\n"); 00080 return; // Kommando nicht gefunden wurde 00081 } 00082 00083 // das erst Wort soll von den Übergabeparametern isoliert werden 00084 00085 for (i = 0; mon_line[i] != ' ' && mon_line[i] != 0; i++); 00086 len = i; 00087 00088 00089 if (i == 0) return; 00090 00091 // die Übergabparameter ermitteln und in als Indexzeiger in 00092 // 'ComLinePtr' abspeichern 00093 00094 for ( ; mon_line[i] == ' ' && mon_line[i] != 0; i++); 00095 MonLinePtr = i; 00096 00097 // die binäre Suche nach den restlichen Zeichen wird hier fortgesetzt 00098 00099 do 00100 { 00101 i = (top + bottom) >> 1; // berechnen des Suchplatzes 00102 //printf_P (PSTR("\n\rVergleich 1 com_line = [%s] und Länge = [%d]"),com_line,len); 00103 //strcpy_P (temp, &command[i][0]); 00104 //printf_P (PSTR("\n\rVergleich 2 command[i] = [%s] und Index = [%d]"),temp,i); 00105 res = strncmp(mon_line, &command[i][0], len); 00106 //printf_P (PSTR("\n\rVergleich 3 res = [%d]"),res); 00107 if (res == 0) break; // Zeichen gefunden 00108 if (res > 0) 00109 bottom = i; // nach unten suchen 00110 else 00111 top = i; // nach oben suchen 00112 if (bottom != 0 && top == bottom + 1) break; 00113 00114 } while (i > 0 && i < COMMAND_MAX - 1); 00115 00116 00117 if (res) 00118 { 00119 pc.printf("\nParser Kommando nicht gefunden.\n"); 00120 } 00121 else 00122 { 00123 pc.printf("\nAufruf von Funktion %d",i); 00124 00125 // "CLCD","DUMP","HELP","SET","TIME"}; 00126 00127 switch(i) // Programmaufruf 00128 { 00129 case 0: dump(); break; 00130 case 1: help(); break; 00131 case 2: set(); break; 00132 case 3: time(); break; 00133 } 00134 } 00135 } 00136 00137 //--------------------------------------------------------------------------- 00138 // 00139 // Function name : monitor 00140 // 00141 // Returns : none 00142 // 00143 // Parameters : none 00144 // 00145 // Purpose : Monitor für die Benutzereingabe 00146 // 00147 //--------------------------------------------------------------------------- 00148 void monitor::monPC(void) 00149 { 00150 uint8_t i; 00151 char ch; 00152 00153 monLine(); 00154 if (cr_flag) // Neue Eingabezeile 00155 { 00156 if (mon_line[0] != 0) 00157 { 00158 // Zeichenkette in Großbuchstaben umwandeln 00159 for (i = 0; mon_line[i] != 0; i++) 00160 { 00161 ch = mon_line[i]; 00162 ch = toupper(ch); // Nur Großbuchstaben 00163 mon_line[i] = ch; 00164 //pc.printf(("\n[%02x] %c"),ch,ch); 00165 if (ch == ' ') i = MON_LINE_LEN; 00166 } 00167 00168 // pc.printf("\n monitor %s", mon_line); // zum Testen => später wird der parcer aufgerufen 00169 parser(); // Parcer wird aufgerufen 00170 } 00171 00172 for (i=0; i < MON_LINE_LEN; mon_line[i++] = 0); 00173 MonLinePtr = 0; 00174 cr_flag = 0; 00175 } 00176 } 00177 00178 //--------------------------------------------------------------------------- 00179 // 00180 // Function name : mon_line 00181 // 00182 // Returns : none 00183 // 00184 // Parameters : none 00185 // 00186 // Purpose : 00187 // Wird periodisch in unregelmäsigen Abständen aufgerufen und ermittelt, 00188 // ob weitere Zeichen von der Schnittstelle empfangen und die Eingabe 00189 // mit Carrige Return abgeschlossen wurde. Sollte dies der Fall sein, 00190 // wird das CR_FLAG gesetzt. Auch Editierfunktionen werden in diesem 00191 // Rahmen behandelt. 00192 // 00193 //--------------------------------------------------------------------------- 00194 00195 void monitor::monLine (void) 00196 { 00197 int ch; 00198 00199 if (pc.readable() == false) return; // kein Zeichen vorhanden 00200 00201 if (MonLinePtr >= 40) // Zeilenüberlauf ? 00202 { 00203 cr_flag = 1; 00204 return; 00205 } 00206 00207 ch = pc.getc(); // Hole das Zeichen 00208 //pc.printf("\nmon_line: %c [%02x]",ch,ch); // nur zum Test 00209 00210 switch(ch) 00211 { 00212 //case ESC: esc_flag = 1; // Sonder Stringkommandos 00213 // break; 00214 00215 case '\r': // CARRIAGE RETURN 00216 cr_flag = 1; 00217 break; 00218 00219 case '\n': // LF empfangen 00220 cr_flag = 1; 00221 break; 00222 00223 default: // Normales Zeichen 00224 if (~iscntrl(ch)) 00225 { 00226 mon_line[MonLinePtr] = ch; // Zeichen einfuegen 00227 MonLinePtr++; 00228 // pc.putc(ch); 00229 } 00230 break; 00231 00232 } // Ende SWITCH 00233 } 00234 00235 //----------------------------------------------------------------------------- 00236 // monitor Aufruf damp 00237 00238 void monitor::dump(void) 00239 { 00240 pc.printf("\nin dump"); 00241 } 00242 00243 //----------------------------------------------------------------------------- 00244 // monitor Aufruf help 00245 00246 void monitor::help(void) 00247 { 00248 pc.printf("\n -- help ------------------------"); 00249 pc.printf("\n clcd val >> lcd Kontrast"); 00250 pc.printf("\n set index [val] >> Ausgang setzen"); 00251 pc.printf("\n time [std min sek tag monat jahr]"); 00252 pc.printf("\n"); 00253 pc.printf("\n"); 00254 } 00255 00256 00257 //----------------------------------------------------------------------------- 00258 // monitor Aufruf set 00259 00260 void monitor::set(void) 00261 { 00262 int n, pos, val; 00263 00264 pos = 0; 00265 val = 0; 00266 00267 n = sscanf(&mon_line[MonLinePtr],"%d %d",&pos,&val); 00268 00269 if ((pos < 0) || (pos > 4)) n = -1; 00270 if ((val < 0) || (val >1)) n = -1; 00271 00272 switch (n) 00273 { 00274 case -1: 00275 pc.printf("\nbitte [Ausgang] [Wert] angeben"); 00276 pc.printf("\n Ausgang >> 1 bis 6"); 00277 pc.printf("\n Wert >> 0 = inaktiv, 1 = aktiv"); 00278 break; 00279 00280 default: 00281 switch (pos) 00282 { 00283 case 1: 00284 pc.printf("\n Ausgang 1 = %d",val); 00285 out1 = val; 00286 break; 00287 case 2: 00288 pc.printf("\n Ausgang 2 = %d",val); 00289 out2 = val; 00290 break; 00291 case 3: 00292 pc.printf("\n Ausgang 3 = %d",val); 00293 out3 = val; 00294 break; 00295 case 4: 00296 pc.printf("\n Ausgang 4 = %d",val); 00297 out4 = val; 00298 break; 00299 } 00300 break; 00301 } // end switch 00302 } 00303 00304 //----------------------------------------------------------------------------- 00305 // monitor Aufruf time 00306 00307 void monitor::time(void) 00308 { 00309 int sek, min, std, day, month, year, n; 00310 00311 sek = 0; 00312 min = 0; 00313 std = 0; 00314 day = 0; 00315 month = 0; 00316 year = 0; 00317 00318 n = sscanf(&mon_line[MonLinePtr],"%d %d %d %d %d %d",&std, &min, &sek, &day, &month, &year); 00319 00320 switch (n) 00321 { 00322 case -1 : // keine Zeichenübergabe 00323 case 0 : // keine Zeichenübergabe 00324 00325 strftime(buffer, 40, "%a, %d.%m.%Y %H:%M:%S", localtime(&down_timer.seconds)); 00326 pc.printf("\nTime = %s\n", buffer); 00327 break; 00328 00329 case 1 : // std 00330 case 2 : // min 00331 case 3 : // sek 00332 case 4 : // tag 00333 case 5 : // mon 00334 case 6 : // jahr 00335 00336 if (sek > 59) sek = 59; 00337 if (sek < 0) sek = 0; 00338 buffer[0] = (uint8_t)sek;; 00339 00340 if (min > 59) min = 59; 00341 if (min < 0) min = 0; 00342 buffer[1] = (uint8_t)min; 00343 00344 if (std > 23) std = 23; 00345 if (std < 0) std = 0; 00346 buffer[2] = (uint8_t)std; 00347 00348 if (day > 31) day = 31; 00349 if (day < 0) day = 0; 00350 buffer[3] = (uint8_t)day;; 00351 00352 if (month > 12) month = 12; 00353 if (month < 0) month = 0; 00354 buffer[4] = (uint8_t)month; 00355 00356 if (year > 2100) year = 2100; 00357 if (year < 2000) year = 2000; 00358 buffer[5] = (uint8_t)(year - 1900); 00359 00360 00361 down_timer.Set_t((uint8_t *)buffer); 00362 00363 strftime(buffer, 40, "%a, %d.%m.%Y %H:%M:%S", localtime(&down_timer.seconds)); 00364 pc.printf("\nnew Time = %s\n", buffer); 00365 break; 00366 } 00367 } 00368
Generated on Thu Jul 28 2022 17:52:04 by
1.7.2
