14 #ifndef PRIMARYDRIVER_H_
15 #define PRIMARYDRIVER_H_
18 #include "interface.h"
31 virtual void stop() = 0;
39 virtual void start() = 0;
42 virtual void closeInterface() = 0;
45 struct RawData :
public std::vector<char> {
51 template <
typename tVar>
52 inline void push(tVar);
54 inline void push_char(
char);
55 inline void push_int16_t(int16_t);
56 inline void push_int32_t(int32_t);
57 inline void push_double(
double);
61 typedef std::vector<char>::const_iterator const_iterator;
64 template <
typename tVar>
67 const_iterator begin()
const {
return m_data.begin();}
68 const_iterator end()
const {
return m_data.end();}
69 unsigned int size()
const {
return m_data.size();}
70 const std::vector<char> &data()
const {
return m_data;}
71 const_iterator &popIterator() {
return it;}
75 RawDataReader(
const std::vector<char> &data) : m_data(data) {it = data.begin();}
78 const std::vector<char> &m_data;
79 inline char pop_char();
80 inline int16_t pop_int16_t();
81 inline int32_t pop_int32_t();
82 inline double pop_double();
96 void finishWritingRaw(
const shared_ptr<const RawData> &rawdata,
97 const XTime &time_awared,
const XTime &time_recorded);
100 const RawData &rawData()
const {
return *m_rawData;}
103 shared_ptr<const RawData> m_rawData;
108 XPrimaryDriver::RawData::push_char(
char x) {
112 XPrimaryDriver::RawData::push_int16_t(int16_t x) {
114 char *p =
reinterpret_cast<char *
>(&y);
115 #ifdef __BIG_ENDIAN__
116 for(
char *z = p +
sizeof(x) - 1; z >= p; z--) {
118 for(
char *z = p; z < p +
sizeof(x); z++) {
124 XPrimaryDriver::RawData::push_int32_t(int32_t x) {
126 char *p =
reinterpret_cast<char *
>(&y);
127 #ifdef __BIG_ENDIAN__
128 for(
char *z = p +
sizeof(x) - 1; z >= p; z--) {
130 for(
char *z = p; z < p +
sizeof(x); z++) {
136 XPrimaryDriver::RawData::push_double(
double x) {
137 static_assert(
sizeof(
double) == 8,
"Not 8-byte sized double");
139 char *p =
reinterpret_cast<char *
>( &y);
140 #ifdef __BIG_ENDIAN__
141 for(
char *z = p +
sizeof(x) - 1; z >= p; z--) {
143 for(
char *z = p; z < p +
sizeof(x); z++) {
149 XPrimaryDriver::RawDataReader::pop_char() {
154 XPrimaryDriver::RawDataReader::pop_int16_t() {
157 char p[
sizeof(int16_t)];
159 #ifdef __BIG_ENDIAN__
160 for(
char *z = uni.p +
sizeof(uni) - 1; z >= uni.p; z--) {
162 for(
char *z = uni.p; z < uni.p +
sizeof(uni); z++) {
169 XPrimaryDriver::RawDataReader::pop_int32_t() {
172 char p[
sizeof(int32_t)];
174 #ifdef __BIG_ENDIAN__
175 for(
char *z = uni.p +
sizeof(uni) - 1; z >= uni.p; z--) {
177 for(
char *z = uni.p; z < uni.p +
sizeof(uni); z++) {
184 XPrimaryDriver::RawDataReader::pop_double() {
187 char p[
sizeof(double)];
189 #ifdef __BIG_ENDIAN__
190 for(
char *z = uni.p +
sizeof(uni) - 1; z >= uni.p; z--) {
192 for(
char *z = uni.p; z < uni.p +
sizeof(uni); z++) {
201 if(it +
sizeof(
char) > end())
throw XBufferUnderflowRecordError(__FILE__, __LINE__);
206 if(it +
sizeof(
char) > end())
throw XBufferUnderflowRecordError(__FILE__, __LINE__);
207 return static_cast<unsigned char>(pop_char());
211 if(it +
sizeof(int16_t) > end())
throw XBufferUnderflowRecordError(__FILE__, __LINE__);
212 return pop_int16_t();
216 if(it +
sizeof(int16_t) > end())
throw XBufferUnderflowRecordError(__FILE__, __LINE__);
217 return static_cast<uint16_t
>(pop_int16_t());
221 if(it +
sizeof(int32_t) > end())
throw XBufferUnderflowRecordError(__FILE__, __LINE__);
222 return pop_int32_t();
226 if(it +
sizeof(int32_t) > end())
throw XBufferUnderflowRecordError(__FILE__, __LINE__);
227 return static_cast<uint32_t
>(pop_int32_t());
231 if(it +
sizeof(
float) > end())
throw XBufferUnderflowRecordError(__FILE__, __LINE__);
236 static_assert(
sizeof(uni.x) ==
sizeof(uni.y),
"Size mismatch");
237 uni.x = pop_int32_t();
242 if(it +
sizeof(
double) > end())
throw XBufferUnderflowRecordError(__FILE__, __LINE__);
243 static_assert(
sizeof(
double) == 8,
"Not 8-byte sized double");
253 push_char(static_cast<char>(x));
261 push_int16_t(static_cast<int16_t>(x));
269 push_int32_t(static_cast<int32_t>(x));
277 static_assert(
sizeof(uni.x) ==
sizeof(uni.y),
"Size mismatch");