Skip to content

Commit

Permalink
make data query optional to reset calypso to default
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jr1221 committed Aug 2, 2024
1 parent f278a9f commit 6de996b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions scylla-server-rust/src/controllers/car_command_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ pub const CALYPSO_BIDIR_CMD_PREFIX: &str = "Calypso/Bidir/Command/";

#[derive(Deserialize, Debug)]
pub struct ConfigRequest {
pub data: Vec<f32>,
pub data: Option<Vec<f32>>,
}

/// This controller recieves two peices of info: the key from the path, and the list of float values from the query params
/// The key is used in accordance with the calypso specification: a command_data object is sent over siren to CALYPSO_BIDIR_CMD_PREFIX/<key>
/// That command_data object is processed and matched via the key to a YAML specification for the encoding and sending of a CAN message
/// That command_data object is processed and matched via the key to a YAML specification for the encoding and sending of a CAN message.
/// If the data is invalid, too short, etc. the default feild from the YAML is instead sent, as with when the car initially turns on before argos connects.
/// TLDR: This triggers a command <key> with the values <data_query.0.data> for calypso to update the CAN packet sent to the bus.
pub async fn send_config(
Path(key): Path<String>,
Expand All @@ -37,7 +38,10 @@ pub async fn send_config(

// create a payload object of the values to be parsed by calypso into a CAN packet
let mut payload = CommandData::new();
payload.data = data_query.0.data;
// writing an empty protobuf is OK, that indicates to calypso that the default value should be used
if let Some(data) = data_query.0.data {
payload.data = data;
}
let Ok(bytes) = payload.write_to_bytes() else {
return Err(ScyllaError::ImpossibleEncoding);
};
Expand Down

0 comments on commit 6de996b

Please sign in to comment.