-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.cpp
More file actions
88 lines (67 loc) · 3.23 KB
/
main.cpp
File metadata and controls
88 lines (67 loc) · 3.23 KB
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
#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("../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();
/// 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);
/// Set team
refView->setTeams(constants->getLeftTeamName(), constants->getLeftTeamColor(), constants->getRightTeamName(), constants->getRightTeamColor());
/// 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;
}