/* FIFO handler for encoded data stream. 
All possible data sources are polled until either no source has more data or fifo is full. */
size_t handle_encoded_fifo(std::array< uint16_t, MODBUS_FIFO_LEN > &fifo)
/* FIFO handler for encoded data stream. 
All possible data sources are polled until either no source has more data or fifo is full. */
size_t handle_encoded_fifo(std::array< uint16_t, MODBUS_FIFO_LEN > &fifo)
{
        encoded = false;
        pickup_accelerometer_sample(encoder, encoded);
        if (encoder.can_encode<LoadcellRecord>()) {
            LoadcellRecord sample;
            if (dwarf::loadcell::get_loadcell_sample(sample)) {
                if (encoder.encode(sample)) {
                    encoded = true;
                } else {
                    failed_to_encode();
                }
            }
        }
        if (encoder.can_encode<LogData>()) {
            LogData log_fragment;
            log_fragment.fill(0);
            size_t num_log_bytes = bufflog_pickup(log_fragment.data(), log_fragment.size());
            if (num_log_bytes) {
                if (encoder.encode(log_fragment)) {
                    encoded = true;
                } else {
                    failed_to_encode();
                }
            }
        }
    }
    encoder.padd();
    return encoder.position();
}