Skip to content

Commit

Permalink
Merge lthiery PR (#85)
Browse files Browse the repository at this point in the history
* make some things public

* use lora_modulation types for SF, BW, CR (#84)

* use lora_modulation types for SF, BW, CR

* bump version in toml

---------

Co-authored-by: Louis Thiery <[email protected]>
  • Loading branch information
madninja and lthiery authored Nov 13, 2024
1 parent eccaa20 commit b1bfd5e
Show file tree
Hide file tree
Showing 11 changed files with 375 additions and 246 deletions.
6 changes: 0 additions & 6 deletions .cargo/config

This file was deleted.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "semtech-udp"
version = "0.11.0"
version = "0.12.0"
authors = ["Louis Thiery <[email protected]>"]
edition = "2021"
description = "Semtech UDP provides serialization and deserialization of packets complying with the Semtech UDP protocol"
Expand All @@ -23,6 +23,7 @@ required-features = ["client"]
[dependencies]
arrayref = "0"
base64 = ">=0.21"
lora-modulation = ">=0.1.5"
macaddr = "1"
num_enum = "0"
rand = "0"
Expand Down
4 changes: 2 additions & 2 deletions examples/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
Event::PacketReceived(rxpk, gateway_mac) => {
println!("{rxpk:?}");
let data = vec![1, 2, 3, 4];
let tmst = rxpk.get_timestamp() + 1_000_000;
let tmst = rxpk.timestamp() + 1_000_000;

let txpk = pull_resp::TxPk {
time: Time::by_tmst(tmst),
Expand All @@ -43,7 +43,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
powe: 27,
modu: Modulation::LORA,
datr: DataRate::default(),
codr: CodingRate::_4_5,
codr: Some(CodingRate::_4_5),
ipol: true,
data: PhyData::new(data),
fdev: None,
Expand Down
12 changes: 2 additions & 10 deletions examples/server_split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
rfch: 0,
powe: cli.power as u64,
modu: Modulation::LORA,
datr: DataRate::new(cli.spreading_factor.clone(), cli.bandwidth.clone()),
codr: CodingRate::_4_5,
datr: DataRate::new(SpreadingFactor::_12, Bandwidth::_125KHz),
codr: Some(CodingRate::_4_5),
ipol: cli.polarization_inversion,
data: PhyData::new(data),
fdev: None,
Expand Down Expand Up @@ -140,14 +140,6 @@ pub struct Opt {
#[structopt(long, default_value = "868.1")]
frequency: f64,

/// Spreading Factor (eg: SF12)
#[structopt(long, default_value = "SF12")]
spreading_factor: SpreadingFactor,

/// Bandwdith (eg: BW125)
#[structopt(long, default_value = "BW125")]
bandwidth: Bandwidth,

/// Polarization inversion (set true when sending to devices)
#[structopt(long)]
polarization_inversion: bool,
Expand Down
2 changes: 1 addition & 1 deletion src/client_runtime/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ pub enum Error {
#[error("Join error: {0}")]
Join(#[from] tokio::task::JoinError),
#[error("Error sending downlink request to client: {0}")]
SendingClient(#[from] tokio::sync::mpsc::error::SendError<super::Event>),
SendingClient(#[from] mpsc::error::SendError<super::Event>),
}
3 changes: 2 additions & 1 deletion src/packet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use serde::{Deserialize, Serialize};
use std::fmt;

mod types;
pub use types::*;
pub use lora_modulation::{Bandwidth, CodingRate, SpreadingFactor};
pub use types::{DataRate, Modulation};

mod error;
pub use error::{Error, ParseError};
Expand Down
23 changes: 20 additions & 3 deletions src/packet/pull_resp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ Bytes | Function
4-end | JSON object, starting with {, ending with }, see section 6
*/
use super::{
tx_ack, write_preamble, CodingRate, DataRate, Error as PktError, Identifier, MacAddress,
Modulation, SerializablePacket, Tmst,
tx_ack, types, write_preamble, Error as PktError, Identifier, MacAddress, SerializablePacket,
Tmst,
};

use serde::{Deserialize, Serialize};
use std::io::{Cursor, Write};
use types::{deserialize_codr, serialize_codr, DataRate, Modulation};

#[derive(Debug, Clone)]
pub struct Packet {
Expand Down Expand Up @@ -96,7 +98,11 @@ pub struct TxPk {
pub powe: u64, // TX output power in dBm (unsigned integer, dBm precision)
pub modu: Modulation, // Modulation identifier "LORA" or "FSK"
pub datr: DataRate, // LoRa datarate identifier (eg. SF12BW500)
pub codr: CodingRate, // LoRa ECC coding rate identifier
#[serde(
serialize_with = "serialize_codr",
deserialize_with = "deserialize_codr"
)]
pub codr: Option<lora_modulation::CodingRate>, // LoRa ECC coding rate identifier
#[serde(skip_serializing_if = "Option::is_none")]
pub fdev: Option<u64>, //FSK frequency deviation (unsigned integer, in Hz)
pub ipol: bool, // Lora modulation polarization inversion
Expand Down Expand Up @@ -186,6 +192,17 @@ impl PhyData {
self.size = data.len();
self.data = data;
}

pub fn data(&self) -> &[u8] {
self.data.as_ref()
}
pub fn len(&self) -> usize {
self.size
}

pub fn is_empty(&self) -> bool {
self.size == 0
}
}

impl TxPk {
Expand Down
Loading

0 comments on commit b1bfd5e

Please sign in to comment.