Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

# Representations/WLan/TeamMessage.cpp

Go to the documentation of this file.

    00001 /**
    00002 * @file Representations/WLan/TeamMessage.cpp
    00003 *
    00004 * Implementation of class TeamMessage.
    00005 *
    00006 * @author <A href=mailto:roefer@tzi.de>Thomas Röfer</A>
    00007 * @author <A href=mailto:sebastian.schmidt@udo.edu>Sebastian Schmidt</A>
    00008 * @author <A href=mailto:m_wachter@gmx.de>Michael Wachter</A>
    00009 */
    00010
    00011 #include "TeamMessage.h"
    00012 #include "Platform/SystemCall.h"
    00013 //#include "Modules/BallLocator/GT2005Particles/GT2005ParticleContainer.h"
    00014 #include "Platform/GTAssert.h"
    00015
    00016 //#define STREAMMARKER(marker) stream << (int) marker + 10000
    00017 //#define CHECKMARKER(marker) { int dummy = 0; stream >> dummy ; ASSERT (dummy == marker + 10000 ); }
    00018
    00019 //int TeamMessage::cryptWord;
    00020
    00021 TeamMessage::TeamMessage() {
    00022   timeStamp = 0;
    00023   incomingTimeStamp[0] = 0;
    00024   incomingTimeStamp[1] = 0;
    00025   incomingTimeStamp[2] = 0;
    00026   incomingTimeStamp[3] = 0;
    00027   lastReceivedTimeStamp[0] = 0;
    00028   lastReceivedTimeStamp[1] = 0;
    00029   lastReceivedTimeStamp[2] = 0;
    00030   lastReceivedTimeStamp[3] = 0;
    00031   playerNumberOfSender = Player::undefinedPlayerNumber;
    00032   resetSendMarkers();
    00033
    00034  // Darmstadt ? Crpypto erts mal deaktiviert ;)
    00035  // char* temp = getPlayer().getTeamName();
    00036  // cryptWord = ((int) *temp) + 7 + ((((int) *temp+1) + 17) << 8) + ((((int) *temp+2) + 37) << 16) + ((((int) *temp+3) + 19) << 24);
    00037 }
    00038
    00039 void TeamMessage::resetSendMarkers()
    00040 {
    00041   sendRobotPose = false;
    00042   sendSeenBallState = false;
    00043   sendBehaviorTeamMessage = false;
    00044   sendPlayersPercept = false;
    00045   sendSensorBehaviorTeamMessage = false;
    00046   sendOdometryData = false;
    00047   sendMultipleBallPerceptList = false;
    00048   sendGT2005ParticleContainerSend = false;
    00049   sendRobotPoseCollection = false;
    00050   sendObstaclesModel = false;
    00051 }
    00052
    00053 TeamMessage::~TeamMessage()
    00054 {
    00055
    00056 }
    00057
    00058 bool TeamMessage::isActual() const
    00059 {
    00060   return SystemCall::getTimeSince(lastReceivedTimeStamp[(int)getPlayer().getPlayerNumber()]) < 2000;
    00061 }
    00062
    00063 bool TeamMessage::isActual(int i) const
    00064 {
    00065   return (SystemCall::getTimeSince(lastReceivedTimeStamp[(int)getPlayer().getPlayerNumber()]) < (unsigned int)i );
    00066 }
    00067
    00068 In& operator>>(In& stream,TeamMessage& teamMessage)
    00069 {
    00070   stream >> teamMessage.timeStamp;
    00071   for (int i=0; i<4; i++)
    00072   {
    00073     stream >> teamMessage.lastReceivedTimeStamp[i];
    00074     stream >> teamMessage.incomingTimeStamp[i];
    00075   }
    00076
    00077   char c;
    00078   stream >> c;
    00079   teamMessage.playerNumberOfSender = (Player::playerNumber)c;
    00080
    00081   int fieldsInMessage;
    00082   stream >> fieldsInMessage;
    00083
    00084   teamMessage.sendRobotPose = ((fieldsInMessage & 1) == 1);
    00085   teamMessage.sendSeenBallState = ((fieldsInMessage & 2) == 2);
    00086   teamMessage.sendBehaviorTeamMessage = ((fieldsInMessage & 4) == 4);
    00087   teamMessage.sendPlayersPercept = ((fieldsInMessage & 8) == 8);
    00088   teamMessage.sendSensorBehaviorTeamMessage = ((fieldsInMessage & 16) == 16);
    00089   teamMessage.sendOdometryData = ((fieldsInMessage & 32) == 32);
    00090   teamMessage.sendMultipleBallPerceptList = ((fieldsInMessage & 64) == 64);
    00091   teamMessage.sendGT2005ParticleContainerSend = ((fieldsInMessage & 128) == 128);
    00092   teamMessage.sendRobotPoseCollection = ((fieldsInMessage & 256) == 256);
    00093   teamMessage.sendObstaclesModel = ((fieldsInMessage & 512) == 512);
    00094
    00095   // robot pose
    00096   if (teamMessage.sendRobotPose)
    00097   {
    00098     //CHECKMARKER(1);
    00099     TeamMessage::read(stream,teamMessage.robotPose);
    00100     stream >> c;
    00101     teamMessage.robotPose.setValidity(c / 100.0);
    00102   }
    00103
    00104   if (teamMessage.sendSeenBallState)
    00105   {
    00106     //CHECKMARKER(2);
    00107     stream >> teamMessage.seenBallState;
    00108   }
    00109
    00110   if (teamMessage.sendBehaviorTeamMessage)
    00111   {
    00112     //CHECKMARKER(3);
    00113     stream >> teamMessage.behaviorTeamMessage;
    00114   }
    00115
    00116   if (teamMessage.sendPlayersPercept)
    00117   {
    00118     //CHECKMARKER(4);
    00119     stream >> teamMessage.playersPercept;
    00120   }
    00121
    00122   if (teamMessage.sendSensorBehaviorTeamMessage)
    00123   {
    00124     //CHECKMARKER(5);
    00125     stream >> teamMessage.sensorBehaviorTeamMessage;
    00126   }
    00127
    00128   if (teamMessage.sendOdometryData)
    00129   {
    00130     //CHECKMARKER(6);
    00131     stream >> teamMessage.odometryData;
    00132   }
    00133
    00134   if (teamMessage.sendMultipleBallPerceptList)
    00135   {
    00136     //CHECKMARKER(7);
    00137     stream >> teamMessage.multipleBallPerceptList;
    00138   }
    00139
    00140   if (teamMessage.sendGT2005ParticleContainerSend)
    00141   {
    00142     //CHECKMARKER(8);
    00143     stream >> teamMessage.gt2005ParticleContainerSend;
    00144   }
    00145
    00146   if (teamMessage.sendRobotPoseCollection)
    00147   {
    00148     //CHECKMARKER(9);
    00149     stream >> teamMessage.robotPoseCollection;
    00150   }
    00151
    00152   if (teamMessage.sendObstaclesModel)
    00153   {
    00154     //CHECKMARKER(10);
    00155     int boolReplacement;
    00156     stream >> boolReplacement
    00157       >> teamMessage.obstaclesModel.widthOfFreePartOfGoal[ObstaclesModel::opponentGoal];
    00158     if (boolReplacement)
    00159       teamMessage.obstaclesModel.angleToFreePartOfGoalWasDetermined[ObstaclesModel::opponentGoal] = 1;
    00160     else
    00161       teamMessage.obstaclesModel.angleToFreePartOfGoalWasDetermined[ObstaclesModel::opponentGoal] = 0;
    00162   }
    00163
    00164   return stream;
    00165 }
    00166
    00167 Out& operator<<(Out& stream,const TeamMessage& teamMessage)
    00168 {
    00169   stream << teamMessage.timeStamp;
    00170   for (int i=0; i<4; i++)
    00171   {
    00172     stream << teamMessage.lastReceivedTimeStamp[i];
    00173     stream << teamMessage.incomingTimeStamp[i];
    00174   }
    00175
    00176   stream << (char)getPlayer().getPlayerNumber();
    00177
    00178   // a bitfield which tells the receiver what fields are transmitted
    00179   int fieldsInMessage =
    00180
    00181     teamMessage.sendRobotPose * 1
    00182     + (teamMessage.sendSeenBallState * 2)
    00183     + (teamMessage.sendBehaviorTeamMessage * 4)
    00184     + (teamMessage.sendPlayersPercept * 8)
    00185     + (teamMessage.sendSensorBehaviorTeamMessage * 16)
    00186     + (teamMessage.sendOdometryData * 32)
    00187     + (teamMessage.sendMultipleBallPerceptList * 64)
    00188     + (teamMessage.sendGT2005ParticleContainerSend * 128)
    00189     + (teamMessage.sendRobotPoseCollection * 256)
    00190     + (teamMessage.sendObstaclesModel * 512)
    00191     ;
    00192   stream << fieldsInMessage;
    00193
    00194   // robot pose
    00195   if (teamMessage.sendRobotPose)
    00196   {
    00197     //STREAMMARKER(1);
    00198     TeamMessage::write(stream,teamMessage.robotPose);
    00199     stream << char(teamMessage.robotPose.getValidity() * 100.0 + 0.5);
    00200   }
    00201
    00202   if (teamMessage.sendSeenBallState)
    00203   {
    00204     //STREAMMARKER(2);
    00205     stream << teamMessage.seenBallState;
    00206   }
    00207
    00208   // BehaviorTeamMessage
    00209   if (teamMessage.sendBehaviorTeamMessage)
    00210   {
    00211     //STREAMMARKER(3);
    00212     stream << teamMessage.behaviorTeamMessage;
    00213   }
    00214
    00215   if (teamMessage.sendPlayersPercept)
    00216   {
    00217     //STREAMMARKER(4);
    00218     stream << teamMessage.playersPercept;
    00219   }
    00220
    00221   if (teamMessage.sendSensorBehaviorTeamMessage)
    00222   {
    00223     //STREAMMARKER(5);
    00224     stream << teamMessage.sensorBehaviorTeamMessage;
    00225   }
    00226
    00227   if (teamMessage.sendOdometryData)
    00228   {
    00229     //STREAMMARKER(6);
    00230     stream << teamMessage.odometryData;
    00231   }
    00232
    00233   if (teamMessage.sendMultipleBallPerceptList)
    00234   {
    00235     //STREAMMARKER(7);
    00236     stream << teamMessage.multipleBallPerceptList;
    00237   }
    00238
    00239   if (teamMessage.sendGT2005ParticleContainerSend)
    00240   {
    00241     //STREAMMARKER(8);
    00242     stream << teamMessage.gt2005ParticleContainerSend;
    00243   }
    00244
    00245   if (teamMessage.sendRobotPoseCollection)
    00246   {
    00247     //STREAMMARKER(9);
    00248     stream << teamMessage.robotPoseCollection;
    00249   }
    00250
    00251   if (teamMessage.sendObstaclesModel)
    00252   {
    00253     //STREAMMARKER(10);
    00254     int boolReplacement;
    00255     teamMessage.obstaclesModel.angleToFreePartOfGoalWasDetermined[ObstaclesModel::opponentGoal] ? boolReplacement = 1 : boolReplacement = 0;
    00256     stream << boolReplacement
    00257       << teamMessage.obstaclesModel.widthOfFreePartOfGoal[ObstaclesModel::opponentGoal];
    00258   }
    00259
    00260   return stream;
    00261 }
    00262
    00263 void TeamMessage::read(In& stream,Vector2<double>& v)
    00264 {
    00265   short x,y;
    00266   stream >> x >> y;
    00267   // x = x ^ cryptWord;
    00268   // y = y ^ cryptWord;
    00269   v.x = x;
    00270   v.y = y;
    00271 }
    00272
    00273 void TeamMessage::read(In& stream,Pose2D& p)
    00274 {
    00275   read(stream,p.translation);
    00276   short rotation;
    00277   stream >> rotation;
    00278   p.rotation = rotation / 1000.0;
    00279 }
    00280
    00281 void TeamMessage::write(Out& stream,const Vector2<double>& v)
    00282 {
    00283   short x = short(v.x + 0.5),y = short(v.y + 0.5);
    00284   // x = x ^ cryptWord;
    00285   // y = y ^ cryptWord;
    00286   stream << x << y;
    00287 }
    00288
    00289 void TeamMessage::write(Out& stream,const Pose2D& p)
    00290 {
    00291   write(stream,p.translation);
    00292   stream << short(p.rotation * 1000 + 0.5);
    00293 }
    00294
    00295 long TeamMessage::getTimeStampInOwnTime() const
    00296 {
    00297   return(timeStamp - timeOffset);
    00298 }
    00299
    00300 long TeamMessage::getTimeInOwnTime(long time) const
    00301 {
    00302   return(time - timeOffset);
    00303 }
    00304
    00305 long TeamMessage::getTimeInRemoteTime(long time) const
    00306 {
    00307   return(time + timeOffset);
    00308 }
    00309