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 "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
00159
00160
00161 myRobot->lock();
00162 sending.byte4ToBuf(ArServerMode::getActiveModeActivityTimeSecSince());
00163 myRobot->unlock();
00164
00165 client->sendPacketTcp(&sending);
00166
00167 }
00168