Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/infuse/states.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ enum infuse_state {
INFUSE_STATE_DEVICE_STOPPED_MOVING = 7,
/* Suppress LED activity */
INFUSE_STATE_LED_SUPPRESS = 8,
/* Device is moving (not stationary) */
INFUSE_STATE_DEVICE_MOVING = 9,
/* Start of application-specific state range */
INFUSE_STATES_APP_START = 128,
INFUSE_STATES_END = UINT8_MAX
Expand Down
2 changes: 2 additions & 0 deletions subsys/algorithm_runner/algorithms/alg_stationary_windowed.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ void algorithm_stationary_windowed_fn(const struct zbus_channel *chan, const voi
* The timeout is included so that even if the IMU stops producing data, the
* state will get cleared.
*/
infuse_state_clear(INFUSE_STATE_DEVICE_MOVING);
if (!infuse_state_set_timeout(INFUSE_STATE_DEVICE_STATIONARY,
c->window_seconds + 10)) {
/* State was not previously set */
Expand All @@ -102,6 +103,7 @@ void algorithm_stationary_windowed_fn(const struct zbus_channel *chan, const voi
/* Stationary state was previously set */
infuse_state_set_timeout(INFUSE_STATE_DEVICE_STARTED_MOVING, 1);
}
infuse_state_set_timeout(INFUSE_STATE_DEVICE_MOVING, c->window_seconds + 10);
}

reset:
Expand Down
14 changes: 11 additions & 3 deletions tests/subsys/algorithm/algorithms/stationary_windowed/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,14 @@ ZTEST(alg_stationary, test_send)

/* Boot the IMU data generator */
imu_thread = task_schedule(0);
zassert_false(infuse_state_get(INFUSE_STATE_DEVICE_STATIONARY));
zassert_false(infuse_state_get(INFUSE_STATE_DEVICE_MOVING));
k_sleep(K_MINUTES(2));

/* 5 minutes, state should not be set */
/* 5 minutes, stationary state should not be set */
for (int i = 0; i < 5; i++) {
zassert_false(infuse_state_get(INFUSE_STATE_DEVICE_STATIONARY));
zassert_true(infuse_state_get(INFUSE_STATE_DEVICE_MOVING));
k_sleep(K_MINUTES(1));
}
zassert_equal(0, moving_count);
Expand All @@ -153,6 +157,7 @@ ZTEST(alg_stationary, test_send)
/* Stationary state should be set */
for (int i = 0; i < 5; i++) {
zassert_true(infuse_state_get(INFUSE_STATE_DEVICE_STATIONARY));
zassert_false(infuse_state_get(INFUSE_STATE_DEVICE_MOVING));
k_sleep(K_MINUTES(1));
}
zassert_equal(0, moving_count);
Expand Down Expand Up @@ -180,8 +185,10 @@ ZTEST(alg_stationary, test_send)
infuse_states_tick(states);
}
zassert_false(infuse_state_get(INFUSE_STATE_DEVICE_STATIONARY));
zassert_false(infuse_state_get(INFUSE_STATE_DEVICE_MOVING));
k_sleep(K_MINUTES(2));
zassert_true(infuse_state_get(INFUSE_STATE_DEVICE_STATIONARY));
zassert_false(infuse_state_get(INFUSE_STATE_DEVICE_MOVING));
zassert_equal(1, moving_count);
zassert_equal(2, stopped_count);

Expand All @@ -195,19 +202,20 @@ ZTEST(alg_stationary, test_send)
infuse_states_tick(states);
}
zassert_false(infuse_state_get(INFUSE_STATE_DEVICE_STATIONARY));
zassert_false(infuse_state_get(INFUSE_STATE_DEVICE_MOVING));

/* Stationary timing out shouldn't update the moving count */
zassert_equal(1, moving_count);
zassert_equal(2, stopped_count);

/* Flush the pending TDF's */
tdf_data_logger_flush(TDF_DATA_LOGGER_SERIAL);
expect_logging(11);
expect_logging(12);

/* Validate the last published data */
struct infuse_zbus_chan_movement_std_dev *out = ZBUS_CHAN->message;

zassert_equal(11, zbus_chan_pub_stats_count(ZBUS_CHAN));
zassert_equal(12, zbus_chan_pub_stats_count(ZBUS_CHAN));
zassert_within(7000, out->data.std_dev, 300);
zassert_equal(1200, out->data.count);
zassert_equal(1200, out->expected_samples);
Expand Down