CFDP SOURCE handler #157

Merged
muellerr merged 107 commits from cfdp-source-handler into develop 2023-10-19 10:59:55 +02:00
2 changed files with 48 additions and 11 deletions
Showing only changes of commit 9c8434d856 - Show all commits

View File

@ -29,6 +29,8 @@ cfdp::SourceHandler::SourceHandler(SourceHandlerParams params, FsfwParams fsfwPa
sif::error << "cfdp::SourceHandler: Seq count provider bit width "
<< sourceParams.seqCountProvider.bitWidth() << " not allowed" << std::endl;
#else
sif::printError("cfdp::SourceHandler: Seq count provider bit width %d not allowed\n",
sourceParams.seqCountProvider.bitWidth());
#endif
// Yeah, what am I supposed to do here? Can't throw an exception in the FSFW..
transactionParams.seqCountWidth = cfdp::WidthInBytes::ONE_BYTE;
@ -70,19 +72,23 @@ cfdp::SourceHandler::FsmResult& cfdp::SourceHandler::fsmNacked() {
if (result != OK) {
// TODO: Error handling
}
if (sourceParams.cfg.indicCfg.eofSentIndicRequired) {
sourceParams.user.eofSentIndication(transactionParams.id);
}
if (transactionParams.closureRequested) {
step = TransactionStep::WAIT_FOR_FINISH;
return fsmResult;
}
step = TransactionStep::NOTICE_OF_COMPLETION;
}
if (step == TransactionStep::WAIT_FOR_FINISH) {
// TODO: In case this is a request with closure, wait for finish.
// Done, issue notice of completion
step = TransactionStep::NOTICE_OF_COMPLETION;
}
if (step == TransactionStep::NOTICE_OF_COMPLETION) {
// TODO: Notice of completion
// We are done, go back to idle state.
// TODO: Possible reset state?
step = TransactionStep::IDLE;
state = CfdpState::IDLE;
noticeOfCompletion();
reset();
}
return fsmResult;
}
@ -98,6 +104,11 @@ cfdp::SourceHandler::FsmResult& cfdp::SourceHandler::stateMachine() {
}
ReturnValue_t cfdp::SourceHandler::checksumGeneration() {
if (transactionParams.fileSize.value() == 0) {
// NULL checksum for empty file.
transactionParams.crc = 0;
return OK;
}
std::array<uint8_t, 1024> buf{};
etl::crc32 crcCalc;
uint64_t currentOffset = 0;
@ -227,14 +238,13 @@ ReturnValue_t cfdp::SourceHandler::prepareAndSendNextFileDataPdu() {
}
ReturnValue_t cfdp::SourceHandler::prepareAndSendEofPdu() {
// TODO: Checksum
auto eofInfo = EofInfo(ConditionCode::NO_ERROR, 0, transactionParams.fileSize);
auto eofInfo =
EofInfo(ConditionCode::NO_ERROR, transactionParams.crc, transactionParams.fileSize);
auto eofPdu = EofPduCreator(transactionParams.pduConf, eofInfo);
ReturnValue_t result = sendGenericPdu(eofPdu);
if (result != OK) {
return result;
}
step = TransactionStep::WAIT_FOR_FINISH;
return OK;
}
@ -276,3 +286,20 @@ ReturnValue_t cfdp::SourceHandler::sendGenericPdu(const SerializeIF& pdu) const
TmTcMessage tcMsg(storeId);
return fsfwParams.msgQueue->sendMessage(fsfwParams.packetDest.getReportReceptionQueue(), &tcMsg);
}
ReturnValue_t cfdp::SourceHandler::noticeOfCompletion() {
if (sourceParams.cfg.indicCfg.transactionFinishedIndicRequired) {
cfdp::TransactionFinishedParams params(transactionParams.id, ConditionCode::NO_ERROR,
FileDeliveryCode::DATA_COMPLETE,
FileDeliveryStatus::RETAINED_IN_FILESTORE);
sourceParams.user.transactionFinishedIndication(params);
}
return OK;
}
ReturnValue_t cfdp::SourceHandler::reset() {
step = TransactionStep::IDLE;
state = cfdp::CfdpState::IDLE;
transactionParams.reset();
return OK;
}

View File

@ -73,8 +73,16 @@ class SourceHandler {
PduConfig pduConf;
cfdp::TransactionId id{};
cfdp::WidthInBytes seqCountWidth;
uint32_t seqNum = 0;
void reset() {
sourceNameSize = 0;
destNameSize = 0;
fileSize.setFileSize(0, false);
progress = 0;
closureRequested = false;
}
} transactionParams;
cfdp::CfdpState state = cfdp::CfdpState::IDLE;
TransactionStep step = TransactionStep::IDLE;
std::array<uint8_t, 4096> fileBuf{};
@ -87,8 +95,10 @@ class SourceHandler {
ReturnValue_t prepareAndSendMetadataPdu();
ReturnValue_t prepareAndSendNextFileDataPdu();
ReturnValue_t prepareAndSendEofPdu();
ReturnValue_t noticeOfCompletion();
ReturnValue_t reset();
ReturnValue_t sendGenericPdu(const SerializeIF& pdu) const;
[[nodiscard]] ReturnValue_t sendGenericPdu(const SerializeIF& pdu) const;
};
} // namespace cfdp