Skip to content

Commit bd50dc7

Browse files
committed
Update device-profile import.
This change uses the id field of the device-profile as device-profile-template id. It also fixes handling default values when decoding the TOML config.
1 parent 20c3334 commit bd50dc7

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

chirpstack/src/cmd/import_lorawan_device_profiles.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::path::Path;
44
use anyhow::Result;
55
use serde::Deserialize;
66
use tracing::{info, span, Instrument, Level};
7+
use uuid::Uuid;
78

89
use crate::codec::Codec;
910
use crate::storage::{self, device_profile_template};
@@ -53,6 +54,8 @@ pub struct ProfileConfig {
5354
#[derive(Deserialize)]
5455
#[serde(default)]
5556
pub struct Profile {
57+
pub id: Uuid,
58+
pub vendor_profile_id: usize,
5659
pub region: region::CommonName,
5760
pub mac_version: region::MacVersion,
5861
pub reg_params_revision: region::Revision,
@@ -69,6 +72,8 @@ pub struct Profile {
6972
impl Default for Profile {
7073
fn default() -> Self {
7174
Self {
75+
id: Uuid::nil(),
76+
vendor_profile_id: 0,
7277
region: region::CommonName::EU868,
7378
mac_version: region::MacVersion::LORAWAN_1_0_4,
7479
reg_params_revision: region::Revision::RP002_1_0_4,
@@ -84,6 +89,7 @@ impl Default for Profile {
8489
}
8590

8691
#[derive(Default, Deserialize)]
92+
#[serde(default)]
8793
pub struct ProfileAbp {
8894
pub rx1_delay: usize,
8995
pub rx1_dr_offset: usize,
@@ -92,6 +98,7 @@ pub struct ProfileAbp {
9298
}
9399

94100
#[derive(Default, Deserialize)]
101+
#[serde(default)]
95102
pub struct ProfileClassB {
96103
pub timeout_secs: usize,
97104
pub ping_slot_periodicity: usize,
@@ -100,6 +107,7 @@ pub struct ProfileClassB {
100107
}
101108

102109
#[derive(Default, Deserialize)]
110+
#[serde(default)]
103111
pub struct ProfileClassC {
104112
pub timeout_secs: usize,
105113
}
@@ -207,15 +215,8 @@ async fn handle_profile(
207215

208216
let profile_conf: ProfileConfig = toml::from_str(&fs::read_to_string(profile_path)?)?;
209217

210-
let id_regex = regex::Regex::new(r"[^a-zA-Z0-9\-]+").unwrap();
211-
let id = format!(
212-
"{}-{}-{}-{}",
213-
vendor.slug, device.slug, firmware.version, profile_conf.profile.region
214-
);
215-
let id = id_regex.replace_all(&id, "-").to_string();
216-
217218
let dpt = device_profile_template::DeviceProfileTemplate {
218-
id,
219+
id: profile_conf.profile.id.to_string(),
219220
name: device.name.clone(),
220221
description: device.description.clone(),
221222
vendor: vendor.name.clone(),

0 commit comments

Comments
 (0)