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