Commit bae371454503efbf3f27faaecc81b37b08cd66c5

Authored by 김태훈
1 parent 81b55e0463
Exists in master and in 2 other branches fhd, fhd-demo

485 통신 오류 검출 루틴

- 10초 동안 UDP를 받지 못하면 통신 오류 시그널 출력
 - 통신 오류 시그널 출력 후 UDP를 받으면 통신 복구 시그널 출력
app/gui/oven_control/udphandler.cpp
... ... @@ -17,6 +17,13 @@ UdpHandler::UdpHandler(QObject *parent) : QObject(parent)
17 17 {
18 18 bzero(&control, sizeof(control));
19 19 bzero(&state, sizeof(state));
  20 +
  21 + emitted = false;
  22 + emitTimeoutTimer.setSingleShot(true);
  23 + emitTimeoutTimer.setInterval(10 * 1000);
  24 + connect(&emitTimeoutTimer, SIGNAL(timeout()), SLOT(emitTimeout()));
  25 +
  26 + emitTimeoutTimer.start();
20 27 }
21 28  
22 29 bool UdpHandler::init()
... ... @@ -48,6 +55,12 @@ void UdpHandler::processDatagram(QByteArray &datagram)
48 55 {
49 56 sock->writeDatagram(datagram, QHostAddress("localhost"), 40001);
50 57  
  58 + if (emitted)
  59 + {
  60 + emitted = false;
  61 + emit recovered();
  62 + }
  63 +
51 64 packet_t *packet = (packet_t *) datagram.data();
52 65 switch (packet->header)
53 66 {
... ... @@ -63,6 +76,8 @@ void UdpHandler::processDatagram(QByteArray &datagram)
63 76 qDebug() << "Received Error";
64 77 break;
65 78 }
  79 +
  80 + emitTimeoutTimer.start();
66 81 }
67 82  
68 83 void UdpHandler::processControl(oven_control_t *control)
... ... @@ -105,6 +120,12 @@ void UdpHandler::sendCommand(int cmd, int target, int value)
105 120 sock->writeDatagram((const char *) &command, sizeof(command), QHostAddress(IPC_UDP_SYS_HOST), IPC_UDP_SYS_PORT);
106 121 }
107 122  
  123 +void UdpHandler::emitTimeout()
  124 +{
  125 + emitted = true;
  126 + emit timeout();
  127 +}
  128 +
108 129 void UdpHandler::fillControl(oven_control_t &container)
109 130 {
110 131 memcpy(&container, &control, sizeof(control));
... ...
app/gui/oven_control/udphandler.h
... ... @@ -4,6 +4,7 @@
4 4 #include <QObject>
5 5 #include <QUdpSocket>
6 6 #include <QByteArray>
  7 +#include <QTimer>
7 8  
8 9 #include "../../app-prime-modbus/include/all_share.h"
9 10  
... ... @@ -55,6 +56,8 @@ public:
55 56  
56 57 signals:
57 58 void changed();
  59 + void timeout();
  60 + void recovered();
58 61  
59 62 public slots:
60 63 void turnOn(int target);
... ... @@ -71,11 +74,14 @@ private:
71 74 void processState(oven_state_t *state);
72 75  
73 76 QUdpSocket *sock;
  77 + QTimer emitTimeoutTimer;
  78 + bool emitted;
74 79  
75 80 private slots:
76 81 void readPendingDatagrams();
77 82 void sendCommand(int cmd, int target, int value);
78 83  
  84 + void emitTimeout();
79 85 };
80 86  
81 87 #endif // UDPHANDLER_H
... ...