LCOV - code coverage report
Current view: top level - src/modules/SX127x - SX1273.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 18 68 26.5 %
Date: 2026-11-08 19:43:08 Functions: 4 5 80.0 %

          Line data    Source code
       1             : #include "SX1273.h"
       2             : #if !RADIOLIB_EXCLUDE_SX127X
       3             : 
       4           1 : SX1273::SX1273(Module* mod) : SX1272(mod) {
       5             : 
       6           1 : }
       7             : 
       8           0 : int16_t SX1273::begin(const ConfigLoRa_t& cfg) {
       9             :   // execute common part
      10           0 :   uint8_t version = RADIOLIB_SX1272_CHIP_VERSION;
      11           0 :   int16_t state = SX127x::begin(&version, 1, cfg.syncWord, cfg.preambleLength);
      12           0 :   RADIOLIB_ASSERT(state);
      13             : 
      14             :   // configure publicly accessible settings
      15           0 :   state = setBandwidth(cfg.bandwidth);
      16           0 :   RADIOLIB_ASSERT(state);
      17             : 
      18           0 :   state = setFrequency(cfg.frequency);
      19           0 :   RADIOLIB_ASSERT(state);
      20             : 
      21           0 :   state = setSpreadingFactor(cfg.spreadingFactor);
      22           0 :   RADIOLIB_ASSERT(state);
      23             : 
      24           0 :   state = setCodingRate(cfg.codingRate);
      25           0 :   RADIOLIB_ASSERT(state);
      26             : 
      27           0 :   state = setOutputPower(cfg.power);
      28           0 :   RADIOLIB_ASSERT(state);
      29             : 
      30           0 :   state = setGain(this->gain);
      31           0 :   RADIOLIB_ASSERT(state);
      32             : 
      33             :   // set publicly accessible settings that are not a part of begin method
      34           0 :   state = setCRC(true);
      35           0 :   return(state);
      36             : }
      37             : 
      38           2 : int16_t SX1273::setSpreadingFactor(uint8_t sf) {
      39             :   uint8_t newSpreadingFactor;
      40             : 
      41             :   // check allowed spreading factor values
      42           2 :   switch(sf) {
      43           0 :     case 6:
      44           0 :       newSpreadingFactor = RADIOLIB_SX127X_SF_6;
      45           0 :       break;
      46           0 :     case 7:
      47           0 :       newSpreadingFactor = RADIOLIB_SX127X_SF_7;
      48           0 :       break;
      49           0 :     case 8:
      50           0 :       newSpreadingFactor = RADIOLIB_SX127X_SF_8;
      51           0 :       break;
      52           0 :     case 9:
      53           0 :       newSpreadingFactor = RADIOLIB_SX127X_SF_9;
      54           0 :       break;
      55           2 :     default:
      56           2 :       return(RADIOLIB_ERR_INVALID_SPREADING_FACTOR);
      57             :   }
      58             : 
      59             :   // set spreading factor and if successful, save the new setting
      60           0 :   int16_t state = setSpreadingFactorRaw(newSpreadingFactor);
      61           0 :   if(state == RADIOLIB_ERR_NONE) {
      62           0 :     SX127x::spreadingFactor = sf;
      63             :   }
      64             : 
      65           0 :   return(state);
      66             : }
      67             : 
      68           1 : int16_t SX1273::checkDataRate(DataRate_t dr, ModemType_t modem) {
      69           1 :   int16_t state = RADIOLIB_ERR_UNKNOWN;
      70             : 
      71             :   // retrieve modem if not supplied
      72           1 :   if(modem == RADIOLIB_MODEM_NONE) {
      73           1 :     state = this->getModem(&modem);
      74           1 :     RADIOLIB_ASSERT(state);
      75             :   }
      76             : 
      77             :   // select interpretation based on modem
      78           1 :   if(modem == RADIOLIB_MODEM_FSK) {
      79           0 :     RADIOLIB_CHECK_RANGE(dr.fsk.bitRate, 500, RADIOLIB_UNIT_KILO(300), RADIOLIB_ERR_INVALID_BIT_RATE);
      80           0 :     if(!((dr.fsk.freqDev + dr.fsk.bitRate/2 <= RADIOLIB_UNIT_KILO(250)) && (dr.fsk.freqDev <= RADIOLIB_UNIT_KILO(200)))) {
      81           0 :       return(RADIOLIB_ERR_INVALID_FREQUENCY_DEVIATION);
      82             :     }
      83           0 :     return(RADIOLIB_ERR_NONE);
      84             : 
      85           1 :   } else if(modem == RADIOLIB_MODEM_LORA) {
      86           1 :     RADIOLIB_CHECK_RANGE(dr.lora.spreadingFactor, 6, 9, RADIOLIB_ERR_INVALID_SPREADING_FACTOR);
      87           0 :     RADIOLIB_CHECK_RANGE(dr.lora.bandwidth, RADIOLIB_UNIT_KILO(125), RADIOLIB_UNIT_KILO(500), RADIOLIB_ERR_INVALID_BANDWIDTH);
      88           0 :     RADIOLIB_CHECK_RANGE(dr.lora.codingRate, 4, 8, RADIOLIB_ERR_INVALID_CODING_RATE);
      89           0 :     return(RADIOLIB_ERR_NONE);
      90             :   
      91             :   }
      92             : 
      93           0 :   return(state);
      94             : }
      95             : 
      96           1 : int16_t SX1273::setModem(ModemType_t modem) {
      97           1 :   switch(modem) {
      98             :     // the default 434 MHz is out of range for SX1273, so keep the current frequency
      99           0 :     case(ModemType_t::RADIOLIB_MODEM_LORA): {
     100           0 :       ConfigLoRa_t cfg;
     101           0 :       cfg.frequency = this->frequency;
     102           0 :       return(this->begin(cfg));
     103             :     } break;
     104           0 :     case(ModemType_t::RADIOLIB_MODEM_FSK): {
     105           0 :       ConfigFSK_t cfg;
     106           0 :       cfg.frequency = this->frequency;
     107           0 :       return(this->beginFSK(cfg));
     108             :     } break;
     109           1 :     default:
     110           1 :       return(RADIOLIB_ERR_WRONG_MODEM);
     111             :   }
     112             : }
     113             : 
     114             : #endif

Generated by: LCOV version 1.14