The conversation on this page has been archived and is no longer active.

10.3.6 battery problem

Message #1 - Posted 2004/11/21 - Robert Peirce

Somebody suggested applying Apple's Battery Update 1.1. I tried it but got the message that it cannot be installed on my powerBook G4 because it is "not necessary."

Meanwhile, the problem continues.

Robert B. Peirce, Venetia, PA 724-941-6883
bob AT peirce-family.com [Mac]
rbp AT cooksonpeirce.com [Office]

Message #2 - Posted 2004/11/21 - Peter Renzland

On 2004-11-21, Robert Peirce wrote:

Somebody suggested applying Apple's Battery Update 1.1. I tried it but got the message that it cannot be installed on my powerBook G4 because it is "not necessary."

Meanwhile, the problem continues.

One thing that might help a bit until your problem gets solved is the latest version of bat.sh -- It now tries to give a more conservative estimate of your battery's charge level (and remaining time).

BTW, I could use some help with the FLAGS.
Goran, are you there?

Yesterday my flags went weird:

130 100% 2149 / 2149 mAh 12321 mV 0 mA F: 838860805 10:36:46 131 100% 2149 / 2149 mAh 12321 mV 0 mA F: 838860805 10:46:46 132 97% 2104 / 2149 mAh 12023 mV 1019 mA F: 4 88% 111 min. 11:14:17 133 97% 2094 / 2149 mAh 12049 mV 910 mA F: 4 89% 127 min. 11:15:17 134 97% 2086 / 2149 mAh 12056 mV 771 mA F: 516 90% 151 min. 11:16:17 135 94% 2033 / 2149 mAh 12202 mV 0 mA F: 838861829 12:42:53 136 94% 2036 / 2149 mAh 12354 mV -1200 mA F: 838861831 -5 min 12:43:53 137 95% 2044 / 2149 mAh 12367 mV -1061 mA F: 838861831 -5 min 12:44:54 138 95% 2050 / 2149 mAh 12380 mV -913 mA F: 838861831 -6 min 12:45:54 139 95% 2057 / 2149 mAh 12387 mV -763 mA F: 838861831 -7 min 12:46:54 140 95% 2063 / 2149 mAh 12393 mV -610 mA F: 838861831 -8 min 12:47:54 141 96% 2069 / 2149 mAh 12393 mV -452 mA F: 838861831 -10 min 12:48:55 142 96% 2074 / 2149 mAh 12407 mV -383 mA F: 838861831 -11 min 12:49:55 143 96% 2080 / 2149 mAh 12407 mV -363 mA F: 838861831 -11 min 12:50:55 144 97% 2085 / 2149 mAh 12407 mV -346 mA F: 838861831 -11 min 12:51:56 145 97% 2090 / 2149 mAh 12407 mV -324 mA F: 838861831 -10 min 12:52:56 146 97% 2095 / 2149 mAh 12407 mV -313 mA F: 838861831 -10 min 12:53:56 147 97% 2099 / 2149 mAh 12420 mV -305 mA F: 838861831 -9 min 12:54:56 148 97% 2104 / 2149 mAh 12420 mV -299 mA F: 838861831 -9 min 12:55:57 149 98% 2108 / 2149 mAh 12420 mV -291 mA F: 838861831 -8 min 12:56:57 150 98% 2113 / 2149 mAh 12420 mV -285 mA F: 838861831 -7 min 12:57:57 151 98% 2117 / 2149 mAh 12420 mV -277 mA F: 838861831 -6 min 12:58:58 152 98% 2121 / 2149 mAh 12420 mV -268 mA F: 838861831 -6 min 12:59:58 153 98% 2125 / 2149 mAh 12427 mV -255 mA F: 838861831 -5 min 13:00:58 154 99% 2129 / 2149 mAh 12427 mV -246 mA F: 838861831 -4 min 13:01:58 155 99% 2133 / 2149 mAh 12427 mV -238 mA F: 838861831 -4 min 13:02:59 156 100% 2149 / 2149 mAh 12374 mV -227 mA F: 838861831 0 min 13:03:59 157 100% 2149 / 2149 mAh 12360 mV -185 mA F: 838861829 0 min 13:04:59

What are those high order bits, anyway?

Anyways, Robert, maybe this helps. It should give you a pretty good estimate. You need to invoke it as bat.sh 60 13700 15800 or something like that.

Here it is:

#! /bin/sh
# bat.sh [SECWAIT] [MVEMPTY [MVFULL]]
# monitor battery while [dis]charging # Peter Renzland 041118 # when plugged in and fully charged [F=838860805 P=100 A=0] check every 10 min. # otherwise every SECWAIT seconds (Default 60)
# Renzland's conjecture: %charge = (mV - mVempty) / mVrange * 100 # mVrange = mVfull - mVempty {iBook G3: 12200-10700 = 1500} # Todo: display flags nicer: lxdwuBCP or just .....BCP (high flag bits???)

# I suggest you run this all the time. Then, when you unplug your computer # it will monitor your battery (within 10 minutes) and beep when necessary.

SECWAIT=${1-60} # Wait this long between checks MVEMPTY=${2-10700} # millivolts when Battery is discharged [G3 iBook default] MVFULL=${3-12200} # millivolts when Battery is full and discharging. MVRANGE=`expr $MVFULL - $MVEMPTY`

SEQNUM=0 # How many measurements have we made
LASTCHARGE=0

while :
do
set -- ` /usr/sbin/ioreg -p IODeviceTree -n battery -w 0 \

grep IOBatteryInfo | tr '[\"\=\(\{\)\}\,]' ' ' `

# X X X X Capacity 2405 Amperage 1108 Current 2390 Voltage 12109 Flags 4

# ioreg may return e.g.: Amperage = 18446744073709550464 when plugged in

shift 5
K=$1 A=$3 C=$5 V=$7 F=$9

case $SEQNUM in
?) echo -n " $SEQNUM " ;;
??) echo -n " $SEQNUM " ;;
*) echo -n "$SEQNUM " ;;
esac

P="`expr $C \* 100 / $K`"
case $P in
?) echo -n " $P% " ;;
??) echo -n " $P% " ;;
*) echo -n "$P% " ;;
esac

echo -n "$C / $K mAh"
DROP=`expr $LASTCHARGE - $C`
case "$DROP" in -*) DROP=`expr 0 - $DROP` ;; esac if [ $DROP -gt $SECWAIT ]
then echo -n "!\a"; sleep 1; echo -n "!\a"; sleep 1; echo -n "!\a" fi
LASTCHARGE=$C

echo -n " $V mV"

case $V in
108*) echo -n "!\a" ;;
107*) echo -n "!\a"; sleep 1; echo -n "!\a" ;; 106*) echo -n "!\a"; sleep 1; echo -n "!\a"; sleep 1; echo -n "!\a" ;; esac

case $A in ?????????*) MA="-`expr 0 - $A`";; *)MA=$A;; esac echo -n " $MA mA "
echo -n "F: $F "

case $A in 0) ;;
*)
case $F in
?????*) MIN=`expr \( $K - $C \) \* 60 / $A` # Time left until charged full echo -n "$MIN min"
;;
*) PCP=`expr \( $V - $MVEMPTY \) \* 100 / $MVRANGE` # % left MIN=`expr \( $V - $MVEMPTY \) \* 60 \* $K / $A / $MVRANGE` # Time left echo -n "\e[7m$PCP% $MIN min.\e[0m "
;;
esac
;;
esac

date "+ %H:%M:%S"
case $F$P$A in 8388608051000) sleep 600 ;; *) sleep $SECWAIT ;; esac SEQNUM=`expr $SEQNUM + 1`
done
exit

Message #3 - Posted 2004/11/21 - Goran Larsson

Previously, Peter Renzland wrote:

BTW, I could use some help with the FLAGS. Goran, are you there?

Yes. First, don't display the flags as a decimal number. It is impossible for a human to decode that just by looking at it. At least display it as a 32 bit hexadecimal or binary number.

Your readings should then display as this:

Decimal Hexadecimal Binary
--------- ----------- ----------------------------------- 838860805 32000005 00110010 00000000 00000000 00000101 4 00000004 00000000 00000000 00000000 00000100 516 00000204 00000000 00000000 00000010 00000100 838861829 32000405 00110010 00000000 00000100 00000101 838861831 32000407 00110010 00000000 00000100 00000111 838861829 32000405 00110010 00000000 00000100 00000101

Before Panther (10.3) only the lower (rightmost) eight bits were used with the following meanings:

Flag mask Bit Meaning
---------- --- --------------------------------------- 0x00000001 0 A charger is connected to the computer. 0x00000002 1 The battery is charging.
0x00000004 2 A battery is installed.
0x00000008 3 An UPS, uninteruptable power supply, is installed. 0x00000010 4 The battery at or below the set warning level. 0x00000020 5 The battery depleted (empty).
0x00000040 6 There is no charging capability. (stationary system?) 0x00000080 7 There is a raw "low battery" signal from the electronics inside the battery.

Your readings should then decode in this sequence:

Flag Meaning
---- ----------------------------------------------------- 05 battery is installed + charger is connected
04 battery is installed
04 battery is installed
05 battery is installed + charger is connected
07 battery is installed + battery is charging + charger is connected 05 battery is installed + charger is connected

I have not investigated the meaning of the other 24 bits. I had to look in the source code for Darwin to find out how the bits worked in Jaguar. Unless someone else knows the meaning of the other 24 bits I have to look in the Darwin source code for Panther when I get some spare time.

A battery program that already decodes the known flag bits is available here:

< http://www.mitt-eget.com/software/macosx/#battery >

$ battery
Battery 1
Battery: battery installed, above warning level
Charger: charger not connected, not charging
UPS: UPS not installed
Voltage: 10.617V
Current: 1.115A (discharge rate giving 0 hours and 23 minutes) Capacity: 0.430Ah of 4.149Ah (10.4%)

$ battery short
2003-03-17 00:51:57 1 _____i__ 10.617V 1.098A 0.453Ah of 4.149Ah (10.9%)

$ battery compact
20030317 124528 1 00000101 12.556 1.200 4.134 4.149 99.6

Gˆran Larsson http://www.mitt-eget.com/

Message #4 - Posted 2004/11/22 - Peter Renzland

On 2004-11-21, Goran Larsson wrote:

Previously, Peter Renzland wrote:

BTW, I could use some help with the FLAGS. Goran, are you there?

Yes. First, don't display the flags as a decimal number. It is impossible for a human to decode that just by looking at it. At least display it as a 32 bit hexadecimal or binary number.

I had started bat.sh in ksh but then dumbed it down to sh because not everyone can handle ksh. Hex/Bin is a little more ugly in sh. But yes, it's on the bat.sh todo list, as posted a couple of days ago.

I have not investigated the meaning of the other 24 bits. I had to look in the source code for Darwin to find out how the bits worked in Jaguar. Unless someone else knows the meaning of the other 24 bits I have to look in the Darwin source code for Panther when I get some spare time.

Yes, those are what I need, since they are changing. Maybe it's just "noise", but I'd like to know.

A battery program that already decodes the known flag bits is available here:

< http://www.mitt-eget.com/software/macosx/#battery >

Yes. Very fine shell programming. Good documentation of low-order flag bits.

-- Peter

Message #5 - Posted 2004/11/22 - Goran Larsson

Previously, Peter Renzland wrote:

I had started bat.sh in ksh but then dumbed it down to sh because not everyone can handle ksh. Hex/Bin is a little more ugly in sh.

The bit handling and the floating point calculations are much easier in zsh than in sh. The "end user" of the script doesn't have to understand ksh or sh to run the script, so I don't understand that decision unless you expect the "end user" to modify the script.

Yes, those are what I need, since they are changing. Maybe it's just "noise", but I'd like to know.

Perhaps. I have seen enough of them that I think they do indicate something, but not enough of them to understand what they indicate. This annoys me --> have to find out.

Yes. Very fine shell programming. Good documentation of low-order flag bits.

Thanks. I always try to keep the source code neat and well documented, both for paying and non-paying customers.

Gˆran Larsson http://www.mitt-eget.com/

Message #6 - Posted 2006/09/13 - Martin Trautmann

On 21 Nov 2004 04:40:23 GMT Peter Renzland wrote:

It should give you a pretty good estimate. You need to invoke it as bat.sh 60 13700 15800 or something like that.

Hi Peter,

I don't know whether you're still around here.
Did you ever build an update for bat.sh?

Later versions return a different IOBatteryInfo line, which can be fixed easily - but maybe you added even further improvements by now.

Thanks
Martin

Need Help? Have a Question?

Looking for more help, comments, and answers?

Ask your questions on Ask Different. Ask Different is a community of Apple users ready to help.