Skyward boardcore
Loading...
Searching...
No Matches
SX1278LoraTimings.h
Go to the documentation of this file.
1/* Copyright (c) 2022 Skyward Experimental Rocketry
2 * Author: Davide Mor
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23#pragma once
24
25#include <cstdint>
26
27namespace Boardcore
28{
29
30namespace SX1278
31{
32
33namespace Lora
34{
35
39inline constexpr uint32_t symbolDuration(uint32_t spreading_factor,
40 uint32_t bandwidth)
41{
42 // The number of chips contained in each symbol is 2^spreadingFactor
43 uint32_t chip_count = (1 << spreading_factor);
44
45 // The number of chips per seconds is equal to the bandwidth
46 uint32_t chips_per_second = bandwidth;
47
48 // With an SR of 12 (4096) this _barely_ fits in an uint32_t
49 return (chip_count * 1000000) / chips_per_second;
50}
51
55inline constexpr uint32_t nominalBitrate(uint32_t spreading_factor,
56 uint32_t bandwidth)
57{
58 // The number of bits per symbol is equal to the spreading factor
59 uint32_t bits_per_symbol = spreading_factor;
60
61 // Calculate the number of symbols per seconds based on the symbol duration
62 uint32_t symbols_per_second =
63 (1000000 / symbolDuration(spreading_factor, bandwidth));
64
65 return symbols_per_second * bits_per_symbol;
66}
67
71inline constexpr uint32_t effectiveBitrate(uint32_t spreading_factor,
72 uint32_t bandwidth,
73 uint32_t coding_rate)
74{
75 // Input user bits
76 uint32_t input_bits = 4;
77 // Output transmitted bits
78 uint32_t output_bits = 4 + coding_rate;
79
80 return (nominalBitrate(spreading_factor, bandwidth) / output_bits) *
81 input_bits;
82}
83
84} // namespace Lora
85
86} // namespace SX1278
87
88} // namespace Boardcore
constexpr uint32_t symbolDuration(uint32_t spreading_factor, uint32_t bandwidth)
Computes the symbol duration in microseconds.
constexpr uint32_t effectiveBitrate(uint32_t spreading_factor, uint32_t bandwidth, uint32_t coding_rate)
Computes the actual usable bitrate in b/s.
constexpr uint32_t nominalBitrate(uint32_t spreading_factor, uint32_t bandwidth)
Computes the nominal (without error correction) bitrate in b/s.
This file includes all the types the logdecoder script will decode.