add printout capabilities

This commit is contained in:
Robin Müller 2022-09-14 14:00:20 +02:00
parent 4dadef34fd
commit 44615c150b
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
6 changed files with 43 additions and 16 deletions

View File

@ -7,6 +7,7 @@
#include "fsfw/cfdp/definitions.h" #include "fsfw/cfdp/definitions.h"
#include "fsfw/serialize/SerializeIF.h" #include "fsfw/serialize/SerializeIF.h"
#include "fsfw/serviceinterface.h"
#include "fsfw/util/UnsignedByteField.h" #include "fsfw/util/UnsignedByteField.h"
namespace cfdp { namespace cfdp {
@ -43,6 +44,14 @@ class VarLenField : public SerializeIF {
[[nodiscard]] cfdp::WidthInBytes getWidth() const; [[nodiscard]] cfdp::WidthInBytes getWidth() const;
[[nodiscard]] size_t getValue() const; [[nodiscard]] size_t getValue() const;
#if FSFW_CPP_OSTREAM_ENABLED == 1
friend std::ostream &operator<<(std::ostream &os, const VarLenField &id) {
os << "dec: " << id.getValue() << ", hex: " << std::hex << std::setw(id.getWidth())
<< std::setfill('0') << id.getValue() << std::dec << std::setfill('0');
return os;
}
#endif
private: private:
ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
Endianness streamEndianness) override; Endianness streamEndianness) override;
@ -83,6 +92,12 @@ struct TransactionId {
return entityId == other.entityId and seqNum == other.seqNum; return entityId == other.entityId and seqNum == other.seqNum;
} }
#if FSFW_CPP_OSTREAM_ENABLED == 1
friend std::ostream &operator<<(std::ostream &os, const TransactionId &id) {
os << "Source ID { " << id.entityId << " }, Sequence Number " << id.seqNum.getValue();
return os;
}
#endif
EntityId entityId; EntityId entityId;
TransactionSeqNum seqNum; TransactionSeqNum seqNum;
}; };

View File

@ -252,7 +252,8 @@ ReturnValue_t cfdp::DestHandler::handleMetadataParseError(ReturnValue_t result,
headerReader.getDestId(destId); headerReader.getDestId(destId);
RemoteEntityCfg* remoteCfg; RemoteEntityCfg* remoteCfg;
if (not dp.remoteCfgTable.getRemoteCfg(destId, &remoteCfg)) { if (not dp.remoteCfgTable.getRemoteCfg(destId, &remoteCfg)) {
// TODO: No remote config for dest ID. I consider this a configuration error. // TODO: No remote config for dest ID. I consider this a configuration error, which is not
// covered by the standard.
// Warning or error, yield or cache appropriate returnvalue // Warning or error, yield or cache appropriate returnvalue
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "No remote config exists for destination ID" << std::endl; sif::warning << "No remote config exists for destination ID" << std::endl;
@ -267,8 +268,9 @@ ReturnValue_t cfdp::DestHandler::handleMetadataParseError(ReturnValue_t result,
ReturnValue_t cfdp::DestHandler::startTransaction(MetadataPduReader& reader, MetadataInfo& info) { ReturnValue_t cfdp::DestHandler::startTransaction(MetadataPduReader& reader, MetadataInfo& info) {
if (fsmRes.state != CfdpStates::IDLE) { if (fsmRes.state != CfdpStates::IDLE) {
// According to standard, discard metadata PDU if we are busy // According to standard, discard metadata PDU if we are busy
return returnvalue::OK; return OK;
} }
ReturnValue_t result = OK;
fsmRes.step = TransactionStep::TRANSACTION_START; fsmRes.step = TransactionStep::TRANSACTION_START;
if (reader.getTransmissionMode() == TransmissionModes::UNACKNOWLEDGED) { if (reader.getTransmissionMode() == TransmissionModes::UNACKNOWLEDGED) {
fsmRes.state = CfdpStates::BUSY_CLASS_1_NACKED; fsmRes.state = CfdpStates::BUSY_CLASS_1_NACKED;
@ -302,10 +304,26 @@ ReturnValue_t cfdp::DestHandler::startTransaction(MetadataPduReader& reader, Met
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "cfdp::DestHandler" << __func__ sif::warning << "cfdp::DestHandler" << __func__
<< ": No remote configuration found for destination ID " << ": No remote configuration found for destination ID "
<< tp.pduConf.destId.getValue() << std::endl; << tp.pduConf.sourceId.getValue() << std::endl;
#endif #endif
return FAILED; return FAILED;
} }
// If both dest name size and source name size are 0, we are dealing with a metadata only PDU,
// so there is no need to create a file or truncate an existing file
if (destNameSize > 0 and sourceNameSize > 0) {
FilesystemParams fparams(tp.destName.data());
// TODO: Filesystem errors?
if (dp.user.vfs.fileExists(fparams)) {
dp.user.vfs.truncateFile(fparams);
} else {
result = dp.user.vfs.createFile(fparams);
if (result != OK) {
// TODO: Handle FS error. This is probably a case for the filestore rejection mechanism of
// CFDP.
// In any case, it does not really make sense to continue here
}
}
}
fsmRes.step = TransactionStep::RECEIVING_FILE_DATA_PDUS; fsmRes.step = TransactionStep::RECEIVING_FILE_DATA_PDUS;
MetadataRecvdParams params(tp.transactionId, tp.pduConf.sourceId); MetadataRecvdParams params(tp.transactionId, tp.pduConf.sourceId);
params.fileSize = tp.fileSize.getSize(); params.fileSize = tp.fileSize.getSize();
@ -313,15 +331,8 @@ ReturnValue_t cfdp::DestHandler::startTransaction(MetadataPduReader& reader, Met
params.sourceFileName = tp.sourceName.data(); params.sourceFileName = tp.sourceName.data();
params.msgsToUserArray = dynamic_cast<MessageToUserTlv*>(userTlvVec.data()); params.msgsToUserArray = dynamic_cast<MessageToUserTlv*>(userTlvVec.data());
params.msgsToUserLen = info.getOptionsLen(); params.msgsToUserLen = info.getOptionsLen();
FilesystemParams fparams(tp.destName.data());
// TODO: Filesystem errors?
if (dp.user.vfs.fileExists(fparams)) {
dp.user.vfs.truncateFile(fparams);
} else {
dp.user.vfs.createFile(fparams);
}
dp.user.metadataRecvdIndication(params); dp.user.metadataRecvdIndication(params);
return OK; return result;
} }
cfdp::CfdpStates cfdp::DestHandler::getCfdpState() const { return fsmRes.state; } cfdp::CfdpStates cfdp::DestHandler::getCfdpState() const { return fsmRes.state; }
@ -376,7 +387,8 @@ ReturnValue_t cfdp::DestHandler::checksumVerification() {
params.size = readLen; params.size = readLen;
auto result = dp.user.vfs.readFromFile(params, buf.data(), buf.size()); auto result = dp.user.vfs.readFromFile(params, buf.data(), buf.size());
if (result != OK) { if (result != OK) {
// TODO: Better error handling // TODO: I think this is a case for a filestore rejection, but it might sense to print
// a warning or trigger an event because this should generally not happen
return FAILED; return FAILED;
} }
crcCalc.add(buf.begin(), buf.begin() + readLen); crcCalc.add(buf.begin(), buf.begin() + readLen);
@ -391,7 +403,7 @@ ReturnValue_t cfdp::DestHandler::checksumVerification() {
} else { } else {
// TODO: Proper error handling // TODO: Proper error handling
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "CRC check for file " << tp.sourceName.data() << " failed" << std::endl; sif::warning << "CRC check for file " << tp.destName.data() << " failed" << std::endl;
#endif #endif
tp.conditionCode = ConditionCode::FILE_CHECKSUM_FAILURE; tp.conditionCode = ConditionCode::FILE_CHECKSUM_FAILURE;
} }

View File

@ -27,6 +27,7 @@ struct LocalEntityCfg {
}; };
struct RemoteEntityCfg { struct RemoteEntityCfg {
explicit RemoteEntityCfg(EntityId id) : remoteId(std::move(id)) {}
EntityId remoteId; EntityId remoteId;
size_t maxFileSegmentLen = 2048; size_t maxFileSegmentLen = 2048;
bool closureRequested = false; bool closureRequested = false;

View File

@ -3,7 +3,6 @@
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
#include <cinttypes> #include <cinttypes>
#include <cstring> #include <cstring>
#include "fsfw/serviceinterface/serviceInterfaceDefintions.h" #include "fsfw/serviceinterface/serviceInterfaceDefintions.h"

View File

@ -1,5 +1,5 @@
#include <stdio.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h>
void __attribute__((weak)) printChar(const char* character, bool errStream) { void __attribute__((weak)) printChar(const char* character, bool errStream) {
if (errStream) { if (errStream) {