#ifndef ABDDRIVERUDP_H
#define ABDDRIVERUDP_H

#include "qgscopedevice.h"

#include "avb_driver.h"

class QHostAddress;

class AvbDriverUDP: public QgScopeDevice, public IAvbDriver
{
    Q_OBJECT

public:
    AvbDriverUDP(const QHostAddress* ha=0);
    virtual ~AvbDriverUDP();

    //IAvbDriver
    virtual bool initialize();
    virtual bool shutdown();

    virtual void set_begin_of_major_frame_handler(avb_1553_major_frame_handler_t handler) override;
    virtual void set_minor_frame_handler(avb_1553_major_frame_handler_t handler) override;
    virtual void set_end_of_frame_handler(avb_1553_major_frame_handler_t handler) override;
    virtual const char* getDeviceName() override;

    virtual bool setUpBcFrame(avb_1553_bc_frame_t& frame) override;

    virtual void set_isr(avb_1553_isr_t) override;

    virtual bool go(int times) override;
    virtual bool stop() override;
    virtual bool go_mon() override;
    virtual bool halt_mon() override;

    virtual run_status_t getRunState() override;

    virtual void niceInterrupt(bool enable) override;

    virtual void enableMonitorIsr(bool enable=true) override;
    virtual void set_mon_isr(avb_1553_monitor_isr_t isr) override;
    virtual bool getMonitorRawBuffer(avb_1553_monitor_info_t* const buffer) override;

    virtual int getLastDriverError() override;
    virtual const char* getDriverErrrorMessage(int error_code) override;

    virtual bool readDataBuffer(avb_1553_message_t* const, void* const dst, unsigned int wc=0) override;
    virtual bool writeDataBuffer(const avb_1553_message_t* const, void* const src, unsigned int wc=0) override;

    virtual void writeSyncWord(avb_1553_word_t) override;

    virtual bool enableSkipMessage(bool enable=true) override;

    //virtual bool adjustMinorFrameTimer();
    virtual avb_1553_intr_status_t getIntrStatus() override;

    virtual bool mon_decode_msg(avb_1553_mon_decoded_t* const decoded, void* const buffer) override;

    virtual avb_microseconds_t getTimetag()override;

    virtual void simulateBcTick() override;

    virtual bool insertMessage(const avb_1553_bc_message_t* const) override;

private slots:
    //void _onSignalDeviceActive(bool active);
    void bcStart();
    void bcStop();
    void monStart();
    void monHalt();
    void onInit();

    void serverNewConnection();

signals:
    void _sigStart();
    void _sigStop();
    void _sigInit();
private:
    class AvbUdpImplemenation;
    AvbUdpImplemenation& p_;
};

#endif // ABDDRIVERUDP_H
