LoRa-BLE-Sensor
Loading...
Searching...
No Matches
sensor_data.h
Go to the documentation of this file.
1
13#ifndef SENSOR_DATA_H
14#define SENSOR_DATA_H
15
16#include "sensor_id.h"
17#include <stddef.h>
18#include <stdint.h>
19#include <zephyr/sys/ring_buffer.h>
20
21#define MAX_DATA_BUFFER_SIZE 100
22
28 DATA_TYPE_INT,
29 DATA_TYPE_UINT8,
30 DATA_TYPE_UINT16,
31 DATA_TYPE_UINT32,
32 DATA_TYPE_FLOAT,
33 DATA_TYPE_LIMIT
34};
35
40typedef struct {
41 /* Sensor id to use for the sensor. */
42 enum sensor_id id;
43 /* Power id to use for the sensor. */
44 enum sensor_power_id power_id;
45 /* Ring buffer for sensor data. */
46 struct ring_buf data_ring_buf;
47 /* Ring buffer for timestamps. */
48 struct ring_buf timestamp_ring_buf;
49 /* Maximum number of samples to store in the buffer. */
50 size_t max_samples;
51 /* Size of the data in the buffer. */
52 size_t data_size;
53 /* Size of the timestamp in the buffer. */
54 size_t timestamp_size;
55 /* Pointer to latest data. */
56 void *latest_data;
57 /* Latest timestamp. */
58 int latest_timestamp;
59 /* Number of samples in the buffer. */
60 uint32_t num_samples;
62
73int sensor_data_setup(sensor_data_t *sensor_data, enum sensor_types type, enum sensor_voltage voltage_enum);
74
82int sensor_data_read(sensor_data_t *sensor_data, int timestamp);
83
90
96int sensor_data_clear(sensor_data_t *sensor_data);
97
106int sensor_data_format_for_lorawan(sensor_data_t *sensor_data, uint8_t *data, uint8_t *data_len);
107
108#endif
int sensor_data_clear(sensor_data_t *sensor_data)
Clear the sensor data.
Definition sensor_data.c:328
int sensor_data_setup(sensor_data_t *sensor_data, enum sensor_types type, enum sensor_voltage voltage_enum)
Setup the sensor data. If the sensor chosen has continuous power, the power will be turned on when th...
Definition sensor_data.c:87
int sensor_data_format_for_lorawan(sensor_data_t *sensor_data, uint8_t *data, uint8_t *data_len)
Format the sensor data for LoRaWAN, this breaks the data into a uint8_t array.
Definition sensor_data.c:353
int sensor_data_print_data(sensor_data_t *sensor_data)
Print the sensor data from data and timestamp ring buffers. Displaying it from the oldest to newest.
Definition sensor_data.c:256
sensor_data_type
Types of data that can be stored in the sensor data buffer. Currently unused, plans to keep it for fu...
Definition sensor_data.h:27
int sensor_data_read(sensor_data_t *sensor_data, int timestamp)
Read the sensor data, and store the data in the buffer. It adds a tinestamp to the data buffer.
Definition sensor_data.c:190
This is a library to keep track of sensor ids and sensor power ids. As well as the configuration for ...
sensor_id
Sensor identifiers.
Definition sensor_id.h:20
sensor_power_id
Sensor power identifiers.
Definition sensor_id.h:45
sensor_types
Types of sensors that can be configured.
Definition sensor_id.h:29
sensor_voltage
Voltage levels for sensor power.
Definition sensor_id.h:54
Structure for the sensor data. This is used to store the sensor data and timestamp for each sensor.
Definition sensor_data.h:40