Rev 492 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 492 | Rev 499 | ||
---|---|---|---|
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 "main.h" |
8 | #include "main.h" |
9 | #include "uart.h" |
9 | #include "uart.h" |
10 | 10 | ||
11 | unsigned char DebugGetAnforderung = 0,DebugDisplayAnforderung = 0,DebugDataAnforderung = 0,GetVersionAnforderung = 0; |
11 | unsigned char DebugGetAnforderung = 0,DebugDisplayAnforderung = 0,DebugDataAnforderung = 0,GetVersionAnforderung = 0; |
12 | unsigned volatile char SioTmp = 0; |
12 | unsigned volatile char SioTmp = 0; |
13 | unsigned volatile char SendeBuffer[MAX_SENDE_BUFF]; |
13 | unsigned volatile char SendeBuffer[MAX_SENDE_BUFF]; |
14 | unsigned volatile char RxdBuffer[MAX_EMPFANGS_BUFF]; |
14 | unsigned volatile char RxdBuffer[MAX_EMPFANGS_BUFF]; |
15 | unsigned volatile char NMEABuffer[MAX_EMPFANGS_BUFF]; |
15 | unsigned volatile char NMEABuffer[MAX_EMPFANGS_BUFF]; |
16 | unsigned volatile char NeuerDatensatzEmpfangen = 0; |
16 | unsigned volatile char NeuerDatensatzEmpfangen = 0; |
17 | unsigned volatile char NeueKoordinateEmpfangen = 0; |
17 | unsigned volatile char NeueKoordinateEmpfangen = 0; |
18 | unsigned volatile char UebertragungAbgeschlossen = 1; |
18 | unsigned volatile char UebertragungAbgeschlossen = 1; |
19 | unsigned volatile char CntCrcError = 0; |
19 | unsigned volatile char CntCrcError = 0; |
20 | unsigned volatile char AnzahlEmpfangsBytes = 0; |
20 | unsigned volatile char AnzahlEmpfangsBytes = 0; |
21 | unsigned volatile char PC_DebugTimeout = 0; |
21 | unsigned volatile char PC_DebugTimeout = 0; |
- | 22 | unsigned char RemotePollDisplayLine = 0; |
|
22 | unsigned char NurKanalAnforderung = 0; |
23 | unsigned char NurKanalAnforderung = 0; |
- | 24 | unsigned char DebugTextAnforderung = 255; |
|
23 | unsigned char PcZugriff = 100; |
25 | unsigned char PcZugriff = 100; |
24 | unsigned char MotorTest[4] = {0,0,0,0}; |
26 | unsigned char MotorTest[4] = {0,0,0,0}; |
25 | unsigned char DubWiseKeys[3] = {0,0,0}; |
27 | unsigned char DubWiseKeys[3] = {0,0,0}; |
26 | unsigned char MeineSlaveAdresse; |
28 | unsigned char MeineSlaveAdresse; |
27 | struct str_DebugOut DebugOut; |
29 | struct str_DebugOut DebugOut; |
28 | struct str_Debug DebugIn; |
30 | struct str_Debug DebugIn; |
29 | struct str_VersionInfo VersionInfo; |
31 | struct str_VersionInfo VersionInfo; |
30 | int Debug_Timer; |
32 | int Debug_Timer; |
- | 33 | ||
- | 34 | const unsigned char ANALOG_TEXT[32][16] = |
|
- | 35 | { |
|
- | 36 | //1234567890123456 |
|
- | 37 | "IntegralNick ", //0 |
|
- | 38 | "IntegralRoll ", |
|
- | 39 | "AccNick ", |
|
- | 40 | "AccRoll ", |
|
- | 41 | "GyroGier ", |
|
- | 42 | "HoehenWert ", //5 |
|
- | 43 | "AccZ ", |
|
- | 44 | "Gas ", |
|
- | 45 | "KompassValue ", |
|
- | 46 | "MesswertNick ", |
|
- | 47 | "10_SenderOkay ", //10 |
|
- | 48 | "11_MesswertRoll ", |
|
- | 49 | "Motor_Vorne ", |
|
- | 50 | "Motor_Hinten ", |
|
- | 51 | "Motor_Links ", |
|
- | 52 | "Motor_Rechts ", //15 |
|
- | 53 | "16_Acc_Z ", |
|
- | 54 | "17MittelAccNick ", |
|
- | 55 | "18_MittelAccRoll", |
|
- | 56 | "Analog19 ", |
|
- | 57 | "IntegralErrRoll ", //20 |
|
- | 58 | "Analog21 ", |
|
- | 59 | "22_MittelGIngR ", |
|
- | 60 | "Analog23 ", |
|
- | 61 | "24RollOffset ", |
|
- | 62 | "25IntRoll*Fakt ", //25 |
|
- | 63 | "Analog26 ", |
|
- | 64 | "DirektAusglRoll ", |
|
- | 65 | "28MesswertRoll ", |
|
- | 66 | "29AusgleichRoll ", |
|
- | 67 | "30_I-LageRoll ", //30 |
|
- | 68 | "31_StickRoll " |
|
- | 69 | }; |
|
- | 70 | ||
- | 71 | ||
31 | 72 | ||
32 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
73 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
33 | //++ Sende-Part der Datenübertragung |
74 | //++ Sende-Part der Datenübertragung |
34 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
75 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
35 | SIGNAL(INT_VEC_TX) |
76 | SIGNAL(INT_VEC_TX) |
36 | { |
77 | { |
37 | static unsigned int ptr = 0; |
78 | static unsigned int ptr = 0; |
38 | unsigned char tmp_tx; |
79 | unsigned char tmp_tx; |
39 | if(!UebertragungAbgeschlossen) |
80 | if(!UebertragungAbgeschlossen) |
40 | { |
81 | { |
41 | ptr++; // die [0] wurde schon gesendet |
82 | ptr++; // die [0] wurde schon gesendet |
42 | tmp_tx = SendeBuffer[ptr]; |
83 | tmp_tx = SendeBuffer[ptr]; |
43 | if((tmp_tx == '\r') || (ptr == MAX_SENDE_BUFF)) |
84 | if((tmp_tx == '\r') || (ptr == MAX_SENDE_BUFF)) |
44 | { |
85 | { |
45 | ptr = 0; |
86 | ptr = 0; |
46 | UebertragungAbgeschlossen = 1; |
87 | UebertragungAbgeschlossen = 1; |
47 | } |
88 | } |
48 | UDR = tmp_tx; |
89 | UDR = tmp_tx; |
49 | } |
90 | } |
50 | else ptr = 0; |
91 | else ptr = 0; |
51 | } |
92 | } |
52 | 93 | ||
53 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
94 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
54 | //++ Empfangs-Part der Datenübertragung, incl. CRC-Auswertung |
95 | //++ Empfangs-Part der Datenübertragung, incl. CRC-Auswertung |
55 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
96 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
56 | SIGNAL(INT_VEC_RX) |
97 | SIGNAL(INT_VEC_RX) |
57 | { |
98 | { |
58 | static unsigned int crc; |
99 | static unsigned int crc; |
59 | static unsigned char crc1,crc2,buf_ptr; |
100 | static unsigned char crc1,crc2,buf_ptr; |
60 | static unsigned char UartState = 0; |
101 | static unsigned char UartState = 0; |
61 | unsigned char CrcOkay = 0; |
102 | unsigned char CrcOkay = 0; |
62 | 103 | ||
63 | SioTmp = UDR; |
104 | SioTmp = UDR; |
64 | if(buf_ptr >= MAX_EMPFANGS_BUFF) UartState = 0; |
105 | if(buf_ptr >= MAX_EMPFANGS_BUFF) UartState = 0; |
65 | if(SioTmp == '\r' && UartState == 2) |
106 | if(SioTmp == '\r' && UartState == 2) |
66 | { |
107 | { |
67 | UartState = 0; |
108 | UartState = 0; |
68 | crc -= RxdBuffer[buf_ptr-2]; |
109 | crc -= RxdBuffer[buf_ptr-2]; |
69 | crc -= RxdBuffer[buf_ptr-1]; |
110 | crc -= RxdBuffer[buf_ptr-1]; |
70 | crc %= 4096; |
111 | crc %= 4096; |
71 | crc1 = '=' + crc / 64; |
112 | crc1 = '=' + crc / 64; |
72 | crc2 = '=' + crc % 64; |
113 | crc2 = '=' + crc % 64; |
73 | CrcOkay = 0; |
114 | CrcOkay = 0; |
74 | if((crc1 == RxdBuffer[buf_ptr-2]) && (crc2 == RxdBuffer[buf_ptr-1])) CrcOkay = 1; else { CrcOkay = 0; CntCrcError++;}; |
115 | if((crc1 == RxdBuffer[buf_ptr-2]) && (crc2 == RxdBuffer[buf_ptr-1])) CrcOkay = 1; else { CrcOkay = 0; CntCrcError++;}; |
75 | if(!NeuerDatensatzEmpfangen && CrcOkay) // Datensatz schon verarbeitet |
116 | if(!NeuerDatensatzEmpfangen && CrcOkay) // Datensatz schon verarbeitet |
76 | { |
117 | { |
77 | NeuerDatensatzEmpfangen = 1; |
118 | NeuerDatensatzEmpfangen = 1; |
78 | AnzahlEmpfangsBytes = buf_ptr; |
119 | AnzahlEmpfangsBytes = buf_ptr; |
79 | RxdBuffer[buf_ptr] = '\r'; |
120 | RxdBuffer[buf_ptr] = '\r'; |
80 | if(RxdBuffer[2] == 'R') wdt_enable(WDTO_250MS); // Reset-Commando |
121 | if(RxdBuffer[2] == 'R') wdt_enable(WDTO_250MS); // Reset-Commando |
81 | } |
122 | } |
82 | } |
123 | } |
83 | else |
124 | else |
84 | switch(UartState) |
125 | switch(UartState) |
85 | { |
126 | { |
86 | case 0: |
127 | case 0: |
87 | if(SioTmp == '#' && !NeuerDatensatzEmpfangen) UartState = 1; // Startzeichen und Daten schon verarbeitet |
128 | if(SioTmp == '#' && !NeuerDatensatzEmpfangen) UartState = 1; // Startzeichen und Daten schon verarbeitet |
88 | buf_ptr = 0; |
129 | buf_ptr = 0; |
89 | RxdBuffer[buf_ptr++] = SioTmp; |
130 | RxdBuffer[buf_ptr++] = SioTmp; |
90 | crc = SioTmp; |
131 | crc = SioTmp; |
91 | break; |
132 | break; |
92 | case 1: // Adresse auswerten |
133 | case 1: // Adresse auswerten |
93 | UartState++; |
134 | UartState++; |
94 | RxdBuffer[buf_ptr++] = SioTmp; |
135 | RxdBuffer[buf_ptr++] = SioTmp; |
95 | crc += SioTmp; |
136 | crc += SioTmp; |
96 | break; |
137 | break; |
97 | case 2: // Eingangsdaten sammeln |
138 | case 2: // Eingangsdaten sammeln |
98 | RxdBuffer[buf_ptr] = SioTmp; |
139 | RxdBuffer[buf_ptr] = SioTmp; |
99 | if(buf_ptr < MAX_EMPFANGS_BUFF) buf_ptr++; |
140 | if(buf_ptr < MAX_EMPFANGS_BUFF) buf_ptr++; |
100 | else UartState = 0; |
141 | else UartState = 0; |
101 | crc += SioTmp; |
142 | crc += SioTmp; |
102 | break; |
143 | break; |
103 | default: |
144 | default: |
104 | UartState = 0; |
145 | UartState = 0; |
105 | break; |
146 | break; |
106 | } |
147 | } |
107 | } |
148 | } |
108 | 149 | ||
109 | 150 | ||
110 | // -------------------------------------------------------------------------- |
151 | // -------------------------------------------------------------------------- |
111 | void AddCRC(unsigned int wieviele) |
152 | void AddCRC(unsigned int wieviele) |
112 | { |
153 | { |
113 | unsigned int tmpCRC = 0,i; |
154 | unsigned int tmpCRC = 0,i; |
114 | for(i = 0; i < wieviele;i++) |
155 | for(i = 0; i < wieviele;i++) |
115 | { |
156 | { |
116 | tmpCRC += SendeBuffer[i]; |
157 | tmpCRC += SendeBuffer[i]; |
117 | } |
158 | } |
118 | tmpCRC %= 4096; |
159 | tmpCRC %= 4096; |
119 | SendeBuffer[i++] = '=' + tmpCRC / 64; |
160 | SendeBuffer[i++] = '=' + tmpCRC / 64; |
120 | SendeBuffer[i++] = '=' + tmpCRC % 64; |
161 | SendeBuffer[i++] = '=' + tmpCRC % 64; |
121 | SendeBuffer[i++] = '\r'; |
162 | SendeBuffer[i++] = '\r'; |
122 | UebertragungAbgeschlossen = 0; |
163 | UebertragungAbgeschlossen = 0; |
123 | UDR = SendeBuffer[0]; |
164 | UDR = SendeBuffer[0]; |
124 | } |
165 | } |
125 | 166 | ||
126 | 167 | ||
127 | 168 | ||
128 | // -------------------------------------------------------------------------- |
169 | // -------------------------------------------------------------------------- |
129 | void SendOutData(unsigned char cmd,unsigned char modul, unsigned char *snd, unsigned char len) |
170 | void SendOutData(unsigned char cmd,unsigned char modul, unsigned char *snd, unsigned char len) |
130 | { |
171 | { |
131 | unsigned int pt = 0; |
172 | unsigned int pt = 0; |
132 | unsigned char a,b,c; |
173 | unsigned char a,b,c; |
133 | unsigned char ptr = 0; |
174 | unsigned char ptr = 0; |
134 | 175 | ||
135 | SendeBuffer[pt++] = '#'; // Startzeichen |
176 | SendeBuffer[pt++] = '#'; // Startzeichen |
136 | SendeBuffer[pt++] = modul; // Adresse (a=0; b=1,...) |
177 | SendeBuffer[pt++] = modul; // Adresse (a=0; b=1,...) |
137 | SendeBuffer[pt++] = cmd; // Commando |
178 | SendeBuffer[pt++] = cmd; // Commando |
138 | 179 | ||
139 | while(len) |
180 | while(len) |
140 | { |
181 | { |
141 | if(len) { a = snd[ptr++]; len--;} else a = 0; |
182 | if(len) { a = snd[ptr++]; len--;} else a = 0; |
142 | if(len) { b = snd[ptr++]; len--;} else b = 0; |
183 | if(len) { b = snd[ptr++]; len--;} else b = 0; |
143 | if(len) { c = snd[ptr++]; len--;} else c = 0; |
184 | if(len) { c = snd[ptr++]; len--;} else c = 0; |
144 | SendeBuffer[pt++] = '=' + (a >> 2); |
185 | SendeBuffer[pt++] = '=' + (a >> 2); |
145 | SendeBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
186 | SendeBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
146 | SendeBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
187 | SendeBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
147 | SendeBuffer[pt++] = '=' + ( c & 0x3f); |
188 | SendeBuffer[pt++] = '=' + ( c & 0x3f); |
148 | } |
189 | } |
149 | AddCRC(pt); |
190 | AddCRC(pt); |
150 | } |
191 | } |
151 | 192 | ||
152 | 193 | ||
153 | // -------------------------------------------------------------------------- |
194 | // -------------------------------------------------------------------------- |
154 | void Decode64(unsigned char *ptrOut, unsigned char len, unsigned char ptrIn,unsigned char max) // Wohin mit den Daten; Wie lang; Wo im RxdBuffer |
195 | void Decode64(unsigned char *ptrOut, unsigned char len, unsigned char ptrIn,unsigned char max) // Wohin mit den Daten; Wie lang; Wo im RxdBuffer |
155 | { |
196 | { |
156 | unsigned char a,b,c,d; |
197 | unsigned char a,b,c,d; |
157 | unsigned char ptr = 0; |
198 | unsigned char ptr = 0; |
158 | unsigned char x,y,z; |
199 | unsigned char x,y,z; |
159 | while(len) |
200 | while(len) |
160 | { |
201 | { |
161 | a = RxdBuffer[ptrIn++] - '='; |
202 | a = RxdBuffer[ptrIn++] - '='; |
162 | b = RxdBuffer[ptrIn++] - '='; |
203 | b = RxdBuffer[ptrIn++] - '='; |
163 | c = RxdBuffer[ptrIn++] - '='; |
204 | c = RxdBuffer[ptrIn++] - '='; |
164 | d = RxdBuffer[ptrIn++] - '='; |
205 | d = RxdBuffer[ptrIn++] - '='; |
165 | if(ptrIn > max - 2) break; // nicht mehr Daten verarbeiten, als empfangen wurden |
206 | if(ptrIn > max - 2) break; // nicht mehr Daten verarbeiten, als empfangen wurden |
166 | 207 | ||
167 | x = (a << 2) | (b >> 4); |
208 | x = (a << 2) | (b >> 4); |
168 | y = ((b & 0x0f) << 4) | (c >> 2); |
209 | y = ((b & 0x0f) << 4) | (c >> 2); |
169 | z = ((c & 0x03) << 6) | d; |
210 | z = ((c & 0x03) << 6) | d; |
170 | 211 | ||
171 | if(len--) ptrOut[ptr++] = x; else break; |
212 | if(len--) ptrOut[ptr++] = x; else break; |
172 | if(len--) ptrOut[ptr++] = y; else break; |
213 | if(len--) ptrOut[ptr++] = y; else break; |
173 | if(len--) ptrOut[ptr++] = z; else break; |
214 | if(len--) ptrOut[ptr++] = z; else break; |
174 | } |
215 | } |
175 | 216 | ||
176 | } |
217 | } |
177 | 218 | ||
178 | // -------------------------------------------------------------------------- |
219 | // -------------------------------------------------------------------------- |
179 | void BearbeiteRxDaten(void) |
220 | void BearbeiteRxDaten(void) |
180 | { |
221 | { |
181 | if(!NeuerDatensatzEmpfangen) return; |
222 | if(!NeuerDatensatzEmpfangen) return; |
182 | 223 | ||
183 | // unsigned int tmp_int_arr1[1]; |
224 | // unsigned int tmp_int_arr1[1]; |
184 | // unsigned int tmp_int_arr2[2]; |
225 | // unsigned int tmp_int_arr2[2]; |
185 | // unsigned int tmp_int_arr3[3]; |
226 | // unsigned int tmp_int_arr3[3]; |
186 | unsigned char tmp_char_arr2[2]; |
227 | unsigned char tmp_char_arr2[2]; |
187 | // unsigned char tmp_char_arr3[3]; |
228 | // unsigned char tmp_char_arr3[3]; |
188 | // unsigned char tmp_char_arr4[4]; |
229 | // unsigned char tmp_char_arr4[4]; |
189 | //if(!MotorenEin) |
230 | //if(!MotorenEin) |
190 | PcZugriff = 255; |
231 | PcZugriff = 255; |
191 | switch(RxdBuffer[2]) |
232 | switch(RxdBuffer[2]) |
192 | { |
233 | { |
- | 234 | case 'a':// Texte der Analogwerte |
|
- | 235 | Decode64((unsigned char *) &tmp_char_arr2[0],sizeof(tmp_char_arr2),3,AnzahlEmpfangsBytes); |
|
- | 236 | DebugTextAnforderung = tmp_char_arr2[0]; |
|
- | 237 | break; |
|
193 | case 'c':// Debugdaten incl. Externe IOs usw |
238 | case 'c':// Debugdaten incl. Externe IOs usw |
194 | Decode64((unsigned char *) &DebugIn,sizeof(DebugIn),3,AnzahlEmpfangsBytes); |
239 | Decode64((unsigned char *) &DebugIn,sizeof(DebugIn),3,AnzahlEmpfangsBytes); |
195 | /* for(unsigned char i=0; i<4;i++) |
240 | /* for(unsigned char i=0; i<4;i++) |
196 | { |
241 | { |
197 | EE_CheckAndWrite(&EE_Buffer[EE_DEBUGWERTE + i*2], DebugIn.Analog[i]); |
242 | EE_CheckAndWrite(&EE_Buffer[EE_DEBUGWERTE + i*2], DebugIn.Analog[i]); |
198 | EE_CheckAndWrite(&EE_Buffer[EE_DEBUGWERTE + i*2 + 1], DebugIn.Analog[i] >> 8); |
243 | EE_CheckAndWrite(&EE_Buffer[EE_DEBUGWERTE + i*2 + 1], DebugIn.Analog[i] >> 8); |
199 | }*/ |
244 | }*/ |
200 | RemoteTasten |= DebugIn.RemoteTasten; |
245 | RemoteTasten |= DebugIn.RemoteTasten; |
201 | DebugDataAnforderung = 1; |
246 | DebugDataAnforderung = 1; |
202 | break; |
247 | break; |
203 | case 'h':// x-1 Displayzeilen |
248 | case 'h':// x-1 Displayzeilen |
204 | Decode64((unsigned char *) &tmp_char_arr2[0],sizeof(tmp_char_arr2),3,AnzahlEmpfangsBytes); |
249 | Decode64((unsigned char *) &tmp_char_arr2[0],sizeof(tmp_char_arr2),3,AnzahlEmpfangsBytes); |
205 | RemoteTasten |= tmp_char_arr2[0]; |
250 | RemoteTasten |= tmp_char_arr2[0]; |
206 | if(tmp_char_arr2[1] == 255) NurKanalAnforderung = 1; else NurKanalAnforderung = 0; // keine Displaydaten |
251 | if(tmp_char_arr2[1] == 255) NurKanalAnforderung = 1; else NurKanalAnforderung = 0; // keine Displaydaten |
207 | DebugDisplayAnforderung = 1; |
252 | DebugDisplayAnforderung = 1; |
208 | break; |
253 | break; |
209 | case 't':// Motortest |
254 | case 't':// Motortest |
210 | Decode64((unsigned char *) &MotorTest[0],sizeof(MotorTest),3,AnzahlEmpfangsBytes); |
255 | Decode64((unsigned char *) &MotorTest[0],sizeof(MotorTest),3,AnzahlEmpfangsBytes); |
211 | break; |
256 | break; |
212 | case 'k':// Keys von DubWise |
257 | case 'k':// Keys von DubWise |
213 | Decode64((unsigned char *) &DubWiseKeys[0],sizeof(DubWiseKeys),3,AnzahlEmpfangsBytes); |
258 | Decode64((unsigned char *) &DubWiseKeys[0],sizeof(DubWiseKeys),3,AnzahlEmpfangsBytes); |
214 | break; |
259 | break; |
215 | case 'v': // Version-Anforderung und Ausbaustufe |
260 | case 'v': // Version-Anforderung und Ausbaustufe |
216 | GetVersionAnforderung = 1; |
261 | GetVersionAnforderung = 1; |
217 | break; |
262 | break; |
218 | case 'g':// "Get"-Anforderung für Debug-Daten |
263 | case 'g':// "Get"-Anforderung für Debug-Daten |
219 | // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
264 | // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
220 | DebugGetAnforderung = 1; |
265 | DebugGetAnforderung = 1; |
221 | break; |
266 | break; |
222 | case 'q':// "Get"-Anforderung für Settings |
267 | case 'q':// "Get"-Anforderung für Settings |
223 | // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
268 | // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
224 | Decode64((unsigned char *) &tmp_char_arr2[0],sizeof(tmp_char_arr2),3,AnzahlEmpfangsBytes); |
269 | Decode64((unsigned char *) &tmp_char_arr2[0],sizeof(tmp_char_arr2),3,AnzahlEmpfangsBytes); |
225 | if(tmp_char_arr2[0] != 0xff) |
270 | if(tmp_char_arr2[0] != 0xff) |
226 | { |
271 | { |
227 | if(tmp_char_arr2[0] > 5) tmp_char_arr2[0] = 5; |
272 | if(tmp_char_arr2[0] > 5) tmp_char_arr2[0] = 5; |
228 | ReadParameterSet(tmp_char_arr2[0], (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
273 | ReadParameterSet(tmp_char_arr2[0], (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
229 | SendOutData('L' + tmp_char_arr2[0] -1,MeineSlaveAdresse,(unsigned char *) &EE_Parameter.Kanalbelegung[0],STRUCT_PARAM_LAENGE); |
274 | SendOutData('L' + tmp_char_arr2[0] -1,MeineSlaveAdresse,(unsigned char *) &EE_Parameter.Kanalbelegung[0],STRUCT_PARAM_LAENGE); |
230 | } |
275 | } |
231 | else |
276 | else |
232 | SendOutData('L' + GetActiveParamSetNumber()-1,MeineSlaveAdresse,(unsigned char *) &EE_Parameter.Kanalbelegung[0],STRUCT_PARAM_LAENGE); |
277 | SendOutData('L' + GetActiveParamSetNumber()-1,MeineSlaveAdresse,(unsigned char *) &EE_Parameter.Kanalbelegung[0],STRUCT_PARAM_LAENGE); |
233 | 278 | ||
234 | break; |
279 | break; |
235 | 280 | ||
236 | case 'l': |
281 | case 'l': |
237 | case 'm': |
282 | case 'm': |
238 | case 'n': |
283 | case 'n': |
239 | case 'o': |
284 | case 'o': |
240 | case 'p': // Parametersatz speichern |
285 | case 'p': // Parametersatz speichern |
241 | Decode64((unsigned char *) &EE_Parameter.Kanalbelegung[0],STRUCT_PARAM_LAENGE,3,AnzahlEmpfangsBytes); |
286 | Decode64((unsigned char *) &EE_Parameter.Kanalbelegung[0],STRUCT_PARAM_LAENGE,3,AnzahlEmpfangsBytes); |
242 | WriteParameterSet(RxdBuffer[2] - 'l' + 1, (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
287 | WriteParameterSet(RxdBuffer[2] - 'l' + 1, (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
243 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], RxdBuffer[2] - 'l' + 1); // aktiven Datensatz merken |
288 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], RxdBuffer[2] - 'l' + 1); // aktiven Datensatz merken |
244 | Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L; |
289 | Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L; |
245 | Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L; |
290 | Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L; |
246 | Piep(GetActiveParamSetNumber()); |
291 | Piep(GetActiveParamSetNumber()); |
247 | break; |
292 | break; |
248 | 293 | ||
249 | 294 | ||
250 | } |
295 | } |
251 | // DebugOut.AnzahlZyklen = Debug_Timer_Intervall; |
296 | // DebugOut.AnzahlZyklen = Debug_Timer_Intervall; |
252 | NeuerDatensatzEmpfangen = 0; |
297 | NeuerDatensatzEmpfangen = 0; |
253 | } |
298 | } |
254 | 299 | ||
255 | //############################################################################ |
300 | //############################################################################ |
256 | //Routine für die Serielle Ausgabe |
301 | //Routine für die Serielle Ausgabe |
257 | int uart_putchar (char c) |
302 | int uart_putchar (char c) |
258 | //############################################################################ |
303 | //############################################################################ |
259 | { |
304 | { |
260 | if (c == '\n') |
305 | if (c == '\n') |
261 | uart_putchar('\r'); |
306 | uart_putchar('\r'); |
262 | //Warten solange bis Zeichen gesendet wurde |
307 | //Warten solange bis Zeichen gesendet wurde |
263 | loop_until_bit_is_set(USR, UDRE); |
308 | loop_until_bit_is_set(USR, UDRE); |
264 | //Ausgabe des Zeichens |
309 | //Ausgabe des Zeichens |
265 | UDR = c; |
310 | UDR = c; |
266 | 311 | ||
267 | return (0); |
312 | return (0); |
268 | } |
313 | } |
269 | 314 | ||
270 | // -------------------------------------------------------------------------- |
315 | // -------------------------------------------------------------------------- |
271 | void WriteProgramData(unsigned int pos, unsigned char wert) |
316 | void WriteProgramData(unsigned int pos, unsigned char wert) |
272 | { |
317 | { |
273 | //if (ProgramLocation == IN_RAM) Buffer[pos] = wert; |
318 | //if (ProgramLocation == IN_RAM) Buffer[pos] = wert; |
274 | // else eeprom_write_byte(&EE_Buffer[pos], wert); |
319 | // else eeprom_write_byte(&EE_Buffer[pos], wert); |
275 | // Buffer[pos] = wert; |
320 | // Buffer[pos] = wert; |
276 | } |
321 | } |
277 | 322 | ||
278 | //############################################################################ |
323 | //############################################################################ |
279 | //INstallation der Seriellen Schnittstelle |
324 | //INstallation der Seriellen Schnittstelle |
280 | void UART_Init (void) |
325 | void UART_Init (void) |
281 | //############################################################################ |
326 | //############################################################################ |
282 | { |
327 | { |
283 | //Enable TXEN im Register UCR TX-Data Enable & RX Enable |
328 | //Enable TXEN im Register UCR TX-Data Enable & RX Enable |
284 | 329 | ||
285 | UCR=(1 << TXEN) | (1 << RXEN); |
330 | UCR=(1 << TXEN) | (1 << RXEN); |
286 | // UART Double Speed (U2X) |
331 | // UART Double Speed (U2X) |
287 | USR |= (1<<U2X); |
332 | USR |= (1<<U2X); |
288 | // RX-Interrupt Freigabe |
333 | // RX-Interrupt Freigabe |
289 | UCSRB |= (1<<RXCIE); |
334 | UCSRB |= (1<<RXCIE); |
290 | // TX-Interrupt Freigabe |
335 | // TX-Interrupt Freigabe |
291 | UCSRB |= (1<<TXCIE); |
336 | UCSRB |= (1<<TXCIE); |
292 | 337 | ||
293 | //Teiler wird gesetzt |
338 | //Teiler wird gesetzt |
294 | UBRR=(SYSCLK / (BAUD_RATE * 8L) - 1); |
339 | UBRR=(SYSCLK / (BAUD_RATE * 8L) - 1); |
295 | //UBRR = 33; |
340 | //UBRR = 33; |
296 | //öffnet einen Kanal für printf (STDOUT) |
341 | //öffnet einen Kanal für printf (STDOUT) |
297 | //fdevopen (uart_putchar, 0); |
342 | //fdevopen (uart_putchar, 0); |
298 | //sbi(PORTD,4); |
343 | //sbi(PORTD,4); |
299 | Debug_Timer = SetDelay(200); |
344 | Debug_Timer = SetDelay(200); |
300 | } |
345 | } |
301 | 346 | ||
302 | //--------------------------------------------------------------------------------------------- |
347 | //--------------------------------------------------------------------------------------------- |
303 | void DatenUebertragung(void) |
348 | void DatenUebertragung(void) |
304 | { |
349 | { |
305 | static char dis_zeile = 0; |
- | |
306 | if(!UebertragungAbgeschlossen) return; |
350 | if(!UebertragungAbgeschlossen) return; |
307 | 351 | ||
308 | if(DebugGetAnforderung && UebertragungAbgeschlossen) // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
352 | if(DebugGetAnforderung && UebertragungAbgeschlossen) // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
309 | { |
353 | { |
310 | SendOutData('G',MeineSlaveAdresse,(unsigned char *) &DebugIn,sizeof(DebugIn)); |
354 | SendOutData('G',MeineSlaveAdresse,(unsigned char *) &DebugIn,sizeof(DebugIn)); |
311 | DebugGetAnforderung = 0; |
355 | DebugGetAnforderung = 0; |
312 | } |
356 | } |
313 | 357 | ||
314 | if((CheckDelay(Debug_Timer) || DebugDataAnforderung) && UebertragungAbgeschlossen) |
358 | if((CheckDelay(Debug_Timer) || DebugDataAnforderung) && UebertragungAbgeschlossen) |
315 | { |
359 | { |
316 | SendOutData('D',MeineSlaveAdresse,(unsigned char *) &DebugOut,sizeof(DebugOut)); |
360 | SendOutData('D',MeineSlaveAdresse,(unsigned char *) &DebugOut,sizeof(DebugOut)); |
317 | DebugDataAnforderung = 0; |
361 | DebugDataAnforderung = 0; |
318 | Debug_Timer = SetDelay(MIN_DEBUG_INTERVALL); |
362 | Debug_Timer = SetDelay(MIN_DEBUG_INTERVALL); |
319 | } |
363 | } |
- | 364 | if(DebugTextAnforderung != 255) // Texte für die Analogdaten |
|
- | 365 | { |
|
- | 366 | SendOutData('A',DebugTextAnforderung + '0',(unsigned char *) ANALOG_TEXT[DebugTextAnforderung],16); |
|
- | 367 | DebugTextAnforderung = 255; |
|
- | 368 | } |
|
320 | 369 | ||
321 | if(DebugDisplayAnforderung && UebertragungAbgeschlossen) |
370 | if(DebugDisplayAnforderung && UebertragungAbgeschlossen) |
322 | { |
371 | { |
323 | Menu(); |
372 | Menu(); |
324 | DebugDisplayAnforderung = 0; |
373 | DebugDisplayAnforderung = 0; |
325 | if(++dis_zeile == 4 || NurKanalAnforderung) |
374 | if(++RemotePollDisplayLine == 4 || NurKanalAnforderung) |
326 | { |
375 | { |
327 | SendOutData('4',0,(unsigned char *)&PPM_in,sizeof(PPM_in)); // DisplayZeile übertragen |
376 | SendOutData('4',0,(unsigned char *)&PPM_in,sizeof(PPM_in)); // DisplayZeile übertragen |
328 | dis_zeile = -1; |
377 | RemotePollDisplayLine = -1; |
329 | } |
378 | } |
330 | else SendOutData('0' + dis_zeile,0,(unsigned char *)&DisplayBuff[20 * dis_zeile],20); // DisplayZeile übertragen |
379 | else SendOutData('0' + RemotePollDisplayLine,0,(unsigned char *)&DisplayBuff[20 * RemotePollDisplayLine],20); // DisplayZeile übertragen |
331 | } |
380 | } |
332 | if(GetVersionAnforderung && UebertragungAbgeschlossen) |
381 | if(GetVersionAnforderung && UebertragungAbgeschlossen) |
333 | { |
382 | { |
334 | SendOutData('V',MeineSlaveAdresse,(unsigned char *) &VersionInfo,sizeof(VersionInfo)); |
383 | SendOutData('V',MeineSlaveAdresse,(unsigned char *) &VersionInfo,sizeof(VersionInfo)); |
335 | GetVersionAnforderung = 0; |
384 | GetVersionAnforderung = 0; |
336 | } |
385 | } |
337 | 386 | ||
338 | } |
387 | } |
339 | 388 | ||
340 | 389 |