Skip to content

Circular FIFO buffer for Arduino. Specifically for CAN bus messages

Notifications You must be signed in to change notification settings

mackelec/meCANbuffer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 

Repository files navigation

meCANBuffer Library

This Arduino library provides a circular buffer for storing and accessing CAN messages.

Features

  • Store up to BUFFER_SIZE CAN_Message_t messages
  • Check if the buffer is empty or full
  • Push new messages onto the buffer
  • Pop messages from the buffer
  • Detect if any data has been lost due to buffer overflow
  • Clear the data lost flag

USE Cases

This meCANbuffer was designed for the use with CAN libraries.

Types

#define BUFFER_SIZE 100

typedef union
{
    struct
    {
        uint16_t id;
        uint8_t data[8];
        uint8_t port:4;
        uint8_t length:4;
    };
    uint8_t raw[11];
} CAN_Message_t;

Class functions

        /**
         * @brief Construct a new me CAN Buffer object
         */
        meCANBuffer();

        /**
         * @brief Check if the buffer is empty
         * 
         * @return int 
         *  0 if not empty
         *  1 if empty
         */
        int is_empty();

        /**
         * @brief Check if the buffer is full
         * 
         * @return int 
         *  0 if not full
         *  1 if full
         */
        int is_full();

        /**
         * @brief Push a message onto the buffer
         * 
         * @param data 
         */
        void push(CAN_Message_t data);

        /**
         * @brief Pop a message from the buffer
         * 
         * @return CAN_Message_t 
         */
        CAN_Message_t pop();

        /**
         * @brief Check if any data has been lost due to buffer overflow
         * 
         * @return bool 
         */
        bool is_data_lost();

        /**
         * @brief 

About

Circular FIFO buffer for Arduino. Specifically for CAN bus messages

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages