the joys of UB or whatever that crap was
This commit is contained in:
parent
7aeb25e064
commit
15629abf19
@ -39,6 +39,7 @@ cfdp::SourceHandler::SourceHandler(SourceHandlerParams params, FsfwParams fsfwPa
|
|||||||
// Yeah, what am I supposed to do here? Can't throw an exception in the FSFW..
|
// Yeah, what am I supposed to do here? Can't throw an exception in the FSFW..
|
||||||
transactionParams.pduConf.seqNum.setWidth(cfdp::WidthInBytes::ONE_BYTE);
|
transactionParams.pduConf.seqNum.setWidth(cfdp::WidthInBytes::ONE_BYTE);
|
||||||
}
|
}
|
||||||
|
transactionParams.pduConf.seqNum.setValue(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
cfdp::SourceHandler::FsmResult& cfdp::SourceHandler::fsmNacked() {
|
cfdp::SourceHandler::FsmResult& cfdp::SourceHandler::fsmNacked() {
|
||||||
@ -190,7 +191,8 @@ ReturnValue_t cfdp::SourceHandler::transactionStart(PutRequest& putRequest, Remo
|
|||||||
}
|
}
|
||||||
// Only used for PDU forwarding, file is sent to file receiver regularly here.
|
// Only used for PDU forwarding, file is sent to file receiver regularly here.
|
||||||
transactionParams.pduConf.direction = Direction::TOWARDS_RECEIVER;
|
transactionParams.pduConf.direction = Direction::TOWARDS_RECEIVER;
|
||||||
transactionParams.id.seqNum.setValue(sourceParams.seqCountProvider.getAndIncrement());
|
transactionParams.pduConf.seqNum.setValue(sourceParams.seqCountProvider.getAndIncrement());
|
||||||
|
transactionParams.id.seqNum = transactionParams.pduConf.seqNum;
|
||||||
|
|
||||||
if (transactionParams.pduConf.mode == TransmissionMode::ACKNOWLEDGED) {
|
if (transactionParams.pduConf.mode == TransmissionMode::ACKNOWLEDGED) {
|
||||||
state = cfdp::CfdpState::BUSY_CLASS_2_ACKED;
|
state = cfdp::CfdpState::BUSY_CLASS_2_ACKED;
|
||||||
@ -210,6 +212,7 @@ ReturnValue_t cfdp::SourceHandler::transactionStart(PutRequest& putRequest, Remo
|
|||||||
transactionParams.checksumType = ChecksumType::CRC_32;
|
transactionParams.checksumType = ChecksumType::CRC_32;
|
||||||
}
|
}
|
||||||
transactionParams.fileSize.setFileSize(fileSize, transactionParams.pduConf.largeFile);
|
transactionParams.fileSize.setFileSize(fileSize, transactionParams.pduConf.largeFile);
|
||||||
|
transactionParams.progress = 0;
|
||||||
transactionParams.remoteCfg = cfg;
|
transactionParams.remoteCfg = cfg;
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
@ -252,9 +255,11 @@ ReturnValue_t cfdp::SourceHandler::prepareAndSendNextFileDataPdu(bool& noFileDat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
FileOpParams fileParams(transactionParams.sourceName.data(), readLen);
|
FileOpParams fileParams(transactionParams.sourceName.data(), readLen);
|
||||||
|
fileParams.offset = transactionParams.progress;
|
||||||
ReturnValue_t result =
|
ReturnValue_t result =
|
||||||
sourceParams.user.vfs.readFromFile(fileParams, fileBuf.data(), fileBuf.size());
|
sourceParams.user.vfs.readFromFile(fileParams, fileBuf.data(), fileBuf.size());
|
||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
|
addError(result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
auto fileDataInfo = FileDataInfo(offset, fileBuf.data(), readLen);
|
auto fileDataInfo = FileDataInfo(offset, fileBuf.data(), readLen);
|
||||||
@ -309,12 +314,13 @@ ReturnValue_t cfdp::SourceHandler::sendGenericPdu(const SerializeIF& pdu) {
|
|||||||
ReturnValue_t result =
|
ReturnValue_t result =
|
||||||
fsfwParams.tmStore->getFreeElement(&storeId, pdu.getSerializedSize(), &dataPtr);
|
fsfwParams.tmStore->getFreeElement(&storeId, pdu.getSerializedSize(), &dataPtr);
|
||||||
if (result != OK) {
|
if (result != OK) {
|
||||||
// TODO: Better error handling?
|
addError(result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
size_t serializedLen = 0;
|
size_t serializedLen = 0;
|
||||||
result = pdu.serializeBe(dataPtr, serializedLen, pdu.getSerializedSize());
|
result = pdu.serializeBe(dataPtr, serializedLen, pdu.getSerializedSize());
|
||||||
if (result != OK) {
|
if (result != OK) {
|
||||||
|
addError(result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
TmTcMessage tmMsg(storeId);
|
TmTcMessage tmMsg(storeId);
|
||||||
@ -345,3 +351,10 @@ ReturnValue_t cfdp::SourceHandler::reset() {
|
|||||||
cfdp::CfdpState cfdp::SourceHandler::getState() const { return state; }
|
cfdp::CfdpState cfdp::SourceHandler::getState() const { return state; }
|
||||||
|
|
||||||
cfdp::SourceHandler::TransactionStep cfdp::SourceHandler::getStep() const { return step; }
|
cfdp::SourceHandler::TransactionStep cfdp::SourceHandler::getStep() const { return step; }
|
||||||
|
|
||||||
|
void cfdp::SourceHandler::addError(ReturnValue_t error) {
|
||||||
|
if (errorIndex < fsmResult.errorCodes.size()) {
|
||||||
|
fsmResult.errorCodes[errorIndex] = error;
|
||||||
|
errorIndex++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -92,6 +92,7 @@ class SourceHandler {
|
|||||||
std::array<uint8_t, 4096> fileBuf{};
|
std::array<uint8_t, 4096> fileBuf{};
|
||||||
SourceHandlerParams sourceParams;
|
SourceHandlerParams sourceParams;
|
||||||
cfdp::FsfwParams fsfwParams;
|
cfdp::FsfwParams fsfwParams;
|
||||||
|
uint8_t errorIndex = 0;
|
||||||
FsmResult fsmResult;
|
FsmResult fsmResult;
|
||||||
|
|
||||||
FsmResult& fsmNacked();
|
FsmResult& fsmNacked();
|
||||||
@ -103,6 +104,7 @@ class SourceHandler {
|
|||||||
ReturnValue_t reset();
|
ReturnValue_t reset();
|
||||||
|
|
||||||
[[nodiscard]] ReturnValue_t sendGenericPdu(const SerializeIF& pdu);
|
[[nodiscard]] ReturnValue_t sendGenericPdu(const SerializeIF& pdu);
|
||||||
|
void addError(ReturnValue_t error);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace cfdp
|
} // namespace cfdp
|
||||||
|
@ -197,8 +197,8 @@ TEST_CASE("CFDP Source Handler", "[cfdp]") {
|
|||||||
TmTcMessage tmtcMessage;
|
TmTcMessage tmtcMessage;
|
||||||
const uint8_t* pduPtr;
|
const uint8_t* pduPtr;
|
||||||
FileDataInfo fdInfo;
|
FileDataInfo fdInfo;
|
||||||
auto accessor = onePduSentCheck(fsmResult, tmtcMessage, &pduPtr);
|
|
||||||
{
|
{
|
||||||
|
auto accessor = onePduSentCheck(fsmResult, tmtcMessage, &pduPtr);
|
||||||
FileDataReader fdReader(pduPtr, accessor.second.size(), fdInfo);
|
FileDataReader fdReader(pduPtr, accessor.second.size(), fdInfo);
|
||||||
// 10 byte PDU header, 4 byte offset, 255 byte file data
|
// 10 byte PDU header, 4 byte offset, 255 byte file data
|
||||||
CHECK(accessor.second.size() == 269);
|
CHECK(accessor.second.size() == 269);
|
||||||
@ -216,7 +216,7 @@ TEST_CASE("CFDP Source Handler", "[cfdp]") {
|
|||||||
|
|
||||||
// Check second file data PDU.
|
// Check second file data PDU.
|
||||||
fsmResult = sourceHandler.stateMachine();
|
fsmResult = sourceHandler.stateMachine();
|
||||||
accessor = onePduSentCheck(fsmResult, tmtcMessage, &pduPtr);
|
auto accessor = onePduSentCheck(fsmResult, tmtcMessage, &pduPtr);
|
||||||
FileDataReader fdReader(pduPtr, accessor.second.size(), fdInfo);
|
FileDataReader fdReader(pduPtr, accessor.second.size(), fdInfo);
|
||||||
// 10 byte PDU header, 4 byte offset, remaining file data (400 - 255 == 145).
|
// 10 byte PDU header, 4 byte offset, remaining file data (400 - 255 == 145).
|
||||||
CHECK(accessor.second.size() == 10 + 4 + largerFileData.size() - MAX_FILE_SEGMENT_SIZE);
|
CHECK(accessor.second.size() == 10 + 4 + largerFileData.size() - MAX_FILE_SEGMENT_SIZE);
|
||||||
|
@ -39,7 +39,8 @@ ReturnValue_t FilesystemMock::readFromFile(FileOpParams params, uint8_t **buffer
|
|||||||
if (readSize + readLen > maxSize) {
|
if (readSize + readLen > maxSize) {
|
||||||
return SerializeIF::STREAM_TOO_SHORT;
|
return SerializeIF::STREAM_TOO_SHORT;
|
||||||
}
|
}
|
||||||
std::copy(info.fileRaw.data() + params.offset, info.fileRaw.data() + readLen, *buffer);
|
std::copy(info.fileRaw.data() + params.offset, info.fileRaw.data() + params.offset + readLen,
|
||||||
|
*buffer);
|
||||||
*buffer += readLen;
|
*buffer += readLen;
|
||||||
readSize += readLen;
|
readSize += readLen;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user