00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "Aria.h"
00027 #include "ArExport.h"
00028 #include "ArServerBase.h"
00029 #include "ArServerSimpleCommands.h"
00030
00031 AREXPORT ArServerSimpleComUC::ArServerSimpleComUC(
00032 ArServerHandlerCommands *handlerCommands, ArRobot *robot) :
00033 myCommandCB(this, &ArServerSimpleComUC::command)
00034 {
00035 myHandlerCommands = handlerCommands;
00036 myRobot = robot;
00037 myHandlerCommands->addStringCommand("MicroControllerCommand",
00038 "MicroController (uC) command mode has three ways to send commands:\ncom: <command>\ncomInt: <command> <int>\ncom2Bytes: <command> <byte1> <byte2>", &myCommandCB);
00039 }
00040
00041 AREXPORT ArServerSimpleComUC::~ArServerSimpleComUC()
00042 {
00043 }
00044
00045 AREXPORT void ArServerSimpleComUC::command(ArArgumentBuilder *arg)
00046 {
00047 int command;
00048 int int1;
00049 int int2;
00050
00051 myRobot->lock();
00052 if (arg->getFullString() == NULL || arg->getFullString()[0] == '\0' ||
00053 arg->getArgc() == 0)
00054 {
00055 ArLog::log(ArLog::Terse, "uCCommand: Syntax error, no arguments.");
00056 }
00057 else if (arg->getArgc() == 1)
00058 {
00059 command = arg->getArgInt(0);
00060 if (command < 0 || command > 255 || !arg->isArgInt(0))
00061 {
00062 ArLog::log(ArLog::Terse,
00063 "uCCommand: Invalid command, must be an integer between 0 and 255");
00064 }
00065 else
00066 {
00067 ArLog::log(ArLog::Terse, "uCCommand: com(%d)", command);
00068 myRobot->com(command);
00069 }
00070 }
00071 else if (arg->getArgc() == 2)
00072 {
00073 command = arg->getArgInt(0);
00074 int1 = arg->getArgInt(1);
00075 if (command < 0 || command > 255 || !arg->isArgInt(0))
00076 {
00077 ArLog::log(ArLog::Terse,
00078 "uCCommand: Invalid command, must be an integer between 0 and 255");
00079 }
00080 else if (int1 < -32767 || int1 > 32767 || !arg->isArgInt(1))
00081 {
00082 ArLog::log(ArLog::Terse,
00083 "uCCommand: Invalid integer, must be an integer between -32767 and 32767");
00084 }
00085 else
00086 {
00087 ArLog::log(ArLog::Terse, "uCCommand: comInt(%d, %d)", command,
00088 int1);
00089 myRobot->comInt(command, int1);
00090 }
00091 }
00092 else if (arg->getArgc() == 3)
00093 {
00094 command = arg->getArgInt(0);
00095 int1 = arg->getArgInt(1);
00096 int2 = arg->getArgInt(2);
00097 if (command < 0 || command > 255 || !arg->isArgInt(0))
00098 {
00099 ArLog::log(ArLog::Terse,
00100 "uCCommand: Invalid command, must be between 0 and 255");
00101 }
00102 else if (int1 < -128 || int1 > 255 || !arg->isArgInt(1))
00103 {
00104 ArLog::log(ArLog::Terse,
00105 "uCCommand: Invalid byte1, must be an integer between -128 and 127, or between 0 and 255");
00106 }
00107 else if (int2 < -128 || int2 > 255 || !arg->isArgInt(2))
00108 {
00109 ArLog::log(ArLog::Terse,
00110 "uCCommand: Invalid byte2, must be an integer between -128 and 127, or between 0 and 255");
00111 }
00112 else
00113 {
00114 ArLog::log(ArLog::Terse,
00115 "uCCommand: com2Bytes(%d, %d, %d)",
00116 command, int1, int2);
00117 myRobot->com2Bytes(command, int1, int2);
00118 }
00119 }
00120 else
00121 {
00122 ArLog::log(ArLog::Terse, "uCCommand: Syntax error, too many arguments");
00123 }
00124 myRobot->unlock();
00125 }
00126
00127
00128 AREXPORT ArServerSimpleComMovementLogging::ArServerSimpleComMovementLogging(
00129 ArServerHandlerCommands *handlerCommands, ArRobot *robot,
00130 ArServerHandlerPopup *popupHandler) :
00131 myLogMovementSentEnableCB(this,
00132 &ArServerSimpleComMovementLogging::logMovementSentEnable),
00133 myLogMovementSentDisableCB(this,
00134 &ArServerSimpleComMovementLogging::logMovementSentDisable),
00135 myLogMovementReceivedEnableCB(this,
00136 &ArServerSimpleComMovementLogging::logMovementReceivedEnable),
00137 myLogMovementReceivedDisableCB(this,
00138 &ArServerSimpleComMovementLogging::logMovementReceivedDisable),
00139 myLogVelocitiesReceivedEnableCB(this,
00140 &ArServerSimpleComMovementLogging::logVelocitiesReceivedEnable),
00141 myLogVelocitiesReceivedDisableCB(this,
00142 &ArServerSimpleComMovementLogging::logVelocitiesReceivedDisable),
00143 myPacketsReceivedTrackingEnableCB(this,
00144 &ArServerSimpleComMovementLogging::packetsReceivedTrackingEnable),
00145 myPacketsReceivedTrackingDisableCB(this,
00146 &ArServerSimpleComMovementLogging::packetsReceivedTrackingDisable),
00147 myPacketsSentTrackingEnableCB(this,
00148 &ArServerSimpleComMovementLogging::packetsSentTrackingEnable),
00149 myPacketsSentTrackingDisableCB(this,
00150 &ArServerSimpleComMovementLogging::packetsSentTrackingDisable),
00151 myLogActionsEnableCB(this,
00152 &ArServerSimpleComMovementLogging::logActionsEnable),
00153 myLogActionsDisableCB(this,
00154 &ArServerSimpleComMovementLogging::logActionsDisable),
00155 myLogActionsCB(this, &ArServerSimpleComMovementLogging::logActions),
00156 myPopupMovementParamsCB(this,
00157 &ArServerSimpleComMovementLogging::popupMovementParams),
00158 myResetOdometerCB(this, &ArServerSimpleComMovementLogging::resetOdometer)
00159 {
00160 myHandlerCommands = handlerCommands;
00161 myRobot = robot;
00162 myPopupHandler = popupHandler;
00163 myHandlerCommands->addCommand(
00164 "LogMovementSentEnable",
00165 "Enables logging of the movement commands sent to the robot",
00166 &myLogMovementSentEnableCB);
00167 myHandlerCommands->addCommand(
00168 "LogMovementSentDisable",
00169 "Disables logging of the movement commands sent to the robot",
00170 &myLogMovementSentDisableCB);
00171 myHandlerCommands->addCommand(
00172 "LogMovementReceivedEnable",
00173 "Enables logging of the movement data received from the robot",
00174 &myLogMovementReceivedEnableCB);
00175 myHandlerCommands->addCommand(
00176 "LogMovementReceivedDisable",
00177 "Disables logging of the movement data received from the robot",
00178 &myLogMovementReceivedDisableCB);
00179 myHandlerCommands->addCommand(
00180 "LogVelocitiesReceivedEnable",
00181 "Enables logging of the velocity data received from the robot",
00182 &myLogVelocitiesReceivedEnableCB);
00183 myHandlerCommands->addCommand(
00184 "LogVelocitiesReceivedDisable",
00185 "Disables logging of the velocity data received from the robot",
00186 &myLogVelocitiesReceivedDisableCB);
00187 myHandlerCommands->addCommand(
00188 "PacketsReceivedTrackingEnable",
00189 "Enables tracking of packets received from the robot",
00190 &myPacketsReceivedTrackingEnableCB);
00191 myHandlerCommands->addCommand(
00192 "PacketsReceivedTrackingDisable",
00193 "Disables tracking of packets received from the robot",
00194 &myPacketsReceivedTrackingDisableCB);
00195 myHandlerCommands->addCommand(
00196 "PacketsSentTrackingEnable",
00197 "Enables tracking of packets sent to the robot",
00198 &myPacketsSentTrackingEnableCB);
00199 myHandlerCommands->addCommand(
00200 "PacketsSentTrackingDisable",
00201 "Disables tracking of packets sent to the robot",
00202 &myPacketsSentTrackingDisableCB);
00203 myHandlerCommands->addCommand(
00204 "LogActionsEnable",
00205 "Enables continual logging of the actions",
00206 &myLogActionsEnableCB);
00207 myHandlerCommands->addCommand(
00208 "LogActionsDisable",
00209 "Disables continual logging of the actions",
00210 &myLogActionsDisableCB);
00211 myHandlerCommands->addCommand(
00212 "LogActions",
00213 "Logs the state of the actions on the robot once",
00214 &myLogActionsCB);
00215 if (myPopupHandler != NULL)
00216 {
00217 myHandlerCommands->addCommand(
00218 "PopupMovementParams",
00219 "Creates a popup with the movement parameters for this robot",
00220 &myPopupMovementParamsCB);
00221 }
00222 myHandlerCommands->addCommand(
00223 "ResetOdometer",
00224 "Resets the robot odometer",
00225 &myResetOdometerCB);
00226
00227 }
00228
00229 AREXPORT ArServerSimpleComMovementLogging::~ArServerSimpleComMovementLogging()
00230 {
00231 }
00232
00233 AREXPORT void ArServerSimpleComMovementLogging::logMovementSentEnable(void)
00234 {
00235 myRobot->lock();
00236 myRobot->setLogMovementSent(true);
00237 myRobot->unlock();
00238 }
00239
00240 AREXPORT void ArServerSimpleComMovementLogging::logMovementSentDisable(void)
00241 {
00242 myRobot->lock();
00243 myRobot->setLogMovementSent(false);
00244 myRobot->unlock();
00245 }
00246
00247 AREXPORT void ArServerSimpleComMovementLogging::logMovementReceivedEnable(void)
00248 {
00249 myRobot->lock();
00250 myRobot->setLogMovementReceived(true);
00251 myRobot->unlock();
00252 }
00253
00254 AREXPORT void ArServerSimpleComMovementLogging::logMovementReceivedDisable(void)
00255 {
00256 myRobot->lock();
00257 myRobot->setLogMovementReceived(false);
00258 myRobot->unlock();
00259 }
00260
00261 AREXPORT void ArServerSimpleComMovementLogging::logVelocitiesReceivedEnable(void)
00262 {
00263 myRobot->lock();
00264 myRobot->setLogVelocitiesReceived(true);
00265 myRobot->unlock();
00266 }
00267
00268 AREXPORT void ArServerSimpleComMovementLogging::logVelocitiesReceivedDisable(void)
00269 {
00270 myRobot->lock();
00271 myRobot->setLogVelocitiesReceived(false);
00272 myRobot->unlock();
00273 }
00274
00275 AREXPORT void ArServerSimpleComMovementLogging::packetsReceivedTrackingEnable(void)
00276 {
00277 myRobot->lock();
00278 myRobot->setPacketsReceivedTracking(true);
00279 myRobot->unlock();
00280 }
00281
00282 AREXPORT void ArServerSimpleComMovementLogging::packetsReceivedTrackingDisable(void)
00283 {
00284 myRobot->lock();
00285 myRobot->setPacketsReceivedTracking(false);
00286 myRobot->unlock();
00287 }
00288
00289
00290 AREXPORT void ArServerSimpleComMovementLogging::packetsSentTrackingEnable(void)
00291 {
00292 myRobot->lock();
00293 myRobot->setPacketsSentTracking(true);
00294 myRobot->unlock();
00295 }
00296
00297 AREXPORT void ArServerSimpleComMovementLogging::packetsSentTrackingDisable(void)
00298 {
00299 myRobot->lock();
00300 myRobot->setPacketsSentTracking(false);
00301 myRobot->unlock();
00302 }
00303
00304 AREXPORT void ArServerSimpleComMovementLogging::logActionsEnable(void)
00305 {
00306 myRobot->lock();
00307 myRobot->setLogActions(true);
00308 myRobot->unlock();
00309 }
00310
00311 AREXPORT void ArServerSimpleComMovementLogging::logActionsDisable(void)
00312 {
00313 myRobot->lock();
00314 myRobot->setLogActions(false);
00315 myRobot->unlock();
00316 }
00317
00318 AREXPORT void ArServerSimpleComMovementLogging::logActions(void)
00319 {
00320 myRobot->lock();
00321 myRobot->logActions();
00322 myRobot->unlock();
00323 }
00324
00325 AREXPORT void ArServerSimpleComMovementLogging::popupMovementParams(void)
00326 {
00327 char buf[32000];
00328 myRobot->lock();
00329 sprintf(buf, "TransVelTop %.0f TransAccelTop %.0f TransDecelTop %.0f\nTransVelMax %.0f TransAccel %.0f TransDecel %.0f\n\nRotVelTop %.0f RotAccelTop %.0f RotDecelTop %.0f\nRotVelMax %.0f RotAccel %.0f RotDecel %.0f",
00330 myRobot->getAbsoluteMaxTransVel(),
00331 myRobot->getAbsoluteMaxTransAccel(),
00332 myRobot->getAbsoluteMaxTransDecel(),
00333 myRobot->getTransVelMax(),
00334 myRobot->getTransAccel(),
00335 myRobot->getTransDecel(),
00336 myRobot->getAbsoluteMaxRotVel(),
00337 myRobot->getAbsoluteMaxRotAccel(),
00338 myRobot->getAbsoluteMaxRotDecel(),
00339 myRobot->getRotVelMax(),
00340 myRobot->getRotAccel(),
00341 myRobot->getRotDecel());
00342 ArServerHandlerPopupInfo popupInfo(
00343 NULL, "Robot Movement Parameters", buf,
00344 ArServerHandlerPopup::INFORMATION,
00345 0, 0, 0, NULL, "OK", "Done viewing movement parameters");
00346
00347 myPopupHandler->createPopup(&popupInfo);
00348 myRobot->unlock();
00349 }
00350 AREXPORT ArServerSimpleComGyro::ArServerSimpleComGyro(
00351 ArServerHandlerCommands *handlerCommands, ArRobot *robot,
00352 ArAnalogGyro *gyro) :
00353 myGyroEnableCB(this, &ArServerSimpleComGyro::gyroEnable),
00354 myGyroDisableCB(this, &ArServerSimpleComGyro::gyroDisable)
00355 {
00356 myHandlerCommands = handlerCommands;
00357 myRobot = robot;
00358 myGyro = gyro;
00359 myHandlerCommands->addCommand("GyroEnable",
00360 "Enables the gyro",
00361 &myGyroEnableCB);
00362 myHandlerCommands->addCommand("GyroDisable",
00363 "Disables the gyro",
00364 &myGyroDisableCB);
00365 }
00366
00367 AREXPORT void ArServerSimpleComMovementLogging::resetOdometer(void)
00368 {
00369 myRobot->lock();
00370 myRobot->resetOdometer();
00371 myRobot->unlock();
00372 }
00373
00374 AREXPORT ArServerSimpleComGyro::~ArServerSimpleComGyro()
00375 {
00376 }
00377
00378 AREXPORT void ArServerSimpleComGyro::gyroEnable(void)
00379 {
00380 myRobot->lock();
00381 if (myGyro != NULL)
00382 myGyro->activate();
00383 myRobot->unlock();
00384 }
00385
00386 AREXPORT void ArServerSimpleComGyro::gyroDisable(void)
00387 {
00388 myRobot->lock();
00389 if (myGyro != NULL)
00390 myGyro->deactivate();
00391 myRobot->unlock();
00392 }
00393
00394 AREXPORT ArServerSimpleComLogRobotConfig::ArServerSimpleComLogRobotConfig(
00395 ArServerHandlerCommands *commands, ArRobot* robot,
00396 ArServerHandlerPopup *popupHandler) :
00397 myPacketArrivedCB(this,
00398 &ArServerSimpleComLogRobotConfig::configPacketArrived),
00399 myPacketReader(robot, false, &myPacketArrivedCB),
00400 myLogConfigCB(this, &ArServerSimpleComLogRobotConfig::logConfig),
00401 myLogOrigConfigCB(this, &ArServerSimpleComLogRobotConfig::logOrigConfig),
00402 myPopupConfigCB(this, &ArServerSimpleComLogRobotConfig::popupConfig),
00403 myPopupOrigConfigCB(this, &ArServerSimpleComLogRobotConfig::popupOrigConfig)
00404 {
00405 myRobot = robot;
00406 myHandlerCommands = commands;
00407 myPopupHandler = popupHandler;
00408
00409 myLogConfig = false;
00410 myPopupConfig = false;
00411
00412 commands->addCommand("LogRobotConfig",
00413 "Get current robot configuration and write it to the server log.",
00414 &myLogConfigCB);
00415 commands->addCommand("LogOrigRobotConfig",
00416 "Logs the original config packet the robot sent on connection.",
00417 &myLogOrigConfigCB);
00418 if (myPopupHandler != NULL)
00419 {
00420 commands->addCommand("PopupRobotConfig",
00421 "Popups up the current robot configuration.",
00422 &myPopupConfigCB);
00423 commands->addCommand("PopupOrigRobotConfig",
00424 "Popups up the original config packet the robot sent on connection.",
00425 &myPopupOrigConfigCB);
00426 }
00427 }
00428
00429
00430 AREXPORT void ArServerSimpleComLogRobotConfig::logConfig(void)
00431 {
00432 ArLog::log(ArLog::Normal, "Server received logRobotConfig command. Config packet requested; waiting...");
00433 myRobot->lock();
00434 myPacketReader.requestPacket();
00435 myLogConfig = true;
00436 myRobot->unlock();
00437 }
00438
00439
00440 AREXPORT void ArServerSimpleComLogRobotConfig::logOrigConfig(void)
00441 {
00442 myRobot->lock();
00443 if (myRobot->getOrigRobotConfig() != NULL &&
00444 myRobot->getOrigRobotConfig()->hasPacketArrived())
00445 {
00446 ArLog::log(ArLog::Normal, "-- Orig Config Packet: --");
00447 myRobot->getOrigRobotConfig()->log();
00448 ArLog::log(ArLog::Normal, "-- End Orig Config --");
00449 }
00450 else
00451 {
00452 ArLog::log(ArLog::Normal,
00453 "Cannot log Orig Config since it was never received.");
00454 }
00455 myRobot->unlock();
00456 }
00457
00458 AREXPORT void ArServerSimpleComLogRobotConfig::popupConfig(void)
00459 {
00460 ArLog::log(ArLog::Normal, "Server received popupRobotConfig command. Config packet requested; waiting...");
00461 myRobot->lock();
00462 myPacketReader.requestPacket();
00463 myPopupConfig = true;
00464 myRobot->unlock();
00465 }
00466
00467 AREXPORT void ArServerSimpleComLogRobotConfig::popupOrigConfig(void)
00468 {
00469 myRobot->lock();
00470 if (myRobot->getOrigRobotConfig() != NULL &&
00471 myRobot->getOrigRobotConfig()->hasPacketArrived())
00472 {
00473 std::string str;
00474 str = myPacketReader.buildString();
00475 ArServerHandlerPopupInfo popupInfo(
00476 NULL, "Orig robot config", str.c_str(),
00477 ArServerHandlerPopup::INFORMATION,
00478 0, 0, 0, NULL, "OK", "Done viewing orig robot config parameters");
00479
00480 myPopupHandler->createPopup(&popupInfo);
00481 }
00482 else
00483 {
00484 ArLog::log(ArLog::Normal,
00485 "Cannot log Orig Config since it was never received.");
00486 }
00487 myRobot->unlock();
00488 }
00489
00490 void ArServerSimpleComLogRobotConfig::configPacketArrived(void)
00491 {
00492 if (myLogConfig)
00493 {
00494 ArLog::log(ArLog::Normal, "-- Robot Config Packet Returned: --");
00495 myPacketReader.log();
00496 ArLog::log(ArLog::Normal, "-- End Config --");
00497 }
00498 if (myPopupConfig)
00499 {
00500 std::string str;
00501 str = myPacketReader.buildString();
00502 ArServerHandlerPopupInfo popupInfo(
00503 NULL, "Robot config", str.c_str(),
00504 ArServerHandlerPopup::INFORMATION,
00505 0, 0, 0, NULL, "OK", "Done viewing robot config parameters");
00506
00507 myPopupHandler->createPopup(&popupInfo);
00508
00509 }
00510
00511 myLogConfig = false;
00512 myPopupConfig = false;
00513 }
00514
00515 AREXPORT ArServerSimpleComLogActions::ArServerSimpleComLogActions(ArServerHandlerCommands *commands, ArRobot* robot) :
00516 myRobot(robot), myCallback(this, &ArServerSimpleComLogActions::logActions)
00517 {
00518 commands->addCommand("LogActions", "Write current ArRobot actions to server log file.",
00519 &myCallback);
00520 }
00521
00522 AREXPORT void ArServerSimpleComLogActions::logActions()
00523 {
00524 ArLog::log(ArLog::Normal, "Server simple command logActions: current ArRobot actions are:");
00525 myRobot->logActions();
00526 }
00527
00528 AREXPORT ArServerSimpleServerCommands::ArServerSimpleServerCommands(
00529 ArServerHandlerCommands *commands, ArServerBase *server) :
00530 myTerseTrackingCB(this, &ArServerSimpleServerCommands::logTerseTracking),
00531 myVerboseTrackingCB(this, &ArServerSimpleServerCommands::logVerboseTracking),
00532 myResetTrackingCB(this, &ArServerSimpleServerCommands::resetTracking)
00533 {
00534 myServer = server;
00535 commands->addCommand("NetworkTrackingLogTerse",
00536 "Logs the information about client commands sent and received:",
00537 &myTerseTrackingCB);
00538 commands->addCommand("NetworkTrackingLogVerbose",
00539 "Logs verbosely (broken up by tcp/udp) the information about client commands sent and received:",
00540 &myVerboseTrackingCB);
00541
00542 commands->addCommand("NetworkTrackingReset",
00543 "Reests the information about client commands sent and received:",
00544 &myResetTrackingCB);
00545 }
00546
00547 AREXPORT ArServerSimpleServerCommands::~ArServerSimpleServerCommands()
00548 {
00549 }
00550
00551 AREXPORT void ArServerSimpleServerCommands::logTerseTracking()
00552 {
00553 myServer->logTracking(true);
00554 }
00555
00556 AREXPORT void ArServerSimpleServerCommands::logVerboseTracking()
00557 {
00558 myServer->logTracking(false);
00559 }
00560
00561 AREXPORT void ArServerSimpleServerCommands::resetTracking()
00562 {
00563 myServer->resetTracking();
00564 }
00565
00566 AREXPORT ArServerSimplePopup::ArServerSimplePopup(
00567 ArServerHandlerCommands *commands,
00568 ArServerHandlerPopup *popupHandler) :
00569 mySimplePopupCB(this, &ArServerSimplePopup::simplePopup)
00570 {
00571 myCommands = commands;
00572 myPopupHandler = popupHandler;
00573 myCommands->addStringCommand(
00574 "SimplePopup",
00575 "\"<title>\" \"<message>\" \"<button>\" <int:timeout>",
00576 &mySimplePopupCB);
00577 }
00578
00579 AREXPORT ArServerSimplePopup::~ArServerSimplePopup()
00580 {
00581 }
00582
00583 AREXPORT void ArServerSimplePopup::simplePopup(ArArgumentBuilder *arg)
00584 {
00585
00586 arg->compressQuoted(true);
00587
00588 if (arg->getArgc() < 4)
00589 {
00590 ArLog::log(ArLog::Terse,
00591 "simplePopup: Syntax error, not enough arguments.");
00592 return;
00593 }
00594
00595 ArServerHandlerPopupInfo popupInfo(
00596 arg->getArg(0), arg->getArg(0),
00597 arg->getArg(1), ArServerHandlerPopup::INFORMATION,
00598 0, 0, arg->getArgInt(3), arg->getArg(1),
00599 arg->getArg(2), arg->getArg(1));
00600 myPopupHandler->createPopup(&popupInfo);
00601 }