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 
00014 bool TeamMessage::isActual() const
00015 {
00016   return SystemCall::getTimeSince(lastReceivedTimeStamp) < 2000;
00017 }
00018 
00019 In& operator>>(In& stream,TeamMessage& teamMessage)
00020 {
00021   stream >> teamMessage.timeStamp >> 
00022     teamMessage.lastReceivedTimeStamp >>
00023     teamMessage.incomingTimeStamp;
00024   char c;
00025   stream >> c;
00026   teamMessage.playerNumberOfSender = (Player::playerNumber)c;
00027   
00028   char fieldsInMessage;
00029   stream >> fieldsInMessage;
00030   teamMessage.sendRobotPose = ((fieldsInMessage & 1) == 1);
00031   teamMessage.sendSeenBallPosition = ((fieldsInMessage & 2) == 2);
00032   teamMessage.sendBehaviorTeamMessage = ((fieldsInMessage & 4) == 4);
00033   
00034   // robot pose
00035   if (teamMessage.sendRobotPose) 
00036   {
00037     TeamMessage::read(stream,teamMessage.robotPose);
00038     stream >> c;
00039     teamMessage.robotPose.setValidity(c / 100.0);
00040   }
00041   
00042   if (teamMessage.sendSeenBallPosition) 
00043   {
00044     stream.read(&teamMessage.seenBallPosition,sizeof(SeenBallPosition));
00045   }
00046   
00047   if (teamMessage.sendBehaviorTeamMessage) 
00048   {
00049     stream >> teamMessage.behaviorTeamMessage;
00050   }
00051     
00052   stream >> c;
00053   teamMessage.playerNumberOfSender = (Player::playerNumber)c;
00054   
00055   return stream;
00056 }
00057 
00058 Out& operator<<(Out& stream,const TeamMessage& teamMessage)
00059 {
00060   stream << teamMessage.timeStamp << teamMessage.lastReceivedTimeStamp 
00061     << teamMessage.incomingTimeStamp;
00062   stream << (char)getPlayer().getPlayerNumber();
00063   
00064   // a bitfield which tells the receiver what fields are transmitted
00065   char fieldsInMessage = 
00066     teamMessage.sendRobotPose  
00067     + (teamMessage.sendSeenBallPosition << 1)
00068     + (teamMessage.sendBehaviorTeamMessage << 2);
00069   
00070   stream << fieldsInMessage;
00071   
00072   // robot pose
00073   if (teamMessage.sendRobotPose) {
00074     TeamMessage::write(stream,teamMessage.robotPose);
00075     stream << char(teamMessage.robotPose.getValidity() * 100.0 + 0.5);
00076   }
00077   
00078   if (teamMessage.sendBehaviorTeamMessage) 
00079   {
00080     stream.write(&teamMessage.seenBallPosition, sizeof(SeenBallPosition));
00081   }
00082   
00083   // BehaviorTeamMessage
00084   if (teamMessage.sendBehaviorTeamMessage) {
00085     stream << teamMessage.behaviorTeamMessage;
00086   }
00087   
00088 
00089   stream << (char) getPlayer().getPlayerNumber();
00090   return stream;
00091 }
00092 
00093 void TeamMessage::read(In& stream,Vector2<double>& v)
00094 {
00095   short x,y;
00096   stream >> x >> y;
00097   v.x = x; 
00098   v.y = y;
00099 }
00100 
00101 void TeamMessage::read(In& stream,Pose2D& p)
00102 {
00103   read(stream,p.translation);
00104   short rotation;
00105   stream >> rotation;
00106   p.rotation = rotation / 1000.0;
00107 }
00108 
00109 void TeamMessage::write(Out& stream,const Vector2<double>& v)
00110 {
00111   stream << short(v.x + 0.5) << short(v.y + 0.5);
00112 }
00113 
00114 void TeamMessage::write(Out& stream,const Pose2D& p)
00115 {
00116   write(stream,p.translation);
00117   stream << short(p.rotation * 1000 + 0.5);
00118 }
00119 
00120 long TeamMessage::getTimeStampInOwnTime() const
00121 {
00122   return(timeStamp - timeOffset);
00123 }
00124 
00125 long TeamMessage::getTimeInOwnTime(long time) const
00126 {
00127   return(time - timeOffset);
00128 }
00129 
00130 long TeamMessage::getTimeInRemoteTime(long time) const
00131 {
00132   return(time + timeOffset);
00133 }
00134 
00135 /*
00136 * Change log :
00137 * 
00138 * $Log: TeamMessage.cpp,v $
00139 * Revision 1.1.1.1  2004/05/22 17:26:05  cvsadm
00140 * created new repository GT2004_WM
00141 *
00142 * Revision 1.2  2003/12/06 17:45:33  loetzsch
00143 * replaced Player::playerRole (goalie, defender, striker1, striker2)
00144 * by Player::playerNumber (one, two, three, four)
00145 *
00146 * Revision 1.1  2003/10/07 10:09:36  cvsadm
00147 * Created GT2004 (M.J.)
00148 *
00149 * Revision 1.3  2003/09/26 15:27:27  juengel
00150 * Renamed DataTypes to representations.
00151 *
00152 * Revision 1.2  2003/07/02 19:14:23  loetzsch
00153 * bug fixes, removed unused functions
00154 *
00155 * Revision 1.1.1.1  2003/07/02 09:40:23  cvsadm
00156 * created new repository for the competitions in Padova from the 
00157 * tamara CVS (Tuesday 2:00 pm)
00158 *
00159 * removed unused solutions
00160 *
00161 * Revision 1.8  2003/05/02 12:57:13  loetzsch
00162 * TeamMessage now contains a SeenBallPosition instead of a BallPercept
00163 *
00164 * Revision 1.7  2003/04/19 03:29:09  pruente
00165 * Merged in changes by Michael: - send right playerRole
00166 *
00167 * Revision 1.6  2003/03/24 12:17:24  wachter
00168 * fixed isActual so that it works like in revision 1.3
00169 * ( returns false if the last message is older than 2000 ms)
00170 *
00171 * Revision 1.5  2003/02/28 17:02:55  wachter
00172 * Reenabled trainer-syncronisation for RuhrpottHellhound-Behavior
00173 *
00174 * Revision 1.4  2003/02/18 13:24:37  wachter
00175 * added new TeamMessageCollection and TeamMessage
00176 *
00177 * Revision 1.3  2002/09/22 18:40:51  risler
00178 * added new math functions, removed GTMath library
00179 *
00180 * Revision 1.2  2002/09/17 23:55:20  loetzsch
00181 * - unraveled several datatypes
00182 * - changed the WATCH macro
00183 * - completed the process restructuring
00184 *
00185 * Revision 1.1  2002/09/10 15:26:41  cvsadm
00186 * Created new project GT2003 (M.L.)
00187 * - Cleaned up the /Src/DataTypes directory
00188 * - Removed Challenge Code
00189 * - Removed processing of incoming audio data
00190 * - Renamed AcousticMessage to SoundRequest
00191 *
00192 * Revision 1.5  2002/06/09 15:24:51  loetzsch
00193 * Added TeamMessageCollection and BehaviorTeamMessage to the execute of BehaviorControl
00194 *
00195 * Revision 1.4  2002/06/08 09:26:32  Thomas Röfer
00196 * Team ball position, first draft
00197 *
00198 * Revision 1.3  2002/06/06 16:10:46  roefer
00199 * Robot pose and ball percept added
00200 *
00201 * Revision 1.2  2002/05/26 14:55:25  roefer
00202 * Team communication is working
00203 *
00204 * Revision 1.1  2002/05/16 22:36:11  roefer
00205 * Team communication and GTMath bugs fixed
00206 *
00207 */

Generated on Thu Sep 23 19:57:37 2004 for GT2004 by doxygen 1.3.6