Rev 1038 | Rev 1053 | Go to most recent revision | Show entire file | Ignore 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] = |
38 | { |
40 | { |
39 | //1234567890123456 |
41 | //1234567890123456 |
40 | "IntegralNick ", //0 |
42 | "IntegralNick ", //0 |
41 | "IntegralRoll ", |
43 | "IntegralRoll ", |
42 | "AccNick ", |
44 | "AccNick ", |
43 | "AccRoll ", |
45 | "AccRoll ", |
44 | "GyroGier ", |
46 | "GyroGier ", |
Line 78... | Line 80... | ||
78 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
80 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
79 | SIGNAL(INT_VEC_TX) |
81 | SIGNAL(INT_VEC_TX) |
80 | { |
82 | { |
81 | static unsigned int ptr = 0; |
83 | static unsigned int ptr = 0; |
82 | unsigned char tmp_tx; |
84 | unsigned char tmp_tx; |
83 | if(!UebertragungAbgeschlossen) |
85 | if(!UebertragungAbgeschlossen) |
84 | { |
86 | { |
85 | ptr++; // die [0] wurde schon gesendet |
87 | ptr++; // die [0] wurde schon gesendet |
86 | tmp_tx = SendeBuffer[ptr]; |
88 | tmp_tx = SendeBuffer[ptr]; |
87 | if((tmp_tx == '\r') || (ptr == MAX_SENDE_BUFF)) |
89 | if((tmp_tx == '\r') || (ptr == MAX_SENDE_BUFF)) |
88 | { |
90 | { |
89 | ptr = 0; |
91 | ptr = 0; |
90 | UebertragungAbgeschlossen = 1; |
92 | UebertragungAbgeschlossen = 1; |
91 | } |
93 | } |
92 | UDR = tmp_tx; |
94 | UDR = tmp_tx; |
93 | } |
95 | } |
94 | else ptr = 0; |
96 | else ptr = 0; |
95 | } |
97 | } |
Line 96... | Line 98... | ||
96 | 98 | ||
97 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
99 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
Line 102... | Line 104... | ||
102 | static unsigned int crc; |
104 | static unsigned int crc; |
103 | static unsigned char crc1,crc2,buf_ptr; |
105 | static unsigned char crc1,crc2,buf_ptr; |
104 | static unsigned char UartState = 0; |
106 | static unsigned char UartState = 0; |
105 | unsigned char CrcOkay = 0; |
107 | unsigned char CrcOkay = 0; |
Line 106... | Line 108... | ||
106 | 108 | ||
107 | SioTmp = UDR; |
109 | SioTmp = UDR; |
108 | if(buf_ptr >= MAX_EMPFANGS_BUFF) UartState = 0; |
110 | if(buf_ptr >= MAX_EMPFANGS_BUFF) UartState = 0; |
109 | if(SioTmp == '\r' && UartState == 2) |
111 | if(SioTmp == '\r' && UartState == 2) |
110 | { |
112 | { |
111 | UartState = 0; |
113 | UartState = 0; |
112 | crc -= RxdBuffer[buf_ptr-2]; |
114 | crc -= RxdBuffer[buf_ptr-2]; |
113 | crc -= RxdBuffer[buf_ptr-1]; |
115 | crc -= RxdBuffer[buf_ptr-1]; |
Line 116... | Line 118... | ||
116 | crc2 = '=' + crc % 64; |
118 | crc2 = '=' + crc % 64; |
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 |
128 | switch(UartState) |
130 | switch(UartState) |
129 | { |
131 | { |
130 | case 0: |
132 | case 0: |
Line 138... | Line 140... | ||
138 | RxdBuffer[buf_ptr++] = SioTmp; |
140 | RxdBuffer[buf_ptr++] = SioTmp; |
139 | crc += SioTmp; |
141 | crc += SioTmp; |
140 | break; |
142 | break; |
141 | case 2: // Eingangsdaten sammeln |
143 | case 2: // Eingangsdaten sammeln |
142 | RxdBuffer[buf_ptr] = SioTmp; |
144 | RxdBuffer[buf_ptr] = SioTmp; |
143 | if(buf_ptr < MAX_EMPFANGS_BUFF) buf_ptr++; |
145 | if(buf_ptr < MAX_EMPFANGS_BUFF) buf_ptr++; |
144 | else UartState = 0; |
146 | else UartState = 0; |
145 | crc += SioTmp; |
147 | crc += SioTmp; |
146 | break; |
148 | break; |
147 | default: |
149 | default: |
148 | UartState = 0; |
150 | UartState = 0; |
149 | break; |
151 | break; |
150 | } |
152 | } |
151 | } |
153 | } |
Line 152... | Line 154... | ||
152 | 154 | ||
153 | 155 | ||
154 | // -------------------------------------------------------------------------- |
156 | // -------------------------------------------------------------------------- |
155 | void AddCRC(unsigned int wieviele) |
157 | void AddCRC(unsigned int wieviele) |
156 | { |
158 | { |
157 | unsigned int tmpCRC = 0,i; |
159 | unsigned int tmpCRC = 0,i; |
158 | for(i = 0; i < wieviele;i++) |
160 | for(i = 0; i < wieviele;i++) |
159 | { |
161 | { |
160 | tmpCRC += SendeBuffer[i]; |
162 | tmpCRC += SendeBuffer[i]; |
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); |
285 | { |
238 | KompassValue = tmp_int_arr1[0]; |
286 | case 'K':// Kompasswert |
239 | KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180; |
287 | memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue)); |
240 | break; |
- | |
241 | case 'a':// Texte der Analogwerte |
- | |
242 | Decode64((unsigned char *) &tmp_char_arr2[0],sizeof(tmp_char_arr2),3,AnzahlEmpfangsBytes); |
288 | KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180; |
243 | DebugTextAnforderung = tmp_char_arr2[0]; |
289 | break; |
244 | PcZugriff = 255; |
290 | case 'a':// Texte der Analogwerte |
245 | break; |
- | |
246 | case 'b': |
291 | DebugTextAnforderung = pRxData[0]; |
247 | Decode64((unsigned char *) &ExternControl,sizeof(ExternControl),3,AnzahlEmpfangsBytes); |
- | |
248 | RemoteTasten |= ExternControl.RemoteTasten; |
- | |
249 | ConfirmFrame = ExternControl.Frame; |
- | |
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; |
- | 313 | break; |
|
- | 314 | case 'v': // Version-Anforderung und Ausbaustufe |
|
- | 315 | GetVersionAnforderung = 1; |
|
- | 316 | break; |
|
- | 317 | case 'g':// |
|
- | 318 | GetExternalControl = 1; |
|
- | 319 | break; |
|
- | 320 | case 'p': // get PPM Channels |
|
- | 321 | GetPPMChannelAnforderung = 1; |
|
273 | Decode64((unsigned char *) &DubWiseKeys[0],sizeof(DubWiseKeys),3,AnzahlEmpfangsBytes); |
322 | break; |
- | 323 | case 't':// "Get"-Anforderung für Settings |
|
274 | ConfirmFrame = DubWiseKeys[3]; |
324 | // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
275 | PcZugriff = 255; |
- | |
276 | break; |
- | |
277 | case 'v': // Version-Anforderung und Ausbaustufe |
- | |
278 | GetVersionAnforderung = 1; |
- | |
279 | break; |
- | |
280 | case 'g':// |
- | |
281 | GetExternalControl = 1; |
- | |
282 | break; |
325 | if(pRxData[0] == 0xFF) |
283 | case 'q':// "Get"-Anforderung für Settings |
- | |
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 321... | Line 366... | ||
321 | uart_putchar('\r'); |
366 | uart_putchar('\r'); |
322 | //Warten solange bis Zeichen gesendet wurde |
367 | //Warten solange bis Zeichen gesendet wurde |
323 | loop_until_bit_is_set(USR, UDRE); |
368 | loop_until_bit_is_set(USR, UDRE); |
324 | //Ausgabe des Zeichens |
369 | //Ausgabe des Zeichens |
325 | UDR = c; |
370 | UDR = c; |
326 | 371 | ||
327 | return (0); |
372 | return (0); |
328 | } |
373 | } |
Line 329... | Line 374... | ||
329 | 374 | ||
330 | // -------------------------------------------------------------------------- |
375 | // -------------------------------------------------------------------------- |
Line 342... | Line 387... | ||
342 | { |
387 | { |
343 | //Enable TXEN im Register UCR TX-Data Enable & RX Enable |
388 | //Enable TXEN im Register UCR TX-Data Enable & RX Enable |
Line 344... | Line 389... | ||
344 | 389 | ||
345 | UCR=(1 << TXEN) | (1 << RXEN); |
390 | UCR=(1 << TXEN) | (1 << RXEN); |
346 | // UART Double Speed (U2X) |
391 | // UART Double Speed (U2X) |
347 | USR |= (1<<U2X); |
392 | USR |= (1<<U2X); |
348 | // RX-Interrupt Freigabe |
393 | // RX-Interrupt Freigabe |
349 | UCSRB |= (1<<RXCIE); |
394 | UCSRB |= (1<<RXCIE); |
350 | // TX-Interrupt Freigabe |
395 | // TX-Interrupt Freigabe |
Line 351... | Line 396... | ||
351 | UCSRB |= (1<<TXCIE); |
396 | UCSRB |= (1<<TXCIE); |
352 | 397 | ||
353 | //Teiler wird gesetzt |
398 | //Teiler wird gesetzt |
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); |
- | 405 | Kompass_Timer = SetDelay(220); |
|
- | 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 | ||
360 | Kompass_Timer = SetDelay(220); |
413 | pRxData = 0; |
Line 361... | Line 414... | ||
361 | MeineSlaveAdresse = 1; // Flight-Ctrl |
414 | RxDataLen = 0; |
362 | } |
415 | } |
363 | 416 | ||
364 | //--------------------------------------------------------------------------------------------- |
417 | //--------------------------------------------------------------------------------------------- |
Line 365... | Line 418... | ||
365 | void DatenUebertragung(void) |
418 | void DatenUebertragung(void) |
366 | { |
419 | { |
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 |
Line 370... | Line 423... | ||
370 | { |
423 | { |
371 | SendOutData('G',MeineSlaveAdresse,(unsigned char *) &ExternControl,sizeof(ExternControl)); |
424 | SendOutData('G',MeineSlaveAdresse, 1, (unsigned char *) &ExternControl, sizeof(ExternControl)); |
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); |
- | |
394 | DebugTextAnforderung = 255; |
446 | SendOutData('A', MeineSlaveAdresse, 2, (unsigned char *)&DebugTextAnforderung, sizeof(DebugTextAnforderung),(unsigned char *) ANALOG_TEXT[DebugTextAnforderung], 16); |
395 | } |
- | |
396 | if(ConfirmFrame && UebertragungAbgeschlossen) // Datensatz ohne CRC bestätigen |
- | |
397 | { |
447 | DebugTextAnforderung = 255; |
398 | SendeBuffer[0] = '#'; |
- | |
399 | SendeBuffer[1] = ConfirmFrame; |
448 | } |
400 | SendeBuffer[2] = '\r'; |
449 | if(ConfirmFrame && UebertragungAbgeschlossen) // Datensatz bestätigen |
401 | UebertragungAbgeschlossen = 0; |
450 | { |
402 | ConfirmFrame = 0; |
451 | SendOutData('B', MeineSlaveAdresse, 1, (uint8_t*)&ConfirmFrame, sizeof(ConfirmFrame)); |
- | 452 | ConfirmFrame = 0; |
|
403 | UDR = SendeBuffer[0]; |
453 | } |
404 | } |
- | |
405 | if(DebugDisplayAnforderung && UebertragungAbgeschlossen) |
- | |
406 | { |
- | |
407 | Menu(); |
- | |
408 | DebugDisplayAnforderung = 0; |
- | |
409 | if(++RemotePollDisplayLine == 4 || NurKanalAnforderung) |
- | |
410 | { |
454 | if(DebugDisplayAnforderung && UebertragungAbgeschlossen) |
411 | SendOutData('4',0,(unsigned char *)&PPM_in,sizeof(PPM_in)); // DisplayZeile übertragen |
455 | { |
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 | } |
- | 460 | if(GetVersionAnforderung && UebertragungAbgeschlossen) |
|
- | 461 | { |
|
- | 462 | SendOutData('V',MeineSlaveAdresse, 1, (unsigned char *) &VersionInfo, sizeof(VersionInfo)); |
|
- | 463 | GetVersionAnforderung = 0; |
|
- | 464 | } |
|
Line 416... | Line 465... | ||
416 | if(GetVersionAnforderung && UebertragungAbgeschlossen) |
465 | if(GetPPMChannelAnforderung && UebertragungAbgeschlossen) |