CANopenNode
CANopen protocol stack
|
Topics | |
Bitfields for status argument from CO_fifo_cpyTok2U8 function and similar | |
Files | |
file | CO_fifo.h |
FIFO circular buffer. | |
Data Structures | |
struct | CO_fifo_t |
Fifo object. More... | |
Functions | |
void | CO_fifo_init (CO_fifo_t *fifo, uint8_t *buf, size_t bufSize) |
Initialize fifo object. | |
static void | CO_fifo_reset (CO_fifo_t *fifo) |
Reset fifo object, make it empty. | |
static bool_t | CO_fifo_purge (CO_fifo_t *fifo) |
Purge all data in fifo object, keep other properties. | |
static size_t | CO_fifo_getSpace (CO_fifo_t *fifo) |
Get free buffer space in CO_fifo_t object. | |
static size_t | CO_fifo_getOccupied (CO_fifo_t *fifo) |
Get size of data inside CO_fifo_t buffer object. | |
static bool_t | CO_fifo_putc (CO_fifo_t *fifo, const uint8_t c) |
Put one character into CO_fifo_t buffer object. | |
static void | CO_fifo_putc_ov (CO_fifo_t *fifo, const uint8_t c) |
Put one character into CO_fifo_t buffer object. | |
static bool_t | CO_fifo_getc (CO_fifo_t *fifo, uint8_t *buf) |
Get one character from CO_fifo_t buffer object. | |
size_t | CO_fifo_write (CO_fifo_t *fifo, const uint8_t *buf, size_t count, uint16_t *crc) |
Write data into CO_fifo_t object. | |
size_t | CO_fifo_read (CO_fifo_t *fifo, uint8_t *buf, size_t count, bool_t *eof) |
Read data from CO_fifo_t object. | |
size_t | CO_fifo_altBegin (CO_fifo_t *fifo, size_t offset) |
Initializes alternate read with CO_fifo_altRead. | |
void | CO_fifo_altFinish (CO_fifo_t *fifo, uint16_t *crc) |
Ends alternate read with CO_fifo_altRead and calculate crc checksum. | |
static size_t | CO_fifo_altGetOccupied (CO_fifo_t *fifo) |
Get alternate size of remaining data, see CO_fifo_altRead. | |
size_t | CO_fifo_altRead (CO_fifo_t *fifo, uint8_t *buf, size_t count) |
Alternate read data from CO_fifo_t object. | |
bool_t | CO_fifo_CommSearch (CO_fifo_t *fifo, bool_t clear) |
Search command inside FIFO. | |
bool_t | CO_fifo_trimSpaces (CO_fifo_t *fifo, bool_t *insideComment) |
Trim spaces inside FIFO. | |
size_t | CO_fifo_readToken (CO_fifo_t *fifo, char *buf, size_t count, uint8_t *closed, bool_t *err) |
Get token from FIFO buffer. | |
size_t | CO_fifo_readU82a (CO_fifo_t *fifo, char *buf, size_t count, bool_t end) |
Read uint8_t variable from fifo and output as ascii string. | |
size_t | CO_fifo_readU162a (CO_fifo_t *fifo, char *buf, size_t count, bool_t end) |
Read uint16_t variable from fifo as ascii string, see CO_fifo_readU82a. | |
size_t | CO_fifo_readU322a (CO_fifo_t *fifo, char *buf, size_t count, bool_t end) |
Read uint32_t variable from fifo as ascii string, see CO_fifo_readU82a. | |
size_t | CO_fifo_readU642a (CO_fifo_t *fifo, char *buf, size_t count, bool_t end) |
Read uint64_t variable from fifo as ascii string, see CO_fifo_readU82a. | |
size_t | CO_fifo_readX82a (CO_fifo_t *fifo, char *buf, size_t count, bool_t end) |
Read uint8_t variable from fifo as ascii string, see CO_fifo_readU82a. | |
size_t | CO_fifo_readX162a (CO_fifo_t *fifo, char *buf, size_t count, bool_t end) |
Read uint16_t variable from fifo as ascii string, see CO_fifo_readU82a. | |
size_t | CO_fifo_readX322a (CO_fifo_t *fifo, char *buf, size_t count, bool_t end) |
Read uint32_t variable from fifo as ascii string, see CO_fifo_readU82a. | |
size_t | CO_fifo_readX642a (CO_fifo_t *fifo, char *buf, size_t count, bool_t end) |
Read uint64_t variable from fifo as ascii string, see CO_fifo_readU82a. | |
size_t | CO_fifo_readI82a (CO_fifo_t *fifo, char *buf, size_t count, bool_t end) |
Read int8_t variable from fifo as ascii string, see CO_fifo_readU82a. | |
size_t | CO_fifo_readI162a (CO_fifo_t *fifo, char *buf, size_t count, bool_t end) |
Read int16_t variable from fifo as ascii string, see CO_fifo_readU82a. | |
size_t | CO_fifo_readI322a (CO_fifo_t *fifo, char *buf, size_t count, bool_t end) |
Read int32_t variable from fifo as ascii string, see CO_fifo_readU82a. | |
size_t | CO_fifo_readI642a (CO_fifo_t *fifo, char *buf, size_t count, bool_t end) |
Read int64_t variable from fifo as ascii string, see CO_fifo_readU82a. | |
size_t | CO_fifo_readR322a (CO_fifo_t *fifo, char *buf, size_t count, bool_t end) |
Read float32_t variable from fifo as ascii string, see CO_fifo_readU82a. | |
size_t | CO_fifo_readR642a (CO_fifo_t *fifo, char *buf, size_t count, bool_t end) |
Read float64_t variable from fifo as ascii string, see CO_fifo_readU82a. | |
size_t | CO_fifo_readHex2a (CO_fifo_t *fifo, char *buf, size_t count, bool_t end) |
Read data from fifo and output as space separated two digit ascii string, see also CO_fifo_readU82a. | |
size_t | CO_fifo_readVs2a (CO_fifo_t *fifo, char *buf, size_t count, bool_t end) |
Read data from fifo and output as visible string. | |
size_t | CO_fifo_readB642a (CO_fifo_t *fifo, char *buf, size_t count, bool_t end) |
Read data from fifo and output as mime-base64 encoded string. | |
size_t | CO_fifo_cpyTok2U8 (CO_fifo_t *dest, CO_fifo_t *src, uint8_t *status) |
Read ascii string from src fifo and copy as uint8_t variable to dest fifo. | |
size_t | CO_fifo_cpyTok2U16 (CO_fifo_t *dest, CO_fifo_t *src, uint8_t *status) |
Copy ascii string to uint16_t variable, see CO_fifo_cpyTok2U8. | |
size_t | CO_fifo_cpyTok2U32 (CO_fifo_t *dest, CO_fifo_t *src, uint8_t *status) |
Copy ascii string to uint32_t variable, see CO_fifo_cpyTok2U8. | |
size_t | CO_fifo_cpyTok2U64 (CO_fifo_t *dest, CO_fifo_t *src, uint8_t *status) |
Copy ascii string to uint64_t variable, see CO_fifo_cpyTok2U8. | |
size_t | CO_fifo_cpyTok2I8 (CO_fifo_t *dest, CO_fifo_t *src, uint8_t *status) |
Copy ascii string to int8_t variable, see CO_fifo_cpyTok2U8. | |
size_t | CO_fifo_cpyTok2I16 (CO_fifo_t *dest, CO_fifo_t *src, uint8_t *status) |
Copy ascii string to int16_t variable, see CO_fifo_cpyTok2U8. | |
size_t | CO_fifo_cpyTok2I32 (CO_fifo_t *dest, CO_fifo_t *src, uint8_t *status) |
Copy ascii string to int32_t variable, see CO_fifo_cpyTok2U8. | |
size_t | CO_fifo_cpyTok2I64 (CO_fifo_t *dest, CO_fifo_t *src, uint8_t *status) |
Copy ascii string to int64_t variable, see CO_fifo_cpyTok2U8. | |
size_t | CO_fifo_cpyTok2R32 (CO_fifo_t *dest, CO_fifo_t *src, uint8_t *status) |
Copy ascii string to float32_t variable, see CO_fifo_cpyTok2U8. | |
size_t | CO_fifo_cpyTok2R64 (CO_fifo_t *dest, CO_fifo_t *src, uint8_t *status) |
Copy ascii string to float64_t variable, see CO_fifo_cpyTok2U8. | |
size_t | CO_fifo_cpyTok2Hex (CO_fifo_t *dest, CO_fifo_t *src, uint8_t *status) |
Copy bytes written as two hex digits into to data. | |
size_t | CO_fifo_cpyTok2Vs (CO_fifo_t *dest, CO_fifo_t *src, uint8_t *status) |
Copy visible string to data. | |
size_t | CO_fifo_cpyTok2B64 (CO_fifo_t *dest, CO_fifo_t *src, uint8_t *status) |
Read ascii mime-base64 encoded string from src fifo and copy as binary data to dest fifo. | |
FIFO is organized as circular buffer with predefined capacity. It must be initialized by CO_fifo_init(). Functions are not not thread safe.
It can be used as general purpose FIFO circular buffer for any data. Data can be written by CO_fifo_write() and read by CO_fifo_read() functions.
Buffer has additional functions for usage with CiA309-3 standard. It acts as circular buffer for storing ascii commands and fetching tokens from them.
Initialize fifo object.
fifo | This object will be initialized |
buf | Pointer to externally defined buffer |
bufSize | Size of the above buffer. Usable size of the buffer will be one byte less than bufSize, it is used for operation of the circular buffer. |
|
inlinestatic |
Reset fifo object, make it empty.
fifo | This object |
Purge all data in fifo object, keep other properties.
fifo | This object |
|
inlinestatic |
Get free buffer space in CO_fifo_t object.
fifo | This object |
|
inlinestatic |
Get size of data inside CO_fifo_t buffer object.
fifo | This object |
Put one character into CO_fifo_t buffer object.
fifo | This object |
c | Character to put |
Put one character into CO_fifo_t buffer object.
Overwrite old characters, if run out of space
fifo | This object |
c | Character to put |
Get one character from CO_fifo_t buffer object.
fifo | This object |
buf | Buffer of length one byte, where character will be copied |
Write data into CO_fifo_t object.
This function copies data from buf into internal buffer of CO_fifo_t object. Function returns number of bytes successfully copied. If there is not enough space in destination, not all bytes will be copied.
fifo | This object | |
buf | Buffer which will be copied | |
count | Number of bytes in buf | |
[in,out] | crc | Externally defined variable for CRC checksum, ignored if NULL |
Read data from CO_fifo_t object.
This function copies data from internal buffer of CO_fifo_t object into buf. Function returns number of bytes successfully copied. Function also writes true into eof argument, if command delimiter character is reached.
fifo | This object | |
buf | Buffer into which data will be copied | |
count | Copy up to count bytes into buffer | |
[out] | eof | If different than NULL, then search for delimiter character. If found, then read up to (including) that character and set *eof to true. Otherwise set *eof to false. |
size_t CO_fifo_altBegin | ( | CO_fifo_t * | fifo, |
size_t | offset ) |
Initializes alternate read with CO_fifo_altRead.
fifo | This object |
offset | Offset in bytes from original read pointer |
Ends alternate read with CO_fifo_altRead and calculate crc checksum.
fifo | This object | |
[in,out] | crc | Externally defined variable for CRC checksum, ignored if NULL |
|
inlinestatic |
Get alternate size of remaining data, see CO_fifo_altRead.
fifo | This object |
Alternate read data from CO_fifo_t object.
This function is similar as CO_fifo_read(), but uses alternate read pointer inside circular buffer. It reads data from the buffer and data remains in it. This function uses alternate read pointer and keeps original read pointer unchanged. Before using this function, alternate read pointer must be initialized with CO_fifo_altBegin(). CO_fifo_altFinish() sets original read pointer to alternate read pointer and so empties the buffer.
fifo | This object |
buf | Buffer into which data will be copied |
count | Copy up to count bytes into buffer |
Search command inside FIFO.
If there are some data inside the FIFO, then search for command delimiter.
If command is long, then in the buffer may not be enough space for it. In that case buffer is full and no delimiter is present. Function then returns true and command should be processed for the starting tokens. Buffer can later be refilled multiple times, until command is closed by command delimiter.
If this function returns different than 0, then buffer is usually read by multiple CO_fifo_readToken() calls. If reads was successful, then delimiter is reached and fifo->readPtr is set after the command. If any CO_fifo_readToken() returns nonzero *err, then there is an error and command should be cleared. All this procedure must be implemented inside single function call.
fifo | This object. |
clear | If true, then command will be cleared from the buffer. If there is no delimiter, buffer will be cleared entirely. |
Trim spaces inside FIFO.
Function removes all non graphical characters and comments from fifo buffer. It stops on first graphical character or on command delimiter (later is also removed).
fifo | This object. | |
[in,out] | insideComment | if set to true as input, it skips all characters and searches only for delimiter. As output it is set to true, if fifo is empty, is inside comment and command delimiter is not found. |
size_t CO_fifo_readToken | ( | CO_fifo_t * | fifo, |
char * | buf, | ||
size_t | count, | ||
uint8_t * | closed, | ||
bool_t * | err ) |
Get token from FIFO buffer.
Function search FIFO buffer for token. Token is string of only graphical characters. Graphical character is any printable character except space with acsii code within limits: 0x20 < code < 0x7F (see isgraph() function).
If token is found, then copy it to the buf, if count is large enough. On success also set readPtr to point to the next graphical character.
Each token must have at least one empty space after it (space, command delimiter, '\0', etc.). Delimiter must not be graphical character.
If comment delimiter (delimComment, see CO_fifo_init) character is found, then all string till command delimiter (delimCommand, see CO_fifo_init) will be erased from the buffer.
See also CO_fifo_CommSearch().
fifo | This object. | |
buf | Buffer into which data will be copied. Will be terminated by '\0'. | |
count | Copy up to count bytes into buffer | |
[in,out] | closed | This is input/output variable. Not used if NULL.
|
[out] | err | If not NULL, it is set to true if token is larger than buf or in matching combination in 'closed' argument. If it is already true, then function returns immediately. |
Read uint8_t variable from fifo and output as ascii string.
fifo | This object. |
buf | Buffer into which ascii string will be copied. |
count | Available count of bytes inside the buf. |
end | True indicates, that fifo contains last bytes of data. |
Read data from fifo and output as visible string.
A visible string is enclosed with double quotes. If a double quote is used within the string, the quotes are escaped by a second quotes, e.g. “Hello “”World””, CANopen is great”. UTF-8 characters and also line breaks works with this function. Function removes all NULL and CR characters from output string. See also CO_fifo_readU82a
Read data from fifo and output as mime-base64 encoded string.
Encoding is as specified in RFC 2045, without CR-LF, but one long string. See also CO_fifo_readU82a
Read ascii string from src fifo and copy as uint8_t variable to dest fifo.
dest | destination fifo buffer object. | |
src | source fifo buffer object. | |
[out] | status | bitfield of the uint8_t type. |
Copy bytes written as two hex digits into to data.
Bytes may be space separated. See CO_fifo_cpyTok2U8 for parameters.
Copy visible string to data.
A visible string must be enclosed with double quotes, if it contains space. If a double quote is used within the string, the quotes are escaped by a second quotes. Input string can not contain newline characters. See CO_fifo_cpyTok2U8