Rev 690 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 690 | Rev 701 | ||
---|---|---|---|
1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 | // + Copyright (c) 04.2007 Holger Buss |
2 | // + Copyright (c) 04.2007 Holger Buss |
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 | 7 | ||
8 | #include <avr/io.h> |
8 | #include <avr/io.h> |
9 | #include <avr/interrupt.h> |
9 | #include <avr/interrupt.h> |
10 | #include <avr/wdt.h> |
10 | #include <avr/wdt.h> |
11 | 11 | ||
12 | #include "eeprom.h" |
12 | #include "eeprom.h" |
13 | #include "main.h" |
13 | #include "main.h" |
14 | #include "menu.h" |
14 | #include "menu.h" |
15 | #include "timer0.h" |
15 | #include "timer0.h" |
16 | #include "uart.h" |
16 | #include "uart.h" |
17 | #include "fc.h" |
17 | #include "fc.h" |
18 | #include "_Settings.h" |
18 | #include "_Settings.h" |
19 | #include "rc.h" |
19 | #include "rc.h" |
20 | 20 | ||
21 | 21 | ||
22 | unsigned char DebugGetAnforderung = 0,DebugDisplayAnforderung = 0,DebugDataAnforderung = 0,GetVersionAnforderung = 0; |
22 | unsigned char DebugGetAnforderung = 0,DebugDisplayAnforderung = 0,DebugDataAnforderung = 0,GetVersionAnforderung = 0; |
23 | unsigned volatile char SioTmp = 0; |
23 | unsigned volatile char SioTmp = 0; |
24 | unsigned volatile char txd_buffer[TXD_BUFFER_LEN]; |
24 | unsigned volatile char txd_buffer[TXD_BUFFER_LEN]; |
25 | unsigned volatile char rxd_buffer[RXD_BUFFER_LEN]; |
25 | unsigned volatile char rxd_buffer[RXD_BUFFER_LEN]; |
26 | 26 | ||
27 | unsigned volatile char NeuerDatensatzEmpfangen = 0; |
27 | unsigned volatile char NeuerDatensatzEmpfangen = 0; |
28 | unsigned volatile char NeueKoordinateEmpfangen = 0; |
28 | unsigned volatile char NeueKoordinateEmpfangen = 0; |
29 | unsigned volatile char UebertragungAbgeschlossen = 1; |
29 | unsigned volatile char UebertragungAbgeschlossen = 1; |
30 | unsigned volatile char CntCrcError = 0; |
30 | unsigned volatile char CntCrcError = 0; |
31 | unsigned volatile char AnzahlEmpfangsBytes = 0; |
31 | unsigned volatile char AnzahlEmpfangsBytes = 0; |
32 | unsigned volatile char PC_DebugTimeout = 0; |
32 | unsigned volatile char PC_DebugTimeout = 0; |
33 | unsigned char RemotePollDisplayLine = 0; |
33 | unsigned char RemotePollDisplayLine = 0; |
34 | unsigned char NurKanalAnforderung = 0; |
34 | unsigned char NurKanalAnforderung = 0; |
35 | unsigned char DebugTextAnforderung = 255; |
35 | unsigned char DebugTextAnforderung = 255; |
36 | unsigned char PcZugriff = 100; |
36 | unsigned char PcZugriff = 100; |
37 | unsigned char MotorTest[4] = {0,0,0,0}; |
37 | unsigned char MotorTest[4] = {0,0,0,0}; |
38 | unsigned char DubWiseKeys[4] = {0,0,0,0}; |
38 | unsigned char DubWiseKeys[4] = {0,0,0,0}; |
39 | unsigned char MeineSlaveAdresse; |
39 | unsigned char MeineSlaveAdresse; |
40 | unsigned char ConfirmFrame; |
40 | unsigned char ConfirmFrame; |
41 | struct str_DebugOut DebugOut; |
41 | struct str_DebugOut DebugOut; |
42 | struct str_ExternControl ExternControl; |
42 | struct str_ExternControl ExternControl; |
43 | struct str_VersionInfo VersionInfo; |
43 | struct str_VersionInfo VersionInfo; |
44 | int Debug_Timer; |
44 | int Debug_Timer; |
45 | 45 | ||
46 | const unsigned char ANALOG_TEXT[32][16] = |
46 | const unsigned char ANALOG_TEXT[32][16] = |
47 | { |
47 | { |
48 | //1234567890123456 |
48 | //1234567890123456 |
49 | "IntegralNick ", //0 |
49 | "IntegralPitch ", //0 |
50 | "IntegralRoll ", |
50 | "IntegralRoll ", |
51 | "AccNick ", |
51 | "AccPitch ", |
52 | "AccRoll ", |
52 | "AccRoll ", |
53 | "GyroGier ", |
53 | "GyroYaw ", |
54 | "HoehenWert ", //5 |
54 | "ReadingHight ", //5 |
55 | "AccZ ", |
55 | "AccZ ", |
56 | "Gas ", |
56 | "Gas ", |
57 | "KompassValue ", |
57 | "CompassHeading ", |
58 | "Spannung ", |
58 | "Voltage ", |
59 | "Empfang ", //10 |
59 | "Receiver Level ", //10 |
60 | "Analog11 ", |
60 | "Analog11 ", |
61 | "Motor_Vorne ", |
61 | "Motor_Front ", |
62 | "Motor_Hinten ", |
62 | "Motor_Rear ", |
63 | "Motor_Links ", |
63 | "Motor_Left ", |
64 | "Motor_Rechts ", //15 |
64 | "Motor_Right ", //15 |
65 | "Acc_Z ", |
65 | "Acc_Z ", |
66 | "MittelAccNick ", |
66 | "MeanAccPitch ", |
67 | "MittelAccRoll ", |
67 | "MeanAccRoll ", |
68 | "IntegralErrNick ", |
68 | "IntegralErrPitch", |
69 | "IntegralErrRoll ", //20 |
69 | "IntegralErrRoll ", //20 |
70 | "MittelIntNick ", |
70 | "MeanIntPitch ", |
71 | "MittelIntRoll ", |
71 | "MMeanIntRoll ", |
72 | "NeutralNick ", |
72 | "NeutralPitch ", |
73 | "RollOffset ", |
73 | "RollOffset ", |
74 | "IntRoll*Faktor ", //25 |
74 | "IntRoll*Factor ", //25 |
75 | "Analog26 ", |
75 | "Analog26 ", |
76 | "DirektAusglRoll ", |
76 | "DirectCorrRoll ", |
77 | "MesswertRoll ", |
77 | "ReadingRoll ", |
78 | "AusgleichRoll ", |
78 | "CorrectionRoll ", |
79 | "I-LageRoll ", //30 |
79 | "I-AttRoll ", //30 |
80 | "StickRoll " |
80 | "StickRoll " |
81 | }; |
81 | }; |
82 | 82 | ||
83 | 83 | ||
84 | 84 | ||
85 | /****************************************************************/ |
85 | /****************************************************************/ |
86 | /* Initialization of the USART0 */ |
86 | /* Initialization of the USART0 */ |
87 | /****************************************************************/ |
87 | /****************************************************************/ |
88 | void USART0_Init (void) |
88 | void USART0_Init (void) |
89 | { |
89 | { |
90 | uint8_t sreg = SREG; |
90 | uint8_t sreg = SREG; |
91 | uint16_t ubrr = (uint16_t) ((uint32_t) SYSCLK/(8 * USART0_BAUD) - 1); |
91 | uint16_t ubrr = (uint16_t) ((uint32_t) SYSCLK/(8 * USART0_BAUD) - 1); |
92 | 92 | ||
93 | // disable all interrupts before configuration |
93 | // disable all interrupts before configuration |
94 | cli(); |
94 | cli(); |
95 | 95 | ||
96 | // disable RX-Interrupt |
96 | // disable RX-Interrupt |
97 | UCSR0B &= ~(1 << RXCIE0); |
97 | UCSR0B &= ~(1 << RXCIE0); |
98 | // disable TX-Interrupt |
98 | // disable TX-Interrupt |
99 | UCSR0B &= ~(1 << TXCIE0); |
99 | UCSR0B &= ~(1 << TXCIE0); |
100 | 100 | ||
101 | // set direction of RXD0 and TXD0 pins |
101 | // set direction of RXD0 and TXD0 pins |
102 | // set RXD0 (PD0) as an input pin |
102 | // set RXD0 (PD0) as an input pin |
103 | PORTD |= (1 << PORTD0); |
103 | PORTD |= (1 << PORTD0); |
104 | DDRD &= ~(1 << DDD0); |
104 | DDRD &= ~(1 << DDD0); |
105 | // set TXD0 (PD1) as an output pin |
105 | // set TXD0 (PD1) as an output pin |
106 | PORTD |= (1 << PORTD1); |
106 | PORTD |= (1 << PORTD1); |
107 | DDRD |= (1 << DDD1); |
107 | DDRD |= (1 << DDD1); |
108 | 108 | ||
109 | // USART0 Baud Rate Register |
109 | // USART0 Baud Rate Register |
110 | // set clock divider |
110 | // set clock divider |
111 | UBRR0H = (uint8_t)(ubrr >> 8); |
111 | UBRR0H = (uint8_t)(ubrr >> 8); |
112 | UBRR0L = (uint8_t)ubrr; |
112 | UBRR0L = (uint8_t)ubrr; |
113 | 113 | ||
114 | // USART0 Control and Status Register A, B, C |
114 | // USART0 Control and Status Register A, B, C |
115 | 115 | ||
116 | // enable double speed operation in |
116 | // enable double speed operation in |
117 | UCSR0A |= (1 << U2X0); |
117 | UCSR0A |= (1 << U2X0); |
118 | // enable receiver and transmitter in |
118 | // enable receiver and transmitter in |
119 | UCSR0B = (1 << TXEN0) | (1 << RXEN0); |
119 | UCSR0B = (1 << TXEN0) | (1 << RXEN0); |
120 | // set asynchronous mode |
120 | // set asynchronous mode |
121 | UCSR0C &= ~(1 << UMSEL01); |
121 | UCSR0C &= ~(1 << UMSEL01); |
122 | UCSR0C &= ~(1 << UMSEL00); |
122 | UCSR0C &= ~(1 << UMSEL00); |
123 | // no parity |
123 | // no parity |
124 | UCSR0C &= ~(1 << UPM01); |
124 | UCSR0C &= ~(1 << UPM01); |
125 | UCSR0C &= ~(1 << UPM00); |
125 | UCSR0C &= ~(1 << UPM00); |
126 | // 1 stop bit |
126 | // 1 stop bit |
127 | UCSR0C &= ~(1 << USBS0); |
127 | UCSR0C &= ~(1 << USBS0); |
128 | // 8-bit |
128 | // 8-bit |
129 | UCSR0B &= ~(1 << UCSZ02); |
129 | UCSR0B &= ~(1 << UCSZ02); |
130 | UCSR0C |= (1 << UCSZ01); |
130 | UCSR0C |= (1 << UCSZ01); |
131 | UCSR0C |= (1 << UCSZ00); |
131 | UCSR0C |= (1 << UCSZ00); |
132 | 132 | ||
133 | // flush receive buffer |
133 | // flush receive buffer |
134 | while ( UCSR0A & (1<<RXC0) ) UDR0; |
134 | while ( UCSR0A & (1<<RXC0) ) UDR0; |
135 | 135 | ||
136 | // enable interrupts at the end |
136 | // enable interrupts at the end |
137 | // enable RX-Interrupt |
137 | // enable RX-Interrupt |
138 | UCSR0B |= (1 << RXCIE0); |
138 | UCSR0B |= (1 << RXCIE0); |
139 | // enable TX-Interrupt |
139 | // enable TX-Interrupt |
140 | UCSR0B |= (1 << TXCIE0); |
140 | UCSR0B |= (1 << TXCIE0); |
141 | 141 | ||
142 | // restore global interrupt flags |
142 | // restore global interrupt flags |
143 | SREG = sreg; |
143 | SREG = sreg; |
144 | } |
144 | } |
145 | 145 | ||
146 | /****************************************************************/ |
146 | /****************************************************************/ |
147 | /* USART0 transmitter ISR */ |
147 | /* USART0 transmitter ISR */ |
148 | /****************************************************************/ |
148 | /****************************************************************/ |
149 | ISR(USART0_TX_vect) |
149 | ISR(USART0_TX_vect) |
150 | { |
150 | { |
151 | static uint16_t ptr = 0; |
151 | static uint16_t ptr = 0; |
152 | uint8_t tmp_tx; |
152 | uint8_t tmp_tx; |
153 | if(!UebertragungAbgeschlossen) |
153 | if(!UebertragungAbgeschlossen) |
154 | { |
154 | { |
155 | ptr++; // die [0] wurde schon gesendet |
155 | ptr++; // die [0] wurde schon gesendet |
156 | tmp_tx = txd_buffer[ptr]; |
156 | tmp_tx = txd_buffer[ptr]; |
157 | if((tmp_tx == '\r') || (ptr == TXD_BUFFER_LEN)) |
157 | if((tmp_tx == '\r') || (ptr == TXD_BUFFER_LEN)) |
158 | { |
158 | { |
159 | ptr = 0; |
159 | ptr = 0; |
160 | UebertragungAbgeschlossen = 1; |
160 | UebertragungAbgeschlossen = 1; |
161 | } |
161 | } |
162 | UDR0 = tmp_tx; // send byte will trigger this ISR again |
162 | UDR0 = tmp_tx; // send byte will trigger this ISR again |
163 | } |
163 | } |
164 | else ptr = 0; |
164 | else ptr = 0; |
165 | } |
165 | } |
166 | 166 | ||
167 | /****************************************************************/ |
167 | /****************************************************************/ |
168 | /* USART0 receiver ISR */ |
168 | /* USART0 receiver ISR */ |
169 | /****************************************************************/ |
169 | /****************************************************************/ |
170 | ISR(USART0_RX_vect) |
170 | ISR(USART0_RX_vect) |
171 | { |
171 | { |
172 | static uint16_t crc; |
172 | static uint16_t crc; |
173 | static uint8_t crc1,crc2,buf_ptr; |
173 | static uint8_t crc1,crc2,buf_ptr; |
174 | static uint8_t UartState = 0; |
174 | static uint8_t UartState = 0; |
175 | uint8_t CrcOkay = 0; |
175 | uint8_t CrcOkay = 0; |
176 | 176 | ||
177 | SioTmp = UDR0; |
177 | SioTmp = UDR0; |
178 | if(buf_ptr >= RXD_BUFFER_LEN) UartState = 0; |
178 | if(buf_ptr >= RXD_BUFFER_LEN) UartState = 0; |
179 | if(SioTmp == '\r' && UartState == 2) |
179 | if(SioTmp == '\r' && UartState == 2) |
180 | { |
180 | { |
181 | UartState = 0; |
181 | UartState = 0; |
182 | crc -= rxd_buffer[buf_ptr-2]; |
182 | crc -= rxd_buffer[buf_ptr-2]; |
183 | crc -= rxd_buffer[buf_ptr-1]; |
183 | crc -= rxd_buffer[buf_ptr-1]; |
184 | crc %= 4096; |
184 | crc %= 4096; |
185 | crc1 = '=' + crc / 64; |
185 | crc1 = '=' + crc / 64; |
186 | crc2 = '=' + crc % 64; |
186 | crc2 = '=' + crc % 64; |
187 | CrcOkay = 0; |
187 | CrcOkay = 0; |
188 | if((crc1 == rxd_buffer[buf_ptr-2]) && (crc2 == rxd_buffer[buf_ptr-1])) CrcOkay = 1; else { CrcOkay = 0; CntCrcError++;}; |
188 | if((crc1 == rxd_buffer[buf_ptr-2]) && (crc2 == rxd_buffer[buf_ptr-1])) CrcOkay = 1; else { CrcOkay = 0; CntCrcError++;}; |
189 | if(!NeuerDatensatzEmpfangen && CrcOkay) // Datensatz schon verarbeitet |
189 | if(!NeuerDatensatzEmpfangen && CrcOkay) // Datensatz schon verarbeitet |
190 | { |
190 | { |
191 | NeuerDatensatzEmpfangen = 1; |
191 | NeuerDatensatzEmpfangen = 1; |
192 | AnzahlEmpfangsBytes = buf_ptr; |
192 | AnzahlEmpfangsBytes = buf_ptr; |
193 | rxd_buffer[buf_ptr] = '\r'; |
193 | rxd_buffer[buf_ptr] = '\r'; |
194 | if(rxd_buffer[2] == 'R') wdt_enable(WDTO_250MS); // Reset-Commando |
194 | if(rxd_buffer[2] == 'R') wdt_enable(WDTO_250MS); // Reset-Commando |
195 | } |
195 | } |
196 | } |
196 | } |
197 | else |
197 | else |
198 | switch(UartState) |
198 | switch(UartState) |
199 | { |
199 | { |
200 | case 0: |
200 | case 0: |
201 | if(SioTmp == '#' && !NeuerDatensatzEmpfangen) UartState = 1; // Startzeichen und Daten schon verarbeitet |
201 | if(SioTmp == '#' && !NeuerDatensatzEmpfangen) UartState = 1; // Startzeichen und Daten schon verarbeitet |
202 | buf_ptr = 0; |
202 | buf_ptr = 0; |
203 | rxd_buffer[buf_ptr++] = SioTmp; |
203 | rxd_buffer[buf_ptr++] = SioTmp; |
204 | crc = SioTmp; |
204 | crc = SioTmp; |
205 | break; |
205 | break; |
206 | case 1: // Adresse auswerten |
206 | case 1: // Adresse auswerten |
207 | UartState++; |
207 | UartState++; |
208 | rxd_buffer[buf_ptr++] = SioTmp; |
208 | rxd_buffer[buf_ptr++] = SioTmp; |
209 | crc += SioTmp; |
209 | crc += SioTmp; |
210 | break; |
210 | break; |
211 | case 2: // Eingangsdaten sammeln |
211 | case 2: // Eingangsdaten sammeln |
212 | rxd_buffer[buf_ptr] = SioTmp; |
212 | rxd_buffer[buf_ptr] = SioTmp; |
213 | if(buf_ptr < RXD_BUFFER_LEN) buf_ptr++; |
213 | if(buf_ptr < RXD_BUFFER_LEN) buf_ptr++; |
214 | else UartState = 0; |
214 | else UartState = 0; |
215 | crc += SioTmp; |
215 | crc += SioTmp; |
216 | break; |
216 | break; |
217 | default: |
217 | default: |
218 | UartState = 0; |
218 | UartState = 0; |
219 | break; |
219 | break; |
220 | } |
220 | } |
221 | } |
221 | } |
222 | 222 | ||
223 | 223 | ||
224 | 224 | ||
225 | // -------------------------------------------------------------------------- |
225 | // -------------------------------------------------------------------------- |
226 | void AddCRC(unsigned int wieviele) |
226 | void AddCRC(unsigned int wieviele) |
227 | { |
227 | { |
228 | uint16_t tmpCRC = 0,i; |
228 | uint16_t tmpCRC = 0,i; |
229 | for(i = 0; i < wieviele;i++) |
229 | for(i = 0; i < wieviele;i++) |
230 | { |
230 | { |
231 | tmpCRC += txd_buffer[i]; |
231 | tmpCRC += txd_buffer[i]; |
232 | } |
232 | } |
233 | tmpCRC %= 4096; |
233 | tmpCRC %= 4096; |
234 | txd_buffer[i++] = '=' + tmpCRC / 64; |
234 | txd_buffer[i++] = '=' + tmpCRC / 64; |
235 | txd_buffer[i++] = '=' + tmpCRC % 64; |
235 | txd_buffer[i++] = '=' + tmpCRC % 64; |
236 | txd_buffer[i++] = '\r'; |
236 | txd_buffer[i++] = '\r'; |
237 | UebertragungAbgeschlossen = 0; |
237 | UebertragungAbgeschlossen = 0; |
238 | UDR0 = txd_buffer[0]; |
238 | UDR0 = txd_buffer[0]; |
239 | } |
239 | } |
240 | 240 | ||
241 | 241 | ||
242 | 242 | ||
243 | // -------------------------------------------------------------------------- |
243 | // -------------------------------------------------------------------------- |
244 | void SendOutData(uint8_t cmd,uint8_t modul, uint8_t *snd, uint8_t len) |
244 | void SendOutData(uint8_t cmd,uint8_t modul, uint8_t *snd, uint8_t len) |
245 | { |
245 | { |
246 | uint16_t pt = 0; |
246 | uint16_t pt = 0; |
247 | uint8_t a,b,c; |
247 | uint8_t a,b,c; |
248 | uint8_t ptr = 0; |
248 | uint8_t ptr = 0; |
249 | 249 | ||
250 | txd_buffer[pt++] = '#'; // Startzeichen |
250 | txd_buffer[pt++] = '#'; // Startzeichen |
251 | txd_buffer[pt++] = modul; // Adresse (a=0; b=1,...) |
251 | txd_buffer[pt++] = modul; // Adresse (a=0; b=1,...) |
252 | txd_buffer[pt++] = cmd; // Commando |
252 | txd_buffer[pt++] = cmd; // Commando |
253 | 253 | ||
254 | while(len) |
254 | while(len) |
255 | { |
255 | { |
256 | if(len) { a = snd[ptr++]; len--;} else a = 0; |
256 | if(len) { a = snd[ptr++]; len--;} else a = 0; |
257 | if(len) { b = snd[ptr++]; len--;} else b = 0; |
257 | if(len) { b = snd[ptr++]; len--;} else b = 0; |
258 | if(len) { c = snd[ptr++]; len--;} else c = 0; |
258 | if(len) { c = snd[ptr++]; len--;} else c = 0; |
259 | txd_buffer[pt++] = '=' + (a >> 2); |
259 | txd_buffer[pt++] = '=' + (a >> 2); |
260 | txd_buffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
260 | txd_buffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
261 | txd_buffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
261 | txd_buffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
262 | txd_buffer[pt++] = '=' + ( c & 0x3f); |
262 | txd_buffer[pt++] = '=' + ( c & 0x3f); |
263 | } |
263 | } |
264 | AddCRC(pt); |
264 | AddCRC(pt); |
265 | } |
265 | } |
266 | 266 | ||
267 | 267 | ||
268 | // -------------------------------------------------------------------------- |
268 | // -------------------------------------------------------------------------- |
269 | void Decode64(uint8_t *ptrOut, uint8_t len, uint8_t ptrIn, uint8_t max) // Wohin mit den Daten; Wie lang; Wo im rxd_buffer |
269 | void Decode64(uint8_t *ptrOut, uint8_t len, uint8_t ptrIn, uint8_t max) // Wohin mit den Daten; Wie lang; Wo im rxd_buffer |
270 | { |
270 | { |
271 | uint8_t a,b,c,d; |
271 | uint8_t a,b,c,d; |
272 | uint8_t ptr = 0; |
272 | uint8_t ptr = 0; |
273 | uint8_t x,y,z; |
273 | uint8_t x,y,z; |
274 | while(len) |
274 | while(len) |
275 | { |
275 | { |
276 | a = rxd_buffer[ptrIn++] - '='; |
276 | a = rxd_buffer[ptrIn++] - '='; |
277 | b = rxd_buffer[ptrIn++] - '='; |
277 | b = rxd_buffer[ptrIn++] - '='; |
278 | c = rxd_buffer[ptrIn++] - '='; |
278 | c = rxd_buffer[ptrIn++] - '='; |
279 | d = rxd_buffer[ptrIn++] - '='; |
279 | d = rxd_buffer[ptrIn++] - '='; |
280 | if(ptrIn > max - 2) break; // nicht mehr Daten verarbeiten, als empfangen wurden |
280 | if(ptrIn > max - 2) break; // nicht mehr Daten verarbeiten, als empfangen wurden |
281 | 281 | ||
282 | x = (a << 2) | (b >> 4); |
282 | x = (a << 2) | (b >> 4); |
283 | y = ((b & 0x0f) << 4) | (c >> 2); |
283 | y = ((b & 0x0f) << 4) | (c >> 2); |
284 | z = ((c & 0x03) << 6) | d; |
284 | z = ((c & 0x03) << 6) | d; |
285 | 285 | ||
286 | if(len--) ptrOut[ptr++] = x; else break; |
286 | if(len--) ptrOut[ptr++] = x; else break; |
287 | if(len--) ptrOut[ptr++] = y; else break; |
287 | if(len--) ptrOut[ptr++] = y; else break; |
288 | if(len--) ptrOut[ptr++] = z; else break; |
288 | if(len--) ptrOut[ptr++] = z; else break; |
289 | } |
289 | } |
290 | 290 | ||
291 | } |
291 | } |
292 | 292 | ||
293 | // -------------------------------------------------------------------------- |
293 | // -------------------------------------------------------------------------- |
294 | void BearbeiteRxDaten(void) |
294 | void BearbeiteRxDaten(void) |
295 | { |
295 | { |
296 | if(!NeuerDatensatzEmpfangen) return; |
296 | if(!NeuerDatensatzEmpfangen) return; |
297 | 297 | ||
298 | uint8_t tmp_char_arr2[2]; |
298 | uint8_t tmp_char_arr2[2]; |
299 | 299 | ||
300 | PcZugriff = 255; |
300 | PcZugriff = 255; |
301 | switch(rxd_buffer[2]) |
301 | switch(rxd_buffer[2]) |
302 | { |
302 | { |
303 | case 'a':// Texte der Analogwerte |
303 | case 'a':// Texte der Analogwerte |
304 | Decode64((uint8_t *) &tmp_char_arr2[0],sizeof(tmp_char_arr2),3,AnzahlEmpfangsBytes); |
304 | Decode64((uint8_t *) &tmp_char_arr2[0],sizeof(tmp_char_arr2),3,AnzahlEmpfangsBytes); |
305 | DebugTextAnforderung = tmp_char_arr2[0]; |
305 | DebugTextAnforderung = tmp_char_arr2[0]; |
306 | break; |
306 | break; |
307 | case 'b': |
307 | case 'b': |
308 | Decode64((uint8_t *) &ExternControl,sizeof(ExternControl),3,AnzahlEmpfangsBytes); |
308 | Decode64((uint8_t *) &ExternControl,sizeof(ExternControl),3,AnzahlEmpfangsBytes); |
309 | RemoteButtons |= ExternControl.RemoteButtons; |
309 | RemoteButtons |= ExternControl.RemoteButtons; |
310 | ConfirmFrame = ExternControl.Frame; |
310 | ConfirmFrame = ExternControl.Frame; |
311 | break; |
311 | break; |
312 | case 'c': |
312 | case 'c': |
313 | Decode64((uint8_t *) &ExternControl,sizeof(ExternControl),3,AnzahlEmpfangsBytes); |
313 | Decode64((uint8_t *) &ExternControl,sizeof(ExternControl),3,AnzahlEmpfangsBytes); |
314 | RemoteButtons |= ExternControl.RemoteButtons; |
314 | RemoteButtons |= ExternControl.RemoteButtons; |
315 | ConfirmFrame = ExternControl.Frame; |
315 | ConfirmFrame = ExternControl.Frame; |
316 | DebugDataAnforderung = 1; |
316 | DebugDataAnforderung = 1; |
317 | break; |
317 | break; |
318 | case 'h':// x-1 Displayzeilen |
318 | case 'h':// x-1 Displayzeilen |
319 | Decode64((uint8_t *) &tmp_char_arr2[0],sizeof(tmp_char_arr2),3,AnzahlEmpfangsBytes); |
319 | Decode64((uint8_t *) &tmp_char_arr2[0],sizeof(tmp_char_arr2),3,AnzahlEmpfangsBytes); |
320 | RemoteButtons |= tmp_char_arr2[0]; |
320 | RemoteButtons |= tmp_char_arr2[0]; |
321 | if(tmp_char_arr2[1] == 255) NurKanalAnforderung = 1; else NurKanalAnforderung = 0; // keine Displaydaten |
321 | if(tmp_char_arr2[1] == 255) NurKanalAnforderung = 1; else NurKanalAnforderung = 0; // keine Displaydaten |
322 | DebugDisplayAnforderung = 1; |
322 | DebugDisplayAnforderung = 1; |
323 | break; |
323 | break; |
324 | case 't':// Motortest |
324 | case 't':// Motortest |
325 | Decode64((uint8_t *) &MotorTest[0],sizeof(MotorTest),3,AnzahlEmpfangsBytes); |
325 | Decode64((uint8_t *) &MotorTest[0],sizeof(MotorTest),3,AnzahlEmpfangsBytes); |
326 | break; |
326 | break; |
327 | case 'k':// Keys von DubWise |
327 | case 'k':// Keys von DubWise |
328 | Decode64((uint8_t *) &DubWiseKeys[0],sizeof(DubWiseKeys),3,AnzahlEmpfangsBytes); |
328 | Decode64((uint8_t *) &DubWiseKeys[0],sizeof(DubWiseKeys),3,AnzahlEmpfangsBytes); |
329 | ConfirmFrame = DubWiseKeys[3]; |
329 | ConfirmFrame = DubWiseKeys[3]; |
330 | break; |
330 | break; |
331 | case 'v': // Version-Anforderung und Ausbaustufe |
331 | case 'v': // Version-Anforderung und Ausbaustufe |
332 | GetVersionAnforderung = 1; |
332 | GetVersionAnforderung = 1; |
333 | break; |
333 | break; |
334 | case 'g':// "Get"-Anforderung für Debug-Daten |
334 | case 'g':// "Get"-Anforderung für Debug-Daten |
335 | // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
335 | // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
336 | DebugGetAnforderung = 1; |
336 | DebugGetAnforderung = 1; |
337 | break; |
337 | break; |
338 | case 'q':// "Get"-Anforderung für Settings |
338 | case 'q':// "Get"-Anforderung für Settings |
339 | // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
339 | // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
340 | Decode64((uint8_t *) &tmp_char_arr2[0],sizeof(tmp_char_arr2),3,AnzahlEmpfangsBytes); |
340 | Decode64((uint8_t *) &tmp_char_arr2[0],sizeof(tmp_char_arr2),3,AnzahlEmpfangsBytes); |
341 | if(tmp_char_arr2[0] != 0xff) |
341 | if(tmp_char_arr2[0] != 0xff) |
342 | { |
342 | { |
343 | if(tmp_char_arr2[0] > 5) tmp_char_arr2[0] = 5; |
343 | if(tmp_char_arr2[0] > 5) tmp_char_arr2[0] = 5; |
344 | ParamSet_ReadFromEEProm(tmp_char_arr2[0]); |
344 | ParamSet_ReadFromEEProm(tmp_char_arr2[0]); |
345 | SendOutData('L' + tmp_char_arr2[0] -1,MeineSlaveAdresse,(uint8_t *) &ParamSet.ChannelAssignment[0],PARAMSET_STRUCT_LEN); |
345 | SendOutData('L' + tmp_char_arr2[0] -1,MeineSlaveAdresse,(uint8_t *) &ParamSet.ChannelAssignment[0],PARAMSET_STRUCT_LEN); |
346 | } |
346 | } |
347 | else |
347 | else |
348 | SendOutData('L' + GetParamByte(PID_ACTIVE_SET)-1,MeineSlaveAdresse,(uint8_t *) &ParamSet.ChannelAssignment[0],PARAMSET_STRUCT_LEN); |
348 | SendOutData('L' + GetParamByte(PID_ACTIVE_SET)-1,MeineSlaveAdresse,(uint8_t *) &ParamSet.ChannelAssignment[0],PARAMSET_STRUCT_LEN); |
349 | 349 | ||
350 | break; |
350 | break; |
351 | 351 | ||
352 | case 'l': |
352 | case 'l': |
353 | case 'm': |
353 | case 'm': |
354 | case 'n': |
354 | case 'n': |
355 | case 'o': |
355 | case 'o': |
356 | case 'p': // Parametersatz speichern |
356 | case 'p': // Parametersatz speichern |
357 | Decode64((uint8_t *) &ParamSet.ChannelAssignment[0],PARAMSET_STRUCT_LEN,3,AnzahlEmpfangsBytes); |
357 | Decode64((uint8_t *) &ParamSet.ChannelAssignment[0],PARAMSET_STRUCT_LEN,3,AnzahlEmpfangsBytes); |
358 | ParamSet_WriteToEEProm(rxd_buffer[2] - 'l' + 1); |
358 | ParamSet_WriteToEEProm(rxd_buffer[2] - 'l' + 1); |
359 | //SetActiveParamSet(rxd_buffer[2] - 'l' + 1); // is alredy done in ParamSet_WriteToEEProm() |
359 | //SetActiveParamSet(rxd_buffer[2] - 'l' + 1); // is alredy done in ParamSet_WriteToEEProm() |
360 | Umschlag180Nick = (int32_t) ParamSet.WinkelUmschlagNick * 2500L; |
360 | TurnOver180Pitch = (int32_t) ParamSet.AngleTurnOverPitch * 2500L; |
361 | Umschlag180Roll = (int32_t) ParamSet.WinkelUmschlagRoll * 2500L; |
361 | TurnOver180Roll = (int32_t) ParamSet.AngleTurnOverRoll * 2500L; |
362 | Piep(GetActiveParamSet()); |
362 | Piep(GetActiveParamSet()); |
363 | break; |
363 | break; |
364 | 364 | ||
365 | 365 | ||
366 | } |
366 | } |
367 | // DebugOut.AnzahlZyklen = Debug_Timer_Intervall; |
367 | // DebugOut.AnzahlZyklen = Debug_Timer_Intervall; |
368 | NeuerDatensatzEmpfangen = 0; |
368 | NeuerDatensatzEmpfangen = 0; |
369 | } |
369 | } |
370 | 370 | ||
371 | //############################################################################ |
371 | //############################################################################ |
372 | //Routine für die Serielle Ausgabe |
372 | //Routine für die Serielle Ausgabe |
373 | int16_t uart_putchar (int8_t c) |
373 | int16_t uart_putchar (int8_t c) |
374 | //############################################################################ |
374 | //############################################################################ |
375 | { |
375 | { |
376 | if (c == '\n') |
376 | if (c == '\n') |
377 | uart_putchar('\r'); |
377 | uart_putchar('\r'); |
378 | //Warten solange bis Zeichen gesendet wurde |
378 | //Warten solange bis Zeichen gesendet wurde |
379 | loop_until_bit_is_set(UCSR0A, UDRE0); |
379 | loop_until_bit_is_set(UCSR0A, UDRE0); |
380 | //Ausgabe des Zeichens |
380 | //Ausgabe des Zeichens |
381 | UDR0 = c; |
381 | UDR0 = c; |
382 | 382 | ||
383 | return (0); |
383 | return (0); |
384 | } |
384 | } |
385 | 385 | ||
386 | // -------------------------------------------------------------------------- |
386 | // -------------------------------------------------------------------------- |
387 | void WriteProgramData(unsigned int pos, unsigned char wert) |
387 | void WriteProgramData(unsigned int pos, unsigned char wert) |
388 | { |
388 | { |
389 | //if (ProgramLocation == IN_RAM) Buffer[pos] = wert; |
389 | //if (ProgramLocation == IN_RAM) Buffer[pos] = wert; |
390 | // else eeprom_write_byte(&EE_Buffer[pos], wert); |
390 | // else eeprom_write_byte(&EE_Buffer[pos], wert); |
391 | // Buffer[pos] = wert; |
391 | // Buffer[pos] = wert; |
392 | } |
392 | } |
393 | 393 | ||
394 | 394 | ||
395 | 395 | ||
396 | //--------------------------------------------------------------------------------------------- |
396 | //--------------------------------------------------------------------------------------------- |
397 | void DatenUebertragung(void) |
397 | void DatenUebertragung(void) |
398 | { |
398 | { |
399 | if(!UebertragungAbgeschlossen) return; |
399 | if(!UebertragungAbgeschlossen) return; |
400 | 400 | ||
401 | if(DebugGetAnforderung && UebertragungAbgeschlossen) // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
401 | if(DebugGetAnforderung && UebertragungAbgeschlossen) // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
402 | { |
402 | { |
403 | SendOutData('G',MeineSlaveAdresse,(uint8_t *) &ExternControl,sizeof(ExternControl)); |
403 | SendOutData('G',MeineSlaveAdresse,(uint8_t *) &ExternControl,sizeof(ExternControl)); |
404 | DebugGetAnforderung = 0; |
404 | DebugGetAnforderung = 0; |
405 | } |
405 | } |
406 | 406 | ||
407 | if((CheckDelay(Debug_Timer) || DebugDataAnforderung) && UebertragungAbgeschlossen) |
407 | if((CheckDelay(Debug_Timer) || DebugDataAnforderung) && UebertragungAbgeschlossen) |
408 | { |
408 | { |
409 | SendOutData('D',MeineSlaveAdresse,(uint8_t *) &DebugOut,sizeof(DebugOut)); |
409 | SendOutData('D',MeineSlaveAdresse,(uint8_t *) &DebugOut,sizeof(DebugOut)); |
410 | DebugDataAnforderung = 0; |
410 | DebugDataAnforderung = 0; |
411 | Debug_Timer = SetDelay(MIN_DEBUG_INTERVALL); |
411 | Debug_Timer = SetDelay(MIN_DEBUG_INTERVALL); |
412 | } |
412 | } |
413 | if(DebugTextAnforderung != 255) // Texte für die Analogdaten |
413 | if(DebugTextAnforderung != 255) // Texte für die Analogdaten |
414 | { |
414 | { |
415 | SendOutData('A',DebugTextAnforderung + '0',(uint8_t *) ANALOG_TEXT[DebugTextAnforderung],16); |
415 | SendOutData('A',DebugTextAnforderung + '0',(uint8_t *) ANALOG_TEXT[DebugTextAnforderung],16); |
416 | DebugTextAnforderung = 255; |
416 | DebugTextAnforderung = 255; |
417 | } |
417 | } |
418 | if(ConfirmFrame && UebertragungAbgeschlossen) // Datensatz ohne CRC bestätigen |
418 | if(ConfirmFrame && UebertragungAbgeschlossen) // Datensatz ohne CRC bestätigen |
419 | { |
419 | { |
420 | txd_buffer[0] = '#'; |
420 | txd_buffer[0] = '#'; |
421 | txd_buffer[1] = ConfirmFrame; |
421 | txd_buffer[1] = ConfirmFrame; |
422 | txd_buffer[2] = '\r'; |
422 | txd_buffer[2] = '\r'; |
423 | UebertragungAbgeschlossen = 0; |
423 | UebertragungAbgeschlossen = 0; |
424 | ConfirmFrame = 0; |
424 | ConfirmFrame = 0; |
425 | UDR0 = txd_buffer[0]; |
425 | UDR0 = txd_buffer[0]; |
426 | } |
426 | } |
427 | if(DebugDisplayAnforderung && UebertragungAbgeschlossen) |
427 | if(DebugDisplayAnforderung && UebertragungAbgeschlossen) |
428 | { |
428 | { |
429 | LCD_PrintMenu(); |
429 | LCD_PrintMenu(); |
430 | DebugDisplayAnforderung = 0; |
430 | DebugDisplayAnforderung = 0; |
431 | if(++RemotePollDisplayLine == 4 || NurKanalAnforderung) |
431 | if(++RemotePollDisplayLine == 4 || NurKanalAnforderung) |
432 | { |
432 | { |
433 | SendOutData('4',0,(uint8_t *)&PPM_in,sizeof(PPM_in)); // DisplayZeile übertragen |
433 | SendOutData('4',0,(uint8_t *)&PPM_in,sizeof(PPM_in)); // DisplayZeile übertragen |
434 | RemotePollDisplayLine = -1; |
434 | RemotePollDisplayLine = -1; |
435 | } |
435 | } |
436 | else SendOutData('0' + RemotePollDisplayLine,0,(uint8_t *)&DisplayBuff[20 * RemotePollDisplayLine],20); // DisplayZeile übertragen |
436 | else SendOutData('0' + RemotePollDisplayLine,0,(uint8_t *)&DisplayBuff[20 * RemotePollDisplayLine],20); // DisplayZeile übertragen |
437 | } |
437 | } |
438 | if(GetVersionAnforderung && UebertragungAbgeschlossen) |
438 | if(GetVersionAnforderung && UebertragungAbgeschlossen) |
439 | { |
439 | { |
440 | SendOutData('V',MeineSlaveAdresse,(uint8_t *) &VersionInfo,sizeof(VersionInfo)); |
440 | SendOutData('V',MeineSlaveAdresse,(uint8_t *) &VersionInfo,sizeof(VersionInfo)); |
441 | GetVersionAnforderung = 0; |
441 | GetVersionAnforderung = 0; |
442 | } |
442 | } |
443 | 443 | ||
444 | } |
444 | } |
445 | 445 | ||
446 | 446 |