LCOV - code coverage report
Current view: top level - src/modules/LR2021 - LR2021_cmds_ook.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 62 0.0 %
Date: 2026-02-22 10:42:45 Functions: 0 9 0.0 %

          Line data    Source code
       1             : #include "LR2021.h"
       2             : 
       3             : #include "../LR11x0/LR_common.h"
       4             : 
       5             : #include <string.h>
       6             : #include <math.h>
       7             : 
       8             : #if !RADIOLIB_EXCLUDE_LR2021
       9             : 
      10           0 : int16_t LR2021::setOokModulationParams(uint32_t bitRate, uint8_t pulseShape, uint8_t rxBw, uint8_t depth) {
      11             :   uint8_t buff[] = { 
      12           0 :     (uint8_t)((bitRate >> 24) & 0xFF), (uint8_t)((bitRate >> 16) & 0xFF),
      13           0 :     (uint8_t)((bitRate >> 8) & 0xFF), (uint8_t)(bitRate & 0xFF),
      14             :     pulseShape, rxBw, depth,
      15           0 :   };
      16           0 :   return(this->SPIcommand(RADIOLIB_LR2021_CMD_SET_OOK_MODULATION_PARAMS, true, buff, sizeof(buff)));
      17             : }
      18             : 
      19           0 : int16_t LR2021::setOokPacketParams(uint16_t preambleLen, uint8_t addrComp, uint8_t packetFormat, uint16_t payloadLen, uint8_t crc, uint8_t manchester) {
      20             :   uint8_t buff[] = { 
      21           0 :     (uint8_t)((preambleLen >> 8) & 0xFF), (uint8_t)(preambleLen & 0xFF),
      22           0 :     (uint8_t)((addrComp << 2) | ((uint8_t)packetFormat & 0x03)),
      23           0 :     (uint8_t)((payloadLen >> 8) & 0xFF), (uint8_t)(payloadLen & 0xFF),
      24           0 :     (uint8_t)(((crc << 4) & 0xF0) | (manchester & 0x0F)),
      25           0 :   };
      26           0 :   return(this->SPIcommand(RADIOLIB_LR2021_CMD_SET_OOK_PACKET_PARAMS, true, buff, sizeof(buff)));
      27             : }
      28             : 
      29           0 : int16_t LR2021::setOokCrcParams(uint32_t poly, uint32_t init) {
      30             :   uint8_t buff[] = { 
      31           0 :     (uint8_t)((poly >> 24) & 0xFF), (uint8_t)((poly >> 16) & 0xFF),
      32           0 :     (uint8_t)((poly >> 8) & 0xFF), (uint8_t)(poly & 0xFF),
      33           0 :     (uint8_t)((init >> 24) & 0xFF), (uint8_t)((init >> 16) & 0xFF),
      34           0 :     (uint8_t)((init >> 8) & 0xFF), (uint8_t)(init & 0xFF),
      35           0 :   };
      36           0 :   return(this->SPIcommand(RADIOLIB_LR2021_CMD_SET_OOK_CRC_PARAMS, true, buff, sizeof(buff)));
      37             : }
      38             : 
      39           0 : int16_t LR2021::setOokSyncword(const uint8_t* syncWord, size_t syncWordLen, bool msbFirst) {
      40           0 :   uint8_t buff[5] = { 0 };
      41           0 :   for(size_t i = 0; i < syncWordLen; i++) {
      42           0 :     buff[3 - i] = syncWord[i];
      43             :   }
      44           0 :   buff[4] = (uint8_t)msbFirst << 7 | ((syncWordLen*8) & 0x7F);
      45           0 :   return(this->SPIcommand(RADIOLIB_LR2021_CMD_SET_OOK_SYNCWORD, true, buff, sizeof(buff)));
      46             : }
      47             : 
      48           0 : int16_t LR2021::setOokAddress(uint8_t addrNode, uint8_t addrBroadcast) {
      49           0 :   uint8_t buff[] = { addrNode, addrBroadcast };
      50           0 :   return(this->SPIcommand(RADIOLIB_LR2021_CMD_SET_OOK_ADDRESS, true, buff, sizeof(buff)));
      51             : }
      52             : 
      53           0 : int16_t LR2021::getOokRxStats(uint16_t* packetRx, uint16_t* crcError, uint16_t* lenError) {
      54           0 :   uint8_t buff[6] = { 0 };
      55           0 :   int16_t state = this->SPIcommand(RADIOLIB_LR2021_CMD_GET_OOK_RX_STATS, false, buff, sizeof(buff));
      56           0 :   if(packetRx) { *packetRx = ((uint16_t)(buff[0]) << 8) | (uint16_t)buff[1]; }
      57           0 :   if(crcError) { *crcError = ((uint16_t)(buff[2]) << 8) | (uint16_t)buff[3]; }
      58           0 :   if(lenError) { *lenError = ((uint16_t)(buff[4]) << 8) | (uint16_t)buff[5]; }
      59           0 :   return(state);
      60             : }
      61             : 
      62           0 : int16_t LR2021::getOokPacketStatus(uint16_t* packetLen, float* rssiAvg, float* rssiSync, bool* addrMatchNode, bool* addrMatchBroadcast, float* lqi) {
      63           0 :   uint8_t buff[6] = { 0 };
      64           0 :   int16_t state = this->SPIcommand(RADIOLIB_LR2021_CMD_GET_OOK_PACKET_STATUS, false, buff, sizeof(buff));
      65             :   uint16_t raw;
      66           0 :   if(packetLen) { *packetLen = ((uint16_t)(buff[0]) << 8) | (uint16_t)buff[1]; }
      67           0 :   if(rssiAvg) {
      68           0 :     raw = (uint16_t)buff[2] << 1;
      69           0 :     raw |= (buff[4] & 0x04) >> 2;
      70           0 :     *rssiAvg = (float)raw / -2.0f;
      71             :   }
      72           0 :   if(rssiSync) {
      73           0 :     raw = (uint16_t)buff[3] << 1;
      74           0 :     raw |= (buff[4] & 0x01);
      75           0 :     *rssiSync = (float)raw / -2.0f;
      76             :   }
      77           0 :   if(addrMatchNode) { *addrMatchNode = (buff[4] & 0x10); }
      78           0 :   if(addrMatchBroadcast) { *addrMatchBroadcast = (buff[4] & 0x20); }
      79           0 :   if(lqi) { *lqi = buff[5] * 4.0f; }
      80           0 :   return(state);
      81             : }
      82             : 
      83           0 : int16_t LR2021::setOokDetector(uint16_t preamblePattern, uint8_t patternLen, uint8_t patternNumRepeaters, bool syncWordRaw, bool sofDelimiterRising, uint8_t sofDelimiterLen) {
      84             :   uint8_t buff[] = { 
      85           0 :     (uint8_t)((preamblePattern >> 8) & 0xFF), (uint8_t)(preamblePattern & 0xFF),
      86           0 :     (uint8_t)(patternLen & 0x0F), (uint8_t)(patternNumRepeaters & 0x1F),
      87           0 :     (uint8_t)(((uint8_t)syncWordRaw << 5) | ((uint8_t)sofDelimiterRising << 4) | (sofDelimiterLen & 0x0F)),
      88           0 :   };
      89           0 :   return(this->SPIcommand(RADIOLIB_LR2021_CMD_SET_OOK_DETECTOR, true, buff, sizeof(buff)));
      90             : }
      91             : 
      92           0 : int16_t LR2021::setOokWhiteningParams(uint8_t bitIdx, uint16_t poly, uint16_t init) {
      93             :   uint8_t buff[] = {
      94           0 :     (uint8_t)((bitIdx << 4) | ((poly >> 8) & 0x0FF)), (uint8_t)(poly & 0xFF),
      95           0 :      (uint8_t)((init >> 8) & 0xFF), (uint8_t)(init & 0xFF),
      96           0 :   };
      97           0 :   return(this->SPIcommand(RADIOLIB_LR2021_CMD_SET_OOK_WHITENING_PARAMS, true, buff, sizeof(buff)));
      98             : }
      99             : 
     100             : #endif

Generated by: LCOV version 1.14