Baseline for testing

Dependents:   mbed_escm2000

EventLog.h

Committer:
foxbrianr
Date:
2019-09-12
Revision:
1:aaddf80105fe
Parent:
0:929bb73983c5
Child:
2:486d068deff9

File content as of revision 1:aaddf80105fe:

#ifndef _EVENT_LOG_
#define _EVENT_LOG_

/* fault log */
#include "mbed.h"

#define  MAX_EVENT_LENGTH 40
#define  MAX_EVENTS       50

class ESCM_Event
{
public:

    uint16_t port;
    uint16_t address;
    uint16_t hours;
    uint16_t mins;
    uint16_t secs;
    uint16_t month;
    uint16_t day;
    uint16_t year;
    
    
    ESCM_Event();
    ESCM_Event(uint16_t address);
    
    
    void getTime (char* buffer);
    void setTimeNow(void);
    

};

class ESCM_EventLog
{

public:


    ESCM_EventLog();
    virtual ~ESCM_EventLog();
    
    ESCM_Event events[MAX_EVENTS] ;
    
    int init();
    int load();
    int save();
    
    void display(Serial *pc);
    void add(uint16_t address);
    void add(uint16_t address, uint16_t port);
    void add(uint16_t address, char* timeStamp);
    void clear();
    ESCM_Event * index (int pos );


    static const int max_size_ = 50;
    
    int head_ ;
    int tail_ ;
    bool full_ ;
    
    void put(ESCM_Event item){
        
        events[head_] = item;

        head_ = (head_ + 1) % max_size_;
        full_ = head_ == tail_;
        
        if(full_)    
        {    
            tail_ = (tail_ + 1) % max_size_;
        }
    
    }
    
    ESCM_Event get() {
           
        if(empty())
        {
            return ESCM_Event();
        }
    
        //Read data and advance the tail (we now have a free space)
        ESCM_Event val = events[tail_];
        full_ = false;
        tail_ = (tail_ + 1) % max_size_;
        
        
        return val;
    
    }
    
    void reset() 
    {
        head_ = tail_;
        full_ = false;
    }
    
    bool empty() const
    {
        
        //if head and tail are equal, we are empty
        return (!full_ && (head_ == tail_));
    }
    
    bool full() const
    {
        //If tail is ahead the head by 1, we are full
        return full_;
    }
    
    int capacity() const
    {
        return max_size_;
    }
    
    int size() const
    {
        int size = max_size_;
        if(!full_)
        {
            if(head_ >= tail_)
            {
                size = head_ - tail_;
            }
            else
            {
                size = max_size_ + head_ - tail_;
            }
        }
        return size;
   }
};
#endif