Skip to content

Commit

Permalink
Support Read DID with hex input on commandline.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshLafleur committed Nov 4, 2024
1 parent b29cbf2 commit eb2a40e
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 4 deletions.
4 changes: 2 additions & 2 deletions conUDS/assets/nodes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ nodes:
request_id: 0x605
response_id: 0x645
bmsb:
request_id: 0x610
response_id: 0x650
request_id: 0x609
response_id: 0x649
9 changes: 9 additions & 0 deletions conUDS/src/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub enum ArgSubCommands {
Download(SubArgDownload),
Reset(SubArgReset),
BootloaderDownload(SubArgBootloaderDownload),
ReadDID(SubArgReadDID),
}

/// Download an application to an ECU
Expand Down Expand Up @@ -57,3 +58,11 @@ pub struct SubArgReset {
#[argh(option, short = 't', default = "SupportedResetTypes::Hard")]
pub reset_type: SupportedResetTypes,
}

/// Read a DID from an ECU
#[derive(Debug, FromArgs)]
#[argh(subcommand, name = "readDID")]
pub struct SubArgReadDID {
#[argh(positional)]
pub id: String,
}
11 changes: 9 additions & 2 deletions conUDS/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ async fn main() -> Result<()> {
"Performing {:#?} reset for node `{}`",
reset.reset_type, args.node
);
uds_client.ecu_reset(reset.reset_type).await?;
uds_client.ecu_reset(reset.reset_type).await;
}
ArgSubCommands::Download(dl) => {
debug!(
Expand All @@ -130,7 +130,6 @@ async fn main() -> Result<()> {
"Downloading binary at '{:#?}' to node `{}`",
dl.binary, args.node
);
let _ = uds_client.ecu_reset(SupportedResetTypes::Hard).await;
uds_client.start_persistent_tp().await?;

info!("Waiting for the user to hit enter before continuing with download");
Expand All @@ -144,6 +143,14 @@ async fn main() -> Result<()> {
error!("While downloading app: {}", e);
}
}
ArgSubCommands::ReadDID(did) => {
debug!(
"Performing DID read on {:#?} for node `{}`",
did, args.node
);
let id = u16::from_str_radix(&did.id, 16).unwrap();
let _ = uds_client.did_read(id).await;
}
}

app.lock().unwrap().exit = true;
Expand Down
41 changes: 41 additions & 0 deletions conUDS/src/modules/uds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,47 @@ impl UdsClient {
.await?)
}

pub async fn did_read(&mut self, did: u16) -> Result<()> {
let id: [u8; 2] = [
(did & 0xff).try_into().unwrap(),
(did >> 8).try_into().unwrap(),
];
let buf: [u8; 3] = [
UdsCommand::ReadDataByIdentifier.into(),
id[0],
id[1],
];

info!("Sending ECU read DID command: {:02x?}", buf);

match CanioCmd::send_recv(&buf, self.uds_queue_tx.clone(), 50)
.await?
.await
{
Ok(resp) => {
if resp.len() == 2 {
let nrc = UdsErrorByte::from(*resp.last().unwrap());
if nrc == ecu_diagnostics::Standard(UdsError::ServiceNotSupported) {
error!("Read DID not supported by ECU.");
}
else {
info!("ECU Read DID results: {:02x?}", resp);
}
}
else {
let app_id = u8::from(*resp.last().unwrap());
info!("ECU Read DID results: {:02x?}", resp);
info!("App ID: {:01x?}", app_id);
}
},
Err(e) => {
error!("When waiting for response from ECU: {}", e);
return Err(e.into());
}
}
Ok(())
}

pub async fn ecu_reset(&mut self, reset_type: SupportedResetTypes) -> Result<()> {
let buf = [
UdsCommand::ECUReset.into(),
Expand Down

0 comments on commit eb2a40e

Please sign in to comment.