Enhance llcc68 definitions with new bandwidth and coding rate enums

- Added a new bandwidth enum value for 7.8MHz and corresponding string conversion function.
- Introduced a string conversion function for coding rates.
- Implemented a utility function to safely convert uint8_t to optional for spreading factors.
- Enhanced the modulation parameters structure with a to_string method for better representation.
This commit is contained in:
2025-06-03 18:33:51 +08:00
parent ee1c1a0497
commit c549538844
2 changed files with 63 additions and 2 deletions

View File

@ -6,6 +6,9 @@
#define LLCC68_DEFINITIONS_H
#include <cstddef>
#include <cstdint>
#include <optional>
#include <string>
#include <format>
#include <tuple>
#include <variant>
#include "radiolib_definitions.hpp"
@ -13,6 +16,7 @@
namespace app::driver::llcc68 {
using freq_t = float;
enum LoRaBandwidth : uint8_t {
BW_7_8 = 0x00,
BW_10_4 = 0x08,
BW_15_6 = 0x01,
BW_20_8 = 0x09,
@ -24,6 +28,33 @@ enum LoRaBandwidth : uint8_t {
BW_500_0 = 0x06,
};
inline const char *bw_to_string(const LoRaBandwidth &bw) {
switch (bw) {
case LoRaBandwidth::BW_7_8:
return "7.8MHz";
case LoRaBandwidth::BW_10_4:
return "10.4MHz";
case LoRaBandwidth::BW_15_6:
return "15.6MHz";
case LoRaBandwidth::BW_20_8:
return "20.8MHz";
case LoRaBandwidth::BW_31_25:
return "31.25MHz";
case LoRaBandwidth::BW_41_7:
return "41.7MHz";
case LoRaBandwidth::BW_62_5:
return "62.5MHz";
case LoRaBandwidth::BW_125_0:
return "125.0MHz";
case LoRaBandwidth::BW_250_0:
return "250.0MHz";
case LoRaBandwidth::BW_500_0:
return "500.0MHz";
default:
return "Unknown";
}
}
enum LoRaCodingRate : uint8_t {
CR_4_5 = 0x01,
CR_4_6 = 0x02,
@ -31,6 +62,21 @@ enum LoRaCodingRate : uint8_t {
CR_4_8 = 0x04,
};
inline const char *cr_to_string(const LoRaCodingRate &cr) {
switch (cr) {
case LoRaCodingRate::CR_4_5:
return "4/5";
case LoRaCodingRate::CR_4_6:
return "4/6";
case LoRaCodingRate::CR_4_7:
return "4/7";
case LoRaCodingRate::CR_4_8:
return "4/8";
default:
return "Unknown";
}
}
constexpr uint16_t DEFAULT_PREAMBLE_LEN = 8;
constexpr uint8_t DEFAULT_SYNC_WORD = RADIOLIB_SX126X_SYNC_WORD_PRIVATE;
constexpr uint8_t DEFAULT_CRC_TYPE = RADIOLIB_SX126X_LORA_CRC_OFF;
@ -43,6 +89,13 @@ constexpr auto DEFAULT_BW = BW_250_0;
constexpr auto DEFAULT_CR = CR_4_5;
constexpr auto DEFAULT_LDR_OPTIMIZE = RADIOLIB_SX126X_LORA_LOW_DATA_RATE_OPTIMIZE_OFF;
inline std::optional<uint8_t> sf_from_uint8_t(const uint8_t sf) {
if (sf < 6 || sf > 12) {
return std::nullopt;
}
return sf;
}
struct modulation_params_t {
uint8_t bw;
@ -58,6 +111,14 @@ struct modulation_params_t {
.ldr_optimize = DEFAULT_LDR_OPTIMIZE,
};
}
std::string to_string() const {
return std::format("mod_params: bw={}, sf={}, cr={}, ldr_optimize={}",
bw_to_string(static_cast<LoRaBandwidth>(bw)),
sf,
cr_to_string(static_cast<LoRaCodingRate>(cr)),
ldr_optimize ? "ON" : "OFF");
}
};
struct packet_params_t {