Static and dynamic payloads now fully fixed and interoperable

This commit is contained in:
maniacbug 2011-08-02 16:30:43 -07:00
parent 4542464e0b
commit a31cafcc88
4 changed files with 31 additions and 16 deletions

View File

@ -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); 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); csn(LOW);
status = SPI.transfer( W_TX_PAYLOAD ); 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-- ) while ( data_len-- )
SPI.transfer(*current++); SPI.transfer(*current++);
while ( blank_len-- ) while ( blank_len-- )
@ -129,10 +132,13 @@ uint8_t RF24::read_payload(void* buf, uint8_t len)
uint8_t status; uint8_t status;
uint8_t* current = reinterpret_cast<uint8_t*>(buf); 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); csn(LOW);
status = SPI.transfer( R_RX_PAYLOAD ); 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-- ) while ( data_len-- )
*current++ = SPI.transfer(0xff); *current++ = SPI.transfer(0xff);
while ( blank_len-- ) 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): 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.setDataMode(SPI_MODE0);
SPI.setClockDivider(SPI_CLOCK_DIV8); 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 // Set generous timeouts, to make testing a little easier
write_register(SETUP_RETR,(B1111 << ARD) | (B1111 << ARC)); 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 // Not sure the use case of only having dynamic payload on certain
// pipes, so the library does not support it. // 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)); 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
View File

@ -26,7 +26,8 @@ private:
uint8_t csn_pin; /**< SPI Chip select */ uint8_t csn_pin; /**< SPI Chip select */
uint8_t payload_size; /**< Fixed size of payloads */ uint8_t payload_size; /**< Fixed size of payloads */
bool ack_payload_available; /**< Whether there is an ack payload waiting */ 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. */ uint64_t pipe0_reading_address; /**< Last address set on pipe 0 for reading. */
protected: protected:

View File

@ -193,9 +193,9 @@ void setup(void)
// Config 3 is static payloads only // Config 3 is static payloads only
if (configuration == '3') if (configuration == '3')
{ {
next_payload_size = max_payload_size; next_payload_size = 16;
payload_size_increments_by = 0; payload_size_increments_by = 0;
radio.setPayloadSize(16); radio.setPayloadSize(next_payload_size);
} }
else else
{ {
@ -351,6 +351,7 @@ void check_radio(void)
printf("FAILED "); printf("FAILED ");
one_failed(); one_failed();
} }
last_message_count = message_count;
} }
// If we're the receiver, we've received a time message // 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; size_t len = max_payload_size;
memset(receive_payload,0,max_payload_size); memset(receive_payload,0,max_payload_size);
if ( configuration != '3' ) if ( configuration == '3' )
len = next_payload_size;
else
len = radio.getDynamicPayloadSize(); len = radio.getDynamicPayloadSize();
radio.read( receive_payload, len ); radio.read( receive_payload, len );
@ -369,8 +372,7 @@ void check_radio(void)
receive_payload[len] = 0; receive_payload[len] = 0;
// Spew it // Spew it
len = strlen(receive_payload); // How much did we REALLY get? printf("Got payload size=%i value=%s strlen=%u\n\r",len,receive_payload,strlen(receive_payload));
printf("Got payload size=%i value=%s\n\r",len,receive_payload);
// Add an ack packet for the next time around. // Add an ack packet for the next time around.
// Here we will report back how many bytes we got this time. // Here we will report back how many bytes we got this time.

View File

@ -3,13 +3,13 @@
# Connect p6 to receiver, p4 to sender # Connect p6 to receiver, p4 to sender
jam p4 p6 || exit 1 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-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` kill `jobs -p`
./runtest.py /dev/tty.usbserial-A600eHIs 2 & ./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` kill `jobs -p`
exit 0 exit 0