-
Notifications
You must be signed in to change notification settings - Fork 0
/
unit.h
89 lines (77 loc) · 1.85 KB
/
unit.h
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
/*
* unit.h
* vConnect
*
* Created by Frank Nobis on 11.12.11.
* Copyright 2011 Radio-DO.de. All rights reserved.
*
*/
#ifndef __unit_h
#define __unit_h
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
enum unitTypes {
Unknown = 0,
CycleTime = 1,
Temperature = 2,
Raw = 3,
Integer1 = 4,
Integer2 = 5,
Integer4 = 6,
Default = 8
};
/*
* Defintion der verschiedenen Einheiten
*
* Unit: CycleTime
* Desc: 1 Byte Codierung der Schaltzeiten.
* Die schaltzeiten werden in 10 Minutenschritten aufgeteilt und codiert
* das spart Platz.
* Die oberen 5 Bit stellen die Stunden dar, die unteren 3 Bit die Anzahl
* von 10 Minuten Anteilen
*
* MSB LSB
* +---+---+---+---+---+---+---+---+
* | h4 h3 h2 h2 h0| m2-m0 * 10|
* +---+---+---+---+---+---+---+---+
*
*
* Unit: Temperature
* Desc: 2 Byte Codierung der Temperature 2-bit Komplement
*
* Unit: Raw
* Desc: decode as hex value. Should be 2 or 4 bytes
*
*/
class vito_unit {
private:
int decode2BytesWithSign(unsigned char hByte, unsigned char lByte);
void decodeAsCycleTime(unsigned char *buffer, int bufferLen);
void decodeAsTemperature(unsigned char *buffer);
void decodeAsRaw(unsigned char *buffer, int bufferLen);
void decodeAsInteger(unsigned char *buffer, int bufferLen);
unitTypes m_eUnitType;
std::string m_sDecodedValue;
float m_fReadMultiplier;
float m_fWriteMultiplier;
public:
vito_unit(unitTypes _UnitType = Unknown,
float fReadMultiplier=1.0,
float fWriteMultiplier=1.0)
{
m_eUnitType = _UnitType;
m_sDecodedValue = "<Test>";
m_fReadMultiplier = fReadMultiplier;
m_fWriteMultiplier = fWriteMultiplier;
};
void decodeBuffer(unsigned char *buffer, int bufferLen);
std::string getValue() {
return m_sDecodedValue;
}
void setValue(std::string val) {
m_sDecodedValue = val;
}
};
#endif