Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mediation sysfs Update health values for battery. #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Mediation sysfs Update health values for battery.
add sysfs read for charge_full and charge_full_design
to update battery health

Tracked-On: OAM-99045
Signed-off-by: Kothapeta, BikshapathiX <bikshapathix.kothapeta@intel.com>
  • Loading branch information
bkothapx committed Jan 18, 2022
commit 147032bb1cbd93d1ed11ff303c1159c65bf945f7
13 changes: 8 additions & 5 deletions vm_battery_utility/battery_sysfsread.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void get_battery_module_name(char *buf)
* module.
*/

void read_sysfs_values(char *filename, void *buf, int len, int flag)
int read_sysfs_values(char *filename, void *buf, int len, int flag)
{
char sysfs_path[120];

Expand All @@ -84,15 +84,15 @@ void read_sysfs_values(char *filename, void *buf, int len, int flag)
FILE *fp = fopen(sysfs_path, "r");
if (!fp) { /* validate file open for reading */
fprintf (stderr, "Failed to open file for read.\n");
return;
return -ENODEV;
}

if (flag==0)
fread(buf, len, 1, fp);
else
fscanf (fp, "%d", (int*)buf); /* read/validate value */
fclose (fp);
return;
return 0;
}

/* read_store_values: Read and store all the battery related sysfs values
Expand All @@ -101,19 +101,22 @@ void read_sysfs_values(char *filename, void *buf, int len, int flag)

void read_store_values()
{
int ret;
read_sysfs_values(MODEL_NAME, initpkt.model_name, sizeof(initpkt.model_name), 0);
read_sysfs_values(SERIAL_NUMBER, initpkt.serial_number, sizeof(initpkt.serial_number), 0);
read_sysfs_values(MANUFACTURER, initpkt.manufacturer, sizeof(initpkt.manufacturer), 0);
read_sysfs_values(TECHNOLOGY, initpkt.technology, sizeof(initpkt.technology), 0);
read_sysfs_values(TYPE, initpkt.type, sizeof(initpkt.type), 0);
read_sysfs_values(PRESENT, initpkt.present, sizeof(initpkt.present), 0);
read_sysfs_values(CAPACITY, &monitorpkt.capacity, sizeof(monitorpkt.capacity), 1);
read_sysfs_values(CHARGE_FULL_DESIGN, &monitorpkt.charge_full_design, sizeof(monitorpkt.charge_full_design), 1);
ret = read_sysfs_values(CHARGE_FULL_DESIGN, &monitorpkt.charge_full_design, sizeof(monitorpkt.charge_full_design), 1);
if (ret != 0) monitorpkt.charge_full_design = 0;
read_sysfs_values(HEALTH, monitorpkt.health, sizeof(monitorpkt.health), 0);
read_sysfs_values(TEMP, &monitorpkt.temp, sizeof(monitorpkt.temp), 1);
read_sysfs_values(CHARGE_NOW, &monitorpkt.charge_now, sizeof(monitorpkt.charge_now), 1);
read_sysfs_values(TIME_TO_EMPTY_AVG, &monitorpkt.time_to_empty_avg, sizeof(monitorpkt.time_to_empty_avg), 1);
read_sysfs_values(CHARGE_FULL, &monitorpkt.charge_full, sizeof(monitorpkt.charge_full), 1);
ret = read_sysfs_values(CHARGE_FULL, &monitorpkt.charge_full, sizeof(monitorpkt.charge_full), 1);
if (ret != 0) monitorpkt.charge_full = 0;
read_sysfs_values(TIME_TO_FULL_NOW, &monitorpkt.time_to_full_now, sizeof(monitorpkt.time_to_full_now), 1);
read_sysfs_values(VOLTAGE_NOW, &monitorpkt.voltage_now, sizeof(monitorpkt.voltage_now), 1);
read_sysfs_values(CHARGE_TYPE, monitorpkt.charge_type, sizeof(monitorpkt.charge_type), 0);
Expand Down