tcpmain.cpp
Go to the documentation of this file.
00001 #include <rtt/os/main.h>
00002 #include <reporting/TcpReporting.hpp>
00003 #include <taskbrowser/TaskBrowser.hpp>
00004 
00005 #include <rtt/extras/SlaveActivity.hpp>
00006 #include <rtt/Activity.hpp>
00007 #include <rtt/Port.hpp>
00008 
00009 using namespace std;
00010 using namespace Orocos;
00011 using namespace RTT;
00012 
00013 class TestTaskContext
00014     : public TaskContext
00015 {
00016     Property<string> hello;
00017     OutputPort<std::vector<double> > dwport;
00018     InputPort<double> drport;
00019     std::vector<double> init;
00020     int pos;
00021 
00022     public:
00023         TestTaskContext(std::string name)
00024     : TaskContext(name),
00025         hello("Hello", "The hello thing", "World"),
00026         dwport("D2Port"),
00027         drport("D1Port"),
00028         init(10,1.0)
00029         {
00030             this->properties()->addProperty( hello );
00031             this->ports()->addPort( drport );
00032             this->ports()->addPort( dwport );
00033             pos = 10;
00034             Logger::log() << Logger::Info << "TestTaskContext initialized" << Logger::endl;
00035 
00036         // write initial value.
00037             dwport.setDataSample( init );
00038         }
00039 
00040         virtual bool startHook () {
00041             return true;
00042         }
00043 
00044         virtual void updateHook () {
00045             if( pos > 9 )
00046             {
00047                 init[2]+=2;
00048             } else if( pos > 3 ) {
00049                 init[2]++;
00050             } else {
00051                 init[2]--;
00052             }
00053             if( pos > 5 ) {
00054               init[4] += 4;
00055             } else {
00056               init[4] -= 4;
00057             }
00058             pos--;
00059             if( pos == 0 ) { pos = 10; }
00060             dwport.write( init );
00061         }
00062 
00063         virtual void stopHook () {
00064 
00065         }
00066 };
00067 
00068 class TestTaskContext2
00069     : public TaskContext
00070 {
00071     Property<string> hello;
00072     OutputPort<double> dwport;
00073     InputPort<std::vector<double> > drport;
00074 
00075     public:
00076         TestTaskContext2(std::string name)
00077     : TaskContext(name),
00078         hello("Hello", "The hello thing", "World"),
00079         dwport("D1Port"),
00080         drport("D2Port")
00081         {
00082             this->properties()->addProperty( hello );
00083             this->ports()->addPort( drport );
00084             this->ports()->addPort( dwport );
00085         }
00086 };
00087 
00088 int ORO_main( int argc, char** argv)
00089 {
00090     // Set log level more verbose than default,
00091     // such that we can see output :
00092     if ( Logger::log().getLogLevel() < Logger::Info ) {
00093         Logger::log().setLogLevel( Logger::Info );
00094         Logger::log() << Logger::Info << argv[0] << " manually raises LogLevel to 'Info' (5). See also file 'orocos.log'."<<Logger::endl;
00095     }
00096 
00097 
00098     Activity act(10, 1.0);
00099     TcpReporting rc("TCPReporting");
00100     TestTaskContext gtc("MyPeer");
00101     TestTaskContext2 gtc2("MyPeer2");
00102     TestTaskContext2 gtc3("MySoloPeer");
00103 
00104     Activity act1(10, 2.0);
00105 
00106     rc.addPeer( &gtc );
00107     rc.addPeer( &gtc2 );
00108     rc.addPeer( &gtc3 );
00109     gtc.connectPeers( &gtc2 );
00110 
00111     TaskBrowser tb( &rc );
00112 
00113     act1.run( gtc.engine() );
00114     act.run( rc.engine() );
00115     tb.loop();
00116     act.stop();
00117     act1.stop();
00118     return 0;
00119 }
00120 


ocl
Author(s): OCL Development Team
autogenerated on Sun Nov 27 2016 03:45:31