diff --git a/core/app_scenario.py b/core/app_scenario.py index a80acc4..d113546 100644 --- a/core/app_scenario.py +++ b/core/app_scenario.py @@ -781,6 +781,7 @@ def monitorLife(self): logging.info("Life monitoring thread started") # Poll DUT to see if it's still responsive, if not, raise timeout exception file_path = self.result_dir + os.sep + 'battery_level.txt' + csv_path = self.result_dir + os.sep + 'battery_level.csv' while(True): try: if self.platform.lower() == 'windows': @@ -795,13 +796,26 @@ def monitorLife(self): # logging.info("RTC Wake timer reset") time.sleep(900) elif self.platform.lower() == 'macos': - result = self._call(["pmset", "-g batt"], blocking=True) - level = result.split("\n")[1].split("\t")[1].split("%")[0] + # Get AppleRawCurrentCapacity level via ioreg + raw_current_capacity_result = self._call(["bash", '-c "ioreg -r -c AppleSmartBattery -a | plutil -extract 0.AppleRawCurrentCapacity raw -"'], blocking=True) + raw_current_capacity_level = raw_current_capacity_result.strip() + + # Get AppleRawMaxCapacity level via ioreg + raw_max_capacity_result = self._call(["bash", '-c "ioreg -r -c AppleSmartBattery -a | plutil -extract 0.AppleRawMaxCapacity raw -"'], blocking=True) + raw_max_capacity_level = raw_max_capacity_result.strip() + + # Calculate Battery level to 2 decimal places + level = round(float(raw_current_capacity_level) / float(raw_max_capacity_level) * 100, 2) + current_time = datetime.now() time_s = current_time.strftime("%m/%d/%Y %I:%M:%S %p") - logging.info(f"Battery level: {level}") + logging.info(f"Battery level : {str(level)}") + + # Write human-readable txt log with open(file_path, 'a', newline='') as f: - f.write(f"{time_s}: total battery: {level}\n") + f.write(f"{time_s}: total battery: {str(level)}\n") + + if int(level) <= int(self.stop_soc): break time.sleep(int(self.poll_rate)) diff --git a/utilities/open_source/config_check.sh b/utilities/open_source/config_check.sh index 3d4b48f..db5f029 100644 --- a/utilities/open_source/config_check.sh +++ b/utilities/open_source/config_check.sh @@ -115,7 +115,10 @@ if [ "$PreRun" = true ]; then # add_to_table "Scenario" "" add_to_table "Run Start Time" "$(date +'%Y-%m-%d %H:%M:%S')" # Add current battery level without the percent sign - battery_level=$(pmset -g batt | grep -o '[0-9]\+%' | head -n 1 | tr -d '%') + # battery_level=$(pmset -g batt | grep -o '[0-9]\+%' | head -n 1 | tr -d '%') + raw_current_capacity_level=$(ioreg -r -c AppleSmartBattery -a | plutil -extract 0.AppleRawCurrentCapacity raw -) + raw_max_capacity_level=$(ioreg -r -c AppleSmartBattery -a | plutil -extract 0.AppleRawMaxCapacity raw -) + battery_level=$(printf "%.2f" $(echo "$raw_current_capacity_level / $raw_max_capacity_level * 100" | bc -l)) add_to_table "Run Start Battery State (%)" "$battery_level" battery_status=$(pmset -g batt | grep -o 'discharging\|charging\|charged' | head -n 1) add_to_table "Run Start Charge State" "$battery_status" @@ -144,7 +147,10 @@ elif [ "$PostRun" = true ]; then run_stop_time=$(date +'%Y-%m-%d %H:%M:%S') add_to_table "Run Stop Time" "$run_stop_time" # Add current battery level without the percent sign - battery_level=$(pmset -g batt | grep -o '[0-9]\+%' | head -n 1 | tr -d '%') + # battery_level=$(pmset -g batt | grep -o '[0-9]\+%' | head -n 1 | tr -d '%') + raw_current_capacity_level=$(ioreg -r -c AppleSmartBattery -a | plutil -extract 0.AppleRawCurrentCapacity raw -) + raw_max_capacity_level=$(ioreg -r -c AppleSmartBattery -a | plutil -extract 0.AppleRawMaxCapacity raw -) + battery_level=$(printf "%.2f" $(echo "$raw_current_capacity_level / $raw_max_capacity_level * 100" | bc -l)) add_to_table "Run Stop Battery State (%)" "$battery_level" battery_status=$(pmset -g batt | grep -o 'discharging\|charging\|charged' | head -n 1) add_to_table "Run Stop Charge State" "$battery_status" diff --git a/utilities/proprietary/ParsePowerLight/parse_power_light.dll b/utilities/proprietary/ParsePowerLight/parse_power_light.dll index 9c5b716..5d3a8cf 100644 Binary files a/utilities/proprietary/ParsePowerLight/parse_power_light.dll and b/utilities/proprietary/ParsePowerLight/parse_power_light.dll differ diff --git a/utilities/proprietary/ParsePowerLight/parse_power_light.exe b/utilities/proprietary/ParsePowerLight/parse_power_light.exe index 0dbbd19..9e81aca 100644 Binary files a/utilities/proprietary/ParsePowerLight/parse_power_light.exe and b/utilities/proprietary/ParsePowerLight/parse_power_light.exe differ diff --git a/utilities/proprietary/ParsePowerLight/parse_power_light.pdb b/utilities/proprietary/ParsePowerLight/parse_power_light.pdb index c1bced6..50eea86 100644 Binary files a/utilities/proprietary/ParsePowerLight/parse_power_light.pdb and b/utilities/proprietary/ParsePowerLight/parse_power_light.pdb differ