Seq Count Persistent + MSG type counter #711

Merged
muellerr merged 14 commits from sequence-counter-persistent-msg-type-count-support into main 2023-06-28 13:37:16 +02:00
36 changed files with 340 additions and 553 deletions
Showing only changes of commit 80160e8291 - Show all commits

View File

@@ -68,18 +68,33 @@ ReturnValue_t PusTmFunnel::handleTmPacket(TmTcMessage &message) {
return result; return result;
} }
packet.setSequenceCount(sourceSequenceCount++); packet.setSequenceCount(sourceSequenceCount++);
// NOTE: This only works because the limit value bit width is below 16 bits!
sourceSequenceCount = sourceSequenceCount % ccsds::LIMIT_SEQUENCE_COUNT; sourceSequenceCount = sourceSequenceCount % ccsds::LIMIT_SEQUENCE_COUNT;
uint8_t service = packet.getMessageTypeCounter();
// Message type counter handling.
uint8_t service = packet.getService();
bool insertionFailed = false;
auto mapIter = msgCounterMap.find(service); auto mapIter = msgCounterMap.find(service);
if (mapIter == msgCounterMap.end()) { if (mapIter == msgCounterMap.end()) {
msgCounterMap.emplace(service, 0); auto iterPair = msgCounterMap.emplace(service, 0);
if (iterPair.second) {
mapIter = iterPair.first;
} else {
// Should really never never happen but you never know..
insertionFailed = true;
}
} }
if (mapIter->second == std::numeric_limits<uint16_t>::max()) { if (not insertionFailed) {
mapIter->second = 0; packet.setMessageCount(mapIter->second);
} else { // Sane overflow handling.
mapIter->second++; if (mapIter->second == std::numeric_limits<uint16_t>::max()) {
mapIter->second = 0;
} else {
mapIter->second++;
}
} }
packet.setMessageCount(mapIter->second);
// Re-calculate CRC after changing the fields. This operation HAS to come last!
packet.updateErrorControl(); packet.updateErrorControl();
// Send to persistent TM store if the packet matches some filter. // Send to persistent TM store if the packet matches some filter.