Skip to content

Commit

Permalink
Introduce network.external_queue
Browse files Browse the repository at this point in the history
- Add external_queue to simplify external data handling on Linux
devices. External data is no longer loaded into the user cache, but into
its own separate queue.
- Prevents issues when external data is received while waiting for a
network ACK
  • Loading branch information
TMRh20 committed Mar 28, 2015
1 parent 5622c65 commit ce0b421
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
24 changes: 16 additions & 8 deletions RF24Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ uint8_t RF24Network::update(void)
//if( (header->type < 148 || header->type > 150) && header->type != NETWORK_MORE_FRAGMENTS_NACK && header->type != EXTERNAL_DATA_TYPE && header->type!= NETWORK_LAST_FRAGMENT){
if( header->type != NETWORK_FIRST_FRAGMENT && header->type != NETWORK_MORE_FRAGMENTS && header->type != NETWORK_MORE_FRAGMENTS_NACK && header->type != EXTERNAL_DATA_TYPE && header->type!= NETWORK_LAST_FRAGMENT){
return returnVal;
}
}
}

if( enqueue(header) == 2 ){ //External data received
Expand Down Expand Up @@ -295,7 +295,12 @@ uint8_t RF24Network::enqueue(RF24NetworkHeader* header) {
RF24NetworkFrame *f = &(frameFragmentsCache[ std::make_pair(frame.header.id,frame.header.from_node) ]);
result=f->header.type == EXTERNAL_DATA_TYPE ? 2 : 1;

frame_queue.push( frameFragmentsCache[ std::make_pair(frame.header.id,frame.header.from_node) ] );
//Load external payloads into a separate queue on linux
if(result == 2){
external_queue.push( frameFragmentsCache[ std::make_pair(frame.header.id,frame.header.from_node) ] );
}else{
frame_queue.push( frameFragmentsCache[ std::make_pair(frame.header.id,frame.header.from_node) ] );
}
frameFragmentsCache.erase( std::make_pair(frame.header.id,frame.header.from_node) );
}

Expand All @@ -304,8 +309,14 @@ uint8_t RF24Network::enqueue(RF24NetworkHeader* header) {

IF_SERIAL_DEBUG(printf_P(PSTR("%u: NET Enqueue @%x "),millis(),frame_queue.size()));
// Copy the current frame into the frame queue
frame_queue.push(frame);
result=frame.header.type == EXTERNAL_DATA_TYPE ? 2 : 1;
//Load external payloads into a separate queue on linux
if(result == 2){
external_queue.push( frame );
}else{
frame_queue.push( frame );
}


}/* else {
//Undefined/Unknown header.type received. Drop frame!
Expand Down Expand Up @@ -582,7 +593,7 @@ uint16_t RF24Network::peek(RF24NetworkHeader& header)
{
#if defined (RF24_LINUX)
RF24NetworkFrame frame = frame_queue.front();
memcpy(&header,&frame,sizeof(RF24NetworkHeader));
memcpy(&header,&frame.header,sizeof(RF24NetworkHeader));
return frame.message_size;
#else
RF24NetworkFrame *frame = (RF24NetworkFrame*)(frame_queue);
Expand Down Expand Up @@ -620,7 +631,6 @@ uint16_t RF24Network::read(RF24NetworkHeader& header,void* message, uint16_t max
{

memcpy(&header,frame_queue,8);
//bufsize = (uint16_t)frame_queue[8];
RF24NetworkFrame *f = (RF24NetworkFrame*)frame_queue;
bufsize = f->message_size;

Expand Down Expand Up @@ -826,7 +836,7 @@ bool RF24Network::write(uint16_t to_node, uint8_t directTo) // Direct To: 0 = F
{
bool ok = false;
bool isAckType = false;
if(frame_buffer[6] > 64 && frame_buffer[6] < 192 && frame_buffer[6] != NETWORK_ACK ){ ++isAckType; }
if(frame_buffer[6] > 64 && frame_buffer[6] < 192 ){ isAckType=true; }

/*if( ( (frame_buffer[7] % 2) && frame_buffer[6] == NETWORK_MORE_FRAGMENTS) ){
isAckType = 0;
Expand Down Expand Up @@ -880,7 +890,6 @@ bool RF24Network::write(uint16_t to_node, uint8_t directTo) // Direct To: 0 = F
IF_SERIAL_DEBUG_ROUTING( printf_P(PSTR("%lu MAC: Route OK to 0%o ACK sent to 0%o\n"),millis(),to_node,header->from_node); );
#endif
}




Expand All @@ -905,7 +914,6 @@ bool RF24Network::write(uint16_t to_node, uint8_t directTo) // Direct To: 0 = F
break;
}
}

}
if(!fastFragTransfer){
#if !defined (DUAL_HEAD_RADIO)
Expand Down
4 changes: 3 additions & 1 deletion RF24Network.h
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,9 @@ class RF24Network
/** The raw system frame buffer of received data. */

uint8_t frame_buffer[MAX_FRAME_SIZE];

#if defined (RF24_LINUX)
std::queue<RF24NetworkFrame> external_queue;
#endif

#if !defined ( DISABLE_FRAGMENTATION ) && !defined (RF24_LINUX)
/**
Expand Down

0 comments on commit ce0b421

Please sign in to comment.