Skip to content

Commit bc791c5

Browse files
committed
Change split to be more like TCP assembly
1 parent 9b028c2 commit bc791c5

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

MeshBase.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ void MeshBase::Update()
5252
bool done = false;
5353
do {
5454
uint8_t len = radio.getDynamicPayloadSize();
55-
uint8_t buff[40];
56-
done = radio.read(buff, min(len, sizeof(buff)));
55+
byte buff[MAX_PAYLOAD_SIZE];
56+
done = radio.read(buff, len);
5757
HandlePacket(buff, len);
5858
} while (!done);
5959
}
@@ -85,7 +85,7 @@ void MeshBase::HandlePacket(const byte* data, uint8_t len)
8585
const MeshBase::Message* msg = (struct MeshBase::Message*)data;
8686
uint8_t payload_length = len - sizeof(Message);
8787
const byte* payload = data + sizeof(Message);
88-
if (msg->split_enabled)
88+
if (msg->split_more || msg->split_part != 0)
8989
{
9090
// Re-assembly needed
9191
// TODO: Re-assemble packets
@@ -98,6 +98,7 @@ void MeshBase::HandlePacket(const byte* data, uint8_t len)
9898
OnMessage(msg, payload, payload_length);
9999
break;
100100
}
101+
delete data;
101102
}
102103
}
103104

@@ -148,13 +149,13 @@ void MeshBase::SendMessage(uint32_t to, uint8_t type, const void* data, uint8_t
148149
msg->ttl = 0;
149150
msg->type = type;
150151
msg->address_from = address;
151-
msg->split_enabled = length > MAX_PAYLOAD_SIZE;
152152

153153
uint8_t num_pkts = (length / MAX_PAYLOAD_SIZE) + 1;
154154
for (uint8_t num = 0; num < num_pkts; ++num)
155155
{
156156
uint8_t remaining_length = length - (num * MAX_PAYLOAD_SIZE);
157157
msg->split_part = num;
158+
msg->split_more = remaining_length > MAX_PAYLOAD_SIZE;
158159
memcpy(buff + sizeof(Message), (const byte*)data + (num * MAX_PAYLOAD_SIZE), min(remaining_length, MAX_PAYLOAD_SIZE));
159160

160161
radio.stopListening();

MeshBase.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ class MeshBase
2020

2121
struct Message
2222
{
23-
uint8_t protocol_version;
24-
uint8_t ttl;
25-
uint8_t type;
26-
bool split_enabled : 1;
23+
uint8_t protocol_version : 4;
24+
uint8_t ttl : 4;
25+
uint8_t msg_id;
26+
bool split_more : 1;
2727
uint8_t split_part : 7;
28+
uint8_t type;
2829
uint32_t address_from;
2930
} PACKED;
3031

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy