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 #ifdef HAVE_MSL2008 00029 # include "msl2008.h" 00030 #endif 00031 #ifdef HAVE_MSL2010 00032 # include "msl2010.h" 00033 #endif 00034 #include "spl.h" 00035 00036 #include <vector> 00037 #include <string> 00038 #include <cstdlib> 00039 #include <cstdio> 00040 #include <cstring> 00041 00042 using namespace fawkes; 00043 00044 void 00045 print_usage(const char *program_name) 00046 { 00047 printf("Usage: %s [-d] -l league -t team -g goal_color [hosts]\n" 00048 " -d Turn on debug mode (prints to stdout)\n" 00049 " -b Use blackboard writer instead of world info sender\n" 00050 " -l league Define league, may be one of\n" 00051 " midsize, msl2007, msl2008, msl2010, spl\n" 00052 " -u Don't use multicast in msl2010\n" 00053 " -t team Our team, either cyan or magenta\n" 00054 " -g goal_color Our goal color, either blue or yellow\n" 00055 " -p port UDP port to send to (default 2806)\n" 00056 " -m addr Multicast address to send to (default 224.16.0.1)\n" 00057 " -k key Encryption key (default AllemaniACs)\n" 00058 " -i iv Encryption initialization vector (default AllemaniACs)\n" 00059 " hosts The hosts of the robots; only when -b is used\n", 00060 program_name); 00061 } 00062 00063 /** Config tool main. 00064 * @param argc argument count 00065 * @param argv arguments 00066 */ 00067 int 00068 main(int argc, char **argv) 00069 { 00070 ArgumentParser argp(argc, argv, "hdbul:t:g:p:m:k:i:"); 00071 00072 if ( argp.has_arg("h") ) { 00073 print_usage(argv[0]); 00074 exit(0); 00075 } 00076 00077 if ( ! argp.has_arg("l") ) { 00078 printf("You must give a league name.\n\n"); 00079 print_usage(argv[0]); 00080 exit(1); 00081 } 00082 00083 if ( ! argp.has_arg("t") ) { 00084 printf("You must give our team color.\n\n"); 00085 print_usage(argv[0]); 00086 exit(2); 00087 } 00088 00089 if ( ! argp.has_arg("g") ) { 00090 printf("You must give our goal color.\n\n"); 00091 print_usage(argv[0]); 00092 exit(3); 00093 } 00094 00095 worldinfo_gamestate_team_t our_team; 00096 worldinfo_gamestate_goalcolor_t our_goal; 00097 const char *addr = "224.16.0.1"; 00098 const char *key = "AllemaniACs"; 00099 const char *iv = "AllemaniACs"; 00100 unsigned short int port = 2806; 00101 00102 if ( strcmp(argp.arg("t"), "cyan") == 0 ) { 00103 our_team = TEAM_CYAN; 00104 } else if ( strcmp(argp.arg("t"), "magenta") == 0 ) { 00105 our_team = TEAM_MAGENTA; 00106 } else { 00107 printf("Invalid team '%s', must be one of 'cyan' and 'magenta'.\n\n", argp.arg("t")); 00108 print_usage(argv[0]); 00109 exit(4); 00110 } 00111 00112 if ( strcmp(argp.arg("g"), "blue") == 0 ) { 00113 our_goal = GOAL_BLUE; 00114 } else if ( strcmp(argp.arg("g"), "yellow") == 0 ) { 00115 our_goal = GOAL_YELLOW; 00116 } else { 00117 printf("Invalid goal '%s', must be one of 'blue' and 'yellow'.\n\n", argp.arg("g")); 00118 print_usage(argv[0]); 00119 exit(5); 00120 } 00121 00122 if ( argp.has_arg("m") ) { 00123 addr = argp.arg("m"); 00124 } 00125 00126 if ( argp.has_arg("k") ) { 00127 key = argp.arg("k"); 00128 } 00129 00130 if ( argp.has_arg("i") ) { 00131 iv = argp.arg("i"); 00132 } 00133 00134 if ( argp.has_arg("p") ) { 00135 port = atoi(argp.arg("p")); 00136 } 00137 00138 printf("Sending to: %s:%u\n" 00139 "Key: %s IV: %s\n", addr, port, key, iv); 00140 00141 RefBoxStateSender *rss; 00142 if ( argp.has_arg("b") ) { 00143 std::vector<const char*> items = argp.items(); 00144 std::vector<std::string> hosts(items.begin(), items.end()); 00145 rss = new RefBoxStateBBWriter(hosts, argp.has_arg("d")); 00146 } else { 00147 rss = new RefBoxStateSender(addr, port, key, iv, argp.has_arg("d")); 00148 } 00149 rss->set_team_goal(our_team, our_goal); 00150 00151 printf("League: %s\n", argp.arg("l")); 00152 if ( strcmp(argp.arg("l"), "msl2007") == 0 || strcmp(argp.arg("l"), "midsize") == 0 ) { 00153 MidsizeRefBoxRepeater mrr(*rss, "127.0.0.1", 28097); 00154 mrr.run(); 00155 #ifdef HAVE_MSL2008 00156 } else if ( strcmp(argp.arg("l"), "msl2008") == 0 ) { 00157 Msl2008RefBoxRepeater m8rr(*rss, "230.0.0.1", 30000); 00158 m8rr.run(); 00159 #endif 00160 #ifdef HAVE_MSL2010 00161 } else if ( strcmp(argp.arg("l"), "msl2010") == 0 ) { 00162 if ( argp.has_arg("u") ) { 00163 //Msl2010RefBoxRepeater m10rr(*rss, "127.0.0.1", port, false); 00164 Msl2010RefBoxRepeater m10rr(*rss, "127.0.0.1", 30010, false); 00165 m10rr.run(); 00166 } 00167 else { 00168 //Msl2010RefBoxRepeater m10rr(*rss, addr, port); 00169 Msl2010RefBoxRepeater m10rr(*rss, "230.0.0.1", 30000); 00170 //Msl2010RefBoxRepeater m10rr(*rss, "230.0.0.1", 30010); 00171 m10rr.run(); 00172 } 00173 #endif 00174 } else if ( strcmp(argp.arg("l"), "spl") == 0 ) { 00175 SplRefBoxRepeater nrr(*rss, "255.255.255.0", 3838, our_team, our_goal); 00176 nrr.run(); 00177 } else { 00178 printf("Invalid league name given.\n\n"); 00179 print_usage(argv[0]); 00180 exit(2); 00181 } 00182 00183 return 0; 00184 }