libSNAP v1.0.0
Open source C/C++ library for the Scaleable Node Address Protocol (SNAP)
snap.c File Reference

Source file of the libSNAP library. Refer to the library documentation for details. More...

#include <stddef.h>
#include "snap.h"
Include dependency graph for snap.c:

Functions

Functions that require a frame structure (snap_frame_t)
int16_t snap_init (snap_frame_t *frame, uint8_t *buffer, const uint16_t maxSize)
 Initialize the frame structure. More...
 
void snap_reset (snap_frame_t *frame)
 Reset the frame size and status. The other variables of the frame remain unchanged. More...
 
int8_t snap_decode (snap_frame_t *frame, const uint8_t newByte)
 Detect, decode, validate and store a frame, one byte at a time. More...
 
int8_t snap_encapsulate (snap_frame_t *frame, snap_fields_t *fields)
 Encapsulate a new frame into the buffer (if there is enough space). Update the frame status and size according to the result. More...
 
int16_t snap_getField (const snap_frame_t *frame, void *fieldContent, const uint8_t fieldType)
 Get the content of a selected frame field. More...
 
int8_t snap_calculateHash (const snap_frame_t *frame, uint32_t *hash)
 Select the error detection method based on the EDM bits and calculate the hash value of a frame. More...
 
Functions that do NOT require a frame structure
uint16_t snap_removePaddingBytes (uint8_t *data, uint16_t size, const bool paddingAfter)
 Remove the padding bytes (SNAP_PADDING) of a frame payload (if there are any). More...
 
uint8_t snap_getNdbFromDataSize (const uint16_t dataSize)
 Get the NDB bits of the HDB1 byte based on the number of data bytes (with or without padding bytes). More...
 
uint16_t snap_getDataSizeFromNdb (const uint8_t ndb)
 Get the number of data bytes based on the NDB bits of the HDB1 byte. More...
 
uint8_t snap_getHashSizeFromEdm (const uint8_t edm)
 Get the hash value size of the frame based on the EDM bits of the HDB1 byte. More...
 
uint8_t snap_calculateChecksum8 (const uint8_t *data, const uint16_t size)
 Calculate the 8-bit checksum of a byte array. More...
 
uint8_t snap_calculateCrc8 (const uint8_t *data, const uint16_t size)
 Calculate the 8-bit CRC of a byte array. More...
 
uint16_t snap_calculateCrc16 (const uint8_t *data, const uint16_t size)
 Calculate the 16-bit CRC of a byte array. More...
 
uint32_t snap_calculateCrc32 (const uint8_t *data, const uint16_t size)
 Calculate the 32-bit CRC of a byte array. More...
 
uint32_t snap_calculateUserHash (const uint8_t *data, const uint16_t size)
 Calculate the hash value of a byte array using a user-defined algorithm. More...
 

Detailed Description

Source file of the libSNAP library. Refer to the library documentation for details.

Author
Lucas Jadilo