From dc6bd5fa1b2e73571f1ac7068d0807bd1e08351f Mon Sep 17 00:00:00 2001 From: Jack Rubacha Date: Sun, 15 Dec 2024 23:09:06 -0500 Subject: [PATCH] in progress faults --- scylla-server/Cargo.lock | 19 +++++++++-------- scylla-server/Cargo.toml | 1 + scylla-server/src/socket_handler.rs | 33 ++++++++++++++++------------- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/scylla-server/Cargo.lock b/scylla-server/Cargo.lock index 874a978e..74d3b7cf 100755 --- a/scylla-server/Cargo.lock +++ b/scylla-server/Cargo.lock @@ -1547,14 +1547,14 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.5" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.4.7", - "regex-syntax 0.8.4", + "regex-automata 0.4.9", + "regex-syntax 0.8.5", ] [[package]] @@ -1568,13 +1568,13 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.7" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.8.4", + "regex-syntax 0.8.5", ] [[package]] @@ -1585,9 +1585,9 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "regex-syntax" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "ring" @@ -1755,6 +1755,7 @@ dependencies = [ "protobuf", "protobuf-codegen", "rand", + "regex", "ringbuffer", "rumqttc", "serde", diff --git a/scylla-server/Cargo.toml b/scylla-server/Cargo.toml index 47229e1a..1e7aaff8 100644 --- a/scylla-server/Cargo.toml +++ b/scylla-server/Cargo.toml @@ -28,6 +28,7 @@ axum-extra = { version = "0.9.3", features = ["query"] } chrono = { version = "0.4.38", features = ["serde"] } serde_json = "1.0.128" diesel_migrations = { version = "2.2.0", features = ["postgres"] } +regex = "1.11.1" [features] top = ["dep:console-subscriber"] diff --git a/scylla-server/src/socket_handler.rs b/scylla-server/src/socket_handler.rs index a82c3fa0..0baf3540 100644 --- a/scylla-server/src/socket_handler.rs +++ b/scylla-server/src/socket_handler.rs @@ -1,6 +1,8 @@ use std::{collections::HashMap, sync::atomic::Ordering, time::Duration}; use chrono::{DateTime, Utc}; +use regex::Regex; +use ringbuffer::AllocRingBuffer; use serde::Serialize; use socketioxide::SocketIo; use tokio::sync::broadcast; @@ -43,13 +45,13 @@ const TIMERS_TOPICS: &[&str] = &[ "BMS/Charging/Control", ]; -// #[derive(Serialize)] -// struct FaultData { -// pub topic: &'static str, -// pub name: String, -// pub occured_at: DateTime, -// } -// const FAULT_SOCKET_KEY: &str = "faults"; +#[derive(Serialize)] +struct FaultData { + pub topic: &'static str, + pub name: String, + pub occured_at: DateTime, +} +const FAULT_SOCKET_KEY: &str = "faults"; pub async fn socket_handler_with_metadata( cancel_token: CancellationToken, @@ -77,10 +79,10 @@ pub async fn socket_handler_with_metadata( } // init faults - // let fault_regex: Regex = Regex::new(r"(BMS/Status/F/*|Charger/Box/F_*|MPU/Fault/F_*") - // .expect("Could not compile regex!"); - // const FAULT_BINS: &[&str] = &["DTI/Fault/FaultCode"]; - // let mut fault_ringbuffer = AllocRingBuffer::::new(25); + let fault_regex: Regex = Regex::new(r"(BMS/Status/F/*|Charger/Box/F_*|MPU/Fault/F_*") + .expect("Could not compile regex!"); + const FAULT_BINS: &[&str] = &["DTI/Fault/FaultCode"]; + let mut fault_ringbuffer = AllocRingBuffer::::new(25); loop { tokio::select! { @@ -106,11 +108,12 @@ pub async fn socket_handler_with_metadata( } continue; } - // if fault_regex.is_match(&data.name) { - // fault_ringbuffer.push() - // } else { - // } + if fault_regex.is_match(&data.name) { + //fault_ringbuffer.push() + } else { + + } } _ = timers_interval.tick() => {