Skip to content

Commit 28d673e

Browse files
authored
Merge pull request #796 from 446564/mutable-queue
make offline queue channel messages mutable
2 parents 695473f + fca16f1 commit 28d673e

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

examples/companion_radio/MyMesh.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,29 @@ void MyMesh::updateContactFromFrame(ContactInfo &contact, uint32_t& last_mod, co
177177

178178
void MyMesh::addToOfflineQueue(const uint8_t frame[], int len) {
179179
if (offline_queue_len >= OFFLINE_QUEUE_SIZE) {
180-
MESH_DEBUG_PRINTLN("ERROR: offline_queue is full!");
180+
MESH_DEBUG_PRINTLN("WARN: offline_queue is full!");
181+
int pos = 0;
182+
while (pos < offline_queue_len) {
183+
if ((offline_queue[pos].buf[0] == RESP_CODE_CHANNEL_MSG_RECV) ||
184+
offline_queue[pos].buf[0] == RESP_CODE_CHANNEL_MSG_RECV_V3) {
185+
for (int i = pos; i < offline_queue_len; i++) { // delete oldest channel msg from queue
186+
offline_queue[i] = offline_queue[i + 1];
187+
}
188+
MESH_DEBUG_PRINTLN("INFO: removed oldest channel message from queue.");
189+
offline_queue[offline_queue_len - 1].len = len;
190+
memcpy(offline_queue[offline_queue_len - 1].buf, frame, len);
191+
return;
192+
}
193+
pos++;
194+
}
195+
MESH_DEBUG_PRINTLN("INFO: no channel messages to remove from queue.");
181196
} else {
182197
offline_queue[offline_queue_len].len = len;
183198
memcpy(offline_queue[offline_queue_len].buf, frame, len);
184199
offline_queue_len++;
185200
}
186201
}
202+
187203
int MyMesh::getFromOfflineQueue(uint8_t frame[]) {
188204
if (offline_queue_len > 0) { // check offline queue
189205
size_t len = offline_queue[0].len; // take from top of queue

0 commit comments

Comments
 (0)