-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathSbetProcessor.cpp
More file actions
76 lines (55 loc) · 1.24 KB
/
SbetProcessor.cpp
File metadata and controls
76 lines (55 loc) · 1.24 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
75
76
#ifndef SBETPROCESSOR_CPP
#define SBETPROCESSOR_CPP
#include "SbetProcessor.hpp"
/**
* Create a SbetProcessor
*/
SbetProcessor::SbetProcessor(){
}
/**
* Destroy the SbetProcessor
*/
SbetProcessor::~SbetProcessor(){
}
int SbetProcessor::doRead(int fd,void * buffer,unsigned int sz){
#ifdef _WIN32
return _read(fd,buffer,sz);
#endif
#ifdef __GNUC__
return read(fd,buffer,sz);
#endif
}
int SbetProcessor::doOpen(const char * filename){
#ifdef _WIN32
return _open(filename,_O_RDONLY|_O_BINARY);
#endif
#ifdef __GNUC__
return open(filename,O_RDONLY);
#endif
}
/**
* Read a SBET file and return true if the reading was successful
*
* @param filename name of the SBET file
*/
bool SbetProcessor::readFile(std::string & filename){
int fd;
if((fd=doOpen(filename.c_str())) == -1){
std::cerr << "Cannot open file " << filename << std::endl;
return false;
}
SbetEntry entry;
int bytesRead;
do{
bytesRead = doRead(fd,(void*)&entry,sizeof(SbetEntry));
if(bytesRead == sizeof(SbetEntry)){
processEntry(&entry);
}
}
while(bytesRead > 0);
if(bytesRead == -1)
perror("Error while reading file");
done();
return true;
}
#endif