File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -210,7 +210,7 @@ class ShapeTeleplot {
210210
211211class Teleplot {
212212public:
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
Original file line number Diff line number Diff 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)
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments