-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
178 lines (163 loc) · 5.81 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/***
* Maracatronics Robotics
* Federal University of Pernambuco (UFPE) at Recife
* http://www.maracatronics.com/
*
* This file is part of Armorial project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include <iostream>
#include <QCoreApplication>
#include <suassuna.h>
#include <exithandler.h>
#include <instancechecker.h>
#include <const/constants.h>
#include <utils/fieldside/fieldside.hh>
#include <utils/fields/wrfields.hh>
Competitions::Competition validateCategory(const QString &input, bool *valid) {
*valid = true;
if(input.toLower()=="ssl")
return Competitions::SSL;
else if(input.toLower()=="vss")
return Competitions::VSS;
else {
*valid = false;
return Competitions::SSL; // return default
}
}
Colors::Color validateTeamColor(const QString &input, bool *valid) {
*valid = true;
if(input.toLower()=="yellow")
return Colors::YELLOW;
else if(input.toLower()=="blue")
return Colors::BLUE;
else {
*valid = false;
return Colors::YELLOW; // return default
}
}
FieldSide validateFieldSide(const QString &input, bool *valid) {
*valid = true;
if(input.toLower()=="right")
return Sides::RIGHT;
else if(input.toLower()=="left")
return Sides::LEFT;
else {
*valid = false;
return Sides::RIGHT; // return default
}
}
bool validateEnableGUI(const QString &input, bool *valid) {
*valid = true;
if(input.toLower()=="true")
return true;
else if(input.toLower()=="false")
return false;
else {
*valid = false;
return true; // return default
}
}
bool validatePlayingAgainstWarthog(const QString &input, bool *valid) {
*valid = true;
if(input.toLower()=="true")
return true;
else if(input.toLower()=="false")
return false;
else {
*valid = false;
return true; // return default
}
}
int main(int argc, char *argv[]) {
QCoreApplication app(argc, argv);
app.setApplicationName("Armorial Suassuna");
app.setApplicationVersion("1.0.0");
// Duplicated instance checking
InstanceChecker::waitIfDuplicated(app.applicationName());
// Command line parser, get arguments
QCommandLineParser parser;
parser.setApplicationDescription("Suassuna application help.");
parser.addHelpOption();
parser.addVersionOption();
parser.addPositionalArgument("teamColor", "Sets the team color ('yellow' or 'blue', default='yellow').");
parser.addPositionalArgument("fieldSide", "Sets the field side ('right' or 'left', default='right').");
parser.addPositionalArgument("enableGUI", "Enable or disable the GUI ('true' or 'false', default='true').");
parser.addPositionalArgument("playingAgainstWarthog", "Set playing against warthog ('true' or 'false', default='false'.");
parser.process(app);
QStringList args = parser.positionalArguments();
// Suassuna parameters (with default values)
Colors::Color ourTeamColor = Colors::YELLOW;
FieldSide ourFieldSide = Sides::RIGHT;
bool enableGUI = true;
bool playingAgainstWarthog = false;
// Check arguments
// Category
// Team color
if(args.size() >= 1) {
bool valid;
ourTeamColor = validateTeamColor(args.at(0), &valid);
if(valid==false) {
std::cout << ">> Armorial Suassuna: Invalid team color argument '" << args.at(0).toStdString() << "'.\n>> Please check help below.\n\n";
parser.showHelp();
return EXIT_FAILURE;
}
}
// Field side
if(args.size() >= 2) {
bool valid;
ourFieldSide = validateFieldSide(args.at(1), &valid);
if(valid==false) {
std::cout << ">> Armorial Suassuna: Invalid field side argument '" << args.at(1).toStdString() << "'.\n>> Please check help below.\n\n";
parser.showHelp();
return EXIT_FAILURE;
}
}
// Enable GUI
if(args.size() >= 3) {
bool valid;
enableGUI = validateEnableGUI(args.at(2), &valid);
if(valid==false) {
std::cout << ">> Armorial Suassuna: Invalid enable GUI argument '" << args.at(2).toStdString() << "'.\n>> Please check help below.\n\n";
parser.showHelp();
return EXIT_FAILURE;
}
}
// Playing against Warthog
if(args.size() >= 4) {
bool valid;
playingAgainstWarthog = validatePlayingAgainstWarthog(args.at(3), &valid);
if(valid==false) {
std::cout << ">> Armorial Suassuna: Invalid playing against warthog argument '" << args.at(3).toStdString() << "'.\n>> Please check help below.\n\n";
parser.showHelp();
return EXIT_FAILURE;
}
}
quint8 ourTeamId = (ourTeamColor == Colors::YELLOW) ? 0 : 1;
if(playingAgainstWarthog) ourTeamId = 1;
// Setup ExitHandler
ExitHandler::setApplication(&app);
ExitHandler::setup();
// Setup constants
MRCConstants *mrcconstants = new MRCConstants("../const/config.json", false);
// Create and start Suassuna
Suassuna suassuna(ourTeamId, ourTeamColor, ourFieldSide, enableGUI, mrcconstants);
suassuna.start();
// Block main thread
bool retn = app.exec();
// Stop Suassuna
suassuna.stop();
return retn;
}