* @brief Calculates an ideal read buffer size for a serial port. */
| 36 | * @brief Calculates an ideal read buffer size for a serial port. |
| 37 | */ |
| 38 | static size_t idealSerialBufferSize(const qint32 baud) |
| 39 | { |
| 40 | size_t bytes = static_cast<size_t>(baud * 0.02); |
| 41 | bytes = std::max<size_t>(256, bytes); |
| 42 | bytes = std::min<size_t>(16384, bytes); |
| 43 | |
| 44 | constexpr size_t granularity = 256; |
| 45 | bytes = ((bytes + granularity - 1) / granularity) * granularity; |
| 46 | |
| 47 | return bytes; |
| 48 | } |
| 49 | |
| 50 | //-------------------------------------------------------------------------------------------------- |
| 51 | // Constructor/destructor & singleton access functions |