RocketLogger 2.1.0
sensor.h File Reference
#include <stdbool.h>
#include <stdint.h>
#include "../rl_file.h"
+ Include dependency graph for sensor.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  rl_sensor
 

Macros

#define MAX_MESSAGE_LENGTH   1000
 
#define I2C_BUS_FILENAME   "/dev/i2c-2"
 
#define SENSOR_REGISTRY_SIZE   5
 Number of sensor registered. More...
 
#define SENSOR_NAME_LENGTH   (RL_FILE_CHANNEL_NAME_LENGTH)
 

Typedefs

typedef struct rl_sensor rl_sensor_t
 

Functions

int sensors_init (void)
 
void sensors_deinit (void)
 
int sensors_open_bus (void)
 
int sensors_close_bus (int bus)
 
int sensors_get_bus (void)
 
int sensors_init_comm (uint8_t device_address)
 
int sensors_scan (bool sensor_available[SENSOR_REGISTRY_SIZE])
 
int sensors_read (int32_t *const sensor_data, bool const sensor_available[SENSOR_REGISTRY_SIZE])
 
void sensors_close (bool const sensor_available[SENSOR_REGISTRY_SIZE])
 

Variables

const rl_sensor_t SENSOR_REGISTRY [SENSOR_REGISTRY_SIZE]
 

Macro Definition Documentation

◆ I2C_BUS_FILENAME

#define I2C_BUS_FILENAME   "/dev/i2c-2"

Definition at line 43 of file sensor.h.

◆ MAX_MESSAGE_LENGTH

#define MAX_MESSAGE_LENGTH   1000

Copyright (c) 2016-2020, ETH Zurich, Computer Engineering Group All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition at line 40 of file sensor.h.

◆ SENSOR_NAME_LENGTH

#define SENSOR_NAME_LENGTH   (RL_FILE_CHANNEL_NAME_LENGTH)

Definition at line 49 of file sensor.h.

◆ SENSOR_REGISTRY_SIZE

#define SENSOR_REGISTRY_SIZE   5

Number of sensor registered.

Definition at line 47 of file sensor.h.

Typedef Documentation

◆ rl_sensor_t

typedef struct rl_sensor rl_sensor_t

Typedef for standardized RocketLogger sensor interface definition

Definition at line 69 of file sensor.h.

Function Documentation

◆ sensors_close()

void sensors_close ( bool const  sensor_available[SENSOR_REGISTRY_SIZE])

Close all sensors used on the I2C bus.

Parameters
sensor_availableList of available (previously initialized) sensors

Definition at line 222 of file sensor.c.

References rl_sensor::deinit, SENSOR_REGISTRY, and SENSOR_REGISTRY_SIZE.

Referenced by hw_deinit().

◆ sensors_close_bus()

int sensors_close_bus ( int  bus)

Close a I2C sensor bus.

Parameters
busThe I2C bus to close
Returns
Returns 0 on success, negative on failure with errno set accordingly

Definition at line 141 of file sensor.c.

References rl_log(), and RL_LOG_ERROR.

Referenced by sensors_deinit().

+ Here is the call graph for this function:

◆ sensors_deinit()

void sensors_deinit ( void  )

Deinitialize the shared I2C sensor bus.

Definition at line 126 of file sensor.c.

References sensor_bus, and sensors_close_bus().

Referenced by hw_deinit().

+ Here is the call graph for this function:

◆ sensors_get_bus()

int sensors_get_bus ( void  )

Get the shared I2C bus handle.

Returns
The I2C bus handle, or negative value if bus unavailable

Definition at line 150 of file sensor.c.

References sensor_bus.

Referenced by bme280_get_id(), bme280_init(), bme280_read(), bme280_read_calibration(), bme280_set_parameters(), tsl4531_get_id(), tsl4531_init(), tsl4531_read(), tsl4531_send_range(), and tsl4531_set_parameters().

◆ sensors_init()

int sensors_init ( void  )

Initialize the shared I2C sensor bus.

Returns
Returns 0 on success, negative on failure with errno set accordingly

Definition at line 121 of file sensor.c.

References sensor_bus, and sensors_open_bus().

Referenced by hw_init().

+ Here is the call graph for this function:

◆ sensors_init_comm()

int sensors_init_comm ( uint8_t  device_address)

Initiate an I2C communication with a device.

Parameters
device_addressThe I2C address of the device
Returns
Returns 0 on success, negative on failure with errno set accordingly

Definition at line 152 of file sensor.c.

References sensor_bus.

Referenced by bme280_init(), bme280_read(), tsl4531_init(), and tsl4531_read().

◆ sensors_open_bus()

int sensors_open_bus ( void  )

Open a new handle of the I2C bus.

Returns
Returns 0 on success, negative on failure with errno set accordingly

Definition at line 132 of file sensor.c.

References I2C_BUS_FILENAME, rl_log(), and RL_LOG_ERROR.

Referenced by sensors_init().

+ Here is the call graph for this function:

◆ sensors_read()

int sensors_read ( int32_t *const  sensor_data,
bool const  sensor_available[SENSOR_REGISTRY_SIZE] 
)

Read available sensors on the I2C bus.

Parameters
sensor_dataData array to store the sensor values to
sensor_availableList of available (previously initialized) sensors
Returns
Number of sensors read on success, negative on failure with errno set accordingly

Definition at line 198 of file sensor.c.

References rl_sensor::get_value, rl_sensor::identifier, rl_sensor::read, SENSOR_REGISTRY, and SENSOR_REGISTRY_SIZE.

Referenced by pru_sample().

◆ sensors_scan()

int sensors_scan ( bool  sensor_available[SENSOR_REGISTRY_SIZE])

Scan the I2C sensor for sensor in the registry and initialize them.

Parameters
sensor_availableList of sensors of the registry available
Returns
Number of sensors from the registry found on the bus

Definition at line 156 of file sensor.c.

References rl_sensor::identifier, rl_sensor::init, MAX_MESSAGE_LENGTH, rl_log(), RL_LOG_INFO, RL_LOG_WARNING, SENSOR_REGISTRY, SENSOR_REGISTRY_SIZE, and SUCCESS.

Referenced by hw_init().

+ Here is the call graph for this function:

Variable Documentation

◆ SENSOR_REGISTRY

const rl_sensor_t SENSOR_REGISTRY[SENSOR_REGISTRY_SIZE]
extern

The sensor registry structure.

Register your sensor (channels) here. Multiple channels from the same sensor should be added as consecutive entries.

The sensor registry structure.

Register your sensor (channels) here. Multiple channels from the same sensor should be added as consecutive entries.

Note
The SENSOR_REGISTRY_SIZE needs to be adjusted accordingly.

Definition at line 63 of file sensor.c.

Referenced by rl_file_setup_ambient_channels(), rl_socket_metadata(), rl_status_get_json(), rl_status_print(), sensors_close(), sensors_read(), and sensors_scan().