#ifndef MGUANGYINGPINWIDGET_H
#define MGUANGYINGPINWIDGET_H

#include <QWidget>
#include "communication/taserialthread.h"
#include <QUdpSocket>
#include <QNetworkInterface>
namespace Ui {
class mGuangYingPinWidget;
}

#define  MACRO_ANSY_PROGRAM(PROGRAM_INDEX) \
    if(ui->groupBox_com->isChecked())\
    {\
    if(ui->pushButtonMainOpen->text()==tr("Close"))\
        Set_program_buf_and_send(ui->comboBox_SPortName->currentIndex(),PROGRAM_INDEX);\
    if(ui->pushButtonAuxOpen->text()==tr("Close"))\
        Set_program_buf_and_send(ui->comboBox_SPortNameAux->currentIndex(),PROGRAM_INDEX);\
    }\
    if(ui->groupBox_Network->isChecked())\
    {\
        Set_program_buf_and_send_by_udp(PROGRAM_INDEX);\
    }
class mGuangYingPinWidget : public QWidget {
    Q_OBJECT
public:
    explicit mGuangYingPinWidget(QWidget *parent = nullptr);
    ~mGuangYingPinWidget();
protected:
    void changeEvent(QEvent *) override;
    void transUi();
public slots:
    void MWOnoffPort(void);
    void MWOnoffPortAux(void);
    void MWSendCmd(uint8_t iComIndex,unsigned char cmd,unsigned char *pUcValue,unsigned int iLength,int iCountCmd);
    void MWSendCmdByUdp(unsigned char cmd,unsigned char *pUcValue,unsigned int iLength,int iCountCmd);

    void MWReadData(void);
    void MWReadDataAux(void);
    void MWClearRecv(void);
    void MWRSNumDisplay(void);
    void OnAnsyProgram1(void);
    void OnAnsyProgram2(void);
    void OnAnsyProgram3(void);
    void OnAnsyProgram4(void);
    void OnAnsyProgram5(void);
    void OnAnsyProgram6(void);
    void OnAnsyProgram7(void);
    void OnAnsyProgram8(void);
    void OnAnsyProgram9(void);
    void OnAnsyProgram10(void);
    void OnAnsyProgram11(void);
    void OnAnsyProgram12(void);
    void OnAnsyProgram13(void);
    void OnAnsyProgram14(void);
    void OnAnsyProgram15(void);
    void OnAnsyProgram16(void);
    void OnAnsyProgram17(void);
    void OnAnsyProgram18(void);
    void OnAnsyProgram19(void);
    void OnAnsyProgram20(void);
    void OnClearLog(void);
    void OnAnsyProgramCustom(void);
    void OnAnsyProgramNext(void);
    void OnAnsyProgramPrevious(void);
    void OnAnsyProgramLoop(void);
    void OnBrightnessSet(void);
    void OnScreenOn(void);
    void OnScreenOff(void);
    void OnAnsyProgramCustomByChanged(int icurIndex);
    void OnBrightnessSetByChanged(int icurValue);
    void OnRefresh(void);
private:
    Ui::mGuangYingPinWidget *ui;
    TA_SerialThread *sPortThread;
    volatile uint32_t m_recvNum;
    volatile uint32_t m_sendNum;
    int g_iCountCmd=0;
    int m_port=31296;
    void Set_program_buf_and_send(int iComIndex,int iProgramIndex);
    void Set_program_buf_and_send_by_udp(int iProgramIndex);
    void Set_Brightness_buf_and_send(int iComIndex,int iBrightnessValue);
    void Set_Brightness_buf_and_send_by_udp(int iBrightnessValue);
    void Screen_OnOff_buf_and_send(int iComIndex,int iScreenOnOff);
    void Screen_OnOff_buf_and_send_by_udp(int iScreenOnOff);
    void NextProgram_buf_and_send(int iComIndex);
    void NextProgram_buf_and_send_by_udp();


    void mymidelay(int imlsec);
    QString ByteArrayToHexString(QByteArray &ba);

};

#endif // MGUANGYINGPINWIDGET_H
