Skip to content

Commit b02b54b

Browse files
Update CRC
1 parent 6b1671f commit b02b54b

4 files changed

Lines changed: 25 additions & 13 deletions

File tree

Svc/Ccsds/CfdpManager/cf_cfdp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ CFE_Status_t CF_CFDP_SendEof(CF_Transaction_t *txn)
449449
eof = &ph->int_header.eof;
450450

451451
eof->cc = CF_TxnStatus_To_ConditionCode(txn->history->txn_stat);
452-
eof->crc = txn->crc.result;
452+
eof->crc = txn->crc.getValue();
453453
eof->size = txn->fsize;
454454

455455
if (eof->cc != CF_CFDP_ConditionCode_NO_ERROR)
@@ -1894,7 +1894,7 @@ void CF_CFDP_SendEotPkt(CF_Transaction_t *txn)
18941894
EotPktPtr->Payload.peer_eid = txn->history->peer_eid;
18951895
EotPktPtr->Payload.seq_num = txn->history->seq_num;
18961896
EotPktPtr->Payload.fsize = txn->fsize;
1897-
EotPktPtr->Payload.crc_result = txn->crc.result;
1897+
EotPktPtr->Payload.crc_result = txn->crc.getValue();
18981898

18991899
/*
19001900
** Timestamp and send eod of transaction telemetry

Svc/Ccsds/CfdpManager/cf_cfdp_r.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,20 @@ void CF_CFDP_R2_Reset(CF_Transaction_t *txn)
8787
CFE_Status_t CF_CFDP_R_CheckCrc(CF_Transaction_t *txn, U32 expected_crc)
8888
{
8989
CFE_Status_t ret = CFE_SUCCESS;
90-
CF_CRC_Finalize(&txn->crc);
91-
if (txn->crc.result != expected_crc)
90+
U32 crc_result;
91+
92+
// The F' version does not have an equivelent finalize call as it
93+
// - Never stores a partial word internally
94+
// - Never needs to "flush" anything
95+
// - Always accounts for padding at update time
96+
// CF_CRC_Finalize(&txn->crc);
97+
crc_result = txn->crc.getValue();
98+
if (crc_result != expected_crc)
9299
{
93100
CFE_EVS_SendEvent(CF_CFDP_R_CRC_ERR_EID, CFE_EVS_EventType_ERROR,
94101
"CF R%d(%lu:%lu): CRC mismatch for R trans. got 0x%08lx expected 0x%08lx",
95102
(txn->state == CF_TxnState_R2), (unsigned long)txn->history->src_eid,
96-
(unsigned long)txn->history->seq_num, (unsigned long)txn->crc.result,
103+
(unsigned long)txn->history->seq_num, (unsigned long)crc_result,
97104
(unsigned long)expected_crc);
98105
++CF_AppData.hk.Payload.channel_hk[txn->chan_num].counters.fault.crc_mismatch;
99106
ret = CF_ERROR;
@@ -386,7 +393,7 @@ void CF_CFDP_R1_SubstateRecvFileData(CF_Transaction_t *txn, CF_Logical_PduBuffer
386393
if (ret == CFE_SUCCESS)
387394
{
388395
/* class 1 digests CRC */
389-
CF_CRC_Digest(&txn->crc, ph->int_header.fd.data_ptr, ph->int_header.fd.data_len);
396+
txn->crc.update(ph->int_header.fd.data_ptr, ph->int_header.fd.offset, ph->int_header.fd.data_len);
390397
}
391398
else
392399
{
@@ -631,7 +638,7 @@ CFE_Status_t CF_CFDP_R2_CalcCrcChunk(CF_Transaction_t *txn)
631638

632639
if (txn->state_data.receive.r2.rx_crc_calc_bytes == 0)
633640
{
634-
CF_CRC_Start(&txn->crc);
641+
txn->crc = CFDP::Checksum(0);
635642
}
636643

637644
while ((count_bytes < CF_AppData.config_table->rx_crc_calc_bytes_per_wakeup) &&
@@ -677,7 +684,7 @@ CFE_Status_t CF_CFDP_R2_CalcCrcChunk(CF_Transaction_t *txn)
677684
break;
678685
}
679686

680-
CF_CRC_Digest(&txn->crc, buf, read_size);
687+
txn->crc.update(buf, txn->state_data.receive.r2.rx_crc_calc_bytes, read_size);
681688
txn->state_data.receive.r2.rx_crc_calc_bytes += read_size;
682689
txn->state_data.receive.cached_pos = txn->state_data.receive.r2.rx_crc_calc_bytes;
683690
count_bytes += read_size;

Svc/Ccsds/CfdpManager/cf_cfdp_s.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ CFE_Status_t CF_CFDP_S_SendEof(CF_Transaction_t *txn)
4646
/* this is OK as we still need to put some value into the EOF */
4747
if (!txn->flags.com.crc_calc)
4848
{
49-
CF_CRC_Finalize(&txn->crc);
49+
// The F' version does not have an equivelent finalize call as it
50+
// - Never stores a partial word internally
51+
// - Never needs to "flush" anything
52+
// - Always accounts for padding at update time
53+
// CF_CRC_Finalize(&txn->crc);
5054
txn->flags.com.crc_calc = true;
5155
}
5256
return CF_CFDP_SendEof(txn);
@@ -189,7 +193,7 @@ CFE_Status_t CF_CFDP_S_SendFileData(CF_Transaction_t *txn, U32 foffs, U32 bytes_
189193
FW_ASSERT((foffs + actual_bytes) <= txn->fsize, foffs, actual_bytes, txn->fsize); /* sanity check */
190194
if (calc_crc)
191195
{
192-
CF_CRC_Digest(&txn->crc, fd->data_ptr, fd->data_len);
196+
txn->crc.update(fd->data_ptr, fd->offset, fd->data_len);
193197
}
194198

195199
ret = actual_bytes;
@@ -409,8 +413,7 @@ void CF_CFDP_S_SubstateSendMetadata(CF_Transaction_t *txn)
409413
CF_CFDP_FinishTransaction(txn, true);
410414
}
411415

412-
/* don't need CF_CRC_Start() since taken care of by reset_cfdp() */
413-
/*CF_CRC_Start(&txn->crc);*/
416+
/* don't need to reset the CRC since its taken care of by reset_cfdp() */
414417
}
415418

416419
/*----------------------------------------------------------------

Svc/Ccsds/CfdpManager/cf_cfdp_types.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
#include "cf_codec.hpp"
3838
#include "CfdpTimer.hpp"
3939

40+
#include <CFDP/Checksum/Checksum.hpp>
41+
#include <Os/File.hpp>
4042
#include <Os/Directory.hpp>
4143

4244
namespace Svc {
@@ -352,7 +354,7 @@ typedef struct CF_Transaction
352354
U32 foffs; /**< \brief offset into file for next read */
353355
Os::FileHandle fd;
354356

355-
CF_Crc_t crc;
357+
CFDP::Checksum crc;
356358

357359
U8 keep;
358360
U8 chan_num; /**< \brief if ever more than one engine, this may need to change to pointer */

0 commit comments

Comments
 (0)