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