Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions RHReliableDatagram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//
// Author: Mike McCauley (mikem@airspayce.com)
// Copyright (C) 2011 Mike McCauley
// $Id: RHReliableDatagram.cpp,v 1.15 2015/12/11 01:10:24 mikem Exp $
// $Id: RHReliableDatagram.cpp,v 1.17 2017/03/08 09:30:47 mikem Exp mikem $

#include <RHReliableDatagram.h>

Expand All @@ -22,6 +22,7 @@ RHReliableDatagram::RHReliableDatagram(RHGenericDriver& driver, uint8_t thisAddr
_lastSequenceNumber = 0;
_timeout = RH_DEFAULT_TIMEOUT;
_retries = RH_DEFAULT_RETRIES;
memset(_seenIds, 0, sizeof(_seenIds));
}

////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -109,7 +110,7 @@ bool RHReliableDatagram::sendtoWait(uint8_t* buf, uint8_t len, uint8_t address)
}

////////////////////////////////////////////////////////////////////
bool RHReliableDatagram::recvfromAck(uint8_t* buf, uint8_t* len, uint8_t* from, uint8_t* to, uint8_t* id, uint8_t* flags)
bool RHReliableDatagram::recvfromAck(uint8_t* buf, uint8_t* len, uint8_t* from, uint8_t* to, uint8_t* id, uint8_t* flags, bool skipDeDupCheck)
{
uint8_t _from;
uint8_t _to;
Expand All @@ -121,21 +122,27 @@ bool RHReliableDatagram::recvfromAck(uint8_t* buf, uint8_t* len, uint8_t* from,
// Never ACK an ACK
if (!(_flags & RH_FLAGS_ACK))
{
// Its a normal message for this node, not an ACK
if (_to != RH_BROADCAST_ADDRESS)
// Its a normal message not an ACK
if (_to ==_thisAddress)
{
// Its for this node and
// Its not a broadcast, so ACK it
// Acknowledge message with ACK set in flags and ID set to received ID
acknowledge(_id, _from);
}
// If we have not seen this message before, then we are interested in it
if (_id != _seenIds[_from])
if ( (_id != _seenIds[_from]) || skipDeDupCheck )
{
if (from) *from = _from;
if (to) *to = _to;
if (id) *id = _id;
if (flags) *flags = _flags;
_seenIds[_from] = _id;

if(!skipDeDupCheck)
{
_seenIds[_from] = _id;
}

return true;
}
// Else just re-ack it and wait for a new one
Expand Down
2 changes: 1 addition & 1 deletion RHReliableDatagram.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class RHReliableDatagram : public RHDatagram
/// \param[in] flags If present and not NULL, the referenced uint8_t will be set to the FLAGS
/// (not just those addressed to this node).
/// \return true if a valid message was copied to buf
bool recvfromAck(uint8_t* buf, uint8_t* len, uint8_t* from = NULL, uint8_t* to = NULL, uint8_t* id = NULL, uint8_t* flags = NULL);
bool recvfromAck(uint8_t* buf, uint8_t* len, uint8_t* from = NULL, uint8_t* to = NULL, uint8_t* id = NULL, uint8_t* flags = NULL, bool skipDeDupCheck = false);

/// Similar to recvfromAck(), this will block until either a valid message available for this node
/// or the timeout expires. Starts the receiver automatically.
Expand Down