AutoTestOut.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00010 #include <coil/Time.h>
00011 #include <iostream>
00012 #include <iomanip>
00013 
00014 #include "AutoTestOut.h"
00015 // Module specification
00016 // <rtc-template block="module_spec">
00017 static const char* autotestout_spec[] =
00018   {
00019     "implementation_id", "AutoTestOut",
00020     "type_name",         "AutoTestOut",
00021     "description",       "Sample component for auto-test",
00022     "version",           "1.0.0",
00023     "vendor",            "AIST",
00024     "category",          "example",
00025     "activity_type",     "PERIODIC",
00026     "kind",              "DataFlowComponent",
00027     "max_instance",      "1",
00028     "language",          "C++",
00029     "lang_type",         "compile",
00030     "exec_cxt.periodic.rate", "1.0",
00031     ""
00032   };
00033 // </rtc-template>
00034 
00039 AutoTestOut::AutoTestOut(RTC::Manager* manager)
00040     // <rtc-template block="initializer">
00041   : RTC::DataFlowComponentBase(manager),
00042     m_outOut("out", m_out),
00043     m_seqoutOut("seqout", m_seqout),
00044     m_MyServicePort("MyService")
00045 
00046     // </rtc-template>
00047 {
00048 }
00049 
00053 AutoTestOut::~AutoTestOut()
00054 {
00055 }
00056 
00057 
00058 
00059 RTC::ReturnCode_t AutoTestOut::onInitialize()
00060 {
00061   // Registration: InPort/OutPort/Service
00062   // <rtc-template block="registration">
00063   // Set InPort buffers
00064   
00065   // Set OutPort buffer
00066   addOutPort("out", m_outOut);
00067   addOutPort("seqout", m_seqoutOut);
00068   m_seqout.data.length(5);
00069   // Set service provider to Ports
00070   
00071   // Set service consumers to Ports
00072   m_MyServicePort.registerConsumer("myservice0", "MyService", m_myservice0);
00073   
00074   // Set CORBA Service Ports
00075   addPort(m_MyServicePort);
00076   
00077   // </rtc-template>
00078 
00079   return RTC::RTC_OK;
00080 }
00081 
00082 /*
00083 RTC::ReturnCode_t AutoTestOut::onFinalize()
00084 {
00085   return RTC::RTC_OK;
00086 }
00087 */
00088 
00089 /*
00090 RTC::ReturnCode_t AutoTestOut::onStartup(RTC::UniqueId ec_id)
00091 {
00092   return RTC::RTC_OK;
00093 }
00094 */
00095 
00096 /*
00097 RTC::ReturnCode_t AutoTestOut::onShutdown(RTC::UniqueId ec_id)
00098 {
00099   return RTC::RTC_OK;
00100 }
00101 */
00102 
00103 
00104 RTC::ReturnCode_t AutoTestOut::onActivated(RTC::UniqueId ec_id)
00105 {
00106   //ここでファイルを開く
00107   fin.open("original-data");
00108   if (!fin){
00109     std::cout << "Can't open original-data..." << std::endl;
00110     return RTC::RTC_ERROR;
00111   }
00112   return RTC::RTC_OK;
00113 }
00114 
00115 
00116 RTC::ReturnCode_t AutoTestOut::onDeactivated(RTC::UniqueId ec_id)
00117 {
00118   fin.close();
00119   fin.clear(); // for win32.
00120   return RTC::RTC_OK;
00121 }
00122 
00123 
00124 RTC::ReturnCode_t AutoTestOut::onExecute(RTC::UniqueId ec_id)
00125 {
00126 
00127   coil::usleep(100000);
00128 
00129   //onexecuteでファイルから3行ずつ読み込み送る
00130   std::vector<std::string> vstr;
00131   std::string ss;
00132   
00133   if (getline(fin, ss)){ //Float
00134 
00135     //std::cout << "1 " << ss << std::endl;
00136     std::cout << std::fixed;
00137     std::cout << std::showpoint;
00138     std::cout << std::setprecision(6);
00139     std::stringstream iss;
00140     std::string str;
00141     iss.str(ss);
00142     iss >> m_out.data;
00143     std::cout << m_out.data << std::endl;
00144     //fout << m_out.data << std::endl;
00145 
00146 
00147     if (getline(fin, ss)){ //SeqFloat
00148       std::cout << ss << std::endl;
00149       //std::cout << strlen(ss) << std::endl;
00150       vstr = coil::split(ss, " ");
00151       std::stringstream isss;
00152 
00153       for (int len=0; len<5; ++len){
00154         //std::cout << vstr[len] << std::endl;
00155         isss.str(vstr[len]);
00156         isss >>m_seqout.data[len];
00157         std::cout << "m_seqout.data[len] = " << m_seqout.data[len] << std::endl;
00158         isss.clear();
00159       }
00160       //fout << m_seqout.data[0] << " " << m_seqout.data[1] << " " << m_seqout.data[2] << " " << m_seqout.data[3] << " " <<m_seqout.data[4] << std::endl;
00161 
00162       if (getline(fin,ss)){ //echo用
00163         std::cout << ss << std::endl;
00164         //fout << ss << std::endl;
00165         char* retmsg;
00166 
00167         if (!CORBA::is_nil(m_myservice0._ptr())){
00168           retmsg = m_myservice0->echo(ss.c_str());
00169         }
00170 
00171         m_outOut.write();
00172         m_seqoutOut.write();
00173 
00174       }
00175     }
00176   }
00177 
00178   return RTC::RTC_OK;
00179 }
00180 
00181 /*
00182 RTC::ReturnCode_t AutoTestOut::onAborting(RTC::UniqueId ec_id)
00183 {
00184   return RTC::RTC_OK;
00185 }
00186 */
00187 
00188 /*
00189 RTC::ReturnCode_t AutoTestOut::onError(RTC::UniqueId ec_id)
00190 {
00191   return RTC::RTC_OK;
00192 }
00193 */
00194 
00195 /*
00196 RTC::ReturnCode_t AutoTestOut::onReset(RTC::UniqueId ec_id)
00197 {
00198   return RTC::RTC_OK;
00199 }
00200 */
00201 
00202 /*
00203 RTC::ReturnCode_t AutoTestOut::onStateUpdate(RTC::UniqueId ec_id)
00204 {
00205   return RTC::RTC_OK;
00206 }
00207 */
00208 
00209 /*
00210 RTC::ReturnCode_t AutoTestOut::onRateChanged(RTC::UniqueId ec_id)
00211 {
00212   return RTC::RTC_OK;
00213 }
00214 */
00215 
00216 
00217 
00218 extern "C"
00219 {
00220  
00221   void AutoTestOutInit(RTC::Manager* manager)
00222   {
00223     coil::Properties profile(autotestout_spec);
00224     manager->registerFactory(profile,
00225                              RTC::Create<AutoTestOut>,
00226                              RTC::Delete<AutoTestOut>);
00227   }
00228   
00229 };
00230 
00231 


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Thu Aug 27 2015 14:16:37