From 40c3dfa20be3816c924dc49df3e3607c9efce01d Mon Sep 17 00:00:00 2001 From: Scott Powell Date: Sun, 26 Jan 2025 15:40:32 +1100 Subject: [PATCH] * fixes for various targets (BaseChatMesh not compiling for non-terminal chat targets) --- src/helpers/BaseChatMesh.cpp | 11 ++++++++++- src/helpers/BaseChatMesh.h | 10 ++++++++++ src/helpers/IdentityStore.cpp | 3 ++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/helpers/BaseChatMesh.cpp b/src/helpers/BaseChatMesh.cpp index a7e8b715..380f2307 100644 --- a/src/helpers/BaseChatMesh.cpp +++ b/src/helpers/BaseChatMesh.cpp @@ -1,5 +1,4 @@ #include -#include #include mesh::Packet* BaseChatMesh::createSelfAdvert(const char* name) { @@ -152,6 +151,7 @@ void BaseChatMesh::onAckRecv(mesh::Packet* packet, uint32_t ack_crc) { } } +#ifdef MAX_GROUP_CHANNELS int BaseChatMesh::searchChannelsByHash(const uint8_t* hash, mesh::GroupChannel dest[], int max_matches) { int n = 0; for (int i = 0; i < num_channels && n < max_matches; i++) { @@ -161,6 +161,7 @@ int BaseChatMesh::searchChannelsByHash(const uint8_t* hash, mesh::GroupChannel d } return n; } +#endif void BaseChatMesh::onGroupDataRecv(mesh::Packet* packet, uint8_t type, const mesh::GroupChannel& channel, uint8_t* data, size_t len) { uint8_t txt_type = data[4]; @@ -266,6 +267,9 @@ bool BaseChatMesh::addContact(const ContactInfo& contact) { return false; } +#ifdef MAX_GROUP_CHANNELS +#include + mesh::GroupChannel* BaseChatMesh::addChannel(const char* psk_base64) { if (num_channels < MAX_GROUP_CHANNELS) { auto dest = &channels[num_channels]; @@ -280,6 +284,11 @@ mesh::GroupChannel* BaseChatMesh::addChannel(const char* psk_base64) { } return NULL; } +#else +mesh::GroupChannel* BaseChatMesh::addChannel(const char* psk_base64) { + return NULL; // not supported +} +#endif bool ContactsIterator::hasNext(const BaseChatMesh* mesh, ContactInfo& dest) { if (next_idx >= mesh->num_contacts) return false; diff --git a/src/helpers/BaseChatMesh.h b/src/helpers/BaseChatMesh.h index 61af0c3a..4a512771 100644 --- a/src/helpers/BaseChatMesh.h +++ b/src/helpers/BaseChatMesh.h @@ -36,6 +36,10 @@ public: bool hasNext(const BaseChatMesh* mesh, ContactInfo& dest); }; +#ifndef MAX_CONTACTS + #define MAX_CONTACTS 32 +#endif + /** * \brief abstract Mesh class for common 'chat' client */ @@ -48,8 +52,10 @@ class BaseChatMesh : public mesh::Mesh { int sort_array[MAX_CONTACTS]; int matching_peer_indexes[MAX_SEARCH_RESULTS]; unsigned long txt_send_timeout; +#ifdef MAX_GROUP_CHANNELS mesh::GroupChannel channels[MAX_GROUP_CHANNELS]; int num_channels; +#endif mesh::Packet* composeMsgPacket(const ContactInfo& recipient, uint8_t attempt, const char *text, uint32_t& expected_ack); @@ -58,7 +64,9 @@ protected: : mesh::Mesh(radio, ms, rng, rtc, mgr, tables) { num_contacts = 0; + #ifdef MAX_GROUP_CHANNELS num_channels = 0; + #endif txt_send_timeout = 0; } @@ -79,7 +87,9 @@ protected: void onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender_idx, const uint8_t* secret, uint8_t* data, size_t len) override; bool onPeerPathRecv(mesh::Packet* packet, int sender_idx, const uint8_t* secret, uint8_t* path, uint8_t path_len, uint8_t extra_type, uint8_t* extra, uint8_t extra_len) override; void onAckRecv(mesh::Packet* packet, uint32_t ack_crc) override; +#ifdef MAX_GROUP_CHANNELS int searchChannelsByHash(const uint8_t* hash, mesh::GroupChannel channels[], int max_matches) override; +#endif void onGroupDataRecv(mesh::Packet* packet, uint8_t type, const mesh::GroupChannel& channel, uint8_t* data, size_t len) override; public: diff --git a/src/helpers/IdentityStore.cpp b/src/helpers/IdentityStore.cpp index 11838385..84cf6ace 100644 --- a/src/helpers/IdentityStore.cpp +++ b/src/helpers/IdentityStore.cpp @@ -23,7 +23,8 @@ bool IdentityStore::load(const char *name, mesh::LocalIdentity& id, char display if (file) { loaded = id.readFrom(file); - int n = min(32, max_name_sz); // up to 32 bytes + int n = max_name_sz; // up to 32 bytes + if (n > 32) n = 32; file.read((uint8_t *) display_name, n); display_name[n - 1] = 0; // ensure null terminator