From 1444edba0cbd603202c4a3284f3f55c1d1f22eeb Mon Sep 17 00:00:00 2001 From: Scott Penrose Date: Wed, 10 Jun 2026 11:29:28 +1000 Subject: [PATCH] Bump to version 3 to get rssi et al --- src/MeshCoreCompanion.h | 2 +- src/meshcore_companion.c | 4 +++- src/meshcore_companion.h | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/MeshCoreCompanion.h b/src/MeshCoreCompanion.h index c4ee87f..260f4ec 100644 --- a/src/MeshCoreCompanion.h +++ b/src/MeshCoreCompanion.h @@ -46,7 +46,7 @@ public: /* ---- commands (fire-and-forget; replies arrive via callbacks) ---- */ void appStart(const char *name = "esp32"); - void deviceQuery(uint8_t appTargetVer = 1); + void deviceQuery(uint8_t appTargetVer = 3); /* 3 = request V3 frames (SNR+RSSI) */ void getDeviceTime(); void setDeviceTime(uint32_t epochSecs); void sendSelfAdvert(bool flood = true); diff --git a/src/meshcore_companion.c b/src/meshcore_companion.c index db91074..d53e1c1 100644 --- a/src/meshcore_companion.c +++ b/src/meshcore_companion.c @@ -46,6 +46,7 @@ static int parse_channel_text(const uint8_t *b, size_t n, int v3, mc_channel_msg m->txt_type = q[2]; m->sender_ts = get_u32(q + 3); m->snr_q4 = v3 ? (int8_t)b[0] : MC_SNR_NONE; + m->rssi = v3 ? (int8_t)b[1] : MC_RSSI_NONE; /* V3 lead: [snr][rssi][?] */ copy_rest_string(m->text, sizeof(m->text), q, 7, qn); return 1; } @@ -63,6 +64,7 @@ static int parse_contact_text(const uint8_t *b, size_t n, int v3, mc_contact_msg m->txt_type = q[7]; m->sender_ts = get_u32(q + 8); m->snr_q4 = v3 ? (int8_t)b[0] : MC_SNR_NONE; + m->rssi = v3 ? (int8_t)b[1] : MC_RSSI_NONE; /* V3 lead: [snr][rssi][?] */ size_t toff = 12; if (m->txt_type == MC_TXT_SIGNED_PLAIN && qn >= toff + 4) { memcpy(m->signature, q + toff, 4); @@ -148,7 +150,7 @@ size_t mc_cmd_app_start(uint8_t *out, size_t cap, const char *app_name) { if (cap < total) return 0; size_t i = 0; out[i++] = MC_CMD_APP_START; - out[i++] = 1; /* app version */ + out[i++] = 3; /* app version (3 = accept V3 frames with SNR+RSSI) */ memset(out + i, 0, 6); i += 6; /* reserved */ memcpy(out + i, app_name, nlen); i += nlen; return i; diff --git a/src/meshcore_companion.h b/src/meshcore_companion.h index e068341..1e364b0 100644 --- a/src/meshcore_companion.h +++ b/src/meshcore_companion.h @@ -154,6 +154,8 @@ enum { MC_ADVERT_ZERO_HOP = 0, MC_ADVERT_FLOOD = 1 }; #define MC_SNR_DB(q4) ((float)(q4) / 4.0f) /* snr_q4 sentinel for non-V3 messages that carry no SNR. */ #define MC_SNR_NONE ((int8_t)-128) +/* rssi sentinel for non-V3 messages that carry no RSSI (0 dBm never occurs). */ +#define MC_RSSI_NONE ((int8_t)0) /* ======================================================================== * * Receive side: streaming frame assembler @@ -262,6 +264,7 @@ typedef struct { uint8_t txt_type; uint32_t sender_ts; int8_t snr_q4; /* V3 only (code 17); MC_SNR_NONE otherwise */ + int8_t rssi; /* dBm; V3 only (code 17); MC_RSSI_NONE otherwise */ char text[MC_MAX_TEXT]; /* for channel msgs this is "Name: body" */ } mc_channel_msg_t; @@ -280,6 +283,7 @@ typedef struct { uint8_t txt_type; uint32_t sender_ts; int8_t snr_q4; /* V3 only (code 16); MC_SNR_NONE otherwise */ + int8_t rssi; /* dBm; V3 only (code 16); MC_RSSI_NONE otherwise */ uint8_t signature[4]; /* present when txt_type==MC_TXT_SIGNED_PLAIN */ int has_signature; char text[MC_MAX_TEXT];