FreeBSD笔记本电脑找出电池寿命状态命令

时间:2020-01-09 10:38:32  来源:igfitidea点击:

如何使用Linux操作系统找出电池寿命状态。
如何在运行FreeBSD版本9.x/10.x/11.x/12.x的笔记本电脑上监视电池状态?
您可以使用以下任一命令来获取FreeBSD笔记本电脑下的电池状态,包括剩余电池寿命等。

FreeBSD笔记本电脑找出电池寿命状态命令

  • " apm"命令:apm实用程序控制Intel/Microsoft APM(高级电源管理)BIOS,并在便携式PC上显示APM的当前状态。
  • sysctl命令:sysctl实用程序检索内核状态。
  • hwstat命令:另一个显示CPU温度和电池信息的命令行工具。
  • acpiconf命令:acpiconf命令允许用户控制ACPI电源管理功能并查询笔记本电脑的电池状态。

amp命令示例

语法为:

apm
apm [options]

执行以下命令:

$ apm

sysctl命令示例

执行以下命令:

$ sysctl hw.acpi.battery

输出示例:

hw.acpi.battery.info_expire: 5
hw.acpi.battery.units: 2
hw.acpi.battery.state: 1 # This will be -1 when we have AC power attached. #
hw.acpi.battery.time: 111
hw.acpi.battery.life: 70

hwstat命令

hwstat命令不是基本系统的一部分。
输入以下命令以使用pkg_add命令/pkg命令安装hwstat:

# pkg install hwstat

或者

# pkg_add -rv hwstat

输出示例:

scheme:   [ftp]
user:     []
password: []
host:     [ftp.freebsd.org]
port:     [0]
document: [/pub/FreeBSD/ports/amd64/packages-9.0-release/Latest/hwstat.tbz]
---> ftp.freebsd.org:21
looking up ftp.freebsd.org
connecting to ftp.freebsd.org:21
<<< 220 beastie.tdk.net FTP server (Version 6.00LS) ready.
>>> USER anonymous
<<< 331 Guest login ok, send your email address as password.
>>> PASS Hyman@fdbsd9
<<< 230 Guest login ok, access restrictions apply.
>>> PWD
<<< 257 "/" is current directory.
>>> CWD pub/FreeBSD/ports/amd64/packages-9.0-release/Latest
<<< 250 CWD command successful.
>>> MODE S
<<< 200 MODE S accepted.
>>> TYPE I
<<< 200 Type set to I.
setting passive mode
>>> PASV
<<< 227 Entering Passive Mode (193,162,146,4,226,183)
opening data connection
initiating transfer
>>> RETR hwstat.tbz
<<< 150 Opening BINARY mode data connection for 'hwstat.tbz' (8779 bytes).
Fetching ftp://ftp.freebsd.org/pub/FreeBSD/ports/amd64/packages-9.0-release/Latest/hwstat.tbz...Waiting for final status
<<< 226 Transfer complete.
x +CONTENTS
x +COMMENT
x +DESC
x +MTREE_DIRS
x bin/hwstat
x share/licenses/hwstat-0.5.1/catalog.mk
x share/licenses/hwstat-0.5.1/LICENSE
x share/licenses/hwstat-0.5.1/BSD
x man/man1/hwstat.1.gz
tar command returns 0 status
Done.
extract: Package name is hwstat-0.5.1
extract: CWD to /usr/local
extract: /usr/local/bin/hwstat
extract: /usr/local/share/licenses/hwstat-0.5.1/catalog.mk
extract: /usr/local/share/licenses/hwstat-0.5.1/LICENSE
extract: /usr/local/share/licenses/hwstat-0.5.1/BSD
extract: /usr/local/man/man1/hwstat.1.gz
extract: CWD to /usr/local
Running mtree for hwstat-0.5.1..
mtree -U -f +MTREE_DIRS -d -e -p /usr/local >/dev/null
Attempting to record package into /var/db/pkg/hwstat-0.5.1..
Package hwstat-0.5.1 registered in /var/db/pkg/hwstat-0.5.1

执行以下命令以查看FreeBSD操作系统下的CPU温度和电池信息:

$ hwstat

acpiconf命令示例

要查看有关指定电池的信息,请执行:

$ acpiconf -i batt#
$ acpiconf -i 0 | grep capacity
$ acpiconf -i 0

输出示例:

Design capacity:	8850 mAh
Last full capacity:	6248 mAh
Technology:		secondary (rechargeable)
Design voltage:		11100 mV
Capacity (warn):	885 mAh
Capacity (low):		268 mAh
Low/warn granularity:	88 mAh
Warn/full granularity:	88 mAh
Model number:		DELL 1C75X35
Serial number:		1142
Type:			LION
OEM info:		Samsung SDI
State:			charging
Remaining capacity:	69%
Remaining time:		unknown
Present rate:		2846 mA (34738 mW)
Present voltage:	12206 mV

如何找出电池设计容量

您需要从上面的" acpiconf -i 0"命令中记下以下值:

Design capacity:	8850 mAh
Last full capacity:	6248 mAh

因此得出电池磨损的公式如下:

last_full_capacity=6248
total_capacity=8850
echo "scale = 2; ${last_full_capacity} / ${total_capacity} * 100" | bc -l

输出:

70.00

如何判断您的FreeBSD笔记本电脑电池是否已磨损

当"最后充满电"低于"设计容量"的80%时,电池可能会出现磨损迹象,需要更换。
例如:

#!/bin/sh
# Author: 
# Purpose: Quick and dirty way to find out laptop battery worn out or not 
# ------------------------------------------------------------------------------
echo "** Battery info for $HOSTNAME @ $(date)  ** "
acpiconf -i 0 | egrep "^(OEM|Model)" | awk -F':' '{sub(/^[ \t]+/, "",); printf "%s\n", }'
last_full_capacity=$(acpiconf -i 0 | grep "^Last full capacity:" | awk '{ print }')
total_capacity=$(acpiconf -i 0 | grep "^Design capacity:" | awk '{ print }')
echo "** Battery wear info ** "
wear=$(echo "scale = 2; ${last_full_capacity} / ${total_capacity} * 100" | bc -l)
echo "$wear"
# if $wear is < 80% warn the user #
if [ ${wear%%.*} -lt 80 ]
then
        # \a will send beep alert #
	echo -e "\aYou may need to replace the battery."
fi

您是否发现基于FreeBSD的笔记本电脑中的电池不能像以前那样持久?
这里如何判断它是否磨损。