From 012c39e7f59bc1f249022c2775a8c3cb0635d335 Mon Sep 17 00:00:00 2001 From: Federico Maggi Date: Tue, 13 Apr 2021 15:25:28 +0200 Subject: [PATCH] Addressing PR#279 comments --- .gitignore | 2 +- src/modules/CC1101/CC1101.cpp | 22 +++++++++++++++++++--- src/modules/CC1101/CC1101.h | 9 ++++++++- src/modules/RF69/RF69.cpp | 4 ++++ src/modules/RF69/RF69.h | 11 +++++------ 5 files changed, 37 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 444a1ef0..58d33796 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,4 @@ extras/decoder/log.txt extras/decoder/out.txt # PlatformIO -.pio* \ No newline at end of file +.pio* diff --git a/src/modules/CC1101/CC1101.cpp b/src/modules/CC1101/CC1101.cpp index e096f4dd..5650852a 100644 --- a/src/modules/CC1101/CC1101.cpp +++ b/src/modules/CC1101/CC1101.cpp @@ -269,7 +269,7 @@ int16_t CC1101::startTransmit(uint8_t* data, size_t len, uint8_t addr) { if (_packetLengthConfig == CC1101_LENGTH_CONFIG_VARIABLE) { // enforce variable len limit. - if (len > 254) { + if (len > CC1101_MAX_PACKET_LENGTH - 1) { return (ERR_PACKET_TOO_LONG); } @@ -307,6 +307,12 @@ int16_t CC1101::startTransmit(uint8_t* data, size_t len, uint8_t addr) { dataSent += bytesToWrite; } else { // wait for radio to send some data. + /* + * Does this work for all rates? If 1 ms is longer than the 1ms delay + * then the entire FIFO will be transmitted during that delay. + * + * TODO: drop this delay(1) or come up with a better solution: + */ delay(1); } } @@ -349,7 +355,7 @@ int16_t CC1101::readData(uint8_t* data, size_t len) { } uint8_t bytesInFIFO = SPIgetRegValue(CC1101_REG_RXBYTES, 6, 0); - uint16_t readBytes = 0; + size_t readBytes = 0; uint32_t lastPop = millis(); // keep reading from FIFO until we get all the packet. @@ -360,6 +366,12 @@ int16_t CC1101::readData(uint8_t* data, size_t len) { RADIOLIB_DEBUG_PRINTLN(F("No data for more than 5mS. Stop here.")); break; } else { + /* + * Does this work for all rates? If 1 ms is longer than the 1ms delay + * then the entire FIFO will be transmitted during that delay. + * + * TODO: drop this delay(1) or come up with a better solution: + */ delay(1); bytesInFIFO = SPIgetRegValue(CC1101_REG_RXBYTES, 6, 0); continue; @@ -392,7 +404,7 @@ int16_t CC1101::readData(uint8_t* data, size_t len) { _rawLQI = val & 0x7F; // check CRC - if (_crcOn && (val & 0b10000000) == 0b00000000) { + if (_crcOn && (val & CC1101_CRC_OK) == CC1101_CRC_ERROR) { return (ERR_CRC_MISMATCH); } } @@ -786,6 +798,10 @@ int16_t CC1101::setPromiscuousMode(bool promiscuous) { return(state); } +bool CC1101::getPromiscuousMode() { + return (_promiscuous); +} + int16_t CC1101::setDataShaping(uint8_t sh) { // set mode to standby int16_t state = standby(); diff --git a/src/modules/CC1101/CC1101.h b/src/modules/CC1101/CC1101.h index a956c344..55ffaa71 100644 --- a/src/modules/CC1101/CC1101.h +++ b/src/modules/CC1101/CC1101.h @@ -602,7 +602,7 @@ class CC1101: public PhysicalLayer { \param dir Signal change direction. Defaults to RISING. */ - void setGdo0Action(void (*func)(void), RADIOLIB_INTERRUPT_STATUS dir = FALLING); + void setGdo0Action(void (*func)(void), RADIOLIB_INTERRUPT_STATUS dir = RISING); /*! \brief Clears interrupt service routine to call when GDO0 activates. @@ -847,6 +847,13 @@ class CC1101: public PhysicalLayer { */ int16_t setPromiscuousMode(bool promiscuous = true); + /*! + \brief Get whether the modem is in promiscuous mode: no packet filtering (e.g., no preamble, sync word, address, CRC). + + \returns Whether the modem is in promiscuous mode + */ + bool getPromiscuousMode(); + /*! \brief Sets Gaussian filter bandwidth-time product that will be used for data shaping. Allowed value is RADIOLIB_SHAPING_0_5. Set to RADIOLIB_SHAPING_NONE to disable data shaping. diff --git a/src/modules/RF69/RF69.cpp b/src/modules/RF69/RF69.cpp index aa5ec80a..f3b11151 100644 --- a/src/modules/RF69/RF69.cpp +++ b/src/modules/RF69/RF69.cpp @@ -910,4 +910,8 @@ void RF69::clearIRQFlags() { _mod->SPIwriteRegister(RF69_REG_IRQ_FLAGS_2, 0b11111111); } +int16_t SPIsetRegValue(uint8_t reg, uint8_t value, uint8_t msb = 7, uint8_t lsb = 0, uint8_t checkInterval = 2) { + return (_mod->SPIsetRegValue(reg, value, msb, lsb, checkInterval)); +} + #endif diff --git a/src/modules/RF69/RF69.h b/src/modules/RF69/RF69.h index ee2564ab..789f19e4 100644 --- a/src/modules/RF69/RF69.h +++ b/src/modules/RF69/RF69.h @@ -874,13 +874,12 @@ class RF69: public PhysicalLayer { #endif Module* _mod; - // SPI read overrides to set bit for burst write and status registers access - int16_t SPIgetRegValue(uint8_t reg, uint8_t msb = 7, uint8_t lsb = 0); + /*! + \brief Proxy to _mod->SPIsetRegValue (to avoid exposing _mod) + + \returns \ref status code + */ int16_t SPIsetRegValue(uint8_t reg, uint8_t value, uint8_t msb = 7, uint8_t lsb = 0, uint8_t checkInterval = 2); - void SPIreadRegisterBurst(uint8_t reg, uint8_t numBytes, uint8_t* inBytes); - uint8_t SPIreadRegister(uint8_t reg); - void SPIwriteRegisterBurst(uint8_t reg, uint8_t* data, size_t len); - void SPIwriteRegister(uint8_t reg, uint8_t data); #if !defined(RADIOLIB_GODMODE) protected: