mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
JP_STRICT: dynamic MAX_TEXT_LEN based on runtime CR value
Instead of compile-time LORA_CR define, MAX_TEXT_LEN is now determined at runtime by reading the actual coding rate from the radio hardware. Added getMaxTextLen() to RadioLibWrapper and Dispatcher: - CR4/5: 48 bytes (~16 JP chars, TX ~3808ms) - CR4/6: 32 bytes (~10 JP chars) - CR4/7: 24 bytes (~8 JP chars) - CR4/8: 16 bytes (~5 JP chars, default) getCodingRate() added to CustomSX1262Wrapper to read codingRate from RadioLib PhysicalLayer at runtime. Tested: 48-byte limit with LORA_CR=5, 16-byte limit with LORA_CR=8.
This commit is contained in:
parent
eb58523775
commit
c5bacd7de9
5 changed files with 30 additions and 21 deletions
|
|
@ -38,6 +38,10 @@ public:
|
|||
|
||||
virtual float packetScore(float snr, int packet_len) = 0;
|
||||
|
||||
#ifdef JP_STRICT
|
||||
virtual int getMaxTextLen() const { return 1 * 16; } // default: CR4/8
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief starts the raw packet send. (no wait)
|
||||
* \param bytes the raw packet data
|
||||
|
|
|
|||
|
|
@ -395,8 +395,15 @@ void BaseChatMesh::onGroupDataRecv(mesh::Packet* packet, uint8_t type, const mes
|
|||
|
||||
mesh::Packet* BaseChatMesh::composeMsgPacket(const ContactInfo& recipient, uint32_t timestamp, uint8_t attempt, const char *text, uint32_t& expected_ack) {
|
||||
int text_len = strlen(text);
|
||||
|
||||
#ifdef JP_STRICT
|
||||
int max_len = _radio->getMaxTextLen();
|
||||
if (text_len > max_len) return NULL;
|
||||
if (attempt > 3 && text_len > max_len - 2) return NULL;
|
||||
#else
|
||||
if (text_len > MAX_TEXT_LEN) return NULL;
|
||||
if (attempt > 3 && text_len > MAX_TEXT_LEN-2) return NULL;
|
||||
#endif
|
||||
|
||||
uint8_t temp[5+MAX_TEXT_LEN+1];
|
||||
memcpy(temp, ×tamp, 4); // mostly an extra blob to help make packet_hash unique
|
||||
|
|
|
|||
|
|
@ -5,26 +5,8 @@
|
|||
#include <helpers/AdvertDataHelpers.h>
|
||||
#include <helpers/TxtDataHelpers.h>
|
||||
|
||||
// JP_STRICT: limit MAX_TEXT_LEN to keep TX time under 4s (ARIB STD-T108)
|
||||
// SF12/BW125, packet overhead ~44 bytes
|
||||
// CR4/5: 100 bytes total = ~3808ms → 56 bytes text → ~18 JP chars
|
||||
// CR4/6: 80 bytes total = ~3530ms → 36 bytes text → ~12 JP chars
|
||||
// CR4/7: 70 bytes total = ~3530ms → 26 bytes text → ~8 JP chars
|
||||
// CR4/8: 60 bytes total = ~3809ms → 16 bytes text → ~5 JP chars
|
||||
#ifdef JP_STRICT
|
||||
#if defined(LORA_CR) && (LORA_CR == 5)
|
||||
#define MAX_TEXT_LEN (3*CIPHER_BLOCK_SIZE) // 48 bytes ~18 JP chars
|
||||
#elif defined(LORA_CR) && (LORA_CR == 6)
|
||||
#define MAX_TEXT_LEN (2*CIPHER_BLOCK_SIZE) // 32 bytes ~10 JP chars
|
||||
#elif defined(LORA_CR) && (LORA_CR == 7)
|
||||
#define MAX_TEXT_LEN (1*CIPHER_BLOCK_SIZE+8) // 24 bytes ~8 JP chars
|
||||
#else
|
||||
#define MAX_TEXT_LEN (1*CIPHER_BLOCK_SIZE) // 16 bytes ~5 JP chars
|
||||
#endif
|
||||
#else
|
||||
#define MAX_TEXT_LEN (10*CIPHER_BLOCK_SIZE)
|
||||
#define MAX_TEXT_LEN (10*CIPHER_BLOCK_SIZE)
|
||||
// must be LESS than (MAX_PACKET_PAYLOAD - 4 - CIPHER_MAC_SIZE - 1)
|
||||
#endif
|
||||
|
||||
#include "ContactInfo.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -36,4 +36,8 @@ public:
|
|||
bool getRxBoostedGainMode() const override {
|
||||
return ((CustomSX1262 *)_radio)->getRxBoostedGainMode();
|
||||
}
|
||||
|
||||
uint8_t getCodingRate() const override {
|
||||
return ((CustomSX1262 *)_radio)->codingRate + 4; // RadioLib stores 1-4, return 5-8
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ class RadioLibWrapper : public mesh::Radio {
|
|||
protected:
|
||||
PhysicalLayer* _radio;
|
||||
mesh::MainBoard* _board;
|
||||
uint32_t n_recv, n_sent, n_recv_errors;
|
||||
uint32_t n_recv, n_sent, n_recv_errors, _tx_start_ms;
|
||||
int16_t _noise_floor, _threshold;
|
||||
uint16_t _num_floor_samples;
|
||||
int32_t _floor_sample_sum;
|
||||
|
|
@ -38,8 +38,20 @@ public:
|
|||
}
|
||||
|
||||
virtual float getCurrentRSSI() =0;
|
||||
virtual int16_t performChannelScan();
|
||||
virtual uint8_t getCodingRate() const = 0;
|
||||
|
||||
#ifdef JP_STRICT
|
||||
int getMaxTextLen() const {
|
||||
uint8_t cr = getCodingRate();
|
||||
if (cr <= 5) return 3 * 16; // 48 bytes ~16 JP chars
|
||||
if (cr == 6) return 2 * 16; // 32 bytes ~10 JP chars
|
||||
if (cr == 7) return 1 * 16 + 8; // 24 bytes ~8 JP chars
|
||||
return 1 * 16; // 16 bytes ~5 JP chars
|
||||
}
|
||||
#endif
|
||||
|
||||
virtual int16_t performChannelScan();
|
||||
|
||||
int getNoiseFloor() const override { return _noise_floor; }
|
||||
void triggerNoiseFloorCalibrate(int threshold) override;
|
||||
void resetAGC() override;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue