From 3913d5689ce400e55d831820aeb538578a1ec949 Mon Sep 17 00:00:00 2001 From: Felix Rusu Date: Wed, 5 Jun 2019 11:38:14 -0400 Subject: [PATCH] null terminate radio.DATA --- RFM69.cpp | 11 ++++------- RFM69.h | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/RFM69.cpp b/RFM69.cpp index d42e149..d2aef58 100644 --- a/RFM69.cpp +++ b/RFM69.cpp @@ -27,7 +27,7 @@ #include #include -uint8_t RFM69::DATA[RF69_MAX_DATA_LEN]; +uint8_t RFM69::DATA[RF69_MAX_DATA_LEN+1]; uint8_t RFM69::_mode; // current transceiver state uint8_t RFM69::DATALEN; uint16_t RFM69::SENDERID; @@ -361,9 +361,9 @@ void RFM69::interruptHandler() { ACK_REQUESTED = CTLbyte & RFM69_CTL_REQACK; // extract ACK-requested flag interruptHook(CTLbyte); // TWS: hook to derived class interrupt function - for (uint8_t i = 0; i < DATALEN; i++) - DATA[i] = SPI.transfer(0); - if (DATALEN < RF69_MAX_DATA_LEN) DATA[DATALEN] = 0; // add null at end of string + for (uint8_t i = 0; i < DATALEN; i++) DATA[i] = SPI.transfer(0); + + DATA[DATALEN] = 0; // add null at end of string // add null at end of string unselect(); setMode(RF69_MODE_RX); } @@ -393,8 +393,6 @@ void RFM69::receiveBegin() { // checks if a packet was received and/or puts transceiver in receive (ie RX or listen) mode bool RFM69::receiveDone() { -//ATOMIC_BLOCK(ATOMIC_FORCEON) -//{ if (_haveData) { _haveData = false; interruptHandler(); @@ -410,7 +408,6 @@ bool RFM69::receiveDone() { } receiveBegin(); return false; -//} } // To enable encryption: radio.encrypt("ABCDEFGHIJKLMNOP"); diff --git a/RFM69.h b/RFM69.h index 10a53e2..e82dd6a 100644 --- a/RFM69.h +++ b/RFM69.h @@ -168,7 +168,7 @@ class RFM69 { public: - static uint8_t DATA[RF69_MAX_DATA_LEN]; // recv/xmit buf, including header & crc bytes + static uint8_t DATA[RF69_MAX_DATA_LEN+1]; // RX/TX payload buffer, including end of string NULL char static uint8_t DATALEN; static uint16_t SENDERID; static uint16_t TARGETID; // should match _address