MOOS学习笔记3——命令行

MOOS学习笔记3——命令行

例程

/**
* @code  A simple example showing how to use a comms client问问怎么样
*/

#include "MOOS/libMOOS/Comms/MOOSAsyncCommClient.h"
#include "MOOS/libMOOS/Utils/CommandLineParser.h"
bool OnConnect ( void *pParam ) {
   CMOOSCommClient *pC = reinterpret_cast <CMOOSCommClient*> (pParam) ;
   pC->Register ("X", 0.0) ;
   return true ;
}
bool OnMail ( void *pParam ) {
   CMOOSCommClient *pC = reinterpret_cast <CMOOSCommClient*>(pParam) ;
   MOOSMSG_LIST M ; // get the mail
   pC->Fetch(M) ;
   MOOSMSG_LIST :: iterator q ; // process it
   for ( q=M . begin ( ) ; q!=M . end ( ) ; q++){
      q->Trace() ;
   }
   return true ;
}
int main ( int argc , char *argv [] ) {
   // understand the command line
   MOOS :: CommandLineParser P(argc , argv);
   std :: string db_host="localhost" ;
   P . GetVariable ("--moos_host" , db_host);
   int db_port =9000;
   P.GetVariable ("--moos_port" , db_port);
   std :: string my_name ="ex30" ;
   P.GetVariable ("--moos_name" , my_name);
   // configure the comms
   MOOS :: MOOSAsyncCommClient Comms;
   Comms . SetOnMailCallBack(OnMail ,& Comms );
   Comms . SetOnConnectCallBack( OnConnect ,&Comms );
   // start the comms running
   Comms . Run( db_host , db_port, my_name );

   // forever loop sending data
   std :: vector<unsigned char> X (100);
   for ( ; ; ) {
      MOOSPause (1000);
      Comms.Notify ("X", X);
   }
   return 0;
}
posted @ 2018-04-29 21:09  静世孔明  阅读(217)  评论(0编辑  收藏  举报