6 #include <satcat5/io_throttle.h>
14 WriteableThrottle::WriteableThrottle(
17 : WriteableRedirect(dst)
18 , m_rate_bps(rate_bps)
19 , m_tokens(rate_bps / 1024)
20 , m_tref(SATCAT5_CLOCK->now())
25 unsigned WriteableThrottle::get_write_space()
const {
30 return min_unsigned(limit1, limit2);
38 m_tref = SATCAT5_CLOCK->now();
43 unsigned WriteableThrottle::calc_tokens(
unsigned usec)
const {
45 u64 incr_bytes = (u64(usec) * u64(m_rate_bps)) / 8000000;
46 return saturate_add(m_tokens,
unsigned(incr_bytes));
Abstract API for writing byte-streams and packets.
unsigned get_write_space() const override
How many bytes can be written without blocking?
bool write_finalize() override
Mark end of frame and release temporary working data.
A rate-controlled io::WriteableRedirect.
void timer_event() override
Child class MUST override this method.
bool write_finalize() override
Mark end of frame and release temporary working data.
Core event-processing loop for SatCat5 software.
unsigned elapsed_usec() const
Elapsed time in microseconds.
unsigned increment_usec()
Measure elapsed time in microseconds, then increment by the returned quantized value.
Miscellaneous mathematical utility functions.
constexpr unsigned min_unsigned(unsigned a, unsigned b)
Min and max functions.
constexpr T saturate_add(T a, T b, T c=T(-1))
Unsigned add with saturation: min(A + B, C).