Skip to content

Commit a4e7bf0

Browse files
committed
transform to react to deviceAdded signal sent by deviceDiscovery
untested, but could discover both devices, regardless of order of appearance
1 parent ea763de commit a4e7bf0

3 files changed

Lines changed: 73 additions & 44 deletions

File tree

src/OpenCOVER/plugins/hlrs/TacxFTMS/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
USING(Pthreads)
22
using(VRML)
33

4-
if(APPLE)
5-
return()
6-
endif()
7-
84
SET(HEADERS
95
TacxFTMS.h
106
)

src/OpenCOVER/plugins/hlrs/TacxFTMS/TacxFTMS.cpp

Lines changed: 69 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ TacxFTMS::TacxFTMS()
4848
stepSizeDown = 2000;
4949

5050
coVRNavigationManager::instance()->registerNavigationProvider(this);
51+
52+
opencover::Input::instance()->discovery()->deviceAdded.connect(&TacxFTMS::addDevice, this);
5153
}
5254

5355
TacxFTMS::~TacxFTMS() {
@@ -77,22 +79,12 @@ bool TacxFTMS::init() {
7779

7880
MAKE_EULER_MAT(TacxFTMSPos, h, p, r);
7981
TacxFTMSPos.postMultTranslate(osg::Vec3(x, y, z));
80-
81-
82-
//const std::string host = configString("TacxFTMS", "severHost", "192.168.178.36")->value();
83-
unsigned short serverPortNeo = configInt("TacxFTMS", "serverPort", 31319)->value();
84-
unsigned short localPortNeo = configInt("TacxFTMS", "localPort", 31322)->value();
85-
86-
unsigned short serverPortAlpine = configInt("Alpine", "serverPort", 31319)->value();
87-
unsigned short localPortAlpine = configInt("Alpine", "localPort", 31328)->value();
8882

8983

9084
/*std::cerr << "TacxFTMS config: UDP: serverHost: " << host
9185
<< ", localPort: " << localPort << ", serverPort: " << serverPort
9286
<< std::endl;*/
93-
bool bothfound = false;
94-
bool ftmsfound = false;
95-
bool alpinefound = false;
87+
bool supportedDeviceFound = false;
9688

9789
bool ret = false;
9890

@@ -102,44 +94,82 @@ bool TacxFTMS::init() {
10294
opencover::Input::instance()->discovery()->getDevices()) {
10395
std::cerr << "Devicename found" << i->deviceName << std::endl;
10496
if (i->deviceName == "TacxNeo") {
105-
host = i->address;
106-
std::cerr << "TacxFTMS config: UDP: TacxHost: " << host
107-
<< std::endl;
108-
udpNeo = new UDPComm(host.c_str(), serverPortNeo, localPortNeo);
109-
if (!udpNeo->isBad()) {
110-
ftmsfound = true;
111-
start();
112-
} else {
113-
std::cerr << "TacxFTMS: failed to open local UDP port"
114-
<< localPortNeo << std::endl;
115-
ftmsfound = false;
116-
}
97+
supportedDeviceFound = true;
11798
}
118-
else if (i->deviceName == "Alpine") {
119-
host = i->address;
120-
std::cerr << "TacxFTMS config: UDP: AlpineHost: " << host
121-
<< std::endl;
122-
udpAlpine = new UDPComm(host.c_str(), serverPortAlpine, localPortAlpine);
123-
if (!udpAlpine->isBad()) {
124-
alpinefound = true;
125-
start();
126-
} else {
127-
std::cerr << "Alpine: failed to open local UDP port"
128-
<< localPortAlpine << std::endl;
129-
alpinefound = false;
130-
}
99+
else if (i->deviceName == "Alpine")
100+
{
101+
supportedDeviceFound = true;
131102
}
132103
}
133-
ret = ftmsfound || alpinefound;
104+
ret = supportedDeviceFound;
134105
coVRMSController::instance()->sendSlaves(&ret, sizeof(ret));
135-
} else {
106+
}
107+
else
108+
{
136109
coVRMSController::instance()->readMaster(&ret, sizeof(ret));
137-
}
110+
}
138111
std::cerr << "Init FTMS done";
139112

140113
return ret;
141114
}
142115

116+
void TacxFTMS::addDevice(const opencover::deviceInfo *i)
117+
{
118+
//const std::string host = configString("TacxFTMS", "severHost", "192.168.178.36")->value();
119+
unsigned short serverPortNeo = configInt("TacxFTMS", "serverPort", 31319)->value();
120+
unsigned short localPortNeo = configInt("TacxFTMS", "localPort", 31322)->value();
121+
122+
unsigned short serverPortAlpine = configInt("Alpine", "serverPort", 31319)->value();
123+
unsigned short localPortAlpine = configInt("Alpine", "localPort", 31328)->value();
124+
125+
126+
if (coVRMSController::instance()->isMaster())
127+
{
128+
std::string host = "";
129+
std::cerr << "Devicename found" << i->deviceName << std::endl;
130+
if (i->deviceName == "TacxNeo")
131+
{
132+
host = i->address;
133+
std::cerr << "TacxFTMS config: UDP: TacxHost: " << host << std::endl;
134+
udpNeo = new UDPComm(host.c_str(), serverPortNeo, localPortNeo);
135+
if (!udpNeo->isBad())
136+
{
137+
ftmsfound = true;
138+
start();
139+
}
140+
else
141+
{
142+
std::cerr << "TacxFTMS: failed to open local UDP port" << localPortNeo << std::endl;
143+
ftmsfound = false;
144+
}
145+
}
146+
else if (i->deviceName == "Alpine")
147+
{
148+
host = i->address;
149+
std::cerr << "TacxFTMS config: UDP: AlpineHost: " << host << std::endl;
150+
udpAlpine = new UDPComm(host.c_str(), serverPortAlpine, localPortAlpine);
151+
if (!udpAlpine->isBad())
152+
{
153+
alpinefound = true;
154+
start();
155+
}
156+
else
157+
{
158+
std::cerr << "Alpine: failed to open local UDP port" << localPortAlpine << std::endl;
159+
alpinefound = false;
160+
}
161+
}
162+
ret = ftmsfound || alpinefound;
163+
coVRMSController::instance()->sendSlaves(&ret, sizeof(ret));
164+
}
165+
else
166+
{
167+
coVRMSController::instance()->readMaster(&ret, sizeof(ret));
168+
}
169+
ftmsfound = coVRMSController::instance()->syncBool(ftmsfound);
170+
alpinefound = coVRMSController::instance()->syncBool(alpinefound);
171+
}
172+
143173
bool TacxFTMS::update() {
144174
if (isEnabled()) {
145175
if (coVRMSController::instance()->isMaster()) {

src/OpenCOVER/plugins/hlrs/TacxFTMS/TacxFTMS.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include <cover/coVRNavigationManager.h>
2020
#include <cover/coVRPlugin.h>
2121
#include <OpenThreads/Thread>
22-
22+
#include <cover/input/deviceDiscovery.h>
2323

2424

2525
#define MAX_CALLSIGN_LEN 8
@@ -69,11 +69,14 @@ class PLUGINEXPORT TacxFTMS : public opencover::coVRPlugin, public opencover::co
6969
bool doStop;
7070

7171
private:
72+
bool ftmsfound = false;
73+
bool alpinefound = false;
7274
float stepSizeUp;
7375
float stepSizeDown;
7476
const float BrakeThreshold = 1.0;
7577
bool braking = true;
7678
bool init();
79+
void addDevice(const opencover::deviceInfo *dev);
7780
float getYAcceleration();
7881
float getGrade();
7982
float resistance;

0 commit comments

Comments
 (0)