|
2 | 2 | #define CMDS_ESP_GENERIC_H
|
3 | 3 |
|
4 | 4 | #include "at_handler.h"
|
5 |
| -#include "ESPping.h" |
6 |
| -char rsl[5]; // ping time |
| 5 | +#include "ping.h" |
7 | 6 |
|
8 | 7 | extern "C" {
|
9 | 8 | #include "esp32-hal-tinyusb.h"
|
@@ -362,91 +361,53 @@ void CAtHandler::add_cmds_esp_generic() {
|
362 | 361 | return chAT::CommandStatus::ERROR;
|
363 | 362 | }
|
364 | 363 | };
|
365 |
| - |
| 364 | + |
366 | 365 | /* ....................................................................... */
|
367 |
| - command_table[_PINGIP] = [this](auto & srv, auto & parser) { |
| 366 | + command_table[_PING] = [this](auto & srv, auto & parser) { |
368 | 367 | /* ....................................................................... */
|
369 |
| - switch (parser.cmd_mode) { |
370 |
| - case chAT::CommandMode::Write: { |
371 |
| - |
372 |
| - if (parser.args.size() != 3) { |
373 |
| - return chAT::CommandStatus::ERROR; |
374 |
| - } |
375 |
| - |
376 |
| - // get IP |
377 |
| - auto &hostip = parser.args[1]; |
378 |
| - if (hostip.empty()) { |
379 |
| - return chAT::CommandStatus::ERROR; |
380 |
| - } |
381 |
| - |
382 |
| - IPAddress address; |
383 |
| - if(!address.fromString(hostip.c_str())) { |
384 |
| - return chAT::CommandStatus::ERROR; |
385 |
| - } |
386 |
| - |
387 |
| - // get count |
388 |
| - auto &cnt = parser.args[2]; |
389 |
| - if (cnt.empty()) { |
| 368 | + switch (parser.cmd_mode) { |
| 369 | + case chAT::CommandMode::Write: { |
| 370 | + if (parser.args.size() != 3) { |
390 | 371 | return chAT::CommandStatus::ERROR;
|
391 |
| - } |
392 |
| - unsigned int count = atoi(cnt.c_str()); |
393 |
| - |
394 |
| - auto res = Ping.ping(address, count); |
395 |
| - if (res) { // ping was succesfull |
396 |
| - srv.write_response_prompt(); |
397 |
| - sprintf(rsl,"%.2f", Ping.averageTime()); |
398 |
| - srv.write_cstr((const char *) rsl); |
399 |
| - srv.write_line_end(); |
400 |
| - return chAT::CommandStatus::OK; |
401 |
| - } |
402 |
| - srv.write_response_prompt(); |
403 |
| - srv.write_error(); |
404 |
| - srv.write_line_end(); |
405 |
| - return chAT::CommandStatus::ERROR; |
406 | 372 | }
|
407 |
| - default: |
408 |
| - return chAT::CommandStatus::ERROR; |
409 |
| - } |
410 |
| - }; |
411 | 373 |
|
412 |
| -/* ....................................................................... */ |
413 |
| - command_table[_PINGNAME] = [this](auto & srv, auto & parser) { |
414 |
| -/* ....................................................................... */ |
415 |
| - switch (parser.cmd_mode) { |
416 |
| - case chAT::CommandMode::Write: { |
417 |
| - |
418 |
| - if (parser.args.size() != 3) { |
| 374 | + // get IP |
| 375 | + auto &target = parser.args[1]; |
| 376 | + if (target.empty()) { |
419 | 377 | return chAT::CommandStatus::ERROR;
|
420 |
| - } |
| 378 | + } |
421 | 379 |
|
422 |
| - // get host name |
423 |
| - auto &host = parser.args[1]; |
424 |
| - if (host.empty()) { |
425 |
| - return chAT::CommandStatus::ERROR; |
426 |
| - } |
| 380 | + // IPAddress address; |
| 381 | + // if(!address.fromString(hostip.c_str())) { |
| 382 | + // return chAT::CommandStatus::ERROR; |
| 383 | + // } |
427 | 384 |
|
428 |
| - // get count |
429 |
| - auto &cnt = parser.args[2]; |
430 |
| - if (cnt.empty()) { |
| 385 | + // get count |
| 386 | + auto &cnt = parser.args[2]; |
| 387 | + if (cnt.empty()) { |
431 | 388 | return chAT::CommandStatus::ERROR;
|
432 |
| - } |
433 |
| - unsigned int count = atoi(cnt.c_str()); |
434 |
| - |
435 |
| - auto res = Ping.ping((const char* ) host.c_str(), count); |
436 |
| - if (res) { // ping was succesfull |
437 |
| - srv.write_response_prompt(); |
438 |
| - sprintf(rsl,"%.2f", Ping.averageTime()); |
439 |
| - srv.write_cstr((const char *) rsl); |
440 |
| - srv.write_line_end(); |
441 |
| - return chAT::CommandStatus::OK; |
442 |
| - } |
443 |
| - srv.write_response_prompt(); |
444 |
| - srv.write_error(); |
445 |
| - srv.write_line_end(); |
446 |
| - return chAT::CommandStatus::ERROR; |
447 | 389 | }
|
448 |
| - default: |
449 |
| - return chAT::CommandStatus::ERROR; |
| 390 | + unsigned int count = atoi(cnt.c_str()); |
| 391 | + |
| 392 | + auto ping_res = execute_ping(target.c_str(), count); |
| 393 | + |
| 394 | + log_e("ping result %d %d %f", ping_res.success_count, ping_res.timedout_count, ping_res.averagertt); |
| 395 | + |
| 396 | + // auto res = Ping.ping(address, count); |
| 397 | + // if (res) { // ping was succesfull |
| 398 | + // srv.write_response_prompt(); |
| 399 | + // sprintf(rsl,"%.2f", Ping.averageTime()); |
| 400 | + // srv.write_cstr((const char *) rsl); |
| 401 | + // srv.write_line_end(); |
| 402 | + // return chAT::CommandStatus::OK; |
| 403 | + // } |
| 404 | + srv.write_response_prompt(); |
| 405 | + srv.write_error(); |
| 406 | + srv.write_line_end(); |
| 407 | + return chAT::CommandStatus::ERROR; |
| 408 | + } |
| 409 | + default: |
| 410 | + return chAT::CommandStatus::ERROR; |
450 | 411 | }
|
451 | 412 | };
|
452 | 413 | }
|
|
0 commit comments