MOOS 0.2375
|
00001 00002 00003 00004 00005 #include <MOOSLIB/MOOSCommClient.h> 00006 00007 CMOOSCommClient theMOOS; 00008 00009 00010 bool OnConnectToServer(void * pParam) 00011 { 00012 return true; 00013 } 00014 00015 void PrintHelp() 00016 { 00017 MOOSTrace("uPoke Help:\n"); 00018 MOOSTrace("\n general use :\n\t\"uPoke host portnumber msgName msgContent\""); 00019 MOOSTrace("\n use assumed MOOSDB settings (localhost 9000):\n\t\"uPoke -d msgName msgContent\""); 00020 MOOSTrace("\n\n\texamples:\n"); 00021 MOOSTrace("\t uPoke robots.ox.ac.uk 9010 BeSmart how=think,when=now\n"); 00022 MOOSTrace("\t uPoke robots.ox.ac.uk 9010 WorryLevel 0.99\n"); 00023 MOOSTrace("\t uPoke -d WorryLevel 0.99\n"); 00024 00025 } 00026 00027 bool Send(CMOOSMsg Msg) 00028 { 00029 while(!theMOOS.IsConnected()) 00030 MOOSPause(10); 00031 00032 00033 if(theMOOS.Post(Msg)) 00034 { 00035 theMOOS.Register(Msg.GetKey(),0); 00036 00037 MOOSMSG_LIST M; 00038 while(!theMOOS.Fetch(M)) 00039 { 00040 MOOSPause(10); 00041 } 00042 } 00043 00044 return true; 00045 } 00046 00047 int main(int argc, char * argv[]) 00048 { 00049 //before we do anything.... 00050 theMOOS.SetQuiet(true); 00051 theMOOS.SetOnConnectCallBack(OnConnectToServer,NULL); 00052 00053 00054 00055 std::string sServer = "localhost"; 00056 int nPort = 9000; 00057 std::string sName; 00058 00059 std::vector<std::string> Arguments; 00060 00061 for (unsigned int i = 1; i < argc; i++) 00062 { 00063 Arguments.push_back(argv[i]); 00064 } 00065 00066 00067 //uPoke -d msg content 00068 //uPoke localhost 9000 msg contents 00069 00070 unsigned int k = 0; 00071 if (Arguments.size() == 3) 00072 { 00073 if (Arguments[k++] != "-d") 00074 { 00075 PrintHelp(); 00076 exit(1); 00077 } 00078 00079 } 00080 else if (Arguments.size() == 4) 00081 { 00082 00083 sServer = Arguments[k++]; 00084 00085 if (!MOOSIsNumeric(Arguments[k])) 00086 return MOOSFail("second argument (port number) is not numeric"); 00087 00088 nPort = atoi(Arguments[k++].c_str()); 00089 } 00090 else 00091 { 00092 PrintHelp(); 00093 exit(1); 00094 } 00095 00096 00097 theMOOS.Run(sServer.c_str(), nPort, theMOOS.GetLocalIPAddress().c_str(),40); 00098 00099 sName = Arguments[k++]; 00100 00101 bool bOK; 00102 if (MOOSIsNumeric(Arguments[k])) 00103 { 00104 bOK = Send(CMOOSMsg(MOOS_NOTIFY, sName, atof(Arguments[k].c_str()), 00105 MOOSTime())); 00106 } 00107 else 00108 { 00109 bOK =Send(CMOOSMsg(MOOS_NOTIFY, sName, Arguments[k].c_str(), MOOSTime())); 00110 } 00111 00112 return bOK ? 0: 1; 00113 00114 } 00115 00116