-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIldaReader.cpp
More file actions
75 lines (59 loc) · 1.57 KB
/
IldaReader.cpp
File metadata and controls
75 lines (59 loc) · 1.57 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "IldaReader.h"
#include "Frame.h"
#include <SD.h>
IldaReader::IldaReader() {}
bool IldaReader::init(int csPin) {
Serial.print("Initializing SD card...");
if (!SD.begin(csPin)) {
Serial.println("initialization failed!");
return false;
}
Serial.println("initialization done.");
root = SD.open("/");
Serial.println("Root selected!");
}
bool IldaReader::openFile(String fileName) {
file = SD.open(fileName, FILE_READ);
if (! file) {
Serial.println("Error opening file!");
return false;
}
return true;
}
void IldaReader::readFile() {
// Read first 32 header bytes from the file and check if the first 4 bytes in ASCII are "ILDA".
checkHeader();
// Read actual data from ILD file.
Frame frame;
int t1,t2,i=0;
t1 = micros();
// Read all points from one frame and try again if there are more frames.
while(frame.getFrame(file)) {
Serial.print("Frame ");
Serial.print(++i);
Serial.println(" end");
}
t2 = micros();
// Some measurement.
Serial.print("Read time (us): ");
Serial.println(t2-t1);
}
// Read first 32 header bytes from the file and check if the first 4 bytes in ASCII are "ILDA".
bool IldaReader::checkHeader() {
byte buf[Frame::NUMBER_OF_HEADER_BYTES];
file.read(buf, Frame::NUMBER_OF_HEADER_BYTES);
String header = "";
for (int i = 0; i < 4; i++) {
header += char(buf[i]);
}
if (header != "ILDA") {
Serial.println("INVALID FILE!");
return false;
}
// Return back to start of the file.
file.seek(0);
return true;
}
void IldaReader::closeFile() {
file.close();
}