API Documentation¶
Provider lib¶
Public API for the provider library. Details on how to use this can be found here.
Enums¶
Functions¶
-
int provider_reader_register(struct provider_reader *pr, struct provider *p)¶
Registers a single provider in the provider reader and increments
dst_N.Usually called from helpers like
provider_reader_register_all_sensor.
-
int provider_reader_read_all(struct provider_reader *pr, float *dst)¶
Reads from all providers in the provider reader using
read_fnand collates results into a float buffer.dstsize must be greater or equal thandst_N.
-
int provider_reader_hdr(struct provider_reader *pr, struct provider_hdr_entry *hdr)¶
Generates a header containing information on provider id and channel of every element in the float buffer returned by
provider_reader_read_all.hdrsize must be greater or equal thandst_N. Header doesn’t change between reads and should be generated only after provider registration.
-
struct provider¶
- #include <provider.h>
-
struct provider_reader¶
- #include <provider.h>
-
struct provider_hdr_entry¶
- #include <provider.h>
Anomaly lib¶
Anomaly lib documentation. Details on usage are found here.
Defines¶
-
DETECTOR_SMOOTHING_NONE¶
No smoothing used for anomaly detection.
-
DETECTOR_SMOOTHING_EXP_SMOOTHING¶
Apply exponential moving average smoothing. Ensure to set the smoothing factor:
struct detector_classifier dc; detector_classifier_init(&dc, ...); dc.exp_moving_avg_opts.smoothing_factor = 0.3f;
-
DETECTOR_DEFAULT_OPTS¶
Typedefs¶
-
typedef void (*detector_cb_t)(void *ctx, float score)¶
Callback type when classifier threshold is met.
-
typedef float (*detector_smoothing_cb_t)(struct detector_classifier *dc, float score, void *ctx)¶
Type for the smoothing function.
Enums¶
Functions¶
-
float detector_smoothing_exp_smoothing(struct detector_classifier *dc, float score, void *ctx)¶
-
static inline int32_t detector_detect(const float *buffer, float *score)¶
Calculates anomaly score of provided data
buffersize depends on the detector.scoreis a single float.
-
static inline int32_t detector_init()¶
-
int32_t detector_classifier_init(struct detector *d, struct detector_classifier *dc, struct provider_reader *pr, detector_smoothing_cb_t smoothing, int64_t processing_delay, float threshold)¶
Initialize the detector classifier struct.
- Parameters:¶
- struct detector *d¶
Initialized detector
- struct detector_classifier *dc¶
Uninitialized detector classifier
- struct provider_reader *pr¶
Pointer to the initialized provider_reader object
- detector_smoothing_cb_t smoothing¶
Function used for smoothing scores. Possible values are:
DETECTOR_SMOOTHING_NONE - no smoothing.
DETECTOR_SMOOTHING_EXP_SMOOTHING - exponential smoothing.
- int64_t processing_delay¶
Cadence for obtaining new values from the detector.
- float threshold¶
Probability threshold in (0, 1) to determine whether a score is anomaly or not.
-
int32_t detector_classifier_start(struct detector_classifier *dc, int priority, int thread_opts)¶
Start the callback handler in the background.
- Parameters:¶
- struct detector_classifier *dc¶
Initialized classifier object
- int priority¶
Priority given to thread.
- int thread_opts¶
Pass
DETECTOR_DEFAULT_OPTSfor the default settings. Otherwise, this contains standard Zephyr thread options.
-
int32_t detector_classifier_deinit(struct detector_classifier *dc)¶
Stop the callback handler and cleanup
- Parameters:¶
- struct detector_classifier *dc¶
classifier object
-
int32_t detector_classifier_register_cb(struct detector_classifier *dc, detector_cb_t cb, void *ctx)¶
Register a callback that is run when an anomaly is detected.
- Parameters:¶
- struct detector_classifier *dc¶
The detector object.
- detector_cb_t cb¶
Callback function
- void *ctx¶
Opaque context passed to this specific callback.
-
void detector_classifier_unregister_cb(struct detector_classifier *dc)¶
Unregister all callbacks
- Parameters:¶
- struct detector_classifier *dc¶
The detector object
-
struct detector¶
- #include <detector.h>
-
struct detector_smoothing_opts_exp_mav¶
- #include <detector.h>
-
struct detector_classifier¶
- #include <detector.h>
Callback handler manager for anomaly detection.
Public Members¶
-
float threshold¶
Threshold for the anomaly detection
-
int64_t process_ms¶
Expected processing time
-
size_t num_cbs¶
Number of registered callbacks
-
void *cb_ctxs[CONFIG_ANOMALY_LIB_DETECTION_CALLBACKS_MAX_CB_HDLRS]¶
-
detector_smoothing_cb_t smoothing¶
Smoothing function
-
float smoothed_moving_average¶
Current value of the moving average
-
bool smoothing_started¶
Indicator whether smoothing started. Used to prevent initializing
smoothing_scoreto some absurd number such as 0 or NaN.
-
struct detector_smoothing_opts_exp_mav exp_moving_avg_opts¶
Options when
DETECTOR_SMOOTHING_EXP_SMOOTHINGis used
- union detector_classifier
Private Members¶
-
struct provider_reader *pr¶
Provider reader object
-
atomic_t deinit_started¶
started deinitialization process
-
struct k_work_q wq¶
internal work queue
-
float buffer[128]¶
internal buffer for the provider
-
struct provider_hdr_entry hdr[128]¶
internal header buffer
-
struct k_thread thread_data¶
thread data
-
k_tid_t tid¶
thread ID
-
detector_cb_t cb_hdlrs[CONFIG_ANOMALY_LIB_DETECTION_CALLBACKS_MAX_CB_HDLRS]¶
Struct containing the registered callbacks
-
float threshold¶