Schnittstelle zur microSPS
Fork of com_0 by
com.cpp@0:3eabf0cac42a, 2015-01-03 (annotated)
- Committer:
- rs27
- Date:
- Sat Jan 03 15:25:35 2015 +0000
- Revision:
- 0:3eabf0cac42a
1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rs27 | 0:3eabf0cac42a | 1 | |
rs27 | 0:3eabf0cac42a | 2 | //--------------------------------------------------------------------------- |
rs27 | 0:3eabf0cac42a | 3 | // Modul...: COM.CPP |
rs27 | 0:3eabf0cac42a | 4 | // Chip....: KL25Z |
rs27 | 0:3eabf0cac42a | 5 | // |
rs27 | 0:3eabf0cac42a | 6 | //--------------------------------------------------------------------------- |
rs27 | 0:3eabf0cac42a | 7 | // Author..: Reinhold Schäfer |
rs27 | 0:3eabf0cac42a | 8 | // Date....: 2014.06.08 |
rs27 | 0:3eabf0cac42a | 9 | // http....: //www.microsps.net |
rs27 | 0:3eabf0cac42a | 10 | //--------------------------------------------------------------------------- |
rs27 | 0:3eabf0cac42a | 11 | #include <stdarg.h> |
rs27 | 0:3eabf0cac42a | 12 | #include <ctype.h> |
rs27 | 0:3eabf0cac42a | 13 | #include "mon.h" |
rs27 | 0:3eabf0cac42a | 14 | #include "MODSERIAL.h" |
rs27 | 0:3eabf0cac42a | 15 | #include "SDFileSystem.h" |
rs27 | 0:3eabf0cac42a | 16 | #include "FATDirHandle.h" |
rs27 | 0:3eabf0cac42a | 17 | #include "myTextLCD.h" |
rs27 | 0:3eabf0cac42a | 18 | #include "timer0.h" |
rs27 | 0:3eabf0cac42a | 19 | |
rs27 | 0:3eabf0cac42a | 20 | #define LED_OFF 1 |
rs27 | 0:3eabf0cac42a | 21 | #define LED_ON 0 |
rs27 | 0:3eabf0cac42a | 22 | #define COM_LINE_LEN 128 // maximale Länge der Eingabezeile |
rs27 | 0:3eabf0cac42a | 23 | #define TEL_SIZE 10 |
rs27 | 0:3eabf0cac42a | 24 | |
rs27 | 0:3eabf0cac42a | 25 | #define XON 0x11 |
rs27 | 0:3eabf0cac42a | 26 | #define XOFF 0x13 |
rs27 | 0:3eabf0cac42a | 27 | |
rs27 | 0:3eabf0cac42a | 28 | struct com_struct |
rs27 | 0:3eabf0cac42a | 29 | { |
rs27 | 0:3eabf0cac42a | 30 | uint8_t flag; // Flag zur Steuerung |
rs27 | 0:3eabf0cac42a | 31 | uint8_t sm; // State maschine |
rs27 | 0:3eabf0cac42a | 32 | uint8_t index; // Index für Zeichenzähler |
rs27 | 0:3eabf0cac42a | 33 | uint8_t len; // Zeichenzähler für Telegramlänge |
rs27 | 0:3eabf0cac42a | 34 | uint8_t nr; // Zähler für array |
rs27 | 0:3eabf0cac42a | 35 | uint8_t byte[10]; // Bytes für Zwischenablage |
rs27 | 0:3eabf0cac42a | 36 | char line[COM_LINE_LEN]; |
rs27 | 0:3eabf0cac42a | 37 | }; |
rs27 | 0:3eabf0cac42a | 38 | |
rs27 | 0:3eabf0cac42a | 39 | extern MODSERIAL pc; // definiert in main |
rs27 | 0:3eabf0cac42a | 40 | extern MODSERIAL uart1; // definiert in main, tx, rx |
rs27 | 0:3eabf0cac42a | 41 | extern TextLCD lcd; |
rs27 | 0:3eabf0cac42a | 42 | extern timer0 down_timer; // Timer für Zeitsteuerung |
rs27 | 0:3eabf0cac42a | 43 | extern DigitalOut led3; // definiert in main |
rs27 | 0:3eabf0cac42a | 44 | extern DigitalOut lcd_bl; // definiert in main, Hintergrundbeleuchtung |
rs27 | 0:3eabf0cac42a | 45 | extern PwmOut lcd_kontrast; // Kontrast wird über PWM gesteuert |
rs27 | 0:3eabf0cac42a | 46 | |
rs27 | 0:3eabf0cac42a | 47 | // Bitposition und Belegung |
rs27 | 0:3eabf0cac42a | 48 | // bit 1 CR Flag |
rs27 | 0:3eabf0cac42a | 49 | // bit 2 byte speichern |
rs27 | 0:3eabf0cac42a | 50 | // bit 4 |
rs27 | 0:3eabf0cac42a | 51 | // bit 8 |
rs27 | 0:3eabf0cac42a | 52 | |
rs27 | 0:3eabf0cac42a | 53 | struct com_struct com; // Schnittstelle zur microSPS |
rs27 | 0:3eabf0cac42a | 54 | |
rs27 | 0:3eabf0cac42a | 55 | void com_init(void) |
rs27 | 0:3eabf0cac42a | 56 | { |
rs27 | 0:3eabf0cac42a | 57 | uint8_t i; |
rs27 | 0:3eabf0cac42a | 58 | |
rs27 | 0:3eabf0cac42a | 59 | led3 = LED_OFF; |
rs27 | 0:3eabf0cac42a | 60 | |
rs27 | 0:3eabf0cac42a | 61 | |
rs27 | 0:3eabf0cac42a | 62 | // Speicher für die Eingangszeile löschen |
rs27 | 0:3eabf0cac42a | 63 | for (i=0; i < COM_LINE_LEN; i++) |
rs27 | 0:3eabf0cac42a | 64 | { |
rs27 | 0:3eabf0cac42a | 65 | com.line[i] = 0; |
rs27 | 0:3eabf0cac42a | 66 | } |
rs27 | 0:3eabf0cac42a | 67 | com.flag = 0; |
rs27 | 0:3eabf0cac42a | 68 | com.sm = 0; |
rs27 | 0:3eabf0cac42a | 69 | com.index = 0; |
rs27 | 0:3eabf0cac42a | 70 | } |
rs27 | 0:3eabf0cac42a | 71 | |
rs27 | 0:3eabf0cac42a | 72 | // Bitposition und Belegung |
rs27 | 0:3eabf0cac42a | 73 | // bit 1 Daten speichern in aktion |
rs27 | 0:3eabf0cac42a | 74 | // bit 2 Datei anlegen |
rs27 | 0:3eabf0cac42a | 75 | // bit 4 Daten schreiben |
rs27 | 0:3eabf0cac42a | 76 | // bit 8 Datei schließen |
rs27 | 0:3eabf0cac42a | 77 | |
rs27 | 0:3eabf0cac42a | 78 | |
rs27 | 0:3eabf0cac42a | 79 | // In dieser therad werden Daten aus der Seriellen Schnittstelle gelesen. Nach dem lesen |
rs27 | 0:3eabf0cac42a | 80 | // von einem Telegramm wird dieses falls es für das Speicher verwendet wird in m_msd abgelegt. |
rs27 | 0:3eabf0cac42a | 81 | // Die anderen Telergamme und die Antworten werde in dieser thread gleich bearbeitet. |
rs27 | 0:3eabf0cac42a | 82 | |
rs27 | 0:3eabf0cac42a | 83 | void com_line(void) |
rs27 | 0:3eabf0cac42a | 84 | { |
rs27 | 0:3eabf0cac42a | 85 | |
rs27 | 0:3eabf0cac42a | 86 | char ch; |
rs27 | 0:3eabf0cac42a | 87 | uint8_t n; |
rs27 | 0:3eabf0cac42a | 88 | int i; |
rs27 | 0:3eabf0cac42a | 89 | FILE *fp; |
rs27 | 0:3eabf0cac42a | 90 | |
rs27 | 0:3eabf0cac42a | 91 | while (true) |
rs27 | 0:3eabf0cac42a | 92 | { |
rs27 | 0:3eabf0cac42a | 93 | if (uart1.readable()) |
rs27 | 0:3eabf0cac42a | 94 | { |
rs27 | 0:3eabf0cac42a | 95 | led3 = 0; |
rs27 | 0:3eabf0cac42a | 96 | |
rs27 | 0:3eabf0cac42a | 97 | // Falls mehr Zeichen ankommen als verarbeitet werden, wird die microSPS gebremst |
rs27 | 0:3eabf0cac42a | 98 | //i = uart1.rxBufferGetCount(); |
rs27 | 0:3eabf0cac42a | 99 | //if (i > 800) // buffer hat 1014 Zeichen |
rs27 | 0:3eabf0cac42a | 100 | //{ |
rs27 | 0:3eabf0cac42a | 101 | // uart1.putc(XOFF); |
rs27 | 0:3eabf0cac42a | 102 | // pc.printf("\nrxBuffer XOFF %d",i); |
rs27 | 0:3eabf0cac42a | 103 | //} |
rs27 | 0:3eabf0cac42a | 104 | |
rs27 | 0:3eabf0cac42a | 105 | //---------------------------------------------------------------------------------------------------- |
rs27 | 0:3eabf0cac42a | 106 | // Eingehende Zeichen lesen und abspeichern |
rs27 | 0:3eabf0cac42a | 107 | |
rs27 | 0:3eabf0cac42a | 108 | ch = uart1.getc(); // Zeichen lesen und auswerten |
rs27 | 0:3eabf0cac42a | 109 | // pc.printf("\ntel> SM[%02d]",com.sm); |
rs27 | 0:3eabf0cac42a | 110 | |
rs27 | 0:3eabf0cac42a | 111 | com.line[com.index] = ch; // Zeichen einfuegen |
rs27 | 0:3eabf0cac42a | 112 | com.index++; // Zeichenzähler erhöhen |
rs27 | 0:3eabf0cac42a | 113 | if (com.index >= 80) com.sm = 100; // ein Telegramm enthält maximal 80 Zeichen |
rs27 | 0:3eabf0cac42a | 114 | /* |
rs27 | 0:3eabf0cac42a | 115 | for (i = 0; i < com.index; i++) |
rs27 | 0:3eabf0cac42a | 116 | { |
rs27 | 0:3eabf0cac42a | 117 | pc.printf(" %02x",com.line[i]); |
rs27 | 0:3eabf0cac42a | 118 | } |
rs27 | 0:3eabf0cac42a | 119 | |
rs27 | 0:3eabf0cac42a | 120 | pc.printf("\n"); |
rs27 | 0:3eabf0cac42a | 121 | */ |
rs27 | 0:3eabf0cac42a | 122 | //---------------------------------------------------------------------------------------------------- |
rs27 | 0:3eabf0cac42a | 123 | // auf Startzeichen auswerten |
rs27 | 0:3eabf0cac42a | 124 | |
rs27 | 0:3eabf0cac42a | 125 | switch (com.sm) // com.sm ist state machine |
rs27 | 0:3eabf0cac42a | 126 | { |
rs27 | 0:3eabf0cac42a | 127 | case 0 : // erstes Zeichen aus einem Telegramm |
rs27 | 0:3eabf0cac42a | 128 | |
rs27 | 0:3eabf0cac42a | 129 | if (ch == 0xE5) com.sm = 1; // Telegramm erstes Startzeichen wurde erkannt |
rs27 | 0:3eabf0cac42a | 130 | if (ch == 0x00) com.sm = 100; // 0 ist kein gültiges Telegramm |
rs27 | 0:3eabf0cac42a | 131 | break; |
rs27 | 0:3eabf0cac42a | 132 | |
rs27 | 0:3eabf0cac42a | 133 | case 1 : // zweites Zeichen aus einem Telegramm |
rs27 | 0:3eabf0cac42a | 134 | |
rs27 | 0:3eabf0cac42a | 135 | if (ch == 0x02) com.sm = 2; // Telegramm zweites Startzeichen wurde erkannt |
rs27 | 0:3eabf0cac42a | 136 | if (ch != 0x02) com.sm = 100; // 0 ist kein gültiges Telegramm |
rs27 | 0:3eabf0cac42a | 137 | break; |
rs27 | 0:3eabf0cac42a | 138 | |
rs27 | 0:3eabf0cac42a | 139 | case 2 : // Command byte auswerten |
rs27 | 0:3eabf0cac42a | 140 | |
rs27 | 0:3eabf0cac42a | 141 | switch(ch) |
rs27 | 0:3eabf0cac42a | 142 | { |
rs27 | 0:3eabf0cac42a | 143 | case 0x00: |
rs27 | 0:3eabf0cac42a | 144 | com.sm = 100; // bei 0 wieder von vorne starten |
rs27 | 0:3eabf0cac42a | 145 | break; |
rs27 | 0:3eabf0cac42a | 146 | |
rs27 | 0:3eabf0cac42a | 147 | case 0x04: // RESET Kennung |
rs27 | 0:3eabf0cac42a | 148 | case 0x06: // Zeit Stempel lesen |
rs27 | 0:3eabf0cac42a | 149 | case 0x10: // LCD löschen |
rs27 | 0:3eabf0cac42a | 150 | case 0x11: // Hintergundbeleuchtung aus |
rs27 | 0:3eabf0cac42a | 151 | case 0x12: // Hintergundbeleuchtung an |
rs27 | 0:3eabf0cac42a | 152 | case 0x13: // Cursor setzen |
rs27 | 0:3eabf0cac42a | 153 | case 0x14: // Text für die LCD Anzeige |
rs27 | 0:3eabf0cac42a | 154 | com.sm = 5; // nur ein Zeichen |
rs27 | 0:3eabf0cac42a | 155 | break; |
rs27 | 0:3eabf0cac42a | 156 | |
rs27 | 0:3eabf0cac42a | 157 | case 0x15: // Text für die LCD Anzeige mit Positionsangabe |
rs27 | 0:3eabf0cac42a | 158 | case 0x20: |
rs27 | 0:3eabf0cac42a | 159 | com.sm = 5; |
rs27 | 0:3eabf0cac42a | 160 | break; |
rs27 | 0:3eabf0cac42a | 161 | |
rs27 | 0:3eabf0cac42a | 162 | default: // Zeichen zum abspeichern |
rs27 | 0:3eabf0cac42a | 163 | uart1.puts("\nsm CMD unbekannt"); |
rs27 | 0:3eabf0cac42a | 164 | com.sm = 12; // Speicher löschen |
rs27 | 0:3eabf0cac42a | 165 | break; |
rs27 | 0:3eabf0cac42a | 166 | |
rs27 | 0:3eabf0cac42a | 167 | } // ende SWITCH |
rs27 | 0:3eabf0cac42a | 168 | |
rs27 | 0:3eabf0cac42a | 169 | break; // end case 0: |
rs27 | 0:3eabf0cac42a | 170 | |
rs27 | 0:3eabf0cac42a | 171 | case 5: // Telegrammlänge ermitteln, danach folgt Text |
rs27 | 0:3eabf0cac42a | 172 | |
rs27 | 0:3eabf0cac42a | 173 | com.len = ch; |
rs27 | 0:3eabf0cac42a | 174 | com.nr = 0; |
rs27 | 0:3eabf0cac42a | 175 | if (com.len == 0xff) |
rs27 | 0:3eabf0cac42a | 176 | { |
rs27 | 0:3eabf0cac42a | 177 | com.sm = 11; |
rs27 | 0:3eabf0cac42a | 178 | } |
rs27 | 0:3eabf0cac42a | 179 | else |
rs27 | 0:3eabf0cac42a | 180 | { |
rs27 | 0:3eabf0cac42a | 181 | com.sm = 7; |
rs27 | 0:3eabf0cac42a | 182 | } |
rs27 | 0:3eabf0cac42a | 183 | break; |
rs27 | 0:3eabf0cac42a | 184 | |
rs27 | 0:3eabf0cac42a | 185 | case 7: // Index Zeichen lesen |
rs27 | 0:3eabf0cac42a | 186 | com.byte[com.nr] = ch, |
rs27 | 0:3eabf0cac42a | 187 | com.nr++; |
rs27 | 0:3eabf0cac42a | 188 | com.len--; |
rs27 | 0:3eabf0cac42a | 189 | if (com.len == 0) |
rs27 | 0:3eabf0cac42a | 190 | { |
rs27 | 0:3eabf0cac42a | 191 | com.sm = 12; |
rs27 | 0:3eabf0cac42a | 192 | |
rs27 | 0:3eabf0cac42a | 193 | // Telegramm zum Testen ausgeben |
rs27 | 0:3eabf0cac42a | 194 | /* |
rs27 | 0:3eabf0cac42a | 195 | pc.printf("\ntel: "); |
rs27 | 0:3eabf0cac42a | 196 | for(i=0; i <= com.index; i++) |
rs27 | 0:3eabf0cac42a | 197 | { |
rs27 | 0:3eabf0cac42a | 198 | pc.printf(" %02x",com.line[i]); |
rs27 | 0:3eabf0cac42a | 199 | } |
rs27 | 0:3eabf0cac42a | 200 | */ |
rs27 | 0:3eabf0cac42a | 201 | } |
rs27 | 0:3eabf0cac42a | 202 | break; |
rs27 | 0:3eabf0cac42a | 203 | |
rs27 | 0:3eabf0cac42a | 204 | case 11: |
rs27 | 0:3eabf0cac42a | 205 | //---------------------------------------------------------------------------------------------------- |
rs27 | 0:3eabf0cac42a | 206 | // bis Abschlussbit alle Zeichen lesen und bei Abschlußzeichen die Auswertung angehen |
rs27 | 0:3eabf0cac42a | 207 | // bei einer Zeichenkette bis 00 lesen |
rs27 | 0:3eabf0cac42a | 208 | |
rs27 | 0:3eabf0cac42a | 209 | if (ch == 0x00) |
rs27 | 0:3eabf0cac42a | 210 | { |
rs27 | 0:3eabf0cac42a | 211 | com.sm = 12; |
rs27 | 0:3eabf0cac42a | 212 | |
rs27 | 0:3eabf0cac42a | 213 | // Telegramm zum Testen ausgeben |
rs27 | 0:3eabf0cac42a | 214 | /* |
rs27 | 0:3eabf0cac42a | 215 | pc.printf("\ntel "); |
rs27 | 0:3eabf0cac42a | 216 | for(i=0; i < com.index; i++) |
rs27 | 0:3eabf0cac42a | 217 | { |
rs27 | 0:3eabf0cac42a | 218 | pc.printf(" %02x",com.line[i]); |
rs27 | 0:3eabf0cac42a | 219 | } |
rs27 | 0:3eabf0cac42a | 220 | */ |
rs27 | 0:3eabf0cac42a | 221 | } |
rs27 | 0:3eabf0cac42a | 222 | |
rs27 | 0:3eabf0cac42a | 223 | break; // end case 1: |
rs27 | 0:3eabf0cac42a | 224 | |
rs27 | 0:3eabf0cac42a | 225 | } // end switch |
rs27 | 0:3eabf0cac42a | 226 | |
rs27 | 0:3eabf0cac42a | 227 | //---------------------------------------------------------------------------------------------------- |
rs27 | 0:3eabf0cac42a | 228 | // Hier werden die Telegramme ausgewertet |
rs27 | 0:3eabf0cac42a | 229 | |
rs27 | 0:3eabf0cac42a | 230 | if (com.sm == 12) // Hardware Reset |
rs27 | 0:3eabf0cac42a | 231 | { |
rs27 | 0:3eabf0cac42a | 232 | switch (com.line[2]) |
rs27 | 0:3eabf0cac42a | 233 | { |
rs27 | 0:3eabf0cac42a | 234 | case 0x04: |
rs27 | 0:3eabf0cac42a | 235 | char buffer[40]; |
rs27 | 0:3eabf0cac42a | 236 | fp = fopen("/sd/log.txt", "a"); |
rs27 | 0:3eabf0cac42a | 237 | if(fp == NULL) |
rs27 | 0:3eabf0cac42a | 238 | { |
rs27 | 0:3eabf0cac42a | 239 | pc.printf("\ncom_line #4 Could not open file for write"); |
rs27 | 0:3eabf0cac42a | 240 | } |
rs27 | 0:3eabf0cac42a | 241 | else |
rs27 | 0:3eabf0cac42a | 242 | { |
rs27 | 0:3eabf0cac42a | 243 | strftime(buffer, 40, "%a,%d.%m.%Y %H:%M:%S", localtime(&down_timer.seconds)); |
rs27 | 0:3eabf0cac42a | 244 | fprintf(fp, "\n%s Reset %02x ", buffer,com.line[4]); |
rs27 | 0:3eabf0cac42a | 245 | } |
rs27 | 0:3eabf0cac42a | 246 | fclose(fp); |
rs27 | 0:3eabf0cac42a | 247 | pc.printf("\n%s RESET %02x\n",buffer,com.line[4]); |
rs27 | 0:3eabf0cac42a | 248 | break; |
rs27 | 0:3eabf0cac42a | 249 | |
rs27 | 0:3eabf0cac42a | 250 | case 0x06: // Systemzeit setzen |
rs27 | 0:3eabf0cac42a | 251 | com.line[9] += 80; // Zeitstempel für Jahr ist beim RTC 1980 und bei kl25z 1900 |
rs27 | 0:3eabf0cac42a | 252 | // |
rs27 | 0:3eabf0cac42a | 253 | // pc.printf("\n telegramm #6 "); |
rs27 | 0:3eabf0cac42a | 254 | // for (i = 0; i < 12; i++) |
rs27 | 0:3eabf0cac42a | 255 | // { |
rs27 | 0:3eabf0cac42a | 256 | // pc.printf(" %02x",com.line[i]); |
rs27 | 0:3eabf0cac42a | 257 | // } |
rs27 | 0:3eabf0cac42a | 258 | // pc.printf("\n"); |
rs27 | 0:3eabf0cac42a | 259 | down_timer.Set_t((uint8_t *)&com.line[4]); |
rs27 | 0:3eabf0cac42a | 260 | break; |
rs27 | 0:3eabf0cac42a | 261 | |
rs27 | 0:3eabf0cac42a | 262 | case 0x10: // LCD löschen |
rs27 | 0:3eabf0cac42a | 263 | lcd.cls(); |
rs27 | 0:3eabf0cac42a | 264 | break; |
rs27 | 0:3eabf0cac42a | 265 | |
rs27 | 0:3eabf0cac42a | 266 | case 0x11 : // LCD backlight off |
rs27 | 0:3eabf0cac42a | 267 | lcd_bl = 0; |
rs27 | 0:3eabf0cac42a | 268 | break; |
rs27 | 0:3eabf0cac42a | 269 | |
rs27 | 0:3eabf0cac42a | 270 | case 0x12 : // LCD backlight on |
rs27 | 0:3eabf0cac42a | 271 | lcd_bl = 1; |
rs27 | 0:3eabf0cac42a | 272 | break; |
rs27 | 0:3eabf0cac42a | 273 | |
rs27 | 0:3eabf0cac42a | 274 | case 0x13: // Cursor setzen |
rs27 | 0:3eabf0cac42a | 275 | //pc.printf("\nCursor setzen %d %d",com.line[4],com.line[5]); |
rs27 | 0:3eabf0cac42a | 276 | lcd.locate(com.line[4], com.line[5]); |
rs27 | 0:3eabf0cac42a | 277 | break; |
rs27 | 0:3eabf0cac42a | 278 | |
rs27 | 0:3eabf0cac42a | 279 | case 0x14: // Text auf LCD ausgeben |
rs27 | 0:3eabf0cac42a | 280 | //pc.printf("\nLCD '%s'",&com.line[4]); |
rs27 | 0:3eabf0cac42a | 281 | lcd.printf("%s",&com.line[4]); |
rs27 | 0:3eabf0cac42a | 282 | lcd.writeLCD(); |
rs27 | 0:3eabf0cac42a | 283 | break; |
rs27 | 0:3eabf0cac42a | 284 | |
rs27 | 0:3eabf0cac42a | 285 | case 0x15: // Text auf LCD ausgeben |
rs27 | 0:3eabf0cac42a | 286 | lcd.locate(com.byte[0], com.byte[1]); |
rs27 | 0:3eabf0cac42a | 287 | lcd.printf("%s",&com.line[6]); |
rs27 | 0:3eabf0cac42a | 288 | lcd.writeLCD(); |
rs27 | 0:3eabf0cac42a | 289 | break; |
rs27 | 0:3eabf0cac42a | 290 | |
rs27 | 0:3eabf0cac42a | 291 | case 0x20: |
rs27 | 0:3eabf0cac42a | 292 | char name[] = "/sd/SD_000.CSV"; // create a file name |
rs27 | 0:3eabf0cac42a | 293 | |
rs27 | 0:3eabf0cac42a | 294 | // Dateiname bilden |
rs27 | 0:3eabf0cac42a | 295 | uint8_t index = com.byte[0]; |
rs27 | 0:3eabf0cac42a | 296 | n = index / 100; |
rs27 | 0:3eabf0cac42a | 297 | name[7] = n + '0'; |
rs27 | 0:3eabf0cac42a | 298 | index -= n * 100; |
rs27 | 0:3eabf0cac42a | 299 | name[8] = index/10 + '0'; |
rs27 | 0:3eabf0cac42a | 300 | name[9] = index%10 + '0'; |
rs27 | 0:3eabf0cac42a | 301 | |
rs27 | 0:3eabf0cac42a | 302 | // Daten abspeichern |
rs27 | 0:3eabf0cac42a | 303 | fp = fopen(name, "a"); |
rs27 | 0:3eabf0cac42a | 304 | if(fp == NULL) |
rs27 | 0:3eabf0cac42a | 305 | { |
rs27 | 0:3eabf0cac42a | 306 | pc.printf("\ncom_line #20 Could not open file for append"); |
rs27 | 0:3eabf0cac42a | 307 | } |
rs27 | 0:3eabf0cac42a | 308 | else |
rs27 | 0:3eabf0cac42a | 309 | { |
rs27 | 0:3eabf0cac42a | 310 | fprintf(fp, "%s",&com.line[5]); |
rs27 | 0:3eabf0cac42a | 311 | // pc.printf("\nfile %d %s",com.byte[0],&com.line[5]); |
rs27 | 0:3eabf0cac42a | 312 | } |
rs27 | 0:3eabf0cac42a | 313 | fclose(fp); |
rs27 | 0:3eabf0cac42a | 314 | break; |
rs27 | 0:3eabf0cac42a | 315 | |
rs27 | 0:3eabf0cac42a | 316 | default: // ungültiges Telegram |
rs27 | 0:3eabf0cac42a | 317 | |
rs27 | 0:3eabf0cac42a | 318 | pc.printf("\nTelegramm 02 ungueltiges Zeichen %02x\n",com.line[2]); |
rs27 | 0:3eabf0cac42a | 319 | break; |
rs27 | 0:3eabf0cac42a | 320 | } // end switch |
rs27 | 0:3eabf0cac42a | 321 | |
rs27 | 0:3eabf0cac42a | 322 | com.sm = 100; // Eingabe wieder löschen |
rs27 | 0:3eabf0cac42a | 323 | |
rs27 | 0:3eabf0cac42a | 324 | } // end if (com.sm == 8) |
rs27 | 0:3eabf0cac42a | 325 | |
rs27 | 0:3eabf0cac42a | 326 | |
rs27 | 0:3eabf0cac42a | 327 | //---------------------------------------------------------------------------------------------------- |
rs27 | 0:3eabf0cac42a | 328 | // Zeile wieder löschen |
rs27 | 0:3eabf0cac42a | 329 | |
rs27 | 0:3eabf0cac42a | 330 | if (com.sm == 100) |
rs27 | 0:3eabf0cac42a | 331 | { |
rs27 | 0:3eabf0cac42a | 332 | // uart1.puts("\nsm 12 Speicher loeschen"); |
rs27 | 0:3eabf0cac42a | 333 | |
rs27 | 0:3eabf0cac42a | 334 | for (i = 0; i < COM_LINE_LEN; i++) com.line[i] = 0x00; |
rs27 | 0:3eabf0cac42a | 335 | |
rs27 | 0:3eabf0cac42a | 336 | com.index = 0; |
rs27 | 0:3eabf0cac42a | 337 | com.flag = 0; |
rs27 | 0:3eabf0cac42a | 338 | com.sm = 0; |
rs27 | 0:3eabf0cac42a | 339 | break; // nach einem Befehl wieder zum Hauptprogramm verzweigen |
rs27 | 0:3eabf0cac42a | 340 | } |
rs27 | 0:3eabf0cac42a | 341 | |
rs27 | 0:3eabf0cac42a | 342 | } // end if (uart1.readabel |
rs27 | 0:3eabf0cac42a | 343 | else break; |
rs27 | 0:3eabf0cac42a | 344 | |
rs27 | 0:3eabf0cac42a | 345 | } // end while(1) |
rs27 | 0:3eabf0cac42a | 346 | |
rs27 | 0:3eabf0cac42a | 347 | led3 = 1; |
rs27 | 0:3eabf0cac42a | 348 | } |
rs27 | 0:3eabf0cac42a | 349 | |
rs27 | 0:3eabf0cac42a | 350 | |
rs27 | 0:3eabf0cac42a | 351 |