Пример #1
0
bool Settings::load()
{
#ifdef TARGET_ROBOT
  robot = NaoBody().getName();
#else
  robot = "Nao";
#endif

  bool loadedSettingsFromFile = false;
#ifdef TARGET_ROBOT
  // load settings from team.cfg
  try
  {
    ConfigMap teams;
    if(teams.read("teams.cfg", false, &ConfigMap::printOnErr) >= 0)
    {
      teams.setFlags(teams.getFlags() | ConfigMap::READONLY);

      std::vector<std::string> keys = teams.getKeys();
      for(std::vector<std::string>::const_iterator i = keys.begin(), end = keys.end(); i != end; ++i)
      {
        const ConfigValue& teamValue = teams[*i];
        if(teamValue.getType() != ConfigValue::MAP)
          continue;
        const ConfigMap& team = teamValue;
        if(!team.hasKey("players"))
          continue;
        const ConfigValue& playersValue = team["players"];
        if(playersValue.getType() != ConfigValue::LIST)
          continue;

        const ListConfigValue& players = playersValue;
        for(int i = 0, len = players.length(); i < len; ++i)
        {
          const ConfigValue& playersValue = players[i];
          if(playersValue.getType() != ConfigValue::PLAIN)
            continue;
          if(((const PlainConfigValue&)playersValue).str() == robot)
          {
            playerNumber = i + 1;
            team["number"] >> teamNumber;
            teamPort = 10001 + teamNumber * 100;
            team["location"] >> location;
            std::string entryName;
            team["color"] >> entryName;
            if(entryName == "blue")
              teamColor = TEAM_BLUE;
            else if(entryName == "red")
              teamColor = TEAM_RED;
            else
              ASSERT(false);
            loadedSettingsFromFile = true;
            goto loadedTeamsCfg;
          }
        }
      }
loadedTeamsCfg:
      ;
    }
Пример #2
0
bool Settings::load()
{
  if(!Global::theStreamHandler)
  {
    static StreamHandler streamHandler;
    Global::theStreamHandler = &streamHandler;
  }

#ifdef TARGET_ROBOT
  headName = SystemCall::getHostName();

  std::string bhdir = File::getBHDir();
  InMapFile robotsStream(bhdir + "/Config/Robots/robots.cfg");
  if(!robotsStream.exists())
  {
    TRACE("Could not load robots.cfg");
    return false;
  }
  else
  {
    Robots robots;
    robotsStream >> robots;
    std::string bodyId = NaoBody().getBodyId();
    for(const Robots::RobotId& robot : robots.robotsIds)
    {
      if(robot.bodyId == bodyId)
      {
        bodyName = robot.name;
        break;
      }
    }
    if(bodyName.empty())
    {
      TRACE("Could not find bodyName in robots.cfg! BodyId: %s", bodyId.c_str());
      return false;
    }
  }
#else
  headName = "Nao";
  bodyName = "Nao";
#endif

  InMapFile stream("settings.cfg");
  if(stream.exists())
    stream >> *this;
  else
  {
Пример #3
0
bool Settings::load()
{
#ifdef TARGET_ROBOT
  robot = NaoBody().getName();
#else
  robot = "Nao";
#endif

  if(!Global::theStreamHandler)
  {
    static StreamHandler streamHandler;
    Global::theStreamHandler = &streamHandler;
  }

  InMapFile stream("settings.cfg");
  if(stream.exists())
    stream >> *this;
  else
  {