implemented conversion for 16bit floats
This commit is contained in:
parent
f6240a1789
commit
899582b0c1
599
csv/VehicleSpeed_HS.csv
Normal file
599
csv/VehicleSpeed_HS.csv
Normal file
@ -0,0 +1,599 @@
|
|||||||
|
5.93
|
||||||
|
5.92
|
||||||
|
5.9
|
||||||
|
5.9
|
||||||
|
5.89
|
||||||
|
5.89
|
||||||
|
5.87
|
||||||
|
5.84
|
||||||
|
5.83
|
||||||
|
5.81
|
||||||
|
5.79
|
||||||
|
5.78
|
||||||
|
5.76
|
||||||
|
5.75
|
||||||
|
5.74
|
||||||
|
5.74
|
||||||
|
5.73
|
||||||
|
5.73
|
||||||
|
5.72
|
||||||
|
5.71
|
||||||
|
5.71
|
||||||
|
5.69
|
||||||
|
5.69
|
||||||
|
5.68
|
||||||
|
5.66
|
||||||
|
5.63
|
||||||
|
5.62
|
||||||
|
5.6
|
||||||
|
5.58
|
||||||
|
5.57
|
||||||
|
5.55
|
||||||
|
5.53
|
||||||
|
5.51
|
||||||
|
5.5
|
||||||
|
5.47
|
||||||
|
5.45
|
||||||
|
5.42
|
||||||
|
5.4
|
||||||
|
5.38
|
||||||
|
5.35
|
||||||
|
5.31
|
||||||
|
5.28
|
||||||
|
5.27
|
||||||
|
5.24
|
||||||
|
5.19
|
||||||
|
5.16
|
||||||
|
5.14
|
||||||
|
7.67
|
||||||
|
5.06
|
||||||
|
5.02
|
||||||
|
5
|
||||||
|
4.97
|
||||||
|
4.92
|
||||||
|
4.88
|
||||||
|
4.86
|
||||||
|
4.82
|
||||||
|
4.77
|
||||||
|
4.74
|
||||||
|
4.7
|
||||||
|
4.66
|
||||||
|
4.62
|
||||||
|
4.58
|
||||||
|
4.54
|
||||||
|
4.48
|
||||||
|
4.43
|
||||||
|
4.37
|
||||||
|
4.31
|
||||||
|
4.24
|
||||||
|
4.18
|
||||||
|
4.13
|
||||||
|
4.06
|
||||||
|
3.98
|
||||||
|
3.91
|
||||||
|
3.83
|
||||||
|
3.77
|
||||||
|
3.72
|
||||||
|
3.64
|
||||||
|
3.57
|
||||||
|
3.51
|
||||||
|
3.44
|
||||||
|
3.39
|
||||||
|
3.33
|
||||||
|
3.28
|
||||||
|
3.24
|
||||||
|
3.17
|
||||||
|
3.11
|
||||||
|
3.06
|
||||||
|
3.01
|
||||||
|
2.96
|
||||||
|
2.92
|
||||||
|
2.88
|
||||||
|
2.83
|
||||||
|
2.79
|
||||||
|
2.75
|
||||||
|
2.71
|
||||||
|
2.68
|
||||||
|
2.64
|
||||||
|
2.61
|
||||||
|
2.59
|
||||||
|
2.56
|
||||||
|
5.11
|
||||||
|
2.52
|
||||||
|
2.51
|
||||||
|
2.49
|
||||||
|
2.48
|
||||||
|
2.46
|
||||||
|
2.46
|
||||||
|
2.45
|
||||||
|
2.44
|
||||||
|
2.43
|
||||||
|
2.42
|
||||||
|
2.41
|
||||||
|
2.4
|
||||||
|
2.41
|
||||||
|
2.39
|
||||||
|
2.38
|
||||||
|
2.35
|
||||||
|
2.31
|
||||||
|
2.26
|
||||||
|
2.21
|
||||||
|
2.16
|
||||||
|
2.1
|
||||||
|
2.05
|
||||||
|
2.01
|
||||||
|
1.94
|
||||||
|
1.91
|
||||||
|
1.84
|
||||||
|
1.77
|
||||||
|
1.73
|
||||||
|
1.65
|
||||||
|
1.59
|
||||||
|
1.58
|
||||||
|
1.55
|
||||||
|
1.52
|
||||||
|
1.53
|
||||||
|
1.52
|
||||||
|
1.5
|
||||||
|
1.49
|
||||||
|
1.47
|
||||||
|
1.47
|
||||||
|
1.47
|
||||||
|
1.47
|
||||||
|
1.48
|
||||||
|
1.48
|
||||||
|
1.48
|
||||||
|
1.48
|
||||||
|
1.48
|
||||||
|
1.46
|
||||||
|
1.44
|
||||||
|
1.44
|
||||||
|
1.43
|
||||||
|
1.41
|
||||||
|
1.41
|
||||||
|
1.4
|
||||||
|
1.38
|
||||||
|
1.37
|
||||||
|
1.36
|
||||||
|
1.35
|
||||||
|
1.33
|
||||||
|
1.32
|
||||||
|
1.31
|
||||||
|
1.28
|
||||||
|
1.27
|
||||||
|
1.26
|
||||||
|
1.24
|
||||||
|
1.22
|
||||||
|
1.21
|
||||||
|
1.21
|
||||||
|
1.19
|
||||||
|
1.17
|
||||||
|
1.16
|
||||||
|
1.16
|
||||||
|
1.13
|
||||||
|
1.12
|
||||||
|
1.12
|
||||||
|
1.11
|
||||||
|
1.09
|
||||||
|
1.08
|
||||||
|
1.07
|
||||||
|
1.07
|
||||||
|
1.05
|
||||||
|
1.04
|
||||||
|
1.03
|
||||||
|
1.02
|
||||||
|
1.01
|
||||||
|
0.99
|
||||||
|
0.98
|
||||||
|
0.96
|
||||||
|
0.95
|
||||||
|
0.94
|
||||||
|
0.9
|
||||||
|
0.87
|
||||||
|
0.84
|
||||||
|
0.8
|
||||||
|
0.79
|
||||||
|
0.78
|
||||||
|
0.75
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
|
2402
csv/myfile.csv
2402
csv/myfile.csv
File diff suppressed because it is too large
Load Diff
2402
csv/pressure_Vacuum.csv
Normal file
2402
csv/pressure_Vacuum.csv
Normal file
File diff suppressed because it is too large
Load Diff
2
makefile
2
makefile
@ -7,7 +7,7 @@ EXE = eatit
|
|||||||
CCC = g++
|
CCC = g++
|
||||||
OPT = -O3 -Wall
|
OPT = -O3 -Wall
|
||||||
|
|
||||||
$(EXE) : $(SRC)main.cpp $(SRC)raweat.hpp
|
$(EXE) : $(SRC)main.cpp $(SRC)raweat.hpp $(SRC)half_precision_floating_point.hpp
|
||||||
$(CCC) $(OPT) $< -o $@
|
$(CCC) $(OPT) $< -o $@
|
||||||
|
|
||||||
clean :
|
clean :
|
||||||
|
60
src/endian.hpp
Normal file
60
src/endian.hpp
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
//---------------------------------------------------------------------------//
|
||||||
|
|
||||||
|
#ifndef MY_LITTLE_ENDIAN
|
||||||
|
#define MY_LITTLE_ENDIAN
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#define IS_BIG_ENDIAN (*(uint16_t*)"\0\xff" < 0x100)
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------//
|
||||||
|
|
||||||
|
class endian
|
||||||
|
{
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
// endianness
|
||||||
|
bool little_endian_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
// constructor
|
||||||
|
endian()
|
||||||
|
{
|
||||||
|
// check endianness on machine
|
||||||
|
little_endian_ = get_endian();
|
||||||
|
}
|
||||||
|
|
||||||
|
// provide information about little versus big endian architecture
|
||||||
|
bool get_endian()
|
||||||
|
{
|
||||||
|
// declare short (16 bit) integer representing "1"
|
||||||
|
short int wd = 0x001;
|
||||||
|
|
||||||
|
// get byte pattern of integer
|
||||||
|
uint8_t *pwd = (uint8_t*)(&wd);
|
||||||
|
|
||||||
|
//for ( int i = 0; i < 2; i ++ ) std::cout<<std::hex<<(int)pwd[i]<<" ";
|
||||||
|
//std::cout<<"\n";
|
||||||
|
|
||||||
|
// check if byte pattern is 0x 0001 or 0x 0100
|
||||||
|
return ((int)pwd[0] == 1 ? true : false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// retrieve information
|
||||||
|
bool little_endian()
|
||||||
|
{
|
||||||
|
return little_endian_?true:false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool big_endian()
|
||||||
|
{
|
||||||
|
return little_endian_?false:true;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------//
|
100
src/half_precision_floating_point.hpp
Normal file
100
src/half_precision_floating_point.hpp
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
//---------------------------------------------------------------------------//
|
||||||
|
|
||||||
|
#ifndef HALF_PRECISION_FLOATING_POINT
|
||||||
|
#define HALF_PRECISION_FLOATING_POINT
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <bitset>
|
||||||
|
#include "endian.hpp"
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------//
|
||||||
|
|
||||||
|
class half_precision_floating_point
|
||||||
|
{
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
// size of half precision floating point number in bits
|
||||||
|
int size_ = 16;
|
||||||
|
|
||||||
|
// construction of the number (binary16) according to IEEE 754-2008 standard
|
||||||
|
std::bitset<1> sign_;
|
||||||
|
std::bitset<5> expo_;
|
||||||
|
std::bitset<10> frac_;
|
||||||
|
|
||||||
|
// endianness of machine/architecture
|
||||||
|
bool little_endian_;
|
||||||
|
|
||||||
|
// number as single-precision floating point number
|
||||||
|
float num_;
|
||||||
|
|
||||||
|
// array of bytes representing the number
|
||||||
|
std::vector<uint8_t> numbytes_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
// constructors
|
||||||
|
half_precision_floating_point(std::vector<uint8_t> numbytes) :
|
||||||
|
numbytes_(numbytes)
|
||||||
|
{
|
||||||
|
assert( numbytes_.size() == 2 );
|
||||||
|
endian endi;
|
||||||
|
little_endian_ = endi.little_endian();
|
||||||
|
assert( little_endian_ && "just don't work on big endian machines!" );
|
||||||
|
}
|
||||||
|
|
||||||
|
half_precision_floating_point(float num) :
|
||||||
|
num_(num)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// destructor
|
||||||
|
~half_precision_floating_point()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// assignment operator
|
||||||
|
half_precision_floating_point& operator=(const half_precision_floating_point& other)
|
||||||
|
{
|
||||||
|
if ( this != &other )
|
||||||
|
{
|
||||||
|
size_ = other.size_;
|
||||||
|
sign_ = other.sign_;
|
||||||
|
expo_ = other.expo_;
|
||||||
|
frac_ = other.frac_;
|
||||||
|
little_endian_ = other.little_endian_;
|
||||||
|
num_ = other.num_;
|
||||||
|
numbytes_ = other.numbytes_;
|
||||||
|
}
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// convert byte pattern to number
|
||||||
|
void convert_to_float()
|
||||||
|
{
|
||||||
|
// declare a single precision floating point number
|
||||||
|
// float myfloat = 0.0;
|
||||||
|
|
||||||
|
if ( little_endian_ )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// convert floating point number to bytes
|
||||||
|
void convert_to_byte()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------//
|
||||||
|
|
36
src/main.cpp
36
src/main.cpp
@ -9,13 +9,13 @@
|
|||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
// path of filename provided ?
|
// path of filename provided ?
|
||||||
assert( argc > 1 && "please provide a filename and path" );
|
assert( argc > 2 && "please provide a filename and path for input and output" );
|
||||||
|
|
||||||
std::cout<<"number of CLI-arguments: "<<argc<<"\n";
|
std::cout<<"number of CLI-arguments: "<<argc<<"\n";
|
||||||
for ( int i = 0; i < argc; i++ ) std::cout<<std::setw(5)<<i<<": "<<argv[i]<<"\n";
|
for ( int i = 0; i < argc; i++ ) std::cout<<std::setw(5)<<i<<": "<<argv[i]<<"\n";
|
||||||
|
|
||||||
// check number of CLI arguments
|
// check number of CLI arguments
|
||||||
assert( argc == 2 );
|
assert( argc == 3 );
|
||||||
|
|
||||||
// get name/path of file from CLI argument
|
// get name/path of file from CLI argument
|
||||||
std::string rawfile(argv[1]);
|
std::string rawfile(argv[1]);
|
||||||
@ -23,9 +23,12 @@ int main(int argc, char* argv[])
|
|||||||
// declare instance of "raw_eater"
|
// declare instance of "raw_eater"
|
||||||
raw_eater eatraw(rawfile);
|
raw_eater eatraw(rawfile);
|
||||||
|
|
||||||
eatraw.show_markers();
|
//eatraw.show_markers();
|
||||||
|
|
||||||
|
// determine position of markers in buffer and read data
|
||||||
eatraw.find_markers();
|
eatraw.find_markers();
|
||||||
|
|
||||||
|
std::cout<<"\n";
|
||||||
std::map<std::string,std::vector<unsigned char>> marks = eatraw.get_markers();
|
std::map<std::string,std::vector<unsigned char>> marks = eatraw.get_markers();
|
||||||
for ( auto mrk: marks )
|
for ( auto mrk: marks )
|
||||||
{
|
{
|
||||||
@ -39,13 +42,32 @@ int main(int argc, char* argv[])
|
|||||||
std::cout<<"\n";
|
std::cout<<"\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
eatraw.convert_data();
|
// convert unsigned char data in buffer to desired data type
|
||||||
|
//eatraw.convert_data();
|
||||||
|
eatraw.convert_data_16_bit_float();
|
||||||
|
|
||||||
std::vector<double> mydata = eatraw.get_data();
|
// get array of encoded data
|
||||||
std::cout<<"\n"<<mydata.size()<<"\n\n";
|
std::vector<double> maindata = eatraw.get_data();
|
||||||
|
std::cout<<"\nsize of data array: "<<maindata.size()<<"\n\n";
|
||||||
//for ( unsigned long int i = 0; i < 10; i++ ) std::cout<<mydata[i]<<"\n";
|
//for ( unsigned long int i = 0; i < 10; i++ ) std::cout<<mydata[i]<<"\n";
|
||||||
|
|
||||||
eatraw.write_data(std::string("csv/myfile.csv"));
|
// write data in csv-file
|
||||||
|
eatraw.write_data(std::string(argv[2]));
|
||||||
|
|
||||||
|
float ab = -0.75;
|
||||||
|
std::cout<<ab<<"\n";
|
||||||
|
uint8_t* pab = reinterpret_cast<uint8_t*>(&ab);
|
||||||
|
for ( int i = 0; i < (int)sizeof(float); i++ ) std::cout<<std::hex<<(int)pab[i]<<std::dec<<" ";
|
||||||
|
std::cout<<"\n";
|
||||||
|
|
||||||
|
uint8_t sc = 0x4f;
|
||||||
|
std::bitset<8> bssc(sc);
|
||||||
|
for ( int i = 0; i < 8; i++ ) std::cout<<bssc[i]<<" ";
|
||||||
|
std::cout<<"\n";
|
||||||
|
std::cout<<std::hex<<bssc.to_ulong()<<"\n\n";
|
||||||
|
|
||||||
|
endian endi;
|
||||||
|
std::cout<<(endi.little_endian()?"little endian":"big endian")<<"\n";
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
109
src/raweat.hpp
109
src/raweat.hpp
@ -1,5 +1,8 @@
|
|||||||
//---------------------------------------------------------------------------//
|
//---------------------------------------------------------------------------//
|
||||||
|
|
||||||
|
#ifndef RAW_EATER
|
||||||
|
#define RAW_EATER
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
@ -8,6 +11,9 @@
|
|||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
#include "half_precision_floating_point.hpp"
|
||||||
|
#include "endian.hpp"
|
||||||
|
|
||||||
//---------------------------------------------------------------------------//
|
//---------------------------------------------------------------------------//
|
||||||
|
|
||||||
class raw_eater
|
class raw_eater
|
||||||
@ -40,6 +46,9 @@ private:
|
|||||||
// data sections corresponding to markers
|
// data sections corresponding to markers
|
||||||
std::map<std::string,std::vector<unsigned char>> datasec_;
|
std::map<std::string,std::vector<unsigned char>> datasec_;
|
||||||
|
|
||||||
|
// length of data array
|
||||||
|
unsigned long int datsize_;
|
||||||
|
|
||||||
// TODO preliminary: for now, we assume 32/64 bit ? floats in all data
|
// TODO preliminary: for now, we assume 32/64 bit ? floats in all data
|
||||||
std::vector<double> datmes_;
|
std::vector<double> datmes_;
|
||||||
|
|
||||||
@ -61,17 +70,6 @@ public:
|
|||||||
(std::istreambuf_iterator<char>()));
|
(std::istreambuf_iterator<char>()));
|
||||||
rawdata_ = rawdata;
|
rawdata_ = rawdata;
|
||||||
|
|
||||||
// show size of buffer
|
|
||||||
std::cout<<"size of buffer "<<rawdata_.size()<<"\n";
|
|
||||||
|
|
||||||
// show excerpt from buffer
|
|
||||||
int ista = 0, iend = 128;
|
|
||||||
for ( int i= ista; i < iend; i++ )
|
|
||||||
{
|
|
||||||
std::cout<<std::hex<<(int)rawdata_[i]<<" ";
|
|
||||||
if ( (i+1)%16 == 0 ) std::cout<<"\n";
|
|
||||||
}
|
|
||||||
std::cout<<"\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// destructor
|
// destructor
|
||||||
@ -80,6 +78,22 @@ public:
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// display buffer/data properties
|
||||||
|
void show_buffer(int numel = 128)
|
||||||
|
{
|
||||||
|
// show size of buffer
|
||||||
|
std::cout<<"size of buffer "<<rawdata_.size()<<"\n\n";
|
||||||
|
|
||||||
|
// show excerpt from buffer
|
||||||
|
int ista = 0, iend = numel;
|
||||||
|
for ( int i= ista; i < iend; i++ )
|
||||||
|
{
|
||||||
|
std::cout<<std::hex<<(int)rawdata_[i]<<" ";
|
||||||
|
if ( (i+1)%16 == 0 ) std::cout<<"\n";
|
||||||
|
}
|
||||||
|
std::cout<<"\n";
|
||||||
|
}
|
||||||
|
|
||||||
// show predefined markers
|
// show predefined markers
|
||||||
void show_markers()
|
void show_markers()
|
||||||
{
|
{
|
||||||
@ -135,6 +149,9 @@ public:
|
|||||||
{
|
{
|
||||||
markseq.push_back(rawdata_[didx]);
|
markseq.push_back(rawdata_[didx]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// obtain length of data segment
|
||||||
|
datsize_ = markseq.size();
|
||||||
}
|
}
|
||||||
datasec_.insert(std::pair<std::string,std::vector<unsigned char>>(mrk.first,markseq));
|
datasec_.insert(std::pair<std::string,std::vector<unsigned char>>(mrk.first,markseq));
|
||||||
}
|
}
|
||||||
@ -198,12 +215,9 @@ public:
|
|||||||
// convert actual measurement data
|
// convert actual measurement data
|
||||||
void convert_data()
|
void convert_data()
|
||||||
{
|
{
|
||||||
// length of data array
|
assert ( (datsize_-28)%4 == 0 && "length of buffer is not a multiple of 4" );
|
||||||
unsigned long int datsize = datasec_["datas marker"].size();
|
|
||||||
|
|
||||||
assert ( (datsize-28)%4 == 0 && "length of buffer is not a multiple of 4" );
|
unsigned long int totnumfl = (datsize_-28)/(int)sizeof(float);
|
||||||
|
|
||||||
unsigned long int totnumfl = (datsize-28)/4;
|
|
||||||
for ( unsigned long int numfl = 0; numfl < totnumfl; numfl++ )
|
for ( unsigned long int numfl = 0; numfl < totnumfl; numfl++ )
|
||||||
{
|
{
|
||||||
// assuming 4 byte float
|
// assuming 4 byte float
|
||||||
@ -211,6 +225,8 @@ public:
|
|||||||
uint8_t* pnum = reinterpret_cast<uint8_t*>(&num);
|
uint8_t* pnum = reinterpret_cast<uint8_t*>(&num);
|
||||||
for ( int byi = 0; byi < (int)sizeof(float); byi++ )
|
for ( int byi = 0; byi < (int)sizeof(float); byi++ )
|
||||||
{
|
{
|
||||||
|
// TODO what's the byte order in the file??
|
||||||
|
// for now, we just don't care...
|
||||||
pnum[byi] = (int)datasec_["datas marker"][(unsigned long int)(28+numfl*sizeof(float)+byi)];
|
pnum[byi] = (int)datasec_["datas marker"][(unsigned long int)(28+numfl*sizeof(float)+byi)];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,6 +235,61 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// convert half-precision (16bit) floating point numbers
|
||||||
|
void convert_data_16_bit_float()
|
||||||
|
{
|
||||||
|
// single (32bit) floating point number
|
||||||
|
float fl = 0.0;
|
||||||
|
|
||||||
|
unsigned long int totnumby = (datsize_-28)/2;
|
||||||
|
for ( unsigned long int by = 0; by < totnumby; by++ )
|
||||||
|
{
|
||||||
|
// retrieve two bytes of floating point number
|
||||||
|
std::vector<uint8_t> pnum;
|
||||||
|
for ( int i = 0; i < 2; i++ ) pnum.push_back(datasec_["datas marker"][(unsigned long int)(28+by*2+i)]);
|
||||||
|
|
||||||
|
// obtain bitset
|
||||||
|
std::bitset<8> byA(pnum[0]), byB(pnum[1]);
|
||||||
|
|
||||||
|
// TODO all following code only works for little endian!!
|
||||||
|
|
||||||
|
// sign
|
||||||
|
float sign = byB[0];
|
||||||
|
|
||||||
|
// exponent of 16bit float
|
||||||
|
long int expo = 0;
|
||||||
|
for ( int i = 0; i < 5; i++ ) if ( byB[1+i] ) expo += pow(2.0,4-i);
|
||||||
|
expo -= 15;
|
||||||
|
|
||||||
|
// convert to exponent of 32bit float
|
||||||
|
|
||||||
|
|
||||||
|
// mantissa
|
||||||
|
|
||||||
|
|
||||||
|
// declare bitset of float
|
||||||
|
std::bitset<8> flA(0x00), flB(0x00), flC(0x00), flD(0x00);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// convert 16bit "decimal-encoding" floating point numbers
|
||||||
|
void convert_data_16_bit_decimal()
|
||||||
|
{
|
||||||
|
//assert ( (datsize_-29)%2 == 0 && "length of buffer is not a multiple of 2" );
|
||||||
|
|
||||||
|
unsigned long int totnumby = (datsize_-30)/2;
|
||||||
|
for ( unsigned long int by = 0; by < totnumby; by++ )
|
||||||
|
{
|
||||||
|
std::vector<uint8_t> pnum;
|
||||||
|
for ( int i = 0; i < 2; i++ ) pnum.push_back(datasec_["datas marker"][(unsigned long int)(29+by*2+i)]);
|
||||||
|
|
||||||
|
datmes_.push_back((double)( (((int)pnum[0]-128)*256 + (int)pnum[1])/100.0 ));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// get data array encoded as floats/doubles
|
// get data array encoded as floats/doubles
|
||||||
std::vector<double>& get_data()
|
std::vector<double>& get_data()
|
||||||
{
|
{
|
||||||
@ -226,14 +297,14 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// write data to csv-like file
|
// write data to csv-like file
|
||||||
void write_data(std::string filename)
|
void write_data(std::string filename, int precision = 9)
|
||||||
{
|
{
|
||||||
// open file
|
// open file
|
||||||
std::ofstream fout(filename.c_str());
|
std::ofstream fout(filename.c_str());
|
||||||
|
|
||||||
for ( auto el : datmes_ )
|
for ( auto el : datmes_ )
|
||||||
{
|
{
|
||||||
fout<<std::dec<<el<<"\n";
|
fout<<std::dec<<std::setprecision(precision)<<el<<"\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// close file
|
// close file
|
||||||
@ -242,4 +313,6 @@ public:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
//---------------------------------------------------------------------------//
|
//---------------------------------------------------------------------------//
|
||||||
|
Loading…
x
Reference in New Issue
Block a user