Fix invalid channel ID handling.

Fix the issue where get_state* functions do not handle when id is RELAY_CHN_ID_ALL.
Fixes #1037.
This commit is contained in:
2025-07-11 18:28:59 +03:00
parent 9b2274ed7c
commit b239b50abe
2 changed files with 5 additions and 4 deletions

View File

@@ -49,6 +49,7 @@ typedef enum relay_chn_direction_enum relay_chn_direction_t;
* @brief Enums that represent the state of a relay channel.
*/
enum relay_chn_state_enum {
RELAY_CHN_STATE_UNDEFINED, ///< The relay channel state is undefined.
RELAY_CHN_STATE_FREE, ///< The relay channel is free to run or execute commands.
RELAY_CHN_STATE_STOPPED, ///< The relay channel is stopped and not running.
RELAY_CHN_STATE_FORWARD, ///< The relay channel is running in the forward direction.

View File

@@ -648,16 +648,16 @@ static void relay_chn_issue_cmd(relay_chn_t* relay_chn, relay_chn_cmd_t cmd)
/* relay_chn APIs */
relay_chn_state_t relay_chn_get_state(uint8_t chn_id)
{
if (!relay_chn_is_channel_id_valid(chn_id)) {
return RELAY_CHN_STATE_STOPPED;
if (!relay_chn_is_channel_id_valid(chn_id) || chn_id == RELAY_CHN_ID_ALL) {
return RELAY_CHN_STATE_UNDEFINED;
}
return relay_channels[chn_id].state;
}
char *relay_chn_get_state_str(uint8_t chn_id)
{
if (!relay_chn_is_channel_id_valid(chn_id)) {
return "INVALID";
if (!relay_chn_is_channel_id_valid(chn_id) || chn_id == RELAY_CHN_ID_ALL) {
return relay_chn_state_str(RELAY_CHN_STATE_UNDEFINED);
}
return relay_chn_state_str(relay_channels[chn_id].state);
}