Skip to content

Commit

Permalink
lib: set/get battery level and nominal capacity properties
Browse files Browse the repository at this point in the history
  • Loading branch information
smelamud authored and aesteve-rh committed Apr 19, 2024
1 parent e780e84 commit a4b5a50
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,30 @@ impl Vhal {
self.set_property(VehicleProperty::AP_POWER_STATE_REQ, value, 0, None)
}

pub fn set_battery_level(&self, speed: f32) -> Result<()> {
let value = VehiclePropertyValue::Float(speed);
self.set_property(VehicleProperty::EV_BATTERY_LEVEL, value, 0, None)
}

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

pub fn set_nominal_battery_capacity(&self, speed: f32) -> Result<()> {
let value = VehiclePropertyValue::Float(speed);
self.set_property(VehicleProperty::INFO_EV_BATTERY_CAPACITY, value, 0, None)
}

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

fn send_cmd(&self, cmd: EmulatorMessage) -> Result<()> {
debug!("Sending command: {:?}", cmd);
let msg_bytes = cmd.write_to_bytes().expect("msg");
Expand Down

0 comments on commit a4b5a50

Please sign in to comment.