AutoTestOut.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
10 #include <coil/Time.h>
11 #include <iostream>
12 #include <iomanip>
13 
14 #include "AutoTestOut.h"
15 // Module specification
16 // <rtc-template block="module_spec">
17 static const char* autotestout_spec[] =
18  {
19  "implementation_id", "AutoTestOut",
20  "type_name", "AutoTestOut",
21  "description", "Sample component for auto-test",
22  "version", "1.0.0",
23  "vendor", "AIST",
24  "category", "example",
25  "activity_type", "PERIODIC",
26  "kind", "DataFlowComponent",
27  "max_instance", "1",
28  "language", "C++",
29  "lang_type", "compile",
30  "exec_cxt.periodic.rate", "1.0",
31  ""
32  };
33 // </rtc-template>
34 
40  // <rtc-template block="initializer">
41  : RTC::DataFlowComponentBase(manager),
42  m_outOut("out", m_out),
43  m_seqoutOut("seqout", m_seqout),
44  m_MyServicePort("MyService")
45 
46  // </rtc-template>
47 {
48 }
49 
54 {
55 }
56 
57 
58 
60 {
61  // Registration: InPort/OutPort/Service
62  // <rtc-template block="registration">
63  // Set InPort buffers
64 
65  // Set OutPort buffer
66  addOutPort("out", m_outOut);
67  addOutPort("seqout", m_seqoutOut);
68  m_seqout.data.length(5);
69  // Set service provider to Ports
70 
71  // Set service consumers to Ports
72  m_MyServicePort.registerConsumer("myservice0", "MyService", m_myservice0);
73 
74  // Set CORBA Service Ports
76 
77  // </rtc-template>
78 
79  return RTC::RTC_OK;
80 }
81 
82 /*
83 RTC::ReturnCode_t AutoTestOut::onFinalize()
84 {
85  return RTC::RTC_OK;
86 }
87 */
88 
89 /*
90 RTC::ReturnCode_t AutoTestOut::onStartup(RTC::UniqueId ec_id)
91 {
92  return RTC::RTC_OK;
93 }
94 */
95 
96 /*
97 RTC::ReturnCode_t AutoTestOut::onShutdown(RTC::UniqueId ec_id)
98 {
99  return RTC::RTC_OK;
100 }
101 */
102 
103 
105 {
106  //ここでファイルを開く
107  fin.open("original-data");
108  if (!fin){
109  std::cout << "Can't open original-data..." << std::endl;
110  return RTC::RTC_ERROR;
111  }
112  return RTC::RTC_OK;
113 }
114 
115 
117 {
118  fin.close();
119  fin.clear(); // for win32.
120  return RTC::RTC_OK;
121 }
122 
123 
125 {
126 
127  coil::usleep(100000);
128 
129  //onexecuteでファイルから3行ずつ読み込み送る std::vector<std::string> vstr; std::string ss; if (getline(fin, ss)){ //Float //std::cout << "1 " << ss << std::endl; std::cout << std::fixed; std::cout << std::showpoint; std::cout << std::setprecision(6); std::stringstream iss; std::string str; iss.str(ss); iss >> m_out.data; std::cout << m_out.data << std::endl; //fout << m_out.data << std::endl; if (getline(fin, ss)){ //SeqFloat std::cout << ss << std::endl; //std::cout << strlen(ss) << std::endl; vstr = coil::split(ss, " "); std::stringstream isss; for (int len=0; len<5; ++len){ //std::cout << vstr[len] << std::endl; isss.str(vstr[len]); isss >>m_seqout.data[len]; std::cout << "m_seqout.data[len] = " << m_seqout.data[len] << std::endl; isss.clear(); } //fout << m_seqout.data[0] << " " << m_seqout.data[1] << " " << m_seqout.data[2] << " " << m_seqout.data[3] << " " <<m_seqout.data[4] << std::endl; if (getline(fin,ss)){ //echo用 std::cout << ss << std::endl; //fout << ss << std::endl; char* retmsg; if (!CORBA::is_nil(m_myservice0._ptr())){ retmsg = m_myservice0->echo(ss.c_str()); } m_outOut.write(); m_seqoutOut.write(); } } } return RTC::RTC_OK; } /* RTC::ReturnCode_t AutoTestOut::onAborting(RTC::UniqueId ec_id) { return RTC::RTC_OK; } */ /* RTC::ReturnCode_t AutoTestOut::onError(RTC::UniqueId ec_id) { return RTC::RTC_OK; } */ /* RTC::ReturnCode_t AutoTestOut::onReset(RTC::UniqueId ec_id) { return RTC::RTC_OK; } */ /* RTC::ReturnCode_t AutoTestOut::onStateUpdate(RTC::UniqueId ec_id) { return RTC::RTC_OK; } */ /* RTC::ReturnCode_t AutoTestOut::onRateChanged(RTC::UniqueId ec_id) { return RTC::RTC_OK; } */ extern "C" { void AutoTestOutInit(RTC::Manager* manager) { coil::Properties profile(autotestout_spec); manager->registerFactory(profile, RTC::Create<AutoTestOut>, RTC::Delete<AutoTestOut>); } };
130  std::vector<std::string> vstr;
131  std::string ss;
132 
133  if (getline(fin, ss)){ //Float
134 
135  //std::cout << "1 " << ss << std::endl;
136  std::cout << std::fixed;
137  std::cout << std::showpoint;
138  std::cout << std::setprecision(6);
139  std::stringstream iss;
140  std::string str;
141  iss.str(ss);
142  iss >> m_out.data;
143  std::cout << m_out.data << std::endl;
144  //fout << m_out.data << std::endl;
145 
146 
147  if (getline(fin, ss)){ //SeqFloat
148  std::cout << ss << std::endl;
149  //std::cout << strlen(ss) << std::endl;
150  vstr = coil::split(ss, " ");
151  std::stringstream isss;
152 
153  for (int len=0; len<5; ++len){
154  //std::cout << vstr[len] << std::endl;
155  isss.str(vstr[len]);
156  isss >>m_seqout.data[len];
157  std::cout << "m_seqout.data[len] = " << m_seqout.data[len] << std::endl;
158  isss.clear();
159  }
160  //fout << m_seqout.data[0] << " " << m_seqout.data[1] << " " << m_seqout.data[2] << " " << m_seqout.data[3] << " " <<m_seqout.data[4] << std::endl;
161 
162  if (getline(fin,ss)){ //echo用
163  std::cout << ss << std::endl;
164  //fout << ss << std::endl;
165  char* retmsg;
166 
167  if (!CORBA::is_nil(m_myservice0._ptr())){
168  retmsg = m_myservice0->echo(ss.c_str());
169  }
170 
171  m_outOut.write();
172  m_seqoutOut.write();
173 
174  }
175  }
176  }
177 
178  return RTC::RTC_OK;
179 }
180 
181 /*
182 RTC::ReturnCode_t AutoTestOut::onAborting(RTC::UniqueId ec_id)
183 {
184  return RTC::RTC_OK;
185 }
186 */
187 
188 /*
189 RTC::ReturnCode_t AutoTestOut::onError(RTC::UniqueId ec_id)
190 {
191  return RTC::RTC_OK;
192 }
193 */
194 
195 /*
196 RTC::ReturnCode_t AutoTestOut::onReset(RTC::UniqueId ec_id)
197 {
198  return RTC::RTC_OK;
199 }
200 */
201 
202 /*
203 RTC::ReturnCode_t AutoTestOut::onStateUpdate(RTC::UniqueId ec_id)
204 {
205  return RTC::RTC_OK;
206 }
207 */
208 
209 /*
210 RTC::ReturnCode_t AutoTestOut::onRateChanged(RTC::UniqueId ec_id)
211 {
212  return RTC::RTC_OK;
213 }
214 */
215 
216 
217 
218 extern "C"
219 {
220 
222  {
224  manager->registerFactory(profile,
225  RTC::Create<AutoTestOut>,
226  RTC::Delete<AutoTestOut>);
227  }
228 
229 };
230 
231 
#define RTC_ERROR(fmt)
Error log output macro.
Definition: SystemLogger.h:422
RT-Component.
TimedFloatSeq m_seqout
Definition: AutoTestOut.h:238
AutoTestOut(RTC::Manager *manager)
constructor
Definition: AutoTestOut.cpp:39
DataFlowComponentBase class.
ReturnCode_t
Definition: doil.h:53
virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id)
Callback function to activate.
std::ifstream fin
Definition: AutoTestOut.h:267
vstring split(const std::string &input, const std::string &delimiter, bool ignore_empty)
Split string by delimiter.
Definition: stringutil.cpp:341
Manager class.
Definition: Manager.h:80
void AutoTestOutInit(RTC::Manager *manager)
Sample component for auto-test.
bool addOutPort(const char *name, OutPortBase &outport)
[local interface] Register DataOutPort
Definition: RTObject.cpp:1645
virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id)
Callback function to deactivate.
RTC::CorbaConsumer< AutoTest::MyService > m_myservice0
Definition: AutoTestOut.h:262
ExecutionContextHandle_t UniqueId
virtual RTC::ReturnCode_t onInitialize()
Callback function to initialize.
Definition: AutoTestOut.cpp:59
~AutoTestOut()
destructor
Definition: AutoTestOut.cpp:53
static const char * autotestout_spec[]
Definition: AutoTestOut.cpp:17
OutPort< TimedFloat > m_outOut
Definition: AutoTestOut.h:237
ObjectTypePtr _ptr()
Get Object reference narrowed as ObjectType.
TimedFloat m_out
Definition: AutoTestOut.h:234
Class represents a set of properties.
Definition: Properties.h:101
virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id)
Callback function to execute periodically.
OutPort< TimedFloatSeq > m_seqoutOut
Definition: AutoTestOut.h:241
RTC::CorbaPort m_MyServicePort
Definition: AutoTestOut.h:249
bool addPort(PortBase &port)
[local interface] Register Port
Definition: RTObject.cpp:1558
virtual bool write(DataType &value)
Write data.
Definition: OutPort.h:203
bool registerConsumer(const char *instance_name, const char *type_name, CorbaConsumerBase &consumer)
Register the consumer.
Definition: CorbaPort.cpp:125
bool registerFactory(coil::Properties &profile, RtcNewFunc new_func, RtcDeleteFunc delete_func)
Register RT-Component Factory.
Definition: Manager.cpp:433
int usleep(useconds_t usec)
Stop a processing at specified micro second time.
Definition: ace/coil/Time.h:51


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Jun 10 2019 14:07:50