SeqOut.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00010 #include "SeqOut.h"
00011 #include <stdlib.h>
00012 
00013 // Connector Listener Dump Flag
00014 bool g_Listener_dump_enabled = false;
00015 
00016 // Module specification
00017 // <rtc-template block="module_spec">
00018 static const char* seqout_spec[] =
00019   {
00020     "implementation_id", "SeqOut",
00021     "type_name",         "SequenceOutComponent",
00022     "description",       "Sequence OutPort component",
00023     "version",           "1.0",
00024     "vendor",            "Noriaki Ando, AIST",
00025     "category",          "example",
00026     "activity_type",     "DataFlowComponent",
00027     "max_instance",      "10",
00028     "language",          "C++",
00029     "lang_type",         "compile",
00030     // Configuration variables
00031     "conf.default.data_type", "serial",
00032     "conf.mode0.data_type", "random",
00033     ""
00034   };
00035 // </rtc-template>
00036 
00037 SeqOut::SeqOut(RTC::Manager* manager)
00038   : RTC::DataFlowComponentBase(manager),
00039     // <rtc-template block="initializer">
00040     m_OctetOut("Octet", m_Octet),
00041     m_ShortOut("Short", m_Short),
00042     m_LongOut("Long", m_Long),
00043     m_FloatOut("Float", m_Float),
00044     m_DoubleOut("Double", m_Double),
00045     m_OctetSeqOut("OctetSeq", m_OctetSeq),
00046     m_ShortSeqOut("ShortSeq", m_ShortSeq),
00047     m_LongSeqOut("LongSeq", m_LongSeq),
00048     m_FloatSeqOut("FloatSeq", m_FloatSeq),
00049     m_DoubleSeqOut("DoubleSeq", m_DoubleSeq)
00050     
00051     // </rtc-template>
00052 {
00053 }
00054 
00055 SeqOut::~SeqOut()
00056 {
00057 }
00058 
00059 
00060 
00061 RTC::ReturnCode_t SeqOut::onInitialize()
00062 {
00063   // Registration: InPort/OutPort/Service
00064   // <rtc-template block="registration">
00065   // Set InPort buffers
00066   
00067   // Set OutPort buffer
00068   addOutPort("Octet", m_OctetOut);
00069   addOutPort("Short", m_ShortOut);
00070   addOutPort("Long", m_LongOut);
00071   addOutPort("Float", m_FloatOut);
00072   addOutPort("Double", m_DoubleOut);
00073   addOutPort("OctetSeq", m_OctetSeqOut);
00074   addOutPort("ShortSeq", m_ShortSeqOut);
00075   addOutPort("LongSeq", m_LongSeqOut);
00076   addOutPort("FloatSeq", m_FloatSeqOut);
00077   addOutPort("DoubleSeq", m_DoubleSeqOut);
00078   
00079   // check m_LongOut port only
00080   m_LongOut.addConnectorDataListener(ON_BUFFER_WRITE,
00081                                     new DataListener("ON_BUFFER_WRITE"));
00082   m_LongOut.addConnectorDataListener(ON_BUFFER_FULL, 
00083                                     new DataListener("ON_BUFFER_FULL"));
00084   m_LongOut.addConnectorDataListener(ON_BUFFER_WRITE_TIMEOUT, 
00085                                     new DataListener("ON_BUFFER_WRITE_TIMEOUT"));
00086   m_LongOut.addConnectorDataListener(ON_BUFFER_OVERWRITE, 
00087                                     new DataListener("ON_BUFFER_OVERWRITE"));
00088   m_LongOut.addConnectorDataListener(ON_BUFFER_READ, 
00089                                     new DataListener("ON_BUFFER_READ"));
00090   m_LongOut.addConnectorDataListener(ON_SEND, 
00091                                     new DataListener("ON_SEND"));
00092   m_LongOut.addConnectorDataListener(ON_RECEIVED,
00093                                     new DataListener("ON_RECEIVED"));
00094   m_LongOut.addConnectorDataListener(ON_RECEIVER_FULL, 
00095                                     new DataListener("ON_RECEIVER_FULL"));
00096   m_LongOut.addConnectorDataListener(ON_RECEIVER_TIMEOUT, 
00097                                     new DataListener("ON_RECEIVER_TIMEOUT"));
00098 
00099   m_LongOut.addConnectorListener(ON_BUFFER_EMPTY,
00100                                     new ConnListener("ON_BUFFER_EMPTY"));
00101   m_LongOut.addConnectorListener(ON_BUFFER_READ_TIMEOUT,
00102                                     new ConnListener("ON_BUFFER_READ_TIMEOUT"));
00103   m_LongOut.addConnectorListener(ON_SENDER_EMPTY,
00104                                     new ConnListener("ON_SENDER_EMPTY"));
00105   m_LongOut.addConnectorListener(ON_SENDER_TIMEOUT,
00106                                     new ConnListener("ON_SENDER_TIMEOUT"));
00107   m_LongOut.addConnectorListener(ON_SENDER_ERROR,
00108                                     new ConnListener("ON_SENDER_ERROR"));
00109   m_LongOut.addConnectorListener(ON_CONNECT,
00110                                     new ConnListener("ON_CONNECT"));
00111   m_LongOut.addConnectorListener(ON_DISCONNECT,
00112                                     new ConnListener("ON_DISCONNECT"));
00113 
00114   // Set service provider to Ports
00115   
00116   // Set service consumers to Ports
00117   
00118   // Set CORBA Service Ports
00119   
00120   // </rtc-template>
00121 
00122   m_DoubleSeq.data.length(10);
00123   m_FloatSeq.data.length(10);
00124   m_LongSeq.data.length(10);
00125   m_ShortSeq.data.length(10);
00126   m_OctetSeq.data.length(10);
00127 
00128   // <rtc-template block="bind_config">
00129   // Bind variables and configuration variable
00130   bindParameter("data_type", m_data_type, "serial");
00131   
00132   // </rtc-template>
00133 
00134   return RTC::RTC_OK;
00135 }
00136 
00137 
00138 /*
00139 RTC::ReturnCode_t SeqOut::onFinalize()
00140 {
00141   return RTC::RTC_OK;
00142 }
00143 */
00144 
00145 /*
00146 RTC::ReturnCode_t SeqOut::onStartup(RTC::UniqueId ec_id)
00147 {
00148   return RTC::RTC_OK;
00149 }
00150 */
00151 
00152 /*
00153 RTC::ReturnCode_t SeqOut::onShutdown(RTC::UniqueId ec_id)
00154 {
00155   return RTC::RTC_OK;
00156 }
00157 */
00158 
00159 /*
00160 RTC::ReturnCode_t SeqOut::onActivated(RTC::UniqueId ec_id)
00161 {
00162   return RTC::RTC_OK;
00163 }
00164 */
00165 
00166 /*
00167 RTC::ReturnCode_t SeqOut::onDeactivated(RTC::UniqueId ec_id)
00168 {
00169   return RTC::RTC_OK;
00170 }
00171 */
00172 
00173 
00174 RTC::ReturnCode_t SeqOut::onExecute(RTC::UniqueId ec_id)
00175 {
00176   static unsigned char cnt0, cntseq0;
00177   static short  cnt1, cntseq1;
00178   static long   cnt2, cntseq2;
00179   static float  cnt3, cntseq3;
00180   static double cnt4, cntseq4;
00181 
00182   // Configuration check
00183   if (m_data_type == "serial")
00184     {
00185       ++cnt0;
00186       if( cnt0 > 254 )
00187         {
00188           cnt0 = 1;
00189         }
00190       m_Octet.data = cnt0;
00191 
00192       ++cnt1;
00193       if( cnt1 > 30000 )
00194         {
00195           cnt1 = 1;
00196         }
00197       m_Short.data = cnt1;
00198 
00199       ++cnt2;
00200       if( cnt2 > 30000 )
00201         {
00202           cnt2 = 1;
00203         }
00204       m_Long.data = cnt2;
00205 
00206       ++cnt3;
00207       if( cnt3 > 30000 )
00208         {
00209           cnt3 = 1.0;
00210         }
00211       m_Float.data = cnt3 + 0.12;
00212 
00213       ++cnt4;
00214       if( cnt4 > 30000 )
00215         {
00216           cnt4 = 1.0;
00217         }
00218       m_Double.data = cnt4 + 0.345;
00219     }
00220   else                          //default
00221     {
00222       m_Octet.data = rand();
00223       m_Short.data = rand();
00224       m_Long.data = rand();
00225       m_Float.data = rand();
00226       m_Double.data = rand();
00227     }
00228 
00229   std::cout << "-: ";
00230   std::cout << m_Double.data << " ";
00231   std::cout << m_Float.data << " ";
00232   std::cout << m_Long.data << " ";
00233   std::cout << m_Short.data << " ";
00234   std::cout << int(m_Octet.data) << "[";
00235   if (int(m_Octet.data) < 0x20 || int(m_Octet.data) > 0x7e)
00236     {
00237       std::cout << " " << "]";
00238     }
00239   else
00240     {
00241       std::cout << m_Octet.data << "]";
00242     }
00243   std::cout << "                                " << std::endl << std::endl;
00244 
00245   for (CORBA::ULong i = 0; i < 10; ++i)
00246     {
00247       // Configuration check
00248       if (m_data_type == "serial")
00249         {
00250           ++cntseq0;
00251           if( cntseq0 > 254 )
00252             {
00253               cntseq0 = 1;
00254             }
00255           m_OctetSeq.data[i] = cntseq0;
00256 
00257           ++cntseq1;
00258           if( cntseq1 > 30000 )
00259             {
00260               cntseq1 = 1;
00261             }
00262           m_ShortSeq.data[i] = cntseq1;
00263 
00264           ++cntseq2;
00265           if( cntseq2 > 30000 )
00266             {
00267               cntseq2 = 1;
00268             }
00269           m_LongSeq.data[i] = cntseq2;
00270 
00271           ++cntseq3;
00272           if( cntseq3 > 30000 )
00273             {
00274               cntseq3 = 1.0;
00275             }
00276           m_FloatSeq.data[i] = cntseq3 + 0.12;
00277 
00278           ++cntseq4;
00279           if( cntseq4 > 30000 )
00280             {
00281               cntseq4 = 1.0;
00282             }
00283           m_DoubleSeq.data[i] = cntseq4 + 0.345;
00284         }
00285       else                              //default
00286         {
00287           m_DoubleSeq.data[i] = static_cast<double>(rand());
00288           m_FloatSeq.data[i] = static_cast<float>(rand());
00289           m_LongSeq.data[i] = static_cast<long>(rand());
00290           m_ShortSeq.data[i] = static_cast<short>(rand());
00291           m_OctetSeq.data[i] = static_cast<unsigned char>(rand());
00292         }
00293 
00294       std::cout << i << ": ";
00295       std::cout << m_DoubleSeq.data[i] << " ";
00296       std::cout << m_FloatSeq.data[i] << " ";
00297       std::cout << m_LongSeq.data[i] << " ";
00298       std::cout << m_ShortSeq.data[i] << " ";
00299       std::cout << int(m_OctetSeq.data[i]) << "[";
00300       if (int(m_OctetSeq.data[i]) < 0x20 || int(m_OctetSeq.data[i]) > 0x7e)
00301         {
00302           std::cout << " " << "]";
00303         }
00304       else
00305         {
00306           std::cout << m_OctetSeq.data[i] << "]";
00307         }
00308       std::cout << "                             " << std::endl;
00309     }
00310   // Configuration check
00311   if (m_data_type == "serial")
00312     {
00313       std::cout << std::endl << "write data type : serial" << std::endl;
00314     }
00315   else                          //default
00316     {
00317       std::cout << std::endl << "write data type : random" << std::endl;
00318     }
00319 
00320   // Connector Listener Dump check
00321   if(!g_Listener_dump_enabled)
00322     {
00323       std::cout << "\r\r\r\r\r\r\r\r\r\r\r\r\r\r";
00324     }
00325 
00326   m_OctetOut.write();
00327   m_ShortOut.write();
00328   m_LongOut.write();
00329   m_FloatOut.write();
00330   m_DoubleOut.write();
00331 
00332   m_OctetSeqOut.write();
00333   m_ShortSeqOut.write();
00334   m_LongSeqOut.write();
00335   m_FloatSeqOut.write();
00336   m_DoubleSeqOut.write();
00337 
00338   // Connector Listener Dump check
00339   if(g_Listener_dump_enabled)
00340     {
00341       coil::usleep(1000000);
00342     }
00343   else
00344     {
00345       coil::usleep(200000);
00346     }
00347 
00348   return RTC::RTC_OK;
00349 }
00350 
00351 
00352 /*
00353 RTC::ReturnCode_t SeqOut::onAborting(RTC::UniqueId ec_id)
00354 {
00355   return RTC::RTC_OK;
00356 }
00357 */
00358 
00359 /*
00360 RTC::ReturnCode_t SeqOut::onError(RTC::UniqueId ec_id)
00361 {
00362   return RTC::RTC_OK;
00363 }
00364 */
00365 
00366 /*
00367 RTC::ReturnCode_t SeqOut::onReset(RTC::UniqueId ec_id)
00368 {
00369   return RTC::RTC_OK;
00370 }
00371 */
00372 
00373 /*
00374 RTC::ReturnCode_t SeqOut::onStateUpdate(RTC::UniqueId ec_id)
00375 {
00376   return RTC::RTC_OK;
00377 }
00378 */
00379 
00380 /*
00381 RTC::ReturnCode_t SeqOut::onRateChanged(RTC::UniqueId ec_id)
00382 {
00383   return RTC::RTC_OK;
00384 }
00385 */
00386 
00387 
00388 
00389 extern "C"
00390 {
00391  
00392   void SeqOutInit(RTC::Manager* manager)
00393   {
00394     coil::Properties profile(seqout_spec);
00395     manager->registerFactory(profile,
00396                              RTC::Create<SeqOut>,
00397                              RTC::Delete<SeqOut>);
00398   }
00399   
00400 };


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sun Mar 26 2017 03:37:17