Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #265, change variable names to be more informative #332

Merged
merged 2 commits into from
Sep 29, 2023
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
583 changes: 292 additions & 291 deletions fsw/src/cf_cfdp.c

Large diffs are not rendered by default.

168 changes: 84 additions & 84 deletions fsw/src/cf_cfdp.h

Large diffs are not rendered by default.

62 changes: 32 additions & 30 deletions fsw/src/cf_cfdp_dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
* See description in cf_cfdp_dispatch.h for argument/return detail
*
*-----------------------------------------------------------------*/
void CF_CFDP_R_DispatchRecv(CF_Transaction_t *t, CF_Logical_PduBuffer_t *ph,
void CF_CFDP_R_DispatchRecv(CF_Transaction_t *txn, CF_Logical_PduBuffer_t *ph,

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
const CF_CFDP_R_SubstateDispatchTable_t *dispatch, CF_CFDP_StateRecvFunc_t fd_fn)
{
CF_Assert(t->state_data.r.sub_state < CF_RxSubState_NUM_STATES);
CF_Assert(txn->state_data.receive.sub_state < CF_RxSubState_NUM_STATES);
CF_CFDP_StateRecvFunc_t selected_handler;
CF_Logical_PduFileDirectiveHeader_t *fdh;

Expand All @@ -52,29 +52,30 @@
fdh = &ph->fdirective;
if (fdh->directive_code < CF_CFDP_FileDirective_INVALID_MAX)
{
if (dispatch->state[t->state_data.r.sub_state] != NULL)
if (dispatch->state[txn->state_data.receive.sub_state] != NULL)
{
selected_handler = dispatch->state[t->state_data.r.sub_state]->fdirective[fdh->directive_code];
selected_handler = dispatch->state[txn->state_data.receive.sub_state]->fdirective[fdh->directive_code];
}
}
else
{
++CF_AppData.hk.channel_hk[t->chan_num].counters.recv.spurious;
++CF_AppData.hk.channel_hk[txn->chan_num].counters.recv.spurious;
CFE_EVS_SendEvent(CF_EID_ERR_CFDP_R_DC_INV, CFE_EVS_EventType_ERROR,
"CF R%d(%lu:%lu): received PDU with invalid directive code %d for sub-state %d",
(t->state == CF_TxnState_R2), (unsigned long)t->history->src_eid,
(unsigned long)t->history->seq_num, fdh->directive_code, t->state_data.r.sub_state);
(txn->state == CF_TxnState_R2), (unsigned long)txn->history->src_eid,
(unsigned long)txn->history->seq_num, fdh->directive_code,
txn->state_data.receive.sub_state);
}
}
else
{
if (!CF_TxnStatus_IsError(t->history->txn_stat))
if (!CF_TxnStatus_IsError(txn->history->txn_stat))
{
selected_handler = fd_fn;
}
else
{
++CF_AppData.hk.channel_hk[t->chan_num].counters.recv.dropped;
++CF_AppData.hk.channel_hk[txn->chan_num].counters.recv.dropped;
}
}

Expand All @@ -84,7 +85,7 @@
*/
if (selected_handler != NULL)
{
selected_handler(t, ph);
selected_handler(txn, ph);

Check notice

Code scanning / CodeQL

Use of non-constant function pointer Note

This call does not go through a const function pointer.
}
}

Expand All @@ -94,10 +95,10 @@
* See description in cf_cfdp_dispatch.h for argument/return detail
*
*-----------------------------------------------------------------*/
void CF_CFDP_S_DispatchRecv(CF_Transaction_t *t, CF_Logical_PduBuffer_t *ph,
void CF_CFDP_S_DispatchRecv(CF_Transaction_t *txn, CF_Logical_PduBuffer_t *ph,

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
const CF_CFDP_S_SubstateRecvDispatchTable_t *dispatch)
{
CF_Assert(t->state_data.s.sub_state < CF_TxSubState_NUM_STATES);
CF_Assert(txn->state_data.send.sub_state < CF_TxSubState_NUM_STATES);
const CF_CFDP_FileDirectiveDispatchTable_t *substate_tbl;
CF_CFDP_StateRecvFunc_t selected_handler;
CF_Logical_PduFileDirectiveHeader_t * fdh;
Expand All @@ -110,26 +111,27 @@
if (fdh->directive_code < CF_CFDP_FileDirective_INVALID_MAX)
{
/* This should be silent (no event) if no handler is defined in the table */
substate_tbl = dispatch->substate[t->state_data.s.sub_state];
substate_tbl = dispatch->substate[txn->state_data.send.sub_state];
if (substate_tbl != NULL)
{
selected_handler = substate_tbl->fdirective[fdh->directive_code];
}
}
else
{
++CF_AppData.hk.channel_hk[t->chan_num].counters.recv.spurious;
++CF_AppData.hk.channel_hk[txn->chan_num].counters.recv.spurious;
CFE_EVS_SendEvent(CF_EID_ERR_CFDP_S_DC_INV, CFE_EVS_EventType_ERROR,
"CF S%d(%lu:%lu): received PDU with invalid directive code %d for sub-state %d",
(t->state == CF_TxnState_S2), (unsigned long)t->history->src_eid,
(unsigned long)t->history->seq_num, fdh->directive_code, t->state_data.s.sub_state);
(txn->state == CF_TxnState_S2), (unsigned long)txn->history->src_eid,
(unsigned long)txn->history->seq_num, fdh->directive_code,
txn->state_data.send.sub_state);
}
}
else
{
CFE_EVS_SendEvent(CF_EID_ERR_CFDP_S_NON_FD_PDU, CFE_EVS_EventType_ERROR,
"CF S%d(%lu:%lu): received non-file directive PDU", (t->state == CF_TxnState_S2),
(unsigned long)t->history->src_eid, (unsigned long)t->history->seq_num);
"CF S%d(%lu:%lu): received non-file directive PDU", (txn->state == CF_TxnState_S2),
(unsigned long)txn->history->src_eid, (unsigned long)txn->history->seq_num);
}

/* check that there's a valid function pointer. If there isn't,
Expand All @@ -140,7 +142,7 @@
* ignore the received packet and keep chugging along. */
if (selected_handler)
{
selected_handler(t, ph);
selected_handler(txn, ph);

Check notice

Code scanning / CodeQL

Use of non-constant function pointer Note

This call does not go through a const function pointer.
}
}

Expand All @@ -150,14 +152,14 @@
* See description in cf_cfdp_dispatch.h for argument/return detail
*
*-----------------------------------------------------------------*/
void CF_CFDP_S_DispatchTransmit(CF_Transaction_t *t, const CF_CFDP_S_SubstateSendDispatchTable_t *dispatch)
void CF_CFDP_S_DispatchTransmit(CF_Transaction_t *txn, const CF_CFDP_S_SubstateSendDispatchTable_t *dispatch)
{
CF_CFDP_StateSendFunc_t selected_handler;

selected_handler = dispatch->substate[t->state_data.s.sub_state];
selected_handler = dispatch->substate[txn->state_data.send.sub_state];
if (selected_handler != NULL)
{
selected_handler(t);
selected_handler(txn);
}
}

Expand All @@ -167,15 +169,15 @@
* See description in cf_cfdp_dispatch.h for argument/return detail
*
*-----------------------------------------------------------------*/
void CF_CFDP_TxStateDispatch(CF_Transaction_t *t, const CF_CFDP_TxnSendDispatchTable_t *dispatch)
void CF_CFDP_TxStateDispatch(CF_Transaction_t *txn, const CF_CFDP_TxnSendDispatchTable_t *dispatch)
{
CF_CFDP_StateSendFunc_t selected_handler;

CF_Assert(t->state < CF_TxnState_INVALID);
selected_handler = dispatch->tx[t->state];
CF_Assert(txn->state < CF_TxnState_INVALID);
selected_handler = dispatch->tx[txn->state];
if (selected_handler != NULL)
{
selected_handler(t);
selected_handler(txn);
}
}

Expand All @@ -185,15 +187,15 @@
* See description in cf_cfdp_dispatch.h for argument/return detail
*
*-----------------------------------------------------------------*/
void CF_CFDP_RxStateDispatch(CF_Transaction_t *t, CF_Logical_PduBuffer_t *ph,
void CF_CFDP_RxStateDispatch(CF_Transaction_t *txn, CF_Logical_PduBuffer_t *ph,

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
const CF_CFDP_TxnRecvDispatchTable_t *dispatch)
{
CF_CFDP_StateRecvFunc_t selected_handler;

CF_Assert(t->state < CF_TxnState_INVALID);
selected_handler = dispatch->rx[t->state];
CF_Assert(txn->state < CF_TxnState_INVALID);
selected_handler = dispatch->rx[txn->state];
if (selected_handler != NULL)
{
selected_handler(t, ph);
selected_handler(txn, ph);

Check notice

Code scanning / CodeQL

Use of non-constant function pointer Note

This call does not go through a const function pointer.
}
}
28 changes: 14 additions & 14 deletions fsw/src/cf_cfdp_dispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
* used on the transmit side, where a PDU will likely be generated/sent by the handler being
* invoked.
*
* @param[inout] t The transaction object
* @param[inout] txn The transaction object
*/
typedef void (*CF_CFDP_StateSendFunc_t)(CF_Transaction_t *t);
typedef void (*CF_CFDP_StateSendFunc_t)(CF_Transaction_t *txn);

Check notice

Code scanning / CodeQL

Hidden pointer indirection Note

The typedef CF_CFDP_StateSendFunc_t hides pointer indirection.

/**
* @brief A function for dispatching actions to a handler, with existing PDU data
Expand All @@ -47,10 +47,10 @@
* used on the receive side where a PDU buffer is associated with the activity, which is then
* interpreted by the handler being invoked.
*
* @param[inout] t The transaction object
* @param[inout] txn The transaction object
* @param[inout] ph The PDU buffer currently being received/processed
*/
typedef void (*CF_CFDP_StateRecvFunc_t)(CF_Transaction_t *t, CF_Logical_PduBuffer_t *ph);
typedef void (*CF_CFDP_StateRecvFunc_t)(CF_Transaction_t *txn, CF_Logical_PduBuffer_t *ph);

Check notice

Code scanning / CodeQL

Hidden pointer indirection Note

The typedef CF_CFDP_StateRecvFunc_t hides pointer indirection.

/**
* @brief A table of transmit handler functions based on transaction state
Expand Down Expand Up @@ -129,12 +129,12 @@
*
* Receive file transactions primarily only react/respond to received PDUs
*
* @param t Transaction
* @param txn Transaction
* @param ph PDU Buffer
* @param dispatch Dispatch table for file directive PDUs
* @param fd_fn Function to handle file data PDUs
*/
void CF_CFDP_R_DispatchRecv(CF_Transaction_t *t, CF_Logical_PduBuffer_t *ph,
void CF_CFDP_R_DispatchRecv(CF_Transaction_t *txn, CF_Logical_PduBuffer_t *ph,
const CF_CFDP_R_SubstateDispatchTable_t *dispatch, CF_CFDP_StateRecvFunc_t fd_fn);

/************************************************************************/
Expand All @@ -144,11 +144,11 @@
* Send file transactions also react/respond to received PDUs. Note that
* a file data PDU is not expected here.
*
* @param t Transaction
* @param txn Transaction
* @param ph PDU Buffer
* @param dispatch Dispatch table for file directive PDUs
*/
void CF_CFDP_S_DispatchRecv(CF_Transaction_t *t, CF_Logical_PduBuffer_t *ph,
void CF_CFDP_S_DispatchRecv(CF_Transaction_t *txn, CF_Logical_PduBuffer_t *ph,
const CF_CFDP_S_SubstateRecvDispatchTable_t *dispatch);

/************************************************************************/
Expand All @@ -160,10 +160,10 @@
* This does not have an existing PDU buffer at the time of dispatch, but one may
* be generated by the invoked function.
*
* @param t Transaction
* @param txn Transaction
* @param dispatch State-based dispatch table
*/
void CF_CFDP_S_DispatchTransmit(CF_Transaction_t *t, const CF_CFDP_S_SubstateSendDispatchTable_t *dispatch);
void CF_CFDP_S_DispatchTransmit(CF_Transaction_t *txn, const CF_CFDP_S_SubstateSendDispatchTable_t *dispatch);

/************************************************************************/
/**
Expand All @@ -172,20 +172,20 @@
* This does not have an existing PDU buffer at the time of dispatch, but one may
* be generated by the invoked function.
*
* @param t Transaction
* @param txn Transaction
* @param dispatch Transaction State-based Dispatch table
*/
void CF_CFDP_TxStateDispatch(CF_Transaction_t *t, const CF_CFDP_TxnSendDispatchTable_t *dispatch);
void CF_CFDP_TxStateDispatch(CF_Transaction_t *txn, const CF_CFDP_TxnSendDispatchTable_t *dispatch);

/************************************************************************/
/**
* @brief Top-level Dispatch function receive a PDU based on current state of a transaction
*
* @param t Transaction
* @param txn Transaction
* @param ph Received PDU Buffer
* @param dispatch Transaction State-based Dispatch table
*/
void CF_CFDP_RxStateDispatch(CF_Transaction_t *t, CF_Logical_PduBuffer_t *ph,
void CF_CFDP_RxStateDispatch(CF_Transaction_t *txn, CF_Logical_PduBuffer_t *ph,
const CF_CFDP_TxnRecvDispatchTable_t *dispatch);

#endif /* CF_CFDP_DISPATCH_H */
Loading