Rev 1038 | Rev 1053 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1038 | Rev 1051 | ||
---|---|---|---|
Line 2... | Line 2... | ||
2 | // + Copyright (c) 04.2007 Holger Buss |
2 | // + Copyright (c) 04.2007 Holger Buss |
3 | // + only for non-profit use |
3 | // + only for non-profit use |
4 | // + www.MikroKopter.com |
4 | // + www.MikroKopter.com |
5 | // + see the File "License.txt" for further Informations |
5 | // + see the File "License.txt" for further Informations |
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
7 | - | ||
- | 7 | #include <stdarg.h> |
|
- | 8 | #include <string.h> |
|
8 | #include "main.h" |
9 | #include "main.h" |
9 | #include "uart.h" |
10 | #include "uart.h" |
Line 10... | Line 11... | ||
10 | 11 | ||
11 | unsigned char GetExternalControl = 0,DebugDisplayAnforderung = 0,DebugDataAnforderung = 0,GetVersionAnforderung = 0; |
12 | unsigned char GetExternalControl = 0,DebugDisplayAnforderung = 0,DebugDataAnforderung = 0,GetVersionAnforderung = 0, GetPPMChannelAnforderung = 0; |
12 | unsigned volatile char SioTmp = 0; |
13 | unsigned volatile char SioTmp = 0; |
13 | unsigned volatile char SendeBuffer[MAX_SENDE_BUFF]; |
14 | unsigned volatile char SendeBuffer[MAX_SENDE_BUFF]; |
14 | unsigned volatile char RxdBuffer[MAX_EMPFANGS_BUFF]; |
15 | unsigned volatile char RxdBuffer[MAX_EMPFANGS_BUFF]; |
15 | unsigned volatile char NMEABuffer[MAX_EMPFANGS_BUFF]; |
16 | unsigned volatile char NMEABuffer[MAX_EMPFANGS_BUFF]; |
16 | unsigned volatile char NeuerDatensatzEmpfangen = 0; |
17 | unsigned volatile char NeuerDatensatzEmpfangen = 0; |
17 | unsigned volatile char NeueKoordinateEmpfangen = 0; |
18 | unsigned volatile char NeueKoordinateEmpfangen = 0; |
18 | unsigned volatile char UebertragungAbgeschlossen = 1; |
19 | unsigned volatile char UebertragungAbgeschlossen = 1; |
19 | unsigned volatile char CntCrcError = 0; |
20 | unsigned volatile char CntCrcError = 0; |
- | 21 | unsigned volatile char AnzahlEmpfangsBytes = 0; |
|
- | 22 | unsigned char *pRxData = 0; |
|
20 | unsigned volatile char AnzahlEmpfangsBytes = 0; |
23 | unsigned char RxDataLen = 0; |
21 | unsigned volatile char PC_DebugTimeout = 0; |
- | |
22 | unsigned char RemotePollDisplayLine = 0; |
- | |
- | 24 | unsigned volatile char PC_DebugTimeout = 0; |
|
23 | unsigned char NurKanalAnforderung = 0; |
25 | |
24 | unsigned char DebugTextAnforderung = 255; |
26 | unsigned char DebugTextAnforderung = 255; |
25 | unsigned char PcZugriff = 100; |
27 | unsigned char PcZugriff = 100; |
26 | unsigned char MotorTest[4] = {0,0,0,0}; |
- | |
27 | unsigned char DubWiseKeys[4] = {0,0,0,0}; |
28 | unsigned char MotorTest[4] = {0,0,0,0}; |
28 | unsigned char MeineSlaveAdresse = 1; // Flight-Ctrl |
29 | unsigned char MeineSlaveAdresse = 1; // Flight-Ctrl |
29 | unsigned char ConfirmFrame; |
30 | unsigned char ConfirmFrame; |
30 | struct str_DebugOut DebugOut; |
31 | struct str_DebugOut DebugOut; |
31 | struct str_ExternControl ExternControl; |
32 | struct str_ExternControl ExternControl; |
32 | struct str_VersionInfo VersionInfo; |
33 | struct str_VersionInfo VersionInfo; |
Line 33... | Line 34... | ||
33 | struct str_WinkelOut WinkelOut; |
34 | struct str_WinkelOut WinkelOut; |
- | 35 | ||
Line 34... | Line 36... | ||
34 | 36 | int Debug_Timer,Kompass_Timer; |
|
35 | int Debug_Timer,Kompass_Timer; |
37 | unsigned int DebugDataIntervall = 200; |
36 | 38 | ||
37 | const unsigned char ANALOG_TEXT[32][16] = |
39 | const unsigned char ANALOG_TEXT[32][16] = |
Line 117... | Line 119... | ||
117 | CrcOkay = 0; |
119 | CrcOkay = 0; |
118 | if((crc1 == RxdBuffer[buf_ptr-2]) && (crc2 == RxdBuffer[buf_ptr-1])) CrcOkay = 1; else { CrcOkay = 0; CntCrcError++;}; |
120 | if((crc1 == RxdBuffer[buf_ptr-2]) && (crc2 == RxdBuffer[buf_ptr-1])) CrcOkay = 1; else { CrcOkay = 0; CntCrcError++;}; |
119 | if(!NeuerDatensatzEmpfangen && CrcOkay) // Datensatz schon verarbeitet |
121 | if(!NeuerDatensatzEmpfangen && CrcOkay) // Datensatz schon verarbeitet |
120 | { |
122 | { |
121 | NeuerDatensatzEmpfangen = 1; |
123 | NeuerDatensatzEmpfangen = 1; |
122 | AnzahlEmpfangsBytes = buf_ptr; |
124 | AnzahlEmpfangsBytes = buf_ptr + 1; |
123 | RxdBuffer[buf_ptr] = '\r'; |
125 | RxdBuffer[buf_ptr] = '\r'; |
124 | if(RxdBuffer[2] == 'R') wdt_enable(WDTO_250MS); // Reset-Commando |
126 | if(RxdBuffer[2] == 'R') wdt_enable(WDTO_250MS); // Reset-Commando |
125 | } |
127 | } |
126 | } |
128 | } |
127 | else |
129 | else |
Line 168... | Line 170... | ||
168 | } |
170 | } |
Line 169... | Line 171... | ||
169 | 171 | ||
170 | 172 | ||
171 | 173 | ||
- | 174 | // -------------------------------------------------------------------------- |
|
172 | // -------------------------------------------------------------------------- |
175 | void SendOutData(unsigned char cmd,unsigned char modul, unsigned char BufferAnzahl, ...) //unsigned char *snd, unsigned char len) |
173 | void SendOutData(unsigned char cmd,unsigned char modul, unsigned char *snd, unsigned char len) |
176 | { |
174 | { |
177 | va_list ap; |
Line -... | Line 178... | ||
- | 178 | unsigned int pt = 0; |
|
- | 179 | unsigned char a,b,c; |
|
- | 180 | unsigned char ptr = 0; |
|
175 | unsigned int pt = 0; |
181 | |
176 | unsigned char a,b,c; |
182 | unsigned char *snd = 0; |
177 | unsigned char ptr = 0; |
183 | int len = 0; |
Line -... | Line 184... | ||
- | 184 | ||
- | 185 | SendeBuffer[pt++] = '#'; // Startzeichen |
|
- | 186 | SendeBuffer[pt++] = modul; // Adresse (a=0; b=1,...) |
|
- | 187 | SendeBuffer[pt++] = cmd; // Commando |
|
- | 188 | ||
- | 189 | va_start(ap, BufferAnzahl); |
|
- | 190 | if(BufferAnzahl) |
|
- | 191 | { |
|
178 | 192 | snd = va_arg(ap, unsigned char*); |
|
179 | SendeBuffer[pt++] = '#'; // Startzeichen |
193 | len = va_arg(ap, int); |
- | 194 | ptr = 0; |
|
- | 195 | BufferAnzahl--; |
|
180 | SendeBuffer[pt++] = modul; // Adresse (a=0; b=1,...) |
196 | } |
- | 197 | while(len) |
|
181 | SendeBuffer[pt++] = cmd; // Commando |
198 | { |
- | 199 | if(len) |
|
- | 200 | { |
|
- | 201 | a = snd[ptr++]; |
|
- | 202 | len--; |
|
- | 203 | if((!len) && BufferAnzahl) |
|
- | 204 | { |
|
- | 205 | snd = va_arg(ap, unsigned char*); |
|
- | 206 | len = va_arg(ap, int); |
|
- | 207 | ptr = 0; |
|
- | 208 | BufferAnzahl--; |
|
- | 209 | } |
|
- | 210 | } |
|
- | 211 | else a = 0; |
|
- | 212 | if(len) |
|
- | 213 | { |
|
- | 214 | b = snd[ptr++]; |
|
- | 215 | len--; |
|
- | 216 | if((!len) && BufferAnzahl) |
|
- | 217 | { |
|
- | 218 | snd = va_arg(ap, unsigned char*); |
|
- | 219 | len = va_arg(ap, int); |
|
- | 220 | ptr = 0; |
|
- | 221 | BufferAnzahl--; |
|
- | 222 | } |
|
- | 223 | } |
|
- | 224 | else b = 0; |
|
- | 225 | if(len) |
|
182 | 226 | { |
|
- | 227 | c = snd[ptr++]; |
|
- | 228 | len--; |
|
- | 229 | if((!len) && BufferAnzahl) |
|
- | 230 | { |
|
- | 231 | snd = va_arg(ap, unsigned char*); |
|
- | 232 | len = va_arg(ap, int); |
|
183 | while(len) |
233 | ptr = 0; |
184 | { |
234 | BufferAnzahl--; |
185 | if(len) { a = snd[ptr++]; len--;} else a = 0; |
235 | } |
186 | if(len) { b = snd[ptr++]; len--;} else b = 0; |
236 | } |
187 | if(len) { c = snd[ptr++]; len--;} else c = 0; |
237 | else c = 0; |
- | 238 | SendeBuffer[pt++] = '=' + (a >> 2); |
|
188 | SendeBuffer[pt++] = '=' + (a >> 2); |
239 | SendeBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
189 | SendeBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
240 | SendeBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
Line 190... | Line 241... | ||
190 | SendeBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
241 | SendeBuffer[pt++] = '=' + ( c & 0x3f); |
191 | SendeBuffer[pt++] = '=' + ( c & 0x3f); |
242 | } |
192 | } |
243 | va_end(ap); |
193 | AddCRC(pt); |
244 | AddCRC(pt); |
194 | } |
- | |
195 | 245 | } |
|
- | 246 | ||
- | 247 | ||
- | 248 | // -------------------------------------------------------------------------- |
|
- | 249 | void Decode64(void) // die daten werden im rx buffer dekodiert, das geht nur, weil aus 4 byte immer 3 gemacht werden. |
|
196 | 250 | { |
|
197 | // -------------------------------------------------------------------------- |
251 | unsigned char a,b,c,d; |
198 | void Decode64(unsigned char *ptrOut, unsigned char len, unsigned char ptrIn,unsigned char max) // Wohin mit den Daten; Wie lang; Wo im RxdBuffer |
252 | unsigned char x,y,z; |
199 | { |
253 | unsigned char ptrIn = 3; // start at begin of data block |
200 | unsigned char a,b,c,d; |
254 | unsigned char ptrOut = 3; |
201 | unsigned char ptr = 0; |
255 | unsigned char len = AnzahlEmpfangsBytes - 6; // von der Gesamtbytezahl eines Frames gehen 3 Bytes des Headers ('#',Addr, Cmd) und 3 Bytes des Footers (CRC1, CRC2, '\r') ab. |
202 | unsigned char x,y,z; |
- | |
Line 203... | Line 256... | ||
203 | while(len) |
256 | |
204 | { |
257 | while(len) |
205 | a = RxdBuffer[ptrIn++] - '='; |
258 | { |
Line 206... | Line 259... | ||
206 | b = RxdBuffer[ptrIn++] - '='; |
259 | a = RxdBuffer[ptrIn++] - '='; |
207 | c = RxdBuffer[ptrIn++] - '='; |
260 | b = RxdBuffer[ptrIn++] - '='; |
208 | d = RxdBuffer[ptrIn++] - '='; |
261 | c = RxdBuffer[ptrIn++] - '='; |
209 | if(ptrIn > max - 2) break; // nicht mehr Daten verarbeiten, als empfangen wurden |
262 | d = RxdBuffer[ptrIn++] - '='; |
- | 263 | ||
- | 264 | x = (a << 2) | (b >> 4); |
|
Line 210... | Line 265... | ||
210 | 265 | y = ((b & 0x0f) << 4) | (c >> 2); |
|
Line 211... | Line 266... | ||
211 | x = (a << 2) | (b >> 4); |
266 | z = ((c & 0x03) << 6) | d; |
212 | y = ((b & 0x0f) << 4) | (c >> 2); |
267 | |
213 | z = ((c & 0x03) << 6) | d; |
268 | if(len--) RxdBuffer[ptrOut++] = x; else break; |
214 | 269 | if(len--) RxdBuffer[ptrOut++] = y; else break; |
|
Line 215... | Line -... | ||
215 | if(len--) ptrOut[ptr++] = x; else break; |
- | |
216 | if(len--) ptrOut[ptr++] = y; else break; |
- | |
217 | if(len--) ptrOut[ptr++] = z; else break; |
- | |
218 | } |
- | |
219 | - | ||
220 | } |
270 | if(len--) RxdBuffer[ptrOut++] = z; else break; |
221 | - | ||
- | 271 | } |
|
222 | // -------------------------------------------------------------------------- |
272 | pRxData = (unsigned char*)&RxdBuffer[3]; // decodierte Daten beginnen beim 4. Byte |
223 | void BearbeiteRxDaten(void) |
273 | RxDataLen = ptrOut - 3; // wie viele Bytes wurden dekodiert? |
224 | { |
274 | |
225 | if(!NeuerDatensatzEmpfangen) return; |
275 | } |
226 | - | ||
227 | unsigned int tmp_int_arr1[1]; |
276 | |
228 | // unsigned int tmp_int_arr2[2]; |
277 | // -------------------------------------------------------------------------- |
229 | // unsigned int tmp_int_arr3[3]; |
278 | void BearbeiteRxDaten(void) |
230 | unsigned char tmp_char_arr2[2]; |
279 | { |
231 | // unsigned char tmp_char_arr3[3]; |
280 | if(!NeuerDatensatzEmpfangen) return; |
232 | // unsigned char tmp_char_arr4[4]; |
281 | |
233 | //if(!MotorenEin) |
282 | Decode64(); // dekodiere datenblock im Empfangsbuffer |
234 | switch(RxdBuffer[2]) |
283 | |
235 | { |
284 | switch(RxdBuffer[2]) |
236 | case 'K':// Kompasswert |
- | |
237 | Decode64((unsigned char *) &tmp_int_arr1[0],sizeof(tmp_int_arr1),3,AnzahlEmpfangsBytes); |
- | |
238 | KompassValue = tmp_int_arr1[0]; |
- | |
239 | KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180; |
- | |
240 | break; |
- | |
241 | case 'a':// Texte der Analogwerte |
- | |
242 | Decode64((unsigned char *) &tmp_char_arr2[0],sizeof(tmp_char_arr2),3,AnzahlEmpfangsBytes); |
- | |
243 | DebugTextAnforderung = tmp_char_arr2[0]; |
285 | { |
244 | PcZugriff = 255; |
- | |
245 | break; |
286 | case 'K':// Kompasswert |
246 | case 'b': |
287 | memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue)); |
247 | Decode64((unsigned char *) &ExternControl,sizeof(ExternControl),3,AnzahlEmpfangsBytes); |
288 | KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180; |
- | 289 | break; |
|
248 | RemoteTasten |= ExternControl.RemoteTasten; |
290 | case 'a':// Texte der Analogwerte |
249 | ConfirmFrame = ExternControl.Frame; |
291 | DebugTextAnforderung = pRxData[0]; |
250 | PcZugriff = 255; |
292 | if (DebugTextAnforderung > 31) DebugTextAnforderung = 31; |
251 | break; |
- | |
252 | case 'c': |
293 | PcZugriff = 255; |
253 | Decode64((unsigned char *) &ExternControl,sizeof(ExternControl),3,AnzahlEmpfangsBytes); |
- | |
254 | RemoteTasten |= ExternControl.RemoteTasten; |
294 | break; |
255 | ConfirmFrame = ExternControl.Frame; |
295 | case 'b': |
256 | DebugDataAnforderung = 1; |
296 | memcpy((unsigned char *)&ExternControl, (unsigned char *)pRxData, sizeof(ExternControl)); |
257 | PcZugriff = 255; |
297 | ConfirmFrame = ExternControl.Frame; |
258 | break; |
298 | PcZugriff = 255; |
259 | case 'f': // Poll the debug data |
- | |
260 | DebugDataAnforderung = 1; |
- | |
261 | break; |
299 | break; |
262 | case 'h':// x-1 Displayzeilen |
- | |
263 | Decode64((unsigned char *) &tmp_char_arr2[0],sizeof(tmp_char_arr2),3,AnzahlEmpfangsBytes); |
300 | case 'd': // Poll the debug data |
264 | RemoteTasten |= tmp_char_arr2[0]; |
301 | DebugDataIntervall = pRxData[0] * 10; |
265 | if(tmp_char_arr2[1] == 255) NurKanalAnforderung = 1; else NurKanalAnforderung = 0; // keine Displaydaten |
302 | if (DebugDataIntervall) DebugDataAnforderung = 1; |
266 | DebugDisplayAnforderung = 1; |
303 | break; |
267 | break; |
304 | case 'l':// x-1 Displayzeilen |
268 | case 't':// Motortest |
305 | MenuePunkt = pRxData[0]; |
269 | Decode64((unsigned char *) &MotorTest[0],sizeof(MotorTest),3,AnzahlEmpfangsBytes); |
306 | DebugDisplayAnforderung = 1; |
270 | PcZugriff = 255; |
307 | break; |
- | 308 | case 'm':// Motortest |
|
- | 309 | memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest)); |
|
- | 310 | while(!UebertragungAbgeschlossen); |
|
271 | break; |
311 | SendOutData('M', MeineSlaveAdresse, 0); |
272 | case 'k':// Keys von DubWise |
312 | PcZugriff = 255; |
273 | Decode64((unsigned char *) &DubWiseKeys[0],sizeof(DubWiseKeys),3,AnzahlEmpfangsBytes); |
- | |
274 | ConfirmFrame = DubWiseKeys[3]; |
- | |
275 | PcZugriff = 255; |
313 | break; |
276 | break; |
314 | case 'v': // Version-Anforderung und Ausbaustufe |
277 | case 'v': // Version-Anforderung und Ausbaustufe |
315 | GetVersionAnforderung = 1; |
278 | GetVersionAnforderung = 1; |
- | |
279 | break; |
- | |
280 | case 'g':// |
316 | break; |
- | 317 | case 'g':// |
|
- | 318 | GetExternalControl = 1; |
|
- | 319 | break; |
|
- | 320 | case 'p': // get PPM Channels |
|
281 | GetExternalControl = 1; |
321 | GetPPMChannelAnforderung = 1; |
282 | break; |
322 | break; |
283 | case 'q':// "Get"-Anforderung für Settings |
323 | case 't':// "Get"-Anforderung für Settings |
- | 324 | // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
|
- | 325 | if(pRxData[0] == 0xFF) |
|
284 | // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
326 | { |
285 | Decode64((unsigned char *) &tmp_char_arr2[0],sizeof(tmp_char_arr2),3,AnzahlEmpfangsBytes); |
- | |
286 | while(!UebertragungAbgeschlossen); |
- | |
287 | if(tmp_char_arr2[0] != 0xff) |
- | |
288 | { |
- | |
289 | if(tmp_char_arr2[0] > 5) tmp_char_arr2[0] = 5; |
- | |
290 | ReadParameterSet(tmp_char_arr2[0], (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
327 | pRxData[0] = GetActiveParamSetNumber(); |
- | 328 | } |
|
- | 329 | else // request active parameter set |
|
291 | SendOutData('L' + tmp_char_arr2[0] -1,MeineSlaveAdresse,(unsigned char *) &EE_Parameter.Kanalbelegung[0],STRUCT_PARAM_LAENGE); |
330 | { |
292 | } |
331 | if(pRxData[0] < 1) pRxData[0] = 1; // limit to 5 |
293 | else |
332 | else if(pRxData[0] > 5) pRxData[0] = 5; // limit to 5 |
294 | SendOutData('L' + GetActiveParamSetNumber()-1,MeineSlaveAdresse,(unsigned char *) &EE_Parameter.Kanalbelegung[0],STRUCT_PARAM_LAENGE); |
333 | // load requested parameter set |
295 | 334 | ReadParameterSet(pRxData[0], (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
|
296 | break; |
335 | } |
- | 336 | while(!UebertragungAbgeschlossen); |
|
- | 337 | SendOutData('T', MeineSlaveAdresse, 2, &pRxData[0], sizeof(unsigned char), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
|
- | 338 | break; |
|
297 | 339 | case 's': // Parametersatz speichern |
|
- | 340 | if((1 <= pRxData[0]) && (pRxData[0] <= 5)) // check for setting to be in range |
|
298 | case 'l': |
341 | { |
299 | case 'm': |
342 | memcpy((unsigned char *) &EE_Parameter.Kanalbelegung[0], (unsigned char *)&pRxData[1], STRUCT_PARAM_LAENGE); |
300 | case 'n': |
343 | WriteParameterSet(pRxData[0], (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
- | 344 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], RxdBuffer[2] - 'l' + 1); // aktiven Datensatz merken |
|
- | 345 | Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L; |
|
301 | case 'o': |
346 | Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L; |
Line 302... | Line 347... | ||
302 | case 'p': // Parametersatz speichern |
347 | Piep(GetActiveParamSetNumber()); |
303 | Decode64((unsigned char *) &EE_Parameter.Kanalbelegung[0],STRUCT_PARAM_LAENGE,3,AnzahlEmpfangsBytes); |
348 | while(!UebertragungAbgeschlossen); |
304 | WriteParameterSet(RxdBuffer[2] - 'l' + 1, (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
349 | SendOutData('S', MeineSlaveAdresse, 1, &pRxData[0], sizeof(unsigned char)); |
Line 354... | Line 399... | ||
354 | UBRR=(SYSCLK / (BAUD_RATE * 8L) - 1); |
399 | UBRR=(SYSCLK / (BAUD_RATE * 8L) - 1); |
355 | //UBRR = 33; |
400 | //UBRR = 33; |
356 | //öffnet einen Kanal für printf (STDOUT) |
401 | //öffnet einen Kanal für printf (STDOUT) |
357 | //fdevopen (uart_putchar, 0); |
402 | //fdevopen (uart_putchar, 0); |
358 | //sbi(PORTD,4); |
403 | //sbi(PORTD,4); |
359 | Debug_Timer = SetDelay(200); |
404 | Debug_Timer = SetDelay(DebugDataIntervall); |
360 | Kompass_Timer = SetDelay(220); |
405 | Kompass_Timer = SetDelay(220); |
361 | MeineSlaveAdresse = 1; // Flight-Ctrl |
406 | MeineSlaveAdresse = 1; // Flight-Ctrl |
- | 407 | ||
- | 408 | VersionInfo.Major = VERSION_MAJOR; |
|
- | 409 | VersionInfo.Minor = VERSION_MINOR; |
|
- | 410 | VersionInfo.Patch = VERSION_PATCH; |
|
- | 411 | VersionInfo.Compatible = VERSION_SERIAL_COMPATIBLE; |
|
- | 412 | ||
- | 413 | pRxData = 0; |
|
- | 414 | RxDataLen = 0; |
|
362 | } |
415 | } |
Line 363... | Line 416... | ||
363 | 416 | ||
364 | //--------------------------------------------------------------------------------------------- |
417 | //--------------------------------------------------------------------------------------------- |
365 | void DatenUebertragung(void) |
418 | void DatenUebertragung(void) |
366 | { |
419 | { |
Line 367... | Line 420... | ||
367 | if(!UebertragungAbgeschlossen) return; |
420 | if(!UebertragungAbgeschlossen) return; |
368 | 421 | ||
369 | if(GetExternalControl && UebertragungAbgeschlossen) // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
422 | if(GetExternalControl && UebertragungAbgeschlossen) // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
370 | { |
423 | { |
371 | SendOutData('G',MeineSlaveAdresse,(unsigned char *) &ExternControl,sizeof(ExternControl)); |
424 | SendOutData('G',MeineSlaveAdresse, 1, (unsigned char *) &ExternControl, sizeof(ExternControl)); |
Line 372... | Line 425... | ||
372 | GetExternalControl = 0; |
425 | GetExternalControl = 0; |
373 | } |
426 | } |
374 | 427 | ||
375 | if((CheckDelay(Kompass_Timer)) && UebertragungAbgeschlossen) |
428 | if((CheckDelay(Kompass_Timer)) && UebertragungAbgeschlossen) |
376 | { |
429 | { |
377 | WinkelOut.Winkel[0] = (int) (IntegralNick / 108); // etwa in 0,1 Grad |
430 | WinkelOut.Winkel[0] = (int) (IntegralNick / 108); // etwa in 0,1 Grad |
378 | WinkelOut.Winkel[1] = (int) (IntegralRoll / 108); // etwa in 0,1 Grad |
431 | WinkelOut.Winkel[1] = (int) (IntegralRoll / 108); // etwa in 0,1 Grad |
379 | WinkelOut.UserParameter[0] = Parameter_UserParam1; |
432 | WinkelOut.UserParameter[0] = Parameter_UserParam1; |
380 | WinkelOut.UserParameter[1] = Parameter_UserParam2; |
433 | WinkelOut.UserParameter[1] = Parameter_UserParam2; |
381 | SendOutData('w',MeineSlaveAdresse,(unsigned char *) &WinkelOut,sizeof(WinkelOut)); |
434 | SendOutData('k',MeineSlaveAdresse, 1, (unsigned char *) &WinkelOut,sizeof(WinkelOut)); |
382 | if(WinkelOut.CalcState > 4) WinkelOut.CalcState = 6; // wird dann in SPI auf Null gesetzt |
435 | if(WinkelOut.CalcState > 4) WinkelOut.CalcState = 6; // wird dann in SPI auf Null gesetzt |
383 | Kompass_Timer = SetDelay(99); |
436 | Kompass_Timer = SetDelay(99); |
384 | } |
437 | } |
385 | if((CheckDelay(Debug_Timer) || DebugDataAnforderung) && UebertragungAbgeschlossen) |
438 | if((( DebugDataIntervall && CheckDelay(Debug_Timer)) || DebugDataAnforderung) && UebertragungAbgeschlossen) |
386 | { |
439 | { |
387 | SendOutData('D',MeineSlaveAdresse,(unsigned char *) &DebugOut,sizeof(DebugOut)); |
440 | SendOutData('D',MeineSlaveAdresse, 1, (unsigned char *) &DebugOut,sizeof(DebugOut)); |
388 | DebugDataAnforderung = 0; |
441 | DebugDataAnforderung = 0; |
389 | Debug_Timer = SetDelay(MIN_DEBUG_INTERVALL); |
442 | if(DebugDataIntervall) Debug_Timer = SetDelay(DebugDataIntervall); |
390 | } |
443 | } |
391 | if(DebugTextAnforderung != 255) // Texte für die Analogdaten |
444 | if(DebugTextAnforderung != 255) // Texte für die Analogdaten |
392 | { |
445 | { |
393 | SendOutData('A',DebugTextAnforderung + '0',(unsigned char *) ANALOG_TEXT[DebugTextAnforderung],16); |
446 | SendOutData('A', MeineSlaveAdresse, 2, (unsigned char *)&DebugTextAnforderung, sizeof(DebugTextAnforderung),(unsigned char *) ANALOG_TEXT[DebugTextAnforderung], 16); |
394 | DebugTextAnforderung = 255; |
447 | DebugTextAnforderung = 255; |
395 | } |
- | |
396 | if(ConfirmFrame && UebertragungAbgeschlossen) // Datensatz ohne CRC bestätigen |
448 | } |
397 | { |
- | |
398 | SendeBuffer[0] = '#'; |
- | |
399 | SendeBuffer[1] = ConfirmFrame; |
449 | if(ConfirmFrame && UebertragungAbgeschlossen) // Datensatz bestätigen |
400 | SendeBuffer[2] = '\r'; |
- | |
401 | UebertragungAbgeschlossen = 0; |
450 | { |
402 | ConfirmFrame = 0; |
451 | SendOutData('B', MeineSlaveAdresse, 1, (uint8_t*)&ConfirmFrame, sizeof(ConfirmFrame)); |
403 | UDR = SendeBuffer[0]; |
452 | ConfirmFrame = 0; |
404 | } |
453 | } |
- | 454 | if(DebugDisplayAnforderung && UebertragungAbgeschlossen) |
|
405 | if(DebugDisplayAnforderung && UebertragungAbgeschlossen) |
455 | { |
406 | { |
- | |
407 | Menu(); |
- | |
408 | DebugDisplayAnforderung = 0; |
- | |
409 | if(++RemotePollDisplayLine == 4 || NurKanalAnforderung) |
- | |
410 | { |
- | |
411 | SendOutData('4',0,(unsigned char *)&PPM_in,sizeof(PPM_in)); // DisplayZeile übertragen |
- | |
412 | RemotePollDisplayLine = -1; |
456 | Menu(); |
413 | } |
457 | SendOutData('L',MeineSlaveAdresse, 3, &MenuePunkt, sizeof(MenuePunkt), &MaxMenue, sizeof(MaxMenue), DisplayBuff, sizeof(DisplayBuff)); |
414 | else SendOutData('0' + RemotePollDisplayLine,0,(unsigned char *)&DisplayBuff[20 * RemotePollDisplayLine],20); // DisplayZeile übertragen |
458 | DebugDisplayAnforderung = 0; |
415 | } |
459 | } |
416 | if(GetVersionAnforderung && UebertragungAbgeschlossen) |
460 | if(GetVersionAnforderung && UebertragungAbgeschlossen) |
417 | { |
461 | { |
- | 462 | SendOutData('V',MeineSlaveAdresse, 1, (unsigned char *) &VersionInfo, sizeof(VersionInfo)); |
|
- | 463 | GetVersionAnforderung = 0; |
|
- | 464 | } |
|
- | 465 | if(GetPPMChannelAnforderung && UebertragungAbgeschlossen) |
|
- | 466 | { |
|
Line 418... | Line 467... | ||
418 | SendOutData('V',MeineSlaveAdresse,(unsigned char *) &VersionInfo,sizeof(VersionInfo)); |
467 | SendOutData('P',MeineSlaveAdresse, 1, (unsigned char *) &PPM_in, sizeof(PPM_in)); |