Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 109 → Rev 110

/Transportables_Koptertool/trunk/V-0.1/debug.c
0,0 → 1,228
// 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[128]; // Dieser Puffer enthält die Rohdaten (kodiert)
//uint8_t p_buffer[128]; // Dieser Puffer enthält die Daten im Klartext
//struct str_DebugIn *p_buffer;
 
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 p_buffer
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() // 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...
base64_decode_debug((unsigned char *) &DebugIn, index); // Die base64-kodierten Rohdaten umwandeln
return 0; // kein Fehler aufgetreten
}
else
{
return 1; // Fehler aufgetreten
}
}
 
uint8_t read_debug(uint8_t command) //
{
uint8_t timeout;
timeout = 0;
p_buffer[0] = '#'; // Debug-Daten anfordern
p_buffer[1] = 'a';
p_buffer[2] = 'c';
p_buffer[3] = command;
p_buffer[4] = 0;
p_buffer[5] = 0;
base64_send(6);
do // warten, bis die Parameter gesendet werden
{
if (get_message_debug() == 1)
timeout = 30;
timeout ++;
}
while ((r_buffer[1] != 'D') && (timeout < 30));
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;
}
}
}
}
// if (sign == 1) text[0] = '-';
text[6] = 0x00;
}
 
void display_debug(void)
{
uint8_t line;
uint8_t zeile;
uint8_t text[10];
 
lcd_cls();
zeile = 0;
lcd_printp(PSTR("Debug-Display"),0);
do
{
while (key != 0x00);
if (read_debug(0) == 1)
{
lcd_printp(PSTR("\r\nTimeout!"),0);
timer = 200;
while (timer > 0);
break;
}
else
{
line = p_buffer[2];
text[0] = line;
text[1] = 0x00;
lcd_print_at(15,0,text,0);
//lcd_print_at(0,++zeile,p_buffer,0);
 
decimal_int(DebugIn.Analog[0],text);
lcd_print_at(0,1,"Nick",0);
lcd_print_at(10,1,text,0);
decimal_int(DebugIn.Analog[1],text);
lcd_print_at(0,2,"Roll",0);
lcd_print_at(10,2,text,0);
decimal_int(DebugIn.Analog[2],text);
lcd_print_at(0,3,"ACC Nick",0);
lcd_print_at(10,3,text,0);
decimal_int(DebugIn.Analog[3],text);
lcd_print_at(0,4,"ACC Roll",0);
lcd_print_at(10,4,text,0);
decimal_int(DebugIn.Analog[4],text);
lcd_print_at(0,5,"Gier",0);
lcd_print_at(10,5,text,0);
decimal_int(DebugIn.Analog[5],text);
lcd_print_at(0,6,"ACC",0);
lcd_print_at(10,6,text,0);
 
decimal_int(DebugIn.Analog[9],text);
lcd_print_at(0,7,"Spannung",0);
lcd_print_at(10,7,text,0);
 
// decimal_int(DebugIn.Analog[zeile],text);
// lcd_print_at(0,++zeile,text,0);
 
 
// decimal(p_buffer[zeile],text);
// lcd_print_at(0,++zeile,text,0);
 
if (zeile > 5) zeile = 0;
 
timer = 10;
while(timer > 0);
// if (key == 0x01)
// read_debug(1);
// if (key == 0x02)
// read_debug(2);
}
}
while (key != 0x04);
}