Fix left overs after models refactor (#3)
Co-authored-by: Felipe Diniello <felipediniello@pm.me> Reviewed-on: #3
This commit was merged in pull request #3.
This commit is contained in:
@@ -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"] }
|
||||
serde_json = { version = "1.0.95" }
|
||||
@@ -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<crate::models::beacon_measure::BeaconMeasure>,
|
||||
}
|
||||
}
|
||||
pub type Antenna = models::antenna::Antenna;
|
||||
pub type DeviceReport = models::DeviceReport;
|
||||
pub type KnownPosition = models::known_position::KnownPosition;
|
||||
|
||||
@@ -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<String>,
|
||||
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
|
||||
|
||||
@@ -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<crate::models::beacon_measure::BeaconMeasure>,
|
||||
}
|
||||
@@ -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 }
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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 }
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ pub async fn solve_for(device_id: MAC) -> Result<Point, ()> {
|
||||
.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)
|
||||
|
||||
Reference in New Issue
Block a user