Wiselib
wiselib.stable/external_interface/tinyos/tinyos_debug.h
Go to the documentation of this file.
00001 /***************************************************************************
00002  ** This file is part of the generic algorithm library Wiselib.           **
00003  ** Copyright (C) 2008,2009 by the Wisebed (www.wisebed.eu) project.      **
00004  **                                                                       **
00005  ** The Wiselib is free software: you can redistribute it and/or modify   **
00006  ** it under the terms of the GNU Lesser General Public License as        **
00007  ** published by the Free Software Foundation, either version 3 of the    **
00008  ** License, or (at your option) any later version.                       **
00009  **                                                                       **
00010  ** The Wiselib is distributed in the hope that it will be useful,        **
00011  ** but WITHOUT ANY WARRANTY; without even the implied warranty of        **
00012  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         **
00013  ** GNU Lesser General Public License for more details.                   **
00014  **                                                                       **
00015  ** You should have received a copy of the GNU Lesser General Public      **
00016  ** License along with the Wiselib.                                       **
00017  ** If not, see <http://www.gnu.org/licenses/>.                           **
00018  ***************************************************************************/
00019 #ifndef EXTERNAL_INTERFACE_TINYOS_DEBUGOUTPUT_H
00020 #define EXTERNAL_INTERFACE_TINYOS_DEBUGOUTPUT_H
00021 
00022 
00023 #define ISENSE_WISEBED
00024 
00025 
00026 
00027 #include <stdarg.h>
00028 #include <stdio.h>
00029 #include <string.h>
00030 
00031 #include "../wiselib.testing/external_interface/tinyos/tinyos_com_uart.h"
00032 extern "C" {
00033 #include "external_interface/tinyos/tinyos_wiselib_glue.h"
00034 }
00035 
00036 namespace wiselib
00037 {
00038 
00046    template<typename OsModel_P>
00047    class TinyOsDebug
00048    {
00049    public:
00050       typedef OsModel_P OsModel;
00051 
00052       typedef TinyOsDebug<OsModel> self_type;
00053       typedef self_type* self_pointer_t;
00054       // --------------------------------------------------------------------
00055       void debug2( const char *msg, ... )
00056       {
00057 
00058 
00059 #define ISENSE_LOG_TYPE_DEBUG 0x0;
00060 #define ISENSE_MESSAGE_TYPE 104;
00061 
00062 
00063 
00064           va_list fmtargs;
00065           char buffer[1024];
00066           va_start( fmtargs, msg );
00067           int length = vsnprintf( buffer+1, sizeof(buffer) - 1, msg, fmtargs );
00068 
00069 
00070 
00071           va_end( fmtargs );
00072 
00073 
00074 
00075 
00076           buffer[0] =  ISENSE_LOG_TYPE_DEBUG;
00077 
00078           char buffer2[length+1+5];
00079 
00080           buffer2[0] =  0x10;
00081           buffer2[1] =  0x02;
00082           buffer2[2] =  ISENSE_MESSAGE_TYPE;
00083 
00084 
00085           memcpy(buffer2+3,buffer,length+1);
00086           buffer2[length+4]=0x10;
00087           buffer2[length+5]=0x03;
00088 
00089 
00090 
00091         TinyOsComUartModel<OsModel> UART;
00092 
00093           UART.enable_serial_comm();
00094 
00095         UART.write(length+1+5,(uint8_t*)buffer2);
00096 
00097 
00098 
00099 
00100       }
00101 void debug( const char *msg, ... )
00102        {
00103 
00104 
00105 
00106 
00107            va_list fmtargs;
00108            char buffer[1024];
00109            va_start( fmtargs, msg );
00110            int length = vsnprintf( buffer, sizeof(buffer) - 1, msg, fmtargs );
00111 
00112 
00113            va_end( fmtargs );
00114 #ifdef ISENSE_WISEBED
00115            debug2("%s",buffer);
00116 #else
00117         TinyOsComUartModel<OsModel> UART;
00118            UART.enable_serial_comm();
00119            UART.write(length+1,(uint8_t*)buffer);
00120 #endif
00121 
00122 
00123 
00124        }
00125    };
00126 
00127 }
00128 
00129 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines