MCPcopy Create free account
hub / github.com/chirpstack/chirpstack / get_next_f_cnt_down

Method get_next_f_cnt_down

chirpstack/src/api/device.rs:1265–1300  ·  view source on GitHub ↗
(
        &self,
        request: Request<api::GetDeviceNextFCntDownRequest>,
    )

Source from the content-addressed store, hash-verified

1263 }
1264
1265 async fn get_next_f_cnt_down(
1266 &self,
1267 request: Request<api::GetDeviceNextFCntDownRequest>,
1268 ) -> Result<Response<api::GetDeviceNextFCntDownResponse>, Status> {
1269 let req = request.get_ref();
1270 let dev_eui = EUI64::from_str(&req.dev_eui).map_err(|e| e.status())?;
1271
1272 self.validator
1273 .validate(
1274 request.extensions(),
1275 validator::ValidateDeviceAccess::new(validator::Flag::Read, dev_eui),
1276 )
1277 .await?;
1278
1279 let d = device::get(&dev_eui).await.map_err(|e| e.status())?;
1280 let ds = match d.get_device_session() {
1281 Ok(v) => v.clone(),
1282 Err(StorageError::NotFound(_)) => Default::default(),
1283 Err(e) => {
1284 return Err(e.status());
1285 }
1286 };
1287
1288 let max_f_cnt_down_queue = device_queue::get_max_f_cnt_down(dev_eui)
1289 .await
1290 .map_err(|e| e.status())?
1291 .unwrap_or_default() as u32;
1292
1293 let mut resp = Response::new(api::GetDeviceNextFCntDownResponse {
1294 f_cnt_down: cmp::max(ds.get_a_f_cnt_down(), max_f_cnt_down_queue + 1),
1295 });
1296 resp.metadata_mut()
1297 .insert("x-log-dev_eui", req.dev_eui.parse().unwrap());
1298
1299 Ok(resp)
1300 }
1301}
1302
1303#[cfg(test)]

Callers 1

test_deviceFunction · 0.80

Calls 8

get_max_f_cnt_downFunction · 0.85
statusMethod · 0.80
get_device_sessionMethod · 0.80
get_a_f_cnt_downMethod · 0.80
insertMethod · 0.80
unwrapMethod · 0.80
getFunction · 0.50
validateMethod · 0.45

Tested by 1

test_deviceFunction · 0.64