Compare commits

..

13 Commits

Author SHA1 Message Date
5ff28ff562 remove newline
Some checks are pending
fsfw/fsfw/pipeline/pr-development Build queued...
fsfw/fsfw/pipeline/head This commit looks good
2022-08-30 16:04:20 +02:00
fcdb90ff0a Merge branch 'mueller/data-wrapper' into mueller/dhb-handle-device-tm
All checks were successful
fsfw/fsfw/pipeline/pr-development This commit looks good
2022-08-30 16:03:15 +02:00
8d1777fa0c additional tests
All checks were successful
fsfw/fsfw/pipeline/pr-development This commit looks good
2022-08-30 16:02:50 +02:00
e10e71cee9 Merge branch 'mueller/data-wrapper' into mueller/dhb-handle-device-tm
All checks were successful
fsfw/fsfw/pipeline/pr-development This commit looks good
2022-08-30 14:42:13 +02:00
d675a789a2 update changelog
All checks were successful
fsfw/fsfw/pipeline/pr-development This commit looks good
2022-08-30 14:41:37 +02:00
6b8c83be29 update changelog
All checks were successful
fsfw/fsfw/pipeline/pr-development This commit looks good
2022-08-30 14:40:02 +02:00
093052604a Merge branch 'mueller/data-wrapper' into mueller/dhb-handle-device-tm
All checks were successful
fsfw/fsfw/pipeline/pr-development This commit looks good
2022-08-30 14:03:45 +02:00
192255df1c additional test
All checks were successful
fsfw/fsfw/pipeline/pr-development This commit looks good
2022-08-30 14:03:33 +02:00
bdd79d060d basic data wrapper unittests
All checks were successful
fsfw/fsfw/pipeline/pr-development This commit looks good
2022-08-30 14:02:58 +02:00
c756297e5c data wrapper update
All checks were successful
fsfw/fsfw/pipeline/pr-development This commit looks good
2022-08-30 13:39:44 +02:00
3a47062f2a refactored dhb TM handler
Some checks are pending
fsfw/fsfw/pipeline/head Build started...
fsfw/fsfw/pipeline/pr-development This commit looks good
2022-08-30 13:39:21 +02:00
0f27c7e7e7 extend data wrapper
All checks were successful
fsfw/fsfw/pipeline/pr-development This commit looks good
2022-08-30 13:24:29 +02:00
20d42add03 add new data wrapper helper type
Some checks are pending
fsfw/fsfw/pipeline/head Build started...
fsfw/fsfw/pipeline/pr-development This commit looks good
2022-08-30 12:07:09 +02:00
23 changed files with 290 additions and 135 deletions

View File

@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
# [unreleased]
# [v6.0.0]
## Changes
- Removed `HasReturnvaluesIF` class in favor of `returnvalue` namespace with `OK` and `FAILED`
@ -16,6 +18,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## Added
- DHB TM handler `handleDeviceTM` renamed to `handleDeviceTm` and now takes
`util::DataWrapper` as the data input argument. This allows more flexibility in the possible
types of telemetry.
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/669
- Add `util::DataWrapper` class inside the `util` module. This is a tagged union which allows
to specify raw data either as a classic C-style raw pointer and size or as a `SerializeIF`
pointer.
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/668
- Add new `UnsignedByteField` class
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/660

View File

@ -360,7 +360,7 @@ if(NOT FSFW_CONFIG_PATH)
if(NOT FSFW_BUILD_DOCS)
message(
WARNING
"${MSG_PREFIX} Flight Software Framework configuration path FSFW_CONFIG_PATH not set")
"${MSG_PREFIX} Flight Software Framework configuration path not set")
message(
WARNING
"${MSG_PREFIX} Setting default configuration from ${DEF_CONF_PATH} ..")

View File

@ -8,7 +8,6 @@
#include "fsfw/ipc/MessageQueueMessage.h"
#include "fsfw/ipc/QueueFactory.h"
#include "fsfw/objectmanager/ObjectManager.h"
#include "fsfw/serialize/SerialBufferAdapter.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "fsfw/storagemanager/StorageManagerIF.h"
#include "fsfw/subsystem/SubsystemBase.h"
@ -1258,32 +1257,40 @@ ReturnValue_t DeviceHandlerBase::letChildHandleMessage(CommandMessage* message)
return returnvalue::FAILED;
}
void DeviceHandlerBase::handleDeviceTm(const uint8_t* rawData, size_t rawDataLen,
DeviceCommandId_t replyId, bool forceDirectTm) {
SerialBufferAdapter bufferWrapper(rawData, rawDataLen);
handleDeviceTm(bufferWrapper, replyId, forceDirectTm);
}
void DeviceHandlerBase::handleDeviceTm(const SerializeIF& dataSet, DeviceCommandId_t replyId,
void DeviceHandlerBase::handleDeviceTm(util::DataWrapper dataWrapper, DeviceCommandId_t replyId,
bool forceDirectTm) {
if (dataWrapper.isNull()) {
return;
}
auto iter = deviceReplyMap.find(replyId);
if (iter == deviceReplyMap.end()) {
triggerEvent(DEVICE_UNKNOWN_REPLY, replyId);
return;
}
auto reportData = [&](MessageQueueId_t queueId) {
if (dataWrapper.type == util::DataTypes::SERIALIZABLE) {
return actionHelper.reportData(queueId, replyId, dataWrapper.dataUnion.serializable);
} else if (dataWrapper.type == util::DataTypes::RAW) {
return actionHelper.reportData(queueId, replyId, dataWrapper.dataUnion.raw.data,
dataWrapper.dataUnion.raw.len);
}
return returnvalue::FAILED;
};
// Regular replies to a command
if (iter->second.command != deviceCommandMap.end()) {
MessageQueueId_t queueId = iter->second.command->second.sendReplyTo;
// This may fail, but we'll ignore the fault.
if (queueId != NO_COMMANDER) {
// This may fail, but we'll ignore the fault.
actionHelper.reportData(queueId, replyId, const_cast<SerializeIF*>(&dataSet));
reportData(queueId);
}
// This check should make sure we get any TM but don't get anything doubled.
if (wiretappingMode == TM && (requestedRawTraffic != queueId)) {
DeviceTmReportingWrapper wrapper(getObjectId(), replyId, dataSet);
DeviceTmReportingWrapper wrapper(getObjectId(), replyId, dataWrapper);
actionHelper.reportData(requestedRawTraffic, replyId, &wrapper);
}
@ -1292,13 +1299,12 @@ void DeviceHandlerBase::handleDeviceTm(const SerializeIF& dataSet, DeviceCommand
// hiding of sender needed so the service will handle it as
// unexpected Data, no matter what state (progress or completed)
// it is in
actionHelper.reportData(defaultRawReceiver, replyId, const_cast<SerializeIF*>(&dataSet),
true);
reportData(defaultRawReceiver);
}
}
// Unrequested or aperiodic replies
else {
DeviceTmReportingWrapper wrapper(getObjectId(), replyId, dataSet);
DeviceTmReportingWrapper wrapper(getObjectId(), replyId, dataWrapper);
if (wiretappingMode == TM) {
actionHelper.reportData(requestedRawTraffic, replyId, &wrapper);
}
@ -1323,10 +1329,10 @@ ReturnValue_t DeviceHandlerBase::executeAction(ActionId_t actionId, MessageQueue
} else if (iter->second.isExecuting) {
result = COMMAND_ALREADY_SENT;
} else {
iter->second.sendReplyTo = commandedBy;
result = buildCommandFromCommand(actionId, data, size);
}
if (result == returnvalue::OK) {
iter->second.sendReplyTo = commandedBy;
iter->second.isExecuting = true;
cookieInfo.pendingCommand = iter;
cookieInfo.state = COOKIE_WRITE_READY;

View File

@ -23,6 +23,7 @@
#include "fsfw/serviceinterface/serviceInterfaceDefintions.h"
#include "fsfw/tasks/ExecutableObjectIF.h"
#include "fsfw/tasks/PeriodicTaskIF.h"
#include "fsfw/util/dataWrapper.h"
namespace Factory {
void setStaticFrameworkObjectIds();
@ -1052,24 +1053,7 @@ class DeviceHandlerBase : public DeviceHandlerIF,
bool isAwaitingReply();
/**
* Wrapper function for @handleDeviceTm which wraps the raw buffer with @SerialBufferAdapter.
* For interpreted data, prefer the other function.
* @param rawData
* @param rawDataLen
* @param replyId
* @param forceDirectTm
*/
void handleDeviceTm(const uint8_t *rawData, size_t rawDataLen, DeviceCommandId_t replyId,
bool forceDirectTm = false);
/**
* Can be used to handle Service 8 data replies. This will also generate the TM wiretapping
* packets accordingly.
* @param dataSet
* @param replyId
* @param forceDirectTm
*/
void handleDeviceTm(const SerializeIF &dataSet, DeviceCommandId_t replyId,
void handleDeviceTm(util::DataWrapper dataWrapper, DeviceCommandId_t replyId,
bool forceDirectTm = false);
virtual ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode,

View File

@ -3,8 +3,8 @@
#include "fsfw/serialize/SerializeAdapter.h"
DeviceTmReportingWrapper::DeviceTmReportingWrapper(object_id_t objectId, ActionId_t actionId,
const SerializeIF& data)
: objectId(objectId), actionId(actionId), data(data) {}
util::DataWrapper data)
: objectId(objectId), actionId(actionId), dataWrapper(data) {}
DeviceTmReportingWrapper::~DeviceTmReportingWrapper() = default;
@ -19,11 +19,24 @@ ReturnValue_t DeviceTmReportingWrapper::serialize(uint8_t** buffer, size_t* size
if (result != returnvalue::OK) {
return result;
}
return data.serialize(buffer, size, maxSize, streamEndianness);
if (dataWrapper.isNull()) {
return returnvalue::FAILED;
}
if (dataWrapper.type == util::DataTypes::SERIALIZABLE) {
return dataWrapper.dataUnion.serializable->serialize(buffer, size, maxSize, streamEndianness);
} else if (dataWrapper.type == util::DataTypes::RAW) {
if (*size + dataWrapper.dataUnion.raw.len > maxSize) {
return SerializeIF::BUFFER_TOO_SHORT;
}
std::memcpy(*buffer, dataWrapper.dataUnion.raw.data, dataWrapper.dataUnion.raw.len);
*buffer += dataWrapper.dataUnion.raw.len;
*size += dataWrapper.dataUnion.raw.len;
}
return returnvalue::OK;
}
size_t DeviceTmReportingWrapper::getSerializedSize() const {
return sizeof(objectId) + sizeof(ActionId_t) + data.getSerializedSize();
return sizeof(objectId) + sizeof(ActionId_t) + dataWrapper.getLength();
}
ReturnValue_t DeviceTmReportingWrapper::deSerialize(const uint8_t** buffer, size_t* size,

View File

@ -1,13 +1,14 @@
#ifndef FSFW_DEVICEHANDLERS_DEVICETMREPORTINGWRAPPER_H_
#define FSFW_DEVICEHANDLERS_DEVICETMREPORTINGWRAPPER_H_
#include "../action/HasActionsIF.h"
#include "../objectmanager/SystemObjectIF.h"
#include "../serialize/SerializeIF.h"
#include "fsfw/action/HasActionsIF.h"
#include "fsfw/objectmanager/SystemObjectIF.h"
#include "fsfw/serialize/SerializeIF.h"
#include "fsfw/util/dataWrapper.h"
class DeviceTmReportingWrapper : public SerializeIF {
public:
DeviceTmReportingWrapper(object_id_t objectId, ActionId_t actionId, const SerializeIF& data);
DeviceTmReportingWrapper(object_id_t objectId, ActionId_t actionId, util::DataWrapper data);
~DeviceTmReportingWrapper() override;
ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
@ -18,7 +19,7 @@ class DeviceTmReportingWrapper : public SerializeIF {
private:
object_id_t objectId;
ActionId_t actionId;
const SerializeIF& data;
util::DataWrapper dataWrapper;
// Deserialization forbidden
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,

View File

@ -4,6 +4,8 @@
#include <stdint.h>
#include "fwSubsystemIdRanges.h"
// could be moved to more suitable location
#include <events/subsystemIdRanges.h>
using EventId_t = uint16_t;
using EventSeverity_t = uint8_t;

View File

@ -161,7 +161,7 @@ void TcpTmTcServer::handleServerOperation(socket_t& connSocket) {
while (true) {
ssize_t retval = recv(connSocket, reinterpret_cast<char*>(receptionBuffer.data()),
receptionBuffer.size(), tcpConfig.tcpFlags);
receptionBuffer.capacity(), tcpConfig.tcpFlags);
if (retval == 0) {
size_t availableReadData = ringBuffer.getAvailableReadData();
if (availableReadData > lastRingBufferSize) {
@ -335,27 +335,31 @@ ReturnValue_t TcpTmTcServer::handleTcRingBufferData(size_t availableReadData) {
}
ringBuffer.readData(receptionBuffer.data(), readAmount, true);
const uint8_t* bufPtr = receptionBuffer.data();
SpacePacketParser::FoundPacketInfo info;
if (spacePacketParser == nullptr) {
return returnvalue::FAILED;
}
spacePacketParser->reset();
while (spacePacketParser->getAmountRead() < readAmount) {
result = spacePacketParser->parseSpacePackets(&bufPtr, readAmount, info);
const uint8_t** bufPtrPtr = &bufPtr;
size_t startIdx = 0;
size_t foundSize = 0;
size_t readLen = 0;
while (readLen < readAmount) {
if (spacePacketParser == nullptr) {
return returnvalue::FAILED;
}
result =
spacePacketParser->parseSpacePackets(bufPtrPtr, readAmount, startIdx, foundSize, readLen);
switch (result) {
case (SpacePacketParser::NO_PACKET_FOUND):
case (SpacePacketParser::SPLIT_PACKET): {
break;
}
case (returnvalue::OK): {
result = handleTcReception(receptionBuffer.data() + info.startIdx, info.sizeFound);
result = handleTcReception(receptionBuffer.data() + startIdx, foundSize);
if (result != returnvalue::OK) {
status = result;
}
}
}
ringBuffer.deleteData(info.sizeFound);
ringBuffer.deleteData(foundSize);
lastRingBufferSize = ringBuffer.getAvailableReadData();
std::memset(receptionBuffer.data() + startIdx, 0, foundSize);
}
return status;
}

View File

@ -38,9 +38,8 @@ class Service11TelecommandScheduling final : public PusServiceBase {
static constexpr uint8_t CLASS_ID = CLASS_ID::PUS_SERVICE_11;
static constexpr ReturnValue_t INVALID_TYPE_TIME_WINDOW = returnvalue::makeCode(CLASS_ID, 1);
static constexpr ReturnValue_t INVALID_TIME_WINDOW = returnvalue::makeCode(CLASS_ID, 2);
static constexpr ReturnValue_t TIMESHIFTING_NOT_POSSIBLE = returnvalue::makeCode(CLASS_ID, 3);
static constexpr ReturnValue_t INVALID_RELATIVE_TIME = returnvalue::makeCode(CLASS_ID, 4);
static constexpr ReturnValue_t TIMESHIFTING_NOT_POSSIBLE = returnvalue::makeCode(CLASS_ID, 2);
static constexpr ReturnValue_t INVALID_RELATIVE_TIME = returnvalue::makeCode(CLASS_ID, 3);
static constexpr uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PUS_SERVICE_11;

View File

@ -571,17 +571,12 @@ inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::getMapFilterFr
if (result != returnvalue::OK) {
return result;
}
if(fromTimestamp > toTimestamp) {
return INVALID_TIME_WINDOW;
}
itBegin = telecommandMap.begin();
itEnd = telecommandMap.begin();
while (itBegin->first < fromTimestamp && itBegin != telecommandMap.end()) {
itBegin++;
}
//start looking for end beginning at begin
itEnd = itBegin;
while (itEnd->first <= toTimestamp && itEnd != telecommandMap.end()) {
itEnd++;
}
@ -591,6 +586,17 @@ inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::getMapFilterFr
default:
return returnvalue::FAILED;
}
// additional security check, this should never be true
if (itBegin > itEnd) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "11::getMapFilterFromData: itBegin > itEnd\n" << std::endl;
#else
sif::printError("11::getMapFilterFromData: itBegin > itEnd\n");
#endif
return returnvalue::FAILED;
}
// the map range should now be set according to the sent filter.
return returnvalue::OK;
}

View File

@ -1,6 +1,8 @@
#ifndef FSFW_RETURNVALUES_RETURNVALUE_H_
#define FSFW_RETURNVALUES_RETURNVALUE_H_
#include <returnvalues/classIds.h>
#include <cstdint>
#include "FwClassIds.h"

View File

@ -6,9 +6,17 @@
SpacePacketParser::SpacePacketParser(std::vector<uint16_t> validPacketIds)
: validPacketIds(validPacketIds) {}
ReturnValue_t SpacePacketParser::parseSpacePackets(const uint8_t* buffer, const size_t maxSize,
size_t& startIndex, size_t& foundSize) {
const uint8_t** tempPtr = &buffer;
size_t readLen = 0;
return parseSpacePackets(tempPtr, maxSize, startIndex, foundSize, readLen);
}
ReturnValue_t SpacePacketParser::parseSpacePackets(const uint8_t** buffer, const size_t maxSize,
FoundPacketInfo& packetInfo) {
if (buffer == nullptr or nextStartIdx > maxSize) {
size_t& startIndex, size_t& foundSize,
size_t& readLen) {
if (buffer == nullptr or maxSize < 5) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "SpacePacketParser::parseSpacePackets: Frame invalid" << std::endl;
#else
@ -18,32 +26,35 @@ ReturnValue_t SpacePacketParser::parseSpacePackets(const uint8_t** buffer, const
}
const uint8_t* bufPtr = *buffer;
auto verifyLengthField = [&](size_t localIdx) {
uint16_t lengthField = (bufPtr[localIdx + 4] << 8) | bufPtr[localIdx + 5];
auto verifyLengthField = [&](size_t idx) {
uint16_t lengthField = bufPtr[idx + 4] << 8 | bufPtr[idx + 5];
size_t packetSize = lengthField + 7;
startIndex = idx;
ReturnValue_t result = returnvalue::OK;
if (packetSize + localIdx + amountRead > maxSize) {
if (lengthField == 0) {
// Skip whole header for now
foundSize = 6;
result = NO_PACKET_FOUND;
} else if (packetSize + idx > maxSize) {
// Don't increment buffer and read length here, user has to decide what to do
packetInfo.sizeFound = packetSize;
foundSize = packetSize;
return SPLIT_PACKET;
} else {
packetInfo.sizeFound = packetSize;
foundSize = packetSize;
}
*buffer += packetInfo.sizeFound;
packetInfo.startIdx = localIdx + amountRead;
nextStartIdx = localIdx + amountRead + packetInfo.sizeFound;
amountRead = nextStartIdx;
*buffer += foundSize;
readLen += idx + foundSize;
return result;
};
size_t idx = 0;
// Space packet ID as start marker
if (validPacketIds.size() > 0) {
while (idx + amountRead < maxSize - 5) {
uint16_t currentPacketId = (bufPtr[idx] << 8) | bufPtr[idx + 1];
while (idx < maxSize - 5) {
uint16_t currentPacketId = bufPtr[idx] << 8 | bufPtr[idx + 1];
if (std::find(validPacketIds.begin(), validPacketIds.end(), currentPacketId) !=
validPacketIds.end()) {
if (idx + amountRead >= maxSize - 5) {
if (idx + 5 >= maxSize) {
return SPLIT_PACKET;
}
return verifyLengthField(idx);
@ -51,10 +62,10 @@ ReturnValue_t SpacePacketParser::parseSpacePackets(const uint8_t** buffer, const
idx++;
}
}
nextStartIdx = maxSize;
packetInfo.sizeFound = maxSize;
amountRead = maxSize;
*buffer += maxSize;
startIndex = 0;
foundSize = maxSize;
*buffer += foundSize;
readLen += foundSize;
return NO_PACKET_FOUND;
}
// Assume that the user verified a valid start of a space packet

View File

@ -17,11 +17,9 @@
*/
class SpacePacketParser {
public:
struct FoundPacketInfo {
size_t startIdx = 0;
size_t sizeFound = 0;
};
//! The first entry is the index inside the buffer while the second index
//! is the size of the PUS packet starting at that index.
using IndexSizePair = std::pair<size_t, size_t>;
static constexpr uint8_t INTERFACE_ID = CLASS_ID::SPACE_PACKET_PARSER;
static constexpr ReturnValue_t NO_PACKET_FOUND = MAKE_RETURN_CODE(0x00);
@ -38,32 +36,44 @@ class SpacePacketParser {
SpacePacketParser(std::vector<uint16_t> validPacketIds);
/**
* Parse a given frame for space packets but also increments the given buffer.
* Parse a given frame for space packets but also increment the given buffer and assign the
* total number of bytes read so far
* @param buffer Parser will look for space packets in this buffer
* @param maxSize Maximum size of the buffer
* @param packetInfo Information about packets found.
* -@c NO_PACKET_FOUND if no packet was found in the given buffer
* -@c SPLIT_PACKET if a packet was found but the detected size exceeds maxSize. packetInfo
* will contain the detected packet size and start index.
* -@c returnvalue::OK if a packet was found. Packet size and start index will be set in
* packetInfo
* @param startIndex Start index of a found space packet
* @param foundSize Found size of the space packet
* @param readLen Length read so far. This value is incremented by the number of parsed
* bytes which also includes the size of a found packet
* -@c NO_PACKET_FOUND if no packet was found in the given buffer or the length field is
* invalid. foundSize will be set to the size of the space packet header. buffer and
* readLen will be incremented accordingly.
* -@c SPLIT_PACKET if a packet was found but the detected size exceeds maxSize. foundSize
* will be set to the detected packet size and startIndex will be set to the start of the
* detected packet. buffer and read length will not be incremented but the found length
* will be assigned.
* -@c returnvalue::OK if a packet was found
*/
ReturnValue_t parseSpacePackets(const uint8_t** buffer, const size_t maxSize,
FoundPacketInfo& packetInfo);
ReturnValue_t parseSpacePackets(const uint8_t** buffer, const size_t maxSize, size_t& startIndex,
size_t& foundSize, size_t& readLen);
size_t getAmountRead() {
return amountRead;
}
void reset() {
nextStartIdx = 0;
amountRead = 0;
}
/**
* Parse a given frame for space packets
* @param buffer Parser will look for space packets in this buffer
* @param maxSize Maximum size of the buffer
* @param startIndex Start index of a found space packet
* @param foundSize Found size of the space packet
* -@c NO_PACKET_FOUND if no packet was found in the given buffer or the length field is
* invalid. foundSize will be set to the size of the space packet header
* -@c SPLIT_PACKET if a packet was found but the detected size exceeds maxSize. foundSize
* will be set to the detected packet size and startIndex will be set to the start of the
* detected packet
* -@c returnvalue::OK if a packet was found
*/
ReturnValue_t parseSpacePackets(const uint8_t* buffer, const size_t maxSize, size_t& startIndex,
size_t& foundSize);
private:
std::vector<uint16_t> validPacketIds;
size_t nextStartIdx = 0;
size_t amountRead = 0;
};
#endif /* FRAMEWORK_TMTCSERVICES_PUSPARSER_H_ */

View File

@ -0,0 +1,76 @@
#ifndef FSFW_UTIL_DATAWRAPPER_H
#define FSFW_UTIL_DATAWRAPPER_H
#include <cstddef>
#include <cstdint>
#include <utility>
#include "fsfw/serialize.h"
namespace util {
using BufPair = std::pair<const uint8_t*, size_t>;
struct RawData {
RawData() = default;
const uint8_t* data = nullptr;
size_t len = 0;
};
enum DataTypes { NONE, RAW, SERIALIZABLE };
union DataUnion {
RawData raw{};
SerializeIF* serializable;
};
struct DataWrapper {
DataWrapper() = default;
DataWrapper(const uint8_t* data, size_t size): type(DataTypes::RAW) {
setRawData({data, size});
}
explicit DataWrapper(BufPair raw): type(DataTypes::RAW) {
setRawData(raw);
}
explicit DataWrapper(SerializeIF& serializable): type(DataTypes::SERIALIZABLE) {
setSerializable(serializable);
}
DataTypes type = DataTypes::NONE;
DataUnion dataUnion;
[[nodiscard]] size_t getLength() const {
if (type == DataTypes::RAW) {
return dataUnion.raw.len;
} else if (type == DataTypes::SERIALIZABLE and dataUnion.serializable != nullptr) {
return dataUnion.serializable->getSerializedSize();
}
return 0;
}
[[nodiscard]] bool isNull() const {
if ((type == DataTypes::NONE) or (type == DataTypes::RAW and dataUnion.raw.data == nullptr) or
(type == DataTypes::SERIALIZABLE and dataUnion.serializable == nullptr)) {
return true;
}
return false;
}
void setRawData(BufPair bufPair) {
type = DataTypes::RAW;
dataUnion.raw.data = bufPair.first;
dataUnion.raw.len = bufPair.second;
}
void setSerializable(SerializeIF& serializable) {
type = DataTypes::SERIALIZABLE;
dataUnion.serializable = &serializable;
}
};
} // namespace util
#endif // FSFW_UTIL_DATAWRAPPER_H

View File

@ -1,3 +1 @@
add_subdirectory(gpio)
target_sources(${LIB_FSFW_NAME} PRIVATE printChar.c)

View File

@ -1,10 +0,0 @@
#include <stdio.h>
#include <stdbool.h>
void __attribute__((weak)) printChar(const char* character, bool errStream) {
if (errStream) {
fprintf(stderr, "%c", *character);
} else {
printf("%c", *character);
}
}

View File

@ -2,6 +2,7 @@
#define MISSION_DEVICES_MGMLIS3MDLHANDLER_H_
#include "devicedefinitions/MgmLIS3HandlerDefs.h"
#include "events/subsystemIdRanges.h"
#include "fsfw/devicehandlers/DeviceHandlerBase.h"
#include "fsfw/globalfunctions/PeriodicOperationDivider.h"

View File

@ -18,7 +18,6 @@ add_subdirectory(power)
add_subdirectory(util)
add_subdirectory(container)
add_subdirectory(osal)
add_subdirectory(pus)
add_subdirectory(serialize)
add_subdirectory(datapoollocal)
add_subdirectory(storagemanager)

View File

@ -1,3 +0,0 @@
target_sources(${FSFW_TEST_TGT} PRIVATE
testService11.cpp
)

View File

@ -1,14 +0,0 @@
#include <fsfw/pus/Service11TelecommandScheduling.h>
#include <catch2/catch_test_macros.hpp>
#include "objects/systemObjectList.h"
#include "tmtc/apid.h"
#include "tmtc/pusIds.h"
TEST_CASE("PUS Service 11", "[pus-srvc11]") {
Service11TelecommandScheduling<13> pusService11(objects::PUS_SERVICE_11_TC_SCHEDULER,
apid::DEFAULT_APID, pus::PUS_SERVICE_11, nullptr);
// TODO test something...
}

View File

@ -1,3 +1,4 @@
target_sources(${FSFW_TEST_TGT} PRIVATE
testUnsignedByteField.cpp
testDataWrapper.cpp
)

View File

@ -0,0 +1,59 @@
#include <array>
#include <catch2/catch_test_macros.hpp>
#include "fsfw/util/dataWrapper.h"
#include "mocks/SimpleSerializable.h"
TEST_CASE("Data Wrapper", "[util]") {
util::DataWrapper wrapper;
SECTION("State") {
REQUIRE(wrapper.isNull());
REQUIRE(wrapper.type == util::DataTypes::NONE);
}
SECTION("Set Raw Data") {
util::DataWrapper* instance = &wrapper;
bool deleteInst = false;
REQUIRE(wrapper.isNull());
std::array<uint8_t, 4> data = {1, 2, 3, 4};
SECTION("Setter") {
wrapper.setRawData({data.data(), data.size()});
}
SECTION("Direct Construction Pair") {
instance = new util::DataWrapper(util::BufPair(data.data(), data.size()));
deleteInst = true;
}
SECTION("Direct Construction Single Args") {
instance = new util::DataWrapper(data.data(), data.size());
deleteInst = true;
}
REQUIRE(not instance->isNull());
REQUIRE(instance->type == util::DataTypes::RAW);
REQUIRE(instance->dataUnion.raw.data == data.data());
REQUIRE(instance->dataUnion.raw.len == data.size());
if(deleteInst) {
delete instance;
}
}
SECTION("Simple Serializable") {
util::DataWrapper* instance = &wrapper;
bool deleteInst = false;
REQUIRE(instance->isNull());
SimpleSerializable serializable;
SECTION("Setter") {
wrapper.setSerializable(serializable);
}
SECTION("Direct Construction") {
instance = new util::DataWrapper(serializable);
deleteInst = true;
}
REQUIRE(not instance->isNull());
REQUIRE(instance->type == util::DataTypes::SERIALIZABLE);
REQUIRE(instance->dataUnion.serializable == &serializable);
if(deleteInst) {
delete instance;
}
}
}

View File

@ -4,7 +4,7 @@
#include "fsfw/util/UnsignedByteField.h"
TEST_CASE("Unsigned Byte Field", "[unsigned-byte-field]") {
TEST_CASE("Unsigned Byte Field", "[util]") {
auto testByteField = UnsignedByteField<uint32_t>(10);
auto u32ByteField = U32ByteField(10);
auto u16ByteField = U16ByteField(5);