udphandler.h 2.09 KB
#ifndef UDPHANDLER_H
#define UDPHANDLER_H

#include <QObject>
#include <QUdpSocket>
#include <QByteArray>

#include "all_share.h"

class UdpHandler : public QObject
{
    Q_OBJECT

    oven_control_t control;
    oven_state_t state;

public:
    explicit UdpHandler(QObject *parent = 0);
    bool init();


    bool burner1() { return (state.onoff_state1 & 0x0001) != 0; }
    bool burner2() { return (state.onoff_state1 & 0x0002) != 0; }
    bool burner3() { return (state.onoff_state1 & 0x0004) != 0; }
    bool burnerFan1() { return (state.onoff_state1 & 0x0008) != 0; }
    bool burnerFan2() { return (state.onoff_state1 & 0x0010) != 0; }
    bool burnerFan3() { return (state.onoff_state1 & 0x0020) != 0; }
    bool convection1() { return (state.onoff_state1 & 0x0040) != 0; }
    bool convection2() { return (state.onoff_state1 & 0x0080) != 0; }

    bool dv() { return (state.onoff_state2 & 0x0001) != 0; }
    bool cfan() { return (state.onoff_state2 & 0x0002) != 0; }
    bool wsv() { return (state.onoff_state2 & 0x0004) != 0; }
    bool qnv() { return (state.onoff_state2 & 0x0008) != 0; }
    bool ssv() { return (state.onoff_state2 & 0x0010) != 0; }
    bool snv() { return (state.onoff_state2 & 0x0020) != 0; }
    bool hl() { return (state.onoff_state2 & 0x0040) != 0; }
    bool dp() { return (state.onoff_state2 & 0x0080) != 0; }
    bool ssp() { return (state.onoff_state2 & 0x0100) != 0; }
    bool unp() { return (state.onoff_state2 & 0x0200) != 0; }
    bool hdm() { return (state.onoff_state2 & 0x0400) != 0; }
    bool sgnv() { return (state.onoff_state2 & 0x0800) != 0; }

signals:
    void changed();

public slots:
    void turnOn(int target);
    void turnOff(int target);
    void set(int target, int value);
    void fillControl(oven_control_t &container);
    void fillData(oven_state_t &container);

private:
    void processDatagram(QByteArray &datagram);
    void processControl(oven_control_t *control);
    void processState(oven_state_t *state);

    QUdpSocket *sock;

private slots:
    void readPendingDatagrams();
    void sendCommand(int cmd, int target, int value);

};

#endif // UDPHANDLER_H