Mercurial > hg > beaglert
view include/WriteFile.h @ 153:3b7270949a97
Added WriteFile class to log data to disc in a low priority thread
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Wed, 07 Oct 2015 20:58:53 +0100 |
parents | |
children | f36313cbb55d |
line wrap: on
line source
/* * WriteMFile.h * * Created on: 5 Oct 2015 * Author: giulio */ #ifndef WRITEMFILE_H_ #define WRITEMFILE_H_ #include <BeagleRT.h> #include <vector> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> class WriteFile { private: static AuxiliaryTask writeAllFilesTask; bool echo; char *header; char *footer; char *stringBuffer; int stringBufferLength; int bufferLength; float* buffer; int readPointer; int writePointer; bool variableOpen; char* format; int lineLength; static int sleepTimeMs; FILE *file; void writeLine(); void writeHeader(); void writeFooter(); void allocateAndCopyString(const char* source, char** destination); void print(const char* string); void setLineLength(int newLineLength); std::vector<char *> formatTokens; static void sanitizeString(char* string); static void sanitizeString(char* string, int numberOfArguments); static bool isThreadRunning(); static bool auxiliaryTaskRunning; static bool threadShouldExit(); static bool threadIsExiting; static bool threadRunning; static bool staticConstructed; static void staticConstructor(); static std::vector<WriteFile *> objAddrs; public: WriteFile(); void setEcho(bool newEcho); void setFormat(const char* newFormat); void setHeader(const char* newHeader); void setFooter(const char* newFooter); void log(float* array, int length); void log(float value); void init(const char* filename); /** * Gets the distance between the write and read pointers of * the buffer that holds data to be written to disk. */ int getOffset(); /** * Inquiries the status of the buffer that holds data to be written to disk. * * @return a value between 0 and 1, with 0 being buffer full (writing to disk not fast enough) * and 1 being buffer empty (writing to disk is fast enough). */ float getBufferStatus(); void writeOutput(); ~WriteFile(); static int getNumInstances(); static void writeAllHeaders(); static void writeAllFooters(); static void writeAllOutputs(); static void startThread(); static void stopThread(); static void run(); }; #endif /* WRITEMFILE_H_ */