-
Notifications
You must be signed in to change notification settings - Fork 15
/
StationController.cpp
149 lines (125 loc) · 3.41 KB
/
StationController.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
/***************************************************************************
* *
* Copyright (C) 2017 by University of Illinois *
* *
* http://illinois.edu *
* *
***************************************************************************/
/**
* @file StationController.h
*
* A Station object organizes drones and senders, communicates with Vicon and
* updates measurements for drones using a separate thread.
*
* A StationWindow is the main GUI.
*
* This is the Controller of the
* Model(Station)-View(StationWindow)-Controller(StationController) pattern.
*
* @author Bo Liu <[email protected]>
*
*/
#include "StationController.h"
StationController::StationController(std::unique_ptr<Station> &station, QObject *parent) :
QObject(parent),
station(station)
{
setupConnections();
initialize();
}
void StationController::setupConnections()
{
connect(station.get(), &Station::droneAdded,
this, &StationController::addDrone);
connect(station.get(), &Station::droneRemoved,
this, &StationController::removeDrone);
connect(station.get(), &Station::dtUpdated,
this, &StationController::dtUpdatedHandler);
connect(station.get(), &Station::ViconConnected,
this, &StationController::viconConnectedHandler);
connect(station.get(), &Station::ViconDisconnected,
this, &StationController::viconDisconnectedHandler);
connect(&dtUpdateTimer, SIGNAL(timeout()), this, SLOT(dtUpdatedHandler()));
}
void StationController::initialize()
{
dtUpdateTimer.start(500);
}
void StationController::connectVicon()
{
station->connectVicon();
}
void StationController::disconnectVicon()
{
station->disconnectVicon();
}
QHostAddress StationController::getHostAddress()
{
return station->getHostAddress();
}
void StationController::setHostAddress(QString ip)
{
station->setHostAddress(QHostAddress(ip));
}
quint16 StationController::getHostPort()
{
return station->getHostPort();
}
void StationController::setHostPort(quint16 hport)
{
station->setHostPort(hport);
}
std::vector<QString> StationController::getTrackingObjectNames()
{
std::vector<QString> names;
for (const auto& x : station->droneCollection)
{
names.push_back(x.getName());
}
return names;
}
QString StationController::getOriginGPS()
{
return station->getOriginGPS();
}
void StationController::setOriginGPS(const QString& q_gps)
{
station->setOriginGPS(q_gps);
}
void StationController::setNorth(const QString &axis)
{
station->setNorth(axis);
}
double StationController::getFrameRate()
{
return station->getRate();
}
double StationController::getdt()
{
return station->getdt();
}
std::unique_ptr<Station> &StationController::getStation()
{
return station;
}
void StationController::addDrone(QString name)
{
emit droneNameAdded(name);
}
void StationController::removeDrone(QString name)
{
emit droneNameRemoved(name);
}
void StationController::viconConnectedHandler()
{
emit viconConnected();
}
void StationController::viconDisconnectedHandler()
{
emit viconDisconnected();
}
void StationController::dtUpdatedHandler()
{
auto dt = station->getdt();
emit dtUpdated(dt);
}