Skip to content

Commit

Permalink
Fix alignment/padding issues non-linux devices #78
Browse files Browse the repository at this point in the history
Per #88
When receiving fragmented payloads, padding was not being added to the
frame on non-linux devices, but subtracted during reads.

- Remove padding altogether from AVR devices (#defined ARDUINO_ARCH_AVR)
- Add padding to received, fragmented payloads on non-AVR, non-Linux
devices (for 32-bit devices like ESP8266)

May have affected nRF24/RF24Mesh#71
  • Loading branch information
TMRh20 committed Apr 12, 2016
1 parent 0849bee commit 609bc2f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions RF24Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,11 @@ IF_SERIAL_DEBUG_FRAGMENTATION_L2(for(int i=0; i< frag_queue.message_size;i++){ S
memcpy(next_frame,&frag_queue,10);
memcpy(next_frame+10,frag_queue.message_buffer,frag_queue.message_size);
next_frame += (10+frag_queue.message_size);
#if !defined(ARDUINO_ARCH_AVR)
if(uint8_t padding = (frag_queue.message_size+10)%4){
next_frame += 4 - padding;
}
#endif
IF_SERIAL_DEBUG_FRAGMENTATION( printf_P(PSTR("enq size %d\n"),frag_queue.message_size); );
return true;
}else{
Expand Down Expand Up @@ -551,10 +556,11 @@ IF_SERIAL_DEBUG_FRAGMENTATION_L2(for(int i=0; i< frag_queue.message_size;i++){ S
//IF_SERIAL_DEBUG_FRAGMENTATION( for(int i=0; i<message_size;i++){ Serial.print(next_frame[i],HEX); Serial.print(" : "); } Serial.println(""); );

next_frame += (message_size + 10);
#if !defined(ARDUINO_ARCH_AVR)
if(uint8_t padding = (message_size+10)%4){
next_frame += 4 - padding;
}

#endif
//IF_SERIAL_DEBUG_FRAGMENTATION( Serial.print("Enq "); Serial.println(next_frame-frame_queue); );//printf_P(PSTR("enq %d\n"),next_frame-frame_queue); );

result = true;
Expand Down Expand Up @@ -655,10 +661,11 @@ uint16_t RF24Network::read(RF24NetworkHeader& header,void* message, uint16_t max
}
memmove(frame_queue,frame_queue+bufsize+10,sizeof(frame_queue)- bufsize);
next_frame-=bufsize+10;
#if !defined(ARDUINO_ARCH_AVR)
if(uint8_t padding = (bufsize+10)%4){
next_frame -= 4 - padding;
}

#endif
//IF_SERIAL_DEBUG(printf_P(PSTR("%lu: NET Received %s\n\r"),millis(),header.toString()));
}
#endif
Expand Down

0 comments on commit 609bc2f

Please sign in to comment.