-
Notifications
You must be signed in to change notification settings - Fork 1
/
ut70x.h
156 lines (141 loc) · 4.48 KB
/
ut70x.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#pragma once
#include <QtSerialPort>
#pragma pack(push, 1)
struct Paket {
Paket() { }
uint8_t echo; // byt 0
uint8_t mode; // byt 1
struct /*Range*/ {
uint8_t unit : 3;
uint8_t subRange : 3;
uint8_t manualNAuto : 1;
uint8_t _alwaysOne8_2 : 1; //?
}; // byt 2
struct /*Flags*/ {
uint8_t _alwaysZero1_3 : 1; //?
uint8_t _alwaysZero2_3 : 1; //?
uint8_t peak1ms : 1;
uint8_t minMax : 2;
uint8_t _alwaysZero6_3 : 1; //?
uint8_t rec : 1;
uint8_t dummy : 1;
}; // byt 3
struct /*Flags*/ {
uint8_t hold : 1;
uint8_t _alwaysZero2_4 : 1; //?
uint8_t freq : 1;
uint8_t overflow : 1;
uint8_t nSign : 1;
uint8_t lowbat : 1;
uint8_t _alwaysZero7_4 : 1; //?
uint8_t _alwaysOne8_4 : 1; //?
}; // byt 4
uint8_t valData[]; // byt 5
//uint8_t checksum();
//uint8_t endOfPaket(); //0xA0
};
#pragma pack(pop)
class UT70X : public QSerialPort {
Q_OBJECT
QByteArray m_data;
unsigned char* data() { return reinterpret_cast<unsigned char*>(m_data.data()); }
Paket* paket() { return reinterpret_cast<Paket*>(m_data.data()); }
public:
UT70X(QObject* parent = nullptr);
enum Mode : uint8_t {
FAIL_range,
Hz_range,
PR_range,
A_DC = 0xA8, // A8 1010 1000 A=
A_AC = 0xA9, // A9 1010 1001 A~
mA_DC = 0xB0, // B0 1011 0000 mA=
mA_AC = 0xB1, // B1 1011 0001 mA~
Dio = 0xD8, // D8 1101 1000 Dio
R_C = 0xE0, // E0 1110 0000 R/C
F = 0xE1, // E1 1110 0001 F
mV = 0xE8, // E8 1110 1000 mV
V_DC = 0xF0, // F0 1111 0000 V=
V_AC = 0xF8, // F8 1111 1000 V~
};
Q_ENUM(Mode)
enum SampleType : uint8_t {
Norm = 0,
Max = 1,
Min = 2,
AVG = 3,
PeakMin = 0,
PeakMax = 1,
};
Q_ENUM(SampleType)
enum MeasType : uint8_t {
Capacity = 0,
//MAX_ = 1,
Main = 2,
//AVG_ = 3,
Frequency = 4,
Percent = 5,
};
Q_ENUM(MeasType)
struct Range {
uint8_t data[8];
uint8_t operator[](int i) const { return data[i]; }
QString description;
};
static inline const std::map<Mode, Range> parMap {
{ A_AC, { { 1, 2, 0, 0, 0, 0, 0, 0 }, "AC A " } },
{ A_DC, { { 1, 2, 0, 0, 0, 0, 0, 0 }, "DC A " } },
{ Dio, { { 1, 0, 0, 0, 0, 0, 0, 0 }, "D " } },
{ F, { { 1, 2, 3, 1, 2, 3, 0, 0 }, "C " } },
{ FAIL_range, { { 0, 0, 0, 0, 0, 0, 0, 0 }, "?" } },
{ Hz_range, { { 2, 3, 1, 2, 3, 1, 2, 3 }, "Hz" } },
{ PR_range, { { 0, 2, 0, 0, 0, 0, 0, 0 }, "%" } },
{ R_C, { { 3, 1, 2, 3, 1, 2, 2, 0 }, "R " } }, //last active range is nS on 5 digit display (800nS)
{ V_AC, { { 3, 1, 2, 3, 4, 0, 0, 0 }, "AC V " } },
{ V_DC, { { 1, 2, 3, 4, 0, 0, 0, 0 }, "DC V " } },
{ mA_AC, { { 2, 3, 0, 0, 0, 0, 0, 0 }, "DC mA " } },
{ mA_DC, { { 2, 3, 0, 0, 0, 0, 0, 0 }, "AC mA " } },
{ mV, { { 2, 3, 0, 0, 0, 0, 0, 0 }, "DC mV " } },
};
Mode mode() { return static_cast<Mode>(reinterpret_cast<uint8_t*>(m_data.data())[1]); };
const uint8_t* range(Mode mode) const
{
if (parMap.find(mode) != parMap.end())
return parMap.at(mode).data; /*[(data[2] >> 3) & 0x7]*/
return nullptr;
}
const uint8_t* baseRange; // value * 10^base_range
int checkSum(uint8_t* d, int len);
bool checkData(unsigned char* d, int len);
// int eeprom();
bool initSerial(const QString& n);
void measure();
void parseRawData(unsigned char* d, int len);
void printMode(unsigned char* buf, int len);
void printsValue(unsigned char* d, int len);
void parseValue();
double value() { return m_value; }
void startMs(int msec)
{
if (m_timerId)
killTimer(m_timerId);
m_timerId = startTimer(msec);
}
void stop()
{
if (m_timerId)
killTimer(m_timerId);
m_timerId = 0;
}
private:
double m_value = 0.0;
double m_unit = 0.0;
int m_timerId = 0;
char m_pol = '\0';
signals:
void valueChanged(double);
void unit(const QString&);
void sign(const QString&);
// QObject interface
protected:
void timerEvent(QTimerEvent* event) override;
};