提交 36d8f694 authored 作者: José Luis Millán's avatar José Luis Millán

SeqManager: enable setting an offset to the output value

上级 d7b65168
...@@ -38,6 +38,7 @@ namespace RTC ...@@ -38,6 +38,7 @@ namespace RTC
public: public:
void Sync(T input); void Sync(T input);
void Drop(T input); void Drop(T input);
void Offset(T offset);
bool Input(const T input, T& output); bool Input(const T input, T& output);
T GetMaxInput() const; T GetMaxInput() const;
T GetMaxOutput() const; T GetMaxOutput() const;
......
...@@ -64,6 +64,12 @@ namespace RTC ...@@ -64,6 +64,12 @@ namespace RTC
this->dropped.insert(input); this->dropped.insert(input);
} }
template<typename T>
void SeqManager<T>::Offset(T offset)
{
this->base += offset;
}
template<typename T> template<typename T>
bool SeqManager<T>::Input(const T input, T& output) bool SeqManager<T>::Input(const T input, T& output)
{ {
......
...@@ -7,8 +7,9 @@ using namespace RTC; ...@@ -7,8 +7,9 @@ using namespace RTC;
struct TestSeqManagerInput struct TestSeqManagerInput
{ {
TestSeqManagerInput(uint16_t input, uint16_t output, bool sync = false, bool drop = false) TestSeqManagerInput(
: input(input), output(output), sync(sync), drop(drop) uint16_t input, uint16_t output, bool sync = false, bool drop = false, uint16_t offset = 0)
: input(input), output(output), sync(sync), drop(drop), offset(offset)
{ {
} }
...@@ -16,6 +17,7 @@ struct TestSeqManagerInput ...@@ -16,6 +17,7 @@ struct TestSeqManagerInput
uint16_t output{ 0 }; uint16_t output{ 0 };
bool sync{ false }; bool sync{ false };
bool drop{ false }; bool drop{ false };
uint16_t offset{ 0 };
}; };
void validate(RTC::SeqManager<uint16_t>& seqManager, std::vector<TestSeqManagerInput>& inputs) void validate(RTC::SeqManager<uint16_t>& seqManager, std::vector<TestSeqManagerInput>& inputs)
...@@ -25,6 +27,9 @@ void validate(RTC::SeqManager<uint16_t>& seqManager, std::vector<TestSeqManagerI ...@@ -25,6 +27,9 @@ void validate(RTC::SeqManager<uint16_t>& seqManager, std::vector<TestSeqManagerI
if (element.sync) if (element.sync)
seqManager.Sync(element.input); seqManager.Sync(element.input);
if (element.offset)
seqManager.Offset(element.offset);
if (element.drop) if (element.drop)
{ {
seqManager.Drop(element.input); seqManager.Drop(element.input);
...@@ -257,4 +262,24 @@ SCENARIO("RTC::SeqManager", "[rtc]") ...@@ -257,4 +262,24 @@ SCENARIO("RTC::SeqManager", "[rtc]")
RTC::SeqManager<uint16_t> seqManager; RTC::SeqManager<uint16_t> seqManager;
validate(seqManager, inputs); validate(seqManager, inputs);
} }
SECTION("receive ordered numbers, sync, no drop, increase input")
{
// clang-format off
std::vector<TestSeqManagerInput> inputs =
{
{ 0, 0, false, false },
{ 1, 1, false, false },
{ 2, 2, false, false },
{ 80, 23, true, false, 20 },
{ 81, 24, false, false },
{ 82, 25, false, false },
{ 83, 26, false, false },
{ 84, 27, false, false }
};
// clang-format on
RTC::SeqManager<uint16_t> seqManager;
validate(seqManager, inputs);
}
} }
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论