Skip to content

Commit 4ed3cf2

Browse files
committed
add third UDPComm just for listening
1 parent c78f6cc commit 4ed3cf2

2 files changed

Lines changed: 34 additions & 41 deletions

File tree

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

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ TacxFTMS::TacxFTMS()
3232
: coVRPlugin(COVER_PLUGIN_NAME)
3333
, udpNeo(NULL)
3434
, udpAlpine(NULL)
35+
, udpListen(NULL)
3536
, coVRNavigationProvider("TacxFTMS", this)
3637
{
3738
ftmsData.speed = 0.0;
@@ -58,6 +59,7 @@ TacxFTMS::~TacxFTMS() {
5859

5960
delete udpNeo;
6061
delete udpAlpine;
62+
delete udpListen;
6163
}
6264

6365
bool TacxFTMS::init() {
@@ -103,6 +105,23 @@ bool TacxFTMS::init() {
103105
}
104106
ret = supportedDeviceFound;
105107
coVRMSController::instance()->sendSlaves(&ret, sizeof(ret));
108+
if (supportedDeviceFound)
109+
{
110+
unsigned short listeningPort = configInt("Listening", "Port", 31322)->value();
111+
112+
std::cerr << "TacxFTMS config: UDP: start listening on port: " << listeningPort << std::endl;
113+
udpListen = new UDPComm(listeningPort);
114+
if (!udpListen->isBad())
115+
{
116+
std::cerr << "TacxFTMS config: UDP: start listening on port: " << listeningPort << std::endl;
117+
118+
}
119+
else
120+
{
121+
//std::cerr << "TacxFTMS: failed to open local UDP port" << localPortNeo << std::endl;
122+
ftmsfound = false;
123+
}
124+
}
106125
}
107126
else
108127
{
@@ -117,10 +136,10 @@ void TacxFTMS::addDevice(const opencover::deviceInfo *i)
117136
{
118137
//const std::string host = configString("TacxFTMS", "severHost", "192.168.178.36")->value();
119138
unsigned short serverPortNeo = configInt("TacxFTMS", "serverPort", 31319)->value();
120-
unsigned short localPortNeo = configInt("TacxFTMS", "localPort", 31322)->value();
139+
//unsigned short localPortNeo = configInt("TacxFTMS", "localPort", 31322)->value();
121140

122141
unsigned short serverPortAlpine = configInt("Alpine", "serverPort", 31319)->value();
123-
unsigned short localPortAlpine = configInt("Alpine", "localPort", 31328)->value();
142+
//unsigned short localPortAlpine = configInt("Alpine", "localPort", 31322)->value();
124143

125144

126145
if (coVRMSController::instance()->isMaster())
@@ -131,31 +150,31 @@ void TacxFTMS::addDevice(const opencover::deviceInfo *i)
131150
{
132151
host = i->address;
133152
std::cerr << "TacxFTMS config: UDP: TacxHost: " << host << std::endl;
134-
udpNeo = new UDPComm(host.c_str(), serverPortNeo, localPortNeo);
153+
udpNeo = new UDPComm(serverPortNeo, host.c_str());
135154
if (!udpNeo->isBad())
136155
{
137156
ftmsfound = true;
138157
start();
139158
}
140159
else
141160
{
142-
std::cerr << "TacxFTMS: failed to open local UDP port" << localPortNeo << std::endl;
161+
//std::cerr << "TacxFTMS: failed to open local UDP port" << localPortNeo << std::endl;
143162
ftmsfound = false;
144163
}
145164
}
146165
else if (i->deviceName == "Alpine")
147166
{
148167
host = i->address;
149168
std::cerr << "TacxFTMS config: UDP: AlpineHost: " << host << std::endl;
150-
udpAlpine = new UDPComm(host.c_str(), serverPortAlpine, localPortAlpine);
169+
udpAlpine = new UDPComm(serverPortAlpine, host.c_str());
151170
if (!udpAlpine->isBad())
152171
{
153172
alpinefound = true;
154173
start();
155174
}
156175
else
157176
{
158-
std::cerr << "Alpine: failed to open local UDP port" << localPortAlpine << std::endl;
177+
//std::cerr << "Alpine: failed to open local UDP port" << localPortAlpine << std::endl;
159178
alpinefound = false;
160179
}
161180
}
@@ -182,6 +201,7 @@ bool TacxFTMS::update() {
182201
VRSceneGraph::instance()->getTransform()->getMatrix();
183202

184203
float grade = getGrade();
204+
ftmsControl.grade = grade;
185205

186206
if (fabs(speed) < 0.00001) {
187207
speed = 0;
@@ -193,7 +213,7 @@ bool TacxFTMS::update() {
193213

194214
osg::Vec3 V(0, s, 0);
195215
float rotAngle = 0.0;
196-
float wheelAngle = getAngle() / 10.0;
216+
float wheelAngle = - getAngle() / 100.0;
197217
//fprintf(stderr, "wheelAngle: %f\n", wheelAngle);
198218

199219
if (fabs(s) < 0.001 || fabs(wheelAngle) < 0.001) {
@@ -279,25 +299,25 @@ void TacxFTMS::run() {
279299
}
280300

281301
void TacxFTMS::updateThread() {
282-
if (udpNeo) {
302+
if (udpListen) {
283303
char tmpBuf[10000];
284304
int status;
285-
status = udpNeo->receive(&tmpBuf, 10000);
305+
status = udpListen->receive(&tmpBuf, 10000);
286306

287307
if (status == -1) {
288308
if (isEnabled()) // otherwise we are not supposed to receive
289309
// anything
290310
{
291311
std::cerr << "TacxFTMS::update: error while reading Neo data"
292312
<< std::endl;
293-
if (udpNeo) // try to wake up the trainer (if the first start UDP
294-
// message was lost)
295-
udpNeo->send("start");
296313
}
297314
} else if (status >= sizeof(FTMSBikeData)) {
298315
if (!isEnabled()) {
299316
if (udpNeo) // still receiving data, send stop
300317
udpNeo->send("stop");
318+
if (udpAlpine)
319+
udpAlpine->send("stop");
320+
return;
301321
}
302322
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mutex);
303323
memcpy(&ftmsData, tmpBuf, sizeof(FTMSBikeData));
@@ -312,34 +332,6 @@ void TacxFTMS::updateThread() {
312332
<< status << ", got=" << status << std::endl;
313333
}
314334
}
315-
if (udpAlpine) {
316-
char tmpBuf[10000];
317-
int status;
318-
status = udpAlpine->receive(&tmpBuf, 10000);
319-
320-
if (status == -1) {
321-
if (isEnabled()) // otherwise we are not supposed to receive
322-
// anything
323-
{
324-
std::cerr << "Alpine::update: error while reading Alpine data"
325-
<< std::endl;
326-
if (udpAlpine) // try to wake up the trainer (if the first start UDP
327-
// message was lost)
328-
udpAlpine->send("start");
329-
}
330-
} else if (status >= sizeof(AlpineData)) {
331-
if (!isEnabled()) {
332-
if (udpAlpine) // still receiving data, send stop
333-
udpAlpine->send("stop");
334-
}
335-
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mutex);
336-
memcpy(&alpineData, tmpBuf, sizeof(AlpineData));
337-
338-
} else {
339-
std::cerr << "Alpine::update: received invalid no. of bytes: recv="
340-
<< status << ", got=" << status << std::endl;
341-
}
342-
}
343335
else {
344336
usleep(5);
345337
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ class PLUGINEXPORT TacxFTMS : public opencover::coVRPlugin, public opencover::co
8585
osg::Matrix TacxFTMSPos;
8686
virtual void setEnabled(bool);
8787
void updateThread();
88-
UDPComm* udpNeo;
88+
UDPComm* udpNeo;
8989
UDPComm* udpAlpine;
90+
UDPComm* udpListen; // for listening to all devices
9091
FTMSBikeData ftmsData;
9192
FTMSControlData ftmsControl;
9293
AlpineData alpineData;

0 commit comments

Comments
 (0)