From bae371454503efbf3f27faaecc81b37b08cd66c5 Mon Sep 17 00:00:00 2001 From: victor Date: Mon, 15 May 2017 10:46:02 +0900 Subject: [PATCH] =?UTF-8?q?485=20=ED=86=B5=EC=8B=A0=20=EC=98=A4=EB=A5=98?= =?UTF-8?q?=20=EA=B2=80=EC=B6=9C=20=EB=A3=A8=ED=8B=B4=20=20-=2010=EC=B4=88?= =?UTF-8?q?=20=EB=8F=99=EC=95=88=20UDP=EB=A5=BC=20=EB=B0=9B=EC=A7=80=20?= =?UTF-8?q?=EB=AA=BB=ED=95=98=EB=A9=B4=20=ED=86=B5=EC=8B=A0=20=EC=98=A4?= =?UTF-8?q?=EB=A5=98=20=EC=8B=9C=EA=B7=B8=EB=84=90=20=EC=B6=9C=EB=A0=A5=20?= =?UTF-8?q?=20-=20=ED=86=B5=EC=8B=A0=20=EC=98=A4=EB=A5=98=20=EC=8B=9C?= =?UTF-8?q?=EA=B7=B8=EB=84=90=20=EC=B6=9C=EB=A0=A5=20=ED=9B=84=20UDP?= =?UTF-8?q?=EB=A5=BC=20=EB=B0=9B=EC=9C=BC=EB=A9=B4=20=ED=86=B5=EC=8B=A0=20?= =?UTF-8?q?=EB=B3=B5=EA=B5=AC=20=EC=8B=9C=EA=B7=B8=EB=84=90=20=EC=B6=9C?= =?UTF-8?q?=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/gui/oven_control/udphandler.cpp | 21 +++++++++++++++++++++ app/gui/oven_control/udphandler.h | 6 ++++++ 2 files changed, 27 insertions(+) diff --git a/app/gui/oven_control/udphandler.cpp b/app/gui/oven_control/udphandler.cpp index 964fcd4..0a64d99 100644 --- a/app/gui/oven_control/udphandler.cpp +++ b/app/gui/oven_control/udphandler.cpp @@ -17,6 +17,13 @@ UdpHandler::UdpHandler(QObject *parent) : QObject(parent) { bzero(&control, sizeof(control)); bzero(&state, sizeof(state)); + + emitted = false; + emitTimeoutTimer.setSingleShot(true); + emitTimeoutTimer.setInterval(10 * 1000); + connect(&emitTimeoutTimer, SIGNAL(timeout()), SLOT(emitTimeout())); + + emitTimeoutTimer.start(); } bool UdpHandler::init() @@ -48,6 +55,12 @@ void UdpHandler::processDatagram(QByteArray &datagram) { sock->writeDatagram(datagram, QHostAddress("localhost"), 40001); + if (emitted) + { + emitted = false; + emit recovered(); + } + packet_t *packet = (packet_t *) datagram.data(); switch (packet->header) { @@ -63,6 +76,8 @@ void UdpHandler::processDatagram(QByteArray &datagram) qDebug() << "Received Error"; break; } + + emitTimeoutTimer.start(); } void UdpHandler::processControl(oven_control_t *control) @@ -105,6 +120,12 @@ void UdpHandler::sendCommand(int cmd, int target, int value) sock->writeDatagram((const char *) &command, sizeof(command), QHostAddress(IPC_UDP_SYS_HOST), IPC_UDP_SYS_PORT); } +void UdpHandler::emitTimeout() +{ + emitted = true; + emit timeout(); +} + void UdpHandler::fillControl(oven_control_t &container) { memcpy(&container, &control, sizeof(control)); diff --git a/app/gui/oven_control/udphandler.h b/app/gui/oven_control/udphandler.h index 4f364dd..7a70209 100644 --- a/app/gui/oven_control/udphandler.h +++ b/app/gui/oven_control/udphandler.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "../../app-prime-modbus/include/all_share.h" @@ -55,6 +56,8 @@ public: signals: void changed(); + void timeout(); + void recovered(); public slots: void turnOn(int target); @@ -71,11 +74,14 @@ private: void processState(oven_state_t *state); QUdpSocket *sock; + QTimer emitTimeoutTimer; + bool emitted; private slots: void readPendingDatagrams(); void sendCommand(int cmd, int target, int value); + void emitTimeout(); }; #endif // UDPHANDLER_H -- 2.1.4