From 870b5d2b702a0604f2735b8ce3ace80c928014e5 Mon Sep 17 00:00:00 2001 From: Scott Powell Date: Mon, 2 Jun 2025 20:28:00 +1000 Subject: [PATCH] * companion: 'self telemetry' request with CMD_SEND_TELEMETRY_REQ (with no pubkey param) --- examples/companion_radio/MyMesh.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/examples/companion_radio/MyMesh.cpp b/examples/companion_radio/MyMesh.cpp index b0905bb6..f7811415 100644 --- a/examples/companion_radio/MyMesh.cpp +++ b/examples/companion_radio/MyMesh.cpp @@ -1373,6 +1373,28 @@ void MyMesh::handleCmdFrame(size_t len) { } else { writeErrFrame(ERR_CODE_NOT_FOUND); // contact not found } + } else if (cmd_frame[0] == CMD_SEND_TELEMETRY_REQ && len == 4) { // 'self' telemetry request + out_frame[0] = RESP_CODE_SENT; + out_frame[1] = 0; + uint32_t tag = 0, est_timeout = 50; + memcpy(&out_frame[2], &tag, 4); + memcpy(&out_frame[6], &est_timeout, 4); + _serial->writeFrame(out_frame, 10); + + telemetry.reset(); + telemetry.addVoltage(TELEM_CHANNEL_SELF, (float)board.getBattMilliVolts() / 1000.0f); + // query other sensors -- target specific + sensors.querySensors(0xFF, telemetry); + + int i = 0; + out_frame[i++] = PUSH_CODE_TELEMETRY_RESPONSE; + out_frame[i++] = 0; // reserved + memcpy(&out_frame[i], self_id.pub_key, 6); + i += 6; // pub_key_prefix + uint8_t tlen = telemetry.getSize(); + memcpy(&out_frame[i], telemetry.getBuffer(), tlen); + i += tlen; + _serial->writeFrame(out_frame, i); } else if (cmd_frame[0] == CMD_HAS_CONNECTION && len >= 1 + PUB_KEY_SIZE) { uint8_t *pub_key = &cmd_frame[1]; if (hasConnectionTo(pub_key)) {