projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
intel_rdt: collect data for monitored processes
[collectd.git]
/
src
/
barometer.c
diff --git
a/src/barometer.c
b/src/barometer.c
index
2db1ea4
..
468a237
100644
(file)
--- a/
src/barometer.c
+++ b/
src/barometer.c
@@
-21,12
+21,15
@@
#include "collectd.h"
#include "collectd.h"
-#include "common.h"
#include "plugin.h"
#include "plugin.h"
+#include "utils/common/common.h"
#include "utils_cache.h"
#include <fcntl.h>
#include <linux/i2c-dev.h>
#include "utils_cache.h"
#include <fcntl.h>
#include <linux/i2c-dev.h>
+#if HAVE_I2C_SMBUS_H
+#include <i2c/smbus.h>
+#endif
#include <math.h>
#include <stdint.h>
#include <sys/ioctl.h>
#include <math.h>
#include <stdint.h>
#include <sys/ioctl.h>
@@
-177,23
+180,23
@@
static const char *config_keys[] = {
static int config_keys_num = STATIC_ARRAY_SIZE(config_keys);
static int config_keys_num = STATIC_ARRAY_SIZE(config_keys);
-static char *config_device
= NULL;
/**< I2C bus device */
-static int config_oversample = 1;
/**< averaging window */
+static char *config_device
;
/**< I2C bus device */
+static int config_oversample = 1; /**< averaging window */
-static double config_press_offset
= 0.0
; /**< pressure offset */
-static double config_temp_offset
= 0.0
; /**< temperature offset */
+static double config_press_offset; /**< pressure offset */
+static double config_temp_offset; /**< temperature offset */
static double config_altitude = NAN; /**< altitude */
static double config_altitude = NAN; /**< altitude */
-static int config_normalize
= 0;
/**< normalization method */
+static int config_normalize
;
/**< normalization method */
-static
_Bool configured = 0
; /**< the whole plugin config status */
+static
bool configured
; /**< the whole plugin config status */
static int i2c_bus_fd = -1; /**< I2C bus device FD */
static enum Sensor_type sensor_type =
Sensor_none; /**< detected/used sensor type */
static int i2c_bus_fd = -1; /**< I2C bus device FD */
static enum Sensor_type sensor_type =
Sensor_none; /**< detected/used sensor type */
-static __s32 mpl3115_oversample
= 0
; /**< MPL3115 CTRL1 oversample setting */
+static __s32 mpl3115_oversample; /**< MPL3115 CTRL1 oversample setting */
// BMP085 configuration
static unsigned bmp085_oversampling; /**< BMP085 oversampling (0-3) */
// BMP085 configuration
static unsigned bmp085_oversampling; /**< BMP085 oversampling (0-3) */
@@
-226,7
+229,7
@@
static short bmp085_MD;
/* Used only for MPL115. MPL3115 supports real oversampling in the device so */
/* no need for any postprocessing. */
/* Used only for MPL115. MPL3115 supports real oversampling in the device so */
/* no need for any postprocessing. */
-static
_Bool avg_initialized = 0
; /**< already initialized by real values */
+static
bool avg_initialized
; /**< already initialized by real values */
typedef struct averaging_s {
long int *ring_buffer;
typedef struct averaging_s {
long int *ring_buffer;
@@
-235,8
+238,8
@@
typedef struct averaging_s {
int ring_buffer_head;
} averaging_t;
int ring_buffer_head;
} averaging_t;
-static averaging_t pressure_averaging
= {NULL, 0, 0L, 0}
;
-static averaging_t temperature_averaging
= {NULL, 0, 0L, 0}
;
+static averaging_t pressure_averaging;
+static averaging_t temperature_averaging;
/**
* Create / allocate averaging buffer
/**
* Create / allocate averaging buffer
@@
-249,7
+252,7
@@
static averaging_t temperature_averaging = {NULL, 0, 0L, 0};
* @return Zero when successful
*/
static int averaging_create(averaging_t *avg, int size) {
* @return Zero when successful
*/
static int averaging_create(averaging_t *avg, int size) {
- avg->ring_buffer = calloc(
(size_t)
size, sizeof(*avg->ring_buffer));
+ avg->ring_buffer = calloc(size, sizeof(*avg->ring_buffer));
if (avg->ring_buffer == NULL) {
ERROR("barometer: averaging_create - ring buffer allocation of size %d "
"failed",
if (avg->ring_buffer == NULL) {
ERROR("barometer: averaging_create - ring buffer allocation of size %d "
"failed",
@@
-313,11
+316,11
@@
static double averaging_add_sample(averaging_t *avg, long int sample) {
typedef struct temperature_list_s {
char *sensor_name; /**< sensor name/reference */
size_t num_values; /**< number of values (usually one) */
typedef struct temperature_list_s {
char *sensor_name; /**< sensor name/reference */
size_t num_values; /**< number of values (usually one) */
-
_Bool initialized;
/**< sensor already provides data */
+
bool initialized;
/**< sensor already provides data */
struct temperature_list_s *next; /**< next in the list */
} temperature_list_t;
struct temperature_list_s *next; /**< next in the list */
} temperature_list_t;
-static temperature_list_t *temp_list
= NULL
;
+static temperature_list_t *temp_list;
/*
* Add new sensor to the temperature reference list
/*
* Add new sensor to the temperature reference list
@@
-412,16
+415,16
@@
static int get_reference_temperature(double *result) {
continue;
}
continue;
}
- DEBUG(
-
"barometer: get_reference_temperature - initialize \"%s\", %zu
vals",
- list->sensor_name, values_num);
+ DEBUG(
"barometer: get_reference_temperature - initialize \"%s\", %" PRIsz
+
"
vals",
+
list->sensor_name, values_num);
list->initialized = 1;
list->num_values = values_num;
for (size_t i = 0; i < values_num; ++i) {
list->initialized = 1;
list->num_values = values_num;
for (size_t i = 0; i < values_num; ++i) {
- DEBUG("barometer: get_reference_temperature - rate %
zu: %lf **", i
,
- values[i]);
+ DEBUG("barometer: get_reference_temperature - rate %
" PRIsz ": %lf **"
,
+
i,
values[i]);
if (!isnan(values[i])) {
avg_sum += values[i];
++avg_num;
if (!isnan(values[i])) {
avg_sum += values[i];
++avg_num;
@@
-444,7
+447,7
@@
static int get_reference_temperature(double *result) {
}
for (size_t i = 0; i < REF_TEMP_AVG_NUM * list->num_values; ++i) {
}
for (size_t i = 0; i < REF_TEMP_AVG_NUM * list->num_values; ++i) {
- DEBUG("barometer: get_reference_temperature - history %
zu
: %lf", i,
+ DEBUG("barometer: get_reference_temperature - history %
" PRIsz "
: %lf", i,
values_history[i]);
if (!isnan(values_history[i])) {
avg_sum += values_history[i];
values_history[i]);
if (!isnan(values_history[i])) {
avg_sum += values_history[i];
@@
-464,8
+467,9
@@
static int get_reference_temperature(double *result) {
}
for (size_t i = 0; i < values_num; ++i) {
}
for (size_t i = 0; i < values_num; ++i) {
- DEBUG("barometer: get_reference_temperature - rate last %zu: %lf **", i,
- values[i]);
+ DEBUG("barometer: get_reference_temperature - rate last %" PRIsz
+ ": %lf **",
+ i, values[i]);
if (!isnan(values[i])) {
avg_sum += values[i];
++avg_num;
if (!isnan(values[i])) {
avg_sum += values[i];
++avg_num;
@@
-1391,7
+1395,7
@@
static int MPL115_collectd_barometer_read(void) {
config_oversample - 1);
usleep(20000);
}
config_oversample - 1);
usleep(20000);
}
- avg_initialized =
1
;
+ avg_initialized =
true
;
}
result = MPL115_read_averaged(&pressure, &temperature);
}
result = MPL115_read_averaged(&pressure, &temperature);
@@
-1634,7
+1638,7
@@
static int collectd_barometer_init(void) {
return -1;
}
return -1;
}
- configured =
1
;
+ configured =
true
;
return 0;
}
return 0;
}