diff --git a/Cargo.toml b/Cargo.toml index aab47a4..d32d81a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,5 +18,4 @@ dotenv = "0.15.0" chrono = "0.4.24" paho-mqtt = "0.12.1" serde = "1.0.162" -serde_json = { version = "1.0.95" } -influxdb = { version = "0.6.0", default-features = false, features = ["derive", "use-serde", "reqwest-client"] } \ No newline at end of file +serde_json = { version = "1.0.95" } \ No newline at end of file diff --git a/kairo-common/src/lib.rs b/kairo-common/src/lib.rs index 44544a7..13f254b 100644 --- a/kairo-common/src/lib.rs +++ b/kairo-common/src/lib.rs @@ -5,17 +5,31 @@ pub mod influx; -pub mod helper; +// random functions for mqtt +pub mod mqtt; pub mod unit_conversion; + +// Commonly used types across the services mod types { - pub mod mac; + pub mod mac; // deprecated for the time being. pub mod point; } pub type Point = types::point::Point; pub type MAC = types::mac::MAC; -mod models; + +mod models { + pub mod antenna; + pub mod beacon_measure; + pub mod dynamic_device_status; + pub mod known_position; + + #[derive(Debug, serde::Serialize, serde::Deserialize)] + pub struct DeviceReport { + pub data: Vec, + } +} pub type Antenna = models::antenna::Antenna; pub type DeviceReport = models::DeviceReport; pub type KnownPosition = models::known_position::KnownPosition; diff --git a/kairo-common/src/models/antenna.rs b/kairo-common/src/models/antenna.rs index 8e3d43c..9d8faf8 100644 --- a/kairo-common/src/models/antenna.rs +++ b/kairo-common/src/models/antenna.rs @@ -6,8 +6,10 @@ use crate::{unit_conversion::UnitsConversion, Point}; pub struct Antenna { pub id: String, pub tssi: f64, - pub coord: Point, pub comment: Option, + pos_x: f64, + pos_y: f64, + pos_z: f64, } impl Antenna { @@ -19,11 +21,17 @@ impl Antenna { Antenna { id: id.into(), comment: None, - coord, + pos_x: coord.x, + pos_y: coord.y, + pos_z: 0.0, tssi, } } + pub fn coord(&self) -> Point { + Point::new(self.pos_x, self.pos_y) + } + pub fn get_rssi(&self, distance: f64) -> f64 { #[allow(non_snake_case)] // Free Space Path Loss diff --git a/kairo-common/src/models/mod.rs b/kairo-common/src/models/mod.rs deleted file mode 100644 index 86f6a64..0000000 --- a/kairo-common/src/models/mod.rs +++ /dev/null @@ -1,9 +0,0 @@ -pub mod antenna; -pub mod beacon_measure; -pub mod dynamic_device_status; -pub mod known_position; - -#[derive(Debug, serde::Serialize, serde::Deserialize)] -pub struct DeviceReport { - pub data: Vec, -} diff --git a/kairo-common/src/helper.rs b/kairo-common/src/mqtt.rs similarity index 100% rename from kairo-common/src/helper.rs rename to kairo-common/src/mqtt.rs diff --git a/simulation-tools/Cargo.toml b/simulation-tools/Cargo.toml index 0e4dd12..83dd80c 100644 --- a/simulation-tools/Cargo.toml +++ b/simulation-tools/Cargo.toml @@ -11,7 +11,6 @@ path = "src/nav_dev/main.rs" [dependencies] paho-mqtt = { workspace = true } -influxdb = { workspace = true } tokio = { workspace = true } dotenv = { workspace = true } chrono = { workspace = true } diff --git a/simulation-tools/src/nav_dev/error_report.rs b/simulation-tools/src/nav_dev/error_report.rs index 2faf8c6..0f67bf6 100644 --- a/simulation-tools/src/nav_dev/error_report.rs +++ b/simulation-tools/src/nav_dev/error_report.rs @@ -1,5 +1,4 @@ use chrono::{DateTime, Utc}; -use influxdb::InfluxDbWriteable; use serde::Serialize; use tokio::time; @@ -7,7 +6,7 @@ use kairo_common::Point; use crate::Config; -#[derive(Debug, Serialize, InfluxDbWriteable)] +#[derive(Debug, Serialize)] pub struct Error { error: f64, speed: f64, diff --git a/simulation-tools/src/nav_dev/main.rs b/simulation-tools/src/nav_dev/main.rs index fb44024..ae26a79 100644 --- a/simulation-tools/src/nav_dev/main.rs +++ b/simulation-tools/src/nav_dev/main.rs @@ -3,7 +3,7 @@ use std::{thread, time}; mod error_report; -use kairo_common::helper::for_sync::{get_mqtt_cli, mqtt_pub}; +use kairo_common::mqtt::for_sync::{get_mqtt_cli, mqtt_pub}; use kairo_common::{Antenna, BeaconMeasure, DeviceReport, Point}; #[derive(Clone)] @@ -47,7 +47,7 @@ async fn main() { let mut report = DeviceReport { data: vec![] }; for ant in (antenna).iter() { - let d = ant.coord.distance_to(&position); + let d = ant.coord().distance_to(&position); let rssi = ant.get_rssi(d); let noise: f64 = noise_gen.sample(&mut rand::thread_rng()); diff --git a/xyz-engine/Cargo.toml b/xyz-engine/Cargo.toml index 3769ad2..ad03d07 100644 --- a/xyz-engine/Cargo.toml +++ b/xyz-engine/Cargo.toml @@ -9,7 +9,6 @@ path = "test/all.rs" [dependencies] paho-mqtt = { workspace = true } -influxdb = { workspace = true } tokio = { workspace = true } dotenv = { workspace = true } chrono = { workspace = true } diff --git a/xyz-engine/src/main.rs b/xyz-engine/src/main.rs index 982decd..4e08638 100644 --- a/xyz-engine/src/main.rs +++ b/xyz-engine/src/main.rs @@ -3,7 +3,7 @@ use futures::stream::StreamExt; mod handler; mod position_solver; -use kairo_common::helper::for_async::{ +use kairo_common::mqtt::for_async::{ get_mqtt_cli_and_stream, mqtt_cli_reconnect, mqtt_subscribe, }; diff --git a/xyz-engine/src/position_solver.rs b/xyz-engine/src/position_solver.rs index 8bd6938..e0b19b7 100644 --- a/xyz-engine/src/position_solver.rs +++ b/xyz-engine/src/position_solver.rs @@ -34,7 +34,7 @@ pub async fn solve_for(device_id: MAC) -> Result { .filter_map(|m| { if let Some(a) = antennas.get(&m.beacon_id) { let kd = KnownDistance { - point: a.coord, + point: a.coord(), dist: a.get_distance_with_W(m.rssi), }; Some(kd)