00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
00060
00061
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
00157 Msl2010RefBoxRepeater m10rr(*rss, "127.0.0.1", 30010, false);
00158 m10rr.run();
00159 }
00160 else {
00161
00162 Msl2010RefBoxRepeater m10rr(*rss, "230.0.0.1", 30000);
00163
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 }