release-1.0.0 #39

Merged
ismail merged 78 commits from release-1.0.0 into main 2025-09-13 10:55:49 +02:00
Owner

Summary

This PR finalizes the first major release v1.0.0 of the relay channel component.
It consolidates new features, performance improvements, bug fixes, and major API refactors to provide a stable and production-ready foundation.

TICKET-1115

Changes

  • Added single channel and multi-channel modes with dedicated examples.
  • Introduced run limit feature with NVS persistence.
  • Added background tasks for NVS and long-running operations.
  • Modularized listener notification system.
  • Improved tilt handling (upper limit checks, STOP command fixes, reverse tilt fixes).
  • Optimized event loop and timer callbacks for performance and lower memory usage.
  • Added SPDX license headers and cleaned up code & comments.
  • Added new public APIs:
    • relay_chn_tilt_get_default_sensitivity
    • relay_chn_state_to_str
    • Specific *_all and *_all_with functions
  • Enhanced unit tests and coverage across all features.
  • Updated CMakeLists and build system to support ESP-IDF build profiles.
  • #957 - Add single channel mode
  • #1074 - Add NVS storage option
  • #1080 - Implement free running time limit
  • #1085 - Code and API optimization
  • #1089 - Add unit tests for new *all functions
  • #1096 - Add background tasks for unpredictable long running operations
  • #1097 - Modularize listener notification
  • #1098 - Do NVS operations in background
  • #1104 - Add examples for both modes
  • #1105 - Implement a single channel example
  • #1108 - Add state to string API function
  • #1111 - Add a multi-channel example
    (and all related bug fixes up to #1114)

Breaking Changes

  • Config parameter renaming: All custom defines are replaced with their original CONFIG_ prefixed names.
  • API refactors:
    • time_sec parameter renamed to limit_sec in run limit APIs.
    • Deprecated RELAY_CHN_ID_ALL in favor of new *_all and *_all_with functions.
    • relay_chn_state_str is renamed and exposed as public API relay_chn_state_to_str.
  • STOP and TILT command behavior:
    • STOP no longer issued when idle.
    • Correct handling of STOP during pending states.
    • TILT_STOP and reverse tilt commands now prioritized and validated.
  • Listener handling:
    • Old inline listener management removed.
    • Now handled by modularized notification system with queue-based dispatch.
  • NVS storage:
    • New background task logic with asynchronous writes (breaking previous synchronous-only flow).
    • Critical key naming bug fix changes how channel values are stored.

Migration Guide

  • Config Parameters: Update code and sdkconfig to use original CONFIG_* names.
  • Run Limit API: Replace any time_sec references with limit_sec.
  • Channel Selection: Remove usage of RELAY_CHN_ID_ALL, switch to *_all or *_all_with.
  • State String API: Replace private relay_chn_state_str with public relay_chn_state_to_str.
  • STOP & TILT Logic: Review application-level command handling; STOP and TILT may now behave differently than before.
  • Listeners: Use new notification module APIs for registering/unregistering listeners.
  • NVS: If relying on synchronous writes, ensure application adapts to asynchronous background task model.
## Summary This PR finalizes the first major release **v1.0.0** of the relay channel component. It consolidates new features, performance improvements, bug fixes, and major API refactors to provide a stable and production-ready foundation. TICKET-1115 ## Changes - Added **single channel** and **multi-channel** modes with dedicated examples. - Introduced **run limit feature** with NVS persistence. - Added **background tasks** for NVS and long-running operations. - Modularized **listener notification system**. - Improved **tilt handling** (upper limit checks, STOP command fixes, reverse tilt fixes). - Optimized **event loop** and **timer callbacks** for performance and lower memory usage. - Added **SPDX license headers** and cleaned up code & comments. - Added **new public APIs**: - `relay_chn_tilt_get_default_sensitivity` - `relay_chn_state_to_str` - Specific `*_all` and `*_all_with` functions - Enhanced **unit tests** and coverage across all features. - Updated **CMakeLists** and build system to support ESP-IDF build profiles. ## Related Issues - #957 - Add single channel mode - #1074 - Add NVS storage option - #1080 - Implement free running time limit - #1085 - Code and API optimization - #1089 - Add unit tests for new *all functions - #1096 - Add background tasks for unpredictable long running operations - #1097 - Modularize listener notification - #1098 - Do NVS operations in background - #1104 - Add examples for both modes - #1105 - Implement a single channel example - #1108 - Add state to string API function - #1111 - Add a multi-channel example (and all related bug fixes up to #1114) ## Breaking Changes - **Config parameter renaming**: All custom defines are replaced with their original `CONFIG_` prefixed names. - **API refactors**: - `time_sec` parameter renamed to `limit_sec` in run limit APIs. - Deprecated `RELAY_CHN_ID_ALL` in favor of new `*_all` and `*_all_with` functions. - `relay_chn_state_str` is renamed and exposed as public API `relay_chn_state_to_str`. - **STOP and TILT command behavior**: - STOP no longer issued when idle. - Correct handling of STOP during pending states. - TILT_STOP and reverse tilt commands now prioritized and validated. - **Listener handling**: - Old inline listener management removed. - Now handled by modularized notification system with queue-based dispatch. - **NVS storage**: - New background task logic with asynchronous writes (breaking previous synchronous-only flow). - Critical key naming bug fix changes how channel values are stored. ## Migration Guide - **Config Parameters**: Update code and sdkconfig to use original `CONFIG_*` names. - **Run Limit API**: Replace any `time_sec` references with `limit_sec`. - **Channel Selection**: Remove usage of `RELAY_CHN_ID_ALL`, switch to `*_all` or `*_all_with`. - **State String API**: Replace private `relay_chn_state_str` with public `relay_chn_state_to_str`. - **STOP & TILT Logic**: Review application-level command handling; STOP and TILT may now behave differently than before. - **Listeners**: Use new notification module APIs for registering/unregistering listeners. - **NVS**: If relying on synchronous writes, ensure application adapts to asynchronous background task model.
ismail added 78 commits 2025-09-13 10:45:15 +02:00
Reviewed-on: #30
The addition of a single-channel mode implied further modularisation of the component. This commit has broken the component down into the following modules to avoid a huge single source file and to make unit testing easier.

The modules:

- Separation of public and private code
- *types and *defs
- public relay_chn API
- *adapter
- *output
- *run_info
- *core
- *ctl (control)
- *tilt

Closes #957.
Refactor relay channel component to support single and multi-channel modes; update CMake configuration and enhance API documentation.
- Created `test_relay_chn_tilt_multi.c` and `test_relay_chn_tilt_single.c` to implement comprehensive tests for the tilt functionality of relay channels, covering various scenarios including transitions between states and sensitivity settings.
- Introduced a new partition table in `partitionTable.csv` for proper memory management.
- Updated `sdkconfig` to set the relay channel count to 1 for single channel testing and adjusted related configurations.
- Added default configuration file `sdkconfig.defaults.single` for streamlined testing setup.
Reviewed-on: #32
Unignore .vscode folder and add necessary configuration files for a
synced development environment.
- Introduced NVS configuration options in Kconfig.
- Implemented NVS initialization and deinitialization in relay_chn_core.
- Added functions for storing and retrieving relay channel direction and tilt sensitivity in NVS.
- Updated relay_chn_tilt and relay_chn_output to utilize NVS for state management.
- Created relay_chn_nvs.c and relay_chn_nvs.h for NVS-related functionalities.

Closes #1074.
- Removed unnecessary calls to relay_chn_create and g_is_component_initialized in multiple test cases across test_relay_chn_core_single.c, test_relay_chn_listener_multi.c, and test_relay_chn_listener_single.c.
- Introduced new test files for NVS functionality: test_relay_chn_nvs_multi.c and test_relay_chn_nvs_single.c, covering initialization, direction setting, invalid parameters, and erase operations.
- Updated partition table configuration to support NVS storage, including the addition of a new partition file part_nvs.csv.
- Adjusted sdkconfig files to enable NVS support and configure custom partition settings for relay channels.
- Added new utility script run_tests_all_cfgs.sh to run tests for all configurations and with test tag support.
- Updated run_tests.sh to add the new test tag for NVS unit tests.
Reviewed-on: #33
- Optimized tilt counting data by reducing the tilt counter variables into one for smaller memory footprint. So the `relay_chn_tilt_counter_t` type is replaced by a single `uint16_t` variable in the `relay_chn_tilt_ctl_t` structure. Hence the `relay_chn_tilt_counter_t` type has been removed since it is not necessary anymore.
- Refactored tilt count handling in NVS: consolidate forward and reverse counts into a single tilt count parameter.
- Updated NVS test files that affected by the data type and function signature changes.

Fixes #1079
Fix NVS module's tag string value to match the module name. IssueID #1081.
Fix key names with more approprite ones and add documentation for them. Fixes #1081.
Reviewed-on: #34
Updated README.md with detailed NVS storage configuration and initialization instructions.

Fixes #1082.
Reviewed-on: #35
- Introduced configuration options for enabling run limits in Kconfig.
- Added APIs to get and set run limits for individual relay channels.
- Implemented run limit timer functionality to automatically stop channels.
- Updated NVS handling to store and retrieve run limit values.
- Enhanced documentation in README and code comments to reflect new feature.

Closes #1080
The sdkconfig.defaults files were enhanced to test the component against all individual configurations for more granularity, as well as with all combinations to ensure consistency and integrity across all configurations.
The event loop queue and  task stack size is optimized to be determined by config factors.

Fixes #1083
It turned out that esp_event was adding extra complexity to the code base and it was completely unnecessary. So it has been removed from the component completely. The actions are now executed directly in the `relay_chn_distpacth_cmd()` and `relay_chn_tilt_dispatch_cmd()` functions.
This change has simplified the component as well as reduced the memory footprint.

Fixes #1084, refs #1083
Reviewed-on: #36
Refs #1085.
The config parameter names defined in the relay_chn_defs.h file
have been changed back to their original names (with the CONFIG_ prefix),
so that they are not confused with application-level defines.

Refs #1085
Unnecessary `#if CONFIG_FOO == 1` checks were removed and the
statements were simplified to` #if CONFIG_FOO`.
`#ifdef CONFIG_FOO` statements were also changed to `#if CONFIG_FOO`
to keep the style as uniform as possible.

Refs #1085
Specific `_*all` and `_*all_with` functions were implemented to make
the API more concise and clean, and to replace the use of
`RELAY_CHN_ID_ALL`, which caused confusion within the API.

Refs #1085
- Delete unused declaration of `g_is_component_initialized`.
- Replace the following constants with approprite config options:
  + `relay_chn_count` > `CONFIG_RELAY_CHN_COUNT`
  + `opposite_inerta_ms` > `CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS`
- Replace the definition of the `test_delay_margin_ms` constant with  `#define TEST_DELAY_MARGIN_MS 50` for preprocessor calculations.
- `TILT_STOP` command is prioritized in `relay_chn_tilt_issue_cmd()` because it should override any other tilt commands.
- The debug logs are cleaned up.

Fixes #1088
Refs #1085
Refactor tilt test functions to use batch operations for all channels and improve state checks.

Refs #1085
Refactor the brackets of the test case functions to align with ESP-IDF style.

Refs #1085
ESP-IDF provides a more efficient way of handling and combining
multi-configurations for a project than the way currently used:
Build profiles.

So I switched to this method instead of providing the sdkconfig.defaults.*
files manually. This reduced the number of sdkconfig.defaults.* files
as well as the configuration parameters defined in them.

Refs #1085
The tilt sensitivity values were passed to the NVS module without
the boundaries being checked, even though the maximum
percent value is 100. This commit fixes this issue.
Also test cases are added to cover the upper boundary checks
for the tilt sensitivity settings.

Fixes #1086
Fixes #1087
Fixed a possible integer underflow bug that may cause the timer
to be set for an unexpectedly long duration.

Fixes #1091
A helper function added for each module so that each module
handles errors by itself.

Fixes #1092
An if statement has been added to handle the STOP command properly
when the `previous_state` is one of the `*PENDING` states.

Fixes #1093
Refs #1090
Some missing test cases for the public API have been added.

Closes #1090
- Refactor reset_channels_to_idle_state to reset_channels_to_defaults
and enhance functionality with direction reset logic. This is because
some tilt test cases were failing due to modified run limit values in some
of the previous core test cases. See #1089-3.
- A relay channel listener has been added to diagnose channel
states during tests.

Refs #1089
Added test cases for the recently implemented `*all` and `*all_with`
functions. Closes #1089.
Implemented `relay_chn_stop_prv` to streamline stop command handling
and avoid unnecessary code execution. Fixes #1095.
Some test cases that were testing for only one channel in multi-channel mode are fixed to test all available channels. Fixes #1094
- 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
- Fixed a critical NVS key generation bug that would cause overwriting the values for all channels.
- Optimized the code for single channel mode since no formatting required.
- Improved multi-channel test coverage to cover that each value for each channel stored correctly.

Refs #1096, #1098 and fixes #1100
- Implemented a dedicated background task to decouple long-running code from the main application task.
- Improved the NVS commit code logic, especially for batch writes to minimize flash wear.
- Updated NVS functions to support asynchronous writes and synchronous reads.
- Added default value parameters to `get` functions for better usability.
- Improved error handling and logging in NVS operations.
- Refactored related code in multiple source files to accommodate these changes.

Refs #1085, #1096 and closes #1098
- Refactored and improved NVS tests to accomodate latest changes in NVS module. See #1098
- Improved channel reset function that is called from `tearDown` to minimize public API calls that trigger a chain of internal calls that involve NVS and timer operations.
- Fixed test case bugs that make some test cases to fail.

Refs #1096, #1098
- Add check for empty listener list in find_listener_entry function.
- Reset notification queue when all listeners are removed.
- Change queue operation to send remove_listener message to the front of the queue.

Refs #1085, #1096 and fixes #1102
Added `relay_chn_tilt_get_default_sensitivity` function and test cases.

Refs #1085 and fixes #1101
Refs #1085 and closes #1099
Fixed static variable names according to the ESP-IDF C code formatting guide.

Refs #1085 and fixes #1103
Fixed include directory settings and conditional includes in CMakeLists and test_common.c. Refs #1085.
Reviewed-on: #37
Fixed a mispelled configuration parameter. Refs #1105
Fixed almost unconditional STOP command issuing when the
channel is idle. Refs #1104, #1105 and closes #1107.
Added a state to string public API function. There was already
a private function (`relay_chn_state_str`) that provides
this functionality. So this function has been renamed to
`relay_chn_state_to_str` and made publicly available.

Refs #1104, #1105 and closes #1108.
Added a helper function to determine if the channel may perform
the requested tilt command. Refs #1105 and fixes #1109.
Fixed TILT_STOP command issuing chain that was causing a running channel
to be stopped when an opposite direction tilting requested. For exeample:
RUN_FORWARD > TILT_REVERSE. Refs #1105 and fixes #1110.
Added a single channel example with run limit and tilting
features. Refs #1104 and closes #1105.
Fixed mistaken channel validity check in `tilt_stop` funciton
in multi mode. Refs #1111 and fixes #1114.
Added a multi channel example with run limit, tilting and channel selection
features. Refs #1104 and closes #1111.
Reviewed-on: #38
Fixed test_apps directory locating issue by fixing the path to
"project_root/test_apps" and removed find command since it
searches recursively and founds the similar directories in
managed_components directory. Also added current time to the output.
TAG constant is only used when run limit is enabled. As a result,
the compiler generates an "unused variable" warning for other cases.
Fixed this warning by adding the unused attribute.
Tilt tests started to fail after the latest changes. Had to make
some fixes and optimizations so that the test code resets the
tilt controls correctly and aligns with relay_chn's timing requirements.

Fixes #1115
ismail self-assigned this 2025-09-13 10:46:24 +02:00
ismail merged commit fafc23591a into main 2025-09-13 10:55:49 +02:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: KozmotronikTech/relay_chn#39