huge commit

- worked on about everything
- grid walker using plugable modules
- wifi models
- new distributions
- worked on geometric data-structures
- added typesafe timestamps
- worked on grid-building
- added sensor-classes
- added sensor analysis (step-detection, turn-detection)
- offline data reader
- many test-cases
This commit is contained in:
2016-08-29 08:18:44 +02:00
parent 99ee95ce7b
commit a2c9e575a2
94 changed files with 8298 additions and 257 deletions

84
data/RingBuffer.h Normal file
View File

@@ -0,0 +1,84 @@
#ifndef RINGBUFFER_H
#define RINGBUFFER_H
#include <vector>
#include "../Assertions.h"
template <typename Element> class RingBuffer {
private:
std::vector<Element> data;
int iWrite;
int iRead;
int available;
public:
/** ctor with the size of the buffer */
RingBuffer(const int size) : data(size), iWrite(0), iRead(0), available(0) {
;
}
/** add a new element */
void add(const Element& element) {
Assert::isTrue(available != (int)data.size(), "buffer overflow");
data[iWrite] = element;
++iWrite;
iWrite %= data.size();
++available;
//if (available > (int)data.size()) {available = data.size();}
}
/** get the next element */
const Element& get() {
Assert::isNot0(available, "buffer is empty");
const Element& tmp = data[iRead];
++iRead;
iRead %= data.size();
--available;
if (available < 0) {available = 0;}
return tmp;
}
/** reset the ringbuffer */
void reset() {
iWrite = 0;
iRead = 0;
available = 0;
}
/** is the buffer empty? */
bool empty() const {
return available == 0;
}
/** get the number of available entries */
int size() const {
return available;
}
struct Iterator {
int idx;
int available;
const std::vector<Element>& data;
/** ctor */
Iterator(const int idx, const int available, const std::vector<Element>& data) : idx(idx), available(available), data(data) {;}
bool operator != (const Iterator& other) {return other.available != available;}
void operator ++ () {idx = (idx+1) % data.size(); --available;}
const Element& operator * () const {return data[idx];}
};
Iterator begin() const {return Iterator(iRead, available, data);}
Iterator end() const {return Iterator(iWrite, 0, data);}
};
#endif // RINGBUFFER_H

66
data/Timestamp.h Normal file
View File

@@ -0,0 +1,66 @@
#ifndef TIMESTAMP_H
#define TIMESTAMP_H
/**
* helper-class to handle timestamps
*/
struct Timestamp {
private:
/** internal timestamp in milliseconds */
int64_t _ms;
/** HIDDEN ctor. use factory methods */
explicit Timestamp(const int64_t ms) : _ms(ms) {;}
public:
/** empty ctor */
explicit Timestamp() : _ms(0) {;}
/** get timestamp from the given value which represents milliesconds */
static inline Timestamp fromMS(const int64_t ms) {return Timestamp(ms);}
/** get timestamp from the given value which represents seconds */
static inline Timestamp fromSec(const float sec) {return Timestamp(sec*1000);}
public:
/** get timestamp in milliseconds */
inline uint64_t ms() const {return _ms;}
/** get timestamp in seconds */
inline float sec() const {return _ms/1000.0f;}
public:
/** is this timestamp zero? */
bool isZero() const {return _ms == 0;}
/** equal? */
bool operator == (const Timestamp& o) const {return _ms == o._ms;}
/** not equal? */
bool operator != (const Timestamp& o) const {return _ms != o._ms;}
/** smaller than the given one? */
bool operator < (const Timestamp& o) const {return _ms < o._ms;}
/** greater than the given one? */
bool operator > (const Timestamp& o) const {return _ms > o._ms;}
Timestamp operator - (const Timestamp& o) const {return Timestamp(_ms - o._ms);}
Timestamp operator + (const Timestamp& o) const {return Timestamp(_ms + o._ms);}
/** cast to float */
operator float () const {return sec();}
};
#endif // TIMESTAMP_H