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