1 #ifndef carma_monitor_dbFFIO_h
2 #define carma_monitor_dbFFIO_h
27 virtual void writeFFHeader(
const long frameCount,
const std::string &sig)=0;
30 virtual void dumpInstAverage(
const long frameCount,
const long tagID,
31 short blanking,
short validity,
short v,
33 virtual void dumpInstAverage(
const long frameCount,
const long tagID,
34 short blanking,
short validity,
int v,
36 virtual void dumpInstAverage(
const long frameCount,
const long tagID,
37 short blanking,
short validity,
long v,
39 virtual void dumpInstAverage(
const long frameCount,
const long tagID,
40 short blanking,
short validity,
float v,
42 virtual void dumpInstAverage(
const long frameCount,
const long tagID,
43 short blanking,
short validity,
double v,
45 virtual void dumpInstAverage(
const long frameCount,
const long tagID,
46 short blanking,
short validity,
47 const std::complex<float> &v,
50 virtual void dumpInstAverage(
const long frameCount,
const long tagID,
51 short blanking,
short validity,
52 const std::string &v,
int dmy=0)=0;
56 bool readFFHeader(
long &frameCount, std::string &sig);
58 virtual bool readInstAverage(
long &frameCount,
long &tagID,
59 short &blanking,
short &validity,
60 short &v,
int &iSample)=0;
61 virtual bool readInstAverage(
long &frameCount,
long &tagID,
62 short &blanking,
short &validity,
63 int &v,
int &iSample)=0;
65 virtual bool readInstAverage(
long &frameCount,
long &tagID,
66 short &blanking,
short &validity,
67 long &v,
int &iSample)=0;
68 virtual bool readInstAverage(
long &frameCount,
long &tagID,
69 short &blanking,
short &validity,
70 float &v,
int &iSample)=0;
71 virtual bool readInstAverage(
long &frameCount,
long &tagID,
72 short &blanking,
short &validity,
73 double &v,
int &iSample)=0;
74 virtual bool readInstAverage(
long &frameCount,
long &tagID,
75 short &blanking,
short &validity,
76 std::complex<float> &v,
int &iSample)=0;
77 virtual bool readInstAverage(
long &frameCount,
long &tagID,
78 short &blanking,
short &validity,
83 virtual void dumpLongAverage(
const long frameCount,
const long tagID,
84 short blanking,
short validity,
86 short maxValue,
short minValue,
88 short nValidSamples,
int nTotalSamples)=0;
89 virtual void dumpLongAverage(
const long frameCount,
const long tagID,
90 short blanking,
short validity,
92 int maxValue,
int minValue,
94 short nValidSamples,
int nTotalSamples)=0;
95 virtual void dumpLongAverage(
const long frameCount,
const long tagID,
96 short blanking,
short validity,
98 long maxValue,
long minValue,
100 short nValidSamples,
int nTotalSamples)=0;
101 virtual void dumpLongAverage(
const long frameCount,
const long tagID,
102 short blanking,
short validity,
float v,
103 float maxValue,
float minValue,
105 short nValidSamples,
int nTotalSamples)=0;
106 virtual void dumpLongAverage(
const long frameCount,
const long tagID,
107 short blanking,
short validity,
double v,
108 double maxValue,
double minValue,
110 short nValidSamples,
int nTotalSamples)=0;
111 virtual void dumpLongAverage(
const long frameCount,
const long tagID,
112 short blanking,
short validity,
113 const std::complex<float> &v,
114 const std::complex<float> maxValue,
115 const std::complex<float> minValue,
117 short nValidSamples,
int nTotalSamples)=0;
118 virtual void dumpLongAverage(
const long frameCount,
const long tagID,
119 short blanking,
short validity,
120 const std::string &v,
121 short nValidSamples,
int nTotalSamples)=0;
126 virtual bool readLongAverage(
long &frameCount,
long &tagID,
127 short &blanking,
short &validity,
129 short &maxValue,
short &minValue,
131 short &nValidSamples,
132 int &nTotalSamples)=0;
133 virtual bool readLongAverage(
long &frameCount,
long &tagID,
134 short &blanking,
short &validity,
136 int &maxValue,
int &minValue,
138 short &nValidSamples,
139 int &nTotalSamples)=0;
140 virtual bool readLongAverage(
long &frameCount,
long &tagID,
141 short &blanking,
short &validity,
143 long &maxValue,
long &minValue,
145 short &nValidSamples,
146 int &nTotalSamples)=0;
147 virtual bool readLongAverage(
long &frameCount,
long &tagID,
148 short &blanking,
short &validity,
150 float &maxValue,
float &minValue,
152 short &nValidSamples,
153 int &nTotalSamples)=0;
154 virtual bool readLongAverage(
long &frameCount,
long &tagID,
155 short &blanking,
short &validity,
157 double &maxValue,
double &minValue,
159 short &nValidSamples,
160 int &nTotalSamples)=0;
161 virtual bool readLongAverage(
long &frameCount,
long &tagID,
162 short &blanking,
short &validity,
163 std::complex<float> &maxValue,
164 std::complex<float> &minValue,
165 std::complex<float> &v,
167 short &nValidSamples,
168 int &nTotalSamples)=0;
169 virtual bool readLongAverage(
long &frameCount,
long &tagID,
170 short &blanking,
short &validity,
172 short &nValidSamples,
173 int &nTotalSamples)=0;
177 enum RECORD_TYPE { RECORD_UNKNOWN=-1, RECORD_SHORT, RECORD_INTEGER,
178 RECORD_LONG, RECORD_FLOAT, RECORD_DOUBLE,
179 RECORD_COMPLEX, RECORD_STRING
183 virtual bool open(
const std::string &fileName,
bool isWrite)=0;
184 bool open(
const std::string &fileName, std::ios_base::openmode openmode);
185 virtual bool close();
186 virtual void flush();
187 inline bool isWrite(){
return isWrite_ && isOpen();}
188 inline bool isRead(){
return !isWrite_ && isOpen();}
189 inline bool eof()
const {
return file_.eof();}
190 bool isOpen(){
return file_.is_open();}
191 virtual bool getRecordInfo(RECORD_TYPE &mvt,
192 unsigned &recordCount)=0;
193 static std::string valuetypeToString(
int valuetype);
196 virtual bool fillBuffer() = 0;
198 virtual void writeBuffer() = 0;
201 std::string fileName_;
202 std::string askedFileName_;
218 class dbFFIOa :
public dbFFIO {
223 virtual void writeFFHeader(
const long frameCount,
const std::string &sig);
225 virtual void dumpInstAverage(
const long frameCount,
const long tagID,
226 short blanking,
short validity,
short v,
228 virtual void dumpInstAverage(
const long frameCount,
const long tagID,
229 short blanking,
short validity,
int v,
231 virtual void dumpInstAverage(
const long frameCount,
const long tagID,
232 short blanking,
short validity,
long v,
234 virtual void dumpInstAverage(
const long frameCount,
const long tagID,
235 short blanking,
short validity,
float v,
237 virtual void dumpInstAverage(
const long frameCount,
const long tagID,
238 short blanking,
short validity,
double v,
240 virtual void dumpInstAverage(
const long frameCount,
const long tagID,
241 short blanking,
short validity,
242 const std::complex<float> &v,
244 virtual void dumpInstAverage(
const long frameCount,
const long tagID,
245 short blanking,
short validity,
246 const std::string &v,
int dmy=0);
248 virtual bool readInstAverage(
long &frameCount,
long &tagID,
249 short &blanking,
short &validity,
250 short &v,
int &iSample);
251 virtual bool readInstAverage(
long &frameCount,
long &tagID,
252 short &blanking,
short &validity,
253 int &v,
int &iSample);
254 virtual bool readInstAverage(
long &frameCount,
long &tagID,
255 short &blanking,
short &validity,
256 long &v,
int &iSample);
257 virtual bool readInstAverage(
long &frameCount,
long &tagID,
258 short &blanking,
short &validity,
259 float &v,
int &iSample);
260 virtual bool readInstAverage(
long &frameCount,
long &tagID,
261 short &blanking,
short &validity,
262 double &v,
int &iSample);
263 virtual bool readInstAverage(
long &frameCount,
long &tagID,
264 short &blanking,
short &validity,
265 std::complex<float> &v,
int &iSample);
266 virtual bool readInstAverage(
long &frameCount,
long &tagID,
267 short &blanking,
short &validity,
270 virtual void dumpLongAverage(
const long frameCount,
const long tagID,
271 short blanking,
short validity,
short v,
272 short maxValue,
short minValue,
274 short nValidSamples,
int nTotalSamples);
275 virtual void dumpLongAverage(
const long frameCount,
const long tagID,
276 short blanking,
short validity,
int v,
277 int maxValue,
int minValue,
279 short nValidSamples,
int nTotalSamples);
280 virtual void dumpLongAverage(
const long frameCount,
const long tagID,
281 short blanking,
short validity,
long v,
282 long maxValue,
long minValue,
284 short nValidSamples,
int nTotalSamples);
285 virtual void dumpLongAverage(
const long frameCount,
const long tagID,
286 short blanking,
short validity,
float v,
287 float maxValue,
float minValue,
289 short nValidSamples,
int nTotalSamples);
290 virtual void dumpLongAverage(
const long frameCount,
const long tagID,
291 short blanking,
short validity,
double v,
292 double maxValue,
double minValue,
294 short nValidSamples,
int nTotalSamples);
295 virtual void dumpLongAverage(
const long frameCount,
const long tagID,
296 short blanking,
short validity,
297 const std::complex<float> &v,
298 const std::complex<float> maxValue,
299 const std::complex<float> minValue,
301 short nValidSamples,
int nTotalSamples);
302 virtual void dumpLongAverage(
const long frameCount,
const long tagID,
303 short blanking,
short validity,
304 const std::string &v,
305 short nValidSamples,
int nTotalSamples);
307 virtual bool readLongAverage(
long &frameCount,
long &tagID,
308 short &blanking,
short &validity,
310 short &maxValue,
short &minValue,
312 short &nValidSamples,
314 virtual bool readLongAverage(
long &frameCount,
long &tagID,
315 short &blanking,
short &validity,
317 int &maxValue,
int &minValue,
319 short &nValidSamples,
321 virtual bool readLongAverage(
long &frameCount,
long &tagID,
322 short &blanking,
short &validity,
324 long &maxValue,
long &minValue,
326 short &nValidSamples,
328 virtual bool readLongAverage(
long &frameCount,
long &tagID,
329 short &blanking,
short &validity,
331 float &maxValue,
float &minValue,
333 short &nValidSamples,
335 virtual bool readLongAverage(
long &frameCount,
long &tagID,
336 short &blanking,
short &validity,
338 double &maxValue,
double &minValue,
340 short &nValidSamples,
342 virtual bool readLongAverage(
long &frameCount,
long &tagID,
343 short &blanking,
short &validity,
344 std::complex<float> &v,
345 std::complex<float> &maxValue,
346 std::complex<float> &minValue,
348 short &nValidSamples,
350 virtual bool readLongAverage(
long &frameCount,
long &tagID,
351 short &blanking,
short &validity,
353 short &nValidSamples,
356 virtual bool open(
const std::string &fileName,
bool write);
357 virtual bool close();
358 virtual bool getRecordInfo(RECORD_TYPE &mvt,
359 unsigned &recordCount);
361 virtual bool fillBuffer();
362 virtual bool checkBuffer();
363 virtual void writeBuffer();
365 unsigned int getMonitorDataFlatFileHeaderLength(
const unsigned& sigLength) {
366 return (19 + sigLength);}
368 void buildRecordFormat(
const long frameCount,
const long tagID,
369 short blanking,
short validity,
const char *fmt);
371 bool getAverageProps(
long &frameCount,
long &tagID,
372 short &blanking,
short &validity);
375 bool tokenToValue(
unsigned int index,
short &v);
376 bool tokenToValue(
unsigned int index,
int &v);
377 bool tokenToValue(
unsigned int index,
long int &v);
378 bool tokenToValue(
unsigned int index,
float &v);
379 bool tokenToValue(
unsigned int index,
double &v);
380 bool tokenToValue(
unsigned int index, std::complex<float> &v);
381 bool tokenToValue(
unsigned int index, std::string &v);
385 char lineBuffer_[512];
386 std::vector<const char *> tokens_;
392 class dbFFIOb :
public dbFFIO {
396 virtual bool open(
const std::string &fileName,
bool write);
397 virtual bool close();
404 virtual bool getRecordInfo(RECORD_TYPE &mvt,
405 unsigned &recordCount);
408 virtual void writeFFHeader(
const long frameCount,
const std::string &sig);
414 static bool copyToASCII(
const std::string &infileName,
const
415 std::string &outfileName,
bool isInstant);
417 virtual void dumpInstAverage(
const long frameCount,
const long tagID,
418 short blanking,
short validity,
short v,
420 virtual void dumpInstAverage(
const long frameCount,
const long tagID,
421 short blanking,
short validity,
int v,
423 virtual void dumpInstAverage(
const long frameCount,
const long tagID,
424 short blanking,
short validity,
long v,
426 virtual void dumpInstAverage(
const long frameCount,
const long tagID,
427 short blanking,
short validity,
428 float v,
int iSample);
429 virtual void dumpInstAverage(
const long frameCount,
const long tagID,
430 short blanking,
short validity,
431 double v,
int iSample);
432 virtual void dumpInstAverage(
const long frameCount,
const long tagID,
433 short blanking,
short validity,
434 const std::complex<float> &v,
436 virtual void dumpInstAverage(
const long frameCount,
const long tagID,
437 short blanking,
short validity,
438 const std::string &v,
int dmy=0);
440 virtual bool readInstAverage(
long &frameCount,
long &tagID,
441 short &blanking,
short &validity,
442 short &v,
int &iSample);
443 virtual bool readInstAverage(
long &frameCount,
long &tagID,
444 short &blanking,
short &validity,
445 int &v,
int &iSample);
446 virtual bool readInstAverage(
long &frameCount,
long &tagID,
447 short &blanking,
short &validity,
448 long &v,
int &iSample);
449 virtual bool readInstAverage(
long &frameCount,
long &tagID,
450 short &blanking,
short &validity,
451 float &v,
int &iSample);
452 virtual bool readInstAverage(
long &frameCount,
long &tagID,
453 short &blanking,
short &validity,
454 double &v,
int &iSample);
455 virtual bool readInstAverage(
long &frameCount,
long &tagID,
456 short &blanking,
short &validity,
457 std::complex<float> &v,
int &iSample);
458 virtual bool readInstAverage(
long &frameCount,
long &tagID,
459 short &blanking,
short &validity,
462 virtual void dumpLongAverage(
const long frameCount,
const long tagID,
463 short blanking,
short validity,
short v,
464 short maxValue,
short minValue,
466 short nValidSamples,
int nTotalSamples);
467 virtual void dumpLongAverage(
const long frameCount,
const long tagID,
468 short blanking,
short validity,
int v,
469 int maxValue,
int minValue,
471 short nValidSamples,
int nTotalSamples);
472 virtual void dumpLongAverage(
const long frameCount,
const long tagID,
473 short blanking,
short validity,
long v,
474 long maxValue,
long minValue,
476 short nValidSamples,
int nTotalSamples);
477 virtual void dumpLongAverage(
const long frameCount,
const long tagID,
478 short blanking,
short validity,
float v,
479 float maxValue,
float minValue,
481 short nValidSamples,
int nTotalSamples);
482 virtual void dumpLongAverage(
const long frameCount,
const long tagID,
483 short blanking,
short validity,
double v,
484 double maxValue,
double minValue,
486 short nValidSamples,
int nTotalSamples);
487 virtual void dumpLongAverage(
const long frameCount,
const long tagID,
488 short blanking,
short validity,
489 const std::complex<float> &v,
490 const std::complex<float> maxValue,
491 const std::complex<float> minValue,
493 short nValidSamples,
int nTotalSamples);
494 virtual void dumpLongAverage(
const long frameCount,
const long tagID,
495 short blanking,
short validity,
496 const std::string &v,
497 short nValidSamples,
int nTotalSamples);
499 virtual bool readLongAverage(
long &frameCount,
long &tagID,
500 short &blanking,
short &validity,
502 short &maxValue,
short &minValue,
504 short &nValidSamples,
506 virtual bool readLongAverage(
long &frameCount,
long &tagID,
507 short &blanking,
short &validity,
509 int &maxValue,
int &minValue,
511 short &nValidSamples,
513 virtual bool readLongAverage(
long &frameCount,
long &tagID,
514 short &blanking,
short &validity,
516 long &maxValue,
long &minValue,
518 short &nValidSamples,
520 virtual bool readLongAverage(
long &frameCount,
long &tagID,
521 short &blanking,
short &validity,
523 float &maxValue,
float &minValue,
525 short &nValidSamples,
527 virtual bool readLongAverage(
long &frameCount,
long &tagID,
528 short &blanking,
short &validity,
530 double &maxValue,
double &minValue,
532 short &nValidSamples,
534 virtual bool readLongAverage(
long &frameCount,
long &tagID,
535 short &blanking,
short &validity,
536 std::complex<float> &v,
537 std::complex<float> &maxValue,
538 std::complex<float> &minValue,
540 short &nValidSamples,
542 virtual bool readLongAverage(
long &frameCount,
long &tagID,
543 short &blanking,
short &validity,
545 short &nValidSamples,
550 static bool copyInstantAverages(dbFFIOb &in, dbFFIOa &out);
551 static bool copyLongAverages(dbFFIOb &in, dbFFIOa &out);
553 virtual bool fillBuffer();
555 virtual bool checkBuffer(RECORD_TYPE mvt,
int size);
556 virtual bool checkBuffer(
int size);
557 virtual void writeBuffer();
558 inline void pack(
short v){pack(v, &byteArray_, &offset_);}
559 inline void pack(
unsigned short v){pack(v, &byteArray_, &offset_);}
560 inline void pack(
int v){pack(v, &byteArray_, &offset_);}
561 inline void pack(
unsigned v){pack(v, &byteArray_, &offset_);}
562 inline void pack(
long v){pack(v, &byteArray_, &offset_);}
563 inline void pack(
float v){pack(v, &byteArray_, &offset_);}
564 inline void pack(
double v){pack(v, &byteArray_, &offset_);}
565 inline void pack(
const std::complex<float> &v)
566 {pack(v, &byteArray_, &offset_);}
567 inline void pack(
const std::string &v){pack(v, &byteArray_, &offset_);}
569 inline void unpack(
short &v){unpack(v, byteArray_, &offset_);}
570 inline void unpack(
unsigned short &v){unpack(v, byteArray_, &offset_);}
571 inline void unpack(
int &v){unpack(v, byteArray_, &offset_);}
572 inline void unpack(
unsigned &v){unpack(v, byteArray_, &offset_);}
573 inline void unpack(
long &v){unpack(v, byteArray_, &offset_);}
574 inline void unpack(
float &v){unpack(v, byteArray_, &offset_);}
575 inline void unpack(
double &v){unpack(v, byteArray_, &offset_);}
576 inline void unpack(std::complex<float> &v){unpack(v, byteArray_, &offset_);}
577 inline void unpack(std::string &v){unpack(v, byteArray_, &offset_);}
586 static inline void pack(
int tmp, std::vector<char>* byteArray,
589 int size =
sizeof(tmp);
590 memcpy(&(*byteArray)[*offset], &tmp, size);
598 static inline void pack(
unsigned tmp, std::vector<char>* byteArray,
601 int size =
sizeof(tmp);
602 memcpy(&(*byteArray)[*offset], &tmp, size);
610 static inline void pack(
char tmp, std::vector<char>* byteArray,
613 int size =
sizeof(tmp);
614 memcpy(&(*byteArray)[*offset], &tmp, size);
618 static inline void pack(
const std::string &v,
619 std::vector<char>* byteArray,
622 int size = v.size() + 1;
623 memcpy(&(*byteArray)[*offset], v.c_str(), size);
631 static inline void pack(
bool tmp, std::vector<char>* byteArray,
634 int size =
sizeof(tmp);
635 memcpy(&(*byteArray)[*offset], &tmp, size);
643 static inline void pack(
short tmp, std::vector<char>* byteArray,
645 int size =
sizeof(tmp);
646 memcpy(&(*byteArray)[*offset], &tmp, size);
650 static inline void pack(
unsigned short tmp, std::vector<char>* byteArray,
654 int size =
sizeof(tmp);
655 memcpy(&(*byteArray)[*offset], &tmp, size);
663 static inline void pack(
long tmp, std::vector<char>* byteArray,
666 int size =
sizeof(tmp);
667 memcpy(&(*byteArray)[*offset], &tmp, size);
675 static inline void pack(
float tmp, std::vector<char>* byteArray,
678 int size =
sizeof(tmp);
679 memcpy(&(*byteArray)[*offset], &tmp, size);
687 static inline void pack(
double tmp, std::vector<char>* byteArray,
690 int size =
sizeof(tmp);
691 memcpy(&(*byteArray)[*offset], &tmp, size);
699 static inline void pack(
const std::complex<float>& tmpc,
700 std::vector<char>* byteArray,
703 int size =
sizeof(std::complex<float>);
704 int size2 =
static_cast< int >(size * .5);
705 float tmp = tmpc.real();
706 memcpy(&(*byteArray)[*offset], &tmp, size2);
710 memcpy(&(*byteArray)[*offset], &tmp, size2);
714 static inline void unpack(std::string &val,
715 const std::vector<char>& byteArray,
717 val = &byteArray[*offset];
718 *offset += val.size() + 1;
724 static inline void unpack(
bool& val,
725 const std::vector<char>& byteArray,
727 memcpy(&val, &byteArray[*offset],
sizeof(val));
728 *offset +=
sizeof(val);
734 static inline void unpack(
short& val,
735 const std::vector<char>& byteArray,
737 memcpy(&val, &byteArray[*offset],
sizeof(val));
738 *offset +=
sizeof(val);
741 static inline void unpack(
unsigned short& val,
742 const std::vector<char>& byteArray,
744 memcpy(&val, &byteArray[*offset],
sizeof(val));
745 *offset +=
sizeof(val);
751 static inline void unpack(
int& val,
752 const std::vector<char>& byteArray,
754 memcpy(&val, &byteArray[*offset],
sizeof(val));
755 *offset +=
sizeof(val);
761 static inline void unpack(
unsigned& val,
762 const std::vector<char>& byteArray,
764 memcpy(&val, &byteArray[*offset],
sizeof(val));
765 *offset +=
sizeof(val);
771 static inline void unpack(
long& val,
772 const std::vector<char>& byteArray,
774 memcpy(&val, &byteArray[*offset],
sizeof(val));
775 *offset +=
sizeof(val);
781 static inline void unpack(
float& val,
782 const std::vector<char>& byteArray,
784 memcpy(&val, &byteArray[*offset],
sizeof(val));
785 *offset +=
sizeof(val);
792 static inline void unpack(
double& val,
793 const std::vector<char>& byteArray,
795 memcpy(&val, &byteArray[*offset],
sizeof(val));
796 *offset +=
sizeof(val);
802 static inline void unpack(std::complex<float>& tmpv,
803 const std::vector<char>& byteArray,
805 int size =
sizeof(std::complex<float>);
806 int size2 =
static_cast< int >(size * .5);
809 memcpy(&real, &byteArray[*offset], size2);
811 memcpy(&imag, &byteArray[*offset], size2);
814 tmpv = std::complex<float>(real, imag);
822 static inline void unpack(std::vector<short>& tmpv,
823 const std::vector<char>& byteArray,
825 int size = tmpv.size() *
sizeof(short);
826 memcpy(&tmpv[0], &byteArray[*offset], size);
837 static inline void unpack(std::vector<int>& tmpv,
838 const std::vector<char>& byteArray,
840 int size = tmpv.size() *
sizeof(int);
841 memcpy(&tmpv[0], &byteArray[*offset], size);
853 static inline void unpack(std::vector<float>& tmpv,
854 const std::vector<char>& byteArray,
856 int size = tmpv.size() *
sizeof(float);
857 memcpy(&tmpv[0], &byteArray[*offset], size);
866 static inline void unpack(std::vector<std::complex<float> >& tmpv,
867 const std::vector<char>& byteArray,
869 int length = tmpv.size();
870 int size2 =
sizeof(float);
874 for (
int idx = 0; idx < length; ++idx) {
875 memcpy(&real, &byteArray[*offset], size2);
877 memcpy(&imag, &byteArray[*offset], size2);
879 tmpv[idx] = std::complex<float>(real, imag);
886 bool startRecordGroup(
int mvt);
887 bool endRecordGroup();
890 void incRecordInfo(
int size){recordCount_++;recordBytes_ += size;}
891 void decRecordInfo(
int size){recordCount_--;recordBytes_ -= size;}
894 std::vector<char> byteArray_;
898 std::ostream::pos_type recordStart_;
900 unsigned recordCount_;
901 unsigned recordBytes_;