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