2020-12-14 21:30:39 +01:00
|
|
|
#ifndef FSFW_TMTCSERVICES_SOURCESEQUENCECOUNTER_H_
|
|
|
|
#define FSFW_TMTCSERVICES_SOURCESEQUENCECOUNTER_H_
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-08-13 20:53:35 +02:00
|
|
|
#include "../tmtcpacket/SpacePacketBase.h"
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
class SourceSequenceCounter {
|
2022-03-14 15:01:17 +01:00
|
|
|
private:
|
|
|
|
uint16_t sequenceCount;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2022-03-14 15:01:17 +01:00
|
|
|
public:
|
|
|
|
SourceSequenceCounter() : sequenceCount(0) {}
|
|
|
|
void increment() {
|
|
|
|
sequenceCount = (sequenceCount + 1) % (SpacePacketBase::LIMIT_SEQUENCE_COUNT);
|
|
|
|
}
|
|
|
|
void decrement() {
|
|
|
|
sequenceCount = (sequenceCount - 1) % (SpacePacketBase::LIMIT_SEQUENCE_COUNT);
|
|
|
|
}
|
|
|
|
uint16_t get() { return this->sequenceCount; }
|
|
|
|
void reset(uint16_t toValue = 0) {
|
|
|
|
sequenceCount = toValue % (SpacePacketBase::LIMIT_SEQUENCE_COUNT);
|
|
|
|
}
|
|
|
|
SourceSequenceCounter& operator++(int) {
|
|
|
|
this->increment();
|
|
|
|
return *this;
|
|
|
|
}
|
2022-03-17 20:00:17 +01:00
|
|
|
SourceSequenceCounter& operator--(int) {
|
|
|
|
this->decrement();
|
|
|
|
return *this;
|
|
|
|
}
|
2022-03-14 15:01:17 +01:00
|
|
|
SourceSequenceCounter& operator=(const uint16_t& newCount) {
|
|
|
|
sequenceCount = newCount;
|
|
|
|
return *this;
|
|
|
|
}
|
2022-03-17 20:00:17 +01:00
|
|
|
operator uint16_t() { return this->get(); }
|
2022-03-14 15:01:17 +01:00
|
|
|
};
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-12-14 21:30:39 +01:00
|
|
|
#endif /* FSFW_TMTCSERVICES_SOURCESEQUENCECOUNTER_H_ */
|