fetcher 0.0.0
A command line utility for reading sensor data over I2C and providing it over stdout.
sensor_api.h File Reference

Types and function prototypes for the sensor API used to communicate with I2C bus sensors. More...

#include <errno.h>
#include <hw/i2c.h>
#include <stdint.h>
#include <stdio.h>

Go to the source code of this file.

Data Structures

struct  vec2d_t
 
struct  vec2d_i32_t
 
struct  vec3d_t
 
struct  common_t
 
struct  SensorTagData
 
struct  SensorTagList
 
struct  SensorContext
 
struct  SensorLocation
 
struct  Sensor
 

Enumerations

enum  SensorTag {
  TAG_TEMPERATURE = 0x0 , TAG_PRESSURE = 0x1 , TAG_HUMIDITY = 0x2 , TAG_TIME = 0x3 ,
  TAG_ALTITUDE_SEA = 0x4 , TAG_ALTITUDE_REL = 0x5 , TAG_ANGULAR_VEL = 0x6 , TAG_LINEAR_ACCEL_REL = 0x7 ,
  TAG_LINEAR_ACCEL_ABS = 0x8 , TAG_COORDS = 0x9 , TAG_VOLTAGE = 0xa
}
 
enum  SensorTagDType {
  TYPE_FLOAT , TYPE_U32 , TYPE_U16 , TYPE_U8 ,
  TYPE_I32 , TYPE_I16 , TYPE_I8 , TYPE_VEC3D ,
  TYPE_VEC2D_I32 , TYPE_VEC2D
}
 
enum  SensorPrecision { PRECISION_HIGH , PRECISION_MED , PRECISION_LOW }
 

Functions

void memcpy_be (void *dest, const void *src, const size_t nbytes)
 
size_t sensor_max_dsize (const Sensor *sensor)
 
const char * sensor_strtag (const SensorTag tag)
 
void sensor_write_data (FILE *stream, const common_t *msg)
 
void sensor_set_precision (Sensor sensor, const SensorPrecision precision)
 
errno_t sensor_open (Sensor sensor)
 
errno_t sensor_read (Sensor sensor, const SensorTag tag, void *buf, size_t *nbytes)
 
size_t sensor_get_ctx_size (Sensor sensor)
 
void sensor_set_ctx (Sensor *sensor, void *buf)
 

Detailed Description

Types and function prototypes for the sensor API used to communicate with I2C bus sensors.

Types and function prototypes for the sensor API used to communicate with I2C bus sensors. This API provides a way to set up and read sensors easily. Sensors can read multiple data types in standard measurements. Sensors also have a configurable precision.

Enumeration Type Documentation

◆ SensorPrecision

Enumerator
PRECISION_HIGH 

High precision measurements

PRECISION_MED 

Medium precision measurements

PRECISION_LOW 

Low precision measurements

◆ SensorTag

enum SensorTag

Describes possible data types that fetcher is capable of producing.

Enumerator
TAG_TEMPERATURE 

Temperature in degrees Celsius

TAG_PRESSURE 

Pressure in kilo Pascals

TAG_HUMIDITY 

Humidity in % relative humidity

TAG_TIME 

Time in milliseconds

TAG_ALTITUDE_SEA 

Altitude above sea level in meters

TAG_ALTITUDE_REL 

Altitude above launch height in meters

TAG_ANGULAR_VEL 

Angular velocity in degrees per second

TAG_LINEAR_ACCEL_REL 

Relative linear acceleration in meters per second squared

TAG_LINEAR_ACCEL_ABS 

Absolute linear acceleration in meters per second squared

TAG_COORDS 

Latitude and longitude in degrees

TAG_VOLTAGE 

Voltage in volts with a unique ID.

◆ SensorTagDType

Describes the data type of the data associated with a tag.

Enumerator
TYPE_FLOAT 

float

TYPE_U32 

uint32_t

TYPE_U16 

uint16_t

TYPE_U8 

uint8_t

TYPE_I32 

int32_t

TYPE_I16 

int16_t

TYPE_I8 

int8_t

TYPE_VEC3D 

vec3d_t

TYPE_VEC2D_I32 

vec2d_u32

TYPE_VEC2D 

vec2d_t

Function Documentation

◆ memcpy_be()

void memcpy_be ( void *  dest,
const void *  src,
const size_t  nbytes 
)

Utility function for copying memory in big-endian format.

Parameters
destThe destination buffer for data copied from src.
srcThe source buffer for data to be copied into dest.
nbytesThe number of bytes to copy from src into dest.

◆ sensor_get_ctx_size()

size_t sensor_get_ctx_size ( Sensor  sensor)

◆ sensor_max_dsize()

size_t sensor_max_dsize ( const Sensor sensor)

Gets the maximum data size returned when reading the sensor.

Parameters
sensorThe sensor to find the maximum data size of.
Returns
The maximum dsize of all the tags in the tag list.

◆ sensor_open()

errno_t sensor_open ( Sensor  sensor)

◆ sensor_read()

errno_t sensor_read ( Sensor  sensor,
const SensorTag  tag,
void *  buf,
size_t *  nbytes 
)

◆ sensor_set_ctx()

void sensor_set_ctx ( Sensor sensor,
void *  buf 
)

◆ sensor_set_precision()

void sensor_set_precision ( Sensor  sensor,
const SensorPrecision  precision 
)

◆ sensor_strtag()

const char * sensor_strtag ( const SensorTag  tag)

◆ sensor_write_data()

void sensor_write_data ( FILE *  stream,
const common_t msg 
)

Writes sensor data in a standard format.

Parameters
streamThe output stream for writing sensor data.
tagThe tag describing the kind of sensor data.
dataA pointer to the sensor data to be printed.