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;
}
上一篇:python 中变量和对象


下一篇:Java中两个线程是否可以同时访问同一个对象的两个不同的synchronized方法?