Wiselib
wiselib.testing/external_interface/shawn/shawn_dummy_com_uart.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 CONNECTOR_ISENSE_SERIAL_COM_UART0_H
00020 #define CONNECTOR_ISENSE_SERIAL_COM_UART0_H
00021 
00022 #include "external_interface/shawn/shawn_types.h"
00023 #include "util/delegates/delegate.hpp"
00024 #include "external_interface/shawn/shawn_timer.h"
00025 #include "external_interface/shawn/shawn_os.h"
00026 
00027 
00028 namespace wiselib
00029 {
00030 
00036    template<typename OsModel_P,
00037             typename Debug_P = typename OsModel_P::Debug>
00038    class ShawnDummyComUartModel
00039    {
00040    public:
00041       typedef OsModel_P OsModel;
00042 
00043       typedef ShawnDummyComUartModel<OsModel,Debug_P> self_type;
00044       typedef self_type* self_pointer_t;
00045 
00046       typedef delegate2<void, uint8_t, uint8_t*> comuart_delegate_t;
00047 
00048       typedef uint8_t block_data_t;
00049       typedef uint8_t size_t;
00050       // --------------------------------------------------------------------
00051       enum ErrorCodes
00052       {
00053          SUCCESS = OsModel::SUCCESS,
00054          ERR_UNSPEC = OsModel::ERR_UNSPEC
00055       };
00056       // --------------------------------------------------------------------
00057       ShawnDummyComUartModel( ShawnOs& os )
00058          : enabled_(false),
00059             debug_(0)
00060       {}
00061       // --------------------------------------------------------------------
00062       int enable_serial_comm()
00063       {
00064           enabled_ = true;
00065           return SUCCESS;
00066       }
00067       // --------------------------------------------------------------------
00068       int disable_serial_comm()
00069       {
00070           enabled_ = false;
00071           return SUCCESS;
00072       }
00073       // --------------------------------------------------------------------
00074       int write( size_t len, block_data_t *buf )
00075       {
00076           //debug_->debug("writing %i bytes\n", msg->payload_length());
00077           if(enabled_)
00078           {
00079               debug_->debug("%s\n",buf);
00080               return SUCCESS;
00081           }
00082           return ERR_UNSPEC;
00083       }
00084       // --------------------------------------------------------------------
00085       template<class T, void (T::*TMethod)(size_t, block_data_t*)>
00086       int reg_read_callback( T *obj_pnt )
00087       {
00088           comuart_callback_ =
00089             comuart_delegate_t::from_method<T, TMethod>( obj_pnt );
00090 
00091          return -1;
00092       }
00093       // --------------------------------------------------------------------
00094       int unreg_read_callback( int idx )
00095       {
00096          comuart_callback_ = comuart_delegate_t();
00097          return ERR_UNSPEC;
00098       }
00099       // --------------------------------------------------------------------
00100       int init(Debug_P& debug)
00101       {
00102           debug_ = &debug;
00103           return SUCCESS;
00104       }
00105       // --------------------------------------------------------------------
00106       void receive(size_t len, block_data_t *buf)
00107       {
00108           comuart_callback_( len, buf );
00109       }
00110 
00111    private:
00112       // --------------------------------------------------------------------
00113       bool enabled_;
00114       Debug_P* debug_;
00115       comuart_delegate_t comuart_callback_;
00116    };
00117 }
00118 
00119 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines