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