Rev 1441 | Rev 1490 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1441 | Rev 1444 | ||
---|---|---|---|
1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 | // + Copyright (c) Holger Buss, Ingo Busker |
2 | // + Copyright (c) Holger Buss, Ingo Busker |
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 | #include <stdarg.h> |
7 | #include <stdarg.h> |
8 | #include <string.h> |
8 | #include <string.h> |
9 | #include "main.h" |
9 | #include "main.h" |
10 | #include "uart.h" |
10 | #include "uart.h" |
11 | #include "libfc.h" |
11 | #include "libfc.h" |
12 | 12 | ||
13 | 13 | ||
14 | #define FC_ADDRESS 1 |
14 | #define FC_ADDRESS 1 |
15 | #define NC_ADDRESS 2 |
15 | #define NC_ADDRESS 2 |
16 | #define MK3MAG_ADDRESS 3 |
16 | #define MK3MAG_ADDRESS 3 |
17 | 17 | ||
18 | #define ABO_TIMEOUT 4000 // disable abo after 4 seconds |
18 | #define ABO_TIMEOUT 4000 // disable abo after 4 seconds |
19 | #define MAX_SENDE_BUFF 160 |
19 | #define MAX_SENDE_BUFF 160 |
20 | #define MAX_EMPFANGS_BUFF 160 |
20 | #define MAX_EMPFANGS_BUFF 160 |
21 | unsigned char GetExternalControl = 0,DebugDisplayAnforderung1 = 0, DebugDisplayAnforderung = 0,DebugDataAnforderung = 0,GetVersionAnforderung = 0, GetPPMChannelAnforderung = 0; |
21 | unsigned char GetExternalControl = 0,DebugDisplayAnforderung1 = 0, DebugDisplayAnforderung = 0,DebugDataAnforderung = 0,GetVersionAnforderung = 0, GetPPMChannelAnforderung = 0; |
22 | unsigned char DisplayLine = 0; |
22 | unsigned char DisplayLine = 0; |
23 | unsigned volatile char SioTmp = 0; |
23 | unsigned volatile char SioTmp = 0; |
24 | unsigned volatile char NeuerDatensatzEmpfangen = 0; |
24 | unsigned volatile char NeuerDatensatzEmpfangen = 0; |
25 | unsigned volatile char NeueKoordinateEmpfangen = 0; |
25 | unsigned volatile char NeueKoordinateEmpfangen = 0; |
26 | unsigned volatile char UebertragungAbgeschlossen = 1; |
26 | unsigned volatile char UebertragungAbgeschlossen = 1; |
27 | unsigned volatile char CntCrcError = 0; |
27 | unsigned volatile char CntCrcError = 0; |
28 | unsigned volatile char AnzahlEmpfangsBytes = 0; |
28 | unsigned volatile char AnzahlEmpfangsBytes = 0; |
29 | unsigned volatile char TxdBuffer[MAX_SENDE_BUFF]; |
29 | unsigned volatile char TxdBuffer[MAX_SENDE_BUFF]; |
30 | unsigned volatile char RxdBuffer[MAX_EMPFANGS_BUFF]; |
30 | unsigned volatile char RxdBuffer[MAX_EMPFANGS_BUFF]; |
31 | 31 | ||
32 | unsigned char *pRxData = 0; |
32 | unsigned char *pRxData = 0; |
33 | unsigned char RxDataLen = 0; |
33 | unsigned char RxDataLen = 0; |
34 | unsigned volatile char PC_DebugTimeout = 0; |
34 | unsigned volatile char PC_DebugTimeout = 0; |
35 | unsigned volatile char PC_MotortestActive = 0; |
35 | unsigned volatile char PC_MotortestActive = 0; |
36 | 36 | ||
37 | unsigned char DebugTextAnforderung = 255; |
37 | unsigned char DebugTextAnforderung = 255; |
38 | unsigned char PcZugriff = 100; |
38 | unsigned char PcZugriff = 100; |
39 | unsigned char MotorTest[16]; |
39 | unsigned char MotorTest[16]; |
40 | unsigned char MeineSlaveAdresse = 1; // Flight-Ctrl |
40 | unsigned char MeineSlaveAdresse = 1; // Flight-Ctrl |
41 | unsigned char ConfirmFrame; |
41 | unsigned char ConfirmFrame; |
42 | struct str_DebugOut DebugOut; |
42 | struct str_DebugOut DebugOut; |
43 | struct str_ExternControl ExternControl; |
43 | struct str_ExternControl ExternControl; |
44 | struct str_VersionInfo VersionInfo; |
44 | struct str_VersionInfo VersionInfo; |
45 | struct str_WinkelOut WinkelOut; |
45 | struct str_WinkelOut WinkelOut; |
46 | struct str_Data3D Data3D; |
46 | struct str_Data3D Data3D; |
47 | 47 | ||
48 | int Display_Timer, Debug_Timer,Kompass_Timer,Timer3D; |
48 | int Display_Timer, Debug_Timer,Kompass_Timer,Timer3D; |
49 | unsigned int DebugDataIntervall = 0, Intervall3D = 0, Display_Interval = 0; |
49 | unsigned int DebugDataIntervall = 0, Intervall3D = 0, Display_Interval = 0; |
50 | unsigned int AboTimeOut = 0; |
50 | unsigned int AboTimeOut = 0; |
51 | 51 | ||
52 | const unsigned char ANALOG_TEXT[32][16] = |
52 | const unsigned char ANALOG_TEXT[32][16] = |
53 | { |
53 | { |
54 | //1234567890123456 |
54 | //1234567890123456 |
55 | "AngleNick ", //0 |
55 | "AngleNick ", //0 |
56 | "AngleRoll ", |
56 | "AngleRoll ", |
57 | "AccNick ", |
57 | "AccNick ", |
58 | "AccRoll ", |
58 | "AccRoll ", |
59 | "GyroGier ", |
59 | "GyroGier ", |
60 | "Hight Value ", //5 |
60 | "Hight Value ", //5 |
61 | "AccZ ", |
61 | "AccZ ", |
62 | "Gas ", |
62 | "Gas ", |
63 | "Compass Value ", |
63 | "Compass Value ", |
64 | "Voltage ", |
64 | "Voltage ", |
65 | "Empfang ", //10 |
65 | "Empfang ", //10 |
66 | "Gyro Kompass ", |
66 | "Gyro Kompass ", |
67 | "Motor Front ", |
67 | "Motor Front ", |
68 | "Motor Rear ", |
68 | "Motor Rear ", |
69 | "Motor Left ", |
69 | "Motor Left ", |
70 | "Motor Right ", //15 |
70 | "Motor Right ", //15 |
71 | " ", |
71 | " ", |
72 | " ", |
72 | " ", |
73 | "VarioMeter ", |
73 | "VarioMeter ", |
74 | "MK3Mag CalState ", |
74 | "MK3Mag CalState ", |
75 | "Servo ", //20 |
75 | "Servo ", //20 |
76 | "Hoovergas ", |
76 | "Hoovergas ", |
77 | " ", |
77 | " ", |
78 | " ", |
78 | " ", |
79 | " ", |
79 | " ", |
80 | " ", //25 |
80 | " ", //25 |
81 | " ", |
81 | " ", |
82 | " ", |
82 | " ", |
83 | "I2C-Error ", |
83 | "I2C-Error ", |
84 | " ",// "Navi Serial Data", |
84 | " ",// "Navi Serial Data", |
85 | "GPS_Nick ", //30 |
85 | "GPS_Nick ", //30 |
86 | "GPS_Roll " |
86 | "GPS_Roll " |
87 | }; |
87 | }; |
88 | 88 | ||
89 | 89 | ||
90 | 90 | ||
91 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
91 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
92 | //++ Sende-Part der Datenübertragung |
92 | //++ Sende-Part der Datenübertragung |
93 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
93 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
94 | SIGNAL(INT_VEC_TX) |
94 | SIGNAL(INT_VEC_TX) |
95 | { |
95 | { |
96 | static unsigned int ptr = 0; |
96 | static unsigned int ptr = 0; |
97 | unsigned char tmp_tx; |
97 | unsigned char tmp_tx; |
98 | if(!UebertragungAbgeschlossen) |
98 | if(!UebertragungAbgeschlossen) |
99 | { |
99 | { |
100 | ptr++; // die [0] wurde schon gesendet |
100 | ptr++; // die [0] wurde schon gesendet |
101 | tmp_tx = TxdBuffer[ptr]; |
101 | tmp_tx = TxdBuffer[ptr]; |
102 | if((tmp_tx == '\r') || (ptr == MAX_SENDE_BUFF)) |
102 | if((tmp_tx == '\r') || (ptr == MAX_SENDE_BUFF)) |
103 | { |
103 | { |
104 | ptr = 0; |
104 | ptr = 0; |
105 | UebertragungAbgeschlossen = 1; |
105 | UebertragungAbgeschlossen = 1; |
106 | } |
106 | } |
107 | UDR = tmp_tx; |
107 | UDR = tmp_tx; |
108 | } |
108 | } |
109 | else ptr = 0; |
109 | else ptr = 0; |
110 | } |
110 | } |
111 | 111 | ||
112 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
112 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
113 | //++ Empfangs-Part der Datenübertragung, incl. CRC-Auswertung |
113 | //++ Empfangs-Part der Datenübertragung, incl. CRC-Auswertung |
114 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
114 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
115 | SIGNAL(INT_VEC_RX) |
115 | SIGNAL(INT_VEC_RX) |
116 | { |
116 | { |
117 | static unsigned int crc; |
117 | static unsigned int crc; |
118 | static unsigned char crc1,crc2,buf_ptr; |
118 | static unsigned char crc1,crc2,buf_ptr; |
119 | static unsigned char UartState = 0; |
119 | static unsigned char UartState = 0; |
120 | unsigned char CrcOkay = 0; |
120 | unsigned char CrcOkay = 0; |
121 | 121 | ||
122 | SioTmp = UDR; |
122 | SioTmp = UDR; |
123 | if(buf_ptr >= MAX_SENDE_BUFF) UartState = 0; |
123 | if(buf_ptr >= MAX_SENDE_BUFF) UartState = 0; |
124 | if(SioTmp == '\r' && UartState == 2) |
124 | if(SioTmp == '\r' && UartState == 2) |
125 | { |
125 | { |
126 | UartState = 0; |
126 | UartState = 0; |
127 | crc -= RxdBuffer[buf_ptr-2]; |
127 | crc -= RxdBuffer[buf_ptr-2]; |
128 | crc -= RxdBuffer[buf_ptr-1]; |
128 | crc -= RxdBuffer[buf_ptr-1]; |
129 | crc %= 4096; |
129 | crc %= 4096; |
130 | crc1 = '=' + crc / 64; |
130 | crc1 = '=' + crc / 64; |
131 | crc2 = '=' + crc % 64; |
131 | crc2 = '=' + crc % 64; |
132 | CrcOkay = 0; |
132 | CrcOkay = 0; |
133 | if((crc1 == RxdBuffer[buf_ptr-2]) && (crc2 == RxdBuffer[buf_ptr-1])) CrcOkay = 1; else { CrcOkay = 0; CntCrcError++;}; |
133 | if((crc1 == RxdBuffer[buf_ptr-2]) && (crc2 == RxdBuffer[buf_ptr-1])) CrcOkay = 1; else { CrcOkay = 0; CntCrcError++;}; |
134 | if(!NeuerDatensatzEmpfangen && CrcOkay) // Datensatz schon verarbeitet |
134 | if(!NeuerDatensatzEmpfangen && CrcOkay) // Datensatz schon verarbeitet |
135 | { |
135 | { |
136 | NeuerDatensatzEmpfangen = 1; |
136 | NeuerDatensatzEmpfangen = 1; |
137 | AnzahlEmpfangsBytes = buf_ptr + 1; |
137 | AnzahlEmpfangsBytes = buf_ptr + 1; |
138 | RxdBuffer[buf_ptr] = '\r'; |
138 | RxdBuffer[buf_ptr] = '\r'; |
139 | if(RxdBuffer[2] == 'R') |
139 | if(RxdBuffer[2] == 'R') |
140 | { |
140 | { |
141 | LcdClear(); |
141 | LcdClear(); |
142 | wdt_enable(WDTO_250MS); // Reset-Commando |
142 | wdt_enable(WDTO_250MS); // Reset-Commando |
143 | ServoActive = 0; |
143 | ServoActive = 0; |
144 | 144 | ||
145 | } |
145 | } |
146 | } |
146 | } |
147 | } |
147 | } |
148 | else |
148 | else |
149 | switch(UartState) |
149 | switch(UartState) |
150 | { |
150 | { |
151 | case 0: |
151 | case 0: |
152 | if(SioTmp == '#' && !NeuerDatensatzEmpfangen) UartState = 1; // Startzeichen und Daten schon verarbeitet |
152 | if(SioTmp == '#' && !NeuerDatensatzEmpfangen) UartState = 1; // Startzeichen und Daten schon verarbeitet |
153 | buf_ptr = 0; |
153 | buf_ptr = 0; |
154 | RxdBuffer[buf_ptr++] = SioTmp; |
154 | RxdBuffer[buf_ptr++] = SioTmp; |
155 | crc = SioTmp; |
155 | crc = SioTmp; |
156 | break; |
156 | break; |
157 | case 1: // Adresse auswerten |
157 | case 1: // Adresse auswerten |
158 | UartState++; |
158 | UartState++; |
159 | RxdBuffer[buf_ptr++] = SioTmp; |
159 | RxdBuffer[buf_ptr++] = SioTmp; |
160 | crc += SioTmp; |
160 | crc += SioTmp; |
161 | break; |
161 | break; |
162 | case 2: // Eingangsdaten sammeln |
162 | case 2: // Eingangsdaten sammeln |
163 | RxdBuffer[buf_ptr] = SioTmp; |
163 | RxdBuffer[buf_ptr] = SioTmp; |
164 | if(buf_ptr < MAX_EMPFANGS_BUFF) buf_ptr++; |
164 | if(buf_ptr < MAX_EMPFANGS_BUFF) buf_ptr++; |
165 | else UartState = 0; |
165 | else UartState = 0; |
166 | crc += SioTmp; |
166 | crc += SioTmp; |
167 | break; |
167 | break; |
168 | default: |
168 | default: |
169 | UartState = 0; |
169 | UartState = 0; |
170 | break; |
170 | break; |
171 | } |
171 | } |
172 | } |
172 | } |
173 | 173 | ||
174 | 174 | ||
175 | // -------------------------------------------------------------------------- |
175 | // -------------------------------------------------------------------------- |
176 | void AddCRC(unsigned int wieviele) |
176 | void AddCRC(unsigned int wieviele) |
177 | { |
177 | { |
178 | unsigned int tmpCRC = 0,i; |
178 | unsigned int tmpCRC = 0,i; |
179 | for(i = 0; i < wieviele;i++) |
179 | for(i = 0; i < wieviele;i++) |
180 | { |
180 | { |
181 | tmpCRC += TxdBuffer[i]; |
181 | tmpCRC += TxdBuffer[i]; |
182 | } |
182 | } |
183 | tmpCRC %= 4096; |
183 | tmpCRC %= 4096; |
184 | TxdBuffer[i++] = '=' + tmpCRC / 64; |
184 | TxdBuffer[i++] = '=' + tmpCRC / 64; |
185 | TxdBuffer[i++] = '=' + tmpCRC % 64; |
185 | TxdBuffer[i++] = '=' + tmpCRC % 64; |
186 | TxdBuffer[i++] = '\r'; |
186 | TxdBuffer[i++] = '\r'; |
187 | UebertragungAbgeschlossen = 0; |
187 | UebertragungAbgeschlossen = 0; |
188 | UDR = TxdBuffer[0]; |
188 | UDR = TxdBuffer[0]; |
189 | } |
189 | } |
190 | 190 | ||
191 | 191 | ||
192 | 192 | ||
193 | // -------------------------------------------------------------------------- |
193 | // -------------------------------------------------------------------------- |
194 | void SendOutData(unsigned char cmd,unsigned char address, unsigned char BufferAnzahl, ...) //unsigned char *snd, unsigned char len) |
194 | void SendOutData(unsigned char cmd,unsigned char address, unsigned char BufferAnzahl, ...) //unsigned char *snd, unsigned char len) |
195 | { |
195 | { |
196 | va_list ap; |
196 | va_list ap; |
197 | unsigned int pt = 0; |
197 | unsigned int pt = 0; |
198 | unsigned char a,b,c; |
198 | unsigned char a,b,c; |
199 | unsigned char ptr = 0; |
199 | unsigned char ptr = 0; |
200 | 200 | ||
201 | unsigned char *snd = 0; |
201 | unsigned char *snd = 0; |
202 | int len = 0; |
202 | int len = 0; |
203 | 203 | ||
204 | TxdBuffer[pt++] = '#'; // Startzeichen |
204 | TxdBuffer[pt++] = '#'; // Startzeichen |
205 | TxdBuffer[pt++] = 'a' + address; // Adresse (a=0; b=1,...) |
205 | TxdBuffer[pt++] = 'a' + address; // Adresse (a=0; b=1,...) |
206 | TxdBuffer[pt++] = cmd; // Commando |
206 | TxdBuffer[pt++] = cmd; // Commando |
207 | 207 | ||
208 | va_start(ap, BufferAnzahl); |
208 | va_start(ap, BufferAnzahl); |
209 | if(BufferAnzahl) |
209 | if(BufferAnzahl) |
210 | { |
210 | { |
211 | snd = va_arg(ap, unsigned char*); |
211 | snd = va_arg(ap, unsigned char*); |
212 | len = va_arg(ap, int); |
212 | len = va_arg(ap, int); |
213 | ptr = 0; |
213 | ptr = 0; |
214 | BufferAnzahl--; |
214 | BufferAnzahl--; |
215 | } |
215 | } |
216 | while(len) |
216 | while(len) |
217 | { |
217 | { |
218 | if(len) |
218 | if(len) |
219 | { |
219 | { |
220 | a = snd[ptr++]; |
220 | a = snd[ptr++]; |
221 | len--; |
221 | len--; |
222 | if((!len) && BufferAnzahl) |
222 | if((!len) && BufferAnzahl) |
223 | { |
223 | { |
224 | snd = va_arg(ap, unsigned char*); |
224 | snd = va_arg(ap, unsigned char*); |
225 | len = va_arg(ap, int); |
225 | len = va_arg(ap, int); |
226 | ptr = 0; |
226 | ptr = 0; |
227 | BufferAnzahl--; |
227 | BufferAnzahl--; |
228 | } |
228 | } |
229 | } |
229 | } |
230 | else a = 0; |
230 | else a = 0; |
231 | if(len) |
231 | if(len) |
232 | { |
232 | { |
233 | b = snd[ptr++]; |
233 | b = snd[ptr++]; |
234 | len--; |
234 | len--; |
235 | if((!len) && BufferAnzahl) |
235 | if((!len) && BufferAnzahl) |
236 | { |
236 | { |
237 | snd = va_arg(ap, unsigned char*); |
237 | snd = va_arg(ap, unsigned char*); |
238 | len = va_arg(ap, int); |
238 | len = va_arg(ap, int); |
239 | ptr = 0; |
239 | ptr = 0; |
240 | BufferAnzahl--; |
240 | BufferAnzahl--; |
241 | } |
241 | } |
242 | } |
242 | } |
243 | else b = 0; |
243 | else b = 0; |
244 | if(len) |
244 | if(len) |
245 | { |
245 | { |
246 | c = snd[ptr++]; |
246 | c = snd[ptr++]; |
247 | len--; |
247 | len--; |
248 | if((!len) && BufferAnzahl) |
248 | if((!len) && BufferAnzahl) |
249 | { |
249 | { |
250 | snd = va_arg(ap, unsigned char*); |
250 | snd = va_arg(ap, unsigned char*); |
251 | len = va_arg(ap, int); |
251 | len = va_arg(ap, int); |
252 | ptr = 0; |
252 | ptr = 0; |
253 | BufferAnzahl--; |
253 | BufferAnzahl--; |
254 | } |
254 | } |
255 | } |
255 | } |
256 | else c = 0; |
256 | else c = 0; |
257 | TxdBuffer[pt++] = '=' + (a >> 2); |
257 | TxdBuffer[pt++] = '=' + (a >> 2); |
258 | TxdBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
258 | TxdBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
259 | TxdBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
259 | TxdBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
260 | TxdBuffer[pt++] = '=' + ( c & 0x3f); |
260 | TxdBuffer[pt++] = '=' + ( c & 0x3f); |
261 | } |
261 | } |
262 | va_end(ap); |
262 | va_end(ap); |
263 | AddCRC(pt); |
263 | AddCRC(pt); |
264 | } |
264 | } |
265 | 265 | ||
266 | // -------------------------------------------------------------------------- |
266 | // -------------------------------------------------------------------------- |
267 | void Decode64(void) // die daten werden im rx buffer dekodiert, das geht nur, weil aus 4 byte immer 3 gemacht werden. |
267 | void Decode64(void) // die daten werden im rx buffer dekodiert, das geht nur, weil aus 4 byte immer 3 gemacht werden. |
268 | { |
268 | { |
269 | unsigned char a,b,c,d; |
269 | unsigned char a,b,c,d; |
270 | unsigned char x,y,z; |
270 | unsigned char x,y,z; |
271 | unsigned char ptrIn = 3; // start at begin of data block |
271 | unsigned char ptrIn = 3; // start at begin of data block |
272 | unsigned char ptrOut = 3; |
272 | unsigned char ptrOut = 3; |
273 | 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. |
273 | 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. |
274 | 274 | ||
275 | while(len) |
275 | while(len) |
276 | { |
276 | { |
277 | a = RxdBuffer[ptrIn++] - '='; |
277 | a = RxdBuffer[ptrIn++] - '='; |
278 | b = RxdBuffer[ptrIn++] - '='; |
278 | b = RxdBuffer[ptrIn++] - '='; |
279 | c = RxdBuffer[ptrIn++] - '='; |
279 | c = RxdBuffer[ptrIn++] - '='; |
280 | d = RxdBuffer[ptrIn++] - '='; |
280 | d = RxdBuffer[ptrIn++] - '='; |
281 | 281 | ||
282 | x = (a << 2) | (b >> 4); |
282 | x = (a << 2) | (b >> 4); |
283 | y = ((b & 0x0f) << 4) | (c >> 2); |
283 | y = ((b & 0x0f) << 4) | (c >> 2); |
284 | z = ((c & 0x03) << 6) | d; |
284 | z = ((c & 0x03) << 6) | d; |
285 | 285 | ||
286 | if(len--) RxdBuffer[ptrOut++] = x; else break; |
286 | if(len--) RxdBuffer[ptrOut++] = x; else break; |
287 | if(len--) RxdBuffer[ptrOut++] = y; else break; |
287 | if(len--) RxdBuffer[ptrOut++] = y; else break; |
288 | if(len--) RxdBuffer[ptrOut++] = z; else break; |
288 | if(len--) RxdBuffer[ptrOut++] = z; else break; |
289 | } |
289 | } |
290 | pRxData = (unsigned char*)&RxdBuffer[3]; // decodierte Daten beginnen beim 4. Byte |
290 | pRxData = (unsigned char*)&RxdBuffer[3]; // decodierte Daten beginnen beim 4. Byte |
291 | RxDataLen = ptrOut - 3; // wie viele Bytes wurden dekodiert? |
291 | RxDataLen = ptrOut - 3; // wie viele Bytes wurden dekodiert? |
292 | 292 | ||
293 | } |
293 | } |
294 | 294 | ||
295 | // -------------------------------------------------------------------------- |
295 | // -------------------------------------------------------------------------- |
296 | void BearbeiteRxDaten(void) |
296 | void BearbeiteRxDaten(void) |
297 | { |
297 | { |
298 | if(!NeuerDatensatzEmpfangen) return; |
298 | if(!NeuerDatensatzEmpfangen) return; |
299 | 299 | ||
300 | unsigned char tempchar1, tempchar2; |
300 | unsigned char tempchar1, tempchar2; |
301 | Decode64(); // dekodiere datenblock im Empfangsbuffer |
301 | Decode64(); // dekodiere datenblock im Empfangsbuffer |
302 | switch(RxdBuffer[1]-'a') // check for Slave Address |
302 | switch(RxdBuffer[1]-'a') // check for Slave Address |
303 | { |
303 | { |
304 | case FC_ADDRESS: // FC special commands |
304 | case FC_ADDRESS: // FC special commands |
305 | switch(RxdBuffer[2]) |
305 | switch(RxdBuffer[2]) |
306 | { |
306 | { |
307 | case 'K':// Kompasswert |
307 | case 'K':// Kompasswert |
308 | memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue)); |
308 | memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue)); |
309 | KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180; |
309 | KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180; |
310 | break; |
310 | break; |
311 | case 't':// Motortest |
311 | case 't':// Motortest |
312 | if(AnzahlEmpfangsBytes > 20) memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest)); |
312 | if(AnzahlEmpfangsBytes > 20) memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest)); |
313 | else memcpy(&MotorTest[0], (unsigned char *)pRxData, 4); |
313 | else memcpy(&MotorTest[0], (unsigned char *)pRxData, 4); |
314 | PC_MotortestActive = 240; |
314 | PC_MotortestActive = 240; |
315 | //while(!UebertragungAbgeschlossen); |
315 | //while(!UebertragungAbgeschlossen); |
316 | //SendOutData('T', MeineSlaveAdresse, 0); |
316 | //SendOutData('T', MeineSlaveAdresse, 0); |
317 | PcZugriff = 255; |
317 | PcZugriff = 255; |
318 | break; |
318 | break; |
319 | 319 | ||
320 | case 'n':// "Get Mixer |
320 | case 'n':// "Get Mixer |
321 | while(!UebertragungAbgeschlossen); |
321 | while(!UebertragungAbgeschlossen); |
322 | SendOutData('N', FC_ADDRESS, 1, (unsigned char *) &Mixer,sizeof(Mixer)); |
322 | SendOutData('N', FC_ADDRESS, 1, (unsigned char *) &Mixer,sizeof(Mixer)); |
323 | break; |
323 | break; |
324 | 324 | ||
325 | case 'm':// "Write Mixer |
325 | case 'm':// "Write Mixer |
326 | while(!UebertragungAbgeschlossen); |
326 | while(!UebertragungAbgeschlossen); |
327 | if(pRxData[0] == MIXER_REVISION) |
327 | if(pRxData[0] == MIXER_REVISION) |
328 | { |
328 | { |
329 | memcpy(&Mixer, (unsigned char *)pRxData, sizeof(Mixer)); |
329 | memcpy(&Mixer, (unsigned char *)pRxData, sizeof(Mixer)); |
330 | eeprom_write_block(&Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer)); |
330 | eeprom_write_block(&Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer)); |
331 | tempchar1 = 1; |
331 | tempchar1 = 1; |
332 | } |
332 | } |
333 | else tempchar1 = 0; |
333 | else tempchar1 = 0; |
334 | SendOutData('M', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1)); |
334 | SendOutData('M', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1)); |
335 | break; |
335 | break; |
336 | 336 | ||
337 | case 'p': // get PPM Channels |
337 | case 'p': // get PPM Channels |
338 | GetPPMChannelAnforderung = 1; |
338 | GetPPMChannelAnforderung = 1; |
339 | PcZugriff = 255; |
339 | PcZugriff = 255; |
340 | break; |
340 | break; |
341 | 341 | ||
342 | case 'q':// "Get"-Anforderung für Settings |
342 | case 'q':// "Get"-Anforderung für Settings |
343 | // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
343 | // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
344 | if(pRxData[0] == 0xFF) |
344 | if(pRxData[0] == 0xFF) |
345 | { |
345 | { |
346 | pRxData[0] = GetActiveParamSetNumber(); |
346 | pRxData[0] = GetActiveParamSetNumber(); |
347 | } |
347 | } |
348 | // limit settings range |
348 | // limit settings range |
349 | if(pRxData[0] < 1) pRxData[0] = 1; // limit to 5 |
349 | if(pRxData[0] < 1) pRxData[0] = 1; // limit to 5 |
350 | else if(pRxData[0] > 5) pRxData[0] = 5; // limit to 5 |
350 | else if(pRxData[0] > 5) pRxData[0] = 5; // limit to 5 |
351 | // load requested parameter set |
351 | // load requested parameter set |
352 | ReadParameterSet(pRxData[0], (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
352 | ReadParameterSet(pRxData[0], (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
353 | 353 | ||
354 | while(!UebertragungAbgeschlossen); |
354 | while(!UebertragungAbgeschlossen); |
355 | tempchar1 = pRxData[0]; |
355 | tempchar1 = pRxData[0]; |
356 | tempchar2 = EE_DATENREVISION; |
356 | tempchar2 = EE_DATENREVISION; |
357 | SendOutData('Q', FC_ADDRESS, 3, &tempchar1, sizeof(tempchar1), &tempchar2, sizeof(tempchar2), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
357 | SendOutData('Q', FC_ADDRESS, 3, &tempchar1, sizeof(tempchar1), &tempchar2, sizeof(tempchar2), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
358 | break; |
358 | break; |
359 | 359 | ||
360 | case 's': // Parametersatz speichern |
360 | case 's': // Parametersatz speichern |
361 | if((1 <= pRxData[0]) && (pRxData[0] <= 5) && (pRxData[1] == EE_DATENREVISION)) // check for setting to be in range |
361 | if((1 <= pRxData[0]) && (pRxData[0] <= 5) && (pRxData[1] == EE_DATENREVISION)) // check for setting to be in range |
362 | { |
362 | { |
363 | memcpy((unsigned char *) &EE_Parameter.Kanalbelegung[0], (unsigned char *)&pRxData[2], STRUCT_PARAM_LAENGE); |
363 | memcpy((unsigned char *) &EE_Parameter.Kanalbelegung[0], (unsigned char *)&pRxData[2], STRUCT_PARAM_LAENGE); |
364 | WriteParameterSet(pRxData[0], (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
364 | WriteParameterSet(pRxData[0], (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
365 | Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L; |
365 | Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L; |
366 | Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L; |
366 | Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L; |
367 | SetActiveParamSetNumber(pRxData[0]); |
367 | SetActiveParamSetNumber(pRxData[0]); |
368 | tempchar1 = GetActiveParamSetNumber(); |
368 | tempchar1 = GetActiveParamSetNumber(); |
369 | } |
369 | } |
370 | else |
370 | else |
371 | { |
371 | { |
372 | tempchar1 = 0; // mark in response an invlid setting |
372 | tempchar1 = 0; // mark in response an invlid setting |
373 | } |
373 | } |
374 | while(!UebertragungAbgeschlossen); |
374 | while(!UebertragungAbgeschlossen); |
375 | SendOutData('S', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1)); |
375 | SendOutData('S', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1)); |
376 | if(!MotorenEin) Piep(tempchar1,110); |
376 | if(!MotorenEin) Piep(tempchar1,110); |
377 | LipoDetection(0); |
377 | LipoDetection(0); |
378 | LIBFC_ReceiverInit(); |
378 | LIBFC_ReceiverInit(); |
379 | break; |
379 | break; |
380 | case 'f': // auf anderen Parametersatz umschalten |
380 | case 'f': // auf anderen Parametersatz umschalten |
381 | if((1 <= pRxData[0]) && (pRxData[0] <= 5)) SetActiveParamSetNumber(pRxData[0]); |
381 | if((1 <= pRxData[0]) && (pRxData[0] <= 5)) SetActiveParamSetNumber(pRxData[0]); |
382 | tempchar1 = pRxData[0]; |
382 | tempchar1 = pRxData[0]; |
383 | while(!UebertragungAbgeschlossen); |
383 | while(!UebertragungAbgeschlossen); |
384 | SendOutData('F', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1)); |
384 | SendOutData('F', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1)); |
385 | if(!MotorenEin) Piep(tempchar1,110); |
385 | if(!MotorenEin) Piep(tempchar1,110); |
386 | LipoDetection(0); |
386 | LipoDetection(0); |
387 | LIBFC_ReceiverInit(); |
387 | LIBFC_ReceiverInit(); |
388 | break; |
388 | break; |
389 | case 'y':// serial Potis |
389 | case 'y':// serial Potis |
390 | PPM_in[13] = (signed char) pRxData[0]; PPM_in[14] = (signed char) pRxData[1]; PPM_in[15] = (signed char) pRxData[2]; PPM_in[16] = (signed char) pRxData[3]; |
390 | PPM_in[13] = (signed char) pRxData[0]; PPM_in[14] = (signed char) pRxData[1]; PPM_in[15] = (signed char) pRxData[2]; PPM_in[16] = (signed char) pRxData[3]; |
391 | PPM_in[17] = (signed char) pRxData[4]; PPM_in[18] = (signed char) pRxData[5]; PPM_in[19] = (signed char) pRxData[6]; PPM_in[20] = (signed char) pRxData[7]; |
391 | PPM_in[17] = (signed char) pRxData[4]; PPM_in[18] = (signed char) pRxData[5]; PPM_in[19] = (signed char) pRxData[6]; PPM_in[20] = (signed char) pRxData[7]; |
392 | PPM_in[21] = (signed char) pRxData[8]; PPM_in[22] = (signed char) pRxData[9]; PPM_in[23] = (signed char) pRxData[10]; PPM_in[24] = (signed char) pRxData[11]; |
392 | PPM_in[21] = (signed char) pRxData[8]; PPM_in[22] = (signed char) pRxData[9]; PPM_in[23] = (signed char) pRxData[10]; PPM_in[24] = (signed char) pRxData[11]; |
393 | break; |
393 | break; |
394 | 394 | ||
395 | } // case FC_ADDRESS: |
395 | } // case FC_ADDRESS: |
396 | 396 | ||
397 | default: // any Slave Address |
397 | default: // any Slave Address |
398 | 398 | ||
399 | switch(RxdBuffer[2]) |
399 | switch(RxdBuffer[2]) |
400 | { |
400 | { |
401 | // 't' comand placed here only for compatibility to BL |
401 | // 't' comand placed here only for compatibility to BL |
402 | case 't':// Motortest |
402 | case 't':// Motortest |
403 | if(AnzahlEmpfangsBytes > 20) memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest)); |
403 | if(AnzahlEmpfangsBytes > 20) memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest)); |
404 | else memcpy(&MotorTest[0], (unsigned char *)pRxData, 4); |
404 | else memcpy(&MotorTest[0], (unsigned char *)pRxData, 4); |
405 | while(!UebertragungAbgeschlossen); |
405 | while(!UebertragungAbgeschlossen); |
406 | SendOutData('T', MeineSlaveAdresse, 0); |
406 | SendOutData('T', MeineSlaveAdresse, 0); |
407 | PC_MotortestActive = 250; |
407 | PC_MotortestActive = 250; |
408 | PcZugriff = 255; |
408 | PcZugriff = 255; |
409 | break; |
409 | break; |
410 | // 'K' comand placed here only for compatibility to old MK3MAG software, that does not send the right Slave Address |
410 | // 'K' comand placed here only for compatibility to old MK3MAG software, that does not send the right Slave Address |
411 | case 'K':// Kompasswert |
411 | case 'K':// Kompasswert |
412 | memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue)); |
412 | memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue)); |
413 | KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180; |
413 | KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180; |
414 | break; |
414 | break; |
415 | case 'a':// Texte der Analogwerte |
415 | case 'a':// Texte der Analogwerte |
416 | DebugTextAnforderung = pRxData[0]; |
416 | DebugTextAnforderung = pRxData[0]; |
417 | if (DebugTextAnforderung > 31) DebugTextAnforderung = 31; |
417 | if (DebugTextAnforderung > 31) DebugTextAnforderung = 31; |
418 | PcZugriff = 255; |
418 | PcZugriff = 255; |
419 | break; |
419 | break; |
420 | case 'b': |
420 | case 'b': |
421 | memcpy((unsigned char *)&ExternControl, (unsigned char *)pRxData, sizeof(ExternControl)); |
421 | memcpy((unsigned char *)&ExternControl, (unsigned char *)pRxData, sizeof(ExternControl)); |
422 | ConfirmFrame = ExternControl.Frame; |
422 | ConfirmFrame = ExternControl.Frame; |
423 | PcZugriff = 255; |
423 | PcZugriff = 255; |
424 | break; |
424 | break; |
425 | case 'c': // Poll the 3D-Data |
425 | case 'c': // Poll the 3D-Data |
426 | if(!Intervall3D) { if(pRxData[0]) Timer3D = SetDelay(pRxData[0] * 10);} |
426 | if(!Intervall3D) { if(pRxData[0]) Timer3D = SetDelay(pRxData[0] * 10);} |
427 | Intervall3D = pRxData[0] * 10; |
427 | Intervall3D = pRxData[0] * 10; |
428 | AboTimeOut = SetDelay(ABO_TIMEOUT); |
428 | AboTimeOut = SetDelay(ABO_TIMEOUT); |
429 | break; |
429 | break; |
430 | case 'd': // Poll the debug data |
430 | case 'd': // Poll the debug data |
431 | PcZugriff = 255; |
431 | PcZugriff = 255; |
432 | DebugDataIntervall = (unsigned int)pRxData[0] * 10; |
432 | DebugDataIntervall = (unsigned int)pRxData[0] * 10; |
433 | if(DebugDataIntervall > 0) DebugDataAnforderung = 1; |
433 | if(DebugDataIntervall > 0) DebugDataAnforderung = 1; |
434 | AboTimeOut = SetDelay(ABO_TIMEOUT); |
434 | AboTimeOut = SetDelay(ABO_TIMEOUT); |
435 | break; |
435 | break; |
436 | 436 | ||
437 | case 'h':// x-1 Displayzeilen |
437 | case 'h':// x-1 Displayzeilen |
438 | PcZugriff = 255; |
438 | PcZugriff = 255; |
439 | if((pRxData[0] & 0x80) == 0x00) // old format |
439 | if((pRxData[0] & 0x80) == 0x00) // old format |
440 | { |
440 | { |
441 | DisplayLine = 2; |
441 | DisplayLine = 2; |
442 | Display_Interval = 0; |
442 | Display_Interval = 0; |
443 | } |
443 | } |
444 | else // new format |
444 | else // new format |
445 | { |
445 | { |
446 | RemoteKeys |= ~pRxData[0]; |
446 | RemoteKeys |= ~pRxData[0]; |
447 | Display_Interval = (unsigned int)pRxData[1] * 10; |
447 | Display_Interval = (unsigned int)pRxData[1] * 10; |
448 | DisplayLine = 4; |
448 | DisplayLine = 4; |
449 | AboTimeOut = SetDelay(ABO_TIMEOUT); |
449 | AboTimeOut = SetDelay(ABO_TIMEOUT); |
450 | } |
450 | } |
451 | DebugDisplayAnforderung = 1; |
451 | DebugDisplayAnforderung = 1; |
452 | break; |
452 | break; |
453 | 453 | ||
454 | case 'l':// x-1 Displayzeilen |
454 | case 'l':// x-1 Displayzeilen |
455 | PcZugriff = 255; |
455 | PcZugriff = 255; |
456 | MenuePunkt = pRxData[0]; |
456 | MenuePunkt = pRxData[0]; |
457 | DebugDisplayAnforderung1 = 1; |
457 | DebugDisplayAnforderung1 = 1; |
458 | break; |
458 | break; |
459 | case 'v': // Version-Anforderung und Ausbaustufe |
459 | case 'v': // Version-Anforderung und Ausbaustufe |
460 | GetVersionAnforderung = 1; |
460 | GetVersionAnforderung = 1; |
461 | break; |
461 | break; |
462 | 462 | ||
463 | case 'g':// |
463 | case 'g':// |
464 | GetExternalControl = 1; |
464 | GetExternalControl = 1; |
465 | break; |
465 | break; |
466 | } |
466 | } |
467 | break; // default: |
467 | break; // default: |
468 | } |
468 | } |
469 | NeuerDatensatzEmpfangen = 0; |
469 | NeuerDatensatzEmpfangen = 0; |
470 | pRxData = 0; |
470 | pRxData = 0; |
471 | RxDataLen = 0; |
471 | RxDataLen = 0; |
472 | } |
472 | } |
473 | 473 | ||
474 | //############################################################################ |
474 | //############################################################################ |
475 | //Routine für die Serielle Ausgabe |
475 | //Routine für die Serielle Ausgabe |
476 | int uart_putchar (char c) |
476 | void uart_putchar (char c) |
477 | //############################################################################ |
477 | //############################################################################ |
478 | { |
478 | { |
479 | if (c == '\n') |
- | |
480 | uart_putchar('\r'); |
479 | //if (c == '\n') uart_putchar('\r'); |
481 | //Warten solange bis Zeichen gesendet wurde |
480 | //Warten solange bis Zeichen gesendet wurde |
482 | loop_until_bit_is_set(USR, UDRE); |
481 | loop_until_bit_is_set(USR, UDRE); |
483 | //Ausgabe des Zeichens |
482 | //Ausgabe des Zeichens |
484 | UDR = c; |
483 | UDR = c; |
485 | - | ||
486 | return (0); |
- | |
487 | } |
484 | } |
488 | 485 | ||
489 | 486 | ||
490 | //############################################################################ |
487 | //############################################################################ |
491 | //INstallation der Seriellen Schnittstelle |
488 | //INstallation der Seriellen Schnittstelle |
492 | void UART_Init (void) |
489 | void UART_Init (void) |
493 | //############################################################################ |
490 | //############################################################################ |
494 | { |
491 | { |
495 | //Enable TXEN im Register UCR TX-Data Enable & RX Enable |
492 | //Enable TXEN im Register UCR TX-Data Enable & RX Enable |
496 | 493 | ||
497 | UCR=(1 << TXEN) | (1 << RXEN); |
494 | UCR=(1 << TXEN) | (1 << RXEN); |
498 | // UART Double Speed (U2X) |
495 | // UART Double Speed (U2X) |
499 | USR |= (1<<U2X); |
496 | USR |= (1<<U2X); |
500 | // RX-Interrupt Freigabe |
497 | // RX-Interrupt Freigabe |
501 | UCSRB |= (1<<RXCIE); |
498 | UCSRB |= (1<<RXCIE); |
502 | // TX-Interrupt Freigabe |
499 | // TX-Interrupt Freigabe |
503 | UCSRB |= (1<<TXCIE); |
500 | UCSRB |= (1<<TXCIE); |
504 | 501 | ||
505 | //Teiler wird gesetzt |
502 | //Teiler wird gesetzt |
506 | UBRR=(SYSCLK / (BAUD_RATE * 8L) - 1); |
503 | UBRR=(SYSCLK / (BAUD_RATE * 8L) - 1); |
507 | //UBRR = 33; |
504 | //UBRR = 33; |
508 | //öffnet einen Kanal für printf (STDOUT) |
505 | //öffnet einen Kanal für printf (STDOUT) |
509 | //fdevopen (uart_putchar, 0); |
506 | //fdevopen (uart_putchar, 0); |
510 | //sbi(PORTD,4); |
507 | //sbi(PORTD,4); |
511 | Debug_Timer = SetDelay(DebugDataIntervall); |
508 | Debug_Timer = SetDelay(DebugDataIntervall); |
512 | Kompass_Timer = SetDelay(220); |
509 | Kompass_Timer = SetDelay(220); |
513 | 510 | ||
514 | VersionInfo.SWMajor = VERSION_MAJOR; |
511 | VersionInfo.SWMajor = VERSION_MAJOR; |
515 | VersionInfo.SWMinor = VERSION_MINOR; |
512 | VersionInfo.SWMinor = VERSION_MINOR; |
516 | VersionInfo.SWPatch = VERSION_PATCH; |
513 | VersionInfo.SWPatch = VERSION_PATCH; |
517 | VersionInfo.ProtoMajor = VERSION_SERIAL_MAJOR; |
514 | VersionInfo.ProtoMajor = VERSION_SERIAL_MAJOR; |
518 | VersionInfo.ProtoMinor = VERSION_SERIAL_MINOR; |
515 | VersionInfo.ProtoMinor = VERSION_SERIAL_MINOR; |
519 | 516 | ||
520 | pRxData = 0; |
517 | pRxData = 0; |
521 | RxDataLen = 0; |
518 | RxDataLen = 0; |
522 | } |
519 | } |
523 | 520 | ||
524 | //--------------------------------------------------------------------------------------------- |
521 | //--------------------------------------------------------------------------------------------- |
525 | void DatenUebertragung(void) |
522 | void DatenUebertragung(void) |
526 | { |
523 | { |
527 | if(!UebertragungAbgeschlossen) return; |
524 | if(!UebertragungAbgeschlossen) return; |
528 | 525 | ||
529 | if(CheckDelay(AboTimeOut)) |
526 | if(CheckDelay(AboTimeOut)) |
530 | { |
527 | { |
531 | Display_Interval = 0; |
528 | Display_Interval = 0; |
532 | DebugDataIntervall = 0; |
529 | DebugDataIntervall = 0; |
533 | Intervall3D = 0; |
530 | Intervall3D = 0; |
534 | } |
531 | } |
535 | 532 | ||
536 | if(((Display_Interval>0 && CheckDelay(Display_Timer)) || DebugDisplayAnforderung) && UebertragungAbgeschlossen) |
533 | if(((Display_Interval>0 && CheckDelay(Display_Timer)) || DebugDisplayAnforderung) && UebertragungAbgeschlossen) |
537 | { |
534 | { |
538 | if(DisplayLine > 3)// new format |
535 | if(DisplayLine > 3)// new format |
539 | { |
536 | { |
540 | Menu(); |
537 | Menu(); |
541 | SendOutData('H', FC_ADDRESS, 1, (uint8_t *)DisplayBuff, 80); |
538 | SendOutData('H', FC_ADDRESS, 1, (uint8_t *)DisplayBuff, 80); |
542 | } |
539 | } |
543 | else // old format |
540 | else // old format |
544 | { |
541 | { |
545 | LCD_printfxy(0,0,"!!! INCOMPATIBLE !!!"); |
542 | LCD_printfxy(0,0,"!!! INCOMPATIBLE !!!"); |
546 | SendOutData('H', FC_ADDRESS, 2, &DisplayLine, sizeof(DisplayLine), (uint8_t *)DisplayBuff, 20); |
543 | SendOutData('H', FC_ADDRESS, 2, &DisplayLine, sizeof(DisplayLine), (uint8_t *)DisplayBuff, 20); |
547 | if(DisplayLine++ > 3) DisplayLine = 0; |
544 | if(DisplayLine++ > 3) DisplayLine = 0; |
548 | } |
545 | } |
549 | Display_Timer = SetDelay(Display_Interval); |
546 | Display_Timer = SetDelay(Display_Interval); |
550 | DebugDisplayAnforderung = 0; |
547 | DebugDisplayAnforderung = 0; |
551 | } |
548 | } |
552 | if(DebugDisplayAnforderung1 && UebertragungAbgeschlossen) |
549 | if(DebugDisplayAnforderung1 && UebertragungAbgeschlossen) |
553 | { |
550 | { |
554 | Menu(); |
551 | Menu(); |
555 | SendOutData('L', FC_ADDRESS, 3, &MenuePunkt, sizeof(MenuePunkt), &MaxMenue, sizeof(MaxMenue), DisplayBuff, sizeof(DisplayBuff)); |
552 | SendOutData('L', FC_ADDRESS, 3, &MenuePunkt, sizeof(MenuePunkt), &MaxMenue, sizeof(MaxMenue), DisplayBuff, sizeof(DisplayBuff)); |
556 | DebugDisplayAnforderung1 = 0; |
553 | DebugDisplayAnforderung1 = 0; |
557 | } |
554 | } |
558 | if(GetVersionAnforderung && UebertragungAbgeschlossen) |
555 | if(GetVersionAnforderung && UebertragungAbgeschlossen) |
559 | { |
556 | { |
560 | SendOutData('V', FC_ADDRESS, 1, (unsigned char *) &VersionInfo, sizeof(VersionInfo)); |
557 | SendOutData('V', FC_ADDRESS, 1, (unsigned char *) &VersionInfo, sizeof(VersionInfo)); |
561 | GetVersionAnforderung = 0; |
558 | GetVersionAnforderung = 0; |
562 | } |
559 | } |
563 | 560 | ||
564 | if(GetExternalControl && UebertragungAbgeschlossen) // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
561 | if(GetExternalControl && UebertragungAbgeschlossen) // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
565 | { |
562 | { |
566 | SendOutData('G',MeineSlaveAdresse, 1, (unsigned char *) &ExternControl, sizeof(ExternControl)); |
563 | SendOutData('G',MeineSlaveAdresse, 1, (unsigned char *) &ExternControl, sizeof(ExternControl)); |
567 | GetExternalControl = 0; |
564 | GetExternalControl = 0; |
568 | } |
565 | } |
569 | if((CheckDelay(Kompass_Timer)) && UebertragungAbgeschlossen) |
566 | if((CheckDelay(Kompass_Timer)) && UebertragungAbgeschlossen) |
570 | { |
567 | { |
571 | WinkelOut.Winkel[0] = (int) (IntegralNick / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
568 | WinkelOut.Winkel[0] = (int) (IntegralNick / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
572 | WinkelOut.Winkel[1] = (int) (IntegralRoll / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
569 | WinkelOut.Winkel[1] = (int) (IntegralRoll / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
573 | WinkelOut.UserParameter[0] = Parameter_UserParam1; |
570 | WinkelOut.UserParameter[0] = Parameter_UserParam1; |
574 | WinkelOut.UserParameter[1] = Parameter_UserParam2; |
571 | WinkelOut.UserParameter[1] = Parameter_UserParam2; |
575 | SendOutData('w', MK3MAG_ADDRESS, 1, (unsigned char *) &WinkelOut,sizeof(WinkelOut)); |
572 | SendOutData('w', MK3MAG_ADDRESS, 1, (unsigned char *) &WinkelOut,sizeof(WinkelOut)); |
576 | if(WinkelOut.CalcState > 4) WinkelOut.CalcState = 6; // wird dann in SPI auf Null gesetzt |
573 | if(WinkelOut.CalcState > 4) WinkelOut.CalcState = 6; // wird dann in SPI auf Null gesetzt |
577 | Kompass_Timer = SetDelay(99); |
574 | Kompass_Timer = SetDelay(99); |
578 | } |
575 | } |
579 | if(((DebugDataIntervall>0 && CheckDelay(Debug_Timer)) || DebugDataAnforderung) && UebertragungAbgeschlossen) |
576 | if(((DebugDataIntervall>0 && CheckDelay(Debug_Timer)) || DebugDataAnforderung) && UebertragungAbgeschlossen) |
580 | { |
577 | { |
581 | //if(Poti3 > 64) |
578 | //if(Poti3 > 64) |
582 | SendOutData('D', FC_ADDRESS, 1, (unsigned char *) &DebugOut,sizeof(DebugOut)); |
579 | SendOutData('D', FC_ADDRESS, 1, (unsigned char *) &DebugOut,sizeof(DebugOut)); |
583 | DebugDataAnforderung = 0; |
580 | DebugDataAnforderung = 0; |
584 | if(DebugDataIntervall>0) Debug_Timer = SetDelay(DebugDataIntervall); |
581 | if(DebugDataIntervall>0) Debug_Timer = SetDelay(DebugDataIntervall); |
585 | } |
582 | } |
586 | if(Intervall3D > 0 && CheckDelay(Timer3D) && UebertragungAbgeschlossen) |
583 | if(Intervall3D > 0 && CheckDelay(Timer3D) && UebertragungAbgeschlossen) |
587 | { |
584 | { |
588 | Data3D.Winkel[0] = (int) (IntegralNick / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
585 | Data3D.Winkel[0] = (int) (IntegralNick / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
589 | Data3D.Winkel[1] = (int) (IntegralRoll / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
586 | Data3D.Winkel[1] = (int) (IntegralRoll / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
590 | Data3D.Winkel[2] = (int) ((10 * ErsatzKompass) / GIER_GRAD_FAKTOR); |
587 | Data3D.Winkel[2] = (int) ((10 * ErsatzKompass) / GIER_GRAD_FAKTOR); |
591 | SendOutData('C', FC_ADDRESS, 1, (unsigned char *) &Data3D,sizeof(Data3D)); |
588 | SendOutData('C', FC_ADDRESS, 1, (unsigned char *) &Data3D,sizeof(Data3D)); |
592 | Timer3D = SetDelay(Intervall3D); |
589 | Timer3D = SetDelay(Intervall3D); |
593 | } |
590 | } |
594 | if(DebugTextAnforderung != 255) // Texte für die Analogdaten |
591 | if(DebugTextAnforderung != 255) // Texte für die Analogdaten |
595 | { |
592 | { |
596 | SendOutData('A', FC_ADDRESS, 2, (unsigned char *)&DebugTextAnforderung, sizeof(DebugTextAnforderung),(unsigned char *) ANALOG_TEXT[DebugTextAnforderung], 16); |
593 | SendOutData('A', FC_ADDRESS, 2, (unsigned char *)&DebugTextAnforderung, sizeof(DebugTextAnforderung),(unsigned char *) ANALOG_TEXT[DebugTextAnforderung], 16); |
597 | DebugTextAnforderung = 255; |
594 | DebugTextAnforderung = 255; |
598 | } |
595 | } |
599 | if(ConfirmFrame && UebertragungAbgeschlossen) // Datensatz bestätigen |
596 | if(ConfirmFrame && UebertragungAbgeschlossen) // Datensatz bestätigen |
600 | { |
597 | { |
601 | SendOutData('B', FC_ADDRESS, 1, (uint8_t*)&ConfirmFrame, sizeof(ConfirmFrame)); |
598 | SendOutData('B', FC_ADDRESS, 1, (uint8_t*)&ConfirmFrame, sizeof(ConfirmFrame)); |
602 | ConfirmFrame = 0; |
599 | ConfirmFrame = 0; |
603 | } |
600 | } |
604 | 601 | ||
605 | if(GetPPMChannelAnforderung && UebertragungAbgeschlossen) |
602 | if(GetPPMChannelAnforderung && UebertragungAbgeschlossen) |
606 | { |
603 | { |
607 | SendOutData('P', FC_ADDRESS, 1, (unsigned char *) &PPM_in, sizeof(PPM_in)); |
604 | SendOutData('P', FC_ADDRESS, 1, (unsigned char *) &PPM_in, sizeof(PPM_in)); |
608 | GetPPMChannelAnforderung = 0; |
605 | GetPPMChannelAnforderung = 0; |
609 | } |
606 | } |
610 | 607 | ||
611 | } |
608 | } |
612 | 609 | ||
613 | 610 |