|
52 | 52 | #define CMD_SEND_PATH_DISCOVERY_REQ 52 |
53 | 53 | #define CMD_SET_FLOOD_SCOPE 54 // v8+ |
54 | 54 | #define CMD_SEND_CONTROL_DATA 55 // v8+ |
| 55 | +#define CMD_GET_STATS_CORE 56 |
| 56 | +#define CMD_GET_STATS_RADIO 57 |
| 57 | +#define CMD_GET_STATS_PACKETS 58 |
55 | 58 |
|
56 | 59 | #define RESP_CODE_OK 0 |
57 | 60 | #define RESP_CODE_ERR 1 |
|
77 | 80 | #define RESP_CODE_CUSTOM_VARS 21 |
78 | 81 | #define RESP_CODE_ADVERT_PATH 22 |
79 | 82 | #define RESP_CODE_TUNING_PARAMS 23 |
| 83 | +#define RESP_CODE_STATS_CORE 24 |
| 84 | +#define RESP_CODE_STATS_RADIO 25 |
| 85 | +#define RESP_CODE_STATS_PACKETS 26 |
80 | 86 |
|
81 | 87 | #define SEND_TIMEOUT_BASE_MILLIS 500 |
82 | 88 | #define FLOOD_SEND_TIMEOUT_FACTOR 16.0f |
@@ -704,7 +710,7 @@ uint32_t MyMesh::calcDirectTimeoutMillisFor(uint32_t pkt_airtime_millis, uint8_t |
704 | 710 | void MyMesh::onSendTimeout() {} |
705 | 711 |
|
706 | 712 | MyMesh::MyMesh(mesh::Radio &radio, mesh::RNG &rng, mesh::RTCClock &rtc, SimpleMeshTables &tables, DataStore& store, AbstractUITask* ui) |
707 | | - : BaseChatMesh(radio, *new ArduinoMillis(), rng, rtc, *new StaticPoolPacketManager(16), tables), |
| 713 | + : BaseChatMesh(radio, *(_ms_clock = new ArduinoMillis()), rng, rtc, *(_pkt_mgr = new StaticPoolPacketManager(16)), tables), |
708 | 714 | _serial(NULL), telemetry(MAX_PACKET_PAYLOAD - 4), _store(&store), _ui(ui) { |
709 | 715 | _iter_started = false; |
710 | 716 | _cli_rescue = false; |
@@ -1529,6 +1535,45 @@ void MyMesh::handleCmdFrame(size_t len) { |
1529 | 1535 | } else { |
1530 | 1536 | writeErrFrame(ERR_CODE_NOT_FOUND); |
1531 | 1537 | } |
| 1538 | + } else if (cmd_frame[0] == CMD_GET_STATS_CORE) { |
| 1539 | + char json_reply[160]; |
| 1540 | + formatStatsReply(json_reply); |
| 1541 | + int i = 0; |
| 1542 | + out_frame[i++] = RESP_CODE_STATS_CORE; |
| 1543 | + int json_len = strlen(json_reply); |
| 1544 | + if (i + json_len <= MAX_FRAME_SIZE) { |
| 1545 | + memcpy(&out_frame[i], json_reply, json_len); |
| 1546 | + i += json_len; |
| 1547 | + _serial->writeFrame(out_frame, i); |
| 1548 | + } else { |
| 1549 | + writeErrFrame(ERR_CODE_TABLE_FULL); |
| 1550 | + } |
| 1551 | + } else if (cmd_frame[0] == CMD_GET_STATS_RADIO) { |
| 1552 | + char json_reply[160]; |
| 1553 | + formatRadioStatsReply(json_reply); |
| 1554 | + int i = 0; |
| 1555 | + out_frame[i++] = RESP_CODE_STATS_RADIO; |
| 1556 | + int json_len = strlen(json_reply); |
| 1557 | + if (i + json_len <= MAX_FRAME_SIZE) { |
| 1558 | + memcpy(&out_frame[i], json_reply, json_len); |
| 1559 | + i += json_len; |
| 1560 | + _serial->writeFrame(out_frame, i); |
| 1561 | + } else { |
| 1562 | + writeErrFrame(ERR_CODE_TABLE_FULL); |
| 1563 | + } |
| 1564 | + } else if (cmd_frame[0] == CMD_GET_STATS_PACKETS) { |
| 1565 | + char json_reply[160]; |
| 1566 | + formatPacketStatsReply(json_reply); |
| 1567 | + int i = 0; |
| 1568 | + out_frame[i++] = RESP_CODE_STATS_PACKETS; |
| 1569 | + int json_len = strlen(json_reply); |
| 1570 | + if (i + json_len <= MAX_FRAME_SIZE) { |
| 1571 | + memcpy(&out_frame[i], json_reply, json_len); |
| 1572 | + i += json_len; |
| 1573 | + _serial->writeFrame(out_frame, i); |
| 1574 | + } else { |
| 1575 | + writeErrFrame(ERR_CODE_TABLE_FULL); |
| 1576 | + } |
1532 | 1577 | } else if (cmd_frame[0] == CMD_FACTORY_RESET && memcmp(&cmd_frame[1], "reset", 5) == 0) { |
1533 | 1578 | bool success = _store->formatFileSystem(); |
1534 | 1579 | if (success) { |
@@ -1565,6 +1610,21 @@ void MyMesh::enterCLIRescue() { |
1565 | 1610 | Serial.println("========= CLI Rescue ========="); |
1566 | 1611 | } |
1567 | 1612 |
|
| 1613 | +void MyMesh::formatStatsReply(char *reply) { |
| 1614 | + // Use StatsFormatHelper |
| 1615 | + // Note: err_flags is private in Dispatcher, so we use 0 |
| 1616 | + StatsFormatHelper::formatCoreStats(reply, board, *_ms_clock, 0, _pkt_mgr); |
| 1617 | +} |
| 1618 | + |
| 1619 | +void MyMesh::formatRadioStatsReply(char *reply) { |
| 1620 | + StatsFormatHelper::formatRadioStats(reply, _radio, radio_driver, getTotalAirTime(), getReceiveAirTime()); |
| 1621 | +} |
| 1622 | + |
| 1623 | +void MyMesh::formatPacketStatsReply(char *reply) { |
| 1624 | + StatsFormatHelper::formatPacketStats(reply, radio_driver, getNumSentFlood(), getNumSentDirect(), |
| 1625 | + getNumRecvFlood(), getNumRecvDirect()); |
| 1626 | +} |
| 1627 | + |
1568 | 1628 | void MyMesh::checkCLIRescueCmd() { |
1569 | 1629 | int len = strlen(cli_command); |
1570 | 1630 | while (Serial.available() && len < sizeof(cli_command)-1) { |
|
0 commit comments