AtmelSerialDriver.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #ifndef __ATMEL_SERIAL_DRIVER_h__
00041 #define __ATMEL_SERIAL_DRIVER_h__
00042
00043 #include "avr-halib/share/cframe.h"
00044 #include "avr-halib/share/delegate.h"
00045
00046 #include "case/Delegate.h"
00047 #include "devices/nic/serial/SerialFrameDelimiter.h"
00048 #include "debug.h"
00049
00050 using namespace std;
00051
00052 namespace device {
00053 namespace nic {
00054 namespace serial {
00067 template <
00068 class DEV,
00069 uint8_t PL = 255,
00070 uint16_t BR = 19200,
00071 class SFD = struct SerialFrameDelimiter
00072 >
00073 class AtmelSerialDriver : public CFrame< DEV, uint8_t, SFD, PL> {
00074 public:
00076 typedef CFrame< DEV, uint8_t, SFD, PL> baseType;
00078 typedef AtmelSerialDriver<DEV, PL, BR, SFD> type;
00080 typedef typename baseType::mob_t mob_t;
00082 struct cfgInfo {
00083 enum {
00084 payload = PL
00085 };
00086 };
00087 protected:
00088 void handleReceive() {
00089 if (this->onReceive) this->onReceive();
00090 }
00091 void handleReady() {
00092 if (this->onReady) this->onReady();
00093 }
00094 public:
00095 AtmelSerialDriver() {}
00096 ~AtmelSerialDriver() {}
00097
00101 void init() {
00102 TRACE_FUNCTION;
00103 baseType::onReady.template bind< type, &type::handleReady>(this);
00104 baseType::onReceive.template bind<type, &type::handleReceive>(this);
00105 baseType::enableonReceive();
00106 }
00107
00112 void recv(mob_t& message) {
00113 TRACE_FUNCTION;
00114 baseType::recv(message);
00115 }
00116
00121 void send(const mob_t& message) {
00122 TRACE_FUNCTION;
00123 baseType::send(message);
00124 }
00125
00127 famouso::util::Delegate<> onReceive;
00128
00134 famouso::util::Delegate<> onReady;
00135 };
00136 }
00137 }
00138 }
00139
00140 #endif //__ATMEL_SERIAL_DRIVER_h__