This repository has been archived by the owner on Dec 27, 2023. It is now read-only.
/
mod_params.rs
100 lines (92 loc) · 2.9 KB
/
mod_params.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
use core::fmt::Debug;
pub use lora_modulation::{Bandwidth, CodingRate, SpreadingFactor};
/// Errors types reported during LoRa physical layer processing
#[allow(clippy::upper_case_acronyms)]
#[derive(Debug, defmt::Format, PartialEq)]
#[allow(missing_docs)]
pub enum RadioError {
SPI,
Reset,
RfSwitchRx,
RfSwitchTx,
Busy,
Irq,
DIO1,
DelayError,
OpError(u8),
InvalidBaseAddress(usize, usize),
PayloadSizeUnexpected(usize),
PayloadSizeMismatch(usize, usize),
InvalidSymbolTimeout,
RetentionListExceeded,
UnavailableSpreadingFactor,
UnavailableBandwidth,
UnavailableCodingRate,
InvalidBandwidthForFrequency,
InvalidSF6ExplicitHeaderRequest,
InvalidOutputPowerForFrequency,
HeaderError,
CRCErrorUnexpected,
CRCErrorOnReceive,
TransmitTimeout,
ReceiveTimeout,
PollingTimeout,
TimeoutUnexpected,
TransmitDoneUnexpected,
ReceiveDoneUnexpected,
DutyCycleUnsupported,
DutyCycleRxContinuousUnsupported,
CADUnexpected,
RngUnsupported,
}
/// Status for a received packet
#[derive(Clone, Copy)]
#[allow(missing_docs)]
pub struct PacketStatus {
pub rssi: i16,
pub snr: i16,
}
/// The state of the radio
#[derive(Clone, Copy, defmt::Format, PartialEq)]
#[allow(missing_docs)]
pub enum RadioMode {
Sleep, // sleep mode
Standby, // standby mode
FrequencySynthesis, // frequency synthesis mode
Transmit, // transmit mode
Receive, // receive mode
ReceiveDutyCycle, // receive duty cycle mode
ChannelActivityDetection, // channel activity detection mode
}
/// Modulation parameters for a send and/or receive communication channel
pub struct ModulationParams {
pub(crate) spreading_factor: SpreadingFactor,
pub(crate) bandwidth: Bandwidth,
pub(crate) coding_rate: CodingRate,
pub(crate) low_data_rate_optimize: u8,
pub(crate) frequency_in_hz: u32,
}
/// Packet parameters for a send or receive communication channel
pub struct PacketParams {
pub(crate) preamble_length: u16, // number of LoRa symbols in the preamble
pub(crate) implicit_header: bool, // if the header is explicit, it will be transmitted in the LoRa packet, but is not transmitted if the header is implicit (known fixed length)
pub(crate) payload_length: u8,
pub(crate) crc_on: bool,
pub(crate) iq_inverted: bool,
}
impl PacketParams {
pub(crate) fn set_payload_length(&mut self, payload_length: usize) -> Result<(), RadioError> {
if payload_length > 255 {
return Err(RadioError::PayloadSizeUnexpected(payload_length));
}
self.payload_length = payload_length as u8;
Ok(())
}
}
/// Receive duty cycle parameters
#[derive(Clone, Copy)]
#[allow(missing_docs)]
pub struct DutyCycleParams {
pub rx_time: u32, // receive interval
pub sleep_time: u32, // sleep interval
}