diff --git a/src/Dispatcher.h b/src/Dispatcher.h index b64909fb1..e4f2d4a53 100644 --- a/src/Dispatcher.h +++ b/src/Dispatcher.h @@ -80,6 +80,9 @@ public: virtual float getLastSNR() const { return 0; } virtual bool isAS923_1_JP() const { return false; } + + virtual int getMaxTextLen() const { return 10 * 16; } // default 160 bytes + virtual int getMaxGroupTextLen() const { return 10 * 16; } // default 160 bytes }; /** diff --git a/src/helpers/BaseChatMesh.cpp b/src/helpers/BaseChatMesh.cpp index 972a97e9e..75d27464b 100644 --- a/src/helpers/BaseChatMesh.cpp +++ b/src/helpers/BaseChatMesh.cpp @@ -419,8 +419,9 @@ 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); - if (text_len > MAX_TEXT_LEN) return NULL; - if (attempt > 3 && text_len > MAX_TEXT_LEN-2) return NULL; + int max_len = _radio->getMaxTextLen(); + if (text_len > max_len) return NULL; + if (attempt > 3 && text_len > max_len - 2) return NULL; uint8_t temp[5+MAX_TEXT_LEN+1]; memcpy(temp, ×tamp, 4); // mostly an extra blob to help make packet_hash unique @@ -460,7 +461,8 @@ int BaseChatMesh::sendMessage(const ContactInfo& recipient, uint32_t timestamp, int BaseChatMesh::sendCommandData(const ContactInfo& recipient, uint32_t timestamp, uint8_t attempt, const char* text, uint32_t& est_timeout) { int text_len = strlen(text); - if (text_len > MAX_TEXT_LEN) return MSG_SEND_FAILED; + int max_len = _radio->getMaxTextLen(); + if (text_len > max_len) return MSG_SEND_FAILED; uint8_t temp[5+MAX_TEXT_LEN+1]; memcpy(temp, ×tamp, 4); // mostly an extra blob to help make packet_hash unique @@ -493,7 +495,8 @@ bool BaseChatMesh::sendGroupMessage(uint32_t timestamp, mesh::GroupChannel& chan char *ep = strchr((char *) &temp[5], 0); int prefix_len = ep - (char *) &temp[5]; - if (text_len + prefix_len > MAX_TEXT_LEN) text_len = MAX_TEXT_LEN - prefix_len; + int max_len = _radio->getMaxGroupTextLen(); + if (text_len + prefix_len > max_len) text_len = max_len - prefix_len; memcpy(ep, text, text_len); ep[text_len] = 0; // null terminator diff --git a/src/helpers/radiolib/RadioLibWrappers.h b/src/helpers/radiolib/RadioLibWrappers.h index 84b12f34c..ef04e158e 100644 --- a/src/helpers/radiolib/RadioLibWrappers.h +++ b/src/helpers/radiolib/RadioLibWrappers.h @@ -64,7 +64,7 @@ public: fabsf(freq - 921.200f) < 0.05f); } - int getMaxTextLen() const { + int getMaxTextLen() const override { if (!isAS923_1_JP()) return 10 * 16; // default 160 bytes uint8_t cr = getCodingRate(); if (cr <= 5) return 64; // 3874ms @ SF12/BW125/CR4-5 @@ -73,7 +73,7 @@ public: return 24; // 3547ms @ SF12/BW125/CR4-8 } - int getMaxGroupTextLen() const { + int getMaxGroupTextLen() const override { if (!isAS923_1_JP()) return 10 * 16; // default 160 bytes uint8_t cr = getCodingRate(); if (cr <= 5) return 64; // 3710ms @ SF12/BW125/CR4-5