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
26 changes: 23 additions & 3 deletions examples/companion_radio/MyMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,24 @@ int MyMesh::getFromOfflineQueue(uint8_t frame[]) {
return 0; // queue is empty
}

int MyMesh::peekOfflineQueue(uint8_t frame[]) {
if (offline_queue_len > 0) {
size_t len = offline_queue[0].len;
memcpy(frame, offline_queue[0].buf, len);
return len;
}
return 0;
}

void MyMesh::popOfflineQueue() {
if (offline_queue_len > 0) {
offline_queue_len--;
for (int i = 0; i < offline_queue_len; i++) {
offline_queue[i] = offline_queue[i + 1];
}
}
}

float MyMesh::getAirtimeBudgetFactor() const {
return _prefs.airtime_factor;
}
Expand Down Expand Up @@ -1416,9 +1434,11 @@ void MyMesh::handleCmdFrame(size_t len) {
}
} else if (cmd_frame[0] == CMD_SYNC_NEXT_MESSAGE) {
int out_len;
if ((out_len = getFromOfflineQueue(out_frame)) > 0) {
_serial->writeFrame(out_frame, out_len);
if (_listener) _listener->onQueueSizeChanged(offline_queue_len);
if ((out_len = peekOfflineQueue(out_frame)) > 0) {
if (_serial->writeFrame(out_frame, out_len) >= out_len) {
popOfflineQueue();
if (_listener) _listener->onQueueSizeChanged(offline_queue_len);
}
} else {
out_frame[0] = RESP_CODE_NO_MORE_MESSAGES;
_serial->writeFrame(out_frame, 1);
Expand Down
2 changes: 2 additions & 0 deletions examples/companion_radio/MyMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ class MyMesh : public BaseChatMesh, public DataStoreHost {
void updateContactFromFrame(ContactInfo &contact, uint32_t& last_mod, const uint8_t *frame, int len);
void addToOfflineQueue(const uint8_t frame[], int len);
int getFromOfflineQueue(uint8_t frame[]);
int peekOfflineQueue(uint8_t frame[]);
void popOfflineQueue();
int getBlobByKey(const uint8_t key[], int key_len, uint8_t dest_buf[]) override {
return _store->getBlobByKey(key, key_len, dest_buf);
}
Expand Down
14 changes: 9 additions & 5 deletions src/helpers/MultiSerialInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,22 @@ class MultiSerialInterface : public BaseSerialInterface {
return 0;
}

// write frame to all enabled interfaces
// write frame to all enabled interfaces that have a client connected
// (an idle interface with no client must not count as a failed write)
bool anyWritten = false;
bool allSuccessful = true;
for(auto iface : _interfaces){
if(iface.instance && iface.instance->isEnabled()){
if(iface.instance->writeFrame(src, len) != len){
if(iface.instance && iface.instance->isEnabled() && iface.instance->isConnected()){
if(iface.instance->writeFrame(src, len) == len){
anyWritten = true;
} else {
allSuccessful = false;
}
}
}

// report success if all writes completed successfully
return allSuccessful ? len : 0;
// report success if all connected interfaces accepted the frame
return (anyWritten && allSuccessful) ? len : 0;
}

size_t checkRecvFrame(uint8_t dest[]) override {
Expand Down