timer/tests/main.cpp
Go to the documentation of this file.
1 #include <boost/bind.hpp>
4 
5 #include <rtt/Activity.hpp>
6 #include <rtt/InputPort.hpp>
7 #include <iostream>
8 #include <rtt/os/main.h>
9 
10 using namespace std;
11 using namespace Orocos;
12 using namespace RTT;
13 
14 class TestTaskContext
15  : public RTT::TaskContext
16 {
18 public:
19  TestTaskContext(std::string name)
20  : RTT::TaskContext(name, PreOperational),
21  receiver("TimerIn")
22  {
23  ports()->addEventPort( receiver );
24  }
25 
27  {
28  if ( receiver.connected() )
29  log(Info) << this->getName() <<" starts listening for timeout events." << endlog();
30  return receiver.connected();
31  }
32 
33  void updateHook()
34  {
36  if (receiver.read(id) == NewData)
37  log(Info) << this->getName() <<" detects timeout for timer " << id << endlog();
38  }
39 };
40 
41 int ORO_main( int argc, char** argv)
42 {
43  // Set log level more verbose than default,
44  // such that we can see output :
45  if ( RTT::Logger::log().getLogLevel() < RTT::Logger::Info ) {
47  log(Info) << argv[0]
48  << " manually raises LogLevel to 'Info' (5). See also file 'orocos.log'."<<endlog();
49  }
50 
51 
52  TimerComponent tcomp("Timer");
53  tcomp.setActivity( new RTT::Activity(ORO_SCHED_RT, os::HighestPriority, 0.0) );
54 
55  TestTaskContext gtc("Peer");
56  gtc.setActivity( new RTT::Activity(ORO_SCHED_RT, os::HighestPriority, 0.1) );
57 
58  gtc.ports()->getPort("TimerIn")->connectTo( tcomp.ports()->getPort("timeout"));
59 
60  TaskBrowser tb( &gtc );
61 
62  gtc.configure();
63  gtc.start();
64  gtc.addPeer( &tcomp );
65  tcomp.configure();
66  tcomp.start();
67 
68  cout <<endl<< " This demo allows testing the TimerComponent." << endl;
69  cout << " Use 'Timer.arm(0, 1.5)' to arm timer '0' to end over 1.5 seconds. " <<endl;
70  cout << " 32 timers are initially available (0..31)." <<endl;
71  cout << " Other methods (type 'this') are available as well."<<endl;
72 
73  tb.loop();
74 
75  tcomp.stop();
76  gtc.stop();
77 
78  return 0;
79 }
80 
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()
NewData
FlowStatus read(base::DataSourceBase::shared_ptr source)
virtual bool configure()
bool setActivity(base::ActivityInterface *new_act)
TestTaskContext(std::string name)
printstream cout
DataFlowInterface * ports()
base::PortInterface * getPort(const std::string &name) const
A Component interface to the Real-Time types::Toolkit&#39;s timer. It must be configured with a Activity ...
int ORO_main(int argc, char **argv)
basic_ostreams & endl(basic_ostreams &s)
Info
InputPort< os::Timer::TimerId > receiver
static Logger & log()
virtual bool connectTo(PortInterface *other, ConnPolicy const &policy)=0
virtual bool connected() const
#define ORO_SCHED_RT
virtual bool start()
virtual bool addPeer(TaskContext *peer, std::string alias="")
void setLogLevel(LogLevel ll)


ocl
Author(s): OCL Development Team
autogenerated on Mon Mar 23 2020 04:47:19