MOOS学习笔记3——命令行
Posted 静世孔明
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;
}
以上是关于MOOS学习笔记3——命令行的主要内容,如果未能解决你的问题,请参考以下文章