Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3 New CC1101 Functions #1038

Merged
merged 13 commits into from
Mar 28, 2024
3 changes: 2 additions & 1 deletion keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ getSNR KEYWORD2
getDataRate KEYWORD2
setBitRate KEYWORD2
setRxBandwidth KEYWORD2
autoSetRxBandwidth KEYWORD2
setAFCBandwidth KEYWORD2
setAFC KEYWORD2
setAFCAGCTrigger KEYWORD2
Expand Down Expand Up @@ -436,4 +437,4 @@ RADIOLIB_ERR_N_FCNT_DOWN_INVALID LITERAL1
RADIOLIB_ERR_A_FCNT_DOWN_INVALID LITERAL1
RADIOLIB_ERR_DATA_RATE_INVALID LITERAL1
RADIOLIB_ERR_DWELL_TIME_EXCEEDED LITERAL1
RADIOLIB_ERR_CHECKSUM_MISMATCH LITERAL1
RADIOLIB_ERR_CHECKSUM_MISMATCH LITERAL1
18 changes: 18 additions & 0 deletions src/modules/CC1101/CC1101.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Crsarmv7l marked this conversation as resolved.
Show resolved Hide resolved

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;
Expand Down
8 changes: 8 additions & 0 deletions src/modules/CC1101/CC1101.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.