updates telemetry to no longer use grpc

This commit is contained in:
2025-12-29 19:08:13 -05:00
parent f658b55586
commit 8d737e8f33
29 changed files with 911 additions and 514 deletions

View File

@@ -0,0 +1,81 @@
use crate::telemetry::management_service::TelemetryManagementService;
use actix_ws::{AggregatedMessage, ProtocolError, Session};
use anyhow::bail;
use api::request::{RequestMessage, RequestMessagePayload};
use api::response::ResponseMessage;
use std::sync::Arc;
use tokio::sync::mpsc::{Receiver, Sender};
pub(super) struct BackendConnection {
session: Session,
tlm_management: Arc<TelemetryManagementService>,
tx: Sender<ResponseMessage>,
pub rx: Receiver<ResponseMessage>,
pub should_close: bool,
}
impl BackendConnection {
pub fn new(session: Session, tlm_management: Arc<TelemetryManagementService>) -> Self {
let (tx, rx) = tokio::sync::mpsc::channel::<ResponseMessage>(128);
Self {
session,
tlm_management,
tx,
rx,
should_close: false,
}
}
async fn handle_request(&mut self, msg: RequestMessage) -> anyhow::Result<()> {
match msg.payload {
RequestMessagePayload::TelemetryDefinitionRequest(tlm_def) => {
self.tx
.send(ResponseMessage {
uuid: msg.uuid,
payload: self.tlm_management.register(tlm_def)?.into(),
})
.await?;
}
RequestMessagePayload::TelemetryEntry(tlm_entry) => {
self.tlm_management.add_tlm_item(tlm_entry)?;
}
}
Ok(())
}
pub async fn handle_request_message(
&mut self,
msg: Result<AggregatedMessage, ProtocolError>,
) -> anyhow::Result<()> {
let msg = msg?;
match msg {
AggregatedMessage::Text(data) => {
self.handle_request(serde_json::from_str(&data)?).await?;
}
AggregatedMessage::Binary(_) => {
bail!("Binary Messages Unsupported");
}
AggregatedMessage::Ping(bytes) => {
self.session.pong(&bytes).await?;
}
AggregatedMessage::Pong(_) => {
// Intentionally Ignore
}
AggregatedMessage::Close(_) => {
self.should_close = true;
}
}
Ok(())
}
pub async fn handle_response(&mut self, msg: ResponseMessage) -> anyhow::Result<()> {
let msg_json = serde_json::to_string(&msg)?;
self.session.text(msg_json).await?;
Ok(())
}
pub async fn cleanup(mut self) {
self.rx.close();
let _ = self.session.close(None).await;
}
}