Skip to content

Commit a7f2362

Browse files
TMRh202bndy5
andauthored
Utilize new stopListening function (#251)
- Utilize new stopListening() function - Check for MAX_PAYLOAD_SIZE on fragemented payloads - `pipe_address()` use buffer by reference avoids allocating 64-bit addresses - adjust min PIO deps' versions --------- Co-authored-by: Brendan <2bndy5@gmail.com>
1 parent 99c7d62 commit a7f2362

File tree

3 files changed

+25
-28
lines changed

3 files changed

+25
-28
lines changed

RF24Network.cpp

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,11 @@ void ESBNetwork<radio_t>::begin(uint8_t _channel, uint16_t _node_address)
107107

108108
// Open up all listening pipes
109109
uint8_t i = NUM_PIPES;
110-
while (i--)
111-
radio.openReadingPipe(i, pipe_address(_node_address, i));
110+
uint8_t address[5];
111+
while (i--) {
112+
pipe_address(_node_address, i, address);
113+
radio.openReadingPipe(i, address);
114+
}
112115

113116
radio.startListening();
114117
}
@@ -143,11 +146,9 @@ uint8_t ESBNetwork<radio_t>::update(void)
143146
#else
144147
frame_size = MAX_FRAME_SIZE;
145148
#endif
146-
147149
if (!frame_size) {
148150
return NETWORK_CORRUPTION;
149151
}
150-
151152
// Fetch the payload, and see if this was the last one.
152153
radio.read(frame_buffer, frame_size);
153154

@@ -293,7 +294,7 @@ uint8_t ESBNetwork<radio_t>::enqueue(RF24NetworkHeader* header)
293294

294295
result = f->header.type == EXTERNAL_DATA_TYPE ? 2 : 1;
295296

296-
if (f->header.id > 0 && f->message_size > 0) {
297+
if (f->header.id > 0 && f->message_size > 0 && f->message_size <= MAX_PAYLOAD_SIZE) {
297298
//Load external payloads into a separate queue on linux
298299
if (result == 2) {
299300
external_queue.push(frameFragmentsCache[frame.header.from_node]);
@@ -749,7 +750,6 @@ bool ESBNetwork<radio_t>::main_write(RF24NetworkHeader& header, const void* mess
749750

750751
if (header.to_node != NETWORK_MULTICAST_ADDRESS) {
751752
networkFlags |= FLAG_FAST_FRAG;
752-
radio.stopListening();
753753
}
754754

755755
uint8_t retriesPerFrag = 0;
@@ -1014,15 +1014,11 @@ bool ESBNetwork<radio_t>::write_to_pipe(uint16_t node, uint8_t pipe, bool multic
10141014
{
10151015
bool ok = false;
10161016

1017-
// Open the correct pipe for writing.
1018-
// First, stop listening so we can talk
1019-
if (!(networkFlags & FLAG_FAST_FRAG)) {
1020-
radio.stopListening();
1021-
}
1022-
10231017
if (!(networkFlags & FLAG_FAST_FRAG) || (frame_buffer[6] == NETWORK_FIRST_FRAGMENT && networkFlags & FLAG_FAST_FRAG)) {
1018+
uint8_t address[5];
1019+
pipe_address(node, pipe, address);
1020+
radio.stopListening(address);
10241021
radio.setAutoAck(0, !multicast);
1025-
radio.openWritingPipe(pipe_address(node, pipe));
10261022
}
10271023

10281024
ok = radio.writeFast(frame_buffer, frame_size, 0);
@@ -1192,7 +1188,9 @@ void ESBNetwork<radio_t>::multicastLevel(uint8_t level)
11921188
{
11931189
_multicast_level = level;
11941190
radio.stopListening();
1195-
radio.openReadingPipe(0, pipe_address(levelToAddress(level), 0));
1191+
uint8_t address[5];
1192+
pipe_address(levelToAddress(level), 0, address);
1193+
radio.openReadingPipe(0, address);
11961194
radio.startListening();
11971195
}
11981196

@@ -1215,7 +1213,7 @@ uint16_t ESBNetwork<radio_t>::levelToAddress(uint8_t level)
12151213
/******************************************************************/
12161214

12171215
template<class radio_t>
1218-
uint64_t ESBNetwork<radio_t>::pipe_address(uint16_t node, uint8_t pipe)
1216+
void ESBNetwork<radio_t>::pipe_address(uint16_t node, uint8_t pipe, uint8_t* address)
12191217
{
12201218

12211219
static uint8_t address_translation[] = { 0xc3,
@@ -1234,8 +1232,7 @@ uint64_t ESBNetwork<radio_t>::pipe_address(uint16_t node, uint8_t pipe)
12341232
#endif
12351233
#endif
12361234
};
1237-
uint64_t result = 0xCCCCCCCCCCLL;
1238-
uint8_t* out = reinterpret_cast<uint8_t*>(&result);
1235+
memset(address, 0xCC, 5);
12391236

12401237
// Translate the address to use our optimally chosen radio address bytes
12411238
uint8_t count = 1;
@@ -1245,7 +1242,7 @@ uint64_t ESBNetwork<radio_t>::pipe_address(uint16_t node, uint8_t pipe)
12451242
#if defined(RF24NetworkMulticast)
12461243
if (pipe != 0 || !node)
12471244
#endif
1248-
out[count] = address_translation[(dec % 8)]; // Convert our decimal values to octal, translate them to address bytes, and set our address
1245+
address[count] = address_translation[(dec % 8)]; // Convert our decimal values to octal, translate them to address bytes, and set our address
12491246

12501247
dec /= 8;
12511248
count++;
@@ -1254,14 +1251,12 @@ uint64_t ESBNetwork<radio_t>::pipe_address(uint16_t node, uint8_t pipe)
12541251
#if defined(RF24NetworkMulticast)
12551252
if (pipe != 0 || !node)
12561253
#endif
1257-
out[0] = address_translation[pipe];
1254+
address[0] = address_translation[pipe];
12581255
#if defined(RF24NetworkMulticast)
12591256
else
1260-
out[1] = address_translation[count - 1];
1257+
address[1] = address_translation[count - 1];
12611258
#endif
1262-
IF_RF24NETWORK_DEBUG(uint32_t* top = reinterpret_cast<uint32_t*>(out + 1); printf_P(PSTR("NET Pipe %i on node 0%o has address %x%x\n\r"), pipe, node, *top, *out));
1263-
1264-
return result;
1259+
IF_RF24NETWORK_DEBUG(uint32_t* top = reinterpret_cast<uint32_t*>(address + 1); printf_P(PSTR("NET Pipe %i on node 0%o has address %x%x\n\r"), pipe, node, *top, *address));
12651260
}
12661261

12671262
/************************ Sleep Mode ******************************************/

RF24Network.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,12 @@
123123
//#define NETWORK_ACK_REQUEST 192
124124

125125
/**
126-
* Messages of this type indicate the network is being overrun with data.
126+
* Messages of this type indicate the network is being overrun with data & RF24Network::available() has returned from a loop.
127127
**/
128128
#define NETWORK_OVERRUN 160
129129

130130
/**
131-
* Messages of this type indicate radio data corruption & the RX FIFO has been flushed.
131+
* Messages of this type indicate the radio has encoutered corrupted data & the RX FIFO has been flushed.
132132
**/
133133
#define NETWORK_CORRUPTION 161
134134

@@ -984,7 +984,7 @@ class ESBNetwork
984984
uint16_t node_mask; /** The bits which contain significant node address information */
985985

986986
/* Given the Logical node address & a pipe number, this returns the Physical address assigned to the radio's pipes. */
987-
uint64_t pipe_address(uint16_t node, uint8_t pipe);
987+
void pipe_address(uint16_t node, uint8_t pipe, uint8_t* address);
988988

989989
#if defined ENABLE_NETWORK_STATS
990990
uint32_t nFails;

library.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@
1212
{
1313
"name": "RF24",
1414
"authors": "nRF24",
15-
"frameworks": "arduino"
15+
"frameworks": "arduino",
16+
"version": ">=1.5"
1617
},
1718
{
1819
"name": "nrf_to_nrf",
1920
"authors": "TMRh20",
2021
"frameworks": "arduino",
2122
"platforms": [
2223
"nordicnrf52"
23-
]
24+
],
25+
"version": ">=1.2.16"
2426
}
2527
],
2628
"export": {

0 commit comments

Comments
 (0)