fsfw/src/fsfw/tmtcservices/SourceSequenceCounter.h

33 lines
1.0 KiB
C
Raw Normal View History

2020-12-14 21:30:39 +01:00
#ifndef FSFW_TMTCSERVICES_SOURCESEQUENCECOUNTER_H_
#define FSFW_TMTCSERVICES_SOURCESEQUENCECOUNTER_H_
2022-07-20 11:43:16 +02:00
#include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h"
class SourceSequenceCounter {
2022-02-02 10:29:30 +01:00
private:
2022-11-28 08:30:45 +01:00
uint16_t sequenceCount = 0;
2022-02-02 10:29:30 +01:00
public:
2022-11-28 08:30:45 +01:00
SourceSequenceCounter(uint16_t initialSequenceCount = 0) : sequenceCount(initialSequenceCount) {}
void increment() { sequenceCount = (sequenceCount + 1) % (ccsds::LIMIT_SEQUENCE_COUNT); }
void decrement() { sequenceCount = (sequenceCount - 1) % (ccsds::LIMIT_SEQUENCE_COUNT); }
2022-12-19 14:58:08 +01:00
uint16_t get() const { return this->sequenceCount; }
2022-11-28 08:30:45 +01:00
void reset(uint16_t toValue = 0) { sequenceCount = toValue % (ccsds::LIMIT_SEQUENCE_COUNT); }
SourceSequenceCounter& operator++(int) {
this->increment();
return *this;
2022-02-02 10:29:30 +01:00
}
2022-11-28 08:30:45 +01:00
SourceSequenceCounter& operator--(int) {
this->decrement();
return *this;
2022-02-02 10:29:30 +01:00
}
2022-11-28 08:30:45 +01:00
SourceSequenceCounter& operator=(const uint16_t& newCount) {
sequenceCount = newCount;
return *this;
2022-02-02 10:29:30 +01:00
}
2022-11-28 08:30:45 +01:00
operator uint16_t() { return this->get(); }
2022-02-02 10:29:30 +01:00
};
2020-12-14 21:30:39 +01:00
#endif /* FSFW_TMTCSERVICES_SOURCESEQUENCECOUNTER_H_ */