initial graph
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use std::error::Error;
|
||||
use std::pin::Pin;
|
||||
use std::sync::Arc;
|
||||
use chrono::{DateTime, SecondsFormat};
|
||||
use log::{error, trace};
|
||||
use tokio::select;
|
||||
use tokio::sync::mpsc;
|
||||
@@ -13,7 +14,7 @@ use tonic::transport::Server;
|
||||
use crate::core::telemetry_service_server::{TelemetryService, TelemetryServiceServer};
|
||||
use crate::core::{TelemetryDataType, TelemetryDefinitionRequest, TelemetryDefinitionResponse, TelemetryInsertResponse, TelemetryItem, TelemetryValue, Uuid};
|
||||
use crate::core::telemetry_value::Value;
|
||||
use crate::telemetry::{TelemetryDataValue, TelemetryManagementService};
|
||||
use crate::telemetry::{TelemetryDataItem, TelemetryDataValue, TelemetryManagementService};
|
||||
|
||||
pub struct CoreTelemetryService {
|
||||
pub tlm_management: Arc<TelemetryManagementService>,
|
||||
@@ -89,6 +90,10 @@ impl CoreTelemetryService {
|
||||
return Err(Status::failed_precondition("Value Missing"));
|
||||
};
|
||||
|
||||
let Some(timestamp) = tlm_item.timestamp else {
|
||||
return Err(Status::failed_precondition("Timestamp Missing"));
|
||||
};
|
||||
|
||||
let expected_type = match value {
|
||||
Value::Float32(_) => TelemetryDataType::Float32,
|
||||
Value::Float64(_) => TelemetryDataType::Float64,
|
||||
@@ -97,9 +102,16 @@ impl CoreTelemetryService {
|
||||
return Err(Status::failed_precondition("Data Type Mismatch"));
|
||||
};
|
||||
|
||||
let _ = tlm_data.data.send_replace(Some(match value {
|
||||
Value::Float32(x) => TelemetryDataValue::Float32(x),
|
||||
Value::Float64(x) => TelemetryDataValue::Float64(x),
|
||||
let Some(timestamp) = DateTime::from_timestamp(timestamp.secs, timestamp.nanos as u32) else {
|
||||
return Err(Status::invalid_argument("Failed to construct UTC DateTime"));
|
||||
};
|
||||
|
||||
let _ = tlm_data.data.send_replace(Some(TelemetryDataItem {
|
||||
value: match value {
|
||||
Value::Float32(x) => TelemetryDataValue::Float32(x),
|
||||
Value::Float64(x) => TelemetryDataValue::Float64(x),
|
||||
},
|
||||
timestamp: timestamp.to_rfc3339_opts(SecondsFormat::Millis, true)
|
||||
}));
|
||||
|
||||
Ok(TelemetryInsertResponse {})
|
||||
|
||||
@@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize};
|
||||
use tokio::select;
|
||||
use tokio_util::sync::CancellationToken;
|
||||
use tonic::codegen::tokio_stream::StreamExt;
|
||||
use crate::telemetry::{TelemetryDataValue, TelemetryManagementService};
|
||||
use crate::telemetry::{TelemetryDataItem, TelemetryDataValue, TelemetryManagementService};
|
||||
|
||||
#[derive(Debug, Display, Error)]
|
||||
enum UserError {
|
||||
@@ -41,7 +41,7 @@ enum WebsocketRequest {
|
||||
enum WebsocketResponse {
|
||||
TlmValue {
|
||||
uuid: String,
|
||||
value: Option<TelemetryDataValue>
|
||||
value: Option<TelemetryDataItem>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,11 +2,12 @@ use std::collections::HashMap;
|
||||
use std::error::Error;
|
||||
use std::fmt::Formatter;
|
||||
use std::sync::Arc;
|
||||
use chrono::{DateTime, Utc};
|
||||
use log::trace;
|
||||
use serde::de::Visitor;
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
use tokio::sync::Mutex;
|
||||
use crate::core::{TelemetryDataType, TelemetryDefinitionRequest, Uuid};
|
||||
use crate::core::{TelemetryDataType, TelemetryDefinitionRequest, TelemetryItem, Timestamp, Uuid};
|
||||
|
||||
fn tlm_data_type_serialzier<S>(tlm_data_type: &TelemetryDataType, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer {
|
||||
serializer.serialize_str(tlm_data_type.as_str_name())
|
||||
@@ -48,10 +49,16 @@ pub enum TelemetryDataValue {
|
||||
Float64(f64),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct TelemetryDataItem {
|
||||
pub value: TelemetryDataValue,
|
||||
pub timestamp: String
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct TelemetryData {
|
||||
pub definition: TelemetryDefinition,
|
||||
pub data: tokio::sync::watch::Sender<Option<TelemetryDataValue>>,
|
||||
pub data: tokio::sync::watch::Sender<Option<TelemetryDataItem>>,
|
||||
}
|
||||
|
||||
pub struct TelemetryManagementService {
|
||||
|
||||
Reference in New Issue
Block a user