YANE-Framework Tutorial 1.1.0

examples/debugmaster/src/debugmasterdemo.cpp

00001 /***************************************************************************
00002  *                                                                         *
00003  * Copyright (C) 2011 by www.nonlinearmpc.com                              *
00004  *                                                                         *
00005  * Authors:                                                                *
00006  *  Juergen Pannek <juergen.pannek@googlemail.com>                         *
00007  *  Michael Schamel <michael.schamel@uni-bayreuth.de>                      *
00008  *                                                                         *
00009  ***************************************************************************/
00010 
00011 #include <iostream>
00012 #include <cstdlib>
00013 #include <cmath>
00014 
00015 #include <yane/utils.h>
00016 
00017 #include "Debugmasterhtml/debugmasterhtml.h"
00018 
00019 using namespace std;
00020 
00021 int main ( int argc, char *argv [ ] )
00022 {
00023 
00024         // Create new clock
00025         yane::Utils::RTClock *clock = new yane::Utils::RTClock ( );
00026 
00027         // Debug to console
00028         yane::Utils::DebugMasterConsole *master =
00029                 new yane::Utils::DebugMasterConsole ( clock, 90 );
00030 
00031         // Debug to textfile
00032         // yane::Utils::DebugMasterFile *master = new yane::Utils::DebugMasterFile(clock, "test.log", 90, true);
00033 
00034         // Debug to our own class
00035         // yane::Utils::DebugMasterHTML *master = new yane::Utils::DebugMasterHTML(clock, "debug.html", 120, true);
00036 
00037         // Debug-Level 4, only messages with level <= 4 are stored
00038         master->setLevel ( 4 );
00039 
00040         // Create Debug-Client
00041         yane::Utils::DebugClient *main_debug = master->newClient ( "Main" );
00042 
00043         // Create testdata
00044         int n = 5;
00045         double* array = new double [ n ];
00046         for ( int i = 0; i < n; i++ )
00047         {
00048                 array [ i ] = exp ( i );
00049         }
00050 
00051         string str = "Testmessage";
00052 
00053         // Debug double-array, Double and string
00054         main_debug->sendDebugInfo ( "Hello World", "Testdata", array,
00055                 sizeof(double) * n, DebugMaster::T_DOUBLEARRAY, 0 );
00056         main_debug->sendDebugInfo ( "Hello World 2", "Testdata", & array [ 3 ],
00057                 sizeof(double), DebugMaster::T_DOUBLE, 3 );
00058         main_debug->sendDebugInfo ( "Hello World 3", "Testdata",
00059                 const_cast < char* > ( str.c_str ( ) ), str.length ( ),
00060                 DebugMaster::T_STRING, 3 );
00061 
00062         // The following message doesn't get debugged because debuglevel 6 > 4.
00063         main_debug->sendDebugInfo ( "Hello World 4", "Testdata", 0, 0, 0, 6 );
00064 
00065         // Change debug-level
00066         master->setLevel ( 6 );
00067 
00068         // Now the message gets debugged.
00069         main_debug->sendDebugInfo ( "Hello World 5", "Testdata", 0, 0, 0, 6 );
00070 
00071         // Create new debugclient e.g. for a thread.
00072         yane::Utils::DebugClient *thread_debug = master->newClient ( "Thread" );
00073 
00074         // Debug some stuff.
00075         thread_debug->sendDebugInfo ( "Hello World", "Testdata", array,
00076                 sizeof(double) * n, DebugMaster::T_DOUBLEARRAY, 0 );
00077         thread_debug->sendDebugInfo ( "Hello World 2", "Testdata", & array [ 3 ],
00078                 sizeof(double), DebugMaster::T_DOUBLE, 3 );
00079 
00080         delete clock;
00081         delete master;
00082         delete main_debug;
00083         delete thread_debug;
00084 
00085         return 0;
00086 }