示例#1
0
文件: battery.c 项目: Civil/collectd
static int battery_read (void) /* {{{ */
{
	double charge  = INVALID_VALUE; /* Current charge in Ah */
	double current = INVALID_VALUE; /* Current in A */
	double voltage = INVALID_VALUE; /* Voltage in V */

	double charge_rel = INVALID_VALUE; /* Current charge in percent */
	double charge_abs = INVALID_VALUE; /* Total capacity */

#if HAVE_IOKIT_PS_IOPOWERSOURCES_H
	get_via_io_power_sources (&charge_rel, &current, &voltage);
#endif
#if HAVE_IOKIT_IOKITLIB_H
	get_via_generic_iokit (&charge_abs, &current, &voltage);
#endif

	if ((charge_rel != INVALID_VALUE) && (charge_abs != INVALID_VALUE))
		charge = charge_abs * charge_rel / 100.0;

	if (charge != INVALID_VALUE)
		battery_submit ("0", "charge", charge);
	if (current != INVALID_VALUE)
		battery_submit ("0", "current", current);
	if (voltage != INVALID_VALUE)
		battery_submit ("0", "voltage", voltage);
} /* }}} int battery_read */
示例#2
0
文件: battery.c 项目: ajdiaz/collectd
static int battery_read(void) /* {{{ */
{
  gauge_t current = NAN; /* Current in A */
  gauge_t voltage = NAN; /* Voltage in V */

  /* We only get the charged capacity as a percentage from
   * IOPowerSources. IOKit, on the other hand, only reports the full
   * capacity. We use the two to calculate the current charged capacity. */
  gauge_t charge_rel = NAN;      /* Current charge in percent */
  gauge_t capacity_charged;      /* Charged capacity */
  gauge_t capacity_full = NAN;   /* Total capacity */
  gauge_t capacity_design = NAN; /* Full design capacity */

  if (query_statefs)
    return battery_read_statefs();

#if HAVE_IOKIT_PS_IOPOWERSOURCES_H
  get_via_io_power_sources(&charge_rel, &current, &voltage);
#endif
#if HAVE_IOKIT_IOKITLIB_H
  get_via_generic_iokit(&capacity_full, &capacity_design, &current, &voltage);
#endif

  capacity_charged = charge_rel * capacity_full / 100.0;
  submit_capacity("0", capacity_charged, capacity_full, capacity_design);

  if (!isnan(current))
    battery_submit("0", "current", current);
  if (!isnan(voltage))
    battery_submit("0", "voltage", voltage);

  return (0);
} /* }}} int battery_read */