Rev 130 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
21 | user | 1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 | // + Copyright (c) 04.2007 Holger Buss |
||
3 | // + only for non-profit use |
||
4 | // + www.MikroKopter.com |
||
5 | // + see the File "License.txt" for further Informations |
||
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
7 | |||
8 | #include "main.h" |
||
9 | #include "uart.h" |
||
10 | |||
11 | unsigned char DebugGetAnforderung = 0,DebugDisplayAnforderung = 0,DebugDataAnforderung = 0,GetVersionAnforderung = 0; |
||
12 | unsigned volatile char SioTmp = 0; |
||
13 | unsigned volatile char SendeBuffer[MAX_SENDE_BUFF]; |
||
14 | unsigned volatile char RxdBuffer[MAX_EMPFANGS_BUFF]; |
||
15 | unsigned volatile char NMEABuffer[MAX_EMPFANGS_BUFF]; |
||
16 | unsigned volatile char NeuerDatensatzEmpfangen = 0; |
||
17 | unsigned volatile char NeueKoordinateEmpfangen = 0; |
||
18 | unsigned volatile char UebertragungAbgeschlossen = 1; |
||
19 | unsigned volatile char CntCrcError = 0; |
||
20 | unsigned volatile char AnzahlEmpfangsBytes = 0; |
||
21 | unsigned volatile char PC_DebugTimeout = 0; |
||
22 | unsigned char PcZugriff = 100; |
||
23 | unsigned char MotorTest[4] = {0,0,0,0}; |
||
24 | unsigned char MeineSlaveAdresse; |
||
25 | struct str_DebugOut DebugOut; |
||
26 | struct str_Debug DebugIn; |
||
27 | struct str_VersionInfo VersionInfo; |
||
28 | int Debug_Timer; |
||
29 | |||
30 | static uint8_t gpsState; |
||
31 | #define GPS_EMPTY 0 |
||
32 | #define GPS_SYNC1 1 |
||
33 | #define GPS_SYNC2 2 |
||
34 | #define GPS_CLASS 3 |
||
35 | #define GPS_LEN1 4 |
||
36 | #define GPS_LEN2 5 |
||
37 | #define GPS_FILLING 6 |
||
38 | #define GPS_CKA 7 |
||
39 | #define GPS_CKB 8 |
||
40 | |||
41 | gpsInfo_t actualPos; // measured position (last gps record) |
||
42 | |||
43 | #define SYNC_CHAR1 0xb5 |
||
44 | #define SYNC_CHAR2 0x62 |
||
45 | |||
46 | #define CLASS_NAV 0x01 |
||
47 | #define MSGID_STATUS 0x03 |
||
243 | hallo2 | 48 | #define MSGID_POSUTM 0x08 |
49 | #define MSGID_VELNED 0x12 |
||
21 | user | 50 | |
51 | |||
52 | |||
53 | typedef struct { |
||
54 | unsigned long ITOW; // time of week |
||
55 | uint8_t GPSfix; // GPSfix Type, range 0..6 |
||
56 | uint8_t Flags; // Navigation Status Flags |
||
57 | uint8_t DiffS; // Differential Status |
||
58 | uint8_t res; // reserved |
||
59 | unsigned long TTFF; // Time to first fix (millisecond time tag) |
||
60 | unsigned long MSSS; // Milliseconds since Startup / Reset |
||
61 | uint8_t packetStatus; |
||
62 | } NAV_STATUS_t; |
||
63 | |||
64 | |||
65 | typedef struct { |
||
66 | unsigned long ITOW; // time of week |
||
67 | long EAST; // cm UTM Easting |
||
68 | long NORTH; // cm UTM Nording |
||
69 | long ALT; // cm altitude |
||
70 | uint8_t ZONE; // UTM zone number |
||
71 | uint8_t HEM; // Hemisphere Indicator (0=North, 1=South) |
||
72 | uint8_t packetStatus; |
||
73 | } NAV_POSUTM_t; |
||
74 | |||
75 | |||
76 | typedef struct { |
||
77 | unsigned long ITOW; // ms GPS Millisecond Time of Week |
||
78 | long VEL_N; // cm/s NED north velocity |
||
79 | long VEL_E; // cm/s NED east velocity |
||
80 | long VEL_D; // cm/s NED down velocity |
||
81 | unsigned long Speed; // cm/s Speed (3-D) |
||
82 | unsigned long GSpeed; // cm/s Ground Speed (2-D) |
||
83 | long Heading; // deg (1e-05) Heading 2-D |
||
84 | unsigned long SAcc; // cm/s Speed Accuracy Estimate |
||
85 | unsigned long CAcc; // deg Course / Heading Accuracy Estimate |
||
86 | uint8_t packetStatus; |
||
87 | } NAV_VELNED_t; |
||
88 | |||
89 | NAV_STATUS_t navStatus; |
||
243 | hallo2 | 90 | NAV_POSUTM_t navPosUtm; |
91 | NAV_VELNED_t navVelNed; |
||
21 | user | 92 | |
93 | volatile char *ubxP, *ubxEp, *ubxSp; // pointers to packet currently transfered |
||
94 | volatile uint8_t CK_A, CK_B; // UBX checksum bytes |
||
95 | volatile unsigned short msgLen; |
||
96 | volatile uint8_t msgID; |
||
97 | volatile uint8_t ignorePacket; // true when previous packet was not processed |
||
98 | |||
99 | |||
100 | // distance to target position |
||
101 | long rollOffset; // in 10cm |
||
102 | long nickOffset; |
||
103 | |||
104 | #define GPS_INTCYCLES 100 |
||
105 | #define GPS_I_LIMIT (long)(40 * MAINLOOPS_PER_SEC) |
||
106 | |||
107 | #ifdef GPS_DEBUG // if set then the GPS data is transfered to display |
||
108 | extern volatile uint8_t v24state; |
||
109 | char buf[200]; |
||
110 | char *bp; |
||
111 | char *ep; |
||
112 | #endif |
||
113 | |||
114 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
115 | //++ Sende-Part der Datenübertragung |
||
116 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
117 | SIGNAL(INT_VEC_TX) |
||
118 | { |
||
119 | static unsigned int ptr = 0; |
||
120 | unsigned char tmp_tx; |
||
121 | if(!UebertragungAbgeschlossen) |
||
122 | { |
||
123 | ptr++; // die [0] wurde schon gesendet |
||
124 | tmp_tx = SendeBuffer[ptr]; |
||
125 | if((tmp_tx == '\r') || (ptr == MAX_SENDE_BUFF)) |
||
126 | { |
||
127 | ptr = 0; |
||
128 | UebertragungAbgeschlossen = 1; |
||
129 | } |
||
130 | UDR = tmp_tx; |
||
131 | } |
||
132 | else ptr = 0; |
||
133 | } |
||
134 | |||
135 | void GPSscanData (void) |
||
136 | { |
||
37 | hallo2 | 137 | |
138 | |||
139 | |||
21 | user | 140 | if (navStatus.packetStatus == 1) // valid packet |
141 | { |
||
142 | actualPos.state = navStatus.GPSfix; |
||
143 | navStatus.packetStatus = 0; |
||
144 | } |
||
243 | hallo2 | 145 | |
21 | user | 146 | if (navPosUtm.packetStatus == 1) // valid packet |
147 | { |
||
243 | hallo2 | 148 | actualPos.northing = navPosUtm.NORTH; ///10; |
36 | chris2798 | 149 | actualPos.easting = navPosUtm.EAST; //10; |
150 | actualPos.altitude = navPosUtm.ALT; //10; |
||
21 | user | 151 | navPosUtm.packetStatus = 0; |
152 | } |
||
153 | |||
154 | if (navVelNed.packetStatus == 1){ |
||
155 | actualPos.velNorth = navVelNed.VEL_N; |
||
156 | actualPos.velEast = navVelNed.VEL_E; |
||
243 | hallo2 | 157 | actualPos.velDown = navVelNed.VEL_D; |
21 | user | 158 | navVelNed.packetStatus = 0;} |
37 | hallo2 | 159 | |
243 | hallo2 | 160 | if (actualPos.state == 2){ROT_ON; gps_new=1;} //-> Rot blinkt mit 4Hz wenn GPS 2D-Fix |
161 | else if (actualPos.state == 3){GRN_OFF; gps_new=1;} //-> Grün blinkt mit 4Hz wenn GPS 3D-Fix |
||
162 | } |
||
37 | hallo2 | 163 | |
21 | user | 164 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
165 | //++ Empfangs-Part der Datenübertragung, incl. CRC-Auswertung |
||
166 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
167 | SIGNAL(INT_VEC_RX) |
||
168 | { |
||
169 | static unsigned int crc; |
||
170 | static unsigned char crc1,crc2,buf_ptr; |
||
171 | static unsigned char UartState = 0; |
||
172 | unsigned char CrcOkay = 0; |
||
173 | |||
174 | SioTmp = UDR; |
||
175 | |||
243 | hallo2 | 176 | uint8_t c; |
21 | user | 177 | uint8_t re; |
178 | |||
179 | re = (UCSR0A & (_B1(FE0) | _B1(DOR0))); // any error occured ? |
||
180 | c = SioTmp; |
||
181 | |||
182 | #ifdef GPS_DEBUG |
||
183 | *bp++ = c; |
||
184 | if (bp >= (buf+200)) bp = buf; |
||
185 | if (v24state == 0) |
||
186 | { |
||
187 | v24state = 1; |
||
188 | UDR0 = *ep++; |
||
189 | if (ep >= buf+200) |
||
190 | ep = buf; |
||
191 | UCSR0B |= _B1(UDRIE0); //enable further irqs |
||
192 | } |
||
193 | #endif |
||
194 | |||
195 | if (re == 0) |
||
196 | { |
||
197 | switch (gpsState) |
||
198 | { |
||
199 | case GPS_EMPTY: |
||
200 | if (c == SYNC_CHAR1) |
||
201 | gpsState = GPS_SYNC1; |
||
202 | break; |
||
203 | case GPS_SYNC1: |
||
204 | if (c == SYNC_CHAR2) |
||
205 | gpsState = GPS_SYNC2; |
||
206 | else if (c != SYNC_CHAR1) |
||
207 | gpsState = GPS_EMPTY; |
||
208 | break; |
||
209 | case GPS_SYNC2: |
||
210 | if (c == CLASS_NAV) |
||
211 | gpsState = GPS_CLASS; |
||
212 | else |
||
213 | gpsState = GPS_EMPTY; |
||
214 | break; |
||
215 | case GPS_CLASS: // msg ID seen: init packed receive |
||
216 | msgID = c; |
||
217 | CK_A = CLASS_NAV + c; |
||
218 | CK_B = CLASS_NAV + CK_A; |
||
219 | gpsState = GPS_LEN1; |
||
220 | |||
221 | switch (msgID) |
||
222 | { |
||
223 | case MSGID_STATUS: |
||
224 | ubxP = (char*)&navStatus; |
||
225 | ubxEp = (char*)(&navStatus + sizeof(NAV_STATUS_t)); |
||
226 | ubxSp = (char*)&navStatus.packetStatus; |
||
227 | ignorePacket = navStatus.packetStatus; |
||
228 | break; |
||
229 | case MSGID_POSUTM: |
||
230 | ubxP = (char*)&navPosUtm; |
||
231 | ubxEp = (char*)(&navPosUtm + sizeof(NAV_POSUTM_t)); |
||
232 | ubxSp = (char*)&navPosUtm.packetStatus; |
||
233 | ignorePacket = navPosUtm.packetStatus; |
||
234 | break; |
||
235 | case MSGID_VELNED: |
||
236 | ubxP = (char*)&navVelNed; |
||
237 | ubxEp = (char*)(&navVelNed + sizeof(NAV_VELNED_t)); |
||
238 | ubxSp = (char*)&navVelNed.packetStatus; |
||
239 | ignorePacket = navVelNed.packetStatus; |
||
240 | break; |
||
37 | hallo2 | 241 | |
243 | hallo2 | 242 | |
21 | user | 243 | default: |
244 | ignorePacket = 1; |
||
245 | ubxSp = (char*)0; |
||
246 | } |
||
247 | break; |
||
248 | case GPS_LEN1: // first len byte |
||
249 | msgLen = c; |
||
250 | CK_A += c; |
||
251 | CK_B += CK_A; |
||
252 | gpsState = GPS_LEN2; |
||
253 | break; |
||
254 | case GPS_LEN2: // second len byte |
||
255 | msgLen = msgLen + (c * 256); |
||
256 | CK_A += c; |
||
257 | CK_B += CK_A; |
||
258 | gpsState = GPS_FILLING; // next data will be stored in packet struct |
||
259 | break; |
||
260 | case GPS_FILLING: |
||
261 | CK_A += c; |
||
262 | CK_B += CK_A; |
||
263 | |||
264 | if ( !ignorePacket && ubxP < ubxEp) |
||
265 | *ubxP++ = c; |
||
266 | |||
267 | if (--msgLen == 0) |
||
268 | gpsState = GPS_CKA; |
||
269 | |||
270 | break; |
||
271 | case GPS_CKA: |
||
272 | if (c == CK_A) |
||
273 | gpsState = GPS_CKB; |
||
274 | else |
||
275 | gpsState = GPS_EMPTY; |
||
276 | break; |
||
277 | case GPS_CKB: |
||
278 | if (c == CK_B && ubxSp) // No error -> packet received successfully |
||
279 | *ubxSp = 1; // set packetStatus in struct |
||
280 | gpsState = GPS_EMPTY; // ready for next packet |
||
281 | break; |
||
282 | default: |
||
283 | gpsState = GPS_EMPTY; // ready for next packet |
||
284 | } |
||
285 | } |
||
286 | else // discard any data if error occured |
||
287 | { |
||
288 | gpsState = GPS_EMPTY; |
||
289 | GPSscanData (); //Test kann ggf. wieder gelöscht werden! |
||
290 | } |
||
291 | GPSscanData (); |
||
243 | hallo2 | 292 | |
21 | user | 293 | |
294 | if(buf_ptr >= MAX_EMPFANGS_BUFF) UartState = 0; |
||
295 | if(SioTmp == '\r' && UartState == 2) |
||
296 | { |
||
297 | UartState = 0; |
||
298 | crc -= RxdBuffer[buf_ptr-2]; |
||
299 | crc -= RxdBuffer[buf_ptr-1]; |
||
300 | crc %= 4096; |
||
301 | crc1 = '=' + crc / 64; |
||
302 | crc2 = '=' + crc % 64; |
||
303 | CrcOkay = 0; |
||
304 | if((crc1 == RxdBuffer[buf_ptr-2]) && (crc2 == RxdBuffer[buf_ptr-1])) CrcOkay = 1; else { CrcOkay = 0; CntCrcError++;}; |
||
305 | if(!NeuerDatensatzEmpfangen && CrcOkay) // Datensatz schon verarbeitet |
||
306 | { |
||
307 | NeuerDatensatzEmpfangen = 1; |
||
308 | AnzahlEmpfangsBytes = buf_ptr; |
||
309 | RxdBuffer[buf_ptr] = '\r'; |
||
243 | hallo2 | 310 | if(RxdBuffer[2] == 'R') wdt_enable(WDTO_250MS); // Reset-Commando |
21 | user | 311 | } |
312 | } |
||
313 | else |
||
314 | switch(UartState) |
||
315 | { |
||
316 | case 0: |
||
317 | if(SioTmp == '#' && !NeuerDatensatzEmpfangen) UartState = 1; // Startzeichen und Daten schon verarbeitet |
||
318 | buf_ptr = 0; |
||
319 | RxdBuffer[buf_ptr++] = SioTmp; |
||
320 | crc = SioTmp; |
||
321 | break; |
||
322 | case 1: // Adresse auswerten |
||
323 | UartState++; |
||
324 | RxdBuffer[buf_ptr++] = SioTmp; |
||
325 | crc += SioTmp; |
||
326 | break; |
||
327 | case 2: // Eingangsdaten sammeln |
||
328 | RxdBuffer[buf_ptr] = SioTmp; |
||
329 | if(buf_ptr < MAX_EMPFANGS_BUFF) buf_ptr++; |
||
330 | else UartState = 0; |
||
331 | crc += SioTmp; |
||
332 | break; |
||
333 | default: |
||
334 | UartState = 0; |
||
335 | break; |
||
336 | } |
||
337 | } |
||
338 | |||
339 | |||
340 | // -------------------------------------------------------------------------- |
||
341 | void AddCRC(unsigned int wieviele) |
||
342 | { |
||
343 | unsigned int tmpCRC = 0,i; |
||
344 | for(i = 0; i < wieviele;i++) |
||
345 | { |
||
346 | tmpCRC += SendeBuffer[i]; |
||
347 | } |
||
348 | tmpCRC %= 4096; |
||
349 | SendeBuffer[i++] = '=' + tmpCRC / 64; |
||
350 | SendeBuffer[i++] = '=' + tmpCRC % 64; |
||
351 | SendeBuffer[i++] = '\r'; |
||
352 | UebertragungAbgeschlossen = 0; |
||
353 | UDR = SendeBuffer[0]; |
||
354 | } |
||
355 | |||
356 | |||
243 | hallo2 | 357 | |
21 | user | 358 | // -------------------------------------------------------------------------- |
359 | void SendOutData(unsigned char cmd,unsigned char modul, unsigned char *snd, unsigned char len) |
||
360 | { |
||
361 | unsigned int pt = 0; |
||
362 | unsigned char a,b,c; |
||
363 | unsigned char ptr = 0; |
||
364 | |||
365 | SendeBuffer[pt++] = '#'; // Startzeichen |
||
366 | SendeBuffer[pt++] = modul; // Adresse (a=0; b=1,...) |
||
367 | SendeBuffer[pt++] = cmd; // Commando |
||
368 | |||
369 | while(len) |
||
370 | { |
||
371 | if(len) { a = snd[ptr++]; len--;} else a = 0; |
||
372 | if(len) { b = snd[ptr++]; len--;} else b = 0; |
||
373 | if(len) { c = snd[ptr++]; len--;} else c = 0; |
||
374 | SendeBuffer[pt++] = '=' + (a >> 2); |
||
375 | SendeBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
||
376 | SendeBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
||
377 | SendeBuffer[pt++] = '=' + ( c & 0x3f); |
||
378 | } |
||
379 | AddCRC(pt); |
||
380 | } |
||
381 | |||
382 | |||
383 | // -------------------------------------------------------------------------- |
||
384 | void Decode64(unsigned char *ptrOut, unsigned char len, unsigned char ptrIn,unsigned char max) // Wohin mit den Daten; Wie lang; Wo im RxdBuffer |
||
385 | { |
||
386 | unsigned char a,b,c,d; |
||
387 | unsigned char ptr = 0; |
||
388 | unsigned char x,y,z; |
||
389 | while(len) |
||
390 | { |
||
391 | a = RxdBuffer[ptrIn++] - '='; |
||
392 | b = RxdBuffer[ptrIn++] - '='; |
||
393 | c = RxdBuffer[ptrIn++] - '='; |
||
394 | d = RxdBuffer[ptrIn++] - '='; |
||
395 | if(ptrIn > max - 2) break; // nicht mehr Daten verarbeiten, als empfangen wurden |
||
396 | |||
397 | x = (a << 2) | (b >> 4); |
||
398 | y = ((b & 0x0f) << 4) | (c >> 2); |
||
399 | z = ((c & 0x03) << 6) | d; |
||
400 | |||
401 | if(len--) ptrOut[ptr++] = x; else break; |
||
402 | if(len--) ptrOut[ptr++] = y; else break; |
||
403 | if(len--) ptrOut[ptr++] = z; else break; |
||
404 | } |
||
405 | |||
406 | } |
||
407 | |||
408 | // -------------------------------------------------------------------------- |
||
409 | void BearbeiteRxDaten(void) |
||
410 | { |
||
411 | if(!NeuerDatensatzEmpfangen) return; |
||
412 | |||
413 | unsigned int tmp_int_arr1[1]; |
||
414 | unsigned int tmp_int_arr2[2]; |
||
415 | unsigned int tmp_int_arr3[3]; |
||
416 | unsigned char tmp_char_arr2[2]; |
||
417 | unsigned char tmp_char_arr3[3]; |
||
418 | unsigned char tmp_char_arr4[4]; |
||
419 | //if(!MotorenEin) |
||
420 | PcZugriff = 255; |
||
421 | switch(RxdBuffer[2]) |
||
422 | { |
||
423 | case 'c':// Debugdaten incl. Externe IOs usw |
||
424 | Decode64((unsigned char *) &DebugIn,sizeof(DebugIn),3,AnzahlEmpfangsBytes); |
||
425 | /* for(unsigned char i=0; i<4;i++) |
||
426 | { |
||
427 | EE_CheckAndWrite(&EE_Buffer[EE_DEBUGWERTE + i*2], DebugIn.Analog[i]); |
||
428 | EE_CheckAndWrite(&EE_Buffer[EE_DEBUGWERTE + i*2 + 1], DebugIn.Analog[i] >> 8); |
||
429 | }*/ |
||
243 | hallo2 | 430 | //RemoteTasten |= DebugIn.RemoteTasten; |
21 | user | 431 | DebugDataAnforderung = 1; |
432 | break; |
||
433 | |||
434 | case 'h':// x-1 Displayzeilen |
||
435 | Decode64((unsigned char *) &tmp_char_arr2[0],sizeof(tmp_char_arr2),3,AnzahlEmpfangsBytes); |
||
436 | RemoteTasten |= tmp_char_arr2[0]; |
||
437 | DebugDisplayAnforderung = 1; |
||
438 | break; |
||
439 | case 't':// Motortest |
||
440 | Decode64((unsigned char *) &MotorTest[0],sizeof(MotorTest),3,AnzahlEmpfangsBytes); |
||
441 | break; |
||
442 | case 'v': // Version-Anforderung und Ausbaustufe |
||
443 | GetVersionAnforderung = 1; |
||
444 | break; |
||
445 | case 'g':// "Get"-Anforderung für Debug-Daten |
||
446 | // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
||
447 | DebugGetAnforderung = 1; |
||
448 | break; |
||
449 | case 'q':// "Get"-Anforderung für Settings |
||
450 | // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
||
451 | Decode64((unsigned char *) &tmp_char_arr2[0],sizeof(tmp_char_arr2),3,AnzahlEmpfangsBytes); |
||
452 | if(tmp_char_arr2[0] != 0xff) |
||
453 | { |
||
454 | if(tmp_char_arr2[0] > 5) tmp_char_arr2[0] = 5; |
||
455 | ReadParameterSet(tmp_char_arr2[0], (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
||
456 | SendOutData('L' + tmp_char_arr2[0] -1,MeineSlaveAdresse,(unsigned char *) &EE_Parameter.Kanalbelegung[0],STRUCT_PARAM_LAENGE); |
||
457 | } |
||
458 | else |
||
459 | SendOutData('L' + GetActiveParamSetNumber()-1,MeineSlaveAdresse,(unsigned char *) &EE_Parameter.Kanalbelegung[0],STRUCT_PARAM_LAENGE); |
||
460 | |||
461 | break; |
||
462 | |||
463 | case 'l': |
||
464 | case 'm': |
||
465 | case 'n': |
||
466 | case 'o': |
||
467 | case 'p': // Parametersatz speichern |
||
468 | Decode64((unsigned char *) &EE_Parameter.Kanalbelegung[0],STRUCT_PARAM_LAENGE,3,AnzahlEmpfangsBytes); |
||
469 | WriteParameterSet(RxdBuffer[2] - 'l' + 1, (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
||
470 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], RxdBuffer[2] - 'l' + 1); // aktiven Datensatz merken |
||
471 | Piep(GetActiveParamSetNumber()); |
||
472 | break; |
||
473 | |||
474 | |||
475 | } |
||
476 | // DebugOut.AnzahlZyklen = Debug_Timer_Intervall; |
||
477 | NeuerDatensatzEmpfangen = 0; |
||
478 | } |
||
479 | |||
480 | //############################################################################ |
||
481 | //Routine für die Serielle Ausgabe |
||
482 | int uart_putchar (char c) |
||
483 | //############################################################################ |
||
484 | { |
||
485 | if (c == '\n') |
||
486 | uart_putchar('\r'); |
||
487 | //Warten solange bis Zeichen gesendet wurde |
||
488 | loop_until_bit_is_set(USR, UDRE); |
||
489 | //Ausgabe des Zeichens |
||
490 | UDR = c; |
||
491 | |||
492 | return (0); |
||
493 | } |
||
494 | |||
495 | // -------------------------------------------------------------------------- |
||
496 | void WriteProgramData(unsigned int pos, unsigned char wert) |
||
497 | { |
||
498 | //if (ProgramLocation == IN_RAM) Buffer[pos] = wert; |
||
499 | // else eeprom_write_byte(&EE_Buffer[pos], wert); |
||
500 | // Buffer[pos] = wert; |
||
501 | } |
||
502 | |||
503 | //############################################################################ |
||
504 | //INstallation der Seriellen Schnittstelle |
||
505 | void UART_Init (void) |
||
506 | //############################################################################ |
||
507 | { |
||
508 | //Enable TXEN im Register UCR TX-Data Enable & RX Enable |
||
509 | |||
510 | UCR=(1 << TXEN) | (1 << RXEN); |
||
511 | // UART Double Speed (U2X) |
||
512 | USR |= (1<<U2X); |
||
513 | // RX-Interrupt Freigabe |
||
514 | UCSRB |= (1<<RXCIE); |
||
515 | // TX-Interrupt Freigabe |
||
516 | UCSRB |= (1<<TXCIE); |
||
517 | |||
518 | //Teiler wird gesetzt |
||
519 | UBRR=(SYSCLK / (BAUD_RATE * 8L) - 1); |
||
520 | //UBRR = 33; |
||
521 | //öffnet einen Kanal für printf (STDOUT) |
||
522 | //fdevopen (uart_putchar, 0); |
||
523 | //sbi(PORTD,4); |
||
524 | Debug_Timer = SetDelay(200); |
||
525 | } |
||
526 | |||
527 | //--------------------------------------------------------------------------------------------- |
||
528 | void DatenUebertragung(void) |
||
529 | { |
||
530 | static char dis_zeile = 0; |
||
531 | if(!UebertragungAbgeschlossen) return; |
||
532 | |||
533 | if(DebugGetAnforderung && UebertragungAbgeschlossen) // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
||
534 | { |
||
535 | SendOutData('G',MeineSlaveAdresse,(unsigned char *) &DebugIn,sizeof(DebugIn)); |
||
536 | DebugGetAnforderung = 0; |
||
537 | } |
||
538 | |||
539 | if((CheckDelay(Debug_Timer) || DebugDataAnforderung) && UebertragungAbgeschlossen) |
||
540 | { |
||
541 | SendOutData('D',MeineSlaveAdresse,(unsigned char *) &DebugOut,sizeof(DebugOut)); |
||
542 | DebugDataAnforderung = 0; |
||
543 | Debug_Timer = SetDelay(MIN_DEBUG_INTERVALL); |
||
544 | } |
||
545 | |||
546 | if(DebugDisplayAnforderung && UebertragungAbgeschlossen) |
||
547 | { |
||
548 | Menu(); |
||
549 | DebugDisplayAnforderung = 0; |
||
243 | hallo2 | 550 | if(++dis_zeile == 4) |
551 | { |
||
552 | SendOutData('4',0,&PPM_in,sizeof(PPM_in)); // DisplayZeile übertragen |
||
553 | dis_zeile = -1; |
||
554 | } |
||
555 | else SendOutData('0' + dis_zeile,0,&DisplayBuff[20 * dis_zeile],20); // DisplayZeile übertragen |
||
21 | user | 556 | } |
557 | if(GetVersionAnforderung && UebertragungAbgeschlossen) |
||
558 | { |
||
559 | SendOutData('V',MeineSlaveAdresse,(unsigned char *) &VersionInfo,sizeof(VersionInfo)); |
||
560 | GetVersionAnforderung = 0; |
||
561 | } |
||
562 | |||
563 | } |
||
564 |