forked from tsb4/VSSReferee
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
108 lines (84 loc) · 4.18 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
#include <QApplication>
#include <src/entity/vssvisionclient/vssvisionclient.h>
#include <src/entity/vssreferee/vssreferee.h>
#include <src/entity/vssreplacer/vssreplacer.h>
#include <src/entity/refereeview/refereeview.h>
#include <constants/constants.h>
#include <exithandler.h>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
/// Creating constants pointer
Constants* constants = new Constants(QString(PROJECT_PATH) + "/constants/constants.json");
Utils::setConstants(constants);
/// Parsing from constants
// Vision
QString visionAddress = constants->getVisionAddress();
int visionPort = constants->getVisionPort();
// Referee
QString refereeAddress = constants->getRefereeAddress();
int refereePort = constants->getRefereePort();
// Replacer
QString replacerAddress = constants->getReplacerAddress();
int replacerPort = constants->getReplacerPort();
// FiraSim
QString firaSimAddress = constants->getFiraSimAddress();
int firaSimPort = constants->getFiraSimPort();
/// Setup ExitHandler
ExitHandler::setApplication(&a);
ExitHandler::setup();
/// Create modules
VSSVisionClient *vssVisionClient = new VSSVisionClient(visionAddress, visionPort);
VSSReferee *vssReferee = new VSSReferee(vssVisionClient, refereeAddress, refereePort, constants);
VSSReplacer *vssReplacer = new VSSReplacer(replacerAddress, replacerPort, firaSimAddress, firaSimPort, constants);
RefereeView *refView = new RefereeView(constants);
/// Make connections with signals and slots
// Foul connetion
QObject::connect(vssReferee, SIGNAL(setFoul(VSSRef::Foul, VSSRef::Color, VSSRef::Quadrant)), vssReplacer, SLOT(takeFoul(VSSRef::Foul, VSSRef::Color, VSSRef::Quadrant)), Qt::DirectConnection);
QObject::connect(vssReferee, SIGNAL(stopReplacerWaiting()), vssReplacer, SLOT(stopWaiting()), Qt::DirectConnection);
QObject::connect(vssReplacer, SIGNAL(teamPlaced(VSSRef::Color)), vssReferee, SLOT(teamSent(VSSRef::Color)), Qt::DirectConnection);
// Half connection
//QObject::connect(vssReferee, SIGNAL(halfPassed()), refView->getUI(), SLOT(switchSides()), Qt::DirectConnection);
// Goalie connection
QObject::connect(vssReferee, SIGNAL(sendGoalie(VSSRef::Color, int)), vssReplacer, SLOT(takeGoalie(VSSRef::Color, int)), Qt::DirectConnection);
QObject::connect(vssReplacer, SIGNAL(requestGoalie(VSSRef::Color)), vssReferee, SLOT(requestGoalie(VSSRef::Color)), Qt::DirectConnection);
// Goal connection
QObject::connect(vssReferee, SIGNAL(goalMarked(VSSRef::Color)), refView->getUI(), SLOT(addGoal(VSSRef::Color)), Qt::DirectConnection);
// Manual referee connection
QObject::connect(refView->getUI(), SIGNAL(sendManualCommand(VSSRef::Foul, VSSRef::Color, VSSRef::Quadrant)), vssReferee, SLOT(takeManualCommand(VSSRef::Foul, VSSRef::Color, VSSRef::Quadrant)));
QObject::connect(refView->getUI(), SIGNAL(resetAll()), vssReferee, SLOT(resetAll()));
/// Set team
// Command line parser, get arguments
QCommandLineParser parser;
parser.setApplicationDescription("VSSReferee application help.");
parser.addHelpOption();
parser.addVersionOption();
parser.addPositionalArgument("teamBlueName", "Sets the team blue name");
parser.addPositionalArgument("teamYellowName", "Sets the team yellow name");
parser.process(a);
QStringList args = parser.positionalArguments();
// Setting default (by json)
refView->setTeams(constants->getLeftTeamName(), constants->getLeftTeamColor(), constants->getRightTeamName(), constants->getRightTeamColor());
// Setting by args
if(args.size() >= 2){
refView->setTeams(args.at(0), VSSRef::Color::BLUE, args.at(1), VSSRef::Color::YELLOW);
}
/// Start all
vssVisionClient->start();
vssReferee->start();
vssReplacer->start();
refView->start();
/// Run app
bool exec = a.exec();
/// Stop modules
vssVisionClient->terminate();
vssReferee->terminate();
vssReplacer->terminate();
refView->terminate();
/// Wait for modules sync
vssVisionClient->wait();
vssReferee->wait();
vssReplacer->wait();
refView->wait();
return exec;
}