| 363 | // TODO: optimize when loop not have a large delay |
| 364 | |
| 365 | void RemoteDebug::handle() { |
| 366 | |
| 367 | #ifdef ALPHA_VERSION // In test, not good yet |
| 368 | static uint32_t lastTime = millis(); |
| 369 | #endif |
| 370 | |
| 371 | #ifdef DEBUGGER_ENABLED |
| 372 | static uint32_t dbgTimeHandle = millis(); // To avoid call the handler desnecessary |
| 373 | static boolean dbgLastConnected = false; // Last is connected ? |
| 374 | #endif |
| 375 | |
| 376 | // Silence timeout ? |
| 377 | |
| 378 | if (_silence && _silenceTimeout > 0 && millis() >= _silenceTimeout) { |
| 379 | |
| 380 | // Get out of silence mode |
| 381 | |
| 382 | silence(false, true); |
| 383 | } |
| 384 | |
| 385 | // Debug level is profiler -> set the level before |
| 386 | |
| 387 | if (_clientDebugLevel == PROFILER) { |
| 388 | if (millis() > _levelProfilerDisable) { |
| 389 | _clientDebugLevel = _levelBeforeProfiler; |
| 390 | debugPrintln("* Debug level profile inactive now"); |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | #ifdef ALPHA_VERSION // In test, not good yet |
| 395 | |
| 396 | // Automatic change to profiler level if time between handles is greater than n millis |
| 397 | |
| 398 | if (_autoLevelProfiler > 0 && _clientDebugLevel != PROFILER) { |
| 399 | |
| 400 | uint32_t diff = (millis() - lastTime); |
| 401 | |
| 402 | if (diff >= _autoLevelProfiler) { |
| 403 | _levelBeforeProfiler = _clientDebugLevel; |
| 404 | _clientDebugLevel = PROFILER; |
| 405 | _levelProfilerDisable = 1000; // Disable it at 1 sec |
| 406 | |
| 407 | debugPrintf("* Debug level profile active now - time between handels: %u\r\n", diff); |
| 408 | } |
| 409 | |
| 410 | lastTime = millis(); |
| 411 | } |
| 412 | #endif |
| 413 | |
| 414 | // look for Client connect trial |
| 415 | |
| 416 | if (TelnetServer.hasClient()) { |
| 417 | |
| 418 | // Old connection logic |
| 419 | |
| 420 | // if (!TelnetClient || !TelnetClient.connected()) { |
| 421 | // |
| 422 | // if (TelnetClient) { // Close the last connect - only one supported |