Blame |
Last modification |
View Log
| RSS feed
// debug Data
#include <avr/io.h>
#include <inttypes.h>
#include <stdlib.h>
#include <avr/pgmspace.h>
#include "main.h"
#include "lcd.h"
#include "rs232.h"
#include "base64.h"
#include "parameter.h"
#include "menu.h"
#include "debug.h"
uint8_t r_buffer[129]; // Dieser Puffer enthält die Rohdaten (kodiert)
uint8_t base64_decode_debug(unsigned char *ptrOut, uint8_t number) // Wandelt die base64-Rohdaten in lesbare Daten um
{
uint8_t p,q;
uint8_t a,b,c,d;
p = 2;
q = 0;
while (p < number)
{
a = r_buffer[p + 0] - 61;
b = r_buffer[p + 1] - 61;
c = r_buffer[p + 2] - 61;
d = r_buffer[p + 3] - 61;
p += 4;
ptrOut[q + 0] = (a << 2) | (b >> 4); // gespeichert werden die Daten in ptrOut
ptrOut[q + 1] = ((b & 0x0F) << 4) | (c >> 2);
ptrOut[q + 2] = ((c & 0x03) << 6) | d;
q += 3;
}
return q; // Rückgabe der Anzahl der Datenbytes
}
uint8_t get_message_debug(uint8_t command) // Liest eine komplette Übertragung und dekodiert sie
{
uint8_t index, comm;
timer = 20; // Timer für Timeout
while ((RS232_get() != '#') && (timer > 0)); // Warten auf Start-Zeichen #
if (timer > 0) // Falls kein Timeout auftrat
{
index = 0; // Die Rohdaten in r_buffer einlesen
do
{
comm = RS232_get();
r_buffer[index++] = comm;
if (index > 127) // Schutz vor Puffer-Überlauf
index = 127;
}
while (comm != 0x0D); // ... bis End-Signal = 0x0D kommt...
if (command == 34)
base64_decode_debug((unsigned char *) &DebugIn,index); // Die base64-kodierten Rohdaten umwandeln
else
base64_decode_debug((unsigned char *) &DebugInText[command][0], index); // Die base64-kodierten Rohdaten umwandeln
DebugInText[command][15] = 0x00; // Ende Zeichen setzen!!
return 0; // kein Fehler aufgetreten
}
else
{
return 1; // Fehler aufgetreten
}
}
uint8_t read_debug(uint8_t command_read) //
{
uint8_t timeout;
char compare;
timeout = 0;
p_buffer[0] = '#'; // Debug-Daten anfordern
p_buffer[1] = 'a';
if (command_read == 34)
{
p_buffer[2] = 'c';
p_buffer[3] = 0;
}
if (command_read < 32)
{
p_buffer[2] = 'a';
p_buffer[3] = command_read;
}
p_buffer[4] = 0;
p_buffer[5] = 0;
base64_send(6);
if (command_read == 34)
compare = 'D';
else
compare = 'A';
do // warten, bis die Parameter gesendet werden
{
if (get_message_debug(command_read) == 1)
timeout = 30;
timeout ++;
}
while (((r_buffer[1] < compare) || (r_buffer[1] > compare)) && (timeout < 30)); // "!=" funktioniert witzigerweise ned
if (timeout >= 30)
return 1;
else
return 0;
}
#define isminus 65536 / 2
void decimal_int (unsigned int data, uint8_t *text) // wandelt Wert in rechtsbündigen Text um
{
int sign = 0;
text[0] = 0x20; // (schneller/kleiner als printf())
if (data > isminus)
{
data = 65536 - data;
sign = 1;
text[0] = '-';
}
text[1] = data/10000;
data -= (text[1] * 10000);
text[2] = data/1000;
data -= (text[2] *1000);
text[3] = data/100;
data -= (text[3] * 100);
text[4] = data/10;
data -= (text[4] *10);
text[5] = data + 0x30;
text[1] += 0x30;
text[2] += 0x30;
text[3] += 0x30;
text[4] += 0x30;
if (text[1] == 0x30)
{
text[0] = 0x20;
if (sign == 1) text[1] = '-'; else text[1] = 0x20;
if (text[2] == 0x30)
{
text[1] = 0x20;
if (sign == 1) text[2] = '-'; else text[2] = 0x20;
if (text[3] == 0x30)
{
text[2] = 0x20;
if (sign == 1) text[3] = '-'; else text[3] = 0x20;
if (text[4] == 0x30)
{
text[3] = 0x20;
if (sign == 1) text[4] = '-'; else text[4] = 0x20;
}
}
}
}
text[6] = 0x00;
}
void display_debug(void)
{
uint8_t zeile;
uint8_t text[10];
uint8_t i = 0;
int page = 0;
#define step 7
uint8_t flag = 0;
lcd_cls();
zeile = 0;
lcd_printp(PSTR("Debug-Display"),0);
for (i=0;i<32;i++)
{
if (read_debug(i) == 1)
{
if (read_debug(i) == 1) // 2mal Probieren
flag = 1;
}
}
if (flag == 1)
{
flag = 0;
lcd_printp(PSTR("\r\nTimeout!"),0);
timer = 200;
while (timer > 0);
}
else
{
do
{
while (key != 0x00);
if (read_debug(34) == 1) //Debugwerte
{
lcd_printp(PSTR("\r\nTimeout!"),0);
timer = 200;
while (timer > 0);
break;
}
else
{
decimal_int(page,text);
// lcd_print_atp(0,6,PSTR("Page"),0);
lcd_print_at(15,0,text,0);
for (i=0;i<step;i++)
{
if ((i + (page * step)) < 32)
{
decimal_int(DebugIn.Analog[i + (page * step)],text);
lcd_print_at(0,i+1,DebugInText[i + (page * step)],0);
lcd_print_at(13,i+1,text,0);
}
else
lcd_print_atp(0,i+1,PSTR(" "),0);
}
// decimal_int(DebugIn.Analog[9],text);
// lcd_print_atp(0,7,PSTR("Spannung"),0);
// lcd_print_at(10,7,text,0);
timer = 10;
while(timer > 0);
if (key == 0x01)
{
page--;
if (page < 0) page = 0;
}
if (key == 0x02)
{
page++;
if (page > 7) page = 7;
}
} // end else
}
while (key != 0x04); // ESC
} // end else
}