Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages | Examples

ArServerInfoRobot.cpp

Go to the documentation of this file.
00001 /*
00002 MobileRobots Advanced Robotics Interface for Applications (ARIA)
00003 Copyright (C) 2004, 2005 ActivMedia Robotics LLC
00004 Copyright (C) 2006, 2007 MobileRobots Inc.
00005 
00006      This program is free software; you can redistribute it and/or modify
00007      it under the terms of the GNU General Public License as published by
00008      the Free Software Foundation; either version 2 of the License, or
00009      (at your option) any later version.
00010 
00011      This program is distributed in the hope that it will be useful,
00012      but WITHOUT ANY WARRANTY; without even the implied warranty of
00013      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014      GNU General Public License for more details.
00015 
00016      You should have received a copy of the GNU General Public License
00017      along with this program; if not, write to the Free Software
00018      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020 If you wish to redistribute ARIA under different terms, contact 
00021 MobileRobots for information about a commercial version of ARIA at 
00022 robots@mobilerobots.com or 
00023 MobileRobots Inc, 19 Columbia Drive, Amherst, NH 03031; 800-639-9481
00024 */
00025 
00026 #include "Aria.h"
00027 #include "ArExport.h"
00028 #include "ArServerInfoRobot.h"
00029 #include "ArServerMode.h"
00030 
00031 
00032 AREXPORT ArServerInfoRobot::ArServerInfoRobot(ArServerBase *server,
00033                                               ArRobot *robot) : 
00034   myUpdateCB(this, &ArServerInfoRobot::update),
00035   myBatteryInfoCB(this, &ArServerInfoRobot::batteryInfo),
00036   myPhysicalInfoCB(this, &ArServerInfoRobot::physicalInfo),
00037         myActivityTimeInfoCB(this, &ArServerInfoRobot::activityTimeInfo)
00038 {
00039   myServer = server;
00040   myRobot = robot;
00041   myServer->addData("update", 
00042                     "gets an update about the important robot status (you should request this at an interval)",
00043                     &myUpdateCB, "none",
00044                     "string: status, string: mode, byte2: 10 * battery, byte4: x, byte4: y, byte2: th, byte2: transVel, byte2: rotVel", "RobotInfo",
00045                     "RETURN_SINGLE");
00046 
00047   myServer->addData("batteryInfo", 
00048                     "gets the low battery voltage and shutdown voltage (you only need to request this once)",
00049                     &myBatteryInfoCB, "none",
00050                     "double: low battery voltage, double: shutdown battery voltage", "RobotInfo", "RETURN_SINGLE");
00051 
00052   myServer->addData("physicalInfo", 
00053                     "gets the information about the physical robot (you only need to request this once)",
00054                     &myPhysicalInfoCB, "none",
00055                     "string: robotType; string: robotSubType; byte2: robotWidth; byte2: robotLengthFront; byte2: robotLengthRear", 
00056                     "RobotInfo", "RETURN_SINGLE");
00057 
00058   myServer->addData("activityTimeInfo", 
00059                     "Returns information about the active server mode's last activity time",
00060                     &myActivityTimeInfoCB, "none",
00061                     "byte4: seconds since"
00062                     "RETURN_SINGLE");
00063 
00064 
00065 }
00066 
00067 AREXPORT ArServerInfoRobot::~ArServerInfoRobot()
00068 {
00069 }
00070 
00071 AREXPORT void ArServerInfoRobot::update(ArServerClient *client, 
00072                                         ArNetPacket *packet)
00073 {
00074   ArNetPacket sending;
00075 
00076   myRobot->lock();
00077 
00078   ArServerMode *netMode;
00079   if ((netMode = ArServerMode::getActiveMode()) != NULL)
00080   {
00081     sending.strToBuf(netMode->getStatus());
00082     sending.strToBuf(netMode->getMode());
00083   }
00084   else 
00085   {
00086     sending.strToBuf("Unknown status");
00087     sending.strToBuf("Unknown mode");
00088   }
00089   if (myRobot->getRealBatteryVoltage() > 0)
00090     sending.byte2ToBuf(ArMath::roundInt(
00091             myRobot->getRealBatteryVoltage() * 10));
00092   else
00093     sending.byte2ToBuf(ArMath::roundInt(
00094             myRobot->getBatteryVoltage() * 10));
00095   sending.byte4ToBuf((int)myRobot->getX());
00096   sending.byte4ToBuf((int)myRobot->getY());
00097   sending.byte2ToBuf((int)myRobot->getTh());
00098   sending.byte2ToBuf((int)myRobot->getVel());
00099   sending.byte2ToBuf((int)myRobot->getRotVel());
00100   myRobot->unlock();
00101 
00102   client->sendPacketUdp(&sending);
00103 
00104 }
00105 
00106 
00107 AREXPORT void ArServerInfoRobot::batteryInfo(ArServerClient *client, 
00108                                              ArNetPacket *packet)
00109 {
00110   ArNetPacket sending;
00111 
00112   myRobot->lock();
00113   const ArRobotConfigPacketReader *reader;
00114   reader = myRobot->getOrigRobotConfig();
00115   if (reader != NULL && reader->hasPacketArrived())
00116   {
00117     if (reader->getLowBattery() != 0)
00118       sending.doubleToBuf(reader->getLowBattery() * .1);
00119     else
00120       sending.doubleToBuf(11.5);
00121     if (reader->getShutdownVoltage() != 0)
00122       sending.doubleToBuf(reader->getShutdownVoltage() * .1);
00123     else
00124       sending.doubleToBuf(11);
00125   }
00126   else
00127   {
00128     sending.doubleToBuf(11.5);
00129     sending.doubleToBuf(11);
00130   }
00131   myRobot->unlock();
00132   client->sendPacketTcp(&sending);
00133 
00134 }
00135 
00136 AREXPORT void ArServerInfoRobot::physicalInfo(ArServerClient *client, 
00137                                              ArNetPacket *packet)
00138 {
00139   ArNetPacket sending;
00140 
00141   myRobot->lock();
00142   sending.strToBuf(myRobot->getRobotType());
00143   sending.strToBuf(myRobot->getRobotSubType());
00144   sending.byte2ToBuf((int)myRobot->getRobotWidth());
00145   sending.byte2ToBuf((int)myRobot->getRobotLengthFront());
00146   sending.byte2ToBuf((int)myRobot->getRobotLengthRear());
00147   myRobot->unlock();
00148   
00149   client->sendPacketTcp(&sending);
00150 }
00151 
00152 
00153 AREXPORT void ArServerInfoRobot::activityTimeInfo(ArServerClient *client, 
00154                                                                                                                                                                                   ArNetPacket *packet)
00155 {
00156   ArNetPacket sending;
00157 
00158         // TODO Not entirely sure whether the robot needs to be locked here, but
00159         // it seems like it shouldn't hurt.
00160         //
00161   myRobot->lock();
00162   sending.byte4ToBuf(ArServerMode::getActiveModeActivityTimeSecSince());
00163   myRobot->unlock();
00164   
00165   client->sendPacketTcp(&sending);
00166 
00167 } // end method activityTimeInfo
00168 

Generated on Tue Feb 20 10:51:50 2007 for ArNetworking by  doxygen 1.4.0