Create workspace from previous implementation files

This commit is contained in:
2023-05-21 13:52:18 +02:00
parent b84f46ed57
commit a5976252e8
23 changed files with 1374 additions and 15 deletions

30
xyz-engine/src/handler.rs Normal file
View File

@@ -0,0 +1,30 @@
pub mod device {
use kairo_common::influxdb_models::BeaconMeasure;
use kairo_common::{unit_conversion::UnitsConversion, DeviceReport, MAC};
use crate::position_solver::solve_for;
pub async fn report(device_id: &str, payload: &str) {
if let Ok(device_report) = serde_json::from_str::<DeviceReport>(payload) {
// device_report.data.sort_by(|a, b| b.pwr.cmp(&a.pwr));
let mut count = 0;
for beacon in device_report.data.iter() {
let measure = BeaconMeasure::new(&beacon.beacon_id, beacon.rssi.dBm_to_W());
if (measure.write_for(device_id).await).is_ok() {
count += 1;
}
}
// If I added more than 3 valid measures it's worth to process the position
if count >= 3 {
let device_id = MAC::new(device_id);
tokio::spawn(async move {
let _r = solve_for(device_id).await;
});
}
} else {
println!("Unable to parse: {}", payload);
}
}
}