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:
Orne Brocaar 2023-10-09 10:55:43 +01:00
parent 41d00cb651
commit 4d27c339cc
7 changed files with 37 additions and 9 deletions

View File

@ -237,6 +237,8 @@ mod test {
min_dr: 0,
max_dr: 0,
uplink_history: vec![],
skip_f_cnt_check: false,
device_variables: Default::default(),
};
for i in 0..20 {
@ -459,6 +461,8 @@ mod test {
min_dr: 0,
max_dr: 0,
uplink_history: vec![],
skip_f_cnt_check: false,
device_variables: Default::default(),
};
req.uplink_history.push(internal::UplinkAdrHistory {
max_snr: 3.0,
@ -497,6 +501,8 @@ mod test {
min_dr: 0,
max_dr: 0,
uplink_history: vec![],
skip_f_cnt_check: false,
device_variables: Default::default(),
};
struct Test {
@ -516,7 +522,7 @@ mod test {
nb_trans: 1,
max_dr: 4,
max_tx_power_index: 5,
..req_template
..req_template.clone()
},
response: Response {
dr: 5,
@ -538,7 +544,7 @@ mod test {
max_snr: 0.0,
..Default::default()
}],
..req_template
..req_template.clone()
},
response: Response {
dr: 4,
@ -561,7 +567,7 @@ mod test {
max_snr: -15.0,
..Default::default()
}],
..req_template
..req_template.clone()
},
response: Response {
dr: 1,

View File

@ -92,6 +92,8 @@ pub mod test {
min_dr: 0,
max_dr: 0,
uplink_history: vec![],
skip_f_cnt_check: false,
device_variables: Default::default(),
};
struct Test {
@ -114,7 +116,7 @@ pub mod test {
max_snr: -10.0,
..Default::default()
}],
..req_template
..req_template.clone()
},
response: Response {
dr: 3,
@ -135,7 +137,7 @@ pub mod test {
max_snr: -12.0,
..Default::default()
}],
..req_template
..req_template.clone()
},
response: Response {
dr: 10,

View File

@ -207,6 +207,8 @@ pub mod test {
min_dr: 0,
max_dr: 0,
uplink_history: vec![],
skip_f_cnt_check: false,
device_variables: Default::default(),
};
struct Test {
@ -228,7 +230,7 @@ pub mod test {
max_rssi: -130,
..Default::default()
}],
..req_template
..req_template.clone()
},
response: Response {
dr: 0,
@ -248,7 +250,7 @@ pub mod test {
max_rssi: -130,
..Default::default()
}],
..req_template
..req_template.clone()
},
response: Response {
dr: 0,
@ -268,7 +270,7 @@ pub mod test {
max_rssi: -130,
..Default::default()
}],
..req_template
..req_template.clone()
},
response: Response {
dr: 10,
@ -290,7 +292,7 @@ pub mod test {
..Default::default()
})
.collect(),
..req_template
..req_template.clone()
},
response: Response {
dr: 11,

View File

@ -92,6 +92,7 @@ pub trait Handler {
async fn handle(&self, req: &Request) -> Result<Response>;
}
#[derive(Clone)]
pub struct Request {
pub region_config_id: String,
pub region_common_name: lrwn::region::CommonName,
@ -108,6 +109,8 @@ pub struct Request {
pub min_dr: u8,
pub max_dr: u8,
pub uplink_history: Vec<internal::UplinkAdrHistory>,
pub skip_f_cnt_check: bool,
pub device_variables: HashMap<String, String>,
}
#[derive(Debug, PartialEq, Eq)]

View File

@ -56,6 +56,11 @@ impl Handler for Plugin {
.context("Compile script")?;
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)?;
input.set("regionConfigId", req.region_config_id.clone())?;
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("minDr", req.min_dr)?;
input.set("maxDr", req.max_dr)?;
input.set("deviceVariables", device_variables)?;
let mut uplink_history: Vec<rquickjs::Object> = Vec::new();
@ -127,6 +133,8 @@ pub mod test {
min_dr: 0,
max_dr: 5,
uplink_history: vec![],
skip_f_cnt_check: false,
device_variables: Default::default(),
};
let resp = p.handle(&req).await.unwrap();

View File

@ -1173,6 +1173,8 @@ impl Data {
min_dr: self.network_conf.min_dr,
max_dr: self.network_conf.max_dr,
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;

View File

@ -26,6 +26,11 @@ export function id() {
// installationMargin: 10,
// minDr: 0,
// maxDr: 5,
// skipFCntCheck: false,
// deviceVariables: {
// "varA": "value1",
// "varB": "value2",
// },
// uplinkHistory: [
// {
// "fCnt": 10,