Rev 18 | Rev 21 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
12 | hbuss | 1 | /*####################################################################################### |
2 | MK3Mag 3D-Magnet sensor |
||
19 | killagreg | 3 | !!! THIS IS NOT FREE SOFTWARE !!! |
12 | hbuss | 4 | #######################################################################################*/ |
5 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
6 | // + Copyright (c) 05.2008 Holger Buss |
||
7 | // + Thanks to Ilja Fähnrich (P_Latzhalter) |
||
1 | ingob | 8 | // + Nur für den privaten Gebrauch |
12 | hbuss | 9 | // + www.MikroKopter.com |
10 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
19 | killagreg | 11 | // + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
12 | hbuss | 12 | // + mit unserer Zustimmung zulässig |
13 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
19 | killagreg | 14 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
15 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
||
12 | hbuss | 16 | // + AUSNAHME: Ein bei www.mikrokopter.de erworbener vorbestückter MK3Mag darf als Baugruppe auch in kommerziellen Systemen verbaut werden |
17 | // + Im Zweifelsfall bitte anfragen bei: info@mikrokopter.de |
||
18 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
19 | killagreg | 19 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
12 | hbuss | 20 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
21 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
22 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
||
23 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
||
24 | // + eindeutig als Ursprung verlinkt werden |
||
25 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
26 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
||
27 | // + Benutzung auf eigene Gefahr |
||
28 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
||
29 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
30 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
||
31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
19 | killagreg | 32 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
12 | hbuss | 33 | // + this list of conditions and the following disclaimer. |
34 | // + * PORTING this software (or parts of it) to systems (other than hardware from www.mikrokopter.de) is NOT allowed |
||
35 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
||
36 | // + from this software without specific prior written permission. |
||
19 | killagreg | 37 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet |
12 | hbuss | 38 | // + for non-commercial use (directly or indirectly) |
19 | killagreg | 39 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
12 | hbuss | 40 | // + with our written permission |
41 | // + Exception: A preassembled MK3Mag, purchased from www.mikrokopter.de may be used as a part of commercial systems |
||
42 | // + In case of doubt please contact: info@MikroKopter.de |
||
19 | killagreg | 43 | // + * If sources or documentations are redistributet on other webpages, our webpage (http://www.MikroKopter.de) must be |
44 | // + clearly linked as origin |
||
12 | hbuss | 45 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
46 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||
47 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||
48 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
||
49 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
||
50 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
||
51 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
||
52 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
||
53 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
||
54 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
||
19 | killagreg | 55 | // + POSSIBILITY OF SUCH DAMAGE. |
12 | hbuss | 56 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
19 | killagreg | 57 | #include <avr/io.h> |
58 | #include <avr/interrupt.h> |
||
59 | #include <avr/wdt.h> |
||
1 | ingob | 60 | #include "main.h" |
61 | #include "uart.h" |
||
19 | killagreg | 62 | #include "timer0.h" |
63 | #include "twislave.h" |
||
1 | ingob | 64 | |
65 | |||
19 | killagreg | 66 | #define FALSE 0 |
67 | #define TRUE 1 |
||
1 | ingob | 68 | |
19 | killagreg | 69 | #define TXD_BUFFER_LEN 100 |
70 | #define RXD_BUFFER_LEN 100 |
||
1 | ingob | 71 | |
19 | killagreg | 72 | volatile uint8_t txd_buffer[TXD_BUFFER_LEN]; |
73 | volatile uint8_t rxd_buffer_locked = FALSE; |
||
74 | volatile uint8_t rxd_buffer[RXD_BUFFER_LEN]; |
||
75 | volatile uint8_t txd_complete = TRUE; |
||
76 | volatile uint8_t ReceivedBytes = 0; |
||
1 | ingob | 77 | |
19 | killagreg | 78 | uint8_t RequestVerInfo = FALSE; |
79 | uint8_t RequestDebugData = FALSE; |
||
80 | uint8_t RequestDebugLabel = FALSE; |
||
81 | uint8_t RequestCompassHeading = FALSE; |
||
3 | ingob | 82 | |
19 | killagreg | 83 | uint8_t MySlaveAddr = 0; |
1 | ingob | 84 | |
19 | killagreg | 85 | //unsigned char,DebugGetAnforderung = 0, |
86 | |||
87 | DebugOut_t DebugOut; |
||
88 | ExternData_t ExternData; |
||
89 | ExternControl_t ExternControl; |
||
90 | VersionInfo_t VersionInfo; |
||
91 | |||
92 | uint16_t Debug_Timer; |
||
93 | |||
94 | const uint8_t ANALOG_LABEL[32][16] = |
||
1 | ingob | 95 | { |
7 | hbuss | 96 | //1234567890123456 |
19 | killagreg | 97 | "Magnet X ", //0 |
98 | "Magnet Y ", |
||
7 | hbuss | 99 | "Magnet Z ", |
19 | killagreg | 100 | "Raw X ", |
101 | "Raw Y ", |
||
102 | "Raw Z ", //5 |
||
103 | "Attitude Nick ", |
||
104 | "Attitude Roll ", |
||
105 | "XOffset ", |
||
106 | "XRange ", |
||
107 | "YOffset ", //10 |
||
108 | "YRange ", |
||
109 | "ZOffset ", |
||
110 | "ZRange ", |
||
7 | hbuss | 111 | "Calstate ", |
19 | killagreg | 112 | "Heading Request ", //15 |
5 | hbuss | 113 | "User0 ", |
114 | "User1 ", |
||
7 | hbuss | 115 | "Analog18 ", |
116 | "Analog19 ", |
||
117 | "Analog20 ", //20 |
||
19 | killagreg | 118 | "Analog21 ", |
7 | hbuss | 119 | "Analog22 ", |
120 | "Analog23 ", |
||
121 | "Analog24 ", |
||
122 | "Analog25 ", //25 |
||
1 | ingob | 123 | "Analog26 ", |
7 | hbuss | 124 | "Analog27 ", |
125 | "Analog28 ", |
||
126 | "Analog29 ", |
||
127 | "Analog30 ", //30 |
||
128 | "Analog31 " |
||
1 | ingob | 129 | }; |
130 | |||
131 | |||
19 | killagreg | 132 | /****************************************************************/ |
133 | /* Initialization of the USART0 */ |
||
134 | /****************************************************************/ |
||
135 | void USART0_Init (void) |
||
136 | { |
||
137 | uint8_t sreg = SREG; |
||
7 | hbuss | 138 | |
19 | killagreg | 139 | uint16_t ubrr = (uint16_t) ((uint32_t) SYSCLK/(8 * BAUD_RATE) - 1); |
140 | |||
141 | // disable all interrupts before configuration |
||
142 | cli(); |
||
143 | |||
144 | // disable RX-Interrupt |
||
145 | UCSR0B &= ~(1 << RXCIE0); |
||
146 | // disable TX-Interrupt |
||
147 | UCSR0B &= ~(1 << TXCIE0); |
||
148 | |||
149 | // set direction of RXD0 and TXD0 pins |
||
150 | |||
151 | // set RXD0 (PD0) as an input pin |
||
152 | PORTD |= (1 << PORTD0); |
||
153 | DDRD &= ~(1 << DDD0); |
||
154 | // set TXD0 (PD1) as an output pin |
||
155 | PORTD |= (1 << PORTD1); |
||
156 | DDRD |= (1 << DDD1); |
||
157 | |||
158 | // USART0 Baud Rate Register |
||
159 | // set clock divider |
||
160 | UBRR0H = (uint8_t)(ubrr >> 8); |
||
161 | UBRR0L = (uint8_t)ubrr; |
||
162 | |||
163 | // USART0 Control and Status Register A, B, C |
||
164 | |||
165 | // enable double speed operation in |
||
166 | UCSR0A |= (1 << U2X0); |
||
167 | // enable receiver and transmitter in |
||
168 | UCSR0B |= (1 << TXEN0) | (1 << RXEN0); |
||
169 | // set asynchronous mode |
||
170 | UCSR0C &= ~(1 << UMSEL01); |
||
171 | UCSR0C &= ~(1 << UMSEL00); |
||
172 | // no parity |
||
173 | UCSR0C &= ~(1 << UPM01); |
||
174 | UCSR0C &= ~(1 << UPM00); |
||
175 | // 1 stop bit |
||
176 | UCSR0C &= ~(1 << USBS0); |
||
177 | // 8-bit |
||
178 | UCSR0B &= ~(1 << UCSZ02); |
||
179 | UCSR0C |= (1 << UCSZ01); |
||
180 | UCSR0C |= (1 << UCSZ00); |
||
181 | |||
182 | // flush receive buffer |
||
183 | while ( UCSR0A & (1<<RXC0) ) UDR0; |
||
184 | |||
185 | // enable interrupts at the end |
||
186 | // enable RX-Interrupt |
||
187 | UCSR0B |= (1 << RXCIE0); |
||
188 | // enable TX-Interrupt |
||
189 | UCSR0B |= (1 << TXCIE0); |
||
190 | |||
191 | rxd_buffer_locked = FALSE; |
||
192 | txd_complete = TRUE; |
||
193 | |||
194 | Debug_Timer = SetDelay(200); |
||
195 | |||
196 | |||
197 | // restore global interrupt flags |
||
198 | SREG = sreg; |
||
199 | |||
200 | VersionInfo.Major = VERSION_MAJOR; |
||
201 | VersionInfo.Minor = VERSION_MINOR; |
||
202 | VersionInfo.PCCompatible = VERSION_COMPATIBLE; |
||
203 | |||
204 | // Version beim Start ausgeben (nicht schön, aber geht... ) |
||
205 | uart_putchar ('\n');uart_putchar ('C');uart_putchar ('P');uart_putchar (':'); |
||
206 | uart_putchar ('V');uart_putchar (0x30 + VERSION_MAJOR);uart_putchar ('.');uart_putchar (0x30 + VERSION_MINOR/10); uart_putchar (0x30 + VERSION_MINOR%10); |
||
207 | uart_putchar ('\n'); |
||
208 | } |
||
209 | |||
210 | // --------------------------------------------------------------------------------- |
||
211 | void USART0_EnableTXD(void) |
||
1 | ingob | 212 | { |
19 | killagreg | 213 | DDRD |= (1<<DDD1); // set TXD pin as output |
214 | UCSR0B |= (1 << TXEN0); // enable TX in USART |
||
1 | ingob | 215 | } |
216 | |||
19 | killagreg | 217 | // --------------------------------------------------------------------------------- |
218 | void USART0_DisableTXD(void) |
||
1 | ingob | 219 | { |
19 | killagreg | 220 | UCSR0B &= ~(1 << TXEN0); // disable TXD in USART |
221 | DDRD &= ~(1<<DDD1); // set TXD pin as input |
||
1 | ingob | 222 | } |
223 | |||
19 | killagreg | 224 | /****************************************************************/ |
225 | /* USART0 transmitter ISR */ |
||
226 | /****************************************************************/ |
||
227 | ISR(USART_TX_vect) |
||
1 | ingob | 228 | { |
19 | killagreg | 229 | static uint16_t ptr_txd_buffer = 0; |
230 | uint8_t tmp_tx; |
||
231 | if(!txd_complete) // transmission not completed |
||
232 | { |
||
233 | ptr_txd_buffer++; // die [0] wurde schon gesendet |
||
234 | tmp_tx = txd_buffer[ptr_txd_buffer]; |
||
235 | // if terminating character or end of txd buffer was reached |
||
236 | if((tmp_tx == '\r') || (ptr_txd_buffer == TXD_BUFFER_LEN)) |
||
237 | { |
||
238 | ptr_txd_buffer = 0; // reset txd pointer |
||
239 | txd_complete = 1; // stop transmission |
||
240 | } |
||
241 | UDR0 = tmp_tx; // send current byte will trigger this ISR again |
||
242 | } |
||
243 | // transmission completed |
||
244 | else ptr_txd_buffer = 0; |
||
245 | } |
||
1 | ingob | 246 | |
19 | killagreg | 247 | /****************************************************************/ |
248 | /* USART0 receiver ISR */ |
||
249 | /****************************************************************/ |
||
250 | ISR(USART_RX_vect) |
||
251 | { |
||
252 | static uint16_t crc; |
||
253 | static uint8_t ptr_rxd_buffer = 0; |
||
254 | uint8_t crc1, crc2; |
||
255 | uint8_t c; |
||
1 | ingob | 256 | |
19 | killagreg | 257 | c = UDR0; // catch the received byte |
1 | ingob | 258 | |
19 | killagreg | 259 | if(rxd_buffer_locked) return; // if rxd buffer is locked immediately return |
260 | |||
261 | // the rxd buffer is unlocked |
||
262 | if((ptr_rxd_buffer == 0) && (c == '#')) // if rxd buffer is empty and syncronisation character is received |
||
263 | { |
||
264 | rxd_buffer[ptr_rxd_buffer++] = c; // copy 1st byte to buffer |
||
265 | crc = c; // init crc |
||
266 | } |
||
267 | #if 0 |
||
268 | else if (ptr_rxd_buffer == 1) // handle address |
||
269 | { |
||
270 | rxd_buffer[ptr_rxd_buffer++] = c; // copy byte to rxd buffer |
||
271 | crc += c; // update crc |
||
272 | } |
||
273 | #endif |
||
274 | else if (ptr_rxd_buffer < RXD_BUFFER_LEN) // collect incomming bytes |
||
275 | { |
||
276 | if(c != '\r') // no termination character |
||
277 | { |
||
278 | rxd_buffer[ptr_rxd_buffer++] = c; // copy byte to rxd buffer |
||
279 | crc += c; // update crc |
||
280 | } |
||
281 | else // termination character was received |
||
282 | { |
||
283 | // the last 2 bytes are no subject for checksum calculation |
||
284 | // they are the checksum itself |
||
285 | crc -= rxd_buffer[ptr_rxd_buffer-2]; |
||
286 | crc -= rxd_buffer[ptr_rxd_buffer-1]; |
||
287 | // calculate checksum from transmitted data |
||
288 | crc %= 4096; |
||
289 | crc1 = '=' + crc / 64; |
||
290 | crc2 = '=' + crc % 64; |
||
291 | // compare checksum to transmitted checksum bytes |
||
292 | if((crc1 == rxd_buffer[ptr_rxd_buffer-2]) && (crc2 == rxd_buffer[ptr_rxd_buffer-1])) |
||
293 | { // checksum valid |
||
294 | rxd_buffer_locked = TRUE; // lock the rxd buffer |
||
295 | ReceivedBytes = ptr_rxd_buffer; // store number of received bytes |
||
296 | rxd_buffer[ptr_rxd_buffer] = '\r'; // set termination character |
||
297 | // if 2nd byte is an 'R' enable watchdog that will result in an reset |
||
298 | if(rxd_buffer[2] == 'R') {wdt_enable(WDTO_250MS);} // Reset-Commando |
||
299 | } |
||
300 | else |
||
301 | { // checksum invalid |
||
302 | rxd_buffer_locked = FALSE; // unlock rxd buffer |
||
303 | } |
||
304 | ptr_rxd_buffer = 0; // reset rxd buffer pointer |
||
305 | } |
||
306 | } |
||
307 | else // rxd buffer overrun |
||
308 | { |
||
309 | ptr_rxd_buffer = 0; // reset rxd buffer |
||
310 | rxd_buffer_locked = FALSE; // unlock rxd buffer |
||
311 | } |
||
1 | ingob | 312 | } |
313 | |||
314 | |||
19 | killagreg | 315 | // -------------------------------------------------------------------------- |
316 | void AddCRC(uint16_t datalen) |
||
1 | ingob | 317 | { |
19 | killagreg | 318 | uint16_t tmpCRC = 0, i; |
319 | for(i = 0; i < datalen; i++) |
||
320 | { |
||
321 | tmpCRC += txd_buffer[i]; |
||
322 | } |
||
323 | tmpCRC %= 4096; |
||
324 | txd_buffer[i++] = '=' + tmpCRC / 64; |
||
325 | txd_buffer[i++] = '=' + tmpCRC % 64; |
||
326 | txd_buffer[i++] = '\r'; |
||
327 | txd_complete = FALSE; |
||
328 | UDR0 = txd_buffer[0]; // initiates the transmission (continued in the TXD ISR) |
||
329 | } |
||
1 | ingob | 330 | |
331 | |||
332 | |||
333 | // -------------------------------------------------------------------------- |
||
19 | killagreg | 334 | void SendOutData(uint8_t cmd,uint8_t module, uint8_t *snd, uint8_t len) |
1 | ingob | 335 | { |
19 | killagreg | 336 | uint16_t pt = 0; |
337 | uint8_t a,b,c; |
||
338 | uint8_t ptr = 0; |
||
339 | |||
340 | txd_buffer[pt++] = '#'; // Start character |
||
341 | txd_buffer[pt++] = module; // Address (a=0; b=1,...) |
||
342 | txd_buffer[pt++] = cmd; // Command |
||
343 | |||
344 | while(len) |
||
345 | { |
||
346 | if(len) { a = snd[ptr++]; len--;} else a = 0; |
||
347 | if(len) { b = snd[ptr++]; len--;} else b = 0; |
||
348 | if(len) { c = snd[ptr++]; len--;} else c = 0; |
||
349 | txd_buffer[pt++] = '=' + (a >> 2); |
||
350 | txd_buffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
||
351 | txd_buffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
||
352 | txd_buffer[pt++] = '=' + ( c & 0x3f); |
||
353 | } |
||
354 | AddCRC(pt); // add checksum after data block and initates the transmission |
||
1 | ingob | 355 | } |
356 | |||
357 | |||
358 | // -------------------------------------------------------------------------- |
||
19 | killagreg | 359 | void Decode64(uint8_t *ptrOut, uint8_t len, uint8_t ptrIn, uint8_t max) |
1 | ingob | 360 | { |
19 | killagreg | 361 | uint8_t a,b,c,d; |
362 | uint8_t ptr = 0; |
||
363 | uint8_t x,y,z; |
||
364 | while(len) |
||
365 | { |
||
366 | a = rxd_buffer[ptrIn++] - '='; |
||
367 | b = rxd_buffer[ptrIn++] - '='; |
||
368 | c = rxd_buffer[ptrIn++] - '='; |
||
369 | d = rxd_buffer[ptrIn++] - '='; |
||
370 | if(ptrIn > max - 2) break; |
||
1 | ingob | 371 | |
19 | killagreg | 372 | x = (a << 2) | (b >> 4); |
373 | y = ((b & 0x0f) << 4) | (c >> 2); |
||
374 | z = ((c & 0x03) << 6) | d; |
||
375 | |||
376 | if(len--) ptrOut[ptr++] = x; else break; |
||
377 | if(len--) ptrOut[ptr++] = y; else break; |
||
378 | if(len--) ptrOut[ptr++] = z; else break; |
||
379 | } |
||
1 | ingob | 380 | } |
381 | |||
382 | |||
19 | killagreg | 383 | // -------------------------------------------------------------------------- |
384 | int16_t uart_putchar (int8_t c) |
||
1 | ingob | 385 | { |
19 | killagreg | 386 | // if tx is not enabled return immediatly |
387 | if(!(UCSR0B & (1 << TXEN0))) return (0); |
||
388 | if (c == '\n') uart_putchar('\r'); |
||
389 | // wait until previous character was send |
||
390 | loop_until_bit_is_set(UCSR0A, UDRE0); |
||
391 | // send character |
||
392 | UDR0 = c; |
||
1 | ingob | 393 | return (0); |
394 | } |
||
395 | |||
19 | killagreg | 396 | |
1 | ingob | 397 | // -------------------------------------------------------------------------- |
19 | killagreg | 398 | void USART0_ProcessRxData(void) |
1 | ingob | 399 | { |
19 | killagreg | 400 | // if data in the rxd buffer are not locked immediately return |
401 | if(!rxd_buffer_locked) return; |
||
1 | ingob | 402 | |
19 | killagreg | 403 | uint8_t tmp_char_arr2[2]; // local char buffer |
1 | ingob | 404 | |
19 | killagreg | 405 | switch(rxd_buffer[2]) |
406 | { |
||
407 | case 'w':// Attitude |
||
408 | Decode64((uint8_t *) &ExternData, sizeof(ExternData), 3, ReceivedBytes); |
||
409 | DebugOut.Analog[15]++; |
||
410 | RequestCompassHeading = TRUE; |
||
411 | break; |
||
1 | ingob | 412 | |
19 | killagreg | 413 | case 'b': // extern control |
414 | case 'c': // extern control with debug request |
||
415 | Decode64((uint8_t *) &ExternControl,sizeof(ExternControl), 3,ReceivedBytes); |
||
416 | ExternData.Attitude[0] = ExternControl.Par1; |
||
417 | ExternData.Attitude[1] = ExternControl.Par2; |
||
418 | break; |
||
1 | ingob | 419 | |
19 | killagreg | 420 | case 'h':// x-1 display columns |
421 | PC_Connected = 255; |
||
422 | break; |
||
1 | ingob | 423 | |
19 | killagreg | 424 | case 'v': // get version and board release |
425 | RequestVerInfo = TRUE; |
||
426 | PC_Connected = 255; |
||
427 | break; |
||
428 | |||
429 | case 'a':// Labels of the Analog Debug outputs |
||
430 | Decode64((uint8_t *) &tmp_char_arr2[0], sizeof(tmp_char_arr2), 3, ReceivedBytes); |
||
431 | RequestDebugLabel = tmp_char_arr2[0]; |
||
432 | PC_Connected = 255; |
||
433 | break; |
||
434 | |||
435 | case 'g':// get debug data |
||
436 | RequestDebugData = TRUE; |
||
437 | PC_Connected = 255; |
||
438 | break; |
||
439 | } |
||
440 | // unlock the rxd buffer after processing |
||
441 | rxd_buffer_locked = FALSE; |
||
1 | ingob | 442 | } |
443 | |||
444 | |||
19 | killagreg | 445 | |
446 | //--------------------------------------------------------------------------------------------- |
||
447 | void USART0_TransmitTxData(void) |
||
1 | ingob | 448 | { |
19 | killagreg | 449 | if(!(UCSR0B & (1 << TXEN0))) return; |
1 | ingob | 450 | |
19 | killagreg | 451 | if(!txd_complete) return; |
1 | ingob | 452 | |
19 | killagreg | 453 | if(CheckDelay(Debug_Timer) && txd_complete) |
454 | { |
||
455 | SetDebugValues(); |
||
456 | SendOutData('D',MySlaveAddr,(uint8_t *) &DebugOut,sizeof(DebugOut)); |
||
457 | Debug_Timer = SetDelay(250); |
||
458 | } |
||
1 | ingob | 459 | |
19 | killagreg | 460 | if(RequestDebugLabel != 255) |
461 | { |
||
462 | SendOutData('A',RequestDebugLabel + '0',(uint8_t *) ANALOG_LABEL[RequestDebugLabel],16); |
||
463 | RequestDebugLabel = 255; |
||
464 | } |
||
1 | ingob | 465 | |
19 | killagreg | 466 | if(RequestVerInfo && txd_complete) |
467 | { |
||
468 | SendOutData('V',MySlaveAddr,(uint8_t *) &VersionInfo, sizeof(VersionInfo)); |
||
469 | RequestVerInfo = FALSE; |
||
470 | } |
||
471 | |||
472 | if(RequestDebugData && txd_complete) |
||
473 | { |
||
474 | SetDebugValues(); |
||
475 | SendOutData('G',MySlaveAddr,(uint8_t *) &ExternControl,sizeof(ExternControl)); |
||
476 | RequestDebugData = FALSE; |
||
477 | } |
||
478 | |||
479 | if(RequestCompassHeading && txd_complete) |
||
480 | { |
||
481 | SendOutData('K',MySlaveAddr,(uint8_t *) &I2C_Heading, sizeof(I2C_Heading)); |
||
482 | RequestCompassHeading = FALSE; |
||
483 | } |
||
1 | ingob | 484 | } |