release-1.0.0 #39
@@ -12,171 +12,197 @@
|
|||||||
#define RELAY_CHN_CMD_FORWARD 1
|
#define RELAY_CHN_CMD_FORWARD 1
|
||||||
#define RELAY_CHN_CMD_REVERSE 2
|
#define RELAY_CHN_CMD_REVERSE 2
|
||||||
|
|
||||||
|
void check_all_channels_for_state(relay_chn_state_t state)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
|
||||||
|
TEST_ASSERT_EQUAL(state, relay_chn_get_state(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Helper function to prepare channel for tilt tests
|
// Helper function to prepare channel for tilt tests
|
||||||
void prepare_channel_for_tilt(uint8_t chn_id, int initial_cmd) {
|
void prepare_channels_for_tilt_with_mixed_runs() {
|
||||||
// Ensure the channel reset tilt control
|
// Ensure the channel reset tilt control
|
||||||
relay_chn_tilt_stop(chn_id);
|
relay_chn_tilt_stop_all();
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
||||||
|
|
||||||
|
// Ensure the channel has had a 'last_run_cmd'
|
||||||
|
for (int i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
|
||||||
|
if (i % 2 == 0) {
|
||||||
|
relay_chn_run_forward(i);
|
||||||
|
} else { // Assuming initial_cmd is RELAY_CHN_CMD_REVERSE
|
||||||
|
relay_chn_run_reverse(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS)); // Allow command to process
|
||||||
|
relay_chn_stop_all(); // Stop it to set last_run_cmd but return to FREE for next test
|
||||||
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
||||||
|
check_all_channels_for_state(RELAY_CHN_STATE_IDLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function to prepare channel for tilt tests
|
||||||
|
void prepare_all_channels_for_tilt(int initial_cmd) {
|
||||||
|
// Ensure the channel reset tilt control
|
||||||
|
relay_chn_tilt_stop_all();
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
||||||
|
|
||||||
|
// If the channels are not IDLE yet, wait more
|
||||||
|
bool not_idle = false;
|
||||||
|
for (int i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
|
||||||
|
if (relay_chn_get_state(i) != RELAY_CHN_STATE_IDLE) {
|
||||||
|
not_idle = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (not_idle) {
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS));
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure the channel has had a 'last_run_cmd'
|
// Ensure the channel has had a 'last_run_cmd'
|
||||||
if (initial_cmd == RELAY_CHN_CMD_FORWARD) {
|
if (initial_cmd == RELAY_CHN_CMD_FORWARD) {
|
||||||
relay_chn_run_forward(chn_id);
|
relay_chn_run_forward_all();
|
||||||
} else { // Assuming initial_cmd is RELAY_CHN_CMD_REVERSE
|
} else { // Assuming initial_cmd is RELAY_CHN_CMD_REVERSE
|
||||||
relay_chn_run_reverse(chn_id);
|
relay_chn_run_reverse_all();
|
||||||
}
|
}
|
||||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS)); // Allow command to process
|
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS)); // Allow command to process
|
||||||
relay_chn_stop(chn_id); // Stop it to set last_run_cmd but return to FREE for next test
|
relay_chn_stop_all(); // Stop all to set last_run_cmd but return to FREE for next test
|
||||||
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
||||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_IDLE, relay_chn_get_state(chn_id));
|
|
||||||
|
check_all_channels_for_state(RELAY_CHN_STATE_IDLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TEST_CASE: Test transition from running forward to tilt forward
|
// TEST_CASE: Test transition from running forward to tilt forward
|
||||||
// Scenario: RELAY_CHN_STATE_FORWARD -> (relay_chn_tilt_forward) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_TILT_FORWARD
|
// Scenario: RELAY_CHN_STATE_FORWARD -> (relay_chn_tilt_forward) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_TILT_FORWARD
|
||||||
TEST_CASE("Run Forward to Tilt Forward transition with inertia", "[relay_chn][tilt][inertia]") {
|
TEST_CASE("Run Forward to Tilt Forward transition with inertia", "[relay_chn][tilt][inertia]") {
|
||||||
uint8_t ch = 0;
|
|
||||||
|
|
||||||
// Prepare channel by running forward first to set last_run_cmd
|
// Prepare channel by running forward first to set last_run_cmd
|
||||||
prepare_channel_for_tilt(ch, RELAY_CHN_CMD_FORWARD);
|
prepare_all_channels_for_tilt(RELAY_CHN_CMD_FORWARD);
|
||||||
|
|
||||||
// 1. Start in forward direction
|
// 1. Start in forward direction
|
||||||
relay_chn_run_forward(ch);
|
relay_chn_run_forward_all();
|
||||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
||||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_FORWARD, relay_chn_get_state(ch));
|
check_all_channels_for_state(RELAY_CHN_STATE_FORWARD);
|
||||||
|
|
||||||
// 2. Issue tilt forward command
|
// 2. Issue tilt forward command
|
||||||
relay_chn_tilt_forward(ch);
|
relay_chn_tilt_forward_all();
|
||||||
// After tilt command, it should immediately stop and then trigger inertia.
|
// After tilt command, it should immediately stop and then trigger inertia.
|
||||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
||||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_STOPPED, relay_chn_get_state(ch));
|
check_all_channels_for_state(RELAY_CHN_STATE_STOPPED);
|
||||||
|
|
||||||
// Wait for the inertia period (after which the tilt command will be dispatched)
|
// Wait for the inertia period (after which the tilt command will be dispatched)
|
||||||
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS));
|
||||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_FORWARD, relay_chn_get_state(ch));
|
check_all_channels_for_state(RELAY_CHN_STATE_TILT_FORWARD);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TEST_CASE: Test transition from running reverse to tilt reverse
|
// TEST_CASE: Test transition from running reverse to tilt reverse
|
||||||
// Scenario: RELAY_CHN_STATE_REVERSE -> (relay_chn_tilt_reverse) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_TILT_REVERSE
|
// Scenario: RELAY_CHN_STATE_REVERSE -> (relay_chn_tilt_reverse) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_TILT_REVERSE
|
||||||
TEST_CASE("Run Reverse to Tilt Reverse transition with inertia", "[relay_chn][tilt][inertia]") {
|
TEST_CASE("Run Reverse to Tilt Reverse transition with inertia", "[relay_chn][tilt][inertia]") {
|
||||||
uint8_t ch = 0;
|
|
||||||
|
|
||||||
// Prepare channel by running reverse first to set last_run_cmd
|
// Prepare channel by running reverse first to set last_run_cmd
|
||||||
prepare_channel_for_tilt(ch, RELAY_CHN_CMD_REVERSE);
|
prepare_all_channels_for_tilt(RELAY_CHN_CMD_REVERSE);
|
||||||
|
|
||||||
// 1. Start in reverse direction
|
// 1. Start in reverse direction
|
||||||
relay_chn_run_reverse(ch);
|
relay_chn_run_reverse_all();
|
||||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
||||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_REVERSE, relay_chn_get_state(ch));
|
check_all_channels_for_state(RELAY_CHN_STATE_REVERSE);
|
||||||
|
|
||||||
// 2. Issue tilt reverse command
|
// 2. Issue tilt reverse command
|
||||||
relay_chn_tilt_reverse(ch);
|
relay_chn_tilt_reverse_all();
|
||||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
||||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_STOPPED, relay_chn_get_state(ch));
|
check_all_channels_for_state(RELAY_CHN_STATE_STOPPED);
|
||||||
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
||||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_REVERSE, relay_chn_get_state(ch));
|
check_all_channels_for_state(RELAY_CHN_STATE_TILT_REVERSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TEST_CASE: Test transition from FREE state to tilt forward (now with preparation)
|
// TEST_CASE: Test transition from FREE state to tilt forward (now with preparation)
|
||||||
// Scenario: RELAY_CHN_STATE_IDLE -> (prepare) -> RELAY_CHN_STATE_IDLE -> (relay_chn_tilt_forward) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_TILT_FORWARD
|
// Scenario: RELAY_CHN_STATE_IDLE -> (prepare) -> RELAY_CHN_STATE_IDLE -> (relay_chn_tilt_forward) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_TILT_FORWARD
|
||||||
TEST_CASE("FREE to Tilt Forward transition with inertia (prepared)", "[relay_chn][tilt][inertia]") {
|
TEST_CASE("FREE to Tilt Forward transition with inertia (prepared)", "[relay_chn][tilt][inertia]") {
|
||||||
uint8_t ch = 0;
|
|
||||||
|
|
||||||
// Prepare channel by running forward first to set last_run_cmd
|
// Prepare channel by running forward first to set last_run_cmd
|
||||||
prepare_channel_for_tilt(ch, RELAY_CHN_CMD_FORWARD);
|
prepare_all_channels_for_tilt(RELAY_CHN_CMD_FORWARD);
|
||||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_IDLE, relay_chn_get_state(ch)); // Ensure we are back to FREE
|
|
||||||
|
|
||||||
// Issue tilt forward command
|
// Issue tilt forward command
|
||||||
relay_chn_tilt_forward(ch);
|
relay_chn_tilt_forward_all();
|
||||||
// From FREE state, tilt command should still incur the inertia due to the internal timer logic
|
// From FREE state, tilt command should still incur the inertia due to the internal timer logic
|
||||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
||||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_FORWARD, relay_chn_get_state(ch));
|
check_all_channels_for_state(RELAY_CHN_STATE_TILT_FORWARD);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TEST_CASE: Test transition from FREE state to tilt reverse (now with preparation)
|
// TEST_CASE: Test transition from FREE state to tilt reverse (now with preparation)
|
||||||
// Scenario: RELAY_CHN_STATE_IDLE -> (prepare) -> RELAY_CHN_STATE_IDLE -> (relay_chn_tilt_reverse) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_TILT_REVERSE
|
// Scenario: RELAY_CHN_STATE_IDLE -> (prepare) -> RELAY_CHN_STATE_IDLE -> (relay_chn_tilt_reverse) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_TILT_REVERSE
|
||||||
TEST_CASE("FREE to Tilt Reverse transition with inertia (prepared)", "[relay_chn][tilt][inertia]") {
|
TEST_CASE("FREE to Tilt Reverse transition with inertia (prepared)", "[relay_chn][tilt][inertia]") {
|
||||||
uint8_t ch = 0;
|
|
||||||
|
|
||||||
// Prepare channel by running reverse first to set last_run_cmd
|
// Prepare channel by running reverse first to set last_run_cmd
|
||||||
prepare_channel_for_tilt(ch, RELAY_CHN_CMD_REVERSE);
|
prepare_all_channels_for_tilt(RELAY_CHN_CMD_REVERSE);
|
||||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_IDLE, relay_chn_get_state(ch)); // Ensure we are back to FREE
|
|
||||||
|
|
||||||
// Issue tilt reverse command
|
// Issue tilt reverse command
|
||||||
relay_chn_tilt_reverse(ch);
|
relay_chn_tilt_reverse_all();
|
||||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
||||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_REVERSE, relay_chn_get_state(ch));
|
check_all_channels_for_state(RELAY_CHN_STATE_TILT_REVERSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TEST_CASE: Test transition from tilt forward to run forward (inertia expected for run)
|
// TEST_CASE: Test transition from tilt forward to run forward (inertia expected for run)
|
||||||
// Scenario: RELAY_CHN_STATE_TILT_FORWARD -> (relay_chn_run_forward) -> RELAY_CHN_STATE_FORWARD
|
// Scenario: RELAY_CHN_STATE_TILT_FORWARD -> (relay_chn_run_forward) -> RELAY_CHN_STATE_FORWARD
|
||||||
TEST_CASE("Tilt Forward to Run Forward transition with inertia", "[relay_chn][tilt][inertia]") {
|
TEST_CASE("Tilt Forward to Run Forward transition with inertia", "[relay_chn][tilt][inertia]") {
|
||||||
uint8_t ch = 0;
|
|
||||||
|
|
||||||
// Prepare channel by running forward first to set last_run_cmd, then tilt
|
// Prepare channel by running forward first to set last_run_cmd, then tilt
|
||||||
prepare_channel_for_tilt(ch, RELAY_CHN_CMD_FORWARD);
|
prepare_all_channels_for_tilt(RELAY_CHN_CMD_FORWARD);
|
||||||
relay_chn_tilt_forward(ch); // Go to tilt state
|
relay_chn_tilt_forward_all(); // Go to tilt state
|
||||||
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
||||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_FORWARD, relay_chn_get_state(ch));
|
check_all_channels_for_state(RELAY_CHN_STATE_TILT_FORWARD);
|
||||||
|
|
||||||
// 2. Issue run forward command
|
// 2. Issue run forward command
|
||||||
relay_chn_run_forward(ch);
|
relay_chn_run_forward_all();
|
||||||
// From Tilt to Run in the same logical name but in the opposite direction, inertia is expected.
|
// From Tilt to Run in the same logical name but in the opposite direction, inertia is expected.
|
||||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_FORWARD_PENDING, relay_chn_get_state(ch));
|
check_all_channels_for_state(RELAY_CHN_STATE_FORWARD_PENDING);
|
||||||
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
||||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_FORWARD, relay_chn_get_state(ch));
|
check_all_channels_for_state(RELAY_CHN_STATE_FORWARD);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TEST_CASE: Test transition from tilt reverse to run reverse (no inertia expected for run)
|
// TEST_CASE: Test transition from tilt reverse to run reverse (no inertia expected for run)
|
||||||
// Scenario: RELAY_CHN_STATE_TILT_REVERSE -> (relay_chn_run_reverse) -> RELAY_CHN_STATE_REVERSE
|
// Scenario: RELAY_CHN_STATE_TILT_REVERSE -> (relay_chn_run_reverse) -> RELAY_CHN_STATE_REVERSE
|
||||||
TEST_CASE("Tilt Reverse to Run Reverse transition with inertia", "[relay_chn][tilt][inertia]") {
|
TEST_CASE("Tilt Reverse to Run Reverse transition with inertia", "[relay_chn][tilt][inertia]") {
|
||||||
uint8_t ch = 0;
|
|
||||||
|
|
||||||
// Prepare channel by running reverse first to set last_run_cmd, then tilt
|
// Prepare channel by running reverse first to set last_run_cmd, then tilt
|
||||||
prepare_channel_for_tilt(ch, RELAY_CHN_CMD_REVERSE);
|
prepare_all_channels_for_tilt(RELAY_CHN_CMD_REVERSE);
|
||||||
relay_chn_tilt_reverse(ch); // Go to tilt state
|
relay_chn_tilt_reverse_all(); // Go to tilt state
|
||||||
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
||||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_REVERSE, relay_chn_get_state(ch));
|
check_all_channels_for_state(RELAY_CHN_STATE_TILT_REVERSE);
|
||||||
|
|
||||||
// 2. Issue run reverse command
|
// 2. Issue run reverse command
|
||||||
relay_chn_run_reverse(ch);
|
relay_chn_run_reverse_all();
|
||||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_REVERSE_PENDING, relay_chn_get_state(ch));
|
check_all_channels_for_state(RELAY_CHN_STATE_REVERSE_PENDING);
|
||||||
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
||||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_REVERSE, relay_chn_get_state(ch));
|
check_all_channels_for_state(RELAY_CHN_STATE_REVERSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TEST_CASE: Test transition from tilt forward to run reverse (without inertia)
|
// TEST_CASE: Test transition from tilt forward to run reverse (without inertia)
|
||||||
// Scenario: RELAY_CHN_STATE_TILT_FORWARD -> (relay_chn_run_reverse) -> RELAY_CHN_STATE_REVERSE
|
// Scenario: RELAY_CHN_STATE_TILT_FORWARD -> (relay_chn_run_reverse) -> RELAY_CHN_STATE_REVERSE
|
||||||
TEST_CASE("Tilt Forward to Run Reverse transition without inertia", "[relay_chn][tilt][inertia]") {
|
TEST_CASE("Tilt Forward to Run Reverse transition without inertia", "[relay_chn][tilt][inertia]") {
|
||||||
uint8_t ch = 0;
|
|
||||||
|
|
||||||
// Prepare channel by running forward first to set last_run_cmd, then tilt
|
// Prepare channel by running forward first to set last_run_cmd, then tilt
|
||||||
prepare_channel_for_tilt(ch, RELAY_CHN_CMD_FORWARD);
|
prepare_all_channels_for_tilt(RELAY_CHN_CMD_FORWARD);
|
||||||
relay_chn_tilt_forward(ch); // Go to tilt state
|
relay_chn_tilt_forward_all(); // Go to tilt state
|
||||||
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
||||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_FORWARD, relay_chn_get_state(ch));
|
check_all_channels_for_state(RELAY_CHN_STATE_TILT_FORWARD);
|
||||||
|
|
||||||
// 2. Issue run reverse command (opposite direction)
|
// 2. Issue run reverse command (opposite direction)
|
||||||
relay_chn_run_reverse(ch);
|
relay_chn_run_reverse_all();
|
||||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
||||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_REVERSE, relay_chn_get_state(ch));
|
check_all_channels_for_state(RELAY_CHN_STATE_REVERSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TEST_CASE: Test stopping from a tilt state (no inertia for stop command itself)
|
// TEST_CASE: Test stopping from a tilt state (no inertia for stop command itself)
|
||||||
// Scenario: RELAY_CHN_STATE_TILT_FORWARD -> (relay_chn_tilt_stop) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_IDLE
|
// Scenario: RELAY_CHN_STATE_TILT_FORWARD -> (relay_chn_tilt_stop) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_IDLE
|
||||||
TEST_CASE("Tilt to Stop transition without immediate inertia for stop", "[relay_chn][tilt][inertia]") {
|
TEST_CASE("Tilt to Stop transition without immediate inertia for stop", "[relay_chn][tilt][inertia]") {
|
||||||
uint8_t ch = 0;
|
// Prepare all channels by running forward first to set last_run_cmd, then tilt
|
||||||
|
prepare_all_channels_for_tilt(RELAY_CHN_CMD_FORWARD);
|
||||||
// Prepare channel by running forward first to set last_run_cmd, then tilt
|
relay_chn_tilt_forward_all(); // Go to tilt state
|
||||||
prepare_channel_for_tilt(ch, RELAY_CHN_CMD_FORWARD);
|
|
||||||
relay_chn_tilt_forward(ch); // Go to tilt state
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
||||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_FORWARD, relay_chn_get_state(ch));
|
// Verify all channels are tilting forward
|
||||||
|
check_all_channels_for_state(RELAY_CHN_STATE_TILT_FORWARD);
|
||||||
|
|
||||||
// 2. Issue stop command
|
// 2. Issue stop command
|
||||||
relay_chn_tilt_stop(ch);
|
relay_chn_tilt_stop_all();
|
||||||
// Stop command should apply immediately, setting state to FREE since last state was tilt.
|
// Stop command should apply immediately, setting state to FREE since last state was tilt.
|
||||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
||||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_IDLE, relay_chn_get_state(ch));
|
// Verify all channels are IDLE
|
||||||
|
check_all_channels_for_state(RELAY_CHN_STATE_IDLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ### Batch Tilt Control Tests
|
// ### Batch Tilt Control Tests
|
||||||
@@ -184,44 +210,34 @@ TEST_CASE("Tilt to Stop transition without immediate inertia for stop", "[relay_
|
|||||||
TEST_CASE("tilt_forward_all sets all channels to TILT_FORWARD", "[relay_chn][tilt][batch]")
|
TEST_CASE("tilt_forward_all sets all channels to TILT_FORWARD", "[relay_chn][tilt][batch]")
|
||||||
{
|
{
|
||||||
// 1. Prepare all channels.
|
// 1. Prepare all channels.
|
||||||
for (uint8_t i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
|
prepare_all_channels_for_tilt(RELAY_CHN_CMD_FORWARD);
|
||||||
prepare_channel_for_tilt(i, RELAY_CHN_CMD_FORWARD);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. Issue tilt forward to all channels
|
// 2. Issue tilt forward to all channels
|
||||||
relay_chn_tilt_forward_all();
|
relay_chn_tilt_forward_all();
|
||||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS)); // Tilt from FREE doesn't have stop-inertia
|
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS)); // Tilt from FREE doesn't have stop-inertia
|
||||||
|
|
||||||
// 3. Verify all channels are tilting forward
|
// 3. Verify all channels are tilting forward
|
||||||
for (uint8_t i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
|
check_all_channels_for_state(RELAY_CHN_STATE_TILT_FORWARD);
|
||||||
ESP_LOGI(TEST_TAG, "Checking channel %d", i);
|
|
||||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_FORWARD, relay_chn_get_state(i));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("tilt_reverse_all sets all channels to TILT_REVERSE", "[relay_chn][tilt][batch]")
|
TEST_CASE("tilt_reverse_all sets all channels to TILT_REVERSE", "[relay_chn][tilt][batch]")
|
||||||
{
|
{
|
||||||
// 1. Prepare all channels.
|
// 1. Prepare all channels.
|
||||||
for (uint8_t i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
|
prepare_all_channels_for_tilt(RELAY_CHN_CMD_REVERSE);
|
||||||
prepare_channel_for_tilt(i, RELAY_CHN_CMD_REVERSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. Issue tilt reverse to all channels
|
// 2. Issue tilt reverse to all channels
|
||||||
relay_chn_tilt_reverse_all();
|
relay_chn_tilt_reverse_all();
|
||||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
||||||
|
|
||||||
// 3. Verify all channels are tilting reverse
|
// 3. Verify all channels are tilting reverse
|
||||||
for (uint8_t i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
|
check_all_channels_for_state(RELAY_CHN_STATE_TILT_REVERSE);
|
||||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_REVERSE, relay_chn_get_state(i));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("tilt_stop_all stops all tilting channels", "[relay_chn][tilt][batch]")
|
TEST_CASE("tilt_stop_all stops all tilting channels", "[relay_chn][tilt][batch]")
|
||||||
{
|
{
|
||||||
// 1. Prepare and start all channels tilting forward
|
// 1. Prepare and start all channels tilting forward
|
||||||
for (uint8_t i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
|
prepare_all_channels_for_tilt(RELAY_CHN_CMD_FORWARD);
|
||||||
prepare_channel_for_tilt(i, RELAY_CHN_CMD_REVERSE);
|
|
||||||
}
|
|
||||||
relay_chn_tilt_forward_all();
|
relay_chn_tilt_forward_all();
|
||||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
||||||
|
|
||||||
@@ -230,10 +246,7 @@ TEST_CASE("tilt_stop_all stops all tilting channels", "[relay_chn][tilt][batch]"
|
|||||||
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
||||||
|
|
||||||
// 3. Verify all channels are free
|
// 3. Verify all channels are free
|
||||||
for (uint8_t i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
|
check_all_channels_for_state(RELAY_CHN_STATE_IDLE);
|
||||||
ESP_LOGI(TEST_TAG, "Checking channel %d", i);
|
|
||||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_IDLE, relay_chn_get_state(i));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("tilt_auto_all tilts channels based on last run direction", "[relay_chn][tilt][batch]")
|
TEST_CASE("tilt_auto_all tilts channels based on last run direction", "[relay_chn][tilt][batch]")
|
||||||
@@ -242,34 +255,39 @@ TEST_CASE("tilt_auto_all tilts channels based on last run direction", "[relay_ch
|
|||||||
TEST_ASSERT_GREATER_OR_EQUAL_MESSAGE(2, CONFIG_RELAY_CHN_COUNT, "Test requires at least 2 channels");
|
TEST_ASSERT_GREATER_OR_EQUAL_MESSAGE(2, CONFIG_RELAY_CHN_COUNT, "Test requires at least 2 channels");
|
||||||
|
|
||||||
// 1. Prepare channel 0 with last run FORWARD and channel 1 with last run REVERSE
|
// 1. Prepare channel 0 with last run FORWARD and channel 1 with last run REVERSE
|
||||||
prepare_channel_for_tilt(0, RELAY_CHN_CMD_FORWARD);
|
prepare_channels_for_tilt_with_mixed_runs(0, RELAY_CHN_CMD_FORWARD);
|
||||||
prepare_channel_for_tilt(1, RELAY_CHN_CMD_REVERSE);
|
|
||||||
|
|
||||||
// 2. Issue auto tilt command to all channels
|
// 2. Issue auto tilt command to all channels
|
||||||
relay_chn_tilt_auto_all();
|
relay_chn_tilt_auto_all();
|
||||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS)); // Tilt from FREE state is dispatched immediately
|
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS)); // Tilt from FREE state is dispatched immediately
|
||||||
|
|
||||||
// 3. Verify channel 0 tilts forward (last run was forward) and channel 1 tilts reverse (last run was reverse)
|
// 3. Verify even channels tilt forward (last run was forward) and odd channels tilt reverse (last run was reverse)
|
||||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_FORWARD, relay_chn_get_state(0));
|
for (int i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
|
||||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_REVERSE, relay_chn_get_state(1));
|
relay_chn_state_t state = i % 2 == 0 ?
|
||||||
|
RELAY_CHN_STATE_TILT_FORWARD : RELAY_CHN_STATE_TILT_REVERSE;
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL(state, relay_chn_get_state(i));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test relay_chn_tilt_auto() chooses correct tilt direction
|
// Test relay_chn_tilt_auto() chooses correct tilt direction
|
||||||
TEST_CASE("relay_chn_tilt_auto chooses correct direction", "[relay_chn][tilt][auto]") {
|
TEST_CASE("relay_chn_tilt_auto chooses correct direction", "[relay_chn][tilt][auto]") {
|
||||||
uint8_t ch = 0;
|
|
||||||
// Prepare FORWARD
|
// Prepare FORWARD
|
||||||
prepare_channel_for_tilt(ch, RELAY_CHN_CMD_FORWARD);
|
prepare_all_channels_for_tilt(RELAY_CHN_CMD_FORWARD);
|
||||||
relay_chn_tilt_auto(ch);
|
relay_chn_tilt_auto_all();
|
||||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
||||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_FORWARD, relay_chn_get_state(ch));
|
// Verify all tilt forward
|
||||||
relay_chn_tilt_stop(ch);
|
check_all_channels_for_state(RELAY_CHN_STATE_TILT_FORWARD);
|
||||||
|
|
||||||
|
relay_chn_tilt_stop_all();
|
||||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
||||||
|
|
||||||
// Prepare REVERSE
|
// Prepare REVERSE
|
||||||
prepare_channel_for_tilt(ch, RELAY_CHN_CMD_REVERSE);
|
prepare_all_channels_for_tilt(RELAY_CHN_CMD_REVERSE);
|
||||||
relay_chn_tilt_auto(ch);
|
relay_chn_tilt_auto_all();
|
||||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
||||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_REVERSE, relay_chn_get_state(ch));
|
// Verify all tilt reverse
|
||||||
|
check_all_channels_for_state(RELAY_CHN_STATE_TILT_REVERSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test sensitivity set/get
|
// Test sensitivity set/get
|
||||||
@@ -296,49 +314,47 @@ TEST_CASE("relay_chn_tilt_set_sensitivity and get", "[relay_chn][tilt][sensitivi
|
|||||||
|
|
||||||
// Test tilt counter logic: forward x3, reverse x3, extra reverse fails
|
// Test tilt counter logic: forward x3, reverse x3, extra reverse fails
|
||||||
TEST_CASE("tilt counter logic: forward and reverse consumption", "[relay_chn][tilt][counter]") {
|
TEST_CASE("tilt counter logic: forward and reverse consumption", "[relay_chn][tilt][counter]") {
|
||||||
uint8_t ch = 0;
|
|
||||||
prepare_channel_for_tilt(ch, RELAY_CHN_CMD_FORWARD);
|
// Tilt execution time at 100% sensitivity in milliseconds (10 + 90)
|
||||||
|
#define TEST_TILT_EXECUTION_TIME_MS 100
|
||||||
|
|
||||||
|
prepare_all_channels_for_tilt(RELAY_CHN_CMD_FORWARD);
|
||||||
|
relay_chn_tilt_set_sensitivity_all_with(100); // Set sentivity to max for fastest execution
|
||||||
|
|
||||||
// Tilt forward 3 times
|
// Tilt forward 3 times
|
||||||
for (int i = 0; i < 3; ++i) {
|
for (int i = 0; i < 3; ++i) {
|
||||||
relay_chn_tilt_forward(ch);
|
relay_chn_tilt_forward_all();
|
||||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
vTaskDelay(pdMS_TO_TICKS(TEST_TILT_EXECUTION_TIME_MS));
|
||||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_FORWARD, relay_chn_get_state(ch));
|
check_all_channels_for_state(RELAY_CHN_STATE_TILT_FORWARD);
|
||||||
relay_chn_tilt_stop(ch);
|
relay_chn_tilt_stop_all();
|
||||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
|
||||||
}
|
}
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
||||||
|
|
||||||
// Now tilt reverse 3 times (should succeed)
|
// Now tilt reverse 3 times (should succeed)
|
||||||
for (int i = 0; i < 3; ++i) {
|
for (int i = 0; i < 3; ++i) {
|
||||||
relay_chn_tilt_reverse(ch);
|
relay_chn_tilt_reverse_all();
|
||||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
vTaskDelay(pdMS_TO_TICKS(TEST_TILT_EXECUTION_TIME_MS));
|
||||||
if (i < 3) {
|
check_all_channels_for_state(RELAY_CHN_STATE_TILT_REVERSE);
|
||||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_REVERSE, relay_chn_get_state(ch));
|
relay_chn_tilt_stop_all();
|
||||||
relay_chn_tilt_stop(ch);
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extra reverse tilt should fail (counter exhausted)
|
// Extra reverse tilt should fail (counter exhausted)
|
||||||
relay_chn_tilt_reverse(ch);
|
relay_chn_tilt_reverse_all();
|
||||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
||||||
// Should not enter TILT_REVERSE, should remain FREE or STOPPED
|
// Should not enter TILT_REVERSE, should remain IDLE
|
||||||
relay_chn_state_t state = relay_chn_get_state(ch);
|
check_all_channels_for_state(RELAY_CHN_STATE_IDLE);
|
||||||
TEST_ASSERT(state != RELAY_CHN_STATE_TILT_REVERSE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test run command during TILT state
|
// Test run command during TILT state
|
||||||
TEST_CASE("run command during TILT state transitions correctly", "[relay_chn][tilt][run-during-tilt]") {
|
TEST_CASE("run command during TILT state transitions correctly", "[relay_chn][tilt][run-during-tilt]") {
|
||||||
uint8_t ch = 0;
|
prepare_all_channels_for_tilt(RELAY_CHN_CMD_FORWARD);
|
||||||
prepare_channel_for_tilt(ch, RELAY_CHN_CMD_FORWARD);
|
relay_chn_tilt_forward_all();
|
||||||
relay_chn_tilt_forward(ch);
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
||||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_FORWARD, relay_chn_get_state(ch));
|
check_all_channels_for_state(RELAY_CHN_STATE_TILT_FORWARD);
|
||||||
|
|
||||||
// Issue run reverse while in TILT_FORWARD
|
// Issue run reverse while in TILT_FORWARD
|
||||||
relay_chn_run_reverse(ch);
|
relay_chn_run_reverse_all();
|
||||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
||||||
// Should transition to REVERSE or REVERSE_PENDING depending on inertia logic
|
// Should transition to REVERSE
|
||||||
relay_chn_state_t state = relay_chn_get_state(ch);
|
check_all_channels_for_state(RELAY_CHN_STATE_REVERSE);
|
||||||
TEST_ASSERT(state == RELAY_CHN_STATE_REVERSE || state == RELAY_CHN_STATE_REVERSE_PENDING);
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user