Skip to content

Commit 98541bd

Browse files
authored
Merge pull request #42 from JordanMcManus/master
refactor accuracyProcessor
2 parents 4c369ed + 826bccb commit 98541bd

File tree

1 file changed

+77
-100
lines changed

1 file changed

+77
-100
lines changed

src/AccuracyProcessor.hpp

Lines changed: 77 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -20,130 +20,107 @@
2020
#endif
2121

2222
#pragma pack(1)
23-
typedef struct{
24-
double time; //GPS seconds of week
25-
double northingSd; //northing standard deviation
26-
double eastingSd; //easting standard deviation
27-
double altitudeSd; //altitude standard deviation
28-
double speedNorthSd; //northing speed standard deviation
29-
double speedEastSd; //easting speed standard deviation
30-
double speedAltitudeSd; //vertical speed standard deviation
31-
double rollSd; //roll standard deviation
32-
double pitchSd; //pitch standard deviation
33-
double headingSd; //heading standard deviation
23+
24+
typedef struct {
25+
double time; //GPS seconds of week
26+
double northingSd; //northing standard deviation
27+
double eastingSd; //easting standard deviation
28+
double altitudeSd; //altitude standard deviation
29+
double speedNorthSd; //northing speed standard deviation
30+
double speedEastSd; //easting speed standard deviation
31+
double speedAltitudeSd; //vertical speed standard deviation
32+
double rollSd; //roll standard deviation
33+
double pitchSd; //pitch standard deviation
34+
double headingSd; //heading standard deviation
3435
} AccuracyEntry;
3536
#pragma pack()
3637

3738
/*!
3839
* \brief AccuracyProcessor class
3940
*/
40-
class AccuracyProcessor{
41-
public:
42-
/**
43-
* Create a AccuracyProcessor
44-
*/
45-
AccuracyProcessor();
46-
47-
/**
48-
* Destroy the AccuracyProcessor
49-
*/
50-
virtual ~AccuracyProcessor();
51-
52-
/**
53-
* Read a SBET file and return true if the reading is successful
54-
*
55-
* @param filename the name of the SBET file
56-
*/
57-
bool readFile(std::string & filename);
58-
59-
/**
60-
* Print the information of the AccuracyEntry
61-
*
62-
* @param entry The AccuracyEntry
63-
*/
64-
virtual void processEntry(AccuracyEntry * entry)=0;
65-
66-
/**
67-
* Called by readFile after file is read
68-
*
69-
*/
70-
virtual void done()=0;
71-
72-
private:
73-
int doRead(int fd,void* buf,unsigned int sz);
74-
int doOpen(const char * filename);
75-
};
41+
class AccuracyProcessor {
42+
public:
7643

77-
/**
78-
* Create a AccuracyProcessor
79-
*/
80-
AccuracyProcessor::AccuracyProcessor(){
44+
/**
45+
* Create a AccuracyProcessor
46+
*/
47+
AccuracyProcessor() {}
8148

82-
}
49+
/**
50+
* Destroy the AccuracyProcessor
51+
*/
52+
virtual ~AccuracyProcessor() {}
8353

84-
/**
85-
* Destroy the AccuracyProcessor
86-
*/
87-
AccuracyProcessor::~AccuracyProcessor(){
54+
/**
55+
* Read a SBET file and return true if reading is successful
56+
*
57+
* @param filename name of the SBET file
58+
*/
59+
bool readFile(std::string & filename) {
60+
int fd;
8861

89-
}
62+
if ((fd = doOpen(filename.c_str())) == -1) {
63+
std::cerr << "Cannot open file " << filename << std::endl;
64+
return false;
65+
}
9066

91-
int AccuracyProcessor::doRead(int fd,void * buffer,unsigned int sz){
67+
AccuracyEntry entry;
9268

93-
#ifdef _WIN32
94-
return _read(fd,buffer,sz);
95-
#endif
69+
int bytesRead;
9670

97-
#ifdef __GNUC__
98-
return read(fd,buffer,sz);
99-
#endif
71+
do {
72+
bytesRead = doRead(fd, (void*) &entry, sizeof (AccuracyEntry));
10073

101-
}
74+
if (bytesRead == sizeof (AccuracyEntry)) {
75+
processEntry(&entry);
76+
}
77+
} while (bytesRead > 0);
10278

103-
int AccuracyProcessor::doOpen(const char * filename){
104-
#ifdef _WIN32
105-
return _open(filename,_O_RDONLY|_O_BINARY);
106-
#endif
79+
if (bytesRead == -1) {
80+
perror("Error while reading file");
81+
}
10782

108-
#ifdef __GNUC__
109-
return open(filename,O_RDONLY);
110-
#endif
111-
}
83+
done();
11284

113-
/**
114-
* Read a SBET file and return true if reading is successful
115-
*
116-
* @param filename name of the SBET file
117-
*/
118-
bool AccuracyProcessor::readFile(std::string & filename){
119-
int fd;
85+
return true;
86+
}
12087

121-
if((fd=doOpen(filename.c_str())) == -1){
122-
std::cerr << "Cannot open file " << filename << std::endl;
123-
return false;
124-
}
88+
/**
89+
* Print the information of the AccuracyEntry
90+
*
91+
* @param entry The AccuracyEntry
92+
*/
93+
virtual void processEntry(AccuracyEntry * entry) = 0;
12594

126-
AccuracyEntry entry;
95+
/**
96+
* Called by readFile after file is read
97+
*
98+
*/
99+
virtual void done() = 0;
127100

128-
int bytesRead;
101+
private:
129102

130-
do{
131-
bytesRead = doRead(fd,(void*)&entry,sizeof(AccuracyEntry));
103+
int doRead(int fd, void * buffer, unsigned int sz) {
132104

133-
if(bytesRead == sizeof(AccuracyEntry)){
134-
processEntry(&entry);
135-
}
136-
}
137-
while(bytesRead > 0);
105+
#ifdef _WIN32
106+
return _read(fd, buffer, sz);
107+
#endif
138108

139-
if(bytesRead == -1){
140-
perror("Error while reading file");
141-
}
142-
143-
done();
109+
#ifdef __GNUC__
110+
return read(fd, buffer, sz);
111+
#endif
144112

145-
return true;
146-
}
113+
}
147114

115+
int doOpen(const char * filename) {
116+
#ifdef _WIN32
117+
return _open(filename, _O_RDONLY | _O_BINARY);
118+
#endif
148119

120+
#ifdef __GNUC__
121+
return open(filename, O_RDONLY);
149122
#endif
123+
}
124+
};
125+
126+
#endif

0 commit comments

Comments
 (0)