25 char *
const error_string,
const size_t space_remaining)
27 if (NULL == error_string)
42 written += snprintf (error_string + written, space_remaining - written,
", ");
48 for (uint8_t ii = 0; ii < 32; ii++)
50 if (error & (1 << ii))
53 error &= 0xFFFFFFFF - (1 << ii);
61 written += snprintf (error_string + written, space_remaining - written,
"%s",
"SUCCESS");
65 written += snprintf (error_string + written, space_remaining - written,
"%s",
"INTERNAL");
69 written += snprintf (error_string + written, space_remaining - written,
"%s",
74 written += snprintf (error_string + written, space_remaining - written,
"%s",
"NO_MEM");
78 written += snprintf (error_string + written, space_remaining - written,
"%s",
83 written += snprintf (error_string + written, space_remaining - written,
"%s",
88 written += snprintf (error_string + written, space_remaining - written,
"%s",
93 written += snprintf (error_string + written, space_remaining - written,
"%s",
98 written += snprintf (error_string + written, space_remaining - written,
"%s",
103 written += snprintf (error_string + written, space_remaining - written,
"%s",
108 written += snprintf (error_string + written, space_remaining - written,
"%s",
113 written += snprintf (error_string + written, space_remaining - written,
"%s",
"TIMEOUT");
117 written += snprintf (error_string + written, space_remaining - written,
"%s",
"NULL");
121 written += snprintf (error_string + written, space_remaining - written,
"%s",
126 written += snprintf (error_string + written, space_remaining - written,
"%s",
131 written += snprintf (error_string + written, space_remaining - written,
"%s",
"BUSY");
135 written += snprintf (error_string + written, space_remaining - written,
"%s",
140 written += snprintf (error_string + written, space_remaining - written,
"%s",
145 written += snprintf (error_string + written, space_remaining - written,
"%s",
150 written += snprintf (error_string + written, space_remaining - written,
"%s",
"SELFTEST");
154 written += snprintf (error_string + written, space_remaining - written,
"%s",
159 written += snprintf (error_string + written, space_remaining - written,
"%s",
164 written += snprintf (error_string + written, space_remaining - written,
"%s",
169 written += snprintf (error_string + written, space_remaining - written,
"%s",
"FATAL");
173 written = snprintf (error_string + written, space_remaining - written,
"%s",
"UNKNOWN");
182 static char * configuration_value_to_string (
const uint8_t val)
185 memset (msg, 0,
sizeof (msg));
187 if (val <= 200 && val > 0)
189 snprintf (msg,
sizeof (msg),
"%d", val);
194 snprintf (msg,
sizeof (msg),
"MIN");
198 snprintf (msg,
sizeof (msg),
"MAX");
202 snprintf (msg,
sizeof (msg),
"CONTINUOUS");
206 snprintf (msg,
sizeof (msg),
"DEFAULT");
210 snprintf (msg,
sizeof (msg),
"No change");
214 snprintf (msg,
sizeof (msg),
"Single");
218 snprintf (msg,
sizeof (msg),
"Sleep");
222 snprintf (msg,
sizeof (msg),
"Not supported");
226 snprintf (msg,
sizeof (msg),
"Not implemented");
230 snprintf (msg,
sizeof (msg),
"Invalid");
234 snprintf (msg,
sizeof (msg),
"Unknown");
246 configuration_value_to_string (configuration->
samplerate));
248 memset (msg, 0,
sizeof (msg));
250 configuration_value_to_string (configuration->
resolution));
252 memset (msg, 0,
sizeof (msg));
254 configuration_value_to_string (configuration->
scale), unit);
256 memset (msg, 0,
sizeof (msg));
284 configuration_value_to_string (configuration->
dsp_parameter));
286 memset (msg, 0,
sizeof (msg));
288 configuration_value_to_string (configuration->
mode));
293 const uint8_t *
const bytes,
299 for (
size_t ii = 0; ii < byte_length; ii++)
301 index += snprintf (msg + index,
sizeof (msg) - index,
"%02X", bytes[ii]);
303 if (ii < (byte_length - 1))
305 index += snprintf (msg + index,
sizeof (msg) - index,
":");
308 if (index >=
sizeof (msg)) {
return; }
348 const char *
const message)
364 const uint8_t *
const bytes,
380 size_t space_remaining)
382 return space_remaining;
#define RD_ERROR_INVALID_PARAM
Invalid Parameter.
#define RD_WARNING_DEPRECATED
Deprecated function, warn user.
#define RD_ERROR_NULL
Null Pointer.
#define RD_ERROR_NOT_INITIALIZED
Driver is not initialized.
#define RD_ERROR_FATAL
Program should always reset after this.
uint32_t rd_status_t
bitfield for representing errors
#define RD_ERROR_INVALID_LENGTH
Invalid Length.
#define RD_ERROR_CHECK(error, mask)
Shorthand macro for calling the rd_error_check with current file & line.
#define RD_ERROR_FORBIDDEN
Forbidden Operation.
#define RD_ERROR_INVALID_DATA
Invalid Data.
#define RD_ERROR_NOT_IMPLEMENTED
Not implemented yet.
#define RD_ERROR_NOT_ENABLED
Driver is not enabled.
#define RD_ERROR_RESOURCES
Not enough resources for operation.
#define RD_ERROR_NOT_SUPPORTED
Not supported.
#define RD_SUCCESS
Internal Error.
#define RD_ERROR_NOT_ACKNOWLEDGED
Ack was expected but not received.
#define RD_ERROR_DATA_SIZE
Invalid Data size.
#define RD_ERROR_NO_MEM
No Memory for operation.
#define RD_ERROR_TIMEOUT
Operation timed out.
#define RD_ERROR_SELFTEST
Self-test fail.
#define RD_ERROR_INVALID_FLAGS
Invalid Flags.
#define RD_ERROR_NOT_FOUND
Not found.
#define RD_ERROR_INVALID_STATE
Invalid state, operation disallowed in this state.
#define RD_ERROR_INTERNAL
Internal Error.
#define RD_ERROR_BUSY
Busy.
#define RD_ERROR_INVALID_ADDR
Bad Memory Address.
void ri_log_hex(const ri_log_severity_t severity, const uint8_t *const bytes, size_t byte_length)
Queues bytes to be logged out as a hex string.
rd_status_t ri_log_init(const ri_log_severity_t min_severity)
Runs initialization code for the logging backend and sets the severity level.
ri_log_severity_t
Enable implementation selected by application.
void ri_log(const ri_log_severity_t severity, const char *const message)
Queues messages into log.
size_t ri_error_to_string(rd_status_t error, char *error_string, size_t space_remaining)
Write text description of error message into given string pointer and null-terminate it....
void ri_log_sensor_configuration(const ri_log_severity_t level, const rd_sensor_configuration_t *const configuration, const char *unit)
rd_status_t ri_log_flush(void)
Blocks until remaining log messages are sent out.
#define RD_SENSOR_DSP_LAST
Return last value from sensor. Parameter: No effect. Use default.
#define RD_SENSOR_ERR_NOT_SUPPORTED
Error code, given parameter is not supported by sensor.
#define RD_SENSOR_CFG_SLEEP
Sensor should go to sleep immediately.
#define RD_SENSOR_CFG_MAX
Configure largest supported and implemented value.
#define RD_SENSOR_CFG_DEFAULT
Default value, always valid for the sensor.
#define RD_SENSOR_DSP_OS
Oversample sensor values. Parameter: Number of samples.
#define RD_SENSOR_DSP_LOW_PASS
Low pass sensor values Parameter: coefficient.
#define RD_SENSOR_ERR_INVALID
Error code, given parameter is invalid.
#define RD_SENSOR_ERR_NOT_IMPLEMENTED
Error code, given parameter is not implemented (todo)
#define RD_SENSOR_CFG_MIN
Configure smallest supported and implemented value.
#define RD_SENSOR_CFG_CONTINUOUS
Sensor will keep sampling at defined sample rate.
#define RD_SENSOR_DSP_HIGH_PASS
High pass sensor values Parameter: coefficient.
#define RD_SENSOR_CFG_NO_CHANGE
Do not change configured value.
#define RD_SENSOR_CFG_SINGLE
Sensor should go to sleep after single measurement.
Header to enable and disable module compilation.
#define RD_LOG_BUFFER_SIZE
Maximum length of one log message.
Ruuvi error codes and error check function.
Ruuvi sensor interface Lifecycle: Beta
All sensors must implement configuration functions which accept this struct.
uint8_t resolution
Resolution, in bits.
uint8_t mode
Mode, RD_SENSOR_SLEEP, _SINGLE, _CONTINOUS.
uint8_t samplerate
Samplerate, in Hz.
uint8_t scale
Scale, in relevant Si-unit.
uint8_t dsp_parameter
Parameter to DSP functions.
uint8_t dsp_function
DSP function, one of RD_SENSOR_DSP_*.