sbufferwrite
by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - USB Interface
Introduced first in SolidGeometry 2.8, Creation date: 2015-12-08, Last change: 2025-09-14
writes bytes into a struct buffer
Description
the basic functions are:
sbuffercreate - create a buffer
sbufferinfo - status info about the buffer
sbufferwrite - write data into the buffer
sbufferget - read data out of the buffer
See Also: sbuffercreate
, sbufferinfo
, sbufferget
Example Illustration
Syntax
[b,err]=sbufferwrite(b,mbytes)
Input Parameter
b: | | struct buffer |
mbytes: | | bytes array to write |
Output Parameter
b: | | updated buffer |
err: | | error number |
Copyright 2015-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth
Algorithm (Workflow)
This algorithm is a function named sbufferwrite that writes a byte array into a buffer structure. It is part of a library for handling buffer operations, specifically designed for a USB interface.
Input Parameters
- b: A struct representing the buffer. It contains fields such as the buffer array, write index, and buffer length.
- mbytes: An array of bytes that need to be written into the buffer.
Output Results
- b: The updated buffer struct after writing the bytes.
- err: An error flag indicating if an error occurred during the write operation.
Algorithm Steps
- Call
sbufferinfo(b) to retrieve the free space f and total length l of the buffer.
- Initialize
err to false.
- Calculate the size of
mbytes and store it in msize.
- Check if
msize is greater than l. If true, issue a warning that the data size is too large for the buffer and set err to true. Exit the function.
- Check if
msize is greater than f. If true, issue a warning that the data size is too large for the available free space in the buffer and set err to true. Exit the function.
- Calculate the buffer indices
bi where the data will be written using mod1 to handle circular buffer logic.
- Update the write index
b.w to the last index in bi.
- Increment the buffer's data count
b.anz by msize.
- Write the
mbytes into the buffer at the calculated indices bi.
Algorithm explaination created using ChatGPT on 2025-08-18 23:44. (Please note: No guarantee for the correctness of this explanation)
Last html export of this page out of FM database by TL: 2025-09-21