-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
151 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,4 @@ prisma.rs | |
|
||
# protobuf | ||
serverdata.rs | ||
command_data.rs |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
scylla-server-rust/src/controllers/send_config_controller.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use std::sync::Arc; | ||
|
||
use axum::{extract::Path, Extension}; | ||
use axum_extra::extract::Query; | ||
use protobuf::Message; | ||
use rumqttc::v5::AsyncClient; | ||
use serde::Deserialize; | ||
use tracing::{info, warn}; | ||
|
||
use crate::{command_data::CommandData, error::ScyllaError}; | ||
|
||
#[derive(Deserialize, Debug)] | ||
pub struct ConfigRequest { | ||
pub data: Vec<f32>, | ||
} | ||
|
||
pub async fn send_config( | ||
Path(key): Path<String>, | ||
data_query: Query<ConfigRequest>, | ||
Extension(client): Extension<Option<Arc<AsyncClient>>>, | ||
) -> Result<(), ScyllaError> { | ||
info!( | ||
"Sending car config with key: {}, and values: {:?}", | ||
key, data_query.0 | ||
); | ||
let Some(client) = client else { | ||
return Err(ScyllaError::NotProd); | ||
}; | ||
|
||
let mut payload = CommandData::new(); | ||
payload.data = data_query.0.data; | ||
let Ok(bytes) = payload.write_to_bytes() else { | ||
return Err(ScyllaError::ImpossibleEncoding); | ||
}; | ||
|
||
if let Err(err) = client | ||
.publish( | ||
format!("Calypso/Bidir/Command/{}", key), | ||
rumqttc::v5::mqttbytes::QoS::ExactlyOnce, | ||
false, | ||
bytes, | ||
) | ||
.await | ||
{ | ||
warn!("Could not publish instruction: {}", err); | ||
return Err(ScyllaError::CommFailure); | ||
} | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// @generated | ||
|
||
pub mod command_data; | ||
pub mod serverdata; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
syntax = "proto3"; | ||
|
||
package command_data.v1; | ||
|
||
message CommandData { | ||
repeated float data = 1; | ||
} |