Fawkes API Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * main.cpp - Fawkes RefBox Repeater 00004 * 00005 * Created: Wed Apr 09 09:46:29 2008 00006 * Copyright 2006-2008 Tim Niemueller [www.niemueller.de] 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU Library General Public License for more details. 00019 * 00020 * Read the full text in the LICENSE.GPL file in the doc directory. 00021 */ 00022 00023 #include <utils/system/argparser.h> 00024 00025 #include "refbox_state_sender.h" 00026 #include "refbox_state_writer.h" 00027 #include "msl2007.h" 00028 #include "msl2008.h" 00029 #include "msl2010.h" 00030 #include "spl.h" 00031 00032 #include <vector> 00033 #include <string> 00034 #include <cstdlib> 00035 #include <cstdio> 00036 #include <cstring> 00037 00038 using namespace fawkes; 00039 00040 void 00041 print_usage(const char *program_name) 00042 { 00043 printf("Usage: %s [-d] -l league -t team -g goal_color [hosts]\n" 00044 " -d Turn on debug mode (prints to stdout)\n" 00045 " -b Use blackboard writer instead of world info sender\n" 00046 " -l league Define league, may be one of\n" 00047 " midsize, msl2007, msl2008, msl2010, spl\n" 00048 " -u Don't use multicast in msl2010\n" 00049 " -t team Our team, either cyan or magenta\n" 00050 " -g goal_color Our goal color, either blue or yellow\n" 00051 " -p port UDP port to send to (default 2806)\n" 00052 " -m addr Multicast address to send to (default 224.16.0.1)\n" 00053 " -k key Encryption key (default AllemaniACs)\n" 00054 " -i iv Encryption initialization vector (default AllemaniACs)\n" 00055 " hosts The hosts of the robots; only when -b is used\n", 00056 program_name); 00057 } 00058 00059 /** Config tool main. 00060 * @param argc argument count 00061 * @param argv arguments 00062 */ 00063 int 00064 main(int argc, char **argv) 00065 { 00066 ArgumentParser argp(argc, argv, "hdbul:t:g:p:m:k:i:"); 00067 00068 if ( argp.has_arg("h") ) { 00069 print_usage(argv[0]); 00070 exit(0); 00071 } 00072 00073 if ( ! argp.has_arg("l") ) { 00074 printf("You must give a league name.\n\n"); 00075 print_usage(argv[0]); 00076 exit(1); 00077 } 00078 00079 if ( ! argp.has_arg("t") ) { 00080 printf("You must give our team color.\n\n"); 00081 print_usage(argv[0]); 00082 exit(2); 00083 } 00084 00085 if ( ! argp.has_arg("g") ) { 00086 printf("You must give our goal color.\n\n"); 00087 print_usage(argv[0]); 00088 exit(3); 00089 } 00090 00091 worldinfo_gamestate_team_t our_team; 00092 worldinfo_gamestate_goalcolor_t our_goal; 00093 const char *addr = "224.16.0.1"; 00094 const char *key = "AllemaniACs"; 00095 const char *iv = "AllemaniACs"; 00096 unsigned short int port = 2806; 00097 00098 if ( strcmp(argp.arg("t"), "cyan") == 0 ) { 00099 our_team = TEAM_CYAN; 00100 } else if ( strcmp(argp.arg("t"), "magenta") == 0 ) { 00101 our_team = TEAM_MAGENTA; 00102 } else { 00103 printf("Invalid team '%s', must be one of 'cyan' and 'magenta'.\n\n", argp.arg("t")); 00104 print_usage(argv[0]); 00105 exit(4); 00106 } 00107 00108 if ( strcmp(argp.arg("g"), "blue") == 0 ) { 00109 our_goal = GOAL_BLUE; 00110 } else if ( strcmp(argp.arg("g"), "yellow") == 0 ) { 00111 our_goal = GOAL_YELLOW; 00112 } else { 00113 printf("Invalid goal '%s', must be one of 'blue' and 'yellow'.\n\n", argp.arg("g")); 00114 print_usage(argv[0]); 00115 exit(5); 00116 } 00117 00118 if ( argp.has_arg("m") ) { 00119 addr = argp.arg("m"); 00120 } 00121 00122 if ( argp.has_arg("k") ) { 00123 key = argp.arg("k"); 00124 } 00125 00126 if ( argp.has_arg("i") ) { 00127 iv = argp.arg("i"); 00128 } 00129 00130 if ( argp.has_arg("p") ) { 00131 port = atoi(argp.arg("p")); 00132 } 00133 00134 printf("Sending to: %s:%u\n" 00135 "Key: %s IV: %s\n", addr, port, key, iv); 00136 00137 RefBoxStateSender *rss; 00138 if ( argp.has_arg("b") ) { 00139 std::vector<const char*> items = argp.items(); 00140 std::vector<std::string> hosts(items.begin(), items.end()); 00141 rss = new RefBoxStateBBWriter(hosts, argp.has_arg("d")); 00142 } else { 00143 rss = new RefBoxStateSender(addr, port, key, iv, argp.has_arg("d")); 00144 } 00145 rss->set_team_goal(our_team, our_goal); 00146 00147 printf("League: %s\n", argp.arg("l")); 00148 if ( strcmp(argp.arg("l"), "msl2007") == 0 || strcmp(argp.arg("l"), "midsize") == 0 ) { 00149 MidsizeRefBoxRepeater mrr(*rss, "127.0.0.1", 28097); 00150 mrr.run(); 00151 } else if ( strcmp(argp.arg("l"), "msl2008") == 0 ) { 00152 Msl2008RefBoxRepeater m8rr(*rss, "230.0.0.1", 30000); 00153 m8rr.run(); 00154 } else if ( strcmp(argp.arg("l"), "msl2010") == 0 ) { 00155 if ( argp.has_arg("u") ) { 00156 //Msl2010RefBoxRepeater m10rr(*rss, "127.0.0.1", port, false); 00157 Msl2010RefBoxRepeater m10rr(*rss, "127.0.0.1", 30010, false); 00158 m10rr.run(); 00159 } 00160 else { 00161 //Msl2010RefBoxRepeater m10rr(*rss, addr, port); 00162 Msl2010RefBoxRepeater m10rr(*rss, "230.0.0.1", 30000); 00163 //Msl2010RefBoxRepeater m10rr(*rss, "230.0.0.1", 30010); 00164 m10rr.run(); 00165 } 00166 } else if ( strcmp(argp.arg("l"), "spl") == 0 ) { 00167 SplRefBoxRepeater nrr(*rss, "255.255.255.0", 3838, our_team, our_goal); 00168 nrr.run(); 00169 } else { 00170 printf("Invalid league name given.\n\n"); 00171 print_usage(argv[0]); 00172 exit(2); 00173 } 00174 00175 return 0; 00176 }