projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
virt plugin: Added support for new shutdown event details
[collectd.git]
/
src
/
barometer.c
diff --git
a/src/barometer.c
b/src/barometer.c
index
0fa62fb
..
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
@@
-515,12
+518,11
@@
static int get_reference_temperature(double *result) {
*/
static int MPL115_detect(void) {
__s32 res;
*/
static int MPL115_detect(void) {
__s32 res;
- char errbuf[1024];
if (ioctl(i2c_bus_fd, I2C_SLAVE_FORCE, MPL115_I2C_ADDRESS) < 0) {
ERROR("barometer: MPL115_detect problem setting i2c slave address to "
"0x%02X: %s",
if (ioctl(i2c_bus_fd, I2C_SLAVE_FORCE, MPL115_I2C_ADDRESS) < 0) {
ERROR("barometer: MPL115_detect problem setting i2c slave address to "
"0x%02X: %s",
- MPL115_I2C_ADDRESS,
sstrerror(errno, errbuf, sizeof(errbuf))
);
+ MPL115_I2C_ADDRESS,
STRERRNO
);
return 0;
}
return 0;
}
@@
-549,14
+551,11
@@
static int MPL115_read_coeffs(void) {
int8_t sic12MSB, sic12LSB, sic11MSB, sic11LSB, sic22MSB, sic22LSB;
int16_t sia0, sib1, sib2, sic12, sic11, sic22;
int8_t sic12MSB, sic12LSB, sic11MSB, sic11LSB, sic22MSB, sic22LSB;
int16_t sia0, sib1, sib2, sic12, sic11, sic22;
- char errbuf[1024];
-
res = i2c_smbus_read_i2c_block_data(i2c_bus_fd, MPL115_ADDR_COEFFS,
STATIC_ARRAY_SIZE(mpl115_coeffs),
mpl115_coeffs);
if (res < 0) {
res = i2c_smbus_read_i2c_block_data(i2c_bus_fd, MPL115_ADDR_COEFFS,
STATIC_ARRAY_SIZE(mpl115_coeffs),
mpl115_coeffs);
if (res < 0) {
- ERROR("barometer: MPL115_read_coeffs - problem reading data: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("barometer: MPL115_read_coeffs - problem reading data: %s", STRERRNO);
return -1;
}
return -1;
}
@@
-658,7
+657,6
@@
static int MPL115_read_averaged(double *pressure, double *temperature) {
int conv_temperature;
double adc_pressure;
double adc_temperature;
int conv_temperature;
double adc_pressure;
double adc_temperature;
- char errbuf[1024];
*pressure = 0.0;
*temperature = 0.0;
*pressure = 0.0;
*temperature = 0.0;
@@
-675,11
+673,11
@@
static int MPL115_read_averaged(double *pressure, double *temperature) {
if (retries > 0) {
ERROR("barometer: MPL115_read_averaged - requesting conversion: %s, "
"will retry at most %d more times",
if (retries > 0) {
ERROR("barometer: MPL115_read_averaged - requesting conversion: %s, "
"will retry at most %d more times",
-
sstrerror(errno, errbuf, sizeof(errbuf))
, retries);
+
STRERRNO
, retries);
} else {
ERROR("barometer: MPL115_read_averaged - requesting conversion: %s, "
"too many failed retries",
} else {
ERROR("barometer: MPL115_read_averaged - requesting conversion: %s, "
"too many failed retries",
-
sstrerror(errno, errbuf, sizeof(errbuf))
);
+
STRERRNO
);
return -1;
}
}
return -1;
}
}
@@
-698,11
+696,11
@@
static int MPL115_read_averaged(double *pressure, double *temperature) {
if (retries > 0) {
ERROR("barometer: MPL115_read_averaged - reading conversion: %s, "
"will retry at most %d more times",
if (retries > 0) {
ERROR("barometer: MPL115_read_averaged - reading conversion: %s, "
"will retry at most %d more times",
-
sstrerror(errno, errbuf, sizeof(errbuf))
, retries);
+
STRERRNO
, retries);
} else {
ERROR("barometer: MPL115_read_averaged - reading conversion: %s, "
"too many failed retries",
} else {
ERROR("barometer: MPL115_read_averaged - reading conversion: %s, "
"too many failed retries",
-
sstrerror(errno, errbuf, sizeof(errbuf))
);
+
STRERRNO
);
return -1;
}
}
return -1;
}
}
@@
-739,12
+737,11
@@
static int MPL115_read_averaged(double *pressure, double *temperature) {
*/
static int MPL3115_detect(void) {
__s32 res;
*/
static int MPL3115_detect(void) {
__s32 res;
- char errbuf[1024];
if (ioctl(i2c_bus_fd, I2C_SLAVE_FORCE, MPL3115_I2C_ADDRESS) < 0) {
ERROR("barometer: MPL3115_detect problem setting i2c slave address to "
"0x%02X: %s",
if (ioctl(i2c_bus_fd, I2C_SLAVE_FORCE, MPL3115_I2C_ADDRESS) < 0) {
ERROR("barometer: MPL3115_detect problem setting i2c slave address to "
"0x%02X: %s",
- MPL3115_I2C_ADDRESS,
sstrerror(errno, errbuf, sizeof(errbuf))
);
+ MPL3115_I2C_ADDRESS,
STRERRNO
);
return 0;
}
return 0;
}
@@
-811,21
+808,18
@@
static int MPL3115_read(double *pressure, double *temperature) {
__s32 ctrl;
__u8 data[MPL3115_NUM_CONV_VALS];
long int tmp_value = 0;
__s32 ctrl;
__u8 data[MPL3115_NUM_CONV_VALS];
long int tmp_value = 0;
- char errbuf[1024];
/* Set Active - activate the device from standby */
res = i2c_smbus_read_byte_data(i2c_bus_fd, MPL3115_REG_CTRL_REG1);
if (res < 0) {
/* Set Active - activate the device from standby */
res = i2c_smbus_read_byte_data(i2c_bus_fd, MPL3115_REG_CTRL_REG1);
if (res < 0) {
- ERROR("barometer: MPL3115_read - cannot read CTRL_REG1: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("barometer: MPL3115_read - cannot read CTRL_REG1: %s", STRERRNO);
return 1;
}
ctrl = res;
res = i2c_smbus_write_byte_data(i2c_bus_fd, MPL3115_REG_CTRL_REG1,
ctrl | MPL3115_CTRL_REG1_SBYB);
if (res < 0) {
return 1;
}
ctrl = res;
res = i2c_smbus_write_byte_data(i2c_bus_fd, MPL3115_REG_CTRL_REG1,
ctrl | MPL3115_CTRL_REG1_SBYB);
if (res < 0) {
- ERROR("barometer: MPL3115_read - problem activating: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("barometer: MPL3115_read - problem activating: %s", STRERRNO);
return 1;
}
return 1;
}
@@
-836,7
+830,7
@@
static int MPL3115_read(double *pressure, double *temperature) {
res = i2c_smbus_read_byte_data(i2c_bus_fd, MPL3115_REG_STATUS);
if (res < 0) {
ERROR("barometer: MPL3115_read - cannot read status register: %s",
res = i2c_smbus_read_byte_data(i2c_bus_fd, MPL3115_REG_STATUS);
if (res < 0) {
ERROR("barometer: MPL3115_read - cannot read status register: %s",
-
sstrerror(errno, errbuf, sizeof(errbuf))
);
+
STRERRNO
);
return 1;
}
return 1;
}
@@
-849,7
+843,7
@@
static int MPL3115_read(double *pressure, double *temperature) {
res = i2c_smbus_read_byte_data(i2c_bus_fd, MPL3115_REG_STATUS);
if (res < 0) {
ERROR("barometer: MPL3115_read - cannot read status register: %s",
res = i2c_smbus_read_byte_data(i2c_bus_fd, MPL3115_REG_STATUS);
if (res < 0) {
ERROR("barometer: MPL3115_read - cannot read status register: %s",
-
sstrerror(errno, errbuf, sizeof(errbuf))
);
+
STRERRNO
);
return 1;
}
}
return 1;
}
}
@@
-858,8
+852,7
@@
static int MPL3115_read(double *pressure, double *temperature) {
res = i2c_smbus_read_i2c_block_data(i2c_bus_fd, MPL3115_REG_OUT_P_MSB,
MPL3115_NUM_CONV_VALS, data);
if (res < 0) {
res = i2c_smbus_read_i2c_block_data(i2c_bus_fd, MPL3115_REG_OUT_P_MSB,
MPL3115_NUM_CONV_VALS, data);
if (res < 0) {
- ERROR("barometer: MPL3115_read - cannot read data registers: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("barometer: MPL3115_read - cannot read data registers: %s", STRERRNO);
return 1;
}
return 1;
}
@@
-889,7
+882,6
@@
static int MPL3115_read(double *pressure, double *temperature) {
static int MPL3115_init_sensor(void) {
__s32 res;
__s8 offset;
static int MPL3115_init_sensor(void) {
__s32 res;
__s8 offset;
- char errbuf[1024];
/* Reset the sensor. It will reset immediately without ACKing */
/* the transaction, so no error handling here. */
/* Reset the sensor. It will reset immediately without ACKing */
/* the transaction, so no error handling here. */
@@
-907,7
+899,7
@@
static int MPL3115_init_sensor(void) {
res = i2c_smbus_write_byte_data(i2c_bus_fd, MPL3115_REG_OFF_T, offset);
if (res < 0) {
ERROR("barometer: MPL3115_init_sensor - problem setting temp offset: %s",
res = i2c_smbus_write_byte_data(i2c_bus_fd, MPL3115_REG_OFF_T, offset);
if (res < 0) {
ERROR("barometer: MPL3115_init_sensor - problem setting temp offset: %s",
-
sstrerror(errno, errbuf, sizeof(errbuf))
);
+
STRERRNO
);
return -1;
}
return -1;
}
@@
-918,7
+910,7
@@
static int MPL3115_init_sensor(void) {
if (res < 0) {
ERROR(
"barometer: MPL3115_init_sensor - problem setting pressure offset: %s",
if (res < 0) {
ERROR(
"barometer: MPL3115_init_sensor - problem setting pressure offset: %s",
-
sstrerror(errno, errbuf, sizeof(errbuf))
);
+
STRERRNO
);
return -1;
}
return -1;
}
@@
-928,7
+920,7
@@
static int MPL3115_init_sensor(void) {
MPL3115_PT_DATA_TDEF);
if (res < 0) {
ERROR("barometer: MPL3115_init_sensor - problem setting PT_DATA_CFG: %s",
MPL3115_PT_DATA_TDEF);
if (res < 0) {
ERROR("barometer: MPL3115_init_sensor - problem setting PT_DATA_CFG: %s",
-
sstrerror(errno, errbuf, sizeof(errbuf))
);
+
STRERRNO
);
return -1;
}
return -1;
}
@@
-937,7
+929,7
@@
static int MPL3115_init_sensor(void) {
mpl3115_oversample);
if (res < 0) {
ERROR("barometer: MPL3115_init_sensor - problem configuring CTRL_REG1: %s",
mpl3115_oversample);
if (res < 0) {
ERROR("barometer: MPL3115_init_sensor - problem configuring CTRL_REG1: %s",
-
sstrerror(errno, errbuf, sizeof(errbuf))
);
+
STRERRNO
);
return -1;
}
return -1;
}
@@
-955,12
+947,11
@@
static int MPL3115_init_sensor(void) {
*/
static int BMP085_detect(void) {
__s32 res;
*/
static int BMP085_detect(void) {
__s32 res;
- char errbuf[1024];
if (ioctl(i2c_bus_fd, I2C_SLAVE_FORCE, BMP085_I2C_ADDRESS) < 0) {
ERROR("barometer: BMP085_detect - problem setting i2c slave address to "
"0x%02X: %s",
if (ioctl(i2c_bus_fd, I2C_SLAVE_FORCE, BMP085_I2C_ADDRESS) < 0) {
ERROR("barometer: BMP085_detect - problem setting i2c slave address to "
"0x%02X: %s",
- BMP085_I2C_ADDRESS,
sstrerror(errno, errbuf, sizeof(errbuf))
);
+ BMP085_I2C_ADDRESS,
STRERRNO
);
return 0;
}
return 0;
}
@@
-972,7
+963,7
@@
static int BMP085_detect(void) {
res = i2c_smbus_read_byte_data(i2c_bus_fd, BMP085_ADDR_VERSION);
if (res < 0) {
ERROR("barometer: BMP085_detect - problem checking chip version: %s",
res = i2c_smbus_read_byte_data(i2c_bus_fd, BMP085_ADDR_VERSION);
if (res < 0) {
ERROR("barometer: BMP085_detect - problem checking chip version: %s",
-
sstrerror(errno, errbuf, sizeof(errbuf))
);
+
STRERRNO
);
return 0;
}
DEBUG("barometer: BMP085_detect - chip version ML:0x%02X AL:0x%02X",
return 0;
}
DEBUG("barometer: BMP085_detect - chip version ML:0x%02X AL:0x%02X",
@@
-1034,13
+1025,11
@@
static void BMP085_adjust_oversampling(void) {
static int BMP085_read_coeffs(void) {
__s32 res;
__u8 coeffs[BMP085_NUM_COEFFS];
static int BMP085_read_coeffs(void) {
__s32 res;
__u8 coeffs[BMP085_NUM_COEFFS];
- char errbuf[1024];
res = i2c_smbus_read_i2c_block_data(i2c_bus_fd, BMP085_ADDR_COEFFS,
BMP085_NUM_COEFFS, coeffs);
if (res < 0) {
res = i2c_smbus_read_i2c_block_data(i2c_bus_fd, BMP085_ADDR_COEFFS,
BMP085_NUM_COEFFS, coeffs);
if (res < 0) {
- ERROR("barometer: BMP085_read_coeffs - problem reading data: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("barometer: BMP085_read_coeffs - problem reading data: %s", STRERRNO);
return -1;
}
return -1;
}
@@
-1141,15
+1130,13
@@
static int BMP085_read(double *pressure, double *temperature) {
long adc_pressure;
long adc_temperature;
long adc_pressure;
long adc_temperature;
- char errbuf[1024];
-
/* start conversion of temperature */
res = i2c_smbus_write_byte_data(i2c_bus_fd, BMP085_ADDR_CTRL_REG,
BMP085_CMD_CONVERT_TEMP);
if (res < 0) {
ERROR("barometer: BMP085_read - problem requesting temperature conversion: "
"%s",
/* start conversion of temperature */
res = i2c_smbus_write_byte_data(i2c_bus_fd, BMP085_ADDR_CTRL_REG,
BMP085_CMD_CONVERT_TEMP);
if (res < 0) {
ERROR("barometer: BMP085_read - problem requesting temperature conversion: "
"%s",
-
sstrerror(errno, errbuf, sizeof(errbuf))
);
+
STRERRNO
);
return 1;
}
return 1;
}
@@
-1159,7
+1146,7
@@
static int BMP085_read(double *pressure, double *temperature) {
i2c_smbus_read_i2c_block_data(i2c_bus_fd, BMP085_ADDR_CONV, 2, measBuff);
if (res < 0) {
ERROR("barometer: BMP085_read - problem reading temperature data: %s",
i2c_smbus_read_i2c_block_data(i2c_bus_fd, BMP085_ADDR_CONV, 2, measBuff);
if (res < 0) {
ERROR("barometer: BMP085_read - problem reading temperature data: %s",
-
sstrerror(errno, errbuf, sizeof(errbuf))
);
+
STRERRNO
);
return 1;
}
return 1;
}
@@
-1170,7
+1157,7
@@
static int BMP085_read(double *pressure, double *temperature) {
bmp085_cmdCnvPress);
if (res < 0) {
ERROR("barometer: BMP085_read - problem requesting pressure conversion: %s",
bmp085_cmdCnvPress);
if (res < 0) {
ERROR("barometer: BMP085_read - problem requesting pressure conversion: %s",
-
sstrerror(errno, errbuf, sizeof(errbuf))
);
+
STRERRNO
);
return 1;
}
return 1;
}
@@
-1180,7
+1167,7
@@
static int BMP085_read(double *pressure, double *temperature) {
i2c_smbus_read_i2c_block_data(i2c_bus_fd, BMP085_ADDR_CONV, 3, measBuff);
if (res < 0) {
ERROR("barometer: BMP085_read - problem reading pressure data: %s",
i2c_smbus_read_i2c_block_data(i2c_bus_fd, BMP085_ADDR_CONV, 3, measBuff);
if (res < 0) {
ERROR("barometer: BMP085_read - problem reading pressure data: %s",
-
sstrerror(errno, errbuf, sizeof(errbuf))
);
+
STRERRNO
);
return 1;
}
return 1;
}
@@
-1408,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);
@@
-1572,7
+1559,6
@@
static int BMP085_collectd_barometer_read(void) {
* @return Zero when successful.
*/
static int collectd_barometer_init(void) {
* @return Zero when successful.
*/
static int collectd_barometer_init(void) {
- char errbuf[1024];
DEBUG("barometer: collectd_barometer_init");
DEBUG("barometer: collectd_barometer_init");
@@
-1597,7
+1583,7
@@
static int collectd_barometer_init(void) {
if (i2c_bus_fd < 0) {
ERROR("barometer: collectd_barometer_init problem opening I2C bus device "
"\"%s\": %s (is loaded mod i2c-dev?)",
if (i2c_bus_fd < 0) {
ERROR("barometer: collectd_barometer_init problem opening I2C bus device "
"\"%s\": %s (is loaded mod i2c-dev?)",
- config_device,
sstrerror(errno, errbuf, sizeof(errbuf))
);
+ config_device,
STRERRNO
);
return -1;
}
return -1;
}
@@
-1652,7
+1638,7
@@
static int collectd_barometer_init(void) {
return -1;
}
return -1;
}
- configured =
1
;
+ configured =
true
;
return 0;
}
return 0;
}