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