SELKIELogger  1.0.0
LoggerI2C.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Swansea University
3  *
4  * This file is part of the SELKIELogger suite of tools.
5  *
6  * SELKIELogger is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the Free
8  * Software Foundation, either version 3 of the License, or (at your option)
9  * any later version.
10  *
11  * SELKIELogger is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this SELKIELogger product.
18  * If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #ifndef SL_LOGGER_I2C_H
22 #define SL_LOGGER_I2C_H
23 
24 #include <errno.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <time.h>
28 #include <unistd.h>
29 
30 #include "SELKIELoggerBase.h"
31 #include "SELKIELoggerI2C.h"
32 #include "SELKIELoggerMP.h"
33 
35 
52 typedef struct {
53  uint8_t messageID;
54  string message_name;
55  uint8_t deviceAddr;
57  void *ext;
58 } i2c_msg_map;
59 
61 typedef struct {
62  char *busName;
63  uint8_t sourceNum;
64  char *sourceName;
65  int handle;
66  int frequency;
67  int en_count;
69 } i2c_params;
70 
72 void *i2c_setup(void *ptargs);
73 
75 void *i2c_logging(void *ptargs);
76 
78 void *i2c_shutdown(void *ptargs);
79 
81 void *i2c_channels(void *ptargs);
82 
85 
88 
91 
93 bool i2c_chanmap_add_ina219(i2c_params *ip, const uint8_t devAddr, const uint8_t baseID);
94 
96 bool i2c_chanmap_add_ads1015(i2c_params *ip, const uint8_t devAddr, const uint8_t baseID,
97  const float scale, const float offset, const float minV,
98  const float maxV);
99 
103 #endif
float(* i2c_dev_read_fn)(const int, const int, const void *)
Device specific callback functions.
Definition: I2CConnection.h:37
void * i2c_shutdown(void *ptargs)
I2C shutdown.
Definition: LoggerI2C.c:131
void * i2c_channels(void *ptargs)
Generate I2C channel map.
Definition: LoggerI2C.c:163
void * i2c_logging(void *ptargs)
I2C main logging loop.
Definition: LoggerI2C.c:68
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.
Definition: LoggerI2C.c:275
bool i2c_validate_chanmap(i2c_params *ip)
Check channel mapping is valid.
Definition: LoggerI2C.c:241
bool i2c_parseConfig(log_thread_args_t *lta, config_section *s)
Take a configuration section, parse parameters and register devices.
Definition: LoggerI2C.c:405
device_callbacks i2c_getCallbacks(void)
Fill out device callback functions for logging.
Definition: LoggerI2C.c:212
void * i2c_setup(void *ptargs)
I2C Connection setup.
Definition: LoggerI2C.c:34
i2c_params i2c_getParams(void)
Fill out default I2C parameters.
Definition: LoggerI2C.c:223
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.
Definition: LoggerI2C.c:333
Configuration file section.
Definition: LoggerConfig.h:54
Device specific function information.
Definition: Logger.h.in:72
Map device functions to message IDs.
Definition: LoggerI2C.h:52
uint8_t messageID
Message ID to report.
Definition: LoggerI2C.h:53
void * ext
If not NULL, pointer to additional device data.
Definition: LoggerI2C.h:57
uint8_t deviceAddr
I2C Device address.
Definition: LoggerI2C.h:55
i2c_dev_read_fn func
Pointer to device read function.
Definition: LoggerI2C.h:56
string message_name
Message name to report.
Definition: LoggerI2C.h:54
I2C Source device specific parameters.
Definition: LoggerI2C.h:61
int en_count
Number of messages in chanmap.
Definition: LoggerI2C.h:67
char * busName
Target port name.
Definition: LoggerI2C.h:62
int frequency
Aim to sample this many times per second.
Definition: LoggerI2C.h:66
char * sourceName
Reported source name.
Definition: LoggerI2C.h:64
uint8_t sourceNum
Source ID for messages.
Definition: LoggerI2C.h:63
i2c_msg_map * chanmap
Map of device functions to poll.
Definition: LoggerI2C.h:68
int handle
Handle for currently opened device.
Definition: LoggerI2C.h:65
Logging thread information.
Definition: Logger.h.in:86