Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions embedded-service/src/cfu/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,25 @@ impl<W: CfuWriterAsync> CfuComponentDefault<W> {
.map(|x| x.unwrap_or_default())
.collect::<Vec<ComponentId, MAX_SUBCMPT_COUNT>>();
component_count += arr.len();

const _: () = {
core::assert!(
MAX_CMPT_COUNT == MAX_SUBCMPT_COUNT + 1,
"MAX_CMPT_COUNT must be one more than MAX_SUBCMPT_COUNT"
);
};
#[allow(clippy::indexing_slicing)]
// panic safety: adding 1 here is safe because MAX_CMPT_COUNT is 1 more than MAX_SUBCMPT_COUNT
for (index, id) in arr.iter().enumerate() {
//info!("Forwarding GetFwVersion command to sub-component: {}", id);
if let InternalResponseData::FwVersionResponse(fwv) =
route_request(*id, RequestData::FwVersionRequest).await?
{
// adding 1 here is safe because MAX_CMPT_COUNT is 1 more than MAX_SUBCMPT_COUNT
comp_info[index + 1] = fwv.component_info[0];
comp_info[index + 1] = fwv
.component_info
.first()
.cloned()
.ok_or(CfuError::ProtocolError(CfuProtocolError::BadResponse))?;
} else {
/*error!(
"Failed to get firmware version from sub-component: {}, adding dummy info to list",
Expand Down
33 changes: 16 additions & 17 deletions embedded-service/src/cfu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,34 +103,33 @@ pub async fn send_request(from: ComponentId, request: RequestData) -> Result<Int

/// Convenience function to route a request to a specific component
pub async fn route_request(to: ComponentId, request: RequestData) -> Result<InternalResponseData, CfuError> {
let device = get_device(to).await;
if device.is_none() {
return Err(CfuError::InvalidComponent);
if let Some(device) = get_device(to).await {
device
.execute_device_request(request)
.await
.map_err(CfuError::ProtocolError)
} else {
Err(CfuError::InvalidComponent)
}
device
.unwrap()
.execute_device_request(request)
.await
.map_err(CfuError::ProtocolError)
}

/// Send a request to the specific CFU device, but don't wait for a response
pub async fn send_device_request(to: ComponentId, request: RequestData) -> Result<(), CfuError> {
let device = get_device(to).await;
if device.is_none() {
return Err(CfuError::InvalidComponent);
if let Some(device) = get_device(to).await {
device.send_request(request).await;
Ok(())
} else {
Err(CfuError::InvalidComponent)
}
device.unwrap().send_request(request).await;
Ok(())
}

/// Wait for a response from the specific CFU device
pub async fn wait_device_response(to: ComponentId) -> Result<InternalResponseData, CfuError> {
let device = get_device(to).await;
if device.is_none() {
return Err(CfuError::InvalidComponent);
if let Some(device) = get_device(to).await {
Ok(device.wait_response().await)
} else {
Err(CfuError::InvalidComponent)
}
Ok(device.unwrap().wait_response().await)
}

/// Singleton struct to give access to the cfu client context
Expand Down