Skip to content
Open
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
1 change: 1 addition & 0 deletions humility-core/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ pub trait Core {
pub enum NetAgent {
UdpRpc,
DumpAgent,
Hiffy,
}

pub fn attach_dump(
Expand Down
40 changes: 40 additions & 0 deletions humility-core/src/hubris.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2091,6 +2091,13 @@ impl HubrisArchive {
}
}

pub fn lookup_module_by_name(&self, name: &str) -> Result<&HubrisModule> {
match self.modules.values().find(|m| m.name == name) {
Some(module) => Ok(module),
None => Err(anyhow!("no such task: {name}")),
}
}

pub fn lookup_module_by_iface(&self, name: &str) -> Option<&HubrisModule> {
(0..self.ntasks())
.map(|t| self.lookup_module(HubrisTask::Task(t as u32)).unwrap())
Expand Down Expand Up @@ -6708,6 +6715,39 @@ impl HubrisModule {
}
}
}

/// Looks up enum variants by name, casting to a particular integer type
pub fn get_enum_variants_by_name<T: TryFrom<u64> + TryFrom<i64>>(
&self,
hubris: &HubrisArchive,
name: &str,
) -> Result<BTreeMap<String, T>>
where
<T as TryFrom<i64>>::Error: std::error::Error + Send + Sync + 'static,
<T as TryFrom<u64>>::Error: std::error::Error + Send + Sync + 'static,
{
let Some(enum_ty) = self.lookup_enum_byname(hubris, name)? else {
bail!("could not find enum `{name}`");
};
enum_ty
.variants
.iter()
.map(|v| {
let Some(tag) = v.tag else {
bail!("variant `{}` has no tag", v.name);
};
let t = match tag {
Tag::Signed(i) => T::try_from(i).with_context(|| {
format!("variant tag {i} for {} does not fit", v.name)
})?,
Tag::Unsigned(i) => T::try_from(i).with_context(|| {
format!("variant tag {i} for {} does not fit", v.name)
})?,
};
Ok((v.name.clone(), t))
})
.collect::<Result<BTreeMap<_, _>>>()
}
}

#[derive(Copy, Clone, Debug, Default)]
Expand Down
16 changes: 15 additions & 1 deletion humility-doppel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use humility::reflect::{self, Base, Load, Ptr, Value};
use indexmap::IndexMap;
use std::convert::TryInto;
use std::fmt;
use zerocopy::{AsBytes, LittleEndian, U16, U64};
use zerocopy::{AsBytes, LittleEndian, U16, U32, U64};

#[derive(Copy, Clone, Debug, Eq, PartialEq, Load)]
pub struct TaskDesc {
Expand Down Expand Up @@ -429,6 +429,20 @@ pub struct RpcHeader {
pub nbytes: U16<LittleEndian>,
}

/// Double of the RPC types from `hiffy` (with the `net` feature enabled)
pub mod hiffy {
use super::*;

#[derive(Copy, Clone, Debug, AsBytes)]
#[repr(C)]
pub struct RpcHeader {
pub image_id: U64<LittleEndian>,
pub version: U16<LittleEndian>,
pub operation: U16<LittleEndian>,
pub arg: U32<LittleEndian>,
}
}

impl humility::reflect::Load for CountedRingbuf {
fn from_value(v: &Value) -> Result<Self> {
let rb_struct = v.as_struct()?;
Expand Down
2 changes: 1 addition & 1 deletion humility-dump-agent/src/hiffy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl DumpAgent for HiffyDumpAgent<'_> {
// returned data size and the Hiffy context's `rdata` array size.
let op = self.hubris.get_idol_command("DumpAgent.read_dump")?;
let rsize = self.hubris.lookup_type(op.ok)?.size(self.hubris)?;
let chunksize = (self.context.rdata_size() / rsize) - 1;
let chunksize = (self.context.rstack_size() / rsize) - 1;

let mut rval = vec![];
loop {
Expand Down
Loading
Loading