Compare commits

...

21 Commits

Author SHA1 Message Date
819a2bfac4 add prototype for new ToAscii CCSDSTime function 2022-10-25 18:20:48 +02:00
096af44e39 needs some fixing 2022-10-24 10:56:01 +02:00
56e8e5a8b3 dont know if I am going to need this 2022-10-24 10:39:43 +02:00
754b71a35f Merge pull request 'Update CFDP components' (#113) from mueller/update-cfdp-components into develop
Reviewed-on: #113
2022-10-21 15:27:40 +02:00
2de9e25ceb Merge remote-tracking branch 'upstream/mueller/new-cfdp-update-with-handlers' into mueller/update-cfdp-components 2022-10-21 11:21:26 +02:00
73454c629c oh god 2022-10-20 16:05:45 +02:00
0c5c2f6c4f important bugfix for i2c device com IF 2022-10-20 14:24:03 +02:00
009700ce80 remove info printout 2022-10-17 17:29:10 +02:00
1e43296f2b missing validity check 2022-10-17 17:24:46 +02:00
1aa062df7f const specifier for AcceptsTelemetryIF 2022-10-17 16:27:41 +02:00
14a8924a83 size check bugfix 2022-10-17 14:01:21 +02:00
9f81926aec some more basic error handling 2022-10-17 12:22:01 +02:00
79c38b45df events for FSFW specific errors 2022-10-17 12:20:26 +02:00
e893e73f86 add first CFDP events 2022-10-17 12:19:31 +02:00
692be9df8d DHB bugfix and addition 2022-10-06 16:57:47 +02:00
8195587604 Merge branch 'mueller/uart-helper-module' into mueller/simplify-dle-parser 2022-10-06 11:14:54 +02:00
1c53b60442 small additional tweak 2022-10-04 23:04:28 +02:00
d1630cdc4c something is wrong 2022-10-04 21:17:35 +02:00
49747fc8a4 some bugfixes 2022-10-04 20:51:58 +02:00
cfc00d0260 try to do this in a simpler way 2022-10-04 18:38:20 +02:00
bdbe0cc9da pass message queue externally 2022-09-16 16:28:41 +02:00
24 changed files with 277 additions and 271 deletions

View File

@@ -425,21 +425,31 @@ ReturnValue_t cfdp::DestHandler::sendFinishedPdu() {
store_address_t storeId; store_address_t storeId;
uint8_t* dataPtr = nullptr; uint8_t* dataPtr = nullptr;
ReturnValue_t result = ReturnValue_t result =
fp.tcStore->getFreeElement(&storeId, finishedPdu.getSerializedSize(), &dataPtr); fp.tmStore->getFreeElement(&storeId, finishedPdu.getSerializedSize(), &dataPtr);
if (result != OK) { if (result != OK) {
// TODO: Error handling and event, this is a non CFDP specific error (most likely store is full) #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "cfdp::DestHandler:sendFinishedPdu: Getting store slot failed" << std::endl;
#endif
fp.eventReporter->forwardEvent(events::STORE_ERROR, result, 0);
return result; return result;
} }
size_t serLen = 0; size_t serLen = 0;
result = finishedPdu.serialize(dataPtr, serLen, finishedPdu.getSerializedSize()); result = finishedPdu.serialize(dataPtr, serLen, finishedPdu.getSerializedSize());
if (result != OK) { if (result != OK) {
// TODO: Error printout, this really should not happen #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "cfdp::DestHandler::sendFinishedPdu: Serializing Finished PDU failed"
<< std::endl;
#endif
fp.eventReporter->forwardEvent(events::SERIALIZATION_ERROR, result, 0);
return result; return result;
} }
TmTcMessage msg(storeId); TmTcMessage msg(storeId);
result = fp.msgQueue->sendMessage(fp.packetDest.getReportReceptionQueue(), &msg); result = fp.msgQueue->sendMessage(fp.packetDest.getReportReceptionQueue(), &msg);
if (result != OK) { if (result != OK) {
// TODO: Error handling and event, this is a non CFDP specific error (most likely store is full) #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "cfdp::DestHandler::sendFinishedPdu: Sending PDU failed" << std::endl;
#endif
fp.eventReporter->forwardEvent(events::MSG_QUEUE_ERROR, result, 0);
return result; return result;
} }
fsmRes.packetsSent++; fsmRes.packetsSent++;

View File

@@ -5,5 +5,15 @@ namespace cfdp {
enum class CfdpStates { IDLE, BUSY_CLASS_1_NACKED, BUSY_CLASS_2_ACKED, SUSPENDED }; enum class CfdpStates { IDLE, BUSY_CLASS_1_NACKED, BUSY_CLASS_2_ACKED, SUSPENDED };
} static constexpr uint8_t SSID = SUBSYSTEM_ID::CFDP;
namespace events {
static constexpr Event STORE_ERROR = event::makeEvent(SSID, 0, severity::LOW);
static constexpr Event MSG_QUEUE_ERROR = event::makeEvent(SSID, 1, severity::LOW);
static constexpr Event SERIALIZATION_ERROR = event::makeEvent(SSID, 2, severity::LOW);
} // namespace events
} // namespace cfdp
#endif // FSFW_CFDP_HANDLER_DEFS_H #endif // FSFW_CFDP_HANDLER_DEFS_H

View File

@@ -17,7 +17,7 @@ ReturnValue_t FinishPduCreator::serialize(uint8_t **buffer, size_t *size, size_t
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
} }
if (*size + 1 >= maxSize) { if (*size + 1 > maxSize) {
return SerializeIF::BUFFER_TOO_SHORT; return SerializeIF::BUFFER_TOO_SHORT;
} }
**buffer = finishInfo.getConditionCode() << 4 | finishInfo.getDeliveryCode() << 2 | **buffer = finishInfo.getConditionCode() << 4 | finishInfo.getDeliveryCode() << 2 |

View File

@@ -467,7 +467,7 @@ ReturnValue_t DeviceHandlerBase::insertInCommandMap(DeviceCommandId_t deviceComm
info.expectedReplies = 0; info.expectedReplies = 0;
info.isExecuting = false; info.isExecuting = false;
info.sendReplyTo = NO_COMMANDER; info.sendReplyTo = NO_COMMANDER;
info.useAlternativeReplyId = alternativeReplyId; info.useAlternativeReplyId = useAlternativeReply;
info.alternativeReplyId = alternativeReplyId; info.alternativeReplyId = alternativeReplyId;
auto resultPair = deviceCommandMap.emplace(deviceCommand, info); auto resultPair = deviceCommandMap.emplace(deviceCommand, info);
if (resultPair.second) { if (resultPair.second) {
@@ -1601,3 +1601,14 @@ void DeviceHandlerBase::disableCommandsAndReplies() {
} }
} }
} }
ReturnValue_t DeviceHandlerBase::finishAction(bool success, DeviceCommandId_t action,
ReturnValue_t result) {
auto commandIter = deviceCommandMap.find(action);
if (commandIter == deviceCommandMap.end()) {
return MessageQueueIF::NO_QUEUE;
}
commandIter->second.isExecuting = false;
actionHelper.finish(success, commandIter->second.sendReplyTo, action, result);
return returnvalue::OK;
}

View File

@@ -399,6 +399,8 @@ class DeviceHandlerBase : public DeviceHandlerIF,
*/ */
virtual ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) = 0; virtual ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) = 0;
MessageQueueId_t getCommanderQueueId(DeviceCommandId_t replyId) const; MessageQueueId_t getCommanderQueueId(DeviceCommandId_t replyId) const;
ReturnValue_t finishAction(bool success, DeviceCommandId_t action, ReturnValue_t result);
/** /**
* Helper function to get pending command. This is useful for devices * Helper function to get pending command. This is useful for devices
* like SPI sensors to identify the last sent command. * like SPI sensors to identify the last sent command.
@@ -1138,6 +1140,22 @@ class DeviceHandlerBase : public DeviceHandlerIF,
*/ */
virtual ReturnValue_t doSendReadHook(); virtual ReturnValue_t doSendReadHook();
/**
* Send a RMAP getRead command.
*
* The size of the getRead command is #maxDeviceReplyLen.
* This is always executed, independently from the current mode.
*/
virtual void doSendRead(void);
/**
* Check the getRead reply and the contained data.
*
* If data was received scanForReply() and, if successful, handleReply()
* are called. If the current mode is @c MODE_RAW, the received packet
* is sent to the commanding object via commandQueue.
*/
virtual void doGetRead();
private: private:
/** /**
* State a cookie is in. * State a cookie is in.
@@ -1273,21 +1291,6 @@ class DeviceHandlerBase : public DeviceHandlerIF,
* - if the action was successful, the reply timout counter is initialized * - if the action was successful, the reply timout counter is initialized
*/ */
void doGetWrite(void); void doGetWrite(void);
/**
* Send a RMAP getRead command.
*
* The size of the getRead command is #maxDeviceReplyLen.
* This is always executed, independently from the current mode.
*/
void doSendRead(void);
/**
* Check the getRead reply and the contained data.
*
* If data was received scanForReply() and, if successful, handleReply()
* are called. If the current mode is @c MODE_RAW, the received packet
* is sent to the commanding object via commandQueue.
*/
void doGetRead(void);
/** /**
* @brief Resets replies which use a timeout to detect missed replies. * @brief Resets replies which use a timeout to detect missed replies.

View File

@@ -33,6 +33,7 @@ enum : uint8_t {
PUS_SERVICE_23 = 103, PUS_SERVICE_23 = 103,
MGM_LIS3MDL = 106, MGM_LIS3MDL = 106,
MGM_RM3100 = 107, MGM_RM3100 = 107,
CFDP = 108,
FW_SUBSYSTEM_ID_RANGE FW_SUBSYSTEM_ID_RANGE
}; };

View File

@@ -3,159 +3,94 @@
#include <fsfw/serviceinterface/ServiceInterface.h> #include <fsfw/serviceinterface/ServiceInterface.h>
#include <cstdio> #include <cstdio>
#include <fstream>
#include <iostream>
DleParser::DleParser(SimpleRingBuffer& decodeRingBuf, DleEncoder& decoder, BufPair encodedBuf, DleParser::DleParser(SimpleRingBuffer& decodeRingBuf, DleEncoder& decoder, BufPair encodedBuf,
BufPair decodedBuf, UserHandler handler, void* args) BufPair decodedBuf)
: decodeRingBuf(decodeRingBuf), : decodeRingBuf(decodeRingBuf),
decoder(decoder), decoder(decoder),
encodedBuf(encodedBuf), encodedBuf(encodedBuf),
decodedBuf(decodedBuf), decodedBuf(decodedBuf) {}
handler(handler),
ctx(args) {
if (handler == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "DleParser::DleParser: Invalid user handler" << std::endl;
#else
sif::printError("DleParser::DleParser: Invalid user handler\n");
#endif
}
}
ReturnValue_t DleParser::passData(uint8_t* data, size_t len) { ReturnValue_t DleParser::passData(const uint8_t* data, size_t len) {
if (data == nullptr or len == 0 or handler == nullptr) { if (data == nullptr or len == 0) {
return returnvalue::FAILED; return returnvalue::FAILED;
} }
size_t copyIntoRingBufFromHere = 0; return decodeRingBuf.writeData(data, len);
size_t copyAmount = len;
size_t startIdx = 0;
ReturnValue_t result = returnvalue::OK;
bool startFoundInThisPacket = false;
for (size_t idx = 0; idx < len; idx++) {
if (data[idx] == DleEncoder::STX_CHAR) {
if (not startFound and not startFoundInThisPacket) {
startIdx = idx;
copyIntoRingBufFromHere = idx;
copyAmount = len - idx;
} else {
// Maybe print warning, should not happen
decodeRingBuf.clear();
ErrorInfo info;
info.len = idx;
prepareErrorContext(ErrorTypes::CONSECUTIVE_STX_CHARS, info);
handler(ctx);
copyIntoRingBufFromHere = idx;
copyAmount = len - idx;
} }
startFound = true;
startFoundInThisPacket = true; ReturnValue_t DleParser::parseRingBuf(size_t& readSize) {
} else if (data[idx] == DleEncoder::ETX_CHAR) { ctx.setType(DleParser::ContextType::NONE);
if (startFoundInThisPacket) { size_t availableData = decodeRingBuf.getAvailableReadData();
size_t readLen = 0; if (availableData == 0) {
return NO_PACKET_FOUND;
}
if (availableData > encodedBuf.second) {
ErrorInfo info;
info.len = decodeRingBuf.getAvailableReadData();
setErrorContext(ErrorTypes::DECODING_BUF_TOO_SMALL, info);
return returnvalue::FAILED;
}
ReturnValue_t result = decodeRingBuf.readData(encodedBuf.first, availableData);
if (result != returnvalue::OK) {
ErrorInfo info;
info.res = result;
setErrorContext(ErrorTypes::RING_BUF_ERROR, info);
return result;
}
bool stxFound = false;
size_t stxIdx = 0;
for (size_t vectorIdx = 0; vectorIdx < availableData; vectorIdx++) {
// handle STX char
if (encodedBuf.first[vectorIdx] == DleEncoder::STX_CHAR) {
if (not stxFound) {
stxFound = true;
stxIdx = vectorIdx;
} else {
// might be lost packet, so we should advance the read pointer
// without skipping the STX
readSize = vectorIdx;
ErrorInfo info;
setErrorContext(ErrorTypes::CONSECUTIVE_STX_CHARS, info);
return POSSIBLE_PACKET_LOSS;
}
}
// handle ETX char
if (encodedBuf.first[vectorIdx] == DleEncoder::ETX_CHAR) {
if (stxFound) {
// This is propably a packet, so we decode it.
size_t decodedLen = 0; size_t decodedLen = 0;
result = decoder.decode(data + startIdx, idx + 1 - startIdx, &readLen, decodedBuf.first, size_t dummy = 0;
decodedBuf.second, &decodedLen);
ReturnValue_t result =
decoder.decode(&encodedBuf.first[stxIdx], availableData - stxIdx, &dummy,
decodedBuf.first, decodedBuf.second, &decodedLen);
if (result == returnvalue::OK) { if (result == returnvalue::OK) {
ctx.setType(ContextType::PACKET_FOUND); ctx.setType(ContextType::PACKET_FOUND);
ctx.decodedPacket.first = decodedBuf.first; ctx.decodedPacket.first = decodedBuf.first;
ctx.decodedPacket.second = decodedLen; ctx.decodedPacket.second = decodedLen;
this->handler(ctx); readSize = ++vectorIdx;
} else if (result == DleEncoder::STREAM_TOO_SHORT) {
ErrorInfo info;
info.res = result;
prepareErrorContext(ErrorTypes::DECODING_BUF_TOO_SMALL, info);
handler(ctx);
} else {
ErrorInfo info;
info.res = result;
prepareErrorContext(ErrorTypes::DECODING_BUF_TOO_SMALL, info);
handler(ctx);
}
decodeRingBuf.clear();
if ((idx + 1) < len) {
copyIntoRingBufFromHere = idx + 1;
copyAmount = len - idx - 1;
} else {
copyAmount = 0;
}
} else if (startFound) {
// ETX found but STX was found in another mini packet. Reconstruct the full packet
// to decode it
result = decodeRingBuf.writeData(data, idx + 1);
if (result != returnvalue::OK) {
ErrorInfo info;
info.res = result;
prepareErrorContext(ErrorTypes::RING_BUF_ERROR, info);
handler(ctx);
}
size_t fullEncodedLen = decodeRingBuf.getAvailableReadData();
if (fullEncodedLen > encodedBuf.second) {
ErrorInfo info;
info.len = fullEncodedLen;
prepareErrorContext(ErrorTypes::ENCODED_BUF_TOO_SMALL, info);
handler(ctx);
decodeRingBuf.clear();
} else {
size_t decodedLen = 0;
size_t readLen = 0;
decodeRingBuf.readData(encodedBuf.first, fullEncodedLen, true);
result = decoder.decode(encodedBuf.first, fullEncodedLen, &readLen, decodedBuf.first,
decodedBuf.second, &decodedLen);
if (result == returnvalue::OK) {
if (this->handler != nullptr) {
ctx.setType(ContextType::PACKET_FOUND);
ctx.decodedPacket.first = decodedBuf.first;
ctx.decodedPacket.second = decodedLen;
this->handler(ctx);
}
} else if (result == DleEncoder::STREAM_TOO_SHORT) {
ErrorInfo info;
info.res = result;
prepareErrorContext(ErrorTypes::DECODING_BUF_TOO_SMALL, info);
handler(ctx);
} else {
ErrorInfo info;
info.res = result;
prepareErrorContext(ErrorTypes::DECODE_ERROR, info);
handler(ctx);
}
decodeRingBuf.clear();
startFound = false;
startFoundInThisPacket = false;
if ((idx + 1) < len) {
copyIntoRingBufFromHere = idx + 1;
copyAmount = len - idx - 1;
} else {
copyAmount = 0;
}
}
} else {
// End data without preceeding STX
ErrorInfo info;
info.len = idx + 1;
prepareErrorContext(ErrorTypes::CONSECUTIVE_ETX_CHARS, info);
handler(ctx);
decodeRingBuf.clear();
if ((idx + 1) < len) {
copyIntoRingBufFromHere = idx + 1;
copyAmount = len - idx - 1;
} else {
copyAmount = 0;
}
}
startFoundInThisPacket = false;
startFound = false;
}
}
if (copyAmount > 0) {
result = decodeRingBuf.writeData(data + copyIntoRingBufFromHere, copyAmount);
if (result != returnvalue::OK) {
ErrorInfo info;
info.res = result;
prepareErrorContext(ErrorTypes::RING_BUF_ERROR, info);
handler(ctx);
}
}
return returnvalue::OK; return returnvalue::OK;
} else {
// invalid packet, skip.
readSize = ++vectorIdx;
ErrorInfo info;
info.res = result;
setErrorContext(ErrorTypes::DECODE_ERROR, info);
return POSSIBLE_PACKET_LOSS;
}
} else {
// might be lost packet, so we should advance the read pointer
readSize = ++vectorIdx;
ErrorInfo info;
info.len = 0;
setErrorContext(ErrorTypes::CONSECUTIVE_ETX_CHARS, info);
return POSSIBLE_PACKET_LOSS;
}
}
}
return NO_PACKET_FOUND;
} }
void DleParser::defaultFoundPacketHandler(uint8_t* packet, size_t len, void* args) { void DleParser::defaultFoundPacketHandler(uint8_t* packet, size_t len, void* args) {
@@ -169,8 +104,12 @@ void DleParser::defaultFoundPacketHandler(uint8_t* packet, size_t len, void* arg
#endif #endif
} }
void DleParser::defaultErrorHandler(ErrorTypes err, ErrorInfo ctx) { void DleParser::defaultErrorHandler() {
switch (err) { if (ctx.getType() != DleParser::ContextType::ERROR) {
errorPrinter("No error");
return;
}
switch (ctx.error.first) {
case (ErrorTypes::NONE): { case (ErrorTypes::NONE): {
errorPrinter("No error"); errorPrinter("No error");
break; break;
@@ -186,8 +125,9 @@ void DleParser::defaultErrorHandler(ErrorTypes err, ErrorInfo ctx) {
case (ErrorTypes::ENCODED_BUF_TOO_SMALL): case (ErrorTypes::ENCODED_BUF_TOO_SMALL):
case (ErrorTypes::DECODING_BUF_TOO_SMALL): { case (ErrorTypes::DECODING_BUF_TOO_SMALL): {
char opt[64]; char opt[64];
snprintf(opt, sizeof(opt), ": Too small for packet with length %zu", ctx.len); snprintf(opt, sizeof(opt), ": Too small for packet with length %zu",
if (err == ErrorTypes::ENCODED_BUF_TOO_SMALL) { ctx.decodedPacket.second);
if (ctx.error.first == ErrorTypes::ENCODED_BUF_TOO_SMALL) {
errorPrinter("Encoded buf too small", opt); errorPrinter("Encoded buf too small", opt);
} else { } else {
errorPrinter("Decoding buf too small", opt); errorPrinter("Decoding buf too small", opt);
@@ -218,13 +158,16 @@ void DleParser::errorPrinter(const char* str, const char* opt) {
#endif #endif
} }
void DleParser::prepareErrorContext(ErrorTypes err, ErrorInfo info) { void DleParser::setErrorContext(ErrorTypes err, ErrorInfo info) {
ctx.setType(ContextType::ERROR); ctx.setType(ContextType::ERROR);
ctx.error.first = err; ctx.error.first = err;
ctx.error.second = info; ctx.error.second = info;
} }
void DleParser::reset() { ReturnValue_t DleParser::confirmBytesRead(size_t bytesRead) {
startFound = false; return decodeRingBuf.deleteData(bytesRead);
decodeRingBuf.clear();
} }
const DleParser::Context& DleParser::getContext() { return ctx; }
void DleParser::reset() { decodeRingBuf.clear(); }

View File

@@ -18,9 +18,11 @@
*/ */
class DleParser { class DleParser {
public: public:
static constexpr ReturnValue_t NO_PACKET_FOUND = returnvalue::makeCode(1, 1);
static constexpr ReturnValue_t POSSIBLE_PACKET_LOSS = returnvalue::makeCode(1, 2);
using BufPair = std::pair<uint8_t*, size_t>; using BufPair = std::pair<uint8_t*, size_t>;
enum class ContextType { PACKET_FOUND, ERROR }; enum class ContextType { NONE, PACKET_FOUND, ERROR };
enum class ErrorTypes { enum class ErrorTypes {
NONE, NONE,
@@ -41,7 +43,7 @@ class DleParser {
struct Context { struct Context {
public: public:
Context(void* args) : userArgs(args) { setType(ContextType::PACKET_FOUND); } Context() { setType(ContextType::PACKET_FOUND); }
void setType(ContextType type) { void setType(ContextType type) {
this->type = type; this->type = type;
@@ -58,14 +60,11 @@ class DleParser {
BufPair decodedPacket = {}; BufPair decodedPacket = {};
ErrorPair error; ErrorPair error;
void* userArgs;
private: private:
ContextType type; ContextType type;
}; };
using UserHandler = void (*)(const Context& ctx);
/** /**
* Base class constructor * Base class constructor
* @param decodeRingBuf Ring buffer used to store multiple packets to allow detecting DLE packets * @param decodeRingBuf Ring buffer used to store multiple packets to allow detecting DLE packets
@@ -79,7 +78,7 @@ class DleParser {
* @param args Arbitrary user argument * @param args Arbitrary user argument
*/ */
DleParser(SimpleRingBuffer& decodeRingBuf, DleEncoder& decoder, BufPair encodedBuf, DleParser(SimpleRingBuffer& decodeRingBuf, DleEncoder& decoder, BufPair encodedBuf,
BufPair decodedBuf, UserHandler handler, void* args); BufPair decodedBuf);
/** /**
* This function allows to pass new data into the parser. It then scans for DLE packets * This function allows to pass new data into the parser. It then scans for DLE packets
@@ -88,8 +87,13 @@ class DleParser {
* @param len * @param len
* @return * @return
*/ */
ReturnValue_t passData(uint8_t* data, size_t len); ReturnValue_t passData(const uint8_t* data, size_t len);
ReturnValue_t parseRingBuf(size_t& bytesRead);
ReturnValue_t confirmBytesRead(size_t bytesRead);
const Context& getContext();
/** /**
* Example found packet handler * Example found packet handler
* function call * function call
@@ -104,11 +108,11 @@ class DleParser {
* - For buffer length errors, will be set to the detected packet length which is too large * - For buffer length errors, will be set to the detected packet length which is too large
* - For decode or ring buffer errors, will be set to the result returned from the failed call * - For decode or ring buffer errors, will be set to the result returned from the failed call
*/ */
static void defaultErrorHandler(ErrorTypes err, ErrorInfo ctx); void defaultErrorHandler();
static void errorPrinter(const char* str, const char* opt = nullptr); static void errorPrinter(const char* str, const char* opt = nullptr);
void prepareErrorContext(ErrorTypes err, ErrorInfo ctx); void setErrorContext(ErrorTypes err, ErrorInfo ctx);
/** /**
* Resets the parser by resetting the internal states and clearing the decoding ring buffer * Resets the parser by resetting the internal states and clearing the decoding ring buffer
*/ */
@@ -119,7 +123,5 @@ class DleParser {
DleEncoder& decoder; DleEncoder& decoder;
BufPair encodedBuf; BufPair encodedBuf;
BufPair decodedBuf; BufPair decodedBuf;
UserHandler handler = nullptr;
Context ctx; Context ctx;
bool startFound = false;
}; };

View File

@@ -15,8 +15,8 @@ Service5EventReporting::Service5EventReporting(PsbParams params, size_t maxNumbe
maxNumberReportsPerCycle(maxNumberReportsPerCycle) { maxNumberReportsPerCycle(maxNumberReportsPerCycle) {
auto mqArgs = MqArgs(getObjectId(), static_cast<void*>(this)); auto mqArgs = MqArgs(getObjectId(), static_cast<void*>(this));
psbParams.name = "PUS 5 Event Reporting"; psbParams.name = "PUS 5 Event Reporting";
eventQueue = QueueFactory::instance()->createMessageQueue(messageQueueDepth, eventQueue = QueueFactory::instance()->createMessageQueue(
MessageQueueMessage::MAX_MESSAGE_SIZE, &mqArgs); messageQueueDepth, MessageQueueMessage::MAX_MESSAGE_SIZE, &mqArgs);
} }
Service5EventReporting::~Service5EventReporting() { Service5EventReporting::~Service5EventReporting() {

View File

@@ -246,6 +246,11 @@ ReturnValue_t CCSDSTime::convertFromASCII(Clock::TimeOfDay_t* to, const uint8_t*
return UNSUPPORTED_TIME_FORMAT; return UNSUPPORTED_TIME_FORMAT;
} }
ReturnValue_t CCSDSTime::convertToASCII(int8_t* to, const Clock::TimeOfDay_t* from,
uint8_t length) {
return returnvalue::OK;
}
ReturnValue_t CCSDSTime::checkCcs(const uint8_t* time, uint8_t length) { ReturnValue_t CCSDSTime::checkCcs(const uint8_t* time, uint8_t length) {
const Ccs_mseconds* time_struct = reinterpret_cast<const Ccs_mseconds*>(time); const Ccs_mseconds* time_struct = reinterpret_cast<const Ccs_mseconds*>(time);

View File

@@ -207,7 +207,7 @@ class CCSDSTime {
static ReturnValue_t convertFromASCII(Clock::TimeOfDay_t *to, uint8_t const *from, static ReturnValue_t convertFromASCII(Clock::TimeOfDay_t *to, uint8_t const *from,
uint8_t length); uint8_t length);
static ReturnValue_t convertToASCII(int8_t *to, const Clock::TimeOfDay_t *from, uint8_t length);
static uint32_t subsecondsToMicroseconds(uint16_t subseconds); static uint32_t subsecondsToMicroseconds(uint16_t subseconds);
private: private:

View File

@@ -6,47 +6,12 @@
#include "fsfw/returnvalues/returnvalue.h" #include "fsfw/returnvalues/returnvalue.h"
#include "tmStorageConf.h" #include "tmStorageConf.h"
class TmPacketMinimal; class PusTmReader;
class SpacePacketBase; class SpacePacketReader;
class TmStoreBackendIF; class TmStoreBackendIF;
class TmStoreFrontendIF { class TmStoreFrontendIF {
public: public:
virtual TmStoreBackendIF* getBackend() const = 0;
/**
* What do I need to implement here?
* This is propably used by PUS Service 15 so we should propably check for messages..
* Provide base implementation?
* @param opCode
* @return
*/
virtual ReturnValue_t performOperation(uint8_t opCode) = 0;
/**
* Callback from the back-end to indicate a certain packet was received.
* front-end takes care of discarding/downloading the packet.
* @param packet Pointer to the newly received Space Packet.
* @param address Start address of the packet found
* @param isLastPacket Indicates if no more packets can be fetched.
* @return If more packets shall be fetched, returnvalue::OK must be returned.
* Any other code stops fetching packets.
*/
virtual ReturnValue_t packetRetrieved(TmPacketMinimal* packet, uint32_t address) = 0;
virtual void noMorePacketsInStore() = 0;
virtual void handleRetrievalFailed(ReturnValue_t errorCode, uint32_t parameter1 = 0,
uint32_t parameter2 = 0) = 0;
/**
* To get the queue where commands shall be sent.
* @return Id of command queue.
*/
virtual MessageQueueId_t getCommandQueue() const = 0;
virtual ReturnValue_t fetchPackets(ApidSsc start, ApidSsc end) = 0;
virtual ReturnValue_t deletePackets(ApidSsc upTo) = 0;
virtual ReturnValue_t checkPacket(SpacePacketBase* tmPacket) = 0;
virtual bool isEnabled() const = 0;
virtual void setEnabled(bool enabled) = 0;
virtual void resetDownlinkedPacketCount() = 0;
virtual ReturnValue_t setDumpTarget(object_id_t dumpTarget) = 0;
static const uint8_t INTERFACE_ID = CLASS_ID::TM_STORE_FRONTEND_IF; static const uint8_t INTERFACE_ID = CLASS_ID::TM_STORE_FRONTEND_IF;
static const ReturnValue_t BUSY = MAKE_RETURN_CODE(1); static const ReturnValue_t BUSY = MAKE_RETURN_CODE(1);
static const ReturnValue_t LAST_PACKET_FOUND = MAKE_RETURN_CODE(2); static const ReturnValue_t LAST_PACKET_FOUND = MAKE_RETURN_CODE(2);
@@ -57,7 +22,38 @@ class TmStoreFrontendIF {
static const ReturnValue_t ALL_DELETED = MAKE_RETURN_CODE(7); static const ReturnValue_t ALL_DELETED = MAKE_RETURN_CODE(7);
static const ReturnValue_t INVALID_DATA = MAKE_RETURN_CODE(8); static const ReturnValue_t INVALID_DATA = MAKE_RETURN_CODE(8);
static const ReturnValue_t NOT_READY = MAKE_RETURN_CODE(9); static const ReturnValue_t NOT_READY = MAKE_RETURN_CODE(9);
virtual ~TmStoreFrontendIF() {}
virtual ~TmStoreFrontendIF() = default;
/**
* To get the queue where commands shall be sent.
* @return Id of command queue.
*/
virtual MessageQueueId_t getCommandQueue() const = 0;
virtual TmStoreBackendIF* getBackend() const = 0;
/**
* Callback from the back-end to indicate a certain packet was received.
* front-end takes care of discarding/downloading the packet.
* @param packet Pointer to the newly received Space Packet.
* @param address Start address of the packet found
* @param isLastPacket Indicates if no more packets can be fetched.
* @return If more packets shall be fetched, returnvalue::OK must be returned.
* Any other code stops fetching packets.
*/
virtual ReturnValue_t packetRetrieved(PusTmReader* packet, uint32_t address) = 0;
virtual void noMorePacketsInStore() = 0;
virtual void handleRetrievalFailed(ReturnValue_t errorCode, uint32_t parameter1 = 0,
uint32_t parameter2 = 0) = 0;
virtual ReturnValue_t fetchPackets(ApidSsc start, ApidSsc end) = 0;
virtual ReturnValue_t deletePackets(ApidSsc upTo) = 0;
virtual ReturnValue_t checkPacket(SpacePacketReader* tmPacket) = 0;
virtual bool isEnabled() const = 0;
virtual void setEnabled(bool enabled) = 0;
virtual void resetDownlinkedPacketCount() = 0;
virtual ReturnValue_t setDumpTarget(object_id_t dumpTarget) = 0;
}; };
#endif /* FSFW_TMTCSERVICES_TMSTOREFRONTENDIF_H_ */ #endif /* FSFW_TMTCSERVICES_TMSTOREFRONTENDIF_H_ */

View File

@@ -0,0 +1,14 @@
#ifndef FSFW_SRC_FSFW_TMSTORAGE_TMSTOREBACKENDSIMPLEIF_H_
#define FSFW_SRC_FSFW_TMSTORAGE_TMSTOREBACKENDSIMPLEIF_H_
#include <fsfw/ipc/messageQueueDefinitions.h>
class TmStoreFrontendSimpleIF {
public:
virtual ~TmStoreFrontendSimpleIF() = default;
private:
virtual MessageQueueId_t getCommandQueue() const = 0;
};
#endif /* FSFW_SRC_FSFW_TMSTORAGE_TMSTOREBACKENDSIMPLEIF_H_ */

View File

@@ -1,6 +1,10 @@
#ifndef FSFW_TMSTORAGE_TMSTOREPACKETS_H_ #ifndef FSFW_TMSTORAGE_TMSTOREPACKETS_H_
#define FSFW_TMSTORAGE_TMSTOREPACKETS_H_ #define FSFW_TMSTORAGE_TMSTOREPACKETS_H_
#include <fsfw/tmtcpacket/pus/tm/PusTmReader.h>
#include <vector>
#include "fsfw/globalfunctions/timevalOperations.h" #include "fsfw/globalfunctions/timevalOperations.h"
#include "fsfw/serialize/SerialBufferAdapter.h" #include "fsfw/serialize/SerialBufferAdapter.h"
#include "fsfw/serialize/SerialFixedArrayListAdapter.h" #include "fsfw/serialize/SerialFixedArrayListAdapter.h"
@@ -24,7 +28,7 @@ class ServiceSubservice : public SerialLinkedListAdapter<SerializeIF> {
class ApidSsc : public SerializeIF { class ApidSsc : public SerializeIF {
public: public:
ApidSsc() : apid(SpacePacketBase::LIMIT_APID), ssc(0) {} ApidSsc() : apid(ccsds::LIMIT_APID), ssc(0) {}
ApidSsc(uint16_t apid, uint16_t ssc) : apid(apid), ssc(ssc) {} ApidSsc(uint16_t apid, uint16_t ssc) : apid(apid), ssc(ssc) {}
uint16_t apid; uint16_t apid;
uint16_t ssc; uint16_t ssc;
@@ -62,51 +66,59 @@ class ChangeSelectionDefinition : public SerialLinkedListAdapter<SerializeIF> {
class TmPacketInformation : public SerializeIF { class TmPacketInformation : public SerializeIF {
public: public:
TmPacketInformation(TmPacketMinimal* packet) { setContent(packet); } TmPacketInformation(PusTmReader* packet, size_t timestampLen) : rawTimestamp(timestampLen) {
TmPacketInformation() setContent(packet);
: apid(SpacePacketBase::LIMIT_APID), }
TmPacketInformation(size_t timestampLen)
: apid(ccsds::LIMIT_APID),
sourceSequenceCount(0), sourceSequenceCount(0),
serviceType(0), serviceType(0),
serviceSubtype(0), serviceSubtype(0),
subCounter(0) {} subCounter(0),
rawTimestamp(timestampLen) {}
void reset() { void reset() {
apid = SpacePacketBase::LIMIT_APID; apid = ccsds::LIMIT_APID;
sourceSequenceCount = 0; sourceSequenceCount = 0;
serviceType = 0; serviceType = 0;
serviceSubtype = 0; serviceSubtype = 0;
subCounter = 0; subCounter = 0;
memset(rawTimestamp, 0, sizeof(rawTimestamp)); memset(rawTimestamp.data(), 0, rawTimestamp.size());
} }
void setContent(TmPacketMinimal* packet) { void setContent(PusTmReader* packet) {
apid = packet->getAPID(); apid = packet->getApid();
sourceSequenceCount = packet->getPacketSequenceCount(); sourceSequenceCount = packet->getSequenceCount();
serviceType = packet->getService(); serviceType = packet->getService();
serviceSubtype = packet->getSubService(); serviceSubtype = packet->getSubService();
subCounter = packet->getPacketSubcounter(); subCounter = packet->getMessageTypeCounter();
memset(rawTimestamp, 0, sizeof(rawTimestamp)); memset(rawTimestamp.data(), 0, rawTimestamp.size());
const uint8_t* pField = NULL; // TODO: Fix all of this
uint32_t size = 0; // const uint8_t* pField = NULL;
ReturnValue_t result = packet->getPacketTimeRaw(&pField, &size); // uint32_t size = 0;
if (result != returnvalue::OK) { // auto* timeReader = packet->getTimeReader();
return; // ReturnValue_t result = packet->getPacketTimeRaw(&pField, &size);
} // if (result != returnvalue::OK) {
if (*pField == CCSDSTime::P_FIELD_CDS_SHORT && size <= TimeStamperIF::MISSION_TIMESTAMP_SIZE) { // return;
//}
// if (*pField == CCSDSTime::P_FIELD_CDS_SHORT && size <= TimeStamperIF::MISSION_TIMESTAMP_SIZE)
// {
// Shortcut to avoid converting CDS back and forth. // Shortcut to avoid converting CDS back and forth.
memcpy(rawTimestamp, pField, size); // TODO: Fix
return; // memcpy(rawTimestamp, pField, size);
} // return;
timeval time = {0, 0}; // }
result = packet->getPacketTime(&time); // timeval time = {0, 0};
if (result != returnvalue::OK) { // result = packet->getPacketTime(&time);
return; // if (result != returnvalue::OK) {
} // return;
// }
CCSDSTime::CDS_short cdsFormat; //
result = CCSDSTime::convertToCcsds(&cdsFormat, &time); // CCSDSTime::CDS_short cdsFormat;
if (result != returnvalue::OK) { // result = CCSDSTime::convertToCcsds(&cdsFormat, &time);
return; // if (result != returnvalue::OK) {
} // return;
memcpy(rawTimestamp, &cdsFormat, sizeof(cdsFormat)); // }
// TODO: Fix
// memcpy(rawTimestamp, &cdsFormat, sizeof(cdsFormat));
} }
void setContent(TmPacketInformation* content) { void setContent(TmPacketInformation* content) {
apid = content->apid; apid = content->apid;
@@ -114,9 +126,10 @@ class TmPacketInformation : public SerializeIF {
serviceType = content->serviceType; serviceType = content->serviceType;
serviceSubtype = content->serviceSubtype; serviceSubtype = content->serviceSubtype;
subCounter = content->subCounter; subCounter = content->subCounter;
memcpy(rawTimestamp, content->rawTimestamp, sizeof(rawTimestamp)); // TODO: Fix
// memcpy(rawTimestamp, content->rawTimestamp, sizeof(rawTimestamp));
} }
bool isValid() const { return (apid < SpacePacketBase::LIMIT_APID) ? true : false; } bool isValid() const { return (apid < ccsds::LIMIT_APID) ? true : false; }
static void reset(TmPacketInformation* packet) { packet->reset(); } static void reset(TmPacketInformation* packet) { packet->reset(); }
static bool isOlderThan(const TmPacketInformation* packet, const timeval* cmpTime) { static bool isOlderThan(const TmPacketInformation* packet, const timeval* cmpTime) {
@@ -216,7 +229,7 @@ class TmPacketInformation : public SerializeIF {
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
} }
SerialBufferAdapter<uint8_t> adapter(rawTimestamp, sizeof(rawTimestamp)); SerialBufferAdapter<uint8_t> adapter(rawTimestamp.data(), rawTimestamp.size());
return adapter.serialize(buffer, size, maxSize, streamEndianness); return adapter.serialize(buffer, size, maxSize, streamEndianness);
} }
@@ -227,7 +240,7 @@ class TmPacketInformation : public SerializeIF {
size += SerializeAdapter::getSerializedSize(&serviceType); size += SerializeAdapter::getSerializedSize(&serviceType);
size += SerializeAdapter::getSerializedSize(&serviceSubtype); size += SerializeAdapter::getSerializedSize(&serviceSubtype);
size += SerializeAdapter::getSerializedSize(&subCounter); size += SerializeAdapter::getSerializedSize(&subCounter);
SerialBufferAdapter<uint8_t> adapter(rawTimestamp, sizeof(rawTimestamp)); SerialBufferAdapter<uint8_t> adapter(rawTimestamp.data(), rawTimestamp.size());
size += adapter.getSerializedSize(); size += adapter.getSerializedSize();
return size; return size;
}; };
@@ -253,7 +266,7 @@ class TmPacketInformation : public SerializeIF {
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
} }
SerialBufferAdapter<uint8_t> adapter(rawTimestamp, sizeof(rawTimestamp)); SerialBufferAdapter<uint8_t> adapter(rawTimestamp.data(), rawTimestamp.size());
return adapter.deSerialize(buffer, size, streamEndianness); return adapter.deSerialize(buffer, size, streamEndianness);
} }
@@ -263,6 +276,6 @@ class TmPacketInformation : public SerializeIF {
uint8_t serviceType; uint8_t serviceType;
uint8_t serviceSubtype; uint8_t serviceSubtype;
uint8_t subCounter; uint8_t subCounter;
uint8_t rawTimestamp[TimeStamperIF::MISSION_TIMESTAMP_SIZE]; std::vector<uint8_t> rawTimestamp;
}; };
#endif /* FSFW_TMSTORAGE_TMSTOREPACKETS_H_ */ #endif /* FSFW_TMSTORAGE_TMSTOREPACKETS_H_ */

View File

@@ -14,6 +14,7 @@ SpacePacketCreator::SpacePacketCreator(ccsds::PacketType packetType, bool secHea
: params(SpacePacketParams(PacketId(packetType, secHeaderFlag, apid), : params(SpacePacketParams(PacketId(packetType, secHeaderFlag, apid),
PacketSeqCtrl(seqFlags, seqCount), dataLen)) { PacketSeqCtrl(seqFlags, seqCount), dataLen)) {
params.version = version; params.version = version;
checkFieldValidity();
} }
uint16_t SpacePacketCreator::getPacketIdRaw() const { return params.packetId.raw(); } uint16_t SpacePacketCreator::getPacketIdRaw() const { return params.packetId.raw(); }

View File

@@ -21,9 +21,11 @@ class AcceptsTelemetryIF {
* receiving message queue. * receiving message queue.
* @return The telemetry reception message queue id. * @return The telemetry reception message queue id.
*/ */
virtual MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel) = 0; [[nodiscard]] virtual MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel) const = 0;
virtual MessageQueueId_t getReportReceptionQueue() { return getReportReceptionQueue(0); } [[nodiscard]] virtual MessageQueueId_t getReportReceptionQueue() const {
return getReportReceptionQueue(0);
}
}; };
#endif /* FSFW_TMTCSERVICES_ACCEPTSTELEMETRYIF_H_ */ #endif /* FSFW_TMTCSERVICES_ACCEPTSTELEMETRYIF_H_ */

View File

@@ -245,7 +245,7 @@ void TmTcBridge::registerCommDisconnect() {
} }
} }
MessageQueueId_t TmTcBridge::getReportReceptionQueue(uint8_t virtualChannel) { MessageQueueId_t TmTcBridge::getReportReceptionQueue(uint8_t virtualChannel) const {
return tmTcReceptionQueue->getId(); return tmTcReceptionQueue->getId();
} }

View File

@@ -65,7 +65,7 @@ class TmTcBridge : public AcceptsTelemetryIF,
ReturnValue_t performOperation(uint8_t operationCode = 0) override; ReturnValue_t performOperation(uint8_t operationCode = 0) override;
/** AcceptsTelemetryIF override */ /** AcceptsTelemetryIF override */
MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel = 0) override; MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel = 0) const override;
/** AcceptsTelecommandsIF override */ /** AcceptsTelecommandsIF override */
uint32_t getIdentifier() const override; uint32_t getIdentifier() const override;

View File

@@ -216,7 +216,7 @@ ReturnValue_t I2cComIF::readReceivedMessage(CookieIF* cookie, uint8_t** buffer,
} }
*buffer = i2cDeviceMapIter->second.replyBuffer.data(); *buffer = i2cDeviceMapIter->second.replyBuffer.data();
*size = i2cDeviceMapIter->second.replyLen; *size = i2cDeviceMapIter->second.replyLen;
i2cDeviceMapIter->second.replyLen = 0;
return returnvalue::OK; return returnvalue::OK;
} }

View File

@@ -1,4 +1,5 @@
#include "UartComIF.h" #include "UartComIF.h"
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <termios.h> #include <termios.h>
@@ -458,5 +459,3 @@ ReturnValue_t UartComIF::flushUartTxAndRxBuf(CookieIF* cookie) {
} }
return returnvalue::FAILED; return returnvalue::FAILED;
} }

View File

@@ -1,15 +1,14 @@
#ifndef BSP_Q7S_COMIF_UARTCOMIF_H_ #ifndef BSP_Q7S_COMIF_UARTCOMIF_H_
#define BSP_Q7S_COMIF_UARTCOMIF_H_ #define BSP_Q7S_COMIF_UARTCOMIF_H_
#include "UartCookie.h"
#include "helper.h"
#include <fsfw/devicehandlers/DeviceCommunicationIF.h> #include <fsfw/devicehandlers/DeviceCommunicationIF.h>
#include <fsfw/objectmanager/SystemObject.h> #include <fsfw/objectmanager/SystemObject.h>
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
#include "UartCookie.h"
#include "helper.h"
/** /**
* @brief This is the communication interface to access serial ports on linux based operating * @brief This is the communication interface to access serial ports on linux based operating

View File

@@ -1,14 +1,12 @@
#ifndef SAM9G20_COMIF_COOKIES_UART_COOKIE_H_ #ifndef SAM9G20_COMIF_COOKIES_UART_COOKIE_H_
#define SAM9G20_COMIF_COOKIES_UART_COOKIE_H_ #define SAM9G20_COMIF_COOKIES_UART_COOKIE_H_
#include "helper.h"
#include <fsfw/devicehandlers/CookieIF.h> #include <fsfw/devicehandlers/CookieIF.h>
#include <fsfw/objectmanager/SystemObjectIF.h> #include <fsfw/objectmanager/SystemObjectIF.h>
#include <string> #include <string>
#include "helper.h"
/** /**
* @brief Cookie for the UartComIF. There are many options available to configure the UART driver. * @brief Cookie for the UartComIF. There are many options available to configure the UART driver.

View File

@@ -1,8 +1,9 @@
#include "helper.h" #include "helper.h"
#include "fsfw/serviceinterface.h"
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include "fsfw/serviceinterface.h"
void uart::setMode(struct termios& options, UartModes mode) { void uart::setMode(struct termios& options, UartModes mode) {
if (mode == UartModes::NON_CANONICAL) { if (mode == UartModes::NON_CANONICAL) {
/* Disable canonical mode */ /* Disable canonical mode */
@@ -147,4 +148,3 @@ void uart::setBaudrate(struct termios& options, UartBaudRate baud) {
int uart::readCountersAndErrors(int serialPort, serial_icounter_struct& icounter) { int uart::readCountersAndErrors(int serialPort, serial_icounter_struct& icounter) {
return ioctl(serialPort, TIOCGICOUNT, &icounter); return ioctl(serialPort, TIOCGICOUNT, &icounter);
} }

View File

@@ -1,8 +1,8 @@
#ifndef FSFW_HAL_LINUX_UART_HELPER_H_ #ifndef FSFW_HAL_LINUX_UART_HELPER_H_
#define FSFW_HAL_LINUX_UART_HELPER_H_ #define FSFW_HAL_LINUX_UART_HELPER_H_
#include <termios.h>
#include <linux/serial.h> #include <linux/serial.h>
#include <termios.h>
enum class Parity { NONE, EVEN, ODD }; enum class Parity { NONE, EVEN, ODD };
@@ -56,7 +56,6 @@ void setBaudrate(struct termios& options, UartBaudRate baud);
int readCountersAndErrors(int serialPort, serial_icounter_struct& icounter); int readCountersAndErrors(int serialPort, serial_icounter_struct& icounter);
} } // namespace uart
#endif /* FSFW_HAL_LINUX_UART_HELPER_H_ */ #endif /* FSFW_HAL_LINUX_UART_HELPER_H_ */