Skip to content

Commit 112b79e

Browse files
committed
Fix teleplot delete/reset
1 parent 64699e1 commit 112b79e

3 files changed

Lines changed: 33 additions & 7 deletions

File tree

include/Teleplot.h

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ class ShapeTeleplot {
210210

211211
class Teleplot {
212212
public:
213-
Teleplot(){};
213+
Teleplot() { Reset(); };
214214
#ifndef TELEPLOT_DISABLE
215215
Teleplot(std::string address, uint32_t port=47269, uint32_t bufferingFrequencyHz = 30)
216216
: address_(address)
@@ -228,8 +228,30 @@ class Teleplot {
228228
#endif
229229
};
230230
#endif
231-
~Teleplot() {initialized_ = false;};
231+
~Teleplot() { Reset(); };
232232
bool IsInitialized() {return initialized_;}
233+
void Reset()
234+
{
235+
initialized_ = false;
236+
#ifndef TELEPLOT_DISABLE
237+
if (sockfd_ >= 0)
238+
{
239+
close(sockfd_);
240+
}
241+
sockfd_ = -1;
242+
address_.clear();
243+
memset(&serv_, 0, sizeof(serv_));
244+
bufferingFrequencyHz_ = 0;
245+
lastBufferingFlushTimestampUs_ = 0;
246+
#ifdef TELEPLOT_USE_BUFFERING
247+
bufferingMap_.clear();
248+
bufferingFlushTimestampsUs_.clear();
249+
#endif
250+
#ifdef TELEPLOT_USE_FREQUENCY
251+
updateTimestampsUs_.clear();
252+
#endif
253+
#endif
254+
}
233255

234256
#ifndef TELEPLOT_DISABLE
235257
// Static localhost instance

src/Printer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ Format Specifier
292292
if (teleplotUDP.IsInitialized())
293293
teleplotUDP.update(varName.c_str(), var);
294294
else
295-
println(">%s:%f", varName, var);
295+
println(">%s:%f", varName.c_str(), var);
296296
}
297297

298298
void teleplot(const String &varName, Point point)

src/Wifi_Helper.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,9 @@ namespace Wifi_Helper
329329
if (Printer::teleplotUDP.IsInitialized())
330330
{
331331
// We need to un-init in case of wifi lost
332-
println("Deleting Teleplot");
333-
Printer::teleplotUDP.~Teleplot();
332+
println("Deleting Teleplot because WiFi is down");
333+
Printer::teleplotUDP.Reset();
334+
println("Teleplot reset complete after WiFi loss");
334335
}
335336
}
336337

@@ -362,13 +363,16 @@ namespace Wifi_Helper
362363

363364
if (!Printer::teleplotUDP.IsInitialized() && teleplotTO.IsTimeOut() && Printer::teleplotUDPEnable == Enable::ENABLE_TRUE)
364365
{
365-
println("Initialising Teleplot");
366+
println("Initialising Teleplot on %s:%i", wifi_teleplot_ip.c_str(), wifi_teleplot_port);
366367
Printer::teleplotUDP = Teleplot(wifi_teleplot_ip.c_str(), wifi_teleplot_port);
368+
println("Teleplot init state: %s", Printer::teleplotUDP.IsInitialized() ? "ready" : "not ready");
367369
}
368370

369371
if (Printer::teleplotUDP.IsInitialized() && Printer::teleplotUDPEnable == Enable::ENABLE_FALSE)
370372
{
371-
Printer::teleplotUDP.~Teleplot();
373+
println("Resetting Teleplot because Teleplot UDP was disabled");
374+
Printer::teleplotUDP.Reset();
375+
println("Teleplot reset complete after disable request");
372376
}
373377
}
374378

0 commit comments

Comments
 (0)