-
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.
* basic proof of concept * misc improvements and cleanup of cursory processing * implement reids review suggestions * try and fix clippy * and again fix clippy * make data query optional to reset calypso to default if calypso receives a short or emtpy protobuf command_data, it will fill the extra values with the default value specified in the YAML. so we should allow the client to specify blank which could end up meaning a "Reset to Default" button. * clippy is trolling me * fixup error handling for plaintext error message * implement reid fixes * remove not prod error
- Loading branch information
Showing
22 changed files
with
243 additions
and
81 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
70 changes: 70 additions & 0 deletions
70
scylla-server-rust/src/controllers/car_command_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,70 @@ | ||
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}; | ||
|
||
/// the prefix for the calypso topic, so topic of cmd is this plus the key appended on | ||
pub const CALYPSO_BIDIR_CMD_PREFIX: &str = "Calypso/Bidir/Command/"; | ||
|
||
#[derive(Deserialize, Debug)] | ||
pub struct ConfigRequest { | ||
pub data: Option<Vec<f32>>, | ||
} | ||
|
||
/// Sends a configuration to the car over MQTT | ||
/// * `key` - The key of the configuration, as defined in the cangen YAML | ||
/// * `data_query` - The data of the configuration, a URI query list of data=<f32>. If empty or too short, filled with cangen YAMl defaults | ||
/// * `client` - The MQTT client to be used to send the data | ||
/// | ||
/// More info: This follows the specification of sending a command_data object over siren to topic CALYPSO_BIDIR_CMD_PREFIX/<key> | ||
pub async fn send_config_command( | ||
Path(key): Path<String>, | ||
Query(data_query): Query<ConfigRequest>, | ||
Extension(client): Extension<Option<Arc<AsyncClient>>>, | ||
) -> Result<(), ScyllaError> { | ||
info!( | ||
"Sending car config with key: {}, and values: {:?}", | ||
key, data_query.data | ||
); | ||
// disable scylla if not prod, as there will be None mqtt client | ||
let Some(client) = client else { | ||
warn!("Cannot use config endpoint in dev mode!"); | ||
return Ok(()) | ||
}; | ||
|
||
// the protobuf calypso converts into CAN | ||
let mut payload = CommandData::new(); | ||
// empty "data" in the protobuf tells calypso to use the default value | ||
if let Some(data) = data_query.data { | ||
payload.data = data; | ||
} | ||
let Ok(bytes) = payload.write_to_bytes() else { | ||
return Err(ScyllaError::InvalidEncoding( | ||
"Payload could not be written!".to_string(), | ||
)); | ||
}; | ||
|
||
// publish the message to the topic that calypso's encoder is susbcribed to | ||
if let Err(err) = client | ||
.publish( | ||
format!("{}{}", CALYPSO_BIDIR_CMD_PREFIX, key), | ||
rumqttc::v5::mqttbytes::QoS::ExactlyOnce, | ||
false, | ||
bytes, | ||
) | ||
.await | ||
{ | ||
warn!("Could not publish instruction: {}", err); | ||
return Err(ScyllaError::CommFailure( | ||
"Siren publish for instruction failed!".to_string(), | ||
)); | ||
} | ||
|
||
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
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
Oops, something went wrong.