Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
376 | 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 = 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 | if (navVelNed.packetStatus == 1) |
||
212 | { |
||
213 | actualPos.velNorth = navVelNed.VEL_N; |
||
214 | actualPos.velEast = navVelNed.VEL_E; |
||
215 | navVelNed.packetStatus = 0; |
||
216 | } |
||
217 | |||
218 | |||
219 | |||
220 | if (actualPos.newData != 0){ROT_ON;} //-> Rot blinkt mit 4Hz wenn Daten vom GPS Empfänger ankommen und brauchbar sind |
||
221 | |||
222 | } |
||
223 | |||
224 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
225 | //++ Empfangs-Part der Datenübertragung, incl. CRC-Auswertung |
||
226 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
227 | SIGNAL(INT_VEC_RX) |
||
228 | { |
||
229 | static unsigned int crc; |
||
230 | static unsigned char crc1,crc2,buf_ptr; |
||
231 | static unsigned char UartState = 0; |
||
232 | unsigned char CrcOkay = 0; |
||
233 | |||
234 | SioTmp = UDR; |
||
235 | |||
236 | uint8_t c; |
||
237 | uint8_t re; |
||
238 | |||
239 | re = (UCSR0A & (_B1(FE0) | _B1(DOR0))); // any error occured ? |
||
240 | c = SioTmp; |
||
241 | |||
242 | #ifdef GPS_DEBUG |
||
243 | *bp++ = c; |
||
244 | if (bp >= (buf+200)) bp = buf; |
||
245 | if (v24state == 0) |
||
246 | { |
||
247 | v24state = 1; |
||
248 | UDR0 = *ep++; |
||
249 | if (ep >= buf+200) |
||
250 | ep = buf; |
||
251 | UCSR0B |= _B1(UDRIE0); //enable further irqs |
||
252 | } |
||
253 | #endif |
||
254 | |||
255 | if (re == 0) |
||
256 | { |
||
257 | switch (gpsState) |
||
258 | { |
||
259 | case GPS_EMPTY: |
||
260 | if (c == SYNC_CHAR1) |
||
261 | gpsState = GPS_SYNC1; |
||
262 | break; |
||
263 | case GPS_SYNC1: |
||
264 | if (c == SYNC_CHAR2) |
||
265 | gpsState = GPS_SYNC2; |
||
266 | else if (c != SYNC_CHAR1) |
||
267 | gpsState = GPS_EMPTY; |
||
268 | break; |
||
269 | case GPS_SYNC2: |
||
270 | if (c == CLASS_NAV) |
||
271 | gpsState = GPS_CLASS; |
||
272 | else |
||
273 | gpsState = GPS_EMPTY; |
||
274 | break; |
||
275 | case GPS_CLASS: // msg ID seen: init packed receive |
||
276 | msgID = c; |
||
277 | CK_A = CLASS_NAV + c; |
||
278 | CK_B = CLASS_NAV + CK_A; |
||
279 | gpsState = GPS_LEN1; |
||
280 | |||
281 | switch (msgID) |
||
282 | { |
||
283 | case MSGID_STATUS: |
||
284 | ubxP = (char*)&navStatus; |
||
285 | ubxEp = (char*)(&navStatus + sizeof(NAV_STATUS_t)); |
||
286 | ubxSp = (char*)&navStatus.packetStatus; |
||
287 | ignorePacket = navStatus.packetStatus; |
||
288 | break; |
||
289 | case MSGID_POSECEF: |
||
290 | ubxP = (char*)&navPosECEF; |
||
291 | ubxEp = (char*)(&navPosECEF + sizeof(NAV_POSECEF_t)); |
||
292 | ubxSp = (char*)&navPosECEF.packetStatus; |
||
293 | ignorePacket = navPosECEF.packetStatus; |
||
294 | break; |
||
295 | case MSGID_VELECEF: |
||
296 | ubxP = (char*)&navVelECEF; |
||
297 | ubxEp = (char*)(&navVelECEF + sizeof(NAV_VELECEF_t)); |
||
298 | ubxSp = (char*)&navVelECEF.packetStatus; |
||
299 | ignorePacket = navVelECEF.packetStatus; |
||
300 | break; |
||
301 | case MSGID_POSUTM: |
||
302 | ubxP = (char*)&navPosUtm; |
||
303 | ubxEp = (char*)(&navPosUtm + sizeof(NAV_POSUTM_t)); |
||
304 | ubxSp = (char*)&navPosUtm.packetStatus; |
||
305 | ignorePacket = navPosUtm.packetStatus; |
||
306 | break; |
||
307 | case MSGID_VELNED: |
||
308 | ubxP = (char*)&navVelNed; |
||
309 | ubxEp = (char*)(&navVelNed + sizeof(NAV_VELNED_t)); |
||
310 | ubxSp = (char*)&navVelNed.packetStatus; |
||
311 | ignorePacket = navVelNed.packetStatus; |
||
312 | break; |
||
313 | |||
314 | |||
315 | default: |
||
316 | ignorePacket = 1; |
||
317 | ubxSp = (char*)0; |
||
318 | } |
||
319 | break; |
||
320 | case GPS_LEN1: // first len byte |
||
321 | msgLen = c; |
||
322 | CK_A += c; |
||
323 | CK_B += CK_A; |
||
324 | gpsState = GPS_LEN2; |
||
325 | break; |
||
326 | case GPS_LEN2: // second len byte |
||
327 | msgLen = msgLen + (c * 256); |
||
328 | CK_A += c; |
||
329 | CK_B += CK_A; |
||
330 | gpsState = GPS_FILLING; // next data will be stored in packet struct |
||
331 | break; |
||
332 | case GPS_FILLING: |
||
333 | CK_A += c; |
||
334 | CK_B += CK_A; |
||
335 | |||
336 | if ( !ignorePacket && ubxP < ubxEp) |
||
337 | *ubxP++ = c; |
||
338 | |||
339 | if (--msgLen == 0) |
||
340 | gpsState = GPS_CKA; |
||
341 | |||
342 | break; |
||
343 | case GPS_CKA: |
||
344 | if (c == CK_A) |
||
345 | gpsState = GPS_CKB; |
||
346 | else |
||
347 | gpsState = GPS_EMPTY; |
||
348 | break; |
||
349 | case GPS_CKB: |
||
350 | if (c == CK_B && ubxSp) // No error -> packet received successfully |
||
351 | *ubxSp = 1; // set packetStatus in struct |
||
352 | gpsState = GPS_EMPTY; // ready for next packet |
||
353 | break; |
||
354 | default: |
||
355 | gpsState = GPS_EMPTY; // ready for next packet |
||
356 | } |
||
357 | } |
||
358 | else // discard any data if error occured |
||
359 | { |
||
360 | gpsState = GPS_EMPTY; |
||
361 | GPSscanData (); //Test kann ggf. wieder gelöscht werden! |
||
362 | } |
||
363 | GPSscanData (); |
||
364 | |||
365 | |||
366 | |||
367 | |||
368 | |||
369 | |||
370 | |||
371 | if(buf_ptr >= MAX_EMPFANGS_BUFF) UartState = 0; |
||
372 | if(SioTmp == '\r' && UartState == 2) |
||
373 | { |
||
374 | UartState = 0; |
||
375 | crc -= RxdBuffer[buf_ptr-2]; |
||
376 | crc -= RxdBuffer[buf_ptr-1]; |
||
377 | crc %= 4096; |
||
378 | crc1 = '=' + crc / 64; |
||
379 | crc2 = '=' + crc % 64; |
||
380 | CrcOkay = 0; |
||
381 | if((crc1 == RxdBuffer[buf_ptr-2]) && (crc2 == RxdBuffer[buf_ptr-1])) CrcOkay = 1; else { CrcOkay = 0; CntCrcError++;}; |
||
382 | if(!NeuerDatensatzEmpfangen && CrcOkay) // Datensatz schon verarbeitet |
||
383 | { |
||
384 | NeuerDatensatzEmpfangen = 1; |
||
385 | AnzahlEmpfangsBytes = buf_ptr; |
||
386 | RxdBuffer[buf_ptr] = '\r'; |
||
387 | if(RxdBuffer[2] == 'R') wdt_enable(WDTO_250MS); // Reset-Commando |
||
388 | } |
||
389 | } |
||
390 | else |
||
391 | switch(UartState) |
||
392 | { |
||
393 | case 0: |
||
394 | if(SioTmp == '#' && !NeuerDatensatzEmpfangen) UartState = 1; // Startzeichen und Daten schon verarbeitet |
||
395 | buf_ptr = 0; |
||
396 | RxdBuffer[buf_ptr++] = SioTmp; |
||
397 | crc = SioTmp; |
||
398 | break; |
||
399 | case 1: // Adresse auswerten |
||
400 | UartState++; |
||
401 | RxdBuffer[buf_ptr++] = SioTmp; |
||
402 | crc += SioTmp; |
||
403 | break; |
||
404 | case 2: // Eingangsdaten sammeln |
||
405 | RxdBuffer[buf_ptr] = SioTmp; |
||
406 | if(buf_ptr < MAX_EMPFANGS_BUFF) buf_ptr++; |
||
407 | else UartState = 0; |
||
408 | crc += SioTmp; |
||
409 | break; |
||
410 | default: |
||
411 | UartState = 0; |
||
412 | break; |
||
413 | } |
||
414 | } |
||
415 | |||
416 | |||
417 | // -------------------------------------------------------------------------- |
||
418 | void AddCRC(unsigned int wieviele) |
||
419 | { |
||
420 | unsigned int tmpCRC = 0,i; |
||
421 | for(i = 0; i < wieviele;i++) |
||
422 | { |
||
423 | tmpCRC += SendeBuffer[i]; |
||
424 | } |
||
425 | tmpCRC %= 4096; |
||
426 | SendeBuffer[i++] = '=' + tmpCRC / 64; |
||
427 | SendeBuffer[i++] = '=' + tmpCRC % 64; |
||
428 | SendeBuffer[i++] = '\r'; |
||
429 | UebertragungAbgeschlossen = 0; |
||
430 | UDR = SendeBuffer[0]; |
||
431 | } |
||
432 | |||
433 | |||
434 | // -------------------------------------------------------------------------- |
||
435 | void SendOutData(unsigned char cmd,unsigned char modul, unsigned char *snd, unsigned char len) |
||
436 | { |
||
437 | unsigned int pt = 0; |
||
438 | unsigned char a,b,c; |
||
439 | unsigned char ptr = 0; |
||
440 | |||
441 | SendeBuffer[pt++] = '#'; // Startzeichen |
||
442 | SendeBuffer[pt++] = modul; // Adresse (a=0; b=1,...) |
||
443 | SendeBuffer[pt++] = cmd; // Commando |
||
444 | |||
445 | while(len) |
||
446 | { |
||
447 | if(len) { a = snd[ptr++]; len--;} else a = 0; |
||
448 | if(len) { b = snd[ptr++]; len--;} else b = 0; |
||
449 | if(len) { c = snd[ptr++]; len--;} else c = 0; |
||
450 | SendeBuffer[pt++] = '=' + (a >> 2); |
||
451 | SendeBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
||
452 | SendeBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
||
453 | SendeBuffer[pt++] = '=' + ( c & 0x3f); |
||
454 | } |
||
455 | AddCRC(pt); |
||
456 | } |
||
457 | |||
458 | |||
459 | // -------------------------------------------------------------------------- |
||
460 | void Decode64(unsigned char *ptrOut, unsigned char len, unsigned char ptrIn,unsigned char max) // Wohin mit den Daten; Wie lang; Wo im RxdBuffer |
||
461 | { |
||
462 | unsigned char a,b,c,d; |
||
463 | unsigned char ptr = 0; |
||
464 | unsigned char x,y,z; |
||
465 | while(len) |
||
466 | { |
||
467 | a = RxdBuffer[ptrIn++] - '='; |
||
468 | b = RxdBuffer[ptrIn++] - '='; |
||
469 | c = RxdBuffer[ptrIn++] - '='; |
||
470 | d = RxdBuffer[ptrIn++] - '='; |
||
471 | if(ptrIn > max - 2) break; // nicht mehr Daten verarbeiten, als empfangen wurden |
||
472 | |||
473 | x = (a << 2) | (b >> 4); |
||
474 | y = ((b & 0x0f) << 4) | (c >> 2); |
||
475 | z = ((c & 0x03) << 6) | d; |
||
476 | |||
477 | if(len--) ptrOut[ptr++] = x; else break; |
||
478 | if(len--) ptrOut[ptr++] = y; else break; |
||
479 | if(len--) ptrOut[ptr++] = z; else break; |
||
480 | } |
||
481 | |||
482 | } |
||
483 | |||
484 | // -------------------------------------------------------------------------- |
||
485 | void BearbeiteRxDaten(void) |
||
486 | { |
||
487 | if(!NeuerDatensatzEmpfangen) return; |
||
488 | |||
489 | //unsigned int tmp_int_arr1[1]; |
||
490 | //unsigned int tmp_int_arr2[2]; |
||
491 | //unsigned int tmp_int_arr3[3]; |
||
492 | unsigned char tmp_char_arr2[2]; |
||
493 | //unsigned char tmp_char_arr3[3]; |
||
494 | //unsigned char tmp_char_arr4[4]; |
||
495 | |||
496 | /* |
||
497 | unsigned int tmp_int_arr1[1]; |
||
498 | unsigned int tmp_int_arr2[2]; |
||
499 | unsigned int tmp_int_arr3[3]; |
||
500 | unsigned char tmp_char_arr2[2]; |
||
501 | unsigned char tmp_char_arr3[3]; |
||
502 | unsigned char tmp_char_arr4[4]; |
||
503 | */ |
||
504 | |||
505 | //if(!MotorenEin) |
||
506 | PcZugriff = 255; |
||
507 | switch(RxdBuffer[2]) |
||
508 | { |
||
509 | case 'c':// Debugdaten incl. Externe IOs usw |
||
510 | Decode64((unsigned char *) &DebugIn,sizeof(DebugIn),3,AnzahlEmpfangsBytes); |
||
511 | /* for(unsigned char i=0; i<4;i++) |
||
512 | { |
||
513 | EE_CheckAndWrite(&EE_Buffer[EE_DEBUGWERTE + i*2], DebugIn.Analog[i]); |
||
514 | EE_CheckAndWrite(&EE_Buffer[EE_DEBUGWERTE + i*2 + 1], DebugIn.Analog[i] >> 8); |
||
515 | }*/ |
||
516 | //RemoteTasten |= DebugIn.RemoteTasten; |
||
517 | DebugDataAnforderung = 1; |
||
518 | break; |
||
519 | |||
520 | case 'h':// x-1 Displayzeilen |
||
521 | Decode64((unsigned char *) &tmp_char_arr2[0],sizeof(tmp_char_arr2),3,AnzahlEmpfangsBytes); |
||
522 | RemoteTasten |= tmp_char_arr2[0]; |
||
523 | DebugDisplayAnforderung = 1; |
||
524 | break; |
||
525 | case 't':// Motortest |
||
526 | Decode64((unsigned char *) &MotorTest[0],sizeof(MotorTest),3,AnzahlEmpfangsBytes); |
||
527 | break; |
||
528 | case 'v': // Version-Anforderung und Ausbaustufe |
||
529 | GetVersionAnforderung = 1; |
||
530 | break; |
||
531 | case 'g':// "Get"-Anforderung für Debug-Daten |
||
532 | // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
||
533 | DebugGetAnforderung = 1; |
||
534 | break; |
||
535 | case 'q':// "Get"-Anforderung für Settings |
||
536 | // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
||
537 | Decode64((unsigned char *) &tmp_char_arr2[0],sizeof(tmp_char_arr2),3,AnzahlEmpfangsBytes); |
||
538 | if(tmp_char_arr2[0] != 0xff) |
||
539 | { |
||
540 | if(tmp_char_arr2[0] > 5) tmp_char_arr2[0] = 5; |
||
541 | ReadParameterSet(tmp_char_arr2[0], (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
||
542 | SendOutData('L' + tmp_char_arr2[0] -1,MeineSlaveAdresse,(unsigned char *) &EE_Parameter.Kanalbelegung[0],STRUCT_PARAM_LAENGE); |
||
543 | } |
||
544 | else |
||
545 | SendOutData('L' + GetActiveParamSetNumber()-1,MeineSlaveAdresse,(unsigned char *) &EE_Parameter.Kanalbelegung[0],STRUCT_PARAM_LAENGE); |
||
546 | |||
547 | break; |
||
548 | |||
549 | case 'l': |
||
550 | case 'm': |
||
551 | case 'n': |
||
552 | case 'o': |
||
553 | case 'p': // Parametersatz speichern |
||
554 | Decode64((unsigned char *) &EE_Parameter.Kanalbelegung[0],STRUCT_PARAM_LAENGE,3,AnzahlEmpfangsBytes); |
||
555 | WriteParameterSet(RxdBuffer[2] - 'l' + 1, (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
||
556 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], RxdBuffer[2] - 'l' + 1); // aktiven Datensatz merken |
||
557 | Piep(GetActiveParamSetNumber()); |
||
558 | break; |
||
559 | |||
560 | |||
561 | } |
||
562 | // DebugOut.AnzahlZyklen = Debug_Timer_Intervall; |
||
563 | NeuerDatensatzEmpfangen = 0; |
||
564 | } |
||
565 | |||
566 | //############################################################################ |
||
567 | //Routine für die Serielle Ausgabe |
||
568 | int uart_putchar (char c) |
||
569 | //############################################################################ |
||
570 | { |
||
571 | if (c == '\n') |
||
572 | uart_putchar('\r'); |
||
573 | //Warten solange bis Zeichen gesendet wurde |
||
574 | loop_until_bit_is_set(USR, UDRE); |
||
575 | //Ausgabe des Zeichens |
||
576 | UDR = c; |
||
577 | |||
578 | return (0); |
||
579 | } |
||
580 | |||
581 | // -------------------------------------------------------------------------- |
||
582 | void WriteProgramData(unsigned int pos, unsigned char wert) |
||
583 | { |
||
584 | //if (ProgramLocation == IN_RAM) Buffer[pos] = wert; |
||
585 | // else eeprom_write_byte(&EE_Buffer[pos], wert); |
||
586 | // Buffer[pos] = wert; |
||
587 | } |
||
588 | |||
589 | //############################################################################ |
||
590 | //INstallation der Seriellen Schnittstelle |
||
591 | void UART_Init (void) |
||
592 | //############################################################################ |
||
593 | { |
||
594 | //Enable TXEN im Register UCR TX-Data Enable & RX Enable |
||
595 | |||
596 | UCR=(1 << TXEN) | (1 << RXEN); |
||
597 | // UART Double Speed (U2X) |
||
598 | USR |= (1<<U2X); |
||
599 | // RX-Interrupt Freigabe |
||
600 | UCSRB |= (1<<RXCIE); |
||
601 | // TX-Interrupt Freigabe |
||
602 | UCSRB |= (1<<TXCIE); |
||
603 | |||
604 | //Teiler wird gesetzt |
||
605 | UBRR=(SYSCLK / (BAUD_RATE * 8L) - 1); |
||
606 | //UBRR = 33; |
||
607 | //öffnet einen Kanal für printf (STDOUT) |
||
608 | //fdevopen (uart_putchar, 0); |
||
609 | //sbi(PORTD,4); |
||
610 | Debug_Timer = SetDelay(200); |
||
611 | |||
612 | gpsState = GPS_EMPTY; |
||
613 | } |
||
614 | |||
615 | //--------------------------------------------------------------------------------------------- |
||
616 | void DatenUebertragung(void) |
||
617 | { |
||
618 | static char dis_zeile = 0; |
||
619 | if(!UebertragungAbgeschlossen) return; |
||
620 | |||
621 | if(DebugGetAnforderung && UebertragungAbgeschlossen) // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
||
622 | { |
||
623 | SendOutData('G',MeineSlaveAdresse,(unsigned char *) &DebugIn,sizeof(DebugIn)); |
||
624 | DebugGetAnforderung = 0; |
||
625 | } |
||
626 | |||
627 | if((CheckDelay(Debug_Timer) || DebugDataAnforderung) && UebertragungAbgeschlossen) |
||
628 | { |
||
629 | SendOutData('D',MeineSlaveAdresse,(unsigned char *) &DebugOut,sizeof(DebugOut)); |
||
630 | DebugDataAnforderung = 0; |
||
631 | Debug_Timer = SetDelay(MIN_DEBUG_INTERVALL); |
||
632 | } |
||
633 | |||
634 | if(DebugDisplayAnforderung && UebertragungAbgeschlossen) |
||
635 | { |
||
636 | Menu(); |
||
637 | DebugDisplayAnforderung = 0; |
||
638 | if(++dis_zeile == 4) |
||
639 | { |
||
640 | SendOutData('4',0,&PPM_in,sizeof(PPM_in)); // DisplayZeile übertragen |
||
641 | dis_zeile = -1; |
||
642 | } |
||
643 | else SendOutData('0' + dis_zeile,0,&DisplayBuff[20 * dis_zeile],20); // DisplayZeile übertragen |
||
644 | } |
||
645 | if(GetVersionAnforderung && UebertragungAbgeschlossen) |
||
646 | { |
||
647 | SendOutData('V',MeineSlaveAdresse,(unsigned char *) &VersionInfo,sizeof(VersionInfo)); |
||
648 | GetVersionAnforderung = 0; |
||
649 | } |
||
650 | |||
651 | } |
||
652 |