Research how to use C++ std::chrono::duration to evaluate time interval

Job ID: 36695573

Budget: $10 – $30 USD

I have a serial port application where I need to ensure a minimum duration has elapsed between the last byte received and the next byte transmission. The concept is simple: capture time now and subtract it from the timestamp of the last received byte, and the ensure it is greater than the duration (11 * 1/115200) where 115200 is the baudrate and 11 represents the number of intervals I wish to see elapse.

I would like to use the C++ std::chrono utilities for this purpose. However, I do not have the time to dig through the documentation and tinker with it to find out exactly what data types and sequence of calls need to happen to accomplish my goal.

I would like someone to investigate this for me and generate an example. Do not use the auto keyword, as I wish to understand the underlying types involved. Also, all math should utilize language features to the maximum extent possible. For example, instead of hard coding a constant such as (1/115200), I would want to see something akin to std::ratio<1,115200>.

Here is what I know so far and what I expect the example to utilize:

std::chrono::time_point
https://en.cppreference.com/w/cpp/chrono/time_point

std::chrono::duration
https://en.cppreference.com/w/cpp/chrono/duration
Related categories: C++ Programming Programming