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