Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions examples/companion_radio/DataStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,11 @@ void DataStore::loadChannels(DataStoreHost* host) {
uint8_t channel_idx = 0;
while (!full) {
ChannelDetails ch;
uint8_t unused[4];
ChannelHeader header;

bool success = (file.read((uint8_t*)&header, sizeof(ChannelHeader)) == sizeof(ChannelHeader));
ch.channel.flags = header.flags;

bool success = (file.read(unused, 4) == 4);
success = success && (file.read((uint8_t *)ch.name, 32) == 32);
success = success && (file.read((uint8_t *)ch.channel.secret, 32) == 32);

Expand All @@ -347,11 +349,12 @@ void DataStore::saveChannels(DataStoreHost* host) {
if (file) {
uint8_t channel_idx = 0;
ChannelDetails ch;
uint8_t unused[4];
memset(unused, 0, 4);


while (host->getChannelForSave(channel_idx, ch)) {
bool success = (file.write(unused, 4) == 4);
ChannelHeader header{};
header.flags = ch.channel.flags;

bool success = (file.write((uint8_t *)&header, sizeof(ChannelHeader)) == sizeof(ChannelHeader));
success = success && (file.write((uint8_t *)ch.name, 32) == 32);
success = success && (file.write((uint8_t *)ch.channel.secret, 32) == 32);

Expand Down
6 changes: 6 additions & 0 deletions examples/companion_radio/DataStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
#include <helpers/ChannelDetails.h>
#include "NodePrefs.h"

struct ChannelHeader {
mesh::ChannelFlags flags;
uint8_t unused[3];
};
static_assert(sizeof(ChannelHeader) == 4, "ChannelHeader must be 4 bytes");

class DataStoreHost {
public:
virtual bool onContactLoaded(const ContactInfo& contact) =0;
Expand Down
7 changes: 6 additions & 1 deletion examples/companion_radio/MyMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,12 @@ void MyMesh::onChannelMessageRecv(const mesh::GroupChannel &channel, mesh::Packe
}
memcpy(&out_frame[i], text, tlen);
i += tlen;
addToOfflineQueue(out_frame, i);

if (channel.flags.noStore && !_serial->isConnected()) {
MESH_DEBUG_PRINTLN("INFO: not storing message for noStore channel");
} else {
addToOfflineQueue(out_frame, i);
}

if (_serial->isConnected()) {
uint8_t frame[1];
Expand Down
6 changes: 6 additions & 0 deletions src/Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@

namespace mesh {

struct ChannelFlags {
bool noStore : 1;
uint8_t reserved : 7; // remaining 7 bits unused
};

class GroupChannel {
public:
uint8_t hash[PATH_HASH_SIZE];
uint8_t secret[PUB_KEY_SIZE];
ChannelFlags flags;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/ChannelDetails.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
struct ChannelDetails {
mesh::GroupChannel channel;
char name[32];
};
};