SeqOut.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
10 #include "SeqOut.h"
11 #include <stdlib.h>
12 
13 // Connector Listener Dump Flag
15 
16 // Module specification
17 // <rtc-template block="module_spec">
18 static const char* seqout_spec[] =
19  {
20  "implementation_id", "SeqOut",
21  "type_name", "SequenceOutComponent",
22  "description", "Sequence OutPort component",
23  "version", "1.0",
24  "vendor", "Noriaki Ando, AIST",
25  "category", "example",
26  "activity_type", "DataFlowComponent",
27  "max_instance", "10",
28  "language", "C++",
29  "lang_type", "compile",
30  // Configuration variables
31  "conf.default.data_type", "serial",
32  "conf.mode0.data_type", "random",
33  ""
34  };
35 // </rtc-template>
36 
38  : RTC::DataFlowComponentBase(manager),
39  // <rtc-template block="initializer">
40  m_OctetOut("Octet", m_Octet),
41  m_ShortOut("Short", m_Short),
42  m_LongOut("Long", m_Long),
43  m_FloatOut("Float", m_Float),
44  m_DoubleOut("Double", m_Double),
45  m_OctetSeqOut("OctetSeq", m_OctetSeq),
46  m_ShortSeqOut("ShortSeq", m_ShortSeq),
47  m_LongSeqOut("LongSeq", m_LongSeq),
48  m_FloatSeqOut("FloatSeq", m_FloatSeq),
49  m_DoubleSeqOut("DoubleSeq", m_DoubleSeq)
50 
51  // </rtc-template>
52 {
53 }
54 
56 {
57 }
58 
59 
60 
62 {
63  // Registration: InPort/OutPort/Service
64  // <rtc-template block="registration">
65  // Set InPort buffers
66 
67  // Set OutPort buffer
68  addOutPort("Octet", m_OctetOut);
69  addOutPort("Short", m_ShortOut);
70  addOutPort("Long", m_LongOut);
71  addOutPort("Float", m_FloatOut);
72  addOutPort("Double", m_DoubleOut);
73  addOutPort("OctetSeq", m_OctetSeqOut);
74  addOutPort("ShortSeq", m_ShortSeqOut);
75  addOutPort("LongSeq", m_LongSeqOut);
76  addOutPort("FloatSeq", m_FloatSeqOut);
77  addOutPort("DoubleSeq", m_DoubleSeqOut);
78 
79  // check m_LongOut port only
81  new DataListener("ON_BUFFER_WRITE"));
83  new DataListener("ON_BUFFER_FULL"));
85  new DataListener("ON_BUFFER_WRITE_TIMEOUT"));
87  new DataListener("ON_BUFFER_OVERWRITE"));
89  new DataListener("ON_BUFFER_READ"));
91  new DataListener("ON_SEND"));
93  new DataListener("ON_RECEIVED"));
95  new DataListener("ON_RECEIVER_FULL"));
97  new DataListener("ON_RECEIVER_TIMEOUT"));
98 
100  new ConnListener("ON_BUFFER_EMPTY"));
102  new ConnListener("ON_BUFFER_READ_TIMEOUT"));
104  new ConnListener("ON_SENDER_EMPTY"));
106  new ConnListener("ON_SENDER_TIMEOUT"));
108  new ConnListener("ON_SENDER_ERROR"));
110  new ConnListener("ON_CONNECT"));
112  new ConnListener("ON_DISCONNECT"));
113 
114  // Set service provider to Ports
115 
116  // Set service consumers to Ports
117 
118  // Set CORBA Service Ports
119 
120  // </rtc-template>
121 
122  m_DoubleSeq.data.length(10);
123  m_FloatSeq.data.length(10);
124  m_LongSeq.data.length(10);
125  m_ShortSeq.data.length(10);
126  m_OctetSeq.data.length(10);
127 
128  // <rtc-template block="bind_config">
129  // Bind variables and configuration variable
130  bindParameter("data_type", m_data_type, "serial");
131 
132  // </rtc-template>
133 
134  return RTC::RTC_OK;
135 }
136 
137 
138 /*
139 RTC::ReturnCode_t SeqOut::onFinalize()
140 {
141  return RTC::RTC_OK;
142 }
143 */
144 
145 /*
146 RTC::ReturnCode_t SeqOut::onStartup(RTC::UniqueId ec_id)
147 {
148  return RTC::RTC_OK;
149 }
150 */
151 
152 /*
153 RTC::ReturnCode_t SeqOut::onShutdown(RTC::UniqueId ec_id)
154 {
155  return RTC::RTC_OK;
156 }
157 */
158 
159 /*
160 RTC::ReturnCode_t SeqOut::onActivated(RTC::UniqueId ec_id)
161 {
162  return RTC::RTC_OK;
163 }
164 */
165 
166 /*
167 RTC::ReturnCode_t SeqOut::onDeactivated(RTC::UniqueId ec_id)
168 {
169  return RTC::RTC_OK;
170 }
171 */
172 
173 
175 {
176  static unsigned char cnt0, cntseq0;
177  static short cnt1, cntseq1;
178  static long cnt2, cntseq2;
179  static float cnt3, cntseq3;
180  static double cnt4, cntseq4;
181 
182  // Configuration check
183  if (m_data_type == "serial")
184  {
185  ++cnt0;
186  if( cnt0 > 254 )
187  {
188  cnt0 = 1;
189  }
190  m_Octet.data = cnt0;
191 
192  ++cnt1;
193  if( cnt1 > 30000 )
194  {
195  cnt1 = 1;
196  }
197  m_Short.data = cnt1;
198 
199  ++cnt2;
200  if( cnt2 > 30000 )
201  {
202  cnt2 = 1;
203  }
204  m_Long.data = cnt2;
205 
206  ++cnt3;
207  if( cnt3 > 30000 )
208  {
209  cnt3 = 1.0;
210  }
211  m_Float.data = cnt3 + 0.12;
212 
213  ++cnt4;
214  if( cnt4 > 30000 )
215  {
216  cnt4 = 1.0;
217  }
218  m_Double.data = cnt4 + 0.345;
219  }
220  else //default
221  {
222  m_Octet.data = rand();
223  m_Short.data = rand();
224  m_Long.data = rand();
225  m_Float.data = rand();
226  m_Double.data = rand();
227  }
228 
229  std::cout << "-: ";
230  std::cout << m_Double.data << " ";
231  std::cout << m_Float.data << " ";
232  std::cout << m_Long.data << " ";
233  std::cout << m_Short.data << " ";
234  std::cout << int(m_Octet.data) << "[";
235  if (int(m_Octet.data) < 0x20 || int(m_Octet.data) > 0x7e)
236  {
237  std::cout << " " << "]";
238  }
239  else
240  {
241  std::cout << m_Octet.data << "]";
242  }
243  std::cout << " " << std::endl << std::endl;
244 
245  for (CORBA::ULong i = 0; i < 10; ++i)
246  {
247  // Configuration check
248  if (m_data_type == "serial")
249  {
250  ++cntseq0;
251  if( cntseq0 > 254 )
252  {
253  cntseq0 = 1;
254  }
255  m_OctetSeq.data[i] = cntseq0;
256 
257  ++cntseq1;
258  if( cntseq1 > 30000 )
259  {
260  cntseq1 = 1;
261  }
262  m_ShortSeq.data[i] = cntseq1;
263 
264  ++cntseq2;
265  if( cntseq2 > 30000 )
266  {
267  cntseq2 = 1;
268  }
269  m_LongSeq.data[i] = cntseq2;
270 
271  ++cntseq3;
272  if( cntseq3 > 30000 )
273  {
274  cntseq3 = 1.0;
275  }
276  m_FloatSeq.data[i] = cntseq3 + 0.12;
277 
278  ++cntseq4;
279  if( cntseq4 > 30000 )
280  {
281  cntseq4 = 1.0;
282  }
283  m_DoubleSeq.data[i] = cntseq4 + 0.345;
284  }
285  else //default
286  {
287  m_DoubleSeq.data[i] = static_cast<double>(rand());
288  m_FloatSeq.data[i] = static_cast<float>(rand());
289  m_LongSeq.data[i] = static_cast<long>(rand());
290  m_ShortSeq.data[i] = static_cast<short>(rand());
291  m_OctetSeq.data[i] = static_cast<unsigned char>(rand());
292  }
293 
294  std::cout << i << ": ";
295  std::cout << m_DoubleSeq.data[i] << " ";
296  std::cout << m_FloatSeq.data[i] << " ";
297  std::cout << m_LongSeq.data[i] << " ";
298  std::cout << m_ShortSeq.data[i] << " ";
299  std::cout << int(m_OctetSeq.data[i]) << "[";
300  if (int(m_OctetSeq.data[i]) < 0x20 || int(m_OctetSeq.data[i]) > 0x7e)
301  {
302  std::cout << " " << "]";
303  }
304  else
305  {
306  std::cout << m_OctetSeq.data[i] << "]";
307  }
308  std::cout << " " << std::endl;
309  }
310  // Configuration check
311  if (m_data_type == "serial")
312  {
313  std::cout << std::endl << "write data type : serial" << std::endl;
314  }
315  else //default
316  {
317  std::cout << std::endl << "write data type : random" << std::endl;
318  }
319 
320  // Connector Listener Dump check
322  {
323  std::cout << "\r\r\r\r\r\r\r\r\r\r\r\r\r\r";
324  }
325 
326  m_OctetOut.write();
327  m_ShortOut.write();
328  m_LongOut.write();
329  m_FloatOut.write();
330  m_DoubleOut.write();
331 
337 
338  // Connector Listener Dump check
340  {
341  coil::usleep(1000000);
342  }
343  else
344  {
345  coil::usleep(200000);
346  }
347 
348  return RTC::RTC_OK;
349 }
350 
351 
352 /*
353 RTC::ReturnCode_t SeqOut::onAborting(RTC::UniqueId ec_id)
354 {
355  return RTC::RTC_OK;
356 }
357 */
358 
359 /*
360 RTC::ReturnCode_t SeqOut::onError(RTC::UniqueId ec_id)
361 {
362  return RTC::RTC_OK;
363 }
364 */
365 
366 /*
367 RTC::ReturnCode_t SeqOut::onReset(RTC::UniqueId ec_id)
368 {
369  return RTC::RTC_OK;
370 }
371 */
372 
373 /*
374 RTC::ReturnCode_t SeqOut::onStateUpdate(RTC::UniqueId ec_id)
375 {
376  return RTC::RTC_OK;
377 }
378 */
379 
380 /*
381 RTC::ReturnCode_t SeqOut::onRateChanged(RTC::UniqueId ec_id)
382 {
383  return RTC::RTC_OK;
384 }
385 */
386 
387 
388 
389 extern "C"
390 {
391 
393  {
394  coil::Properties profile(seqout_spec);
395  manager->registerFactory(profile,
396  RTC::Create<SeqOut>,
397  RTC::Delete<SeqOut>);
398  }
399 
400 };
OutPort< TimedFloat > m_FloatOut
Definition: SeqOut.h:174
OutPort< TimedDouble > m_DoubleOut
Definition: SeqOut.h:176
void addConnectorDataListener(ConnectorDataListenerType listener_type, ConnectorDataListener *listener, bool autoclean=true)
Adding BufferDataListener type listener.
RT-Component.
void addConnectorListener(ConnectorListenerType callback_type, ConnectorListener *listener, bool autoclean=true)
Adding ConnectorListener type listener.
OutPort< TimedFloatSeq > m_FloatSeqOut
Definition: SeqOut.h:184
TimedFloat m_Float
Definition: SeqOut.h:173
DataFlowComponentBase class.
ReturnCode_t
Definition: doil.h:53
TimedShortSeq m_ShortSeq
Definition: SeqOut.h:179
TimedOctetSeq m_OctetSeq
Definition: SeqOut.h:177
TimedLongSeq m_LongSeq
Definition: SeqOut.h:181
Manager class.
Definition: Manager.h:80
static const char * seqout_spec[]
Definition: SeqOut.cpp:18
OutPort< TimedLong > m_LongOut
Definition: SeqOut.h:172
bool addOutPort(const char *name, OutPortBase &outport)
[local interface] Register DataOutPort
Definition: RTObject.cpp:1645
TimedFloatSeq m_FloatSeq
Definition: SeqOut.h:183
~SeqOut()
Definition: SeqOut.cpp:55
virtual RTC::ReturnCode_t onInitialize()
Callback function to initialize.
Definition: SeqOut.cpp:61
TimedShort m_Short
Definition: SeqOut.h:169
OutPort< TimedShortSeq > m_ShortSeqOut
Definition: SeqOut.h:180
ExecutionContextHandle_t UniqueId
OutPort< TimedLongSeq > m_LongSeqOut
Definition: SeqOut.h:182
void SeqOutInit(RTC::Manager *manager)
Definition: SeqOut.cpp:392
bool bindParameter(const char *param_name, VarType &var, const char *def_val, bool(*trans)(VarType &, const char *)=coil::stringTo)
Setup for configuration parameters.
Definition: RTObject.h:2251
std::string m_data_type
Definition: SeqOut.h:207
Sequence OutPort component.
OutPort< TimedShort > m_ShortOut
Definition: SeqOut.h:170
bool g_Listener_dump_enabled
Definition: SeqOut.cpp:14
TimedDoubleSeq m_DoubleSeq
Definition: SeqOut.h:185
SeqOut(RTC::Manager *manager)
Definition: SeqOut.cpp:37
Class represents a set of properties.
Definition: Properties.h:101
OutPort< TimedOctet > m_OctetOut
Definition: SeqOut.h:168
TimedLong m_Long
Definition: SeqOut.h:171
TimedOctet m_Octet
Definition: SeqOut.h:167
virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id)
Callback function to execute periodically.
Definition: SeqOut.cpp:174
virtual bool write(DataType &value)
Write data.
Definition: OutPort.h:203
OutPort< TimedOctetSeq > m_OctetSeqOut
Definition: SeqOut.h:178
TimedDouble m_Double
Definition: SeqOut.h:175
OutPort< TimedDoubleSeq > m_DoubleSeqOut
Definition: SeqOut.h:186
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 Thu Jun 6 2019 19:26:00