NetBurner 3.5.0
PDF Version
 
FDBuffer

Many of NetBurner's libraries utilize file descriptors(fd) for data input/output(I/O) transmission. To name a few, some libraries that utilize fd's include TCP, WebSockets, HTTP, FTP, email, serial, and the config system.

The user may find themselves wanting to capture I/O data from an fd to a buffer instead of using the fd as originally intended by a library. This may helpful for debugging, printing to serial, or logging. The intent of this example is to demonstrate exactly that.

This example utilizes the FDBuffer class which associates a buffer with an fd which can then be used with API's that utilize fd's. The FDBuffer class is defined in fd_adapter.h. The FBuffer class supports the use of file descriptor functions defined in iosys.h, such as read(), write(), and close().

This example will demonstrate the use of an FDBuffer object to read the config system's JSON object. The config system maintains config variables and their values as a JSON object. The config system API exposes functions to write the JSON object to an fd, which can be used to write the JSON to a TCP socket or to serial. Instead, we will use the FDBuffer to write the config JSON to a local buffer. The local buffer can be adapted to be stored to persistent storage (flash, SD card, etc), or transmitted remotely (email, syslog, FTP, etc).

An FDBuffer object, by default, can dynamically allocate as many as 20 pool_buffers to store data. Each pool_buffer is capable of storing ETHER_BUFFER_SIZE (1548) bytes. This translates to a total of 30,960 bytes of storage in an FDBuffer object. This value can be increased by modifying the MAX_FDBUFFER_FIFO_BUFFERS macro defined in /nburn/nbrtos/include/fd_adapter.h.