ELEC351 SUBMISSION - Same as on the DLE

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers recordsMaster.hpp Source File

recordsMaster.hpp

00001 #ifndef __recordsMaster__ //Inclusion safeguards
00002 #define __recordsMaster__
00003 #include "dateAndTime.hpp"
00004 #include "samplingMaster.hpp"
00005 
00006 
00007 typedef struct __attribute__ ((packed)) { // Store one after another
00008 
00009     TDS_DT          record_DT;   // Type Def Struct _ Date Time
00010     TDS_sensorData  record_Data; // Type Def Struct _ sensor Data
00011 
00012 } TDS_record;                    // Type Def Struct _ record
00013 
00014 
00015 class circularBuffer             // Class _ circular Buffer
00016 {
00017 
00018 private:
00019     TDS_record record[120]; /* Array of 120 TDS_records. Please note
00020     that this is not an instance variable and it does not need to be static
00021     since it is in the scope of the circularBuffer class which will not be
00022     deleted once called, otherwise where will you store your data. */
00023     TDS_record blankRecord;      // Blank record
00024     int bufferLoopBack;          // End of buffer (if END=1-START => Overrite next)
00025     Mutex recordLock;            /* Mutex when working with a data record. This 
00026     mutex is used for writing to ensure that the whole record is written before 
00027     it can be modified or read. Similarly, the mutex is used when reading to 
00028     ensure that the data read belongs to the same record and not to a new record
00029     that could have been written in the meantime. One such example that is 
00030     safeguarded against is the user reading a record when the sampling interupt 
00031     occurs. This would result in Date and Time belonging to one record but the 
00032     sensor data to another.
00033     Mitigation against deadlocks is handled by the nature of the scheduler since
00034     all producer threads push the data to be written to the stack so it is
00035     buffered if the mutex is locked. Even in the case of the Highst priority
00036     producer thread the data is buffered and the thread will be blocked until
00037     another mutex operation (reading or deleting record) is complete. Then the
00038     highest priority thread will write the buffered data.                     */
00039     
00040 public:
00041     circularBuffer();       // Initilise buffer
00042     int write(TDS_record);  // Write single record to buffer
00043     int read(int);          // Read single record from buffer
00044     int del(int);           // Delete single record from buffer
00045     int readAll();          // Read all records from buffer
00046     int delAll();           // Delete all records from buffer
00047     int recNum();           // Returns last record number
00048     ~circularBuffer();      // Warn if buffer destroyed
00049 };
00050 
00051 #endif