From fbc65dedcfd0e95c2d5c406ede3434369408a78c Mon Sep 17 00:00:00 2001 From: Felix Rusu Date: Tue, 21 Jan 2020 12:52:45 -0500 Subject: [PATCH] Replace promiscuous() with spyMode() --- RFM69.cpp | 19 ++++++++++++------- RFM69.h | 5 +++-- keywords.txt | 2 +- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/RFM69.cpp b/RFM69.cpp index 2efbcea..41bf357 100644 --- a/RFM69.cpp +++ b/RFM69.cpp @@ -43,7 +43,7 @@ RFM69::RFM69(uint8_t slaveSelectPin, uint8_t interruptPin, bool isRFM69HW) _slaveSelectPin = slaveSelectPin; _interruptPin = interruptPin; _mode = RF69_MODE_STANDBY; - _promiscuousMode = false; + _spyMode = false; _powerLevel = 31; _isRFM69HW = isRFM69HW; #if defined(RF69_LISTENMODE_ENABLE) @@ -349,7 +349,7 @@ void RFM69::interruptHandler() { TARGETID |= (uint16_t(CTLbyte) & 0x0C) << 6; //10 bit address (most significant 2 bits stored in bits(2,3) of CTL byte SENDERID |= (uint16_t(CTLbyte) & 0x03) << 8; //10 bit address (most sifnigicant 2 bits stored in bits(0,1) of CTL byte - if(!(_promiscuousMode || TARGETID == _address || TARGETID == RF69_BROADCAST_ADDR) // match this node's address, or broadcast address or anything in promiscuous mode + if(!(_spyMode || TARGETID == _address || TARGETID == RF69_BROADCAST_ADDR) // match this node's address, or broadcast address or anything in spy mode || PAYLOADLEN < 3) // address situation could receive packets that are malformed and don't fit this libraries extra fields { PAYLOADLEN = 0; @@ -501,13 +501,18 @@ void RFM69::unselect() { #endif } -// true = disable filtering to capture all frames on network -// false = enable node/broadcast filtering to capture only frames sent to this/broadcast address -void RFM69::promiscuous(bool onOff) { - _promiscuousMode = onOff; +// true = disable ID filtering to capture all packets on network, regardless of TARGETID +// false (default) = enable node/broadcast ID filtering to capture only frames sent to this/broadcast address +void RFM69::spyMode(bool onOff) { + _spyMode = onOff; //writeReg(REG_PACKETCONFIG1, (readReg(REG_PACKETCONFIG1) & 0xF9) | (onOff ? RF_PACKET1_ADRSFILTERING_OFF : RF_PACKET1_ADRSFILTERING_NODEBROADCAST)); } +void RFM69::promiscuous(bool onOff) { + Serial.println("\nRFM69::promiscuous(bool): DEPRECATED, use spyMode(bool) instead!\n"); + spyMode(onOff); +} + // for RFM69HW only: you must call setHighPower(true) after initialize() or else transmission won't work void RFM69::setHighPower(bool onOff) { _isRFM69HW = onOff; @@ -979,7 +984,7 @@ void RFM69::listenModeInterruptHandler(void) PAYLOADLEN = SPI.transfer(0); PAYLOADLEN = PAYLOADLEN > 64 ? 64 : PAYLOADLEN; // precaution TARGETID = SPI.transfer(0); - if(!(_promiscuousMode || TARGETID == _address || TARGETID == RF69_BROADCAST_ADDR) // match this node's address, or broadcast address or anything in promiscuous mode + if(!(_spyMode || TARGETID == _address || TARGETID == RF69_BROADCAST_ADDR) // match this node's address, or broadcast address or anything in spy mode || PAYLOADLEN < 3) // address situation could receive packets that are malformed and don't fit this library's extra fields { listenModeReset(); diff --git a/RFM69.h b/RFM69.h index b970d88..4c277df 100644 --- a/RFM69.h +++ b/RFM69.h @@ -204,7 +204,8 @@ class RFM69 { void encrypt(const char* key); void setCS(uint8_t newSPISlaveSelect); int16_t readRSSI(bool forceTrigger=false); // *current* signal strength indicator; e.g. < -90dBm says the frequency channel is free + ready to transmit - void promiscuous(bool onOff=true); + void spyMode(bool onOff=true); + void promiscuous(bool onOff=true); //deprecated, replaced with spyMode() virtual void setHighPower(bool onOFF=true); // has to be called after initialize() for RFM69HW virtual void setPowerLevel(uint8_t level); // reduce/increase transmit power level void sleep(); @@ -228,7 +229,7 @@ class RFM69 { uint8_t _interruptPin; uint8_t _interruptNum; uint16_t _address; - bool _promiscuousMode; + bool _spyMode; uint8_t _powerLevel; bool _isRFM69HW; #if defined (SPCR) && defined (SPSR) diff --git a/keywords.txt b/keywords.txt index 48381d0..6d4fd20 100644 --- a/keywords.txt +++ b/keywords.txt @@ -30,7 +30,7 @@ getFrequency KEYWORD2 encrypt KEYWORD2 setCS KEYWORD2 readRSSI KEYWORD2 -promiscuous KEYWORD2 +spyMode KEYWORD2 setHighPower KEYWORD2 sleep KEYWORD2 readReg KEYWORD2