Skip to content

Commit

Permalink
Added packet peek functionality (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
Avamander authored Feb 9, 2018
1 parent a2ce4ae commit ce12854
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
34 changes: 27 additions & 7 deletions RF24Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,14 +604,10 @@ uint16_t RF24Network::parent() const
}

/******************************************************************/
/*uint8_t RF24Network::peekData(){
return frame_queue[0];
}*/

uint16_t RF24Network::peek(RF24NetworkHeader& header)
{
if ( available() )
if (available())
{
#if defined (RF24_LINUX)
RF24NetworkFrame frame = frame_queue.front();
Expand All @@ -630,12 +626,36 @@ uint16_t RF24Network::peek(RF24NetworkHeader& header)

/******************************************************************/

void RF24Network::peek(RF24NetworkHeader& header, void* message, uint16_t maxlen)
{
#if defined (RF24_LINUX)
if (available())
{ // TODO: Untested
RF24NetworkFrame frame = frame_queue.front();
memcpy(&header, &(frame.header), sizeof(RF24NetworkHeader));
memcpy(message, frame.message_buffer, maxlen);
}
#else
if(available())
{
memcpy(&header, frame_queue, 8); //Copy the header
if(maxlen > 0)
{
memcpy(message, frame_queue + 10, maxlen); //Copy the message
}
}
#endif
}

/******************************************************************/

uint16_t RF24Network::read(RF24NetworkHeader& header,void* message, uint16_t maxlen)
{
uint16_t bufsize = 0;

#if defined (RF24_LINUX)
if ( available() ) {
if (available())
{
RF24NetworkFrame frame = frame_queue.front();

// How much buffer size should we actually copy?
Expand All @@ -651,7 +671,7 @@ uint16_t RF24Network::read(RF24NetworkHeader& header,void* message, uint16_t max
frame_queue.pop();
}
#else
if ( available() )
if (available())
{

memcpy(&header,frame_queue,8);
Expand Down
13 changes: 13 additions & 0 deletions RF24Network.h
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,19 @@ class RF24Network
*/
uint16_t peek(RF24NetworkHeader& header);

/**
* Read the next available payload
*
* Reads the next available payload without advancing to the next
* incoming message. Useful for doing a transparent packet
* manipulation layer on top of RF24Network.
*
* @param[out] header The header (envelope) of this message
* @param[out] message Pointer to memory where the message should be placed
* @param maxlen Amount of bytes to copy to message.
*/
void peek(RF24NetworkHeader& header, void* message, uint16_t maxlen);

/**
* Read a message
*
Expand Down

0 comments on commit ce12854

Please sign in to comment.