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