Rev 1226 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1226 | Rev 1340 | ||
---|---|---|---|
1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 | // + Copyright (c) 04.2007 Holger Buss |
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 Debug_Timer,Kompass_Timer,Timer3D; |
45 | unsigned int DebugDataIntervall = 200, Intervall3D = 0; |
45 | unsigned int DebugDataIntervall = 200, Intervall3D = 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 | " ", |
68 | " ", |
69 | "MK3Mag CalState ", |
69 | "MK3Mag CalState ", |
70 | "Servo ", //20 |
70 | "Servo ", //20 |
71 | " ", |
71 | " ", |
72 | " ", |
72 | " ", |
73 | " ", |
73 | " ", |
74 | " ", |
74 | " ", |
75 | " ", //25 |
75 | " ", //25 |
76 | " ", |
76 | " ", |
77 | "Kalman_MaxDrift ", |
77 | "Kalman_MaxDrift ", |
78 | " ", |
78 | " ", |
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') wdt_enable(WDTO_250MS); // Reset-Commando |
134 | if(RxdBuffer[2] == 'R') wdt_enable(WDTO_250MS); // Reset-Commando |
135 | } |
135 | } |
136 | } |
136 | } |
137 | else |
137 | else |
138 | switch(UartState) |
138 | switch(UartState) |
139 | { |
139 | { |
140 | case 0: |
140 | case 0: |
141 | if(SioTmp == '#' && !NeuerDatensatzEmpfangen) UartState = 1; // Startzeichen und Daten schon verarbeitet |
141 | if(SioTmp == '#' && !NeuerDatensatzEmpfangen) UartState = 1; // Startzeichen und Daten schon verarbeitet |
142 | buf_ptr = 0; |
142 | buf_ptr = 0; |
143 | RxdBuffer[buf_ptr++] = SioTmp; |
143 | RxdBuffer[buf_ptr++] = SioTmp; |
144 | crc = SioTmp; |
144 | crc = SioTmp; |
145 | break; |
145 | break; |
146 | case 1: // Adresse auswerten |
146 | case 1: // Adresse auswerten |
147 | UartState++; |
147 | UartState++; |
148 | RxdBuffer[buf_ptr++] = SioTmp; |
148 | RxdBuffer[buf_ptr++] = SioTmp; |
149 | crc += SioTmp; |
149 | crc += SioTmp; |
150 | break; |
150 | break; |
151 | case 2: // Eingangsdaten sammeln |
151 | case 2: // Eingangsdaten sammeln |
152 | RxdBuffer[buf_ptr] = SioTmp; |
152 | RxdBuffer[buf_ptr] = SioTmp; |
153 | if(buf_ptr < MAX_EMPFANGS_BUFF) buf_ptr++; |
153 | if(buf_ptr < MAX_EMPFANGS_BUFF) buf_ptr++; |
154 | else UartState = 0; |
154 | else UartState = 0; |
155 | crc += SioTmp; |
155 | crc += SioTmp; |
156 | break; |
156 | break; |
157 | default: |
157 | default: |
158 | UartState = 0; |
158 | UartState = 0; |
159 | break; |
159 | break; |
160 | } |
160 | } |
161 | } |
161 | } |
162 | 162 | ||
163 | 163 | ||
164 | // -------------------------------------------------------------------------- |
164 | // -------------------------------------------------------------------------- |
165 | void AddCRC(unsigned int wieviele) |
165 | void AddCRC(unsigned int wieviele) |
166 | { |
166 | { |
167 | unsigned int tmpCRC = 0,i; |
167 | unsigned int tmpCRC = 0,i; |
168 | for(i = 0; i < wieviele;i++) |
168 | for(i = 0; i < wieviele;i++) |
169 | { |
169 | { |
170 | tmpCRC += SendeBuffer[i]; |
170 | tmpCRC += SendeBuffer[i]; |
171 | } |
171 | } |
172 | tmpCRC %= 4096; |
172 | tmpCRC %= 4096; |
173 | SendeBuffer[i++] = '=' + tmpCRC / 64; |
173 | SendeBuffer[i++] = '=' + tmpCRC / 64; |
174 | SendeBuffer[i++] = '=' + tmpCRC % 64; |
174 | SendeBuffer[i++] = '=' + tmpCRC % 64; |
175 | SendeBuffer[i++] = '\r'; |
175 | SendeBuffer[i++] = '\r'; |
176 | UebertragungAbgeschlossen = 0; |
176 | UebertragungAbgeschlossen = 0; |
177 | UDR = SendeBuffer[0]; |
177 | UDR = SendeBuffer[0]; |
178 | } |
178 | } |
179 | 179 | ||
180 | 180 | ||
181 | 181 | ||
182 | // -------------------------------------------------------------------------- |
182 | // -------------------------------------------------------------------------- |
183 | void SendOutData(unsigned char cmd,unsigned char address, unsigned char BufferAnzahl, ...) //unsigned char *snd, unsigned char len) |
183 | void SendOutData(unsigned char cmd,unsigned char address, unsigned char BufferAnzahl, ...) //unsigned char *snd, unsigned char len) |
184 | { |
184 | { |
185 | va_list ap; |
185 | va_list ap; |
186 | unsigned int pt = 0; |
186 | unsigned int pt = 0; |
187 | unsigned char a,b,c; |
187 | unsigned char a,b,c; |
188 | unsigned char ptr = 0; |
188 | unsigned char ptr = 0; |
189 | 189 | ||
190 | unsigned char *snd = 0; |
190 | unsigned char *snd = 0; |
191 | int len = 0; |
191 | int len = 0; |
192 | 192 | ||
193 | SendeBuffer[pt++] = '#'; // Startzeichen |
193 | SendeBuffer[pt++] = '#'; // Startzeichen |
194 | SendeBuffer[pt++] = 'a' + address; // Adresse (a=0; b=1,...) |
194 | SendeBuffer[pt++] = 'a' + address; // Adresse (a=0; b=1,...) |
195 | SendeBuffer[pt++] = cmd; // Commando |
195 | SendeBuffer[pt++] = cmd; // Commando |
196 | 196 | ||
197 | va_start(ap, BufferAnzahl); |
197 | va_start(ap, BufferAnzahl); |
198 | if(BufferAnzahl) |
198 | if(BufferAnzahl) |
199 | { |
199 | { |
200 | snd = va_arg(ap, unsigned char*); |
200 | snd = va_arg(ap, unsigned char*); |
201 | len = va_arg(ap, int); |
201 | len = va_arg(ap, int); |
202 | ptr = 0; |
202 | ptr = 0; |
203 | BufferAnzahl--; |
203 | BufferAnzahl--; |
204 | } |
204 | } |
205 | while(len) |
205 | while(len) |
206 | { |
206 | { |
207 | if(len) |
207 | if(len) |
208 | { |
208 | { |
209 | a = snd[ptr++]; |
209 | a = snd[ptr++]; |
210 | len--; |
210 | len--; |
211 | if((!len) && BufferAnzahl) |
211 | if((!len) && BufferAnzahl) |
212 | { |
212 | { |
213 | snd = va_arg(ap, unsigned char*); |
213 | snd = va_arg(ap, unsigned char*); |
214 | len = va_arg(ap, int); |
214 | len = va_arg(ap, int); |
215 | ptr = 0; |
215 | ptr = 0; |
216 | BufferAnzahl--; |
216 | BufferAnzahl--; |
217 | } |
217 | } |
218 | } |
218 | } |
219 | else a = 0; |
219 | else a = 0; |
220 | if(len) |
220 | if(len) |
221 | { |
221 | { |
222 | b = snd[ptr++]; |
222 | b = snd[ptr++]; |
223 | len--; |
223 | len--; |
224 | if((!len) && BufferAnzahl) |
224 | if((!len) && BufferAnzahl) |
225 | { |
225 | { |
226 | snd = va_arg(ap, unsigned char*); |
226 | snd = va_arg(ap, unsigned char*); |
227 | len = va_arg(ap, int); |
227 | len = va_arg(ap, int); |
228 | ptr = 0; |
228 | ptr = 0; |
229 | BufferAnzahl--; |
229 | BufferAnzahl--; |
230 | } |
230 | } |
231 | } |
231 | } |
232 | else b = 0; |
232 | else b = 0; |
233 | if(len) |
233 | if(len) |
234 | { |
234 | { |
235 | c = snd[ptr++]; |
235 | c = snd[ptr++]; |
236 | len--; |
236 | len--; |
237 | if((!len) && BufferAnzahl) |
237 | if((!len) && BufferAnzahl) |
238 | { |
238 | { |
239 | snd = va_arg(ap, unsigned char*); |
239 | snd = va_arg(ap, unsigned char*); |
240 | len = va_arg(ap, int); |
240 | len = va_arg(ap, int); |
241 | ptr = 0; |
241 | ptr = 0; |
242 | BufferAnzahl--; |
242 | BufferAnzahl--; |
243 | } |
243 | } |
244 | } |
244 | } |
245 | else c = 0; |
245 | else c = 0; |
246 | SendeBuffer[pt++] = '=' + (a >> 2); |
246 | SendeBuffer[pt++] = '=' + (a >> 2); |
247 | SendeBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
247 | SendeBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
248 | SendeBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
248 | SendeBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
249 | SendeBuffer[pt++] = '=' + ( c & 0x3f); |
249 | SendeBuffer[pt++] = '=' + ( c & 0x3f); |
250 | } |
250 | } |
251 | va_end(ap); |
251 | va_end(ap); |
252 | AddCRC(pt); |
252 | AddCRC(pt); |
253 | } |
253 | } |
254 | 254 | ||
255 | 255 | ||
256 | // -------------------------------------------------------------------------- |
256 | // -------------------------------------------------------------------------- |
257 | void Decode64(void) // die daten werden im rx buffer dekodiert, das geht nur, weil aus 4 byte immer 3 gemacht werden. |
257 | void Decode64(void) // die daten werden im rx buffer dekodiert, das geht nur, weil aus 4 byte immer 3 gemacht werden. |
258 | { |
258 | { |
259 | unsigned char a,b,c,d; |
259 | unsigned char a,b,c,d; |
260 | unsigned char x,y,z; |
260 | unsigned char x,y,z; |
261 | unsigned char ptrIn = 3; // start at begin of data block |
261 | unsigned char ptrIn = 3; // start at begin of data block |
262 | unsigned char ptrOut = 3; |
262 | unsigned char ptrOut = 3; |
263 | 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. |
263 | 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. |
264 | 264 | ||
265 | while(len) |
265 | while(len) |
266 | { |
266 | { |
267 | a = RxdBuffer[ptrIn++] - '='; |
267 | a = RxdBuffer[ptrIn++] - '='; |
268 | b = RxdBuffer[ptrIn++] - '='; |
268 | b = RxdBuffer[ptrIn++] - '='; |
269 | c = RxdBuffer[ptrIn++] - '='; |
269 | c = RxdBuffer[ptrIn++] - '='; |
270 | d = RxdBuffer[ptrIn++] - '='; |
270 | d = RxdBuffer[ptrIn++] - '='; |
271 | 271 | ||
272 | x = (a << 2) | (b >> 4); |
272 | x = (a << 2) | (b >> 4); |
273 | y = ((b & 0x0f) << 4) | (c >> 2); |
273 | y = ((b & 0x0f) << 4) | (c >> 2); |
274 | z = ((c & 0x03) << 6) | d; |
274 | z = ((c & 0x03) << 6) | d; |
275 | 275 | ||
276 | if(len--) RxdBuffer[ptrOut++] = x; else break; |
276 | if(len--) RxdBuffer[ptrOut++] = x; else break; |
277 | if(len--) RxdBuffer[ptrOut++] = y; else break; |
277 | if(len--) RxdBuffer[ptrOut++] = y; else break; |
278 | if(len--) RxdBuffer[ptrOut++] = z; else break; |
278 | if(len--) RxdBuffer[ptrOut++] = z; else break; |
279 | } |
279 | } |
280 | pRxData = (unsigned char*)&RxdBuffer[3]; // decodierte Daten beginnen beim 4. Byte |
280 | pRxData = (unsigned char*)&RxdBuffer[3]; // decodierte Daten beginnen beim 4. Byte |
281 | RxDataLen = ptrOut - 3; // wie viele Bytes wurden dekodiert? |
281 | RxDataLen = ptrOut - 3; // wie viele Bytes wurden dekodiert? |
282 | 282 | ||
283 | } |
283 | } |
284 | 284 | ||
285 | // -------------------------------------------------------------------------- |
285 | // -------------------------------------------------------------------------- |
286 | void BearbeiteRxDaten(void) |
286 | void BearbeiteRxDaten(void) |
287 | { |
287 | { |
288 | if(!NeuerDatensatzEmpfangen) return; |
288 | if(!NeuerDatensatzEmpfangen) return; |
289 | 289 | ||
290 | unsigned char tempchar1, tempchar2; |
290 | unsigned char tempchar1, tempchar2; |
291 | Decode64(); // dekodiere datenblock im Empfangsbuffer |
291 | Decode64(); // dekodiere datenblock im Empfangsbuffer |
292 | switch(RxdBuffer[1]-'a') // check for Slave Address |
292 | switch(RxdBuffer[1]-'a') // check for Slave Address |
293 | { |
293 | { |
294 | case FC_ADDRESS: // FC special commands |
294 | case FC_ADDRESS: // FC special commands |
295 | 295 | ||
296 | switch(RxdBuffer[2]) |
296 | switch(RxdBuffer[2]) |
297 | { |
297 | { |
298 | case 'K':// Kompasswert |
298 | case 'K':// Kompasswert |
299 | memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue)); |
299 | memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue)); |
300 | KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180; |
300 | KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180; |
301 | break; |
301 | break; |
302 | case 't':// Motortest |
302 | case 't':// Motortest |
303 | if(AnzahlEmpfangsBytes > 20) memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest)); |
303 | if(AnzahlEmpfangsBytes > 20) memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest)); |
304 | else memcpy(&MotorTest[0], (unsigned char *)pRxData, 4); |
304 | else memcpy(&MotorTest[0], (unsigned char *)pRxData, 4); |
305 | PC_MotortestActive = 240; |
305 | PC_MotortestActive = 240; |
306 | //while(!UebertragungAbgeschlossen); |
306 | //while(!UebertragungAbgeschlossen); |
307 | //SendOutData('T', MeineSlaveAdresse, 0); |
307 | //SendOutData('T', MeineSlaveAdresse, 0); |
308 | PcZugriff = 255; |
308 | PcZugriff = 255; |
309 | break; |
309 | break; |
310 | 310 | ||
311 | case 'n':// "Get Mixer |
311 | case 'n':// "Get Mixer |
312 | while(!UebertragungAbgeschlossen); |
312 | while(!UebertragungAbgeschlossen); |
313 | SendOutData('N', FC_ADDRESS, 1, (unsigned char *) &Mixer,sizeof(Mixer)); |
313 | SendOutData('N', FC_ADDRESS, 1, (unsigned char *) &Mixer,sizeof(Mixer)); |
314 | break; |
314 | break; |
315 | 315 | ||
316 | case 'm':// "Write Mixer |
316 | case 'm':// "Write Mixer |
317 | while(!UebertragungAbgeschlossen); |
317 | while(!UebertragungAbgeschlossen); |
318 | if(pRxData[0] == MIXER_REVISION) |
318 | if(pRxData[0] == MIXER_REVISION) |
319 | { |
319 | { |
320 | memcpy(&Mixer, (unsigned char *)pRxData, sizeof(Mixer)); |
320 | memcpy(&Mixer, (unsigned char *)pRxData, sizeof(Mixer)); |
321 | eeprom_write_block(&Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer)); |
321 | eeprom_write_block(&Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer)); |
322 | tempchar1 = 1; |
322 | tempchar1 = 1; |
323 | } |
323 | } |
324 | else tempchar1 = 0; |
324 | else tempchar1 = 0; |
325 | SendOutData('M', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1)); |
325 | SendOutData('M', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1)); |
326 | break; |
326 | break; |
327 | 327 | ||
328 | case 'p': // get PPM Channels |
328 | case 'p': // get PPM Channels |
329 | GetPPMChannelAnforderung = 1; |
329 | GetPPMChannelAnforderung = 1; |
330 | break; |
330 | break; |
331 | 331 | ||
332 | case 'q':// "Get"-Anforderung für Settings |
332 | case 'q':// "Get"-Anforderung für Settings |
333 | // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
333 | // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
334 | if(pRxData[0] == 0xFF) |
334 | if(pRxData[0] == 0xFF) |
335 | { |
335 | { |
336 | pRxData[0] = GetActiveParamSetNumber(); |
336 | pRxData[0] = GetActiveParamSetNumber(); |
337 | } |
337 | } |
338 | // limit settings range |
338 | // limit settings range |
339 | if(pRxData[0] < 1) pRxData[0] = 1; // limit to 5 |
339 | if(pRxData[0] < 1) pRxData[0] = 1; // limit to 5 |
340 | else if(pRxData[0] > 5) pRxData[0] = 5; // limit to 5 |
340 | else if(pRxData[0] > 5) pRxData[0] = 5; // limit to 5 |
341 | // load requested parameter set |
341 | // load requested parameter set |
342 | ReadParameterSet(pRxData[0], (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
342 | ReadParameterSet(pRxData[0], (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
343 | 343 | ||
344 | while(!UebertragungAbgeschlossen); |
344 | while(!UebertragungAbgeschlossen); |
345 | tempchar1 = pRxData[0]; |
345 | tempchar1 = pRxData[0]; |
346 | tempchar2 = EE_DATENREVISION; |
346 | tempchar2 = EE_DATENREVISION; |
347 | SendOutData('Q', FC_ADDRESS, 3, &tempchar1, sizeof(tempchar1), &tempchar2, sizeof(tempchar2), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
347 | SendOutData('Q', FC_ADDRESS, 3, &tempchar1, sizeof(tempchar1), &tempchar2, sizeof(tempchar2), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
348 | break; |
348 | break; |
349 | 349 | ||
350 | case 's': // Parametersatz speichern |
350 | case 's': // Parametersatz speichern |
351 | if((1 <= pRxData[0]) && (pRxData[0] <= 5) && (pRxData[1] == EE_DATENREVISION)) // check for setting to be in range |
351 | if((1 <= pRxData[0]) && (pRxData[0] <= 5) && (pRxData[1] == EE_DATENREVISION)) // check for setting to be in range |
352 | { |
352 | { |
353 | memcpy((unsigned char *) &EE_Parameter.Kanalbelegung[0], (unsigned char *)&pRxData[2], STRUCT_PARAM_LAENGE); |
353 | memcpy((unsigned char *) &EE_Parameter.Kanalbelegung[0], (unsigned char *)&pRxData[2], STRUCT_PARAM_LAENGE); |
354 | WriteParameterSet(pRxData[0], (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
354 | WriteParameterSet(pRxData[0], (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
355 | Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L; |
355 | Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L; |
356 | Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L; |
356 | Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L; |
357 | SetActiveParamSetNumber(pRxData[0]); |
357 | SetActiveParamSetNumber(pRxData[0]); |
358 | tempchar1 = GetActiveParamSetNumber(); |
358 | tempchar1 = GetActiveParamSetNumber(); |
359 | Piep(tempchar1); |
359 | Piep(tempchar1); |
360 | } |
360 | } |
361 | else |
361 | else |
362 | { |
362 | { |
363 | tempchar1 = 0; // mark in response an invlid setting |
363 | tempchar1 = 0; // mark in response an invlid setting |
364 | } |
364 | } |
365 | while(!UebertragungAbgeschlossen); |
365 | while(!UebertragungAbgeschlossen); |
366 | SendOutData('S', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1)); |
366 | SendOutData('S', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1)); |
367 | break; |
367 | break; |
368 | 368 | ||
369 | } // case FC_ADDRESS: |
369 | } // case FC_ADDRESS: |
370 | 370 | ||
371 | default: // any Slave Address |
371 | default: // any Slave Address |
372 | 372 | ||
373 | switch(RxdBuffer[2]) |
373 | switch(RxdBuffer[2]) |
374 | { |
374 | { |
375 | // 't' comand placed here only for compatibility to BL |
375 | // 't' comand placed here only for compatibility to BL |
376 | case 't':// Motortest |
376 | case 't':// Motortest |
377 | if(AnzahlEmpfangsBytes > 20) memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest)); |
377 | if(AnzahlEmpfangsBytes > 20) memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest)); |
378 | else memcpy(&MotorTest[0], (unsigned char *)pRxData, 4); |
378 | else memcpy(&MotorTest[0], (unsigned char *)pRxData, 4); |
379 | while(!UebertragungAbgeschlossen); |
379 | while(!UebertragungAbgeschlossen); |
380 | SendOutData('T', MeineSlaveAdresse, 0); |
380 | SendOutData('T', MeineSlaveAdresse, 0); |
381 | PC_MotortestActive = 250; |
381 | PC_MotortestActive = 250; |
382 | PcZugriff = 255; |
382 | PcZugriff = 255; |
383 | break; |
383 | break; |
384 | // 'K' comand placed here only for compatibility to old MK3MAG software, that does not send the right Slave Address |
384 | // 'K' comand placed here only for compatibility to old MK3MAG software, that does not send the right Slave Address |
385 | case 'K':// Kompasswert |
385 | case 'K':// Kompasswert |
386 | memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue)); |
386 | memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue)); |
387 | KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180; |
387 | KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180; |
388 | break; |
388 | break; |
389 | case 'a':// Texte der Analogwerte |
389 | case 'a':// Texte der Analogwerte |
390 | DebugTextAnforderung = pRxData[0]; |
390 | DebugTextAnforderung = pRxData[0]; |
391 | if (DebugTextAnforderung > 31) DebugTextAnforderung = 31; |
391 | if (DebugTextAnforderung > 31) DebugTextAnforderung = 31; |
392 | PcZugriff = 255; |
392 | PcZugriff = 255; |
393 | break; |
393 | break; |
394 | case 'b': |
394 | case 'b': |
395 | memcpy((unsigned char *)&ExternControl, (unsigned char *)pRxData, sizeof(ExternControl)); |
395 | memcpy((unsigned char *)&ExternControl, (unsigned char *)pRxData, sizeof(ExternControl)); |
396 | ConfirmFrame = ExternControl.Frame; |
396 | ConfirmFrame = ExternControl.Frame; |
397 | PcZugriff = 255; |
397 | PcZugriff = 255; |
398 | break; |
398 | break; |
399 | case 'c': // Poll the 3D-Data |
399 | case 'c': // Poll the 3D-Data |
400 | if(!Intervall3D) { if(pRxData[0]) Timer3D = SetDelay(pRxData[0] * 10);} |
400 | if(!Intervall3D) { if(pRxData[0]) Timer3D = SetDelay(pRxData[0] * 10);} |
401 | Intervall3D = pRxData[0] * 10; |
401 | Intervall3D = pRxData[0] * 10; |
402 | break; |
402 | break; |
403 | case 'd': // Poll the debug data |
403 | case 'd': // Poll the debug data |
404 | DebugDataIntervall = pRxData[0] * 10; |
404 | DebugDataIntervall = pRxData[0] * 10; |
405 | if(DebugDataIntervall > 0) DebugDataAnforderung = 1; |
405 | if(DebugDataIntervall > 0) DebugDataAnforderung = 1; |
406 | break; |
406 | break; |
407 | 407 | ||
408 | case 'h':// x-1 Displayzeilen |
408 | case 'h':// x-1 Displayzeilen |
409 | PcZugriff = 255; |
409 | PcZugriff = 255; |
410 | RemoteKeys |= pRxData[0]; |
410 | RemoteKeys |= pRxData[0]; |
411 | if(RemoteKeys) DisplayLine = 0; |
411 | if(RemoteKeys) DisplayLine = 0; |
412 | DebugDisplayAnforderung = 1; |
412 | DebugDisplayAnforderung = 1; |
413 | break; |
413 | break; |
414 | 414 | ||
415 | case 'l':// x-1 Displayzeilen |
415 | case 'l':// x-1 Displayzeilen |
416 | PcZugriff = 255; |
416 | PcZugriff = 255; |
417 | MenuePunkt = pRxData[0]; |
417 | MenuePunkt = pRxData[0]; |
418 | DebugDisplayAnforderung1 = 1; |
418 | DebugDisplayAnforderung1 = 1; |
419 | break; |
419 | break; |
420 | case 'v': // Version-Anforderung und Ausbaustufe |
420 | case 'v': // Version-Anforderung und Ausbaustufe |
421 | GetVersionAnforderung = 1; |
421 | GetVersionAnforderung = 1; |
422 | break; |
422 | break; |
423 | 423 | ||
424 | case 'g':// |
424 | case 'g':// |
425 | GetExternalControl = 1; |
425 | GetExternalControl = 1; |
426 | break; |
426 | break; |
427 | } |
427 | } |
428 | break; // default: |
428 | break; // default: |
429 | } |
429 | } |
430 | NeuerDatensatzEmpfangen = 0; |
430 | NeuerDatensatzEmpfangen = 0; |
431 | pRxData = 0; |
431 | pRxData = 0; |
432 | RxDataLen = 0; |
432 | RxDataLen = 0; |
433 | } |
433 | } |
434 | 434 | ||
435 | //############################################################################ |
435 | //############################################################################ |
436 | //Routine für die Serielle Ausgabe |
436 | //Routine für die Serielle Ausgabe |
437 | int uart_putchar (char c) |
437 | int uart_putchar (char c) |
438 | //############################################################################ |
438 | //############################################################################ |
439 | { |
439 | { |
440 | if (c == '\n') |
440 | if (c == '\n') |
441 | uart_putchar('\r'); |
441 | uart_putchar('\r'); |
442 | //Warten solange bis Zeichen gesendet wurde |
442 | //Warten solange bis Zeichen gesendet wurde |
443 | loop_until_bit_is_set(USR, UDRE); |
443 | loop_until_bit_is_set(USR, UDRE); |
444 | //Ausgabe des Zeichens |
444 | //Ausgabe des Zeichens |
445 | UDR = c; |
445 | UDR = c; |
446 | 446 | ||
447 | return (0); |
447 | return (0); |
448 | } |
448 | } |
449 | 449 | ||
450 | // -------------------------------------------------------------------------- |
450 | // -------------------------------------------------------------------------- |
451 | void WriteProgramData(unsigned int pos, unsigned char wert) |
451 | void WriteProgramData(unsigned int pos, unsigned char wert) |
452 | { |
452 | { |
453 | //if (ProgramLocation == IN_RAM) Buffer[pos] = wert; |
453 | //if (ProgramLocation == IN_RAM) Buffer[pos] = wert; |
454 | // else eeprom_write_byte(&EE_Buffer[pos], wert); |
454 | // else eeprom_write_byte(&EE_Buffer[pos], wert); |
455 | // Buffer[pos] = wert; |
455 | // Buffer[pos] = wert; |
456 | } |
456 | } |
457 | 457 | ||
458 | //############################################################################ |
458 | //############################################################################ |
459 | //INstallation der Seriellen Schnittstelle |
459 | //INstallation der Seriellen Schnittstelle |
460 | void UART_Init (void) |
460 | void UART_Init (void) |
461 | //############################################################################ |
461 | //############################################################################ |
462 | { |
462 | { |
463 | //Enable TXEN im Register UCR TX-Data Enable & RX Enable |
463 | //Enable TXEN im Register UCR TX-Data Enable & RX Enable |
464 | 464 | ||
465 | UCR=(1 << TXEN) | (1 << RXEN); |
465 | UCR=(1 << TXEN) | (1 << RXEN); |
466 | // UART Double Speed (U2X) |
466 | // UART Double Speed (U2X) |
467 | USR |= (1<<U2X); |
467 | USR |= (1<<U2X); |
468 | // RX-Interrupt Freigabe |
468 | // RX-Interrupt Freigabe |
469 | UCSRB |= (1<<RXCIE); |
469 | UCSRB |= (1<<RXCIE); |
470 | // TX-Interrupt Freigabe |
470 | // TX-Interrupt Freigabe |
471 | UCSRB |= (1<<TXCIE); |
471 | UCSRB |= (1<<TXCIE); |
472 | 472 | ||
473 | //Teiler wird gesetzt |
473 | //Teiler wird gesetzt |
474 | UBRR=(SYSCLK / (BAUD_RATE * 8L) - 1); |
474 | UBRR=(SYSCLK / (BAUD_RATE * 8L) - 1); |
475 | //UBRR = 33; |
475 | //UBRR = 33; |
476 | //öffnet einen Kanal für printf (STDOUT) |
476 | //öffnet einen Kanal für printf (STDOUT) |
477 | //fdevopen (uart_putchar, 0); |
477 | //fdevopen (uart_putchar, 0); |
478 | //sbi(PORTD,4); |
478 | //sbi(PORTD,4); |
479 | Debug_Timer = SetDelay(DebugDataIntervall); |
479 | Debug_Timer = SetDelay(DebugDataIntervall); |
480 | Kompass_Timer = SetDelay(220); |
480 | Kompass_Timer = SetDelay(220); |
481 | 481 | ||
482 | VersionInfo.SWMajor = VERSION_MAJOR; |
482 | VersionInfo.SWMajor = VERSION_MAJOR; |
483 | VersionInfo.SWMinor = VERSION_MINOR; |
483 | VersionInfo.SWMinor = VERSION_MINOR; |
484 | VersionInfo.SWPatch = VERSION_PATCH; |
484 | VersionInfo.SWPatch = VERSION_PATCH; |
485 | VersionInfo.ProtoMajor = VERSION_SERIAL_MAJOR; |
485 | VersionInfo.ProtoMajor = VERSION_SERIAL_MAJOR; |
486 | VersionInfo.ProtoMinor = VERSION_SERIAL_MINOR; |
486 | VersionInfo.ProtoMinor = VERSION_SERIAL_MINOR; |
487 | 487 | ||
488 | pRxData = 0; |
488 | pRxData = 0; |
489 | RxDataLen = 0; |
489 | RxDataLen = 0; |
490 | } |
490 | } |
491 | 491 | ||
492 | //--------------------------------------------------------------------------------------------- |
492 | //--------------------------------------------------------------------------------------------- |
493 | void DatenUebertragung(void) |
493 | void DatenUebertragung(void) |
494 | { |
494 | { |
495 | if(!UebertragungAbgeschlossen) return; |
495 | if(!UebertragungAbgeschlossen) return; |
496 | 496 | ||
497 | if(DebugDisplayAnforderung && UebertragungAbgeschlossen) |
497 | if(DebugDisplayAnforderung && UebertragungAbgeschlossen) |
498 | { |
498 | { |
499 | Menu(); |
499 | Menu(); |
500 | SendOutData('H', FC_ADDRESS, 2, &DisplayLine, sizeof(DisplayLine), &DisplayBuff[DisplayLine * 20], 20); |
500 | SendOutData('H', FC_ADDRESS, 2, &DisplayLine, sizeof(DisplayLine), &DisplayBuff[DisplayLine * 20], 20); |
501 | DisplayLine++; |
501 | DisplayLine++; |
502 | if(DisplayLine >= 4) DisplayLine = 0; |
502 | if(DisplayLine >= 4) DisplayLine = 0; |
503 | DebugDisplayAnforderung = 0; |
503 | DebugDisplayAnforderung = 0; |
504 | } |
504 | } |
505 | if(DebugDisplayAnforderung1 && UebertragungAbgeschlossen) |
505 | if(DebugDisplayAnforderung1 && UebertragungAbgeschlossen) |
506 | { |
506 | { |
507 | Menu(); |
507 | Menu(); |
508 | SendOutData('L', FC_ADDRESS, 3, &MenuePunkt, sizeof(MenuePunkt), &MaxMenue, sizeof(MaxMenue), DisplayBuff, sizeof(DisplayBuff)); |
508 | SendOutData('L', FC_ADDRESS, 3, &MenuePunkt, sizeof(MenuePunkt), &MaxMenue, sizeof(MaxMenue), DisplayBuff, sizeof(DisplayBuff)); |
509 | DebugDisplayAnforderung1 = 0; |
509 | DebugDisplayAnforderung1 = 0; |
510 | } |
510 | } |
511 | if(GetVersionAnforderung && UebertragungAbgeschlossen) |
511 | if(GetVersionAnforderung && UebertragungAbgeschlossen) |
512 | { |
512 | { |
513 | SendOutData('V', FC_ADDRESS, 1, (unsigned char *) &VersionInfo, sizeof(VersionInfo)); |
513 | SendOutData('V', FC_ADDRESS, 1, (unsigned char *) &VersionInfo, sizeof(VersionInfo)); |
514 | GetVersionAnforderung = 0; |
514 | GetVersionAnforderung = 0; |
515 | } |
515 | } |
516 | 516 | ||
517 | if(GetExternalControl && UebertragungAbgeschlossen) // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
517 | if(GetExternalControl && UebertragungAbgeschlossen) // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
518 | { |
518 | { |
519 | SendOutData('G',MeineSlaveAdresse, 1, (unsigned char *) &ExternControl, sizeof(ExternControl)); |
519 | SendOutData('G',MeineSlaveAdresse, 1, (unsigned char *) &ExternControl, sizeof(ExternControl)); |
520 | GetExternalControl = 0; |
520 | GetExternalControl = 0; |
521 | } |
521 | } |
522 | if((CheckDelay(Kompass_Timer)) && UebertragungAbgeschlossen) |
522 | if((CheckDelay(Kompass_Timer)) && UebertragungAbgeschlossen) |
523 | { |
523 | { |
524 | WinkelOut.Winkel[0] = (int) (IntegralNick / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
524 | WinkelOut.Winkel[0] = (int) (IntegralNick / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
525 | WinkelOut.Winkel[1] = (int) (IntegralRoll / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
525 | WinkelOut.Winkel[1] = (int) (IntegralRoll / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
526 | WinkelOut.UserParameter[0] = Parameter_UserParam1; |
526 | WinkelOut.UserParameter[0] = Parameter_UserParam1; |
527 | WinkelOut.UserParameter[1] = Parameter_UserParam2; |
527 | WinkelOut.UserParameter[1] = Parameter_UserParam2; |
528 | SendOutData('w', MK3MAG_ADDRESS, 1, (unsigned char *) &WinkelOut,sizeof(WinkelOut)); |
528 | SendOutData('w', MK3MAG_ADDRESS, 1, (unsigned char *) &WinkelOut,sizeof(WinkelOut)); |
529 | if(WinkelOut.CalcState > 4) WinkelOut.CalcState = 6; // wird dann in SPI auf Null gesetzt |
529 | if(WinkelOut.CalcState > 4) WinkelOut.CalcState = 6; // wird dann in SPI auf Null gesetzt |
530 | Kompass_Timer = SetDelay(99); |
530 | Kompass_Timer = SetDelay(99); |
531 | } |
531 | } |
532 | if(((DebugDataIntervall>0 && CheckDelay(Debug_Timer)) || DebugDataAnforderung) && UebertragungAbgeschlossen) |
532 | if(((DebugDataIntervall>0 && CheckDelay(Debug_Timer)) || DebugDataAnforderung) && UebertragungAbgeschlossen) |
533 | { |
533 | { |
534 | SendOutData('D', FC_ADDRESS, 1, (unsigned char *) &DebugOut,sizeof(DebugOut)); |
534 | SendOutData('D', FC_ADDRESS, 1, (unsigned char *) &DebugOut,sizeof(DebugOut)); |
535 | DebugDataAnforderung = 0; |
535 | DebugDataAnforderung = 0; |
536 | if(DebugDataIntervall>0) Debug_Timer = SetDelay(DebugDataIntervall); |
536 | if(DebugDataIntervall>0) Debug_Timer = SetDelay(DebugDataIntervall); |
537 | } |
537 | } |
538 | if(Intervall3D > 0 && CheckDelay(Timer3D) && UebertragungAbgeschlossen) |
538 | if(Intervall3D > 0 && CheckDelay(Timer3D) && UebertragungAbgeschlossen) |
539 | { |
539 | { |
540 | Data3D.Winkel[0] = (int) (IntegralNick / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
540 | Data3D.Winkel[0] = (int) (IntegralNick / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
541 | Data3D.Winkel[1] = (int) (IntegralRoll / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
541 | Data3D.Winkel[1] = (int) (IntegralRoll / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
542 | Data3D.Winkel[2] = (int) ((10 * ErsatzKompass) / GIER_GRAD_FAKTOR); |
542 | Data3D.Winkel[2] = (int) ((10 * ErsatzKompass) / GIER_GRAD_FAKTOR); |
543 | SendOutData('C', FC_ADDRESS, 1, (unsigned char *) &Data3D,sizeof(Data3D)); |
543 | SendOutData('C', FC_ADDRESS, 1, (unsigned char *) &Data3D,sizeof(Data3D)); |
544 | Timer3D = SetDelay(Intervall3D); |
544 | Timer3D = SetDelay(Intervall3D); |
545 | } |
545 | } |
546 | if(DebugTextAnforderung != 255) // Texte für die Analogdaten |
546 | if(DebugTextAnforderung != 255) // Texte für die Analogdaten |
547 | { |
547 | { |
548 | SendOutData('A', FC_ADDRESS, 2, (unsigned char *)&DebugTextAnforderung, sizeof(DebugTextAnforderung),(unsigned char *) ANALOG_TEXT[DebugTextAnforderung], 16); |
548 | SendOutData('A', FC_ADDRESS, 2, (unsigned char *)&DebugTextAnforderung, sizeof(DebugTextAnforderung),(unsigned char *) ANALOG_TEXT[DebugTextAnforderung], 16); |
549 | DebugTextAnforderung = 255; |
549 | DebugTextAnforderung = 255; |
550 | } |
550 | } |
551 | if(ConfirmFrame && UebertragungAbgeschlossen) // Datensatz bestätigen |
551 | if(ConfirmFrame && UebertragungAbgeschlossen) // Datensatz bestätigen |
552 | { |
552 | { |
553 | SendOutData('B', FC_ADDRESS, 1, (uint8_t*)&ConfirmFrame, sizeof(ConfirmFrame)); |
553 | SendOutData('B', FC_ADDRESS, 1, (uint8_t*)&ConfirmFrame, sizeof(ConfirmFrame)); |
554 | ConfirmFrame = 0; |
554 | ConfirmFrame = 0; |
555 | } |
555 | } |
556 | 556 | ||
557 | if(GetPPMChannelAnforderung && UebertragungAbgeschlossen) |
557 | if(GetPPMChannelAnforderung && UebertragungAbgeschlossen) |
558 | { |
558 | { |
559 | SendOutData('P', FC_ADDRESS, 1, (unsigned char *) &PPM_in, sizeof(PPM_in)); |
559 | SendOutData('P', FC_ADDRESS, 1, (unsigned char *) &PPM_in, sizeof(PPM_in)); |
560 | GetPPMChannelAnforderung = 0; |
560 | GetPPMChannelAnforderung = 0; |
561 | } |
561 | } |
562 | 562 | ||
563 | } |
563 | } |
564 | 564 | ||
565 | 565 |