Skip to content

Commit

Permalink
Loop for the right msg_type
Browse files Browse the repository at this point in the history
Signed-off-by: Albert Esteve <[email protected]>
  • Loading branch information
aesteve-rh committed Jan 23, 2024
1 parent 80d3f65 commit e403d28
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,10 @@ impl Vhal {

pub fn get_gear_selection(&self) -> Result<c::VehicleGear> {
self.get_property(VehicleProperty::GEAR_SELECTION, 0)?;
let resp = self.recv_cmd()?;
resp.is_valid(VehicleHalProto::MsgType::GET_PROPERTY_RESP)?;
let mut resp = self.recv_cmd()?;
while resp.is_valid(VehicleHalProto::MsgType::GET_PROPERTY_RESP).is_err() {
resp = self.recv_cmd()?;
}

Ok(c::VehicleGear::try_from(resp.expect_i32()?)
.map_err(|_| VhalError::ReceiveMessageValueError)?)
Expand All @@ -343,8 +345,10 @@ impl Vhal {

pub fn get_vehicle_speed(&self) -> Result<f32> {
self.get_property(VehicleProperty::PERF_VEHICLE_SPEED, 0)?;
let resp = self.recv_cmd()?;
resp.is_valid(VehicleHalProto::MsgType::GET_PROPERTY_RESP)?;
let mut resp = self.recv_cmd()?;
while resp.is_valid(VehicleHalProto::MsgType::GET_PROPERTY_RESP).is_err() {
resp = self.recv_cmd()?;
}
resp.expect_f32()
}

Expand All @@ -355,8 +359,10 @@ impl Vhal {

pub fn get_vehicle_display_speed(&self) -> Result<f32> {
self.get_property(VehicleProperty::PERF_VEHICLE_SPEED_DISPLAY, 0)?;
let resp = self.recv_cmd()?;
resp.is_valid(VehicleHalProto::MsgType::GET_PROPERTY_RESP)?;
let mut resp = self.recv_cmd()?;
while resp.is_valid(VehicleHalProto::MsgType::GET_PROPERTY_RESP).is_err() {
resp = self.recv_cmd()?;
}
resp.expect_f32()
}

Expand Down

0 comments on commit e403d28

Please sign in to comment.