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