Rev 1760 | Rev 1765 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1760 | Rev 1761 | ||
---|---|---|---|
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 <avr/pgmspace.h> |
9 | #include <avr/pgmspace.h> |
10 | #include "main.h" |
10 | #include "main.h" |
11 | #include "uart.h" |
11 | #include "uart.h" |
12 | #include "libfc.h" |
12 | #include "libfc.h" |
13 | #include "eeprom.h" |
13 | #include "eeprom.h" |
14 | 14 | ||
15 | #define FC_ADDRESS 1 |
15 | #define FC_ADDRESS 1 |
16 | #define NC_ADDRESS 2 |
16 | #define NC_ADDRESS 2 |
17 | #define MK3MAG_ADDRESS 3 |
17 | #define MK3MAG_ADDRESS 3 |
18 | #define BL_CTRL_ADDRESS 5 |
18 | #define BL_CTRL_ADDRESS 5 |
19 | 19 | ||
20 | #define ABO_TIMEOUT 4000 // disable abo after 4 seconds |
20 | #define ABO_TIMEOUT 4000 // disable abo after 4 seconds |
21 | #define MAX_SENDE_BUFF 170 |
21 | #define MAX_SENDE_BUFF 170 |
22 | #define MAX_EMPFANGS_BUFF 170 |
22 | #define MAX_EMPFANGS_BUFF 170 |
23 | 23 | ||
24 | #define BLPARAM_REVISION 1 |
24 | #define BLPARAM_REVISION 1 |
25 | #define MASK_SET_PWM_SCALING 0x01 |
25 | #define MASK_SET_PWM_SCALING 0x01 |
26 | #define MASK_SET_CURRENT_LIMIT 0x02 |
26 | #define MASK_SET_CURRENT_LIMIT 0x02 |
27 | #define MASK_SET_TEMP_LIMIT 0x04 |
27 | #define MASK_SET_TEMP_LIMIT 0x04 |
28 | #define MASK_SET_CURRENT_SCALING 0x08 |
28 | #define MASK_SET_CURRENT_SCALING 0x08 |
29 | #define MASK_SET_BITCONFIG 0x10 |
29 | #define MASK_SET_BITCONFIG 0x10 |
30 | #define MASK_RESET_CAPCOUNTER 0x20 |
30 | #define MASK_RESET_CAPCOUNTER 0x20 |
31 | #define MASK_SET_DEFAULT_PARAMS 0x40 |
31 | #define MASK_SET_DEFAULT_PARAMS 0x40 |
32 | #define MASK_SET_SAVE_EEPROM 0x80 |
32 | #define MASK_SET_SAVE_EEPROM 0x80 |
33 | 33 | ||
34 | typedef struct |
34 | typedef struct |
35 | { |
35 | { |
36 | unsigned char Revision; // revision of parameter structure |
36 | unsigned char Revision; // revision of parameter structure |
37 | unsigned char Address; // target address |
37 | unsigned char Address; // target address |
38 | unsigned char PwmScaling; // maximum value of pwm setpoint |
38 | unsigned char PwmScaling; // maximum value of pwm setpoint |
39 | unsigned char CurrentLimit; // current limit in 1A steps |
39 | unsigned char CurrentLimit; // current limit in 1A steps |
40 | unsigned char TemperatureLimit; // in °C |
40 | unsigned char TemperatureLimit; // in °C |
41 | unsigned char CurrentScaling; // scaling factor for current measurement |
41 | unsigned char CurrentScaling; // scaling factor for current measurement |
42 | unsigned char BitConfig; // see defines above |
42 | unsigned char BitConfig; // see defines above |
43 | unsigned char SetMask; // filter for active paramters |
43 | unsigned char SetMask; // filter for active paramters |
44 | unsigned char Checksum; // checksum for parameter sturcture |
44 | unsigned char Checksum; // checksum for parameter sturcture |
45 | } __attribute__((packed)) BLParameter_t; |
45 | } __attribute__((packed)) BLParameter_t; |
46 | 46 | ||
47 | 47 | ||
48 | unsigned char GetExternalControl = 0,DebugDisplayAnforderung1 = 0, DebugDisplayAnforderung = 0,DebugDataAnforderung = 0,GetVersionAnforderung = 0, GetPPMChannelAnforderung = 0; |
48 | unsigned char GetExternalControl = 0,DebugDisplayAnforderung1 = 0, DebugDisplayAnforderung = 0,DebugDataAnforderung = 0,GetVersionAnforderung = 0, GetPPMChannelAnforderung = 0; |
49 | unsigned char DisplayLine = 0; |
49 | unsigned char DisplayLine = 0; |
50 | unsigned volatile char SioTmp = 0; |
50 | unsigned volatile char SioTmp = 0; |
51 | unsigned volatile char NeuerDatensatzEmpfangen = 0; |
51 | unsigned volatile char NeuerDatensatzEmpfangen = 0; |
52 | unsigned volatile char NeueKoordinateEmpfangen = 0; |
52 | unsigned volatile char NeueKoordinateEmpfangen = 0; |
53 | unsigned volatile char UebertragungAbgeschlossen = 1; |
53 | unsigned volatile char UebertragungAbgeschlossen = 1; |
54 | unsigned volatile char CntCrcError = 0; |
54 | unsigned volatile char CntCrcError = 0; |
55 | unsigned volatile char AnzahlEmpfangsBytes = 0; |
55 | unsigned volatile char AnzahlEmpfangsBytes = 0; |
56 | unsigned volatile char TxdBuffer[MAX_SENDE_BUFF]; |
56 | unsigned volatile char TxdBuffer[MAX_SENDE_BUFF]; |
57 | unsigned volatile char RxdBuffer[MAX_EMPFANGS_BUFF]; |
57 | unsigned volatile char RxdBuffer[MAX_EMPFANGS_BUFF]; |
58 | 58 | ||
59 | unsigned char *pRxData = 0; |
59 | unsigned char *pRxData = 0; |
60 | unsigned char RxDataLen = 0; |
60 | unsigned char RxDataLen = 0; |
61 | unsigned volatile char PC_DebugTimeout = 0; |
61 | unsigned volatile char PC_DebugTimeout = 0; |
62 | unsigned volatile char PC_MotortestActive = 0; |
62 | unsigned volatile char PC_MotortestActive = 0; |
63 | unsigned char DebugTextAnforderung = 255; |
63 | unsigned char DebugTextAnforderung = 255; |
64 | 64 | ||
65 | unsigned char PcZugriff = 100; |
65 | unsigned char PcZugriff = 100; |
66 | unsigned char MotorTest[16]; |
66 | unsigned char MotorTest[16]; |
67 | unsigned char MeineSlaveAdresse = 1; // Flight-Ctrl |
67 | unsigned char MeineSlaveAdresse = 1; // Flight-Ctrl |
68 | unsigned char ConfirmFrame; |
68 | unsigned char ConfirmFrame; |
69 | struct str_DebugOut DebugOut; |
69 | struct str_DebugOut DebugOut; |
70 | struct str_ExternControl ExternControl; |
70 | struct str_ExternControl ExternControl; |
71 | struct str_VersionInfo VersionInfo; |
71 | struct str_VersionInfo VersionInfo; |
72 | struct str_WinkelOut WinkelOut; |
72 | struct str_WinkelOut WinkelOut; |
73 | struct str_Data3D Data3D; |
73 | struct str_Data3D Data3D; |
74 | 74 | ||
75 | int Display_Timer, Debug_Timer,Kompass_Timer,Timer3D; |
75 | int Display_Timer, Debug_Timer,Kompass_Timer,Timer3D; |
76 | unsigned int DebugDataIntervall = 0, Intervall3D = 0, Display_Interval = 0; |
76 | unsigned int DebugDataIntervall = 0, Intervall3D = 0, Display_Interval = 0; |
77 | unsigned int AboTimeOut = 0; |
77 | unsigned int AboTimeOut = 0; |
78 | 78 | ||
79 | const unsigned char ANALOG_TEXT[32][16] PROGMEM = |
79 | const unsigned char ANALOG_TEXT[32][16] PROGMEM = |
80 | { |
80 | { |
81 | //1234567890123456 |
81 | //1234567890123456 |
82 | "AngleNick ", //0 |
82 | "AngleNick ", //0 |
83 | "AngleRoll ", |
83 | "AngleRoll ", |
84 | "AccNick ", |
84 | "AccNick ", |
85 | "AccRoll ", |
85 | "AccRoll ", |
86 | "YawGyro ", |
86 | "YawGyro ", |
87 | "Height Value ", //5 |
87 | "Height Value ", //5 |
88 | "AccZ ", |
88 | "AccZ ", |
89 | "Gas ", |
89 | "Gas ", |
90 | "Compass Value ", |
90 | "Compass Value ", |
91 | "Voltage [0.1V] ", |
91 | "Voltage [0.1V] ", |
92 | "Receiver Level ", //10 |
92 | "Receiver Level ", //10 |
93 | "Gyro Compass ", |
93 | "Gyro Compass ", |
94 | "Motor 1 ", |
94 | "Motor 1 ", |
95 | "Motor 2 ", |
95 | "Motor 2 ", |
96 | "Motor 3 ", |
96 | "Motor 3 ", |
97 | "Motor 4 ", //15 |
97 | "Motor 4 ", //15 |
98 | "16 ", |
98 | "16 ", |
99 | "17 ", |
99 | "17 ", |
100 | "18 ", |
100 | "18 ", |
101 | "19 ", |
101 | "19 ", |
102 | "Servo ", //20 |
102 | "Servo ", //20 |
103 | "Hovergas ", |
103 | "Hovergas ", |
104 | "Current [0.1A] ", |
104 | "Current [0.1A] ", |
105 | "Capacity [mAh] ", |
105 | "Capacity [mAh] ", |
106 | "24 ", |
106 | "24 ", |
107 | "25 ", //25 |
107 | "25 ", //25 |
108 | "26 ", |
108 | "26 ", |
109 | "27 ", |
109 | "27 ", |
110 | "I2C-Error ", |
110 | "I2C-Error ", |
111 | "BL Limit ", |
111 | "BL Limit ", |
112 | "GPS_Nick ", //30 |
112 | "GPS_Nick ", //30 |
113 | "GPS_Roll " |
113 | "GPS_Roll " |
114 | }; |
114 | }; |
115 | 115 | ||
116 | 116 | ||
117 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
117 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
118 | //++ Sende-Part der Datenübertragung |
118 | //++ Sende-Part der Datenübertragung |
119 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
119 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
120 | ISR(USART0_TX_vect) |
120 | ISR(USART0_TX_vect) |
121 | { |
121 | { |
122 | static unsigned int ptr = 0; |
122 | static unsigned int ptr = 0; |
123 | unsigned char tmp_tx; |
123 | unsigned char tmp_tx; |
124 | if(!UebertragungAbgeschlossen) |
124 | if(!UebertragungAbgeschlossen) |
125 | { |
125 | { |
126 | ptr++; // die [0] wurde schon gesendet |
126 | ptr++; // die [0] wurde schon gesendet |
127 | tmp_tx = TxdBuffer[ptr]; |
127 | tmp_tx = TxdBuffer[ptr]; |
128 | if((tmp_tx == '\r') || (ptr == MAX_SENDE_BUFF)) |
128 | if((tmp_tx == '\r') || (ptr == MAX_SENDE_BUFF)) |
129 | { |
129 | { |
130 | ptr = 0; |
130 | ptr = 0; |
131 | UebertragungAbgeschlossen = 1; |
131 | UebertragungAbgeschlossen = 1; |
132 | } |
132 | } |
133 | UDR0 = tmp_tx; |
133 | UDR0 = tmp_tx; |
134 | } |
134 | } |
135 | else ptr = 0; |
135 | else ptr = 0; |
136 | } |
136 | } |
137 | 137 | ||
138 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
138 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
139 | //++ Empfangs-Part der Datenübertragung, incl. CRC-Auswertung |
139 | //++ Empfangs-Part der Datenübertragung, incl. CRC-Auswertung |
140 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
140 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
141 | ISR(USART0_RX_vect) |
141 | ISR(USART0_RX_vect) |
142 | { |
142 | { |
143 | static unsigned int crc; |
143 | static unsigned int crc; |
144 | static unsigned char crc1,crc2,buf_ptr; |
144 | static unsigned char crc1,crc2,buf_ptr; |
145 | static unsigned char UartState = 0; |
145 | static unsigned char UartState = 0; |
146 | unsigned char CrcOkay = 0; |
146 | unsigned char CrcOkay = 0; |
147 | 147 | ||
148 | SioTmp = UDR0; |
148 | SioTmp = UDR0; |
149 | if(buf_ptr >= MAX_SENDE_BUFF) UartState = 0; |
149 | if(buf_ptr >= MAX_SENDE_BUFF) UartState = 0; |
150 | if(SioTmp == '\r' && UartState == 2) |
150 | if(SioTmp == '\r' && UartState == 2) |
151 | { |
151 | { |
152 | UartState = 0; |
152 | UartState = 0; |
153 | crc -= RxdBuffer[buf_ptr-2]; |
153 | crc -= RxdBuffer[buf_ptr-2]; |
154 | crc -= RxdBuffer[buf_ptr-1]; |
154 | crc -= RxdBuffer[buf_ptr-1]; |
155 | crc %= 4096; |
155 | crc %= 4096; |
156 | crc1 = '=' + crc / 64; |
156 | crc1 = '=' + crc / 64; |
157 | crc2 = '=' + crc % 64; |
157 | crc2 = '=' + crc % 64; |
158 | CrcOkay = 0; |
158 | CrcOkay = 0; |
159 | if((crc1 == RxdBuffer[buf_ptr-2]) && (crc2 == RxdBuffer[buf_ptr-1])) CrcOkay = 1; else { CrcOkay = 0; CntCrcError++;}; |
159 | if((crc1 == RxdBuffer[buf_ptr-2]) && (crc2 == RxdBuffer[buf_ptr-1])) CrcOkay = 1; else { CrcOkay = 0; CntCrcError++;}; |
160 | if(!NeuerDatensatzEmpfangen && CrcOkay) // Datensatz schon verarbeitet |
160 | if(!NeuerDatensatzEmpfangen && CrcOkay) // Datensatz schon verarbeitet |
161 | { |
161 | { |
162 | NeuerDatensatzEmpfangen = 1; |
162 | NeuerDatensatzEmpfangen = 1; |
163 | AnzahlEmpfangsBytes = buf_ptr + 1; |
163 | AnzahlEmpfangsBytes = buf_ptr + 1; |
164 | RxdBuffer[buf_ptr] = '\r'; |
164 | RxdBuffer[buf_ptr] = '\r'; |
165 | if(RxdBuffer[2] == 'R') |
165 | if(RxdBuffer[2] == 'R') |
166 | { |
166 | { |
167 | LcdClear(); |
167 | LcdClear(); |
168 | wdt_enable(WDTO_250MS); // Reset-Commando |
168 | wdt_enable(WDTO_250MS); // Reset-Commando |
169 | ServoActive = 0; |
169 | ServoActive = 0; |
170 | 170 | ||
171 | } |
171 | } |
172 | } |
172 | } |
173 | } |
173 | } |
174 | else |
174 | else |
175 | switch(UartState) |
175 | switch(UartState) |
176 | { |
176 | { |
177 | case 0: |
177 | case 0: |
178 | if(SioTmp == '#' && !NeuerDatensatzEmpfangen) UartState = 1; // Startzeichen und Daten schon verarbeitet |
178 | if(SioTmp == '#' && !NeuerDatensatzEmpfangen) UartState = 1; // Startzeichen und Daten schon verarbeitet |
179 | buf_ptr = 0; |
179 | buf_ptr = 0; |
180 | RxdBuffer[buf_ptr++] = SioTmp; |
180 | RxdBuffer[buf_ptr++] = SioTmp; |
181 | crc = SioTmp; |
181 | crc = SioTmp; |
182 | break; |
182 | break; |
183 | case 1: // Adresse auswerten |
183 | case 1: // Adresse auswerten |
184 | UartState++; |
184 | UartState++; |
185 | RxdBuffer[buf_ptr++] = SioTmp; |
185 | RxdBuffer[buf_ptr++] = SioTmp; |
186 | crc += SioTmp; |
186 | crc += SioTmp; |
187 | break; |
187 | break; |
188 | case 2: // Eingangsdaten sammeln |
188 | case 2: // Eingangsdaten sammeln |
189 | RxdBuffer[buf_ptr] = SioTmp; |
189 | RxdBuffer[buf_ptr] = SioTmp; |
190 | if(buf_ptr < MAX_EMPFANGS_BUFF) buf_ptr++; |
190 | if(buf_ptr < MAX_EMPFANGS_BUFF) buf_ptr++; |
191 | else UartState = 0; |
191 | else UartState = 0; |
192 | crc += SioTmp; |
192 | crc += SioTmp; |
193 | break; |
193 | break; |
194 | default: |
194 | default: |
195 | UartState = 0; |
195 | UartState = 0; |
196 | break; |
196 | break; |
197 | } |
197 | } |
198 | } |
198 | } |
199 | 199 | ||
200 | 200 | ||
201 | // -------------------------------------------------------------------------- |
201 | // -------------------------------------------------------------------------- |
202 | void AddCRC(unsigned int wieviele) |
202 | void AddCRC(unsigned int wieviele) |
203 | { |
203 | { |
204 | unsigned int tmpCRC = 0,i; |
204 | unsigned int tmpCRC = 0,i; |
205 | for(i = 0; i < wieviele;i++) |
205 | for(i = 0; i < wieviele;i++) |
206 | { |
206 | { |
207 | tmpCRC += TxdBuffer[i]; |
207 | tmpCRC += TxdBuffer[i]; |
208 | } |
208 | } |
209 | tmpCRC %= 4096; |
209 | tmpCRC %= 4096; |
210 | TxdBuffer[i++] = '=' + tmpCRC / 64; |
210 | TxdBuffer[i++] = '=' + tmpCRC / 64; |
211 | TxdBuffer[i++] = '=' + tmpCRC % 64; |
211 | TxdBuffer[i++] = '=' + tmpCRC % 64; |
212 | TxdBuffer[i++] = '\r'; |
212 | TxdBuffer[i++] = '\r'; |
213 | UebertragungAbgeschlossen = 0; |
213 | UebertragungAbgeschlossen = 0; |
214 | UDR0 = TxdBuffer[0]; |
214 | UDR0 = TxdBuffer[0]; |
215 | } |
215 | } |
216 | 216 | ||
217 | 217 | ||
218 | 218 | ||
219 | // -------------------------------------------------------------------------- |
219 | // -------------------------------------------------------------------------- |
220 | void SendOutData(unsigned char cmd,unsigned char address, unsigned char BufferAnzahl, ...) //unsigned char *snd, unsigned char len) |
220 | void SendOutData(unsigned char cmd,unsigned char address, unsigned char BufferAnzahl, ...) //unsigned char *snd, unsigned char len) |
221 | { |
221 | { |
222 | va_list ap; |
222 | va_list ap; |
223 | unsigned int pt = 0; |
223 | unsigned int pt = 0; |
224 | unsigned char a,b,c; |
224 | unsigned char a,b,c; |
225 | unsigned char ptr = 0; |
225 | unsigned char ptr = 0; |
226 | 226 | ||
227 | unsigned char *snd = 0; |
227 | unsigned char *snd = 0; |
228 | int len = 0; |
228 | int len = 0; |
229 | 229 | ||
230 | TxdBuffer[pt++] = '#'; // Startzeichen |
230 | TxdBuffer[pt++] = '#'; // Startzeichen |
231 | TxdBuffer[pt++] = 'a' + address; // Adresse (a=0; b=1,...) |
231 | TxdBuffer[pt++] = 'a' + address; // Adresse (a=0; b=1,...) |
232 | TxdBuffer[pt++] = cmd; // Commando |
232 | TxdBuffer[pt++] = cmd; // Commando |
233 | 233 | ||
234 | va_start(ap, BufferAnzahl); |
234 | va_start(ap, BufferAnzahl); |
235 | if(BufferAnzahl) |
235 | if(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 | while(len) |
242 | while(len) |
243 | { |
243 | { |
244 | if(len) |
244 | if(len) |
245 | { |
245 | { |
246 | a = snd[ptr++]; |
246 | a = 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 a = 0; |
256 | else a = 0; |
257 | if(len) |
257 | if(len) |
258 | { |
258 | { |
259 | b = snd[ptr++]; |
259 | b = snd[ptr++]; |
260 | len--; |
260 | len--; |
261 | if((!len) && BufferAnzahl) |
261 | if((!len) && BufferAnzahl) |
262 | { |
262 | { |
263 | snd = va_arg(ap, unsigned char*); |
263 | snd = va_arg(ap, unsigned char*); |
264 | len = va_arg(ap, int); |
264 | len = va_arg(ap, int); |
265 | ptr = 0; |
265 | ptr = 0; |
266 | BufferAnzahl--; |
266 | BufferAnzahl--; |
267 | } |
267 | } |
268 | } |
268 | } |
269 | else b = 0; |
269 | else b = 0; |
270 | if(len) |
270 | if(len) |
271 | { |
271 | { |
272 | c = snd[ptr++]; |
272 | c = snd[ptr++]; |
273 | len--; |
273 | len--; |
274 | if((!len) && BufferAnzahl) |
274 | if((!len) && BufferAnzahl) |
275 | { |
275 | { |
276 | snd = va_arg(ap, unsigned char*); |
276 | snd = va_arg(ap, unsigned char*); |
277 | len = va_arg(ap, int); |
277 | len = va_arg(ap, int); |
278 | ptr = 0; |
278 | ptr = 0; |
279 | BufferAnzahl--; |
279 | BufferAnzahl--; |
280 | } |
280 | } |
281 | } |
281 | } |
282 | else c = 0; |
282 | else c = 0; |
283 | TxdBuffer[pt++] = '=' + (a >> 2); |
283 | TxdBuffer[pt++] = '=' + (a >> 2); |
284 | TxdBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
284 | TxdBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
285 | TxdBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
285 | TxdBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
286 | TxdBuffer[pt++] = '=' + ( c & 0x3f); |
286 | TxdBuffer[pt++] = '=' + ( c & 0x3f); |
287 | } |
287 | } |
288 | va_end(ap); |
288 | va_end(ap); |
289 | AddCRC(pt); |
289 | AddCRC(pt); |
290 | } |
290 | } |
291 | 291 | ||
292 | // -------------------------------------------------------------------------- |
292 | // -------------------------------------------------------------------------- |
293 | void Decode64(void) // die daten werden im rx buffer dekodiert, das geht nur, weil aus 4 byte immer 3 gemacht werden. |
293 | void Decode64(void) // die daten werden im rx buffer dekodiert, das geht nur, weil aus 4 byte immer 3 gemacht werden. |
294 | { |
294 | { |
295 | unsigned char a,b,c,d; |
295 | unsigned char a,b,c,d; |
296 | unsigned char x,y,z; |
296 | unsigned char x,y,z; |
297 | unsigned char ptrIn = 3; // start at begin of data block |
297 | unsigned char ptrIn = 3; // start at begin of data block |
298 | unsigned char ptrOut = 3; |
298 | unsigned char ptrOut = 3; |
299 | 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. |
299 | 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. |
300 | 300 | ||
301 | while(len) |
301 | while(len) |
302 | { |
302 | { |
303 | a = RxdBuffer[ptrIn++] - '='; |
303 | a = RxdBuffer[ptrIn++] - '='; |
304 | b = RxdBuffer[ptrIn++] - '='; |
304 | b = RxdBuffer[ptrIn++] - '='; |
305 | c = RxdBuffer[ptrIn++] - '='; |
305 | c = RxdBuffer[ptrIn++] - '='; |
306 | d = RxdBuffer[ptrIn++] - '='; |
306 | d = RxdBuffer[ptrIn++] - '='; |
307 | 307 | ||
308 | x = (a << 2) | (b >> 4); |
308 | x = (a << 2) | (b >> 4); |
309 | y = ((b & 0x0f) << 4) | (c >> 2); |
309 | y = ((b & 0x0f) << 4) | (c >> 2); |
310 | z = ((c & 0x03) << 6) | d; |
310 | z = ((c & 0x03) << 6) | d; |
311 | 311 | ||
312 | if(len--) RxdBuffer[ptrOut++] = x; else break; |
312 | if(len--) RxdBuffer[ptrOut++] = x; else break; |
313 | if(len--) RxdBuffer[ptrOut++] = y; else break; |
313 | if(len--) RxdBuffer[ptrOut++] = y; else break; |
314 | if(len--) RxdBuffer[ptrOut++] = z; else break; |
314 | if(len--) RxdBuffer[ptrOut++] = z; else break; |
315 | } |
315 | } |
316 | pRxData = (unsigned char*)&RxdBuffer[3]; // decodierte Daten beginnen beim 4. Byte |
316 | pRxData = (unsigned char*)&RxdBuffer[3]; // decodierte Daten beginnen beim 4. Byte |
317 | RxDataLen = ptrOut - 3; // wie viele Bytes wurden dekodiert? |
317 | RxDataLen = ptrOut - 3; // wie viele Bytes wurden dekodiert? |
318 | 318 | ||
319 | } |
319 | } |
320 | 320 | ||
321 | // -------------------------------------------------------------------------- |
321 | // -------------------------------------------------------------------------- |
322 | void BearbeiteRxDaten(void) |
322 | void BearbeiteRxDaten(void) |
323 | { |
323 | { |
324 | if(!NeuerDatensatzEmpfangen) return; |
324 | if(!NeuerDatensatzEmpfangen) return; |
325 | 325 | ||
326 | unsigned char tempchar1, tempchar2; |
326 | unsigned char tempchar1, tempchar2; |
327 | Decode64(); // dekodiere datenblock im Empfangsbuffer |
327 | Decode64(); // dekodiere datenblock im Empfangsbuffer |
328 | switch(RxdBuffer[1]-'a') // check for Slave Address |
328 | switch(RxdBuffer[1]-'a') // check for Slave Address |
329 | { |
329 | { |
330 | case FC_ADDRESS: // FC special commands |
330 | case FC_ADDRESS: // FC special commands |
331 | switch(RxdBuffer[2]) |
331 | switch(RxdBuffer[2]) |
332 | { |
332 | { |
333 | case 'K':// Kompasswert |
333 | case 'K':// Kompasswert |
334 | memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue)); |
334 | memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue)); |
335 | KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180; |
335 | KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180; |
336 | break; |
336 | break; |
337 | case 't':// Motortest |
337 | case 't':// Motortest |
338 | if(AnzahlEmpfangsBytes > 20) memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest)); |
338 | if(AnzahlEmpfangsBytes > 20) memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest)); |
339 | else memcpy(&MotorTest[0], (unsigned char *)pRxData, 4); |
339 | else memcpy(&MotorTest[0], (unsigned char *)pRxData, 4); |
340 | PC_MotortestActive = 240; |
340 | PC_MotortestActive = 240; |
341 | //while(!UebertragungAbgeschlossen); |
341 | //while(!UebertragungAbgeschlossen); |
342 | //SendOutData('T', MeineSlaveAdresse, 0); |
342 | //SendOutData('T', MeineSlaveAdresse, 0); |
343 | PcZugriff = 255; |
343 | PcZugriff = 255; |
344 | break; |
344 | break; |
345 | 345 | ||
346 | case 'n':// "Get Mixer |
346 | case 'n':// "Get Mixer |
347 | while(!UebertragungAbgeschlossen); |
347 | while(!UebertragungAbgeschlossen); |
348 | SendOutData('N', FC_ADDRESS, 1, (unsigned char *) &Mixer, sizeof(Mixer) - 1); |
348 | SendOutData('N', FC_ADDRESS, 1, (unsigned char *) &Mixer, sizeof(Mixer) - 1); |
349 | Debug("Mixer lesen"); |
349 | Debug("Mixer lesen"); |
350 | break; |
350 | break; |
351 | 351 | ||
352 | case 'm':// "Write Mixer |
352 | case 'm':// "Write Mixer |
353 | if(pRxData[0] == EEMIXER_REVISION) |
353 | if(pRxData[0] == EEMIXER_REVISION) |
354 | { |
354 | { |
355 | memcpy(&Mixer, (unsigned char *)pRxData, sizeof(Mixer) - 1); |
355 | memcpy(&Mixer, (unsigned char *)pRxData, sizeof(Mixer) - 1); |
356 | MixerTable_WriteToEEProm(); |
356 | MixerTable_WriteToEEProm(); |
357 | tempchar1 = 1; |
357 | tempchar1 = 1; |
358 | VersionInfo.HardwareError[1] &= ~DEFEKT_MIXER_ERR; |
358 | VersionInfo.HardwareError[1] &= ~DEFEKT_MIXER_ERR; |
359 | } |
359 | } |
360 | else |
360 | else |
361 | { |
361 | { |
362 | tempchar1 = 0; |
362 | tempchar1 = 0; |
363 | } |
363 | } |
364 | while(!UebertragungAbgeschlossen); |
364 | while(!UebertragungAbgeschlossen); |
365 | SendOutData('M', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1)); |
365 | SendOutData('M', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1)); |
366 | break; |
366 | break; |
367 | 367 | ||
368 | case 'p': // get PPM Channels |
368 | case 'p': // get PPM Channels |
369 | GetPPMChannelAnforderung = 1; |
369 | GetPPMChannelAnforderung = 1; |
370 | PcZugriff = 255; |
370 | PcZugriff = 255; |
371 | break; |
371 | break; |
372 | 372 | ||
373 | case 'q':// "Get"-Anforderung für Settings |
373 | case 'q':// "Get"-Anforderung für Settings |
374 | // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
374 | // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
375 | if(pRxData[0] == 0xFF) |
375 | if((10 <= pRxData[0]) && (pRxData[0] < 20)) |
376 | { |
376 | { |
- | 377 | tempchar1 = pRxData[0] - 10; |
|
- | 378 | if(tempchar1< 1) tempchar1 = 1; // limit to 1 |
|
- | 379 | else if(tempchar1 > 5) tempchar1 = 5; // limit to 5 |
|
377 | pRxData[0] = GetActiveParamSet(); |
380 | SetDefaultParameter(tempchar1, 1); |
- | 381 | } |
|
- | 382 | else if((20 <= pRxData[0]) && (pRxData[0] < 30)) |
|
- | 383 | { |
|
- | 384 | tempchar1 = pRxData[0] - 20; |
|
- | 385 | if(tempchar1< 1) tempchar1 = 1; // limit to 1 |
|
- | 386 | else if(tempchar1 > 5) tempchar1 = 5; // limit to 5 |
|
- | 387 | SetDefaultParameter(tempchar1, 0); |
|
378 | } |
388 | } |
- | 389 | else |
|
- | 390 | { |
|
- | 391 | tempchar1 = pRxData[0]; |
|
- | 392 | if(tempchar1 == 0xFF) |
|
- | 393 | { |
|
379 | // limit settings range |
394 | tempchar1 = GetActiveParamSet(); |
- | 395 | } |
|
380 | if(pRxData[0] < 1) pRxData[0] = 1; // limit to 5 |
396 | if(tempchar1< 1) tempchar1 = 1; // limit to 1 |
381 | else if(pRxData[0] > 5) pRxData[0] = 5; // limit to 5 |
397 | else if(tempchar1 > 5) tempchar1 = 5; // limit to 5 |
382 | // load requested parameter set |
398 | // load requested parameter set |
383 | ParamSet_ReadFromEEProm(pRxData[0]); |
399 | ParamSet_ReadFromEEProm(tempchar1); |
- | 400 | } |
|
384 | tempchar1 = pRxData[0]; |
401 | tempchar1 = pRxData[0]; |
385 | while(!UebertragungAbgeschlossen); |
402 | while(!UebertragungAbgeschlossen); |
386 | SendOutData('Q', FC_ADDRESS, 2, &tempchar1, sizeof(tempchar1), (unsigned char *) &EE_Parameter, sizeof(EE_Parameter) - 1); |
403 | SendOutData('Q', FC_ADDRESS, 2, &tempchar1, sizeof(tempchar1), (unsigned char *) &EE_Parameter, sizeof(EE_Parameter) - 1); |
387 | Debug("Lese Setting %d", tempchar1); |
404 | Debug("Lese Setting %d", tempchar1); |
388 | 405 | ||
389 | break; |
406 | break; |
390 | 407 | ||
391 | case 's': // Parametersatz speichern |
408 | case 's': // Parametersatz speichern |
392 | if((1 <= pRxData[0]) && (pRxData[0] <= 5) && (pRxData[1] == EEPARAM_REVISION)) // check for setting to be in range |
409 | if((1 <= pRxData[0]) && (pRxData[0] <= 5) && (pRxData[1] == EEPARAM_REVISION)) // check for setting to be in range |
393 | { |
410 | { |
394 | memcpy(&EE_Parameter, (uint8_t*)&pRxData[1], sizeof(EE_Parameter) - 1); |
411 | memcpy(&EE_Parameter, (uint8_t*)&pRxData[1], sizeof(EE_Parameter) - 1); |
395 | ParamSet_WriteToEEProm(pRxData[0]); |
412 | ParamSet_WriteToEEProm(pRxData[0]); |
396 | Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L; |
413 | Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L; |
397 | Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L; |
414 | Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L; |
398 | tempchar1 = GetActiveParamSet(); |
415 | tempchar1 = GetActiveParamSet(); |
399 | } |
416 | } |
400 | else |
417 | else |
401 | { |
418 | { |
402 | tempchar1 = 0; // mark in response an invlid setting |
419 | tempchar1 = 0; // mark in response an invlid setting |
403 | } |
420 | } |
404 | while(!UebertragungAbgeschlossen); |
421 | while(!UebertragungAbgeschlossen); |
405 | SendOutData('S', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1)); |
422 | SendOutData('S', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1)); |
406 | if(!MotorenEin) Piep(tempchar1,110); |
423 | if(!MotorenEin) Piep(tempchar1,110); |
407 | LipoDetection(0); |
424 | LipoDetection(0); |
408 | LIBFC_ReceiverInit(EE_Parameter.Receiver); |
425 | LIBFC_ReceiverInit(EE_Parameter.Receiver); |
409 | break; |
426 | break; |
410 | case 'f': // auf anderen Parametersatz umschalten |
427 | case 'f': // auf anderen Parametersatz umschalten |
411 | if((1 <= pRxData[0]) && (pRxData[0] <= 5)) ParamSet_ReadFromEEProm(pRxData[0]); |
428 | if((1 <= pRxData[0]) && (pRxData[0] <= 5)) ParamSet_ReadFromEEProm(pRxData[0]); |
412 | tempchar1 = GetActiveParamSet(); |
429 | tempchar1 = GetActiveParamSet(); |
413 | while(!UebertragungAbgeschlossen); |
430 | while(!UebertragungAbgeschlossen); |
414 | SendOutData('F', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1)); |
431 | SendOutData('F', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1)); |
415 | if(!MotorenEin) Piep(tempchar1,110); |
432 | if(!MotorenEin) Piep(tempchar1,110); |
416 | LipoDetection(0); |
433 | LipoDetection(0); |
417 | LIBFC_ReceiverInit(EE_Parameter.Receiver); |
434 | LIBFC_ReceiverInit(EE_Parameter.Receiver); |
418 | break; |
435 | break; |
419 | case 'y':// serial Potis |
436 | case 'y':// serial Potis |
420 | 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]; |
437 | 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]; |
421 | 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]; |
438 | 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]; |
422 | 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]; |
439 | 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]; |
423 | break; |
440 | break; |
424 | 441 | ||
425 | case 'u': // request BL parameter |
442 | case 'u': // request BL parameter |
426 | Debug("Reading BL %d", pRxData[0]); |
443 | Debug("Reading BL %d", pRxData[0]); |
427 | // try to read BL configuration |
444 | // try to read BL configuration |
428 | tempchar2 = I2C_ReadBLConfig(pRxData[0]); |
445 | tempchar2 = I2C_ReadBLConfig(pRxData[0]); |
429 | if(tempchar2 == BLCONFIG_SUCCESS) tempchar1 = 1; |
446 | if(tempchar2 == BLCONFIG_SUCCESS) tempchar1 = 1; |
430 | else tempchar1 = 0; |
447 | else tempchar1 = 0; |
431 | while(!UebertragungAbgeschlossen); // wait for previous frame to be sent |
448 | while(!UebertragungAbgeschlossen); // wait for previous frame to be sent |
432 | SendOutData('U', FC_ADDRESS, 4, &tempchar1, sizeof(tempchar1), &tempchar2, sizeof(tempchar2), &pRxData[0], 1, &BLConfig, sizeof(BLConfig_t)); |
449 | SendOutData('U', FC_ADDRESS, 4, &tempchar1, sizeof(tempchar1), &tempchar2, sizeof(tempchar2), &pRxData[0], 1, &BLConfig, sizeof(BLConfig_t)); |
433 | break; |
450 | break; |
434 | 451 | ||
435 | case 'w': // write BL parameter |
452 | case 'w': // write BL parameter |
436 | Debug("Writing BL %d", pRxData[0]); |
453 | Debug("Writing BL %d", pRxData[0]); |
437 | if(RxDataLen >= 1+sizeof(BLConfig_t)) |
454 | if(RxDataLen >= 1+sizeof(BLConfig_t)) |
438 | { |
455 | { |
439 | memcpy(&BLConfig, (uint8_t*)(&pRxData[1]), sizeof(BLConfig_t)); |
456 | memcpy(&BLConfig, (uint8_t*)(&pRxData[1]), sizeof(BLConfig_t)); |
440 | tempchar2 = I2C_WriteBLConfig(pRxData[0]); |
457 | tempchar2 = I2C_WriteBLConfig(pRxData[0]); |
441 | if(tempchar2 == BLCONFIG_SUCCESS) tempchar1 = 1; |
458 | if(tempchar2 == BLCONFIG_SUCCESS) tempchar1 = 1; |
442 | else tempchar1 = 0; // indicate error |
459 | else tempchar1 = 0; // indicate error |
443 | while(!UebertragungAbgeschlossen); // wait for previous frame to be sent |
460 | while(!UebertragungAbgeschlossen); // wait for previous frame to be sent |
444 | SendOutData('W', FC_ADDRESS,2, &tempchar1, sizeof(tempchar1), &tempchar2, sizeof(tempchar2)); |
461 | SendOutData('W', FC_ADDRESS,2, &tempchar1, sizeof(tempchar1), &tempchar2, sizeof(tempchar2)); |
445 | } |
462 | } |
446 | break; |
463 | break; |
447 | 464 | ||
448 | } // case FC_ADDRESS: |
465 | } // case FC_ADDRESS: |
449 | 466 | ||
450 | default: // any Slave Address |
467 | default: // any Slave Address |
451 | 468 | ||
452 | switch(RxdBuffer[2]) |
469 | switch(RxdBuffer[2]) |
453 | { |
470 | { |
454 | // 't' comand placed here only for compatibility to BL |
471 | // 't' comand placed here only for compatibility to BL |
455 | case 't':// Motortest |
472 | case 't':// Motortest |
456 | if(AnzahlEmpfangsBytes >= sizeof(MotorTest)) memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest)); |
473 | if(AnzahlEmpfangsBytes >= sizeof(MotorTest)) memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest)); |
457 | else memcpy(&MotorTest[0], (unsigned char *)pRxData, 4); |
474 | else memcpy(&MotorTest[0], (unsigned char *)pRxData, 4); |
458 | while(!UebertragungAbgeschlossen); |
475 | while(!UebertragungAbgeschlossen); |
459 | SendOutData('T', MeineSlaveAdresse, 0); |
476 | SendOutData('T', MeineSlaveAdresse, 0); |
460 | PC_MotortestActive = 250; |
477 | PC_MotortestActive = 250; |
461 | PcZugriff = 255; |
478 | PcZugriff = 255; |
462 | AboTimeOut = SetDelay(ABO_TIMEOUT); |
479 | AboTimeOut = SetDelay(ABO_TIMEOUT); |
463 | break; |
480 | break; |
464 | // 'K' comand placed here only for compatibility to old MK3MAG software, that does not send the right Slave Address |
481 | // 'K' comand placed here only for compatibility to old MK3MAG software, that does not send the right Slave Address |
465 | case 'K':// Kompasswert |
482 | case 'K':// Kompasswert |
466 | memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue)); |
483 | memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue)); |
467 | KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180; |
484 | KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180; |
468 | break; |
485 | break; |
469 | case 'a':// Texte der Analogwerte |
486 | case 'a':// Texte der Analogwerte |
470 | DebugTextAnforderung = pRxData[0]; |
487 | DebugTextAnforderung = pRxData[0]; |
471 | if (DebugTextAnforderung > 31) DebugTextAnforderung = 31; |
488 | if (DebugTextAnforderung > 31) DebugTextAnforderung = 31; |
472 | PcZugriff = 255; |
489 | PcZugriff = 255; |
473 | break; |
490 | break; |
474 | case 'b': |
491 | case 'b': |
475 | memcpy((unsigned char *)&ExternControl, (unsigned char *)pRxData, sizeof(ExternControl)); |
492 | memcpy((unsigned char *)&ExternControl, (unsigned char *)pRxData, sizeof(ExternControl)); |
476 | ConfirmFrame = ExternControl.Frame; |
493 | ConfirmFrame = ExternControl.Frame; |
477 | PcZugriff = 255; |
494 | PcZugriff = 255; |
478 | break; |
495 | break; |
479 | case 'c': // Poll the 3D-Data |
496 | case 'c': // Poll the 3D-Data |
480 | if(!Intervall3D) { if(pRxData[0]) Timer3D = SetDelay(pRxData[0] * 10);} |
497 | if(!Intervall3D) { if(pRxData[0]) Timer3D = SetDelay(pRxData[0] * 10);} |
481 | Intervall3D = pRxData[0] * 10; |
498 | Intervall3D = pRxData[0] * 10; |
482 | AboTimeOut = SetDelay(ABO_TIMEOUT); |
499 | AboTimeOut = SetDelay(ABO_TIMEOUT); |
483 | break; |
500 | break; |
484 | case 'd': // Poll the debug data |
501 | case 'd': // Poll the debug data |
485 | PcZugriff = 255; |
502 | PcZugriff = 255; |
486 | DebugDataIntervall = (unsigned int)pRxData[0] * 10; |
503 | DebugDataIntervall = (unsigned int)pRxData[0] * 10; |
487 | if(DebugDataIntervall > 0) DebugDataAnforderung = 1; |
504 | if(DebugDataIntervall > 0) DebugDataAnforderung = 1; |
488 | AboTimeOut = SetDelay(ABO_TIMEOUT); |
505 | AboTimeOut = SetDelay(ABO_TIMEOUT); |
489 | break; |
506 | break; |
490 | 507 | ||
491 | case 'h':// x-1 Displayzeilen |
508 | case 'h':// x-1 Displayzeilen |
492 | PcZugriff = 255; |
509 | PcZugriff = 255; |
493 | if((pRxData[0] & 0x80) == 0x00) // old format |
510 | if((pRxData[0] & 0x80) == 0x00) // old format |
494 | { |
511 | { |
495 | DisplayLine = 2; |
512 | DisplayLine = 2; |
496 | Display_Interval = 0; |
513 | Display_Interval = 0; |
497 | } |
514 | } |
498 | else // new format |
515 | else // new format |
499 | { |
516 | { |
500 | RemoteKeys |= ~pRxData[0]; |
517 | RemoteKeys |= ~pRxData[0]; |
501 | Display_Interval = (unsigned int)pRxData[1] * 10; |
518 | Display_Interval = (unsigned int)pRxData[1] * 10; |
502 | DisplayLine = 4; |
519 | DisplayLine = 4; |
503 | AboTimeOut = SetDelay(ABO_TIMEOUT); |
520 | AboTimeOut = SetDelay(ABO_TIMEOUT); |
504 | } |
521 | } |
505 | DebugDisplayAnforderung = 1; |
522 | DebugDisplayAnforderung = 1; |
506 | break; |
523 | break; |
507 | 524 | ||
508 | case 'l':// x-1 Displayzeilen |
525 | case 'l':// x-1 Displayzeilen |
509 | PcZugriff = 255; |
526 | PcZugriff = 255; |
510 | MenuePunkt = pRxData[0]; |
527 | MenuePunkt = pRxData[0]; |
511 | DebugDisplayAnforderung1 = 1; |
528 | DebugDisplayAnforderung1 = 1; |
512 | break; |
529 | break; |
513 | case 'v': // Version-Anforderung und Ausbaustufe |
530 | case 'v': // Version-Anforderung und Ausbaustufe |
514 | GetVersionAnforderung = 1; |
531 | GetVersionAnforderung = 1; |
515 | break; |
532 | break; |
516 | 533 | ||
517 | case 'g':// |
534 | case 'g':// |
518 | GetExternalControl = 1; |
535 | GetExternalControl = 1; |
519 | break; |
536 | break; |
520 | 537 | ||
521 | default: |
538 | default: |
522 | //unsupported command received |
539 | //unsupported command received |
523 | break; |
540 | break; |
524 | } |
541 | } |
525 | break; // default: |
542 | break; // default: |
526 | } |
543 | } |
527 | NeuerDatensatzEmpfangen = 0; |
544 | NeuerDatensatzEmpfangen = 0; |
528 | pRxData = 0; |
545 | pRxData = 0; |
529 | RxDataLen = 0; |
546 | RxDataLen = 0; |
530 | } |
547 | } |
531 | 548 | ||
532 | //############################################################################ |
549 | //############################################################################ |
533 | //Routine für die Serielle Ausgabe |
550 | //Routine für die Serielle Ausgabe |
534 | void uart_putchar (char c) |
551 | void uart_putchar (char c) |
535 | //############################################################################ |
552 | //############################################################################ |
536 | { |
553 | { |
537 | //Warten solange bis Zeichen gesendet wurde |
554 | //Warten solange bis Zeichen gesendet wurde |
538 | loop_until_bit_is_set(UCSR0A, UDRE0); |
555 | loop_until_bit_is_set(UCSR0A, UDRE0); |
539 | //Ausgabe des Zeichens |
556 | //Ausgabe des Zeichens |
540 | UDR0 = c; |
557 | UDR0 = c; |
541 | } |
558 | } |
542 | 559 | ||
543 | 560 | ||
544 | //############################################################################ |
561 | //############################################################################ |
545 | //INstallation der Seriellen Schnittstelle |
562 | //INstallation der Seriellen Schnittstelle |
546 | void UART_Init (void) |
563 | void UART_Init (void) |
547 | //############################################################################ |
564 | //############################################################################ |
548 | { |
565 | { |
549 | unsigned int ubrr = (unsigned int) ((unsigned long) F_CPU/(8 * USART0_BAUD) - 1); |
566 | unsigned int ubrr = (unsigned int) ((unsigned long) F_CPU/(8 * USART0_BAUD) - 1); |
550 | 567 | ||
551 | //Enable TXEN im Register UCR TX-Data Enable & RX Enable |
568 | //Enable TXEN im Register UCR TX-Data Enable & RX Enable |
552 | UCSR0B = (1 << TXEN0) | (1 << RXEN0); |
569 | UCSR0B = (1 << TXEN0) | (1 << RXEN0); |
553 | // UART Double Speed (U2X) |
570 | // UART Double Speed (U2X) |
554 | UCSR0A |= (1 << U2X0); |
571 | UCSR0A |= (1 << U2X0); |
555 | // RX-Interrupt Freigabe |
572 | // RX-Interrupt Freigabe |
556 | UCSR0B |= (1 << RXCIE0); |
573 | UCSR0B |= (1 << RXCIE0); |
557 | // TX-Interrupt Freigabe |
574 | // TX-Interrupt Freigabe |
558 | UCSR0B |= (1 << TXCIE0); |
575 | UCSR0B |= (1 << TXCIE0); |
559 | // USART0 Baud Rate Register |
576 | // USART0 Baud Rate Register |
560 | // set clock divider |
577 | // set clock divider |
561 | UBRR0H = (uint8_t)(ubrr >> 8); |
578 | UBRR0H = (uint8_t)(ubrr >> 8); |
562 | UBRR0L = (uint8_t)ubrr; |
579 | UBRR0L = (uint8_t)ubrr; |
563 | 580 | ||
564 | Debug_Timer = SetDelay(DebugDataIntervall); |
581 | Debug_Timer = SetDelay(DebugDataIntervall); |
565 | Kompass_Timer = SetDelay(220); |
582 | Kompass_Timer = SetDelay(220); |
566 | 583 | ||
567 | VersionInfo.SWMajor = VERSION_MAJOR; |
584 | VersionInfo.SWMajor = VERSION_MAJOR; |
568 | VersionInfo.SWMinor = VERSION_MINOR; |
585 | VersionInfo.SWMinor = VERSION_MINOR; |
569 | VersionInfo.SWPatch = VERSION_PATCH; |
586 | VersionInfo.SWPatch = VERSION_PATCH; |
570 | VersionInfo.ProtoMajor = VERSION_SERIAL_MAJOR; |
587 | VersionInfo.ProtoMajor = VERSION_SERIAL_MAJOR; |
571 | VersionInfo.ProtoMinor = VERSION_SERIAL_MINOR; |
588 | VersionInfo.ProtoMinor = VERSION_SERIAL_MINOR; |
572 | 589 | ||
573 | pRxData = 0; |
590 | pRxData = 0; |
574 | RxDataLen = 0; |
591 | RxDataLen = 0; |
575 | } |
592 | } |
576 | 593 | ||
577 | //--------------------------------------------------------------------------------------------- |
594 | //--------------------------------------------------------------------------------------------- |
578 | void DatenUebertragung(void) |
595 | void DatenUebertragung(void) |
579 | { |
596 | { |
580 | if(!UebertragungAbgeschlossen) return; |
597 | if(!UebertragungAbgeschlossen) return; |
581 | 598 | ||
582 | if(CheckDelay(AboTimeOut)) |
599 | if(CheckDelay(AboTimeOut)) |
583 | { |
600 | { |
584 | Display_Interval = 0; |
601 | Display_Interval = 0; |
585 | DebugDataIntervall = 0; |
602 | DebugDataIntervall = 0; |
586 | Intervall3D = 0; |
603 | Intervall3D = 0; |
587 | } |
604 | } |
588 | 605 | ||
589 | if(((Display_Interval>0 && CheckDelay(Display_Timer)) || DebugDisplayAnforderung) && UebertragungAbgeschlossen) |
606 | if(((Display_Interval>0 && CheckDelay(Display_Timer)) || DebugDisplayAnforderung) && UebertragungAbgeschlossen) |
590 | { |
607 | { |
591 | if(DisplayLine > 3)// new format |
608 | if(DisplayLine > 3)// new format |
592 | { |
609 | { |
593 | Menu(); |
610 | Menu(); |
594 | SendOutData('H', FC_ADDRESS, 1, (uint8_t *)DisplayBuff, 80); |
611 | SendOutData('H', FC_ADDRESS, 1, (uint8_t *)DisplayBuff, 80); |
595 | } |
612 | } |
596 | else // old format |
613 | else // old format |
597 | { |
614 | { |
598 | LCD_printfxy(0,0,"!!! INCOMPATIBLE !!!"); |
615 | LCD_printfxy(0,0,"!!! INCOMPATIBLE !!!"); |
599 | SendOutData('H', FC_ADDRESS, 2, &DisplayLine, sizeof(DisplayLine), (uint8_t *)DisplayBuff, 20); |
616 | SendOutData('H', FC_ADDRESS, 2, &DisplayLine, sizeof(DisplayLine), (uint8_t *)DisplayBuff, 20); |
600 | if(DisplayLine++ > 3) DisplayLine = 0; |
617 | if(DisplayLine++ > 3) DisplayLine = 0; |
601 | } |
618 | } |
602 | Display_Timer = SetDelay(Display_Interval); |
619 | Display_Timer = SetDelay(Display_Interval); |
603 | DebugDisplayAnforderung = 0; |
620 | DebugDisplayAnforderung = 0; |
604 | } |
621 | } |
605 | if(DebugDisplayAnforderung1 && UebertragungAbgeschlossen) |
622 | if(DebugDisplayAnforderung1 && UebertragungAbgeschlossen) |
606 | { |
623 | { |
607 | Menu(); |
624 | Menu(); |
608 | SendOutData('L', FC_ADDRESS, 3, &MenuePunkt, sizeof(MenuePunkt), &MaxMenue, sizeof(MaxMenue), DisplayBuff, sizeof(DisplayBuff)); |
625 | SendOutData('L', FC_ADDRESS, 3, &MenuePunkt, sizeof(MenuePunkt), &MaxMenue, sizeof(MaxMenue), DisplayBuff, sizeof(DisplayBuff)); |
609 | DebugDisplayAnforderung1 = 0; |
626 | DebugDisplayAnforderung1 = 0; |
610 | } |
627 | } |
611 | if(GetVersionAnforderung && UebertragungAbgeschlossen) |
628 | if(GetVersionAnforderung && UebertragungAbgeschlossen) |
612 | { |
629 | { |
613 | SendOutData('V', FC_ADDRESS, 1, (unsigned char *) &VersionInfo, sizeof(VersionInfo)); |
630 | SendOutData('V', FC_ADDRESS, 1, (unsigned char *) &VersionInfo, sizeof(VersionInfo)); |
614 | GetVersionAnforderung = 0; |
631 | GetVersionAnforderung = 0; |
615 | Debug_OK("Version gesendet"); |
632 | Debug_OK("Version gesendet"); |
616 | } |
633 | } |
617 | 634 | ||
618 | if(GetExternalControl && UebertragungAbgeschlossen) // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
635 | if(GetExternalControl && UebertragungAbgeschlossen) // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
619 | { |
636 | { |
620 | SendOutData('G',MeineSlaveAdresse, 1, (unsigned char *) &ExternControl, sizeof(ExternControl)); |
637 | SendOutData('G',MeineSlaveAdresse, 1, (unsigned char *) &ExternControl, sizeof(ExternControl)); |
621 | GetExternalControl = 0; |
638 | GetExternalControl = 0; |
622 | } |
639 | } |
623 | if((CheckDelay(Kompass_Timer)) && UebertragungAbgeschlossen) |
640 | if((CheckDelay(Kompass_Timer)) && UebertragungAbgeschlossen) |
624 | { |
641 | { |
625 | WinkelOut.Winkel[0] = (int) (IntegralNick / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
642 | WinkelOut.Winkel[0] = (int) (IntegralNick / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
626 | WinkelOut.Winkel[1] = (int) (IntegralRoll / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
643 | WinkelOut.Winkel[1] = (int) (IntegralRoll / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
627 | WinkelOut.UserParameter[0] = Parameter_UserParam1; |
644 | WinkelOut.UserParameter[0] = Parameter_UserParam1; |
628 | WinkelOut.UserParameter[1] = Parameter_UserParam2; |
645 | WinkelOut.UserParameter[1] = Parameter_UserParam2; |
629 | SendOutData('k', MK3MAG_ADDRESS, 1, (unsigned char *) &WinkelOut,sizeof(WinkelOut)); |
646 | SendOutData('k', MK3MAG_ADDRESS, 1, (unsigned char *) &WinkelOut,sizeof(WinkelOut)); |
630 | if(WinkelOut.CalcState > 4) WinkelOut.CalcState = 6; // wird dann in SPI auf Null gesetzt |
647 | if(WinkelOut.CalcState > 4) WinkelOut.CalcState = 6; // wird dann in SPI auf Null gesetzt |
631 | Kompass_Timer = SetDelay(99); |
648 | Kompass_Timer = SetDelay(99); |
632 | } |
649 | } |
633 | if(((DebugDataIntervall>0 && CheckDelay(Debug_Timer)) || DebugDataAnforderung) && UebertragungAbgeschlossen) |
650 | if(((DebugDataIntervall>0 && CheckDelay(Debug_Timer)) || DebugDataAnforderung) && UebertragungAbgeschlossen) |
634 | { |
651 | { |
635 | CopyDebugValues(); |
652 | CopyDebugValues(); |
636 | SendOutData('D', FC_ADDRESS, 1, (unsigned char *) &DebugOut,sizeof(DebugOut)); |
653 | SendOutData('D', FC_ADDRESS, 1, (unsigned char *) &DebugOut,sizeof(DebugOut)); |
637 | DebugDataAnforderung = 0; |
654 | DebugDataAnforderung = 0; |
638 | if(DebugDataIntervall>0) Debug_Timer = SetDelay(DebugDataIntervall); |
655 | if(DebugDataIntervall>0) Debug_Timer = SetDelay(DebugDataIntervall); |
639 | } |
656 | } |
640 | if(Intervall3D > 0 && CheckDelay(Timer3D) && UebertragungAbgeschlossen) |
657 | if(Intervall3D > 0 && CheckDelay(Timer3D) && UebertragungAbgeschlossen) |
641 | { |
658 | { |
642 | Data3D.Winkel[0] = (int) (IntegralNick / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
659 | Data3D.Winkel[0] = (int) (IntegralNick / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
643 | Data3D.Winkel[1] = (int) (IntegralRoll / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
660 | Data3D.Winkel[1] = (int) (IntegralRoll / (EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad |
644 | Data3D.Winkel[2] = (int) ((10 * ErsatzKompass) / GIER_GRAD_FAKTOR); |
661 | Data3D.Winkel[2] = (int) ((10 * ErsatzKompass) / GIER_GRAD_FAKTOR); |
645 | Data3D.Centroid[0] = SummeNick >> 9; |
662 | Data3D.Centroid[0] = SummeNick >> 9; |
646 | Data3D.Centroid[1] = SummeRoll >> 9; |
663 | Data3D.Centroid[1] = SummeRoll >> 9; |
647 | Data3D.Centroid[2] = Mess_Integral_Gier >> 9; |
664 | Data3D.Centroid[2] = Mess_Integral_Gier >> 9; |
648 | SendOutData('C', FC_ADDRESS, 1, (unsigned char *) &Data3D,sizeof(Data3D)); |
665 | SendOutData('C', FC_ADDRESS, 1, (unsigned char *) &Data3D,sizeof(Data3D)); |
649 | Timer3D = SetDelay(Intervall3D); |
666 | Timer3D = SetDelay(Intervall3D); |
650 | } |
667 | } |
651 | if(DebugTextAnforderung != 255) // Texte für die Analogdaten |
668 | if(DebugTextAnforderung != 255) // Texte für die Analogdaten |
652 | { |
669 | { |
653 | unsigned char label[16]; // local sram buffer |
670 | unsigned char label[16]; // local sram buffer |
654 | memcpy_P(label, ANALOG_TEXT[DebugTextAnforderung], 16); // read lable from flash to sra |
671 | memcpy_P(label, ANALOG_TEXT[DebugTextAnforderung], 16); // read lable from flash to sra |
655 | SendOutData('A', FC_ADDRESS, 2, (unsigned char *)&DebugTextAnforderung, sizeof(DebugTextAnforderung),label, 16); |
672 | SendOutData('A', FC_ADDRESS, 2, (unsigned char *)&DebugTextAnforderung, sizeof(DebugTextAnforderung),label, 16); |
656 | DebugTextAnforderung = 255; |
673 | DebugTextAnforderung = 255; |
657 | } |
674 | } |
658 | if(ConfirmFrame && UebertragungAbgeschlossen) // Datensatz bestätigen |
675 | if(ConfirmFrame && UebertragungAbgeschlossen) // Datensatz bestätigen |
659 | { |
676 | { |
660 | SendOutData('B', FC_ADDRESS, 1, (uint8_t*)&ConfirmFrame, sizeof(ConfirmFrame)); |
677 | SendOutData('B', FC_ADDRESS, 1, (uint8_t*)&ConfirmFrame, sizeof(ConfirmFrame)); |
661 | ConfirmFrame = 0; |
678 | ConfirmFrame = 0; |
662 | } |
679 | } |
663 | 680 | ||
664 | if(GetPPMChannelAnforderung && UebertragungAbgeschlossen) |
681 | if(GetPPMChannelAnforderung && UebertragungAbgeschlossen) |
665 | { |
682 | { |
666 | SendOutData('P', FC_ADDRESS, 1, (unsigned char *) &PPM_in, sizeof(PPM_in)); |
683 | SendOutData('P', FC_ADDRESS, 1, (unsigned char *) &PPM_in, sizeof(PPM_in)); |
667 | GetPPMChannelAnforderung = 0; |
684 | GetPPMChannelAnforderung = 0; |
668 | } |
685 | } |
669 | 686 | ||
670 | #ifdef DEBUG // only include functions if DEBUG is defined |
687 | #ifdef DEBUG // only include functions if DEBUG is defined |
671 | if(SendDebugOutput && UebertragungAbgeschlossen) |
688 | if(SendDebugOutput && UebertragungAbgeschlossen) |
672 | { |
689 | { |
673 | SendOutData('0', FC_ADDRESS, 1, (unsigned char *) &tDebug, sizeof(tDebug)); |
690 | SendOutData('0', FC_ADDRESS, 1, (unsigned char *) &tDebug, sizeof(tDebug)); |
674 | SendDebugOutput = 0; |
691 | SendDebugOutput = 0; |
675 | } |
692 | } |
676 | #endif |
693 | #endif |
677 | 694 | ||
678 | } |
695 | } |
679 | 696 | ||
680 | 697 | ||
681 | 698 |