From 1fb51004134a66d001f3065ddf8bab50d7ff1e59 Mon Sep 17 00:00:00 2001 From: Crsarmv7l <85343771+Crsarmv7l@users.noreply.github.com> Date: Thu, 28 Mar 2024 13:44:10 -0400 Subject: [PATCH] [CC1101] 3 New CC1101 Functions (#1038) * getFrequency implementation * getFrequency Method * Get bitrate method * getBitRate * CalcRxBandwidth() method * CalcRxBandwidth(); * Fix Notes * Changes for pull * Changes for pull 2 * Update keywords.txt * Revert to hopefully bring in current * Fix () * Re add --- keywords.txt | 1 + src/modules/CC1101/CC1101.cpp | 18 ++++++++++++++++++ src/modules/CC1101/CC1101.h | 8 ++++++++ 3 files changed, 27 insertions(+) diff --git a/keywords.txt b/keywords.txt index cb129454..d9d59507 100644 --- a/keywords.txt +++ b/keywords.txt @@ -134,6 +134,7 @@ getSNR KEYWORD2 getDataRate KEYWORD2 setBitRate KEYWORD2 setRxBandwidth KEYWORD2 +autoSetRxBandwidth KEYWORD2 setAFCBandwidth KEYWORD2 setAFC KEYWORD2 setAFCAGCTrigger KEYWORD2 diff --git a/src/modules/CC1101/CC1101.cpp b/src/modules/CC1101/CC1101.cpp index 16bd25ee..2965a343 100644 --- a/src/modules/CC1101/CC1101.cpp +++ b/src/modules/CC1101/CC1101.cpp @@ -489,6 +489,24 @@ int16_t CC1101::setRxBandwidth(float rxBw) { return(RADIOLIB_ERR_INVALID_RX_BANDWIDTH); } +int16_t CC1101::autoSetRxBandwidth() { + // Uncertainty ~ +/- 40ppm for a cheap CC1101 + // Uncertainty * 2 for both transmitter and receiver + float uncertainty = ((this->frequency) * 40 * 2); + uncertainty = (uncertainty/1000); //Since bitrate is in kBit + float minbw = ((this->bitRate) + uncertainty); + + int possibles[16] = {58, 68, 81, 102, 116, 135, 162, 203, 232, 270, 325, 406, 464, 541, 650, 812}; + + for (int i = 0; i < 16; i++) { + if (possibles[i] > minbw) { + int16_t state = setRxBandwidth(possibles[i]); + return(state); + } + } + return(RADIOLIB_ERR_UNKNOWN); + } + int16_t CC1101::setFrequencyDeviation(float freqDev) { // set frequency deviation to lowest available setting (required for digimodes) float newFreqDev = freqDev; diff --git a/src/modules/CC1101/CC1101.h b/src/modules/CC1101/CC1101.h index bb979116..69b8e4eb 100644 --- a/src/modules/CC1101/CC1101.h +++ b/src/modules/CC1101/CC1101.h @@ -745,6 +745,14 @@ class CC1101: public PhysicalLayer { */ int16_t setRxBandwidth(float rxBw); + /*! + \brief calculates and sets Rx bandwidth based on the freq, baud and freq uncertainty. + Reimplement of atlas0fd00m's (RfCat) CalculatePktChanBw function. + Modified for worse ppm with the CC1101, and adjusted for the supportted CC1101 bw. + \returns \ref status_codes + */ + int16_t autoSetRxBandwidth(); + /*! \brief Sets frequency deviation. Allowed values range from 1.587 to 380.8 kHz. \param freqDev Frequency deviation to be set in kHz.