Subject: measuring each battery's charge
To: None <netbsd-users@netbsd.org>
From: Steve Bellovin <smb@research.att.com>
List: netbsd-users
Date: 06/16/2003 01:29:37
Here's a hack to apm.c to let you specify which battery's charge you 
want to ask about.  -n specifies the battery number; 0 (the default) 
means "all batteries".  This only works with -d, since I haven't (yet?) 
added similar code to apmd.

b131$ diff -c apm.c.orig apm.c
*** apm.c.orig  Sun Jun 15 12:33:12 2003
--- apm.c       Sun Jun 15 12:38:44 2003
***************
*** 77,83 ****
  zzusage(void)
  {
  
!       fprintf(stderr,"usage: %s [-z | -S] [-f socket]\n",
            getprogname());
        exit(1);
  }
--- 77,83 ----
  zzusage(void)
  {
  
!       fprintf(stderr,"usage: %s [-n batt] [-z | -S] [-f socket]\n",
            getprogname());
        exit(1);
  }
***************
*** 161,171 ****
        enum apm_action action = NONE;
        int ch, doac, dobstate, domin, dopct, dostatus, fd, nodaemon,
            rval, verbose;
  
        doac = dobstate = domin = dopct = dostatus = nodaemon =
            verbose = FALSE;
!       while ((ch = getopt(argc, argv, "lmbvadsSzf:d")) != -1)
                switch (ch) {
                case 'v':
                        verbose = TRUE;
                        break;
--- 161,175 ----
        enum apm_action action = NONE;
        int ch, doac, dobstate, domin, dopct, dostatus, fd, nodaemon,
            rval, verbose;
+       int batteryid = 0;
  
        doac = dobstate = domin = dopct = dostatus = nodaemon =
            verbose = FALSE;
!       while ((ch = getopt(argc, argv, "lmbvadsSzf:dn:")) != -1)
                switch (ch) {
+               case 'n':
+                       batteryid = atoi(optarg);
+                       break;
                case 'v':
                        verbose = TRUE;
                        break;
***************
*** 243,248 ****
--- 247,253 ----
                                    _PATH_APM_NORMAL);
                        }
                        memset(&reply, 0, sizeof(reply));
+                       api->batteryid = batteryid;
                        if (ioctl(fd, APM_IOC_GETPOWER,
                            &reply.batterystate) == -1)
                                err(1, "ioctl(APM_IOC_GETPOWER)");


		--Steve Bellovin, http://www.research.att.com/~smb (me)
		http://www.wilyhacker.com (2nd edition of "Firewalls" book)