Skip to content

Commit 67efa7a

Browse files
tekka007Yveaux
authored andcommitted
Move noACK control to transportSendWrite() (#1317)
1 parent e091471 commit 67efa7a

File tree

7 files changed

+20
-33
lines changed

7 files changed

+20
-33
lines changed

core/MyTransport.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -978,17 +978,15 @@ bool transportSendWrite(const uint8_t to, MyMessage &message)
978978
// msg length changes if signed
979979
const uint8_t totalMsgLength = HEADER_SIZE + ( message.getSigned() ? MAX_PAYLOAD_SIZE :
980980
message.getLength() );
981-
981+
const bool noACK = _transportConfig.passiveMode || (to == BROADCAST_ADDRESS);
982982
// send
983983
setIndication(INDICATION_TX);
984-
bool result = transportHALSend(to, &message, totalMsgLength,
985-
_transportConfig.passiveMode);
986-
// broadcasting (workaround counterfeits)
987-
result |= (to == BROADCAST_ADDRESS);
984+
const bool result = transportHALSend(to, &message, totalMsgLength,
985+
noACK);
988986

989987
TRANSPORT_DEBUG(PSTR("%sTSF:MSG:SEND,%" PRIu8 "-%" PRIu8 "-%" PRIu8 "-%" PRIu8 ",s=%" PRIu8 ",c=%"
990988
PRIu8 ",t=%" PRIu8 ",pt=%" PRIu8 ",l=%" PRIu8 ",sg=%" PRIu8 ",ft=%" PRIu8 ",st=%s:%s\n"),
991-
(_transportConfig.passiveMode ? "?" : result ? "" : "!"), message.getSender(), message.getLast(),
989+
(noACK ? "?" : result ? "" : "!"), message.getSender(), message.getLast(),
992990
to,
993991
message.getDestination(),
994992
message.getSensor(),

hal/transport/RFM69/MyTransportRFM69.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,7 @@ uint8_t transportGetAddress(void)
5959

6060
bool transportSend(const uint8_t to, const void *data, uint8_t len, const bool noACK)
6161
{
62-
if (noACK) {
63-
(void)RFM69_sendWithRetry(to, data, len, 0, 0);
64-
return true;
65-
}
66-
return RFM69_sendWithRetry(to, data, len);
62+
return RFM69_sendWithRetry(to, data, len, noACK);
6763
}
6864

6965
bool transportDataAvailable(void)

hal/transport/RFM69/driver/new/RFM69_new.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -609,22 +609,22 @@ LOCAL void RFM69_ATCmode(const bool onOff, const int16_t targetRSSI)
609609

610610

611611
LOCAL bool RFM69_sendWithRetry(const uint8_t recipient, const void *buffer,
612-
const uint8_t bufferSize, const uint8_t retries, const uint32_t retryWaitTimeMS)
612+
const uint8_t bufferSize, const bool noACK)
613613
{
614-
for (uint8_t retry = 0; retry <= retries; retry++) {
614+
for (uint8_t retry = 0; retry < RFM69_RETRIES; retry++) {
615615
RFM69_DEBUG(PSTR("RFM69:SWR:SEND,TO=%" PRIu8 ",SEQ=%" PRIu16 ",RETRY=%" PRIu8 "\n"), recipient,
616616
RFM69.txSequenceNumber,retry);
617617
rfm69_controlFlags_t flags = 0u; // reset all flags
618-
RFM69_setACKRequested(flags, (recipient != RFM69_BROADCAST_ADDRESS));
618+
RFM69_setACKRequested(flags, noACK);
619619
RFM69_setACKRSSIReport(flags, RFM69.ATCenabled);
620620
(void)RFM69_send(recipient, (uint8_t *)buffer, bufferSize, flags, !retry);
621-
if (recipient == RFM69_BROADCAST_ADDRESS) {
621+
if (noACK) {
622622
// no ACK requested
623623
return true;
624624
}
625625
// radio is in RX
626626
const uint32_t enterMS = hwMillis();
627-
while (hwMillis() - enterMS < retryWaitTimeMS && !RFM69.dataReceived) {
627+
while (hwMillis() - enterMS < RFM69_RETRY_TIMEOUT_MS && !RFM69.dataReceived) {
628628
RFM69_handler();
629629
if (RFM69.ackReceived) {
630630
// radio is in stdby

hal/transport/RFM69/driver/new/RFM69_new.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,13 +466,12 @@ LOCAL void RFM69_sendACK(const uint8_t recipient, const rfm69_sequenceNumber_t s
466466
* @param recipient
467467
* @param buffer
468468
* @param bufferSize
469-
* @param retries
470-
* @param retryWaitTimeMS
469+
* @param noACK
471470
* @return True if packet successfully sent
472471
*/
473472
LOCAL bool RFM69_sendWithRetry(const uint8_t recipient, const void *buffer,
474473
const uint8_t bufferSize,
475-
const uint8_t retries = RFM69_RETRIES, const uint32_t retryWaitTimeMS = RFM69_RETRY_TIMEOUT_MS);
474+
const bool noACK);
476475

477476
/**
478477
* @brief RFM69_setRadioMode

hal/transport/RFM95/MyTransportRFM95.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,7 @@ uint8_t transportGetAddress(void)
4444

4545
bool transportSend(const uint8_t to, const void *data, const uint8_t len, const bool noACK)
4646
{
47-
if (noACK) {
48-
(void)RFM95_sendWithRetry(to, data, len, 0, 0);
49-
return true;
50-
}
51-
return RFM95_sendWithRetry(to, data, len);
47+
return RFM95_sendWithRetry(to, data, len, noACK);
5248
}
5349

5450
bool transportDataAvailable(void)

hal/transport/RFM95/driver/RFM95.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -539,24 +539,24 @@ LOCAL bool RFM95_executeATC(const rfm95_RSSI_t currentRSSI, const rfm95_RSSI_t t
539539
}
540540

541541
LOCAL bool RFM95_sendWithRetry(const uint8_t recipient, const void *buffer,
542-
const uint8_t bufferSize, const uint8_t retries, const uint32_t retryWaitTime)
542+
const uint8_t bufferSize, const bool noACK)
543543
{
544-
for (uint8_t retry = 0; retry <= retries; retry++) {
544+
for (uint8_t retry = 0; retry < RFM95_RETRIES; retry++) {
545545
RFM95_DEBUG(PSTR("RFM95:SWR:SEND,TO=%" PRIu8 ",SEQ=%" PRIu16 ",RETRY=%" PRIu8 "\n"), recipient,
546546
RFM95.txSequenceNumber,
547547
retry);
548548
rfm95_controlFlags_t flags = 0u;
549-
RFM95_setACKRequested(flags, (recipient != RFM95_BROADCAST_ADDRESS));
549+
RFM95_setACKRequested(flags, noACK);
550550
// send packet
551551
if (!RFM95_send(recipient, (uint8_t *)buffer, bufferSize, flags, !retry)) {
552552
return false;
553553
}
554554
(void)RFM95_setRadioMode(RFM95_RADIO_MODE_RX);
555-
if (recipient == RFM95_BROADCAST_ADDRESS) {
555+
if (noACK) {
556556
return true;
557557
}
558558
const uint32_t enterMS = hwMillis();
559-
while (hwMillis() - enterMS < retryWaitTime && !RFM95.dataReceived) {
559+
while (hwMillis() - enterMS < RFM95_RETRY_TIMEOUT_MS && !RFM95.dataReceived) {
560560
RFM95_handler();
561561
if (RFM95.ackReceived) {
562562
const uint8_t sender = RFM95.currentPacket.header.sender;

hal/transport/RFM95/driver/RFM95.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,13 +402,11 @@ LOCAL void RFM95_sendACK(const uint8_t recipient, const rfm95_sequenceNumber_t s
402402
* @param recipient
403403
* @param buffer
404404
* @param bufferSize
405-
* @param retries
406-
* @param retryWaitTime
405+
* @param noACK
407406
* @return True if packet successfully sent
408407
*/
409408
LOCAL bool RFM95_sendWithRetry(const uint8_t recipient, const void *buffer,
410-
const uint8_t bufferSize, const uint8_t retries = RFM95_RETRIES,
411-
const uint32_t retryWaitTime = RFM95_RETRY_TIMEOUT_MS);
409+
const uint8_t bufferSize, const bool noACK);
412410
/**
413411
* @brief Wait until no channel activity detected
414412
* @return True if no channel activity detected, False if timeout occured

0 commit comments

Comments
 (0)