mirror of
https://github.com/chirpstack/chirpstack.git
synced 2025-01-18 18:46:24 +00:00
Expose skip_f_cnt and device variables to ADR.
This provides more flexibility to custom ADR algorithm implementations. E.g. the device variables can be used to store per-device variables that might overwrite normal ADR logic.
This commit is contained in:
parent
41d00cb651
commit
4d27c339cc
@ -237,6 +237,8 @@ mod test {
|
|||||||
min_dr: 0,
|
min_dr: 0,
|
||||||
max_dr: 0,
|
max_dr: 0,
|
||||||
uplink_history: vec![],
|
uplink_history: vec![],
|
||||||
|
skip_f_cnt_check: false,
|
||||||
|
device_variables: Default::default(),
|
||||||
};
|
};
|
||||||
|
|
||||||
for i in 0..20 {
|
for i in 0..20 {
|
||||||
@ -459,6 +461,8 @@ mod test {
|
|||||||
min_dr: 0,
|
min_dr: 0,
|
||||||
max_dr: 0,
|
max_dr: 0,
|
||||||
uplink_history: vec![],
|
uplink_history: vec![],
|
||||||
|
skip_f_cnt_check: false,
|
||||||
|
device_variables: Default::default(),
|
||||||
};
|
};
|
||||||
req.uplink_history.push(internal::UplinkAdrHistory {
|
req.uplink_history.push(internal::UplinkAdrHistory {
|
||||||
max_snr: 3.0,
|
max_snr: 3.0,
|
||||||
@ -497,6 +501,8 @@ mod test {
|
|||||||
min_dr: 0,
|
min_dr: 0,
|
||||||
max_dr: 0,
|
max_dr: 0,
|
||||||
uplink_history: vec![],
|
uplink_history: vec![],
|
||||||
|
skip_f_cnt_check: false,
|
||||||
|
device_variables: Default::default(),
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Test {
|
struct Test {
|
||||||
@ -516,7 +522,7 @@ mod test {
|
|||||||
nb_trans: 1,
|
nb_trans: 1,
|
||||||
max_dr: 4,
|
max_dr: 4,
|
||||||
max_tx_power_index: 5,
|
max_tx_power_index: 5,
|
||||||
..req_template
|
..req_template.clone()
|
||||||
},
|
},
|
||||||
response: Response {
|
response: Response {
|
||||||
dr: 5,
|
dr: 5,
|
||||||
@ -538,7 +544,7 @@ mod test {
|
|||||||
max_snr: 0.0,
|
max_snr: 0.0,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}],
|
}],
|
||||||
..req_template
|
..req_template.clone()
|
||||||
},
|
},
|
||||||
response: Response {
|
response: Response {
|
||||||
dr: 4,
|
dr: 4,
|
||||||
@ -561,7 +567,7 @@ mod test {
|
|||||||
max_snr: -15.0,
|
max_snr: -15.0,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}],
|
}],
|
||||||
..req_template
|
..req_template.clone()
|
||||||
},
|
},
|
||||||
response: Response {
|
response: Response {
|
||||||
dr: 1,
|
dr: 1,
|
||||||
|
@ -92,6 +92,8 @@ pub mod test {
|
|||||||
min_dr: 0,
|
min_dr: 0,
|
||||||
max_dr: 0,
|
max_dr: 0,
|
||||||
uplink_history: vec![],
|
uplink_history: vec![],
|
||||||
|
skip_f_cnt_check: false,
|
||||||
|
device_variables: Default::default(),
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Test {
|
struct Test {
|
||||||
@ -114,7 +116,7 @@ pub mod test {
|
|||||||
max_snr: -10.0,
|
max_snr: -10.0,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}],
|
}],
|
||||||
..req_template
|
..req_template.clone()
|
||||||
},
|
},
|
||||||
response: Response {
|
response: Response {
|
||||||
dr: 3,
|
dr: 3,
|
||||||
@ -135,7 +137,7 @@ pub mod test {
|
|||||||
max_snr: -12.0,
|
max_snr: -12.0,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}],
|
}],
|
||||||
..req_template
|
..req_template.clone()
|
||||||
},
|
},
|
||||||
response: Response {
|
response: Response {
|
||||||
dr: 10,
|
dr: 10,
|
||||||
|
@ -207,6 +207,8 @@ pub mod test {
|
|||||||
min_dr: 0,
|
min_dr: 0,
|
||||||
max_dr: 0,
|
max_dr: 0,
|
||||||
uplink_history: vec![],
|
uplink_history: vec![],
|
||||||
|
skip_f_cnt_check: false,
|
||||||
|
device_variables: Default::default(),
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Test {
|
struct Test {
|
||||||
@ -228,7 +230,7 @@ pub mod test {
|
|||||||
max_rssi: -130,
|
max_rssi: -130,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}],
|
}],
|
||||||
..req_template
|
..req_template.clone()
|
||||||
},
|
},
|
||||||
response: Response {
|
response: Response {
|
||||||
dr: 0,
|
dr: 0,
|
||||||
@ -248,7 +250,7 @@ pub mod test {
|
|||||||
max_rssi: -130,
|
max_rssi: -130,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}],
|
}],
|
||||||
..req_template
|
..req_template.clone()
|
||||||
},
|
},
|
||||||
response: Response {
|
response: Response {
|
||||||
dr: 0,
|
dr: 0,
|
||||||
@ -268,7 +270,7 @@ pub mod test {
|
|||||||
max_rssi: -130,
|
max_rssi: -130,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}],
|
}],
|
||||||
..req_template
|
..req_template.clone()
|
||||||
},
|
},
|
||||||
response: Response {
|
response: Response {
|
||||||
dr: 10,
|
dr: 10,
|
||||||
@ -290,7 +292,7 @@ pub mod test {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
..req_template
|
..req_template.clone()
|
||||||
},
|
},
|
||||||
response: Response {
|
response: Response {
|
||||||
dr: 11,
|
dr: 11,
|
||||||
|
@ -92,6 +92,7 @@ pub trait Handler {
|
|||||||
async fn handle(&self, req: &Request) -> Result<Response>;
|
async fn handle(&self, req: &Request) -> Result<Response>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct Request {
|
pub struct Request {
|
||||||
pub region_config_id: String,
|
pub region_config_id: String,
|
||||||
pub region_common_name: lrwn::region::CommonName,
|
pub region_common_name: lrwn::region::CommonName,
|
||||||
@ -108,6 +109,8 @@ pub struct Request {
|
|||||||
pub min_dr: u8,
|
pub min_dr: u8,
|
||||||
pub max_dr: u8,
|
pub max_dr: u8,
|
||||||
pub uplink_history: Vec<internal::UplinkAdrHistory>,
|
pub uplink_history: Vec<internal::UplinkAdrHistory>,
|
||||||
|
pub skip_f_cnt_check: bool,
|
||||||
|
pub device_variables: HashMap<String, String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
|
@ -56,6 +56,11 @@ impl Handler for Plugin {
|
|||||||
.context("Compile script")?;
|
.context("Compile script")?;
|
||||||
let func: rquickjs::Function = m.get("handle").context("Get handle function")?;
|
let func: rquickjs::Function = m.get("handle").context("Get handle function")?;
|
||||||
|
|
||||||
|
let device_variables = rquickjs::Object::new(ctx)?;
|
||||||
|
for (k, v) in &req.device_variables {
|
||||||
|
device_variables.set(k, v)?;
|
||||||
|
}
|
||||||
|
|
||||||
let input = rquickjs::Object::new(ctx)?;
|
let input = rquickjs::Object::new(ctx)?;
|
||||||
input.set("regionConfigId", req.region_config_id.clone())?;
|
input.set("regionConfigId", req.region_config_id.clone())?;
|
||||||
input.set("regionCommonName", req.region_common_name.to_string())?;
|
input.set("regionCommonName", req.region_common_name.to_string())?;
|
||||||
@ -71,6 +76,7 @@ impl Handler for Plugin {
|
|||||||
input.set("installationMargin", req.installation_margin)?;
|
input.set("installationMargin", req.installation_margin)?;
|
||||||
input.set("minDr", req.min_dr)?;
|
input.set("minDr", req.min_dr)?;
|
||||||
input.set("maxDr", req.max_dr)?;
|
input.set("maxDr", req.max_dr)?;
|
||||||
|
input.set("deviceVariables", device_variables)?;
|
||||||
|
|
||||||
let mut uplink_history: Vec<rquickjs::Object> = Vec::new();
|
let mut uplink_history: Vec<rquickjs::Object> = Vec::new();
|
||||||
|
|
||||||
@ -127,6 +133,8 @@ pub mod test {
|
|||||||
min_dr: 0,
|
min_dr: 0,
|
||||||
max_dr: 5,
|
max_dr: 5,
|
||||||
uplink_history: vec![],
|
uplink_history: vec![],
|
||||||
|
skip_f_cnt_check: false,
|
||||||
|
device_variables: Default::default(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let resp = p.handle(&req).await.unwrap();
|
let resp = p.handle(&req).await.unwrap();
|
||||||
|
@ -1173,6 +1173,8 @@ impl Data {
|
|||||||
min_dr: self.network_conf.min_dr,
|
min_dr: self.network_conf.min_dr,
|
||||||
max_dr: self.network_conf.max_dr,
|
max_dr: self.network_conf.max_dr,
|
||||||
uplink_history: self.device_session.uplink_adr_history.clone(),
|
uplink_history: self.device_session.uplink_adr_history.clone(),
|
||||||
|
skip_f_cnt_check: self.device_session.skip_f_cnt_check,
|
||||||
|
device_variables: self.device.variables.into_hashmap(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let resp = adr::handle(&self.device_profile.adr_algorithm_id, &req).await;
|
let resp = adr::handle(&self.device_profile.adr_algorithm_id, &req).await;
|
||||||
|
@ -26,6 +26,11 @@ export function id() {
|
|||||||
// installationMargin: 10,
|
// installationMargin: 10,
|
||||||
// minDr: 0,
|
// minDr: 0,
|
||||||
// maxDr: 5,
|
// maxDr: 5,
|
||||||
|
// skipFCntCheck: false,
|
||||||
|
// deviceVariables: {
|
||||||
|
// "varA": "value1",
|
||||||
|
// "varB": "value2",
|
||||||
|
// },
|
||||||
// uplinkHistory: [
|
// uplinkHistory: [
|
||||||
// {
|
// {
|
||||||
// "fCnt": 10,
|
// "fCnt": 10,
|
||||||
|
Loading…
Reference in New Issue
Block a user