-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
Since a fragment_id and fragment type is sent, we can include and restore the user-defined header type with fragmented payloads by including it with the final fragment, since we know its expected fragment_id and that this should be the last expected fragment.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -193,15 +193,15 @@ bool RF24Network::enqueue(RF24NetworkFrame frame) { | |
bool result = false; | ||
|
||
|
||
if (frame.header.fragment_id > 1 && (frame.header.type == NETWORK_MORE_FRAGMENTS || frame.header.type== NETWORK_FIRST_FRAGMENT)){ | ||
if ((frame.header.fragment_id > 1 && (frame.header.type == NETWORK_MORE_FRAGMENTS || frame.header.type== NETWORK_FIRST_FRAGMENT)) ){ | ||
//Set the more fragments flag to indicate a fragmented frame | ||
IF_SERIAL_DEBUG_FRAGMENTATION(printf("%u: FRG fragmented payload of size %i Bytes with fragmentID '%i' received.\n\r",millis(),frame.message_size,frame.header.fragment_id);); | ||
|
||
//Append payload | ||
appendFragmentToFrame(frame); | ||
result = true; | ||
|
||
} else if (frame.header.fragment_id == 1 && frame.header.type == NETWORK_LAST_FRAGMENT) { | ||
result = true; | ||
}else if ( frame.header.type == NETWORK_LAST_FRAGMENT) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
TMRh20
Author
Member
|
||
//Set the last fragment flag to indicate the last fragment | ||
IF_SERIAL_DEBUG_FRAGMENTATION(printf("%u: FRG Last fragment with size %i Bytes and fragmentID '%i' received.\n\r",millis(),frame.message_size,frame.header.fragment_id);); | ||
|
||
|
@@ -262,6 +262,10 @@ void RF24Network::appendFragmentToFrame(RF24NetworkFrame frame) { | |
//Append payload | ||
RF24NetworkFrame *f = &(frameFragmentsCache[ std::make_pair(frame.header.from_node,frame.header.id) ]); | ||
|
||
if(frame.header.type == NETWORK_LAST_FRAGMENT){ | ||
f->header.type = frame.header.fragment_id; | ||
This comment has been minimized.
Sorry, something went wrong.
reixd
Contributor
|
||
frame.header.fragment_id = 1; | ||
} | ||
//Error checking for missed fragments and payload size | ||
if(frame.header.fragment_id != f->header.fragment_id-1){ | ||
if(frame.header.fragment_id > f->header.fragment_id){ | ||
|
@@ -407,7 +411,7 @@ bool RF24Network::write(RF24NetworkHeader& header,const void* message, size_t le | |
|
||
IF_SERIAL_DEBUG_FRAGMENTATION(printf("%u: FRG Total message fragments %i\n\r",millis(),fragment_id);); | ||
|
||
bool firstFrag = 1; | ||
|
||
//Iterate over the payload chuncks | ||
// Assemble a new message, copy and fill out the header | ||
// Try to send this message | ||
|
@@ -422,10 +426,10 @@ bool RF24Network::write(RF24NetworkHeader& header,const void* message, size_t le | |
|
||
if (fragment_id == 1) { | ||
fragmentHeader.type = NETWORK_LAST_FRAGMENT; //Set the last fragment flag to indicate the last fragment | ||
fragmentHeader.fragment_id = header.type; | ||
This comment has been minimized.
Sorry, something went wrong.
reixd
Contributor
|
||
} else { | ||
if(firstFrag == 1){ | ||
if(msgCount == 0){ | ||
fragmentHeader.type = NETWORK_FIRST_FRAGMENT; | ||
firstFrag = 0; | ||
}else{ | ||
fragmentHeader.type = NETWORK_MORE_FRAGMENTS; //Set the more fragments flag to indicate a fragmented frame | ||
} | ||
|
2 comments
on commit 6a79f9b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you commited the header file with the new defined types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only new type is the NETWORK_FIRST_FRAGMENT, and yeah, it was added on the previous commit.
I think we should nevertheless check if (frame.header.fragment_id == 1), otherwise it would be a bad (fragmentation-)protocol behavior. Mostly it is redundant but could also be used to avoid obscure problems like a bit inversion during tx and this inversion does not affect the NRF24 CRC. A small chance is there ;)