libSNAP v1.0.0
Open source C/C++ library for the Scaleable Node Address Protocol (SNAP)
Public Macros

Macros visible to all files that include the library header file. Most macros are for naming constant values, but some are wrappers for functions and other macros. More...

Collaboration diagram for Public Macros:

Modules

 User Convenience
 Function-like macros defined just for user convenience. Most of them are wrappers for functions and other macros.
 

Error codes returned from functions

#define SNAP_ERROR_NULL_FRAME   (-1)
 Null frame pointer.
 
#define SNAP_ERROR_NULL_BUFFER   (-2)
 Null buffer pointer.
 
#define SNAP_ERROR_SHORT_BUFFER   (-3)
 Buffer size is smaller than the minimum frame size allowed.
 
#define SNAP_ERROR_UNKNOWN_FORMAT   (-4)
 Frame header is not complete, hence it is impossible to know the frame format.
 
#define SNAP_ERROR_FRAME_FORMAT   (-5)
 Frame format does not have the requested field. Check the frame format (header bytes).
 
#define SNAP_ERROR_SHORT_FRAME   (-6)
 Frame format has the requested field, but it is incomplete or empty.
 
#define SNAP_ERROR_FIELD_TYPE   (-7)
 Invalid field type value. It must be a value from snap_fieldType_t.
 

Bit mask and position of HDB2 fields

#define SNAP_HDB2_DAB_MASK   (0x03U)
 Bit mask of the DAB bits in the HDB2 byte.
 
#define SNAP_HDB2_DAB_POS   (6U)
 Position of the DAB bits (LSb) in the HDB2 byte.
 
#define SNAP_HDB2_SAB_MASK   (0x03U)
 Bit mask of the SAB bits in the HDB2 byte.
 
#define SNAP_HDB2_SAB_POS   (4U)
 Position of the SAB bits (LSb) in the HDB2 byte.
 
#define SNAP_HDB2_PFB_MASK   (0x03U)
 Bit mask of the PFB bits in the HDB2 byte.
 
#define SNAP_HDB2_PFB_POS   (2U)
 Position of the PFB bits (LSb) in the HDB2 byte.
 
#define SNAP_HDB2_ACK_MASK   (0x03U)
 Bit mask of the ACK bits in the HDB2 byte.
 
#define SNAP_HDB2_ACK_POS   (0U)
 Position of the ACK bits (LSb) in the HDB2 byte.
 

Bit mask and position of HDB1 fields

#define SNAP_HDB1_CMD_MASK   (0x01U)
 Bit mask of the CMD bit in the HDB1 byte.
 
#define SNAP_HDB1_CMD_POS   (7U)
 Position of the CMD bit in the HDB1 byte.
 
#define SNAP_HDB1_EDM_MASK   (0x07U)
 Bit mask of the EDM bits in the HDB1 byte.
 
#define SNAP_HDB1_EDM_POS   (4U)
 Position of the EDM bits (LSb) in the HDB1 byte.
 
#define SNAP_HDB1_NDB_MASK   (0x0FU)
 Bit mask of the NDB bits in the HDB1 byte.
 
#define SNAP_HDB1_NDB_POS   (0U)
 Position of the NDB bits (LSb) in the HDB1 byte.
 

Header content

#define SNAP_GET_BITS(integer, mask, pos)   (((unsigned int)(integer) >> (pos)) & (mask))
 Get a subset of bits from an integer. More...
 
#define SNAP_HDB2(pByteArray)   ((pByteArray)[SNAP_INDEX_HDB2])
 Get the HDB2 byte of a frame. More...
 
#define SNAP_HDB1(pByteArray)   ((pByteArray)[SNAP_INDEX_HDB1])
 Get the HDB1 byte of a frame. More...
 
#define SNAP_HDB2_DAB(pByteArray)   (SNAP_GET_BITS(SNAP_HDB2(pByteArray), SNAP_HDB2_DAB_MASK, SNAP_HDB2_DAB_POS))
 Get the DAB bits of a frame. More...
 
#define SNAP_HDB2_SAB(pByteArray)   (SNAP_GET_BITS(SNAP_HDB2(pByteArray), SNAP_HDB2_SAB_MASK, SNAP_HDB2_SAB_POS))
 Get the SAB bits of a frame. More...
 
#define SNAP_HDB2_PFB(pByteArray)   (SNAP_GET_BITS(SNAP_HDB2(pByteArray), SNAP_HDB2_PFB_MASK, SNAP_HDB2_PFB_POS))
 Get the PFB bits of a frame. More...
 
#define SNAP_HDB2_ACK(pByteArray)   (SNAP_GET_BITS(SNAP_HDB2(pByteArray), SNAP_HDB2_ACK_MASK, SNAP_HDB2_ACK_POS))
 Get the ACK bits of a frame. More...
 
#define SNAP_HDB1_CMD(pByteArray)   (SNAP_GET_BITS(SNAP_HDB1(pByteArray), SNAP_HDB1_CMD_MASK, SNAP_HDB1_CMD_POS))
 Get the CMD bit of a frame. More...
 
#define SNAP_HDB1_EDM(pByteArray)   (SNAP_GET_BITS(SNAP_HDB1(pByteArray), SNAP_HDB1_EDM_MASK, SNAP_HDB1_EDM_POS))
 Get the EDM bits of a frame. More...
 
#define SNAP_HDB1_NDB(pByteArray)   (SNAP_GET_BITS(SNAP_HDB1(pByteArray), SNAP_HDB1_NDB_MASK, SNAP_HDB1_NDB_POS))
 Get the NDB bits of a frame. More...
 

Frame and field sizes

#define SNAP_SIZE_SYNC   (1U)
 Size of the sync field.
 
#define SNAP_SIZE_HDB2   (1U)
 Size of the HDB2 field.
 
#define SNAP_SIZE_HDB1   (1U)
 Size of the HDB1 field.
 
#define SNAP_SIZE_HEADER   (SNAP_SIZE_HDB2 + SNAP_SIZE_HDB1)
 Size of the header field.
 
#define SNAP_SIZE_DATA(pByteArray)   (snap_getDataSizeFromNdb(SNAP_HDB1_NDB(pByteArray)))
 Size of the data field based on the NDB bits. More...
 
#define SNAP_SIZE_HASH(pByteArray)   (snap_getHashSizeFromEdm(SNAP_HDB1_EDM(pByteArray)))
 Size of the hash field based on the EDM bits. More...
 
#define SNAP_MIN_SIZE_FRAME   (SNAP_SIZE_SYNC + SNAP_SIZE_HEADER)
 Minimum frame size allowed = 1 (sync) + 2 (header).
 
#define SNAP_MAX_SIZE_FRAME   (528U)
 Maximum frame size allowed = 1 (sync) + 2 (header) + 3 (destination address) + 3 (source address) + 3 (flags) + 512 (data) + 4 (hash).
 
#define SNAP_SIZE_USER_HASH   (0U)
 Size of the user hash field (0 to 4 bytes). It is supposed to be defined by the user in the compilation command.
 

Field indexes

#define SNAP_INDEX_SYNC   (0U)
 Index of the sync byte.
 
#define SNAP_INDEX_HDB2   (1U)
 Index of the HDB2 byte.
 
#define SNAP_INDEX_HDB1   (2U)
 Index of the HDB1 byte.
 
#define SNAP_INDEX_DAB   (3U)
 Index of the first (MSB) destination address byte (if there are any).
 
#define SNAP_INDEX_SAB(pByteArray)   (SNAP_INDEX_DAB + SNAP_HDB2_DAB(pByteArray))
 Index of the first (MSB) source address byte (if there are any), based on the frame header. More...
 
#define SNAP_INDEX_PFB(pByteArray)   (SNAP_INDEX_SAB(pByteArray) + SNAP_HDB2_SAB(pByteArray))
 Index of the first (MSB) protocol flags byte (if there are any), based on the frame header. More...
 
#define SNAP_INDEX_DATA(pByteArray)   (SNAP_INDEX_PFB(pByteArray) + SNAP_HDB2_PFB(pByteArray))
 Index of the first data byte (if there are any), based on the frame header. More...
 
#define SNAP_INDEX_HASH(pByteArray)   (SNAP_INDEX_DATA(pByteArray) + SNAP_SIZE_DATA(pByteArray))
 Index of the first (MSB) hash byte (if there are any), based on the frame header. More...
 

Miscellaneous values

#define SNAP_BROADCAST_ADDRESS   (0U)
 All nodes in the network should accept a packet that has this value as its destination address. No node should have this value as its local address.
 
#define SNAP_SYNC   (0x54U)
 Value of the sync byte. It is the first byte of every frame.
 
#define SNAP_PADDING   (0x00U)
 Value of the byte used in payload padding (when the payload size is greater than the actual data size).
 

Detailed Description

Macros visible to all files that include the library header file. Most macros are for naming constant values, but some are wrappers for functions and other macros.

Macro Definition Documentation

◆ SNAP_GET_BITS

#define SNAP_GET_BITS (   integer,
  mask,
  pos 
)    (((unsigned int)(integer) >> (pos)) & (mask))

Get a subset of bits from an integer.

Parameters
integerSource of the bits.
maskBit mask.
posPosition of the first bit (LSb).

◆ SNAP_HDB2

#define SNAP_HDB2 (   pByteArray)    ((pByteArray)[SNAP_INDEX_HDB2])

Get the HDB2 byte of a frame.

Parameters
pByteArrayPointer to the array of bytes that contains the frame.

◆ SNAP_HDB1

#define SNAP_HDB1 (   pByteArray)    ((pByteArray)[SNAP_INDEX_HDB1])

Get the HDB1 byte of a frame.

Parameters
pByteArrayPointer to the array of bytes that contains the frame.

◆ SNAP_HDB2_DAB

#define SNAP_HDB2_DAB (   pByteArray)    (SNAP_GET_BITS(SNAP_HDB2(pByteArray), SNAP_HDB2_DAB_MASK, SNAP_HDB2_DAB_POS))

Get the DAB bits of a frame.

Parameters
pByteArrayPointer to the array of bytes that contains the frame.

◆ SNAP_HDB2_SAB

#define SNAP_HDB2_SAB (   pByteArray)    (SNAP_GET_BITS(SNAP_HDB2(pByteArray), SNAP_HDB2_SAB_MASK, SNAP_HDB2_SAB_POS))

Get the SAB bits of a frame.

Parameters
pByteArrayPointer to the array of bytes that contains the frame.

◆ SNAP_HDB2_PFB

#define SNAP_HDB2_PFB (   pByteArray)    (SNAP_GET_BITS(SNAP_HDB2(pByteArray), SNAP_HDB2_PFB_MASK, SNAP_HDB2_PFB_POS))

Get the PFB bits of a frame.

Parameters
pByteArrayPointer to the array of bytes that contains the frame.

◆ SNAP_HDB2_ACK

#define SNAP_HDB2_ACK (   pByteArray)    (SNAP_GET_BITS(SNAP_HDB2(pByteArray), SNAP_HDB2_ACK_MASK, SNAP_HDB2_ACK_POS))

Get the ACK bits of a frame.

Parameters
pByteArrayPointer to the array of bytes that contains the frame.

◆ SNAP_HDB1_CMD

#define SNAP_HDB1_CMD (   pByteArray)    (SNAP_GET_BITS(SNAP_HDB1(pByteArray), SNAP_HDB1_CMD_MASK, SNAP_HDB1_CMD_POS))

Get the CMD bit of a frame.

Parameters
pByteArrayPointer to the array of bytes that contains the frame.

◆ SNAP_HDB1_EDM

#define SNAP_HDB1_EDM (   pByteArray)    (SNAP_GET_BITS(SNAP_HDB1(pByteArray), SNAP_HDB1_EDM_MASK, SNAP_HDB1_EDM_POS))

Get the EDM bits of a frame.

Parameters
pByteArrayPointer to the array of bytes that contains the frame.

◆ SNAP_HDB1_NDB

#define SNAP_HDB1_NDB (   pByteArray)    (SNAP_GET_BITS(SNAP_HDB1(pByteArray), SNAP_HDB1_NDB_MASK, SNAP_HDB1_NDB_POS))

Get the NDB bits of a frame.

Parameters
pByteArrayPointer to the array of bytes that contains the frame.

◆ SNAP_SIZE_DATA

#define SNAP_SIZE_DATA (   pByteArray)    (snap_getDataSizeFromNdb(SNAP_HDB1_NDB(pByteArray)))

Size of the data field based on the NDB bits.

Parameters
pByteArrayPointer to the array of bytes that contains the frame.

◆ SNAP_SIZE_HASH

#define SNAP_SIZE_HASH (   pByteArray)    (snap_getHashSizeFromEdm(SNAP_HDB1_EDM(pByteArray)))

Size of the hash field based on the EDM bits.

Parameters
pByteArrayPointer to the array of bytes that contains the frame.

◆ SNAP_INDEX_SAB

#define SNAP_INDEX_SAB (   pByteArray)    (SNAP_INDEX_DAB + SNAP_HDB2_DAB(pByteArray))

Index of the first (MSB) source address byte (if there are any), based on the frame header.

Parameters
pByteArrayPointer to the array of bytes that contains the frame.

◆ SNAP_INDEX_PFB

#define SNAP_INDEX_PFB (   pByteArray)    (SNAP_INDEX_SAB(pByteArray) + SNAP_HDB2_SAB(pByteArray))

Index of the first (MSB) protocol flags byte (if there are any), based on the frame header.

Parameters
pByteArrayPointer to the array of bytes that contains the frame.

◆ SNAP_INDEX_DATA

#define SNAP_INDEX_DATA (   pByteArray)    (SNAP_INDEX_PFB(pByteArray) + SNAP_HDB2_PFB(pByteArray))

Index of the first data byte (if there are any), based on the frame header.

Parameters
pByteArrayPointer to the array of bytes that contains the frame.

◆ SNAP_INDEX_HASH

#define SNAP_INDEX_HASH (   pByteArray)    (SNAP_INDEX_DATA(pByteArray) + SNAP_SIZE_DATA(pByteArray))

Index of the first (MSB) hash byte (if there are any), based on the frame header.

Parameters
pByteArrayPointer to the array of bytes that contains the frame.