-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdspcontroller.cpp
152 lines (122 loc) · 4.15 KB
/
dspcontroller.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
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
#include "dspcontroller.h"
// Verwaltet die Verbindung mit dem Controller
DspController::DspController(QObject *parent) :
QObject(parent)
,m_handlerDspProtocol(new HandlerDspProtocol())
,m_handlerChannelInfo(new HandlerChInfoProtocol())
,m_protoHandler(nullptr)
,m_sendQueue(new QQueue<QByteArray>())
{
connect(&m_timer, &QTimer::timeout, this, &DspController::timerTimeout);
m_timer.setSingleShot(false);
m_timer.start(300);
}
void DspController::timerTimeout() {
qDebug() << "DspController::timerTimeout";
this->updateLineData();
}
void DspController::updateDisplayName()
{
qDebug() << "DspController::updateDisplayName";
emit displayName("Test123");
}
void DspController::updateConnectionStatus()
{
qDebug() << "DspController::updateConnectionStatus";
emit connectionStatus("Foooo!");
}
void DspController::initDevice()
{
qDebug() << "DspController::initDevice";
this->request(DspProtocol::INIT);
}
void DspController::disconnectDevice()
{
qDebug() << "DspController::disconnectDevice";
this->request(DspProtocol::QUIT);
}
void DspController::updateLineData()
{
qDebug() << "DspController::updateLineData";
this->request(DspProtocol::LINE_DATA);
}
void DspController::muteChannel(unsigned char channel, bool status)
{
qDebug() << "DspController::mute(" << QString::number(channel) << "-" << status << ")";
unsigned char data[] = {channel, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, status};
this->request(DspProtocol::MUTE, data);
}
void DspController::request(unsigned char cmd) {
qDebug() << "DspController::request (cmd)";
unsigned char data[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
this->request(cmd, data);
}
void DspController::request(unsigned char cmd, unsigned char* data) {
qDebug() << "DspController::request (cmd,data)";
QByteArray serialPacket;
serialPacket = m_handlerDspProtocol->buildPacket(cmd, data);
qDebug() << "~~ " << serialPacket.toHex();
this->request(serialPacket);
}
void DspController::request(QByteArray serialPacket) {
qDebug() << "DspController::request (Packet)";
qDebug() << "- Locking m_sendMutex";
m_sendMutex.lock();
DspProtocol::PacketUnion packet;
memcpy(packet.packetData, serialPacket.data(), serialPacket.length());
QByteArray packetTmp(reinterpret_cast<const char*>(serialPacket.data()), serialPacket.length());
// packet.packetData = serialPacket.data();
if(m_protoHandler == nullptr) {
qDebug() << "- protoHandler is not set .. processing";
switch(packet.cmd) {
/*case DspProtocol::CH_INFO:
qDebug() << "- Handler: Channel Info";
m_protoHandler = m_handlerChannelInfo;
break;*/
default:
qDebug() << "- Handler: DspProtocol";
m_protoHandler = m_handlerDspProtocol;
}
m_lastRequest = serialPacket;
emit serialWrite(serialPacket);
} else {
qDebug() << "- protoHandler is already set .. enqueue packet";
m_sendQueue->enqueue(serialPacket);
}
qDebug() << "- Unlocking m_sendMutex";
m_sendMutex.unlock();
}
void DspController::serialReceive(QByteArray recvData)
{
qDebug() << "DspController::serialReceive";
qDebug() << "- Packet-Size: " << recvData.length();
DspProtocol::Packet packet;
m_protoHandler->parsePacket<DspProtocol::Packet>(recvData, packet);
QByteArray lastRequest = m_lastRequest;
m_lastRequest = NULL;
m_protoHandler = nullptr;
if(!m_sendQueue->empty()) {
QByteArray packetData = m_sendQueue->dequeue();
this->request(packetData);
}
switch (packet.cmd) {
case DspProtocol::LINE_DATA:
qDebug() << "# Line Data";
DspProtocol::LineInfo data;
data.inA = packet.d0;
data.inB = packet.d1;
data.out1 = packet.d2;
data.out2 = packet.d3;
data.out3 = packet.d4;
data.out4 = packet.d5;
emit lineData(data);
break;
case DspProtocol::MUTE:
qDebug() << "# Mute";
emit mute(packet.d0, packet.d7);
break;
default:
qDebug() << "# Some Data";
break;
}
}