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