-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtype.cpp
100 lines (76 loc) · 2.27 KB
/
vtype.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <map>
#include <string>
#include <sstream>
#include <iomanip>
#include "hexdump.hpp"
#include "vtype.h"
std::map<std::string,VT::Default*> vtmap;
namespace VT {
Default::Default(std::string name, Default *vt) {
vtmap.emplace(name, vt);
}
std::string Default::decode(std::string value) const {
std::stringstream ss;
hex::dump(value.c_str(), value.size(), ss);
return ss.str();
}
class Float : public Default {
int size;
std::string unit;
int divisor;
public:
Float(std::string name, int size, std::string unit, int divisor) : Default(name,this),size(size),unit(unit),divisor(divisor) {}
std::string decode(std::string value) const {
uint32_t num=0;
for(int i=0;i<size;i++)
num=(num<<8)|(uint8_t) value.at(i);
std::stringstream ss;
ss << std::fixed << std::showpoint << std::setprecision(2) << ((double) num)/divisor << unit;
return ss.str();
}
};
class Hexdump : public Default {
public:
Hexdump(std::string name) : Default(name, this) {}
};
class DateTime : public Default {
public:
DateTime(std::string name) : Default(name, this) {}
};
class Bit : public Default {
std::string set;
std::string unset;
public:
Bit(std::string name, int size, std::string set, std::string unset) : Default(name, this),set(set),unset(unset) {};
std::string decode(std::string value) const {
if (value.at(0))
return set;
return unset;
}
};
class Enum : public Default {
public:
Enum(std::string name) : Default(name, this) {}
};
class BrennerStatus : public Default {
public:
BrennerStatus(std::string name) : Default(name, this) {}
std::string decode(std::string value) const {
char i=value.at(0);
std::stringstream ss;
ss << (((i&0x04)==0x04) ? "On" : "Off")
<< "("
<< std::hex << static_cast<uint8_t>(i)
<< ")";
return ss.str();
}
};
} // Namespace VT
static VT::Hexdump hexdump("hexdump");
static VT::Hexdump unknown("unknown");
static VT::Hexdump hkinfo("hkinfo");
static VT::DateTime datetime("datetime");
static VT::Float float3div64tempC("float3-div64-tempC", 3, "°C", 64);
static VT::Bit bitanaus("bit-anaus", 1, "an", "aus");
static VT::Enum enumlist("enum");
static VT::BrennerStatus bstatus("brennerstatus");