#include "bridge.h"
#include <QDebug>
Bridge::Bridge(QObject *parent) : QObject(parent)
{
    m_TCPSocketHelper = new TCPSocketHelper();
    m_TCPSocketHelper_thread = new QThread;
    //m_TCPSocketHelper->moveToThread(m_TCPSocketHelper_thread);
    connect(this,&Bridge::SendToTCPSocketHelperConnect,m_TCPSocketHelper,&TCPSocketHelper::openTCPSocket);
    connect(this,&Bridge::SendToTCPSocketHelperRegister,m_TCPSocketHelper,&TCPSocketHelper::Register);
    connect(this,&Bridge::SendToTCPSocketHelperBinding,m_TCPSocketHelper,&TCPSocketHelper::Binding);

    m_ReadEPCControl = new ReadEPCControl();
    m_ReadEPCControl_thread = new QThread;
    m_ReadEPCControl->moveToThread(m_ReadEPCControl_thread);
    m_ReadEPCControl_thread->start();

    ReadEPCControl_Func();
}

void Bridge::ReadEPCControl_Func()
{
    connect(this,&Bridge::SendToReadEPCControl_Start_Read,m_ReadEPCControl,&ReadEPCControl::setComm);
    connect(m_ReadEPCControl,&ReadEPCControl::SendToBridge,this,[=](QByteArray data){
        QString str;
        str = data.toHex();
        qDebug()<< str;
        if(str.size() == 16){
            str = str.mid(8,4);
            qDebug()<< str;
            bool ok;
            int hexnum = str.toInt(&ok,16); // 表示以16进制方式读取字符串
            emit SendToWindow(hexnum);
        }
    });
}
