tcpmain.cpp
Go to the documentation of this file.
1 #include <rtt/os/main.h>
4 
6 #include <rtt/Activity.hpp>
7 #include <rtt/Port.hpp>
8 
9 using namespace std;
10 using namespace Orocos;
11 using namespace RTT;
12 
13 class TestTaskContext
14  : public TaskContext
15 {
16  Property<string> hello;
18  InputPort<double> drport;
19  std::vector<double> init;
20  int pos;
21 
22  public:
23  TestTaskContext(std::string name)
24  : TaskContext(name),
25  hello("Hello", "The hello thing", "World"),
26  dwport("D2Port"),
27  drport("D1Port"),
28  init(10,1.0)
29  {
30  this->properties()->addProperty( hello );
31  this->ports()->addPort( drport );
32  this->ports()->addPort( dwport );
33  pos = 10;
34  Logger::log() << Logger::Info << "TestTaskContext initialized" << Logger::endl;
35 
36  // write initial value.
37  dwport.setDataSample( init );
38  }
39 
40  virtual bool startHook () {
41  return true;
42  }
43 
44  virtual void updateHook () {
45  if( pos > 9 )
46  {
47  init[2]+=2;
48  } else if( pos > 3 ) {
49  init[2]++;
50  } else {
51  init[2]--;
52  }
53  if( pos > 5 ) {
54  init[4] += 4;
55  } else {
56  init[4] -= 4;
57  }
58  pos--;
59  if( pos == 0 ) { pos = 10; }
60  dwport.write( init );
61  }
62 
63  virtual void stopHook () {
64 
65  }
66 };
67 
68 class TestTaskContext2
69  : public TaskContext
70 {
71  Property<string> hello;
72  OutputPort<double> dwport;
74 
75  public:
76  TestTaskContext2(std::string name)
77  : TaskContext(name),
78  hello("Hello", "The hello thing", "World"),
79  dwport("D1Port"),
80  drport("D2Port")
81  {
82  this->properties()->addProperty( hello );
83  this->ports()->addPort( drport );
84  this->ports()->addPort( dwport );
85  }
86 };
87 
88 int ORO_main( int argc, char** argv)
89 {
90  // Set log level more verbose than default,
91  // such that we can see output :
92  if ( Logger::log().getLogLevel() < Logger::Info ) {
93  Logger::log().setLogLevel( Logger::Info );
94  Logger::log() << Logger::Info << argv[0] << " manually raises LogLevel to 'Info' (5). See also file 'orocos.log'."<<Logger::endl;
95  }
96 
97 
98  Activity act(10, 1.0);
99  TcpReporting rc("TCPReporting");
100  TestTaskContext gtc("MyPeer");
101  TestTaskContext2 gtc2("MyPeer2");
102  TestTaskContext2 gtc3("MySoloPeer");
103 
104  Activity act1(10, 2.0);
105 
106  rc.addPeer( &gtc );
107  rc.addPeer( &gtc2 );
108  rc.addPeer( &gtc3 );
109  gtc.connectPeers( &gtc2 );
110 
111  TaskBrowser tb( &rc );
112 
113  act1.run( gtc.engine() );
114  act.run( rc.engine() );
115  tb.loop();
116  act.stop();
117  act1.stop();
118  return 0;
119 }
120 
void setDataSample(const T &sample)
void loop()
Call this method from ORO_main() to process keyboard input and thus startup the TaskBrowser.
This component allows a text client to browse the peers of a peer RTT::TaskContext and execute comman...
Definition: TaskBrowser.hpp:86
virtual bool stop()
virtual void stopHook()
Definition: tcpmain.cpp:63
A component which writes data reports to a tcp/ip socket. It can serve different clients. It uses a ASCI-based protocol.
int ORO_main(int argc, char **argv)
Definition: tcpmain.cpp:88
virtual bool connectPeers(TaskContext *peer)
virtual bool run(RunnableInterface *r)
TestTaskContext(std::string name)
Definition: tcpmain.cpp:23
virtual void updateHook()
Definition: tcpmain.cpp:44
std::vector< double > init
Definition: tcpmain.cpp:19
WriteStatus write(const T &sample)
virtual bool startHook()
Definition: tcpmain.cpp:40
TestTaskContext2(std::string name)
Definition: tcpmain.cpp:76
const ExecutionEngine * engine() const
virtual bool addPeer(TaskContext *peer, std::string alias="")


ocl
Author(s): OCL Development Team
autogenerated on Wed Jun 26 2019 19:26:27