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;
}
本文为保持文章完整性可能使用了其他作者的文字,如果影响到您的权益,请与我联系,谢谢理解!
转载本文请注明出处,非作者授权不得用于商业用途。