SELKIELogger  1.0.0
Collaboration diagram for Logger: I2C Support:

Classes

struct  i2c_msg_map
 Map device functions to message IDs. More...
 
struct  i2c_params
 I2C Source device specific parameters. More...
 

Functions

void * i2c_setup (void *ptargs)
 I2C Connection setup. More...
 
void * i2c_logging (void *ptargs)
 I2C main logging loop. More...
 
void * i2c_shutdown (void *ptargs)
 I2C shutdown. More...
 
void * i2c_channels (void *ptargs)
 Generate I2C channel map. More...
 
device_callbacks i2c_getCallbacks (void)
 Fill out device callback functions for logging. More...
 
i2c_params i2c_getParams (void)
 Fill out default I2C parameters. More...
 
bool i2c_validate_chanmap (i2c_params *ip)
 Check channel mapping is valid. More...
 
bool i2c_chanmap_add_ina219 (i2c_params *ip, const uint8_t devAddr, const uint8_t baseID)
 Add INA219 voltage and current readings to channel map. More...
 
bool i2c_chanmap_add_ads1015 (i2c_params *ip, const uint8_t devAddr, const uint8_t baseID, const float scale, const float offset, const float minV, const float maxV)
 Add ADS1015 single ended voltage measurements to channel map. More...
 
bool i2c_parseConfig (log_thread_args_t *lta, config_section *s)
 Take a configuration section, parse parameters and register devices. More...
 

Detailed Description

Adds support for reading messages from an I2C bus directly connected to the logging machine.

General support functions are detailed in SELKIELoggerI2C.h. As the I2C bus must be polled rather than streaming data to the logger, each sensor and value that needs to be logged must be registered into the channel map in i2c_params before i2c_logging is called.

Function Documentation

◆ i2c_chanmap_add_ads1015()

bool i2c_chanmap_add_ads1015 ( i2c_params ip,
const uint8_t  devAddr,
const uint8_t  baseID,
const float  scale,
const float  offset,
const float  minV,
const float  maxV 
)

Add ADS1015 single ended voltage measurements to channel map.

Adds four entries to the channel map for a specified ADS1015 device, representing the four single ended measurement channels

  • baseID: A0 [V]
  • baseID+1: A1 [V]
  • baseID+2: A2 [V]
  • baseID+3: A3 [V]
Parameters
[in]ipi2c_params structure to modify
[in]devAddrADS1015 Device Address
[in]baseIDMessage ID for first channel (A0)
[in]scaleMultiply received values by this quantity
[in]offsetAdd this amount to received values
[in]minVMinimum valid value
[in]maxVMaximum valid value
Returns
True on success, false otherwise

Definition at line 333 of file LoggerI2C.c.

◆ i2c_chanmap_add_ina219()

bool i2c_chanmap_add_ina219 ( i2c_params ip,
const uint8_t  devAddr,
const uint8_t  baseID 
)

Add INA219 voltage and current readings to channel map.

Adds three entries to the channel map for a specified INA219 device

  • baseID: Shunt Voltage [mV]
  • baseID+1: Bus Voltage [V]
  • baseID+2: Bus Current [A]
Parameters
[in]ipi2c_params structure to modify
[in]devAddrINA219 Device Address
[in]baseIDMessage ID for first message type (Shunt Voltage)
Returns
True on success, false otherwise

Definition at line 275 of file LoggerI2C.c.

◆ i2c_channels()

void* i2c_channels ( void *  ptargs)

Generate I2C channel map.

Populate list of channels and push to queue as a map message

Terminates thread on error

Parameters
[in]ptargsPointer to log_thread_args_t
Returns
NULL - Error code set in ptargs->returnCode if required

Definition at line 163 of file LoggerI2C.c.

◆ i2c_getCallbacks()

device_callbacks i2c_getCallbacks ( void  )

Fill out device callback functions for logging.

Returns
device_callbacks for I2C devices

Definition at line 212 of file LoggerI2C.c.

◆ i2c_getParams()

i2c_params i2c_getParams ( void  )

Fill out default I2C parameters.

Returns
Default I2C parameters

Definition at line 223 of file LoggerI2C.c.

◆ i2c_logging()

void* i2c_logging ( void *  ptargs)

I2C main logging loop.

Iterates over all registered channels, calling the appropriate read function against the registered I2C device ID.

After each conversion function has been called, this thread will sleep in an attempt to keep the poll frequency at the rate requested. This is a best effort attempt.

Thread will exit on error

Parameters
[in]ptargsPointer to log_thread_args_t
Returns
NULL - Error code set in ptargs->returnCode if required

Definition at line 68 of file LoggerI2C.c.

◆ i2c_parseConfig()

bool i2c_parseConfig ( log_thread_args_t lta,
config_section s 
)

Take a configuration section, parse parameters and register devices.

Parameters
[in]ltaPointer to log_thread_args_t
[in]sPointer to config_section to be parsed
Returns
True on success, false on error

Definition at line 405 of file LoggerI2C.c.

◆ i2c_setup()

void* i2c_setup ( void *  ptargs)

I2C Connection setup.

Connects to specified I2C bus after validating the configured channel map.

Device specific parameters need to be specified in an i2c_params structure

Parameters
[in]ptargsPointer to log_thread_args_t
Returns
NULL - Error code set in ptargs->returnCode if required

Definition at line 34 of file LoggerI2C.c.

◆ i2c_shutdown()

void* i2c_shutdown ( void *  ptargs)

I2C shutdown.

Simple wrapper around i2c_closeConnection(), which will do any cleanup required.

Parameters
[in]ptargsPointer to log_thread_args_t
Returns
NULL

Definition at line 131 of file LoggerI2C.c.

◆ i2c_validate_chanmap()

bool i2c_validate_chanmap ( i2c_params ip)

Check channel mapping is valid.

Ensures that the only one message is set for each channel, that no reserved channels are used and that device addresses and read functions are set.

Parameters
[in]ipPointer to i2c_params structure
Returns
True if all parameters are valid, false otherwise

Definition at line 241 of file LoggerI2C.c.