8c2952457
김태훈
응용 프로그램 추가
|
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
|
}
bool UdpHandler::init()
{
sock = new QUdpSocket(this);
if (!sock->bind(IPC_UDP_GUI_PORT))
return false;
connect(sock, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams()));
return true;
}
void UdpHandler::readPendingDatagrams()
{
while (sock->hasPendingDatagrams()) {
QByteArray datagram;
datagram.resize(sock->pendingDatagramSize());
QHostAddress sender;
quint16 senderPort;
sock->readDatagram(datagram.data(), datagram.size(), &sender, &senderPort);
processDatagram(datagram);
}
}
void UdpHandler::processDatagram(QByteArray &datagram)
{
|
8c2952457
김태훈
응용 프로그램 추가
|
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
|
break;
}
}
void UdpHandler::processControl(oven_control_t *control)
{
if (memcmp(&this->control, control, sizeof(this->control)))
{
memcpy(&this->control, control, sizeof(this->control));
emit changed();
}
}
void UdpHandler::processState(oven_state_t *state)
{
if (memcmp(&this->state, state, sizeof(this->state)))
{
memcpy(&this->state, state, sizeof(this->state));
emit changed();
}
}
void UdpHandler::turnOn(int target)
{
sendCommand(CMD_ONOFF, target, SWITCH_ON);
}
void UdpHandler::turnOff(int target)
{
sendCommand(CMD_ONOFF, target, SWITCH_OFF);
}
void UdpHandler::set(int target, int value)
{
sendCommand(CMD_VALUE, target, value);
}
void UdpHandler::sendCommand(int cmd, int target, int value)
{
command_t command = { cmd, target, value };
qDebug() << "Send" << cmd << target << value;
sock->writeDatagram((const char *) &command, sizeof(command), QHostAddress(IPC_UDP_SYS_HOST), IPC_UDP_SYS_PORT);
}
void UdpHandler::fillControl(oven_control_t &container)
{
memcpy(&container, &control, sizeof(control));
}
void UdpHandler::fillData(oven_state_t &container)
{
memcpy(&container, &state, sizeof(state));
}
|