Files
relay_chn/test_apps/main/test_relay_chn_notify_common.h
ismail 5e8e5a4cab Add notification system for relay channel state changes
- Introduced a new notification module to handle state change listeners.
- Added functions to register and unregister listeners for relay channel state changes.
- Implemented a queue-based system to manage notifications and listener callbacks.
- Updated core relay channel logic to utilize the new notification system.
- Removed old listener management code from relay channel core.
- Refactored the former listener tests to notify tests and added tests for the notification system, including handling of multiple listeners and queue overflow scenarios.
- Updated CMakeLists.txt to include new source files and headers for the notification module.
- Revised README.md to include warnings about callback execution context and performance considerations.

Refs #1096, #1085 and closes #1097
2025-09-02 15:46:48 +03:00

49 lines
1.4 KiB
C

#pragma once
#include "test_common.h"
#include "freertos/semphr.h"
#include <stdarg.h>
#ifdef __cplusplus
extern "C" {
#endif
// This is defined in the source file, we redefine it here for the test.
// The test build must have the same CONFIG_RELAY_CHN_COUNT.
#define TEST_RELAY_CHN_NOTIFY_QUEUE_LEN (16 + CONFIG_RELAY_CHN_COUNT * 4)
// --- Listener Test Globals ---
typedef struct {
uint8_t chn_id;
relay_chn_state_t old_state;
relay_chn_state_t new_state;
int call_count;
} listener_callback_info_t;
// --- Listener callback infos to be defined ---
extern listener_callback_info_t listener1_info;
extern listener_callback_info_t listener2_info;
// --- Globals for Advanced Tests ---
extern SemaphoreHandle_t blocking_listener_sem;
extern SemaphoreHandle_t log_check_sem;
extern volatile int blocking_listener_call_count;
extern vprintf_like_t original_vprintf;
// --- Listener Test Helper Functions ---
// Clear the memory from possible garbage values
void reset_listener_info(listener_callback_info_t* info);
// State listeners for notify module testing
void test_listener_1(uint8_t chn_id, relay_chn_state_t old_state, relay_chn_state_t new_state);
void test_listener_2(uint8_t chn_id, relay_chn_state_t old_state, relay_chn_state_t new_state);
void blocking_listener(uint8_t chn_id, relay_chn_state_t old_state, relay_chn_state_t new_state);
int log_check_vprintf(const char *format, va_list args);
#ifdef __cplusplus
}
#endif