Beispiel #1
0
  /**
   * Receives a packet from the GameController.
   * Packets are only accepted when the team number is know (nonzero) and
   * they are addressed to this team.
   */
  bool receive()
  {
    bool received = false;
    int size;
    RoboCupGameControlData buffer;
    struct sockaddr_in from;
    while(udp && (size = udp->read((char*) &buffer, sizeof(buffer), from)) > 0)
    {
      if(size == sizeof(buffer) &&
         !std::memcmp(&buffer, GAMECONTROLLER_STRUCT_HEADER, 4) &&
         buffer.version == GAMECONTROLLER_STRUCT_VERSION &&
         teamNumber &&
         (buffer.teams[0].teamNumber == teamNumber ||
          buffer.teams[1].teamNumber == teamNumber))
      {
        gameCtrlData = buffer;
        if(memcmp(&gameControllerAddress, &from.sin_addr, sizeof(in_addr)))
        {
          memcpy(&gameControllerAddress, &from.sin_addr, sizeof(in_addr));
          udp->setTarget(inet_ntoa(gameControllerAddress), GAMECONTROLLER_RETURN_PORT);
        }

        received = true;
      }
    }
    return received;
  }
 /**
  * Receives a packet from the GameController.
  * Packets are only accepted when the team number is know (nonzero) and
  * they are addressed to this team.
  */
 bool receive()
 {
   bool received = false;
   int size;
   RoboCupGameControlData buffer;
   while(udp && (size = udp->read((char*) &buffer, sizeof(buffer))) > 0)
   {
     if(size == sizeof(buffer) &&
        !std::memcmp(&buffer, GAMECONTROLLER_STRUCT_HEADER, 4) &&
        buffer.version == GAMECONTROLLER_STRUCT_VERSION &&
        teamNumber &&
        (buffer.teams[0].teamNumber == teamNumber ||
         buffer.teams[1].teamNumber == teamNumber))
     {
       gameCtrlData = buffer;
       received = true;
     }
   }
   return received;
 }