Static and dynamic payloads now fully fixed and interoperable
This commit is contained in:
parent
4542464e0b
commit
a31cafcc88
22
RF24.cpp
22
RF24.cpp
|
@ -108,10 +108,13 @@ uint8_t RF24::write_payload(const void* buf, uint8_t len)
|
|||
|
||||
const uint8_t* current = reinterpret_cast<const uint8_t*>(buf);
|
||||
|
||||
uint8_t data_len = min(len,payload_size);
|
||||
uint8_t blank_len = dynamic_payloads_enabled ? 0 : payload_size - data_len;
|
||||
|
||||
//printf("[Writing %u bytes %u blanks]",data_len,blank_len);
|
||||
|
||||
csn(LOW);
|
||||
status = SPI.transfer( W_TX_PAYLOAD );
|
||||
uint8_t data_len = min(len,payload_size);
|
||||
uint8_t blank_len = payload_size - data_len;
|
||||
while ( data_len-- )
|
||||
SPI.transfer(*current++);
|
||||
while ( blank_len-- )
|
||||
|
@ -129,10 +132,13 @@ uint8_t RF24::read_payload(void* buf, uint8_t len)
|
|||
uint8_t status;
|
||||
uint8_t* current = reinterpret_cast<uint8_t*>(buf);
|
||||
|
||||
uint8_t data_len = min(len,payload_size);
|
||||
uint8_t blank_len = dynamic_payloads_enabled ? 0 : payload_size - data_len;
|
||||
|
||||
//printf("[Reading %u bytes %u blanks]",data_len,blank_len);
|
||||
|
||||
csn(LOW);
|
||||
status = SPI.transfer( R_RX_PAYLOAD );
|
||||
uint8_t data_len = min(len,payload_size);
|
||||
uint8_t blank_len = payload_size - data_len;
|
||||
while ( data_len-- )
|
||||
*current++ = SPI.transfer(0xff);
|
||||
while ( blank_len-- )
|
||||
|
@ -241,7 +247,8 @@ void RF24::print_address_register(prog_char* name, uint8_t reg, uint8_t qty)
|
|||
/****************************************************************************/
|
||||
|
||||
RF24::RF24(uint8_t _cepin, uint8_t _cspin):
|
||||
ce_pin(_cepin), csn_pin(_cspin), payload_size(32), ack_payload_available(false)
|
||||
ce_pin(_cepin), csn_pin(_cspin), payload_size(32), ack_payload_available(false),
|
||||
dynamic_payloads_enabled(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -300,6 +307,9 @@ void RF24::begin(void)
|
|||
SPI.setDataMode(SPI_MODE0);
|
||||
SPI.setClockDivider(SPI_CLOCK_DIV8);
|
||||
|
||||
// Disable dynamic payloads, to match dynamic_payloads_enabled setting
|
||||
write_register(DYNPD,0);
|
||||
|
||||
// Set generous timeouts, to make testing a little easier
|
||||
write_register(SETUP_RETR,(B1111 << ARD) | (B1111 << ARC));
|
||||
|
||||
|
@ -592,6 +602,8 @@ void RF24::enableDynamicPayloads(void)
|
|||
// Not sure the use case of only having dynamic payload on certain
|
||||
// pipes, so the library does not support it.
|
||||
write_register(DYNPD,read_register(DYNPD) | _BV(DPL_P5) | _BV(DPL_P4) | _BV(DPL_P3) | _BV(DPL_P2) | _BV(DPL_P1) | _BV(DPL_P0));
|
||||
|
||||
dynamic_payloads_enabled = true;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
|
3
RF24.h
3
RF24.h
|
@ -26,7 +26,8 @@ private:
|
|||
uint8_t csn_pin; /**< SPI Chip select */
|
||||
uint8_t payload_size; /**< Fixed size of payloads */
|
||||
bool ack_payload_available; /**< Whether there is an ack payload waiting */
|
||||
uint8_t ack_payload_length; /**< Dynamic size of pending ack payload. Note: not used. */
|
||||
bool dynamic_payloads_enabled; /**< Whether dynamic payloads are enabled. */
|
||||
uint8_t ack_payload_length; /**< Dynamic size of pending ack payload. */
|
||||
uint64_t pipe0_reading_address; /**< Last address set on pipe 0 for reading. */
|
||||
|
||||
protected:
|
||||
|
|
|
@ -193,9 +193,9 @@ void setup(void)
|
|||
// Config 3 is static payloads only
|
||||
if (configuration == '3')
|
||||
{
|
||||
next_payload_size = max_payload_size;
|
||||
next_payload_size = 16;
|
||||
payload_size_increments_by = 0;
|
||||
radio.setPayloadSize(16);
|
||||
radio.setPayloadSize(next_payload_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -351,6 +351,7 @@ void check_radio(void)
|
|||
printf("FAILED ");
|
||||
one_failed();
|
||||
}
|
||||
last_message_count = message_count;
|
||||
}
|
||||
|
||||
// If we're the receiver, we've received a time message
|
||||
|
@ -360,7 +361,9 @@ void check_radio(void)
|
|||
size_t len = max_payload_size;
|
||||
memset(receive_payload,0,max_payload_size);
|
||||
|
||||
if ( configuration != '3' )
|
||||
if ( configuration == '3' )
|
||||
len = next_payload_size;
|
||||
else
|
||||
len = radio.getDynamicPayloadSize();
|
||||
|
||||
radio.read( receive_payload, len );
|
||||
|
@ -369,8 +372,7 @@ void check_radio(void)
|
|||
receive_payload[len] = 0;
|
||||
|
||||
// Spew it
|
||||
len = strlen(receive_payload); // How much did we REALLY get?
|
||||
printf("Got payload size=%i value=%s\n\r",len,receive_payload);
|
||||
printf("Got payload size=%i value=%s strlen=%u\n\r",len,receive_payload,strlen(receive_payload));
|
||||
|
||||
// Add an ack packet for the next time around.
|
||||
// Here we will report back how many bytes we got this time.
|
||||
|
|
|
@ -3,13 +3,13 @@
|
|||
# Connect p6 to receiver, p4 to sender
|
||||
|
||||
jam p4 p6 || exit 1
|
||||
./runtest.py /dev/tty.usbserial-A600eHIs 3 &
|
||||
./runtest.py /dev/tty.usbserial-A40081RP 3 || exit 1
|
||||
kill `jobs -p`
|
||||
./runtest.py /dev/tty.usbserial-A600eHIs 1 &
|
||||
./runtest.py /dev/tty.usbserial-A40081RP 1 || exit 1
|
||||
./runtest.py /dev/tty.usbserial-A40081RP 1 || ( kill `jobs -p` && exit 1 )
|
||||
kill `jobs -p`
|
||||
./runtest.py /dev/tty.usbserial-A600eHIs 2 &
|
||||
./runtest.py /dev/tty.usbserial-A40081RP 2 || exit 1
|
||||
./runtest.py /dev/tty.usbserial-A40081RP 2 || ( kill `jobs -p` && exit 1 )
|
||||
kill `jobs -p`
|
||||
./runtest.py /dev/tty.usbserial-A600eHIs 3 &
|
||||
./runtest.py /dev/tty.usbserial-A40081RP 3 || ( kill `jobs -p` && exit 1 )
|
||||
kill `jobs -p`
|
||||
exit 0
|
||||
|
|
Loading…
Reference in New Issue