Mercurial > hg > beaglert
comparison 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 |
comparison
equal
deleted
inserted
replaced
145:8ff5668bbbad | 153:3b7270949a97 |
---|---|
1 /* | |
2 * WriteMFile.h | |
3 * | |
4 * Created on: 5 Oct 2015 | |
5 * Author: giulio | |
6 */ | |
7 | |
8 #ifndef WRITEMFILE_H_ | |
9 #define WRITEMFILE_H_ | |
10 #include <BeagleRT.h> | |
11 #include <vector> | |
12 #include <stdio.h> | |
13 #include <stdlib.h> | |
14 #include <string.h> | |
15 #include <unistd.h> | |
16 | |
17 class WriteFile { | |
18 private: | |
19 static AuxiliaryTask writeAllFilesTask; | |
20 bool echo; | |
21 char *header; | |
22 char *footer; | |
23 char *stringBuffer; | |
24 int stringBufferLength; | |
25 int bufferLength; | |
26 float* buffer; | |
27 int readPointer; | |
28 int writePointer; | |
29 bool variableOpen; | |
30 char* format; | |
31 int lineLength; | |
32 static int sleepTimeMs; | |
33 FILE *file; | |
34 void writeLine(); | |
35 void writeHeader(); | |
36 void writeFooter(); | |
37 void allocateAndCopyString(const char* source, char** destination); | |
38 void print(const char* string); | |
39 void setLineLength(int newLineLength); | |
40 std::vector<char *> formatTokens; | |
41 static void sanitizeString(char* string); | |
42 static void sanitizeString(char* string, int numberOfArguments); | |
43 static bool isThreadRunning(); | |
44 static bool auxiliaryTaskRunning; | |
45 static bool threadShouldExit(); | |
46 static bool threadIsExiting; | |
47 static bool threadRunning; | |
48 static bool staticConstructed; | |
49 static void staticConstructor(); | |
50 static std::vector<WriteFile *> objAddrs; | |
51 public: | |
52 WriteFile(); | |
53 void setEcho(bool newEcho); | |
54 void setFormat(const char* newFormat); | |
55 void setHeader(const char* newHeader); | |
56 void setFooter(const char* newFooter); | |
57 void log(float* array, int length); | |
58 void log(float value); | |
59 void init(const char* filename); | |
60 | |
61 /** | |
62 * Gets the distance between the write and read pointers of | |
63 * the buffer that holds data to be written to disk. | |
64 */ | |
65 int getOffset(); | |
66 | |
67 /** | |
68 * Inquiries the status of the buffer that holds data to be written to disk. | |
69 * | |
70 * @return a value between 0 and 1, with 0 being buffer full (writing to disk not fast enough) | |
71 * and 1 being buffer empty (writing to disk is fast enough). | |
72 */ | |
73 float getBufferStatus(); | |
74 void writeOutput(); | |
75 ~WriteFile(); | |
76 static int getNumInstances(); | |
77 static void writeAllHeaders(); | |
78 static void writeAllFooters(); | |
79 static void writeAllOutputs(); | |
80 static void startThread(); | |
81 static void stopThread(); | |
82 static void run(); | |
83 }; | |
84 | |
85 #endif /* WRITEMFILE_H_ */ |