forked from Duet3D/RepRapFirmware
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileStore.h
More file actions
60 lines (47 loc) · 1.87 KB
/
FileStore.h
File metadata and controls
60 lines (47 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// This class handles input from, and output to, files.
#ifndef FILESTORE_H
#define FILESTORE_H
typedef uint32_t FilePosition;
const FilePosition noFilePosition = 0xFFFFFFFF;
const size_t FileBufLen = 256; // 512 would be more efficient, but need to free up some RAM first
class FileStore
{
public:
uint8_t Status(); // Returns OR of IOStatus
bool Read(char& b); // Read 1 byte
int Read(char* buf, unsigned int nBytes); // Read a block of nBytes length
bool Write(char b); // Write 1 byte
bool Write(const char *s, unsigned int len); // Write a block of len bytes
bool Write(const char* s); // Write a string
bool Close(); // Shut the file and tidy up
bool Seek(FilePosition pos); // Jump to pos in the file
FilePosition GetPosition() const; // Return the current position in the file, assuming we are reading the file
#if 0 // not currently used
bool GoToEnd(); // Position the file at the end (so you can write on the end).
#endif
FilePosition Length() const; // File size in bytes
float FractionRead() const; // How far in we are
void Duplicate(); // Create a second reference to this file
bool Flush(); // Write remaining buffer data
static float GetAndClearLongestWriteTime(); // Return the longest time it took to write a block to a file, in milliseconds
friend class Platform;
protected:
FileStore(Platform* p);
void Init();
bool Open(const char* directory, const char* fileName, bool write);
private:
bool ReadBuffer();
bool WriteBuffer();
bool InternalWriteBlock(const char *s, unsigned int len);
byte *GetBuffer() { return reinterpret_cast<byte*>(buf32); }
uint32_t buf32[FileBufLen/4];
Platform* platform;
unsigned int bufferPointer;
FIL file;
unsigned int lastBufferEntry;
unsigned int openCount;
bool inUse;
bool writing;
static uint32_t longestWriteTime;
};
#endif