Fawkes API  Fawkes Development Version
main.cpp
1 
2 /***************************************************************************
3  * main.cpp - Fawkes RefBox Repeater
4  *
5  * Created: Wed Apr 09 09:46:29 2008
6  * Copyright 2006-2008 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #include <utils/system/argparser.h>
24 
25 #include "refbox_state_sender.h"
26 #include "refbox_state_writer.h"
27 #include "msl2007.h"
28 #ifdef HAVE_MSL2008
29 # include "msl2008.h"
30 #endif
31 #ifdef HAVE_MSL2010
32 # include "msl2010.h"
33 #endif
34 #include "spl.h"
35 
36 #include <vector>
37 #include <string>
38 #include <cstdlib>
39 #include <cstdio>
40 #include <cstring>
41 
42 using namespace fawkes;
43 
44 void
45 print_usage(const char *program_name)
46 {
47  printf("Usage: %s [-d] -l league -t team -g goal_color [hosts]\n"
48  " -d Turn on debug mode (prints to stdout)\n"
49  " -b Use blackboard writer instead of world info sender\n"
50  " -l league Define league, may be one of\n"
51  " midsize, msl2007, msl2008, msl2010, spl\n"
52  " -u Don't use multicast in msl2010\n"
53  " -t team Our team, either cyan or magenta\n"
54  " -g goal_color Our goal color, either blue or yellow\n"
55  " -p port UDP port to send to (default 2806)\n"
56  " -m addr Multicast address to send to (default 224.16.0.1)\n"
57  " -k key Encryption key (default AllemaniACs)\n"
58  " -i iv Encryption initialization vector (default AllemaniACs)\n"
59  " hosts The hosts of the robots; only when -b is used\n",
60  program_name);
61 }
62 
63 /** Config tool main.
64  * @param argc argument count
65  * @param argv arguments
66  */
67 int
68 main(int argc, char **argv)
69 {
70  ArgumentParser argp(argc, argv, "hdbul:t:g:p:m:k:i:");
71 
72  if ( argp.has_arg("h") ) {
73  print_usage(argv[0]);
74  exit(0);
75  }
76 
77  if ( ! argp.has_arg("l") ) {
78  printf("You must give a league name.\n\n");
79  print_usage(argv[0]);
80  exit(1);
81  }
82 
83  if ( ! argp.has_arg("t") ) {
84  printf("You must give our team color.\n\n");
85  print_usage(argv[0]);
86  exit(2);
87  }
88 
89  if ( ! argp.has_arg("g") ) {
90  printf("You must give our goal color.\n\n");
91  print_usage(argv[0]);
92  exit(3);
93  }
94 
97  const char *addr = "224.16.0.1";
98  const char *key = "AllemaniACs";
99  const char *iv = "AllemaniACs";
100  unsigned short int port = 2806;
101 
102  if ( strcmp(argp.arg("t"), "cyan") == 0 ) {
103  our_team = TEAM_CYAN;
104  } else if ( strcmp(argp.arg("t"), "magenta") == 0 ) {
105  our_team = TEAM_MAGENTA;
106  } else {
107  printf("Invalid team '%s', must be one of 'cyan' and 'magenta'.\n\n", argp.arg("t"));
108  print_usage(argv[0]);
109  exit(4);
110  }
111 
112  if ( strcmp(argp.arg("g"), "blue") == 0 ) {
113  our_goal = GOAL_BLUE;
114  } else if ( strcmp(argp.arg("g"), "yellow") == 0 ) {
115  our_goal = GOAL_YELLOW;
116  } else {
117  printf("Invalid goal '%s', must be one of 'blue' and 'yellow'.\n\n", argp.arg("g"));
118  print_usage(argv[0]);
119  exit(5);
120  }
121 
122  if ( argp.has_arg("m") ) {
123  addr = argp.arg("m");
124  }
125 
126  if ( argp.has_arg("k") ) {
127  key = argp.arg("k");
128  }
129 
130  if ( argp.has_arg("i") ) {
131  iv = argp.arg("i");
132  }
133 
134  if ( argp.has_arg("p") ) {
135  port = atoi(argp.arg("p"));
136  }
137 
138  printf("Sending to: %s:%u\n"
139  "Key: %s IV: %s\n", addr, port, key, iv);
140 
141  RefBoxStateSender *rss;
142  if ( argp.has_arg("b") ) {
143  std::vector<const char*> items = argp.items();
144  std::vector<std::string> hosts(items.begin(), items.end());
145  rss = new RefBoxStateBBWriter(hosts, argp.has_arg("d"));
146  } else {
147  rss = new RefBoxStateSender(addr, port, key, iv, argp.has_arg("d"));
148  }
149  rss->set_team_goal(our_team, our_goal);
150 
151  printf("League: %s\n", argp.arg("l"));
152  if ( strcmp(argp.arg("l"), "msl2007") == 0 || strcmp(argp.arg("l"), "midsize") == 0 ) {
153  MidsizeRefBoxRepeater mrr(*rss, "127.0.0.1", 28097);
154  mrr.run();
155 #ifdef HAVE_MSL2008
156  } else if ( strcmp(argp.arg("l"), "msl2008") == 0 ) {
157  Msl2008RefBoxRepeater m8rr(*rss, "230.0.0.1", 30000);
158  m8rr.run();
159 #endif
160 #ifdef HAVE_MSL2010
161  } else if ( strcmp(argp.arg("l"), "msl2010") == 0 ) {
162  if ( argp.has_arg("u") ) {
163  //Msl2010RefBoxRepeater m10rr(*rss, "127.0.0.1", port, false);
164  Msl2010RefBoxRepeater m10rr(*rss, "127.0.0.1", 30010, false);
165  m10rr.run();
166  }
167  else {
168  //Msl2010RefBoxRepeater m10rr(*rss, addr, port);
169  Msl2010RefBoxRepeater m10rr(*rss, "230.0.0.1", 30000);
170  //Msl2010RefBoxRepeater m10rr(*rss, "230.0.0.1", 30010);
171  m10rr.run();
172  }
173 #endif
174  } else if ( strcmp(argp.arg("l"), "spl") == 0 ) {
175  SplRefBoxRepeater nrr(*rss, "255.255.255.0", 3838, our_team, our_goal);
176  nrr.run();
177  } else {
178  printf("Invalid league name given.\n\n");
179  print_usage(argv[0]);
180  exit(2);
181  }
182 
183  return 0;
184 }
SPL league refbox repeater.
Definition: spl.h:68
Blue goal.
Definition: enums.h:64
Mid-size league refbox repeater.
Definition: msl2010.h:43
RefBox repeater state sender.
Mid-size league refbox repeater.
Definition: msl2007.h:33
Fawkes library namespace.
Parse command line arguments.
Definition: argparser.h:66
Mid-size league refbox repeater.
Definition: msl2008.h:41
Yellow goal.
Definition: enums.h:65
Magenta team.
Definition: enums.h:57
RefBox repeater state writer.
Cyan team.
Definition: enums.h:56
worldinfo_gamestate_team_t
Team.
Definition: enums.h:54
worldinfo_gamestate_goalcolor_t
Goal color.
Definition: enums.h:63