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-03-14 15:01:17 +01:00
private:
2022-05-11 15:42:52 +02:00
uint16_t sequenceCount = 0;
2022-03-14 15:01:17 +01:00
public:
2022-05-11 14:31:49 +02:00
SourceSequenceCounter(uint16_t initialSequenceCount = 0) : sequenceCount(initialSequenceCount) {}
2022-08-27 01:01:29 +02:00
void increment() { sequenceCount = (sequenceCount + 1) % (ccsds::LIMIT_SEQUENCE_COUNT); }
void decrement() { sequenceCount = (sequenceCount - 1) % (ccsds::LIMIT_SEQUENCE_COUNT); }
2022-03-14 15:01:17 +01:00
uint16_t get() { return this->sequenceCount; }
2022-08-27 01:01:29 +02:00
void reset(uint16_t toValue = 0) { sequenceCount = toValue % (ccsds::LIMIT_SEQUENCE_COUNT); }
2022-03-14 15:01:17 +01:00
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-05-11 14:31:49 +02:00
2022-03-17 20:00:17 +01:00
operator uint16_t() { return this->get(); }
2022-03-14 15:01:17 +01:00
};
2020-12-14 21:30:39 +01:00
#endif /* FSFW_TMTCSERVICES_SOURCESEQUENCECOUNTER_H_ */