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 #ifndef CANCONFIGURATOR_HPP
00030 #define CANCONFIGURATOR_HPP
00031
00032 #include <rtt/ConfigurationInterface.hpp>
00033 #include "CANRequest.hpp"
00034
00035
00036 #include <rtt/os/rtstreams.hpp>
00037
00038 #include <vector>
00039 #include <utility>
00040 #include <iostream>
00041 #include <rtt/os/rtstreams.hpp>
00042
00043 namespace RTT
00044 {namespace CAN
00045 {
00046
00047 using namespace std;
00048
00054 class CANConfigurator
00055 : public ConfigurationInterface
00056 {
00057 std::vector< std::pair<CANRequest*, bool> > requests;
00058
00059 public:
00063 CANConfigurator( CANBusInterface* _bus)
00064 : bus(_bus), status(false)
00065 {
00066 }
00067
00075 void addRequest( CANRequest* req, bool weakcheck = false){
00076 requests.push_back( std::make_pair(req, weakcheck) );
00077 }
00078
00079 virtual void configInit()
00080 {
00081 it = requests.begin();
00082 if ( it != requests.end() )
00083 it->first->sendTo(bus);
00084 }
00085
00090 virtual bool configStep()
00091 {
00092 if ( it == requests.end() )
00093 status = true;
00094 else if ( ( it->first->isReceived() && it->second )
00095 || (! it->second && it->first->isExactMatch() ) )
00096 {
00097 ++it;
00098 if ( it != requests.end() )
00099 it->first->sendTo(bus);
00100 }
00101 else if ( it->first->isExpired() )
00102 {
00103 rt_std::cout << "Request " << ( it - requests.begin() ) <<" expired!"<<rt_std::endl;
00104 return false;
00105 }
00106
00107 return true;
00108 }
00109
00110 virtual bool isFinished() const { return status; }
00111
00112 virtual void configCleanup()
00113 {
00114 for (unsigned int j=0; j<requests.size(); ++j)
00115 delete requests[j].first;
00116 requests.clear();
00117 status = false;
00118 }
00119
00120 protected:
00121
00122 CANBusInterface* bus;
00123
00124 std::vector< std::pair<CANRequest*, bool> >::iterator it;
00125
00129 bool status;
00130
00131 };
00132
00133 }}
00134
00135
00136 #endif
00137
00138