Package: acpitool
Version: 0.5-3
Severity: minor
Tags: patch
Hi Daniel,
please find attached a new version of my patch you included in acpitool 0.5-3.
This version basically adds two things:
1. report values as mili-*, not micro-* as it was always the case in procfs
2. report units of values we know (or can guess), this was also present in
procfs but sysfs shows only plain integers.
Regards
Evgeni
-- System Information:
Debian Release: squeeze/sid
APT prefers unstable
APT policy: (500, 'unstable'), (500, 'testing'), (1, 'experimental')
Architecture: i386 (i686)
Kernel: Linux 2.6.30-1-686 (SMP w/1 CPU core)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Versions of packages acpitool depends on:
ii libc6 2.9-19 GNU C Library: Shared libraries
ii libgcc1 1:4.4.0-10 GCC support library
ii libstdc++6 4.4.0-10 The GNU Standard C++ Library v3
Versions of packages acpitool recommends:
ii acpid 1.0.10-2 Utilities for using ACPI power man
acpitool suggests no packages.
-- no debconf information
--- acpitool-0.5~/src/acpitool.h 2008-07-22 00:11:40.000000000 +0200
+++ acpitool-0.5/src/acpitool.h 2009-05-26 17:20:18.000000000 +0200
@@ -39,6 +39,7 @@
char Serial[13];
char Bat_Type[13];
char Voltage_Now[13];
+ char Charge_Now[13];
};
--- acpitool-0.5~/src/battery.cpp 2008-07-24 01:04:16.000000000 +0200
+++ acpitool-0.5/src/battery.cpp 2009-07-06 21:10:54.000000000 +0200
@@ -102,6 +102,7 @@
memset(Batt_Info[i]->Model, '\0', 13);
memset(Batt_Info[i]->Serial, '\0', 13);
memset(Batt_Info[i]->Bat_Type, '\0', 13);
+ memset(Batt_Info[i]->Charge_Now, '\0', 13);
// initialize all struct members to blanks --> avoid rubbish in output //
if(Use_Proc)
@@ -133,19 +134,24 @@
else
Precision = 4;
- if(strncmp(Batt_Info[i]->Charging_State,"char",4)==0)
+ if(strncasecmp(Batt_Info[i]->Charging_State,"char",4)==0)
{
Is_Charging = 1;
}
else
{
- if(strncmp(Batt_Info[i]->Charging_State,"disch",5)==0) Is_Discharging = 1;
+ if(strncasecmp(Batt_Info[i]->Charging_State,"disch",5)==0) Is_Discharging = 1;
}
if(Show_Time) // calculate remaining or charging time only if present battery rate != 0 //
{
- if(Is_Charging)
+ if(Is_Charging) {
+ if (strcmp(Batt_Info[i]->Charge_Now,"")!=0 &&
+ strcmp(Batt_Info[i]->Charge_Now,"unknown")!=0)
+ Remaining_Time = float(atoi(Batt_Info[i]->Charge_Now)) / float(atoi(Batt_Info[i]->Present_Rate));
+ else
Remaining_Time = (float(atoi(Batt_Info[i]->LastFull_Cap)) - float(atoi(Batt_Info[i]->Remaining_Cap))) / float(atoi(Batt_Info[i]->Present_Rate));
+ }
else
Remaining_Time = float(atoi(Batt_Info[i]->Remaining_Cap)) / float(atoi(Batt_Info[i]->Present_Rate));
// this represents hours //
@@ -482,8 +488,8 @@
int Get_Battery_Info_from_Sys(const int bat_nr, Battery_Info *bat_info, int verbose)
{
ifstream file_in;
- char filename[6][65], str[100], temp[100];
- int bat_count = 0, start = 0, findex = 0;
+ char filename[6][65], str[100], temp[100], attr[100];
+ int bat_count = 0, start = 0, findex = 0, value = 0;
DIR *battery_dir;
char *name, *dirname;
@@ -588,142 +594,89 @@
return -1;
}
- memset(str, '\0', 100);
- for(int t=0; t<5; t++)
- fgets(str, 100, power_fp); /* skip first 5 lines */
+ strncpy(bat_info->Technology, "unknown", 7);
+ strncpy(bat_info->Voltage_Now, "unknown", 7);
+ strncpy(bat_info->Charge_Now, "unknown", 7);
+ strncpy(bat_info->Present_Rate, "unknown", 7);
+ strncpy(bat_info->Design_Cap, "unknown", 7);
+ strncpy(bat_info->LastFull_Cap, "unknown", 7);
+ strncpy(bat_info->Remaining_Cap, "unknown", 7);
+ strncpy(bat_info->Model, "unknown", 7);
+ strncpy(bat_info->Serial, "unknown", 7);
+
+ // see linux-2.6/drivers/power/power_supply_sysfs.c
+ // there can be different number of lines, so read up to 40 lines
+ for(int t=0; t<40; t++) {
- /* get battery status (full, charging, ...) */
memset(str, '\0', 100);
- fgets(str, 100, power_fp);
- if (strlen(str)>0)
- {
+ memset(attr, '\0', 100);
memset(temp, '\0', 100);
+ fgets(str, 100, power_fp);
+ sscanf(str, "%[^=]s %*s %[^\n]", attr);
sscanf(str, "%*[^=] %*c %s %[^\n]",temp);
+ if (strcmp(attr,"POWER_SUPPLY_STATUS")==0) {
strncpy(bat_info->Charging_State, temp, 12);
}
-
-
- /* get battery presence (0 or 1) */
- memset(str, '\0', 100);
- fgets(str, 100, power_fp);
- if (strlen(str)>0)
- {
- memset(temp, '\0', 100);
- strncpy(temp, str+21, 1);
- if(strncmp(temp,"1",1)==0)
- bat_info->Battery_Present = 1; /* yes, we have a battery */
- else
- {
- bat_info->Battery_Present = 0;
- printf(" Battery is not present, bailing out. \n");
- return 0; /* bail out if battery is not present */
- }
+ else if (strcmp(attr,"POWER_SUPPLY_TYPE")==0) {
+ strncpy(bat_info->Bat_Type, temp, 12);
}
-
-
- /* get technology */
- fgets(str, 100, power_fp);
- if (strlen(str)>0)
- {
- memset(temp, '\0', 100);
- sscanf(str, "%*[^=] %*c %s %[^\n]",temp);
+ else if (strcmp(attr,"POWER_SUPPLY_TECHNOLOGY")==0) {
strncpy(bat_info->Technology, temp, 12);
}
- else
- strncpy(bat_info->Technology, "unknown", 7);
-
-
- fgets(str, 100, power_fp); /* skip 1 line */
-
-
- /* get voltage_now */
- fgets(str, 100, power_fp);
- if (strlen(str)>0)
- {
- memset(temp, '\0', 100);
- sscanf(str, "%*[^=] %*c %s %[^\n]",temp);
+ else if (strcmp(attr,"POWER_SUPPLY_VOLTAGE_NOW")==0) {
+ value = atoi(temp) / 1000;
+ snprintf(temp, sizeof(temp), "%i mV", value);
strncpy(bat_info->Voltage_Now, temp, 12);
}
- else
- strncpy(bat_info->Voltage_Now, "unknown", 7);
-
-
- /* get current_now, which I believe is the charging rate ? */
- fgets(str, 100, power_fp);
- if (strlen(str)>0)
- {
- memset(temp, '\0', 100);
- sscanf(str, "%*[^=] %*c %s %[^\n]",temp);
- strncpy(bat_info->Present_Rate, temp, 12);
+ else if (strcmp(attr,"POWER_SUPPLY_CURRENT_NOW")==0 ||
+ strcmp(attr,"POWER_SUPPLY_POWER_NOW")==0) {
+ value = atoi(temp) / 1000;
+ snprintf(temp, sizeof(temp), "%i", value);
+ strncpy(bat_info->Present_Rate, temp, 9);
+ }
+ else if (strcmp(attr,"POWER_SUPPLY_CHARGE_NOW")==0) {
+ value = atoi(temp) / 1000;
+ snprintf(temp, sizeof(temp), "%i mA", value);
+ strncpy(bat_info->Charge_Now, temp, 12);
+ }
+ else if (strcmp(attr,"POWER_SUPPLY_ENERGY_FULL_DESIGN")==0) {
+ value = atoi(temp) / 1000;
+ snprintf(temp, sizeof(temp), "%i mWh", value);
+ strncpy(bat_info->Design_Cap, temp, 9);
+ }
+ else if (strcmp(attr,"POWER_SUPPLY_ENERGY_FULL")==0) {
+ value = atoi(temp) / 1000;
+ snprintf(temp, sizeof(temp), "%i mWh", value);
+ strncpy(bat_info->LastFull_Cap, temp, 9);
+ }
+ else if (strcmp(attr,"POWER_SUPPLY_ENERGY_NOW")==0) {
+ value = atoi(temp) / 1000;
+ snprintf(temp, sizeof(temp), "%i mWh", value);
+ strncpy(bat_info->Remaining_Cap, temp, 9);
}
- else
- strncpy(bat_info->Present_Rate, "unknown", 7);
-
-
- /* get charge_full_design */
- fgets(str, 100, power_fp);
- if (strlen(str)>0)
- {
- memset(temp, '\0', 100);
- sscanf(str, "%*[^=] %*c %s %[^\n]",temp);
- strncpy(bat_info->Design_Cap, temp, 12);
+ else if (strcmp(attr,"POWER_SUPPLY_MODEL_NAME")==0) {
+ strncpy(bat_info->Model, temp, 12);
}
- else
- strncpy(bat_info->Design_Cap, "unknown", 7);
-
-
- /* get charge_full, which is the last full capacity I guess ? */
- fgets(str, 100, power_fp);
- if (strlen(str)>0)
- {
- memset(temp, '\0', 100);
- sscanf(str, "%*[^=] %*c %s %[^\n]",temp);
- strncpy(bat_info->LastFull_Cap, temp, 12);
+ else if (strcmp(attr,"POWER_SUPPLY_SERIAL_NUMBER")==0) {
+ strncpy(bat_info->Serial, temp, 12);
}
- else
- strncpy(bat_info->LastFull_Cap, "unknown", 7);
-
-
- /* get charge_now */
- fgets(str, 100, power_fp);
- if (strlen(str)>0)
- {
- memset(temp, '\0', 100);
- sscanf(str, "%*[^=] %*c %s %[^\n]",temp);
- strncpy(bat_info->Remaining_Cap, temp, 12);
+ else if (strcmp(attr,"POWER_SUPPLY_PRESENT")==0) {
+ if(strncmp(temp,"1",1)==0) {
+ bat_info->Battery_Present = 1;
+ }
+ else {
+ bat_info->Battery_Present = 0;
+ printf(" Battery is not present, bailing out. \n");
+ return 0;
}
- else
- strncpy(bat_info->Remaining_Cap, "unknown", 7);
-
-
- /* get model_name */
-
- fgets(str, 100, power_fp);
- if (strlen(str)>0)
- {
- memset(temp, '\0', 100);
- strncpy(temp, str+24, 12); // use strncpy here because sscanf chokes on blanks in this one ? //
-
- memset(str, '\0', 100);
- sscanf(temp, "%[^\n]", str); // strip trailing \n, fucks up output //
-
- strncpy(bat_info->Model, str, 12);
}
- else
- strncpy(bat_info->Model, "unknown", 7);
-
- fgets(str, 100, power_fp);
-
- /* get serial */
- fgets(str, 100, power_fp);
- if (strlen(str)!=0)
- {
- memset(temp, '\0', 100);
- sscanf(str, "%*[^=] %*c %s %[^\n]",temp);
- strncpy(bat_info->Serial, temp, 12);
}
+ if (strcmp(bat_info->Charge_Now,"")!=0 &&
+ strcmp(bat_info->Charge_Now,"unknown")!=0)
+ snprintf(temp, sizeof(temp), "%s mA", bat_info->Present_Rate);
else
- strncpy(bat_info->Serial, "unknown", 7);
+ snprintf(temp, sizeof(temp), "%s mW", bat_info->Present_Rate);
+ strncpy(bat_info->Present_Rate, temp, 9);
fclose(power_fp);
}