Skip to content

Commit a98eb7d

Browse files
committed
Automatically Load the hiffy_call result
1 parent 511a371 commit a98eb7d

13 files changed

Lines changed: 211 additions & 376 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/console-proxy/src/posix.rs

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::os::unix::io::AsRawFd;
1010
use std::time::Duration;
1111
use std::{io, thread};
1212

13-
use anyhow::{Context, Result, anyhow, bail};
13+
use anyhow::{Context, Result};
1414
use clap::Parser;
1515
use crossbeam_channel::{Sender, select};
1616
use picocom_map::RemapRules;
@@ -53,7 +53,7 @@ impl<'a> UartConsoleHandler<'a> {
5353
fn uart_read(&mut self, buf: &mut [u8]) -> Result<usize> {
5454
let op = self.hubris.get_idol_command("ControlPlaneAgent.uart_read")?;
5555

56-
let value = humility_hiffy::hiffy_call(
56+
let v = humility_hiffy::hiffy_call::<u32>(
5757
self.hubris,
5858
self.core,
5959
&mut self.context,
@@ -63,14 +63,6 @@ impl<'a> UartConsoleHandler<'a> {
6363
Some(buf),
6464
)?;
6565

66-
let v = match value {
67-
Ok(v) => v,
68-
Err(e) => bail!("Got Hiffy error: {e}"),
69-
};
70-
71-
let v =
72-
v.as_base()?.as_u32().ok_or_else(|| anyhow!("Couldn't get U32"))?;
73-
7466
Ok(v as usize)
7567
}
7668

@@ -80,7 +72,7 @@ impl<'a> UartConsoleHandler<'a> {
8072

8173
let buf = &buf[..usize::min(buf.len(), HIFFY_BUF_SIZE)];
8274

83-
let value = humility_hiffy::hiffy_call(
75+
let v = humility_hiffy::hiffy_call::<u32>(
8476
self.hubris,
8577
self.core,
8678
&mut self.context,
@@ -90,14 +82,6 @@ impl<'a> UartConsoleHandler<'a> {
9082
None,
9183
)?;
9284

93-
let v = match value {
94-
Ok(v) => v,
95-
Err(e) => bail!("Got Hiffy error: {e}"),
96-
};
97-
98-
let v =
99-
v.as_base()?.as_u32().ok_or_else(|| anyhow!("Couldn't get U32"))?;
100-
10185
Ok(v as usize)
10286
}
10387

@@ -180,7 +164,7 @@ impl<'a> UartConsoleHandler<'a> {
180164
.hubris
181165
.get_idol_command("ControlPlaneAgent.set_humility_uart_client")?;
182166

183-
let value = humility_hiffy::hiffy_call(
167+
humility_hiffy::hiffy_call::<()>(
184168
self.hubris,
185169
self.core,
186170
&mut self.context,
@@ -189,19 +173,15 @@ impl<'a> UartConsoleHandler<'a> {
189173
None,
190174
None,
191175
)?;
192-
193-
match value {
194-
Ok(_) => Ok(()),
195-
Err(e) => bail!("Got Hiffy error: {e}"),
196-
}
176+
Ok(())
197177
}
198178

199179
fn current_client(&mut self) -> Result<()> {
200180
let op = self
201181
.hubris
202182
.get_idol_command("ControlPlaneAgent.get_uart_client")?;
203183

204-
let value = humility_hiffy::hiffy_call(
184+
let value = humility_hiffy::hiffy_call::<humility::reflect::Enum>(
205185
self.hubris,
206186
self.core,
207187
&mut self.context,
@@ -211,15 +191,6 @@ impl<'a> UartConsoleHandler<'a> {
211191
None,
212192
)?;
213193

214-
let value = match value {
215-
Ok(v) => v,
216-
Err(e) => bail!("Got Hiffy error: {e}"),
217-
};
218-
219-
let value = value
220-
.as_enum()
221-
.context("get_uart_client did not return an enum")?;
222-
223194
println!("Current console client: {}", value.disc());
224195
Ok(())
225196
}

cmd/hiffy/src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,15 +311,19 @@ fn hiffy(context: &mut ExecutionContext) -> Result<()> {
311311
};
312312

313313
(
314-
hiffy_call(
314+
match hiffy_call(
315315
hubris,
316316
core,
317317
&mut context,
318318
&op,
319319
&args,
320320
input.as_deref(),
321321
output.as_deref_mut(),
322-
)?,
322+
) {
323+
Ok(s) => Ok(s),
324+
Err(HiffyCallError::Hiffy(s)) => Err(s),
325+
Err(HiffyCallError::Other(e)) => return Err(e),
326+
},
323327
output,
324328
)
325329
};

cmd/host/src/lib.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ fn host_post_codes(
353353

354354
let mut context = HiffyContext::new(hubris, core, 5000)?;
355355
let op = hubris.get_idol_command("Sequencer.post_code_buffer_len")?;
356-
let value = humility_hiffy::hiffy_call(
356+
let count = humility_hiffy::hiffy_call::<u32>(
357357
hubris,
358358
core,
359359
&mut context,
@@ -362,12 +362,6 @@ fn host_post_codes(
362362
None,
363363
None,
364364
)?;
365-
let Ok(reflect::Value::Base(reflect::Base::U32(count))) = value else {
366-
bail!(
367-
"Got bad value from post_code_buffer_len: \
368-
expected U32, got {value:?}"
369-
);
370-
};
371365

372366
let op = hubris.get_idol_command("Sequencer.get_post_code")?;
373367
let handle_value = |v| {
@@ -440,7 +434,7 @@ fn host_last_post_code(
440434

441435
let mut context = HiffyContext::new(hubris, core, 5000)?;
442436
let op = hubris.get_idol_command("Sequencer.last_post_code")?;
443-
let value = humility_hiffy::hiffy_call(
437+
let v = humility_hiffy::hiffy_call::<u32>(
444438
hubris,
445439
core,
446440
&mut context,
@@ -449,9 +443,6 @@ fn host_last_post_code(
449443
None,
450444
None,
451445
)?;
452-
let Ok(reflect::Value::Base(reflect::Base::U32(v))) = value else {
453-
bail!("Got bad value from last_post_code: expected U32, got {value:?}");
454-
};
455446
if raw {
456447
println!("{v:08x}");
457448
} else {

0 commit comments

Comments
 (0)