Skip to content

Commit

Permalink
Merge pull request nasa#381 from skliper/fix380-no_delay_poll
Browse files Browse the repository at this point in the history
Fix nasa#380, Support polling with no delay
  • Loading branch information
dzbaker authored May 4, 2023
2 parents 930b0e5 + 9c85db0 commit 913b5fc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
6 changes: 1 addition & 5 deletions fsw/inc/cf_tbldefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@
*/
typedef struct CF_PollDir
{
uint32 interval_sec; /**<
* \brief number of seconds to wait before trying a new directory.
*
* Must be >0 or slot is inactive.
*/
uint32 interval_sec; /**< \brief number of seconds to wait before trying a new directory */

uint8 priority; /**< \brief priority to use when placing transactions on the pending queue */
CF_CFDP_Class_t cfdp_class; /**< \brief the CFDP class to send */
Expand Down
7 changes: 4 additions & 3 deletions fsw/src/cf_cfdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1510,12 +1510,11 @@ void CF_CFDP_ProcessPollingDirectories(CF_Channel_t *c)
pd = &cc->polldir[i];
count_check = 0;

if (pd->enabled && pd->interval_sec)
if (pd->enabled)
{
/* only handle polling for polldirs configured with a non-zero interval */
if (!p->pb.busy && !p->pb.num_ts)
{
if (!p->timer_set)
if (!p->timer_set && pd->interval_sec)
{
/* timer was not set, so set it now */
CF_Timer_InitRelSec(&p->interval_timer, pd->interval_sec);
Expand All @@ -1539,7 +1538,9 @@ void CF_CFDP_ProcessPollingDirectories(CF_Channel_t *c)
}
}
else
{
CF_Timer_Tick(&p->interval_timer);
}
}
else
{
Expand Down
16 changes: 9 additions & 7 deletions unit-test/cf_cfdp_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -1137,27 +1137,29 @@ void Test_CF_CFDP_ProcessPollingDirectories(void)
pdcfg = &config->chan[UT_CFDP_CHANNEL].polldir[0];
poll = &c->poll[0];

/* nominal call, w/engine disabled (noop) */
/* nominal call, polldir disabled (noop) */
UtAssert_VOIDCALL(CF_CFDP_ProcessPollingDirectories(c));
UtAssert_UINT32_EQ(CF_AppData.hk.channel_hk[UT_CFDP_CHANNEL].poll_counter, 0);

/* nominal call, w/engine enabled, polldir enabled but interval_sec == 0 */
CF_AppData.engine.enabled = 1;
pdcfg->enabled = 1;
/* nominal call, polldir enabled but interval_sec == 0 */
/* Will tick because CF_Timer_Expired stub returns 0 by default (not expired) */
pdcfg->enabled = 1;
UtAssert_VOIDCALL(CF_CFDP_ProcessPollingDirectories(c));
UtAssert_UINT32_EQ(CF_AppData.hk.channel_hk[UT_CFDP_CHANNEL].poll_counter, 0);
UtAssert_BOOL_FALSE(poll->timer_set);
UtAssert_UINT32_EQ(CF_AppData.hk.channel_hk[UT_CFDP_CHANNEL].poll_counter, 1);
UtAssert_STUB_COUNT(CF_Timer_Tick, 1);

/* with interval_sec nonzero the timer should get set, but not tick */
pdcfg->interval_sec = 1;
UtAssert_VOIDCALL(CF_CFDP_ProcessPollingDirectories(c));
UtAssert_BOOL_TRUE(poll->timer_set);
UtAssert_STUB_COUNT(CF_Timer_Tick, 0);
UtAssert_STUB_COUNT(CF_Timer_Tick, 1);
UtAssert_UINT32_EQ(CF_AppData.hk.channel_hk[UT_CFDP_CHANNEL].poll_counter, 1);

/* call again should tick */
UtAssert_VOIDCALL(CF_CFDP_ProcessPollingDirectories(c));
UtAssert_BOOL_TRUE(poll->timer_set);
UtAssert_STUB_COUNT(CF_Timer_Tick, 1);
UtAssert_STUB_COUNT(CF_Timer_Tick, 2);

/* call again timer should expire and start a playback */
UT_SetDeferredRetcode(UT_KEY(CF_Timer_Expired), 1, true);
Expand Down

0 comments on commit 913b5fc

Please sign in to comment.