Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/Development'
Browse files Browse the repository at this point in the history
  • Loading branch information
TMRh20 committed Mar 20, 2016
2 parents 6909ede + 09a9ccf commit 0e102a2
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions RF24Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ bool RF24Network::appendFragmentToFrame(RF24NetworkFrame frame) {
uint8_t RF24Network::enqueue(RF24NetworkHeader* header)
{
bool result = false;
uint8_t message_size = frame_size - sizeof(RF24NetworkHeader);
uint16_t message_size = frame_size - sizeof(RF24NetworkHeader);

IF_SERIAL_DEBUG(printf_P(PSTR("%lu: NET Enqueue @%x "),millis(),next_frame-frame_queue));

Expand Down Expand Up @@ -545,13 +545,16 @@ IF_SERIAL_DEBUG_FRAGMENTATION_L2(for(int i=0; i< frag_queue.message_size;i++){ S
#else
if(message_size + (next_frame-frame_queue) <= MAIN_BUFFER_SIZE){
memcpy(next_frame,&frame_buffer,8);
RF24NetworkFrame *f = (RF24NetworkFrame*)next_frame;
f->message_size = message_size;
memcpy(next_frame+10,frame_buffer+sizeof(RF24NetworkHeader),message_size);

memcpy(next_frame+8,&message_size,2);
memcpy(next_frame+10,frame_buffer+8,message_size);

//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(uint8_t padding = (message_size+10)%4){
next_frame += 4 - padding;
}

//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 @@ -603,7 +606,9 @@ uint16_t RF24Network::peek(RF24NetworkHeader& header)
#else
RF24NetworkFrame *frame = (RF24NetworkFrame*)(frame_queue);
memcpy(&header,&frame->header,sizeof(RF24NetworkHeader));
return frame->message_size;
uint16_t msg_size;
memcpy(&msg_size,frame+8,2);
return msg_size;
#endif
}
return 0;
Expand Down Expand Up @@ -636,8 +641,7 @@ uint16_t RF24Network::read(RF24NetworkHeader& header,void* message, uint16_t max
{

memcpy(&header,frame_queue,8);
RF24NetworkFrame *f = (RF24NetworkFrame*)frame_queue;
bufsize = f->message_size;
memcpy(&bufsize,frame_queue+8,2);

if (maxlen > 0)
{
Expand All @@ -651,6 +655,9 @@ 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(uint8_t padding = (bufsize+10)%4){
next_frame -= 4 - padding;
}

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

0 comments on commit 0e102a2

Please sign in to comment.