Baseline for testing

Dependents:   mbed_escm2000

Revision:
0:929bb73983c5
Child:
1:aaddf80105fe
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EventLog.h	Thu Jul 25 00:43:28 2019 +0000
@@ -0,0 +1,117 @@
+#ifndef _EVENT_LOG_
+#define _EVENT_LOG_
+
+/* fault log */
+#include "mbed.h"
+
+#define  MAX_EVENT_LENGTH 40
+#define  MAX_EVENTS       50
+
+class ESCM_Event
+{
+public:
+
+    int port;
+    int address;
+    char timeStr[MAX_EVENT_LENGTH];
+
+};
+
+class ESCM_EventLog
+{
+
+public:
+
+
+    ESCM_EventLog();
+    virtual ~ESCM_EventLog();
+    
+    ESCM_Event events[MAX_EVENTS] ;
+    
+    void init();
+    int  load();
+    void save();
+    void display(Serial *pc);
+    void add(int address);
+    void add(int address, char* timeStamp);
+    void clear();
+
+    static const int max_size_ = 5;
+    
+    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