Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
BandwidthMerger.hxx
Go to the documentation of this file.
1
35#ifndef _UTILS_BANDWIDTHMERGER_HXX_
36#define _UTILS_BANDWIDTHMERGER_HXX_
37
38#include <inttypes.h>
39
40#include "utils/macros.h"
41
47{
51 BandwidthMerger(uint8_t percent)
52 : percentFirst_(percent)
53 {
54 HASSERT(percentFirst_ <= 100);
55 }
58 bool step()
59 {
61 if (currentState_ >= 100)
62 {
63 currentState_ -= 100;
64 return true;
65 }
66 return false;
67 }
68
73 void reset()
74 {
75 // Reduces the state by 100 but clips it to zero. Since the state is
76 // always < 100, the clipping will always win.
77 currentState_ = 0;
78 }
79
83 uint8_t currentState_ {0};
87};
88
89#endif // _UTILS_BANDWIDTHMERGER_HXX_
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.
Definition macros.h:138
Simple stride scheduler.
bool step()
Runs one step.
uint8_t currentState_
State of the current stride.
void reset()
If the step function returned false, but still the first source was taken (e.g.
uint8_t percentFirst_
Percentage of the bandwidth that should be assigned to the first source.
BandwidthMerger(uint8_t percent)
Constructor.