-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdevice.h
79 lines (58 loc) · 1.76 KB
/
device.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
#ifndef DEVICE_H
#define DEVICE_H
#include <com-handle.h>
#include <com-parser.h>
#include <QSerialPort>
#include <QObject>
#include <QTimer>
#include <QMap>
#include <register-model.h>
#include <inttypes.h>
#define ADC_NUM_CHANNELS 8
class Device : public QObject
{
Q_OBJECT
public:
Device(QSerialPortInfo info);
ComParser parser;
ComHandle* handle;
bool open();
void readRegister(uint16_t address);
typedef struct {
uint16_t adc_buffer[ADC_NUM_CHANNELS];
uint16_t throttle;
uint8_t direction;
uint8_t direction_mode;
uint16_t startup_throttle;
} global_t;
global_t deviceGlobal;
void readRegisters();
void readRegisterMulti(uint16_t address, uint16_t count);
void requestDeviceInformation();
void requestProtocolVersion();
void requestMessage(uint16_t messageId);
void setThrottle(uint16_t throttle);
void writeRegister(uint16_t address, uint32_t* data);
void writeRegisterMulti(uint16_t address, uint16_t length);
void readRegister(uint16_t address, uint32_t* data);
void consumeData();
uint8_t device_type;
uint8_t device_id;
void handleMessage(ping_message* message);
uint16_t phaseA, phaseB, phaseC, neutral, current, voltage, throttle, commutationFrequency;
void writeRegister(uint16_t address, uint32_t value);
void commitRegister(uint16_t index);
void writeMessage(ping_message message);
RegisterModel* getRegisterModel() { return ®isterModel; }
void close();
QVector<RegisterModel::register_t> registerList;
RegisterModel registerModel;
private:
uint16_t _throttle = 0;
void write(uint8_t* data, uint16_t length);
QTimer sendThrottleTimer;
signals:
void newData();
void closed();
};
#endif // DEVICE_H