Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
107 | mikeljo | 1 | // debug Data |
2 | |||
3 | #include <avr/io.h> |
||
4 | #include <inttypes.h> |
||
5 | #include <stdlib.h> |
||
6 | #include <avr/pgmspace.h> |
||
7 | |||
8 | #include "main.h" |
||
9 | #include "lcd.h" |
||
10 | #include "rs232.h" |
||
11 | #include "base64.h" |
||
12 | #include "parameter.h" |
||
13 | #include "menu.h" |
||
14 | #include "debug.h" |
||
15 | |||
16 | uint8_t r_buffer[128]; // Dieser Puffer enthält die Rohdaten (kodiert) |
||
17 | //uint8_t p_buffer[128]; // Dieser Puffer enthält die Daten im Klartext |
||
18 | //struct str_DebugIn *p_buffer; |
||
19 | |||
20 | uint8_t base64_decode_debug(unsigned char *ptrOut, uint8_t number) // Wandelt die base64-Rohdaten in lesbare Daten um |
||
21 | { |
||
22 | uint8_t p,q; |
||
23 | uint8_t a,b,c,d; |
||
24 | |||
25 | p = 2; |
||
26 | q = 0; |
||
27 | |||
28 | while (p < number) |
||
29 | { |
||
30 | a = r_buffer[p + 0] - 61; |
||
31 | b = r_buffer[p + 1] - 61; |
||
32 | c = r_buffer[p + 2] - 61; |
||
33 | d = r_buffer[p + 3] - 61; |
||
34 | |||
35 | p += 4; |
||
36 | |||
37 | ptrOut[q + 0] = (a << 2) | (b >> 4); // gespeichert werden die Daten in p_buffer |
||
38 | ptrOut[q + 1] = ((b & 0x0F) << 4) | (c >> 2); |
||
39 | ptrOut[q + 2] = ((c & 0x03) << 6) | d; |
||
40 | |||
41 | q += 3; |
||
42 | } |
||
43 | return q; // Rückgabe der Anzahl der Datenbytes |
||
44 | } |
||
45 | |||
46 | uint8_t get_message_debug() // Liest eine komplette Übertragung und dekodiert sie |
||
47 | { |
||
48 | uint8_t index, comm; |
||
49 | |||
50 | timer = 20; // Timer für Timeout |
||
51 | |||
52 | while ((RS232_get() != '#') && (timer > 0)); // Warten auf Start-Zeichen # |
||
53 | |||
54 | if (timer > 0) // Falls kein Timeout auftrat |
||
55 | { |
||
56 | index = 0; // Die Rohdaten in r_buffer einlesen |
||
57 | do |
||
58 | { |
||
59 | comm = RS232_get(); |
||
60 | r_buffer[index++] = comm; |
||
61 | |||
62 | if (index > 127) // Schutz vor Puffer-Überlauf |
||
63 | index = 127; |
||
64 | } |
||
65 | while (comm != 0x0D); // ... bis End-Signal = 0x0D kommt... |
||
66 | base64_decode_debug((unsigned char *) &DebugIn, index); // Die base64-kodierten Rohdaten umwandeln |
||
67 | return 0; // kein Fehler aufgetreten |
||
68 | } |
||
69 | else |
||
70 | { |
||
71 | return 1; // Fehler aufgetreten |
||
72 | } |
||
73 | } |
||
74 | |||
75 | uint8_t read_debug(uint8_t command) // |
||
76 | { |
||
77 | uint8_t timeout; |
||
78 | |||
79 | timeout = 0; |
||
80 | p_buffer[0] = '#'; // Debug-Daten anfordern |
||
81 | p_buffer[1] = 'a'; |
||
82 | p_buffer[2] = 'c'; |
||
83 | p_buffer[3] = command; |
||
84 | p_buffer[4] = 0; |
||
85 | p_buffer[5] = 0; |
||
86 | base64_send(6); |
||
87 | |||
88 | do // warten, bis die Parameter gesendet werden |
||
89 | { |
||
90 | if (get_message_debug() == 1) |
||
91 | timeout = 30; |
||
92 | timeout ++; |
||
93 | } |
||
94 | while ((r_buffer[1] != 'D') && (timeout < 30)); |
||
95 | |||
96 | if (timeout >= 30) |
||
97 | return 1; |
||
98 | else |
||
99 | return 0; |
||
100 | } |
||
101 | |||
102 | #define isminus 65536 / 2 |
||
103 | |||
104 | void decimal_int (unsigned int data, uint8_t *text) // wandelt Wert in rechtsbündigen Text um |
||
105 | { |
||
106 | int sign = 0; |
||
107 | text[0] = 0x20; // (schneller/kleiner als printf()) |
||
108 | if (data > isminus) |
||
109 | { |
||
110 | data = 65536 - data; |
||
111 | sign = 1; |
||
112 | text[0] = '-'; |
||
113 | } |
||
114 | |||
115 | text[1] = data/10000; |
||
116 | data -= (text[1] * 10000); |
||
117 | text[2] = data/1000; |
||
118 | data -= (text[2] *1000); |
||
119 | |||
120 | text[3] = data/100; |
||
121 | data -= (text[3] * 100); |
||
122 | text[4] = data/10; |
||
123 | data -= (text[4] *10); |
||
124 | |||
125 | |||
126 | text[5] = data + 0x30; |
||
127 | text[1] += 0x30; |
||
128 | text[2] += 0x30; |
||
129 | text[3] += 0x30; |
||
130 | text[4] += 0x30; |
||
131 | |||
132 | |||
133 | if (text[1] == 0x30) |
||
134 | { |
||
135 | text[0] = 0x20; |
||
136 | if (sign == 1) text[1] = '-'; else text[1] = 0x20; |
||
137 | if (text[2] == 0x30) |
||
138 | { |
||
139 | text[1] = 0x20; |
||
140 | if (sign == 1) text[2] = '-'; else text[2] = 0x20; |
||
141 | if (text[3] == 0x30) |
||
142 | { |
||
143 | text[2] = 0x20; |
||
144 | if (sign == 1) text[3] = '-'; else text[3] = 0x20; |
||
145 | if (text[4] == 0x30) |
||
146 | { |
||
147 | text[3] = 0x20; |
||
148 | if (sign == 1) text[4] = '-'; else text[4] = 0x20; |
||
149 | } |
||
150 | } |
||
151 | } |
||
152 | } |
||
153 | // if (sign == 1) text[0] = '-'; |
||
154 | text[6] = 0x00; |
||
155 | } |
||
156 | |||
157 | void display_debug(void) |
||
158 | { |
||
159 | uint8_t line; |
||
160 | uint8_t zeile; |
||
161 | uint8_t text[10]; |
||
162 | |||
163 | lcd_cls(); |
||
164 | zeile = 0; |
||
165 | lcd_printp(PSTR("Debug-Display"),0); |
||
166 | do |
||
167 | { |
||
168 | while (key != 0x00); |
||
169 | if (read_debug(0) == 1) |
||
170 | { |
||
171 | lcd_printp(PSTR("\r\nTimeout!"),0); |
||
172 | timer = 200; |
||
173 | while (timer > 0); |
||
174 | break; |
||
175 | } |
||
176 | else |
||
177 | { |
||
178 | line = p_buffer[2]; |
||
179 | text[0] = line; |
||
180 | text[1] = 0x00; |
||
181 | lcd_print_at(15,0,text,0); |
||
182 | |||
183 | //lcd_print_at(0,++zeile,p_buffer,0); |
||
184 | |||
185 | decimal_int(DebugIn.Analog[0],text); |
||
186 | lcd_print_at(0,1,"Nick",0); |
||
187 | lcd_print_at(10,1,text,0); |
||
188 | decimal_int(DebugIn.Analog[1],text); |
||
189 | lcd_print_at(0,2,"Roll",0); |
||
190 | lcd_print_at(10,2,text,0); |
||
191 | decimal_int(DebugIn.Analog[2],text); |
||
192 | lcd_print_at(0,3,"ACC Nick",0); |
||
193 | lcd_print_at(10,3,text,0); |
||
194 | decimal_int(DebugIn.Analog[3],text); |
||
195 | lcd_print_at(0,4,"ACC Roll",0); |
||
196 | lcd_print_at(10,4,text,0); |
||
197 | decimal_int(DebugIn.Analog[4],text); |
||
198 | lcd_print_at(0,5,"Gier",0); |
||
199 | lcd_print_at(10,5,text,0); |
||
200 | decimal_int(DebugIn.Analog[5],text); |
||
201 | lcd_print_at(0,6,"ACC",0); |
||
202 | lcd_print_at(10,6,text,0); |
||
203 | |||
204 | decimal_int(DebugIn.Analog[9],text); |
||
205 | lcd_print_at(0,7,"Spannung",0); |
||
206 | lcd_print_at(10,7,text,0); |
||
207 | |||
208 | // decimal_int(DebugIn.Analog[zeile],text); |
||
209 | // lcd_print_at(0,++zeile,text,0); |
||
210 | |||
211 | |||
212 | // decimal(p_buffer[zeile],text); |
||
213 | // lcd_print_at(0,++zeile,text,0); |
||
214 | |||
215 | if (zeile > 5) zeile = 0; |
||
216 | |||
217 | timer = 10; |
||
218 | while(timer > 0); |
||
219 | |||
220 | // if (key == 0x01) |
||
221 | // read_debug(1); |
||
222 | // if (key == 0x02) |
||
223 | // read_debug(2); |
||
224 | } |
||
225 | |||
226 | } |
||
227 | while (key != 0x04); |
||
228 | } |