Skip to content

CF_CFDP_ProcessPollingDirectories() can be simplified #467

@thnkslprpt

Description

@thnkslprpt

Checklist

  • I reviewed the Contributing Guide.
  • I performed a cursory search to see if the bug report is relevant, not redundant, nor in conflict with other tickets.

Describe the bug
count_check and ret are only used once, so they are unnecessary and can be removed.
chan_index and cc don't seem to get updated so can be initialized once instead of in every run through the loop.

Code snips

CF/fsw/src/cf_cfdp.c

Lines 1480 to 1541 in ba12bc1

void CF_CFDP_ProcessPollingDirectories(CF_Channel_t *chan)
{
CF_Poll_t * poll;
CF_ChannelConfig_t *cc;
CF_PollDir_t * pd;
int i;
int chan_index;
int count_check;
int ret;
for (i = 0; i < CF_MAX_POLLING_DIR_PER_CHAN; ++i)
{
poll = &chan->poll[i];
chan_index = (chan - CF_AppData.engine.channels);
cc = &CF_AppData.config_table->chan[chan_index];
pd = &cc->polldir[i];
count_check = 0;
if (pd->enabled)
{
if (!poll->pb.busy && !poll->pb.num_ts)
{
if (!poll->timer_set && pd->interval_sec)
{
/* timer was not set, so set it now */
CF_Timer_InitRelSec(&poll->interval_timer, pd->interval_sec);
poll->timer_set = 1;
}
else if (CF_Timer_Expired(&poll->interval_timer))
{
/* the timer has expired */
ret = CF_CFDP_PlaybackDir_Initiate(&poll->pb, pd->src_dir, pd->dst_dir, pd->cfdp_class, 0,
chan_index, pd->priority, pd->dest_eid);
if (!ret)
{
poll->timer_set = 0;
}
else
{
/* error occurred in playback directory, so reset the timer */
/* an event is sent in CF_CFDP_PlaybackDir_Initiate so there is no reason to
* to have another here */
CF_Timer_InitRelSec(&poll->interval_timer, pd->interval_sec);
}
}
else
{
CF_Timer_Tick(&poll->interval_timer);
}
}
else
{
/* playback is active, so step it */
CF_CFDP_ProcessPlaybackDirectory(chan, &poll->pb);
}
count_check = 1;
}
CF_CFDP_UpdatePollPbCounted(&poll->pb, count_check, &CF_AppData.hk.Payload.channel_hk[chan_index].poll_counter);
}
}

Expected behavior
Simplify where possible to improve clarify and ease future maintenance.

Reporter Info
Avi Weiss   @thnkslprpt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions