#include "bridge.h"
#include <QDebug>
#include "myhelper.h"
/*全局参数*/
//修改称重启动条件
//extern bool is_carPlnum;    //false:无车牌     true:有车牌    缺省值:false;
//extern bool is_weight;      //地磅是否达到条件
//extern bool is_carStop;     //光栅是否正常;

//extern vector <QString> m_VoiceList;    // 语音列表
int     PicNum = 0; //计数抓拍,
extern QString serialName = "com8" ;
extern long baudRate = 9600;
extern int dataBits;
extern int parity;
extern int stopBits;

extern QString ServerHost;
extern int ServerPort;

extern QString m_poundNo;
extern QString m_siteCode;
extern QString m_userName;
//结构体中的数据

static string m_busNum;//业务流水号
static string m_plateNum;//车牌号
static string m_interTime;//入场时间
static string m_outTime;//入场时间
static string m_weightTime;//称重时间
static string m_platePic;//车牌图
static string m_frontPic;//车头图
static string m_lSidePic;  //左侧抓拍
static string m_rSidePic;  //右侧抓拍
static double m_weightdata;  //稳定重量

static int m_ErrorNo = 1;

//LCD
//extern screenArea screenText;
//extern screenArea screenPic;
int colorId = 1;
Bridge* Bridge::m_instance = nullptr;
QMutex  Bridge::m_mutex;

Bridge::Bridge()
{
//    m_TcpControl = TcpControl::GetInstance();
//    m_MeterModel = MeterModel::GetInstance();
//    m_EqptControl = EqptControl::GetInstance();
//    m_EqptModel = new EqptModel;
//    m_CameraControl = new CameraControl();
//    m_RightCarmeraControl = new RightCarmeraControl();
//    m_LeftCarmeraControl = new LeftCarmeraControl();
//    m_PicToBase64Model = new PicToBase64Model();
//    m_PicToBase64Model_LeftPic = new PicToBase64Model_LeftPic();
//    m_PicToBase64Model_CarPic = new PicToBase64Model_CarPic();
//    m_PicToBase64Model_CarPlnumPic = new PicToBase64Model_CarPlnumPic();
    //    m_SqliteControl = new SqliteControl();

    m_ScanCodeControl = new ScanCodeControl();
//    m_TcpToolsControl = new TcpToolsControl();
//    m_TcpToolsModel = new TcpToolsModel();
//    m_yangbangScreen = new yangbangScreen();
    m_Headtimer = new QTimer();
    m_Headtimer2 = new QTimer();
    m_Lasttimer = new QTimer();
    m_Lasttimer2 = new QTimer();

//    m_TcpControl_Thread = new QThread;
//    m_TcpControl->moveToThread(m_TcpControl_Thread);
//    m_TcpControl_Thread->start();

//    m_EqptControl_Thread = new QThread;
//    m_EqptControl->moveToThread(m_EqptControl_Thread);
//    m_EqptControl_Thread->start();

//    m_CameraControl_Thread = new QThread;
//    m_CameraControl->moveToThread(m_CameraControl_Thread);
//    m_CameraControl_Thread->start();

//    m_RightCarmeraControl_Thread = new QThread;
//    m_RightCarmeraControl->moveToThread(m_RightCarmeraControl_Thread);
//    m_RightCarmeraControl_Thread->start();

//    m_LeftCarmeraControl_Thread = new QThread;
//    m_LeftCarmeraControl->moveToThread(m_LeftCarmeraControl_Thread);
//    m_LeftCarmeraControl_Thread->start();

//    m_PicToBase64Model_Thread = new QThread;
//    m_PicToBase64Model->moveToThread(m_PicToBase64Model_Thread);
//    m_PicToBase64Model_Thread->start();

//    m_PicToBase64Model_LeftPic_Thread = new QThread;
//    m_PicToBase64Model_LeftPic->moveToThread(m_PicToBase64Model_LeftPic_Thread);
//    m_PicToBase64Model_LeftPic_Thread->start();

//    m_PicToBase64Model_CarPic_Thread = new QThread;
//    m_PicToBase64Model_CarPic->moveToThread(m_PicToBase64Model_CarPic_Thread);
//    m_PicToBase64Model_CarPic_Thread->start();

//    m_PicToBase64Model_CarPlnumPic_Thread= new QThread;
//    m_PicToBase64Model_CarPlnumPic->moveToThread(m_PicToBase64Model_CarPlnumPic_Thread);
//    m_PicToBase64Model_CarPlnumPic_Thread->start();

//    //    m_SqliteControl_Thread= new QThread;
//    //    m_SqliteControl->moveToThread(m_SqliteControl_Thread);
//    //    m_SqliteControl_Thread->start();

//    m_TcpToolsControl_Thread= new QThread;
//    m_TcpToolsControl->moveToThread(m_TcpToolsControl_Thread);
//    m_TcpToolsControl_Thread->start();
        m_ScanCodeControl_Thread= new QThread;
        m_ScanCodeControl->moveToThread(m_ScanCodeControl_Thread);
        m_ScanCodeControl_Thread->start();

    BridgeToTcpControl_connect();
    BridgeToEqptControl_connect();
    BridgeToEqptModel_connect();
    BridgeToCameraControl_connect();
    BridgeToRightCarmeraControl_connect();
    BridgeToLeftCarmeraControl_connect();
    BridgeToPicToBase64Model_connect();
    BridgeToSqliteControl_connect();
    BridgeToScanCodeControl_connect();
    BridgeToTcpToolsControl_connect();
    BridgeToTcpToolsModel_connect();
    BridgeToyangbangScreen_connect();
}

void Bridge::BridgeToTcpControl_connect()
{
//    connect(this,&Bridge::SendToTcpControl_threadStart,m_TcpControl,[=](){
//        TcpControl::GetInstance()->Tcp_start();
//    });
//    connect(m_TcpControl,&TcpControl::SendToBridge_data,this,[=](QByteArray data){
//        //qDebug()<<"m_TcpControl:"<<data;
//        m_WeighingData_timely = m_MeterModel->MeterData(data);
//        if(m_WeighingData_timely.toDouble() < 4.0 ||m_WeighingData_timely.toDouble() > 200.0){
//            //qDebug()<<"地磅重量小于5kg,或者＞100kg,不启动稳定判断";
//            is_weight = false;
//        }
//        if(m_WeighingData_timely.toDouble() > 4.0 && m_WeighingData_timely.toDouble()< 200.0){
//            //qDebug()<<"地磅重量大于5kg,小于100Kg,启动稳定判断";
//            is_weight = true;
//        }
//    });
//    connect(m_TcpControl,&TcpControl::SendToBridge_data,this,[=](QByteArray data){
//        if(is_startCheck){

//            m_MeterModel->RecvFromBridgeData_Weightdata(data);
//        }else{
//            return ;
//        }
//    });
//    connect(m_MeterModel,&MeterModel::SendToBridge_Sqlweight,this,[=](double data){
//        qDebug()<<"稳定数据:"<<data;
//        m_weightdata = data;
//        QString str;
//        QString name_1 = "重量:";
//        QString name_11 = "KG";
//        QString name_2 = "过磅完成";
//        str = QString("\n%1%2%3\n%4").arg(name_1).arg(m_weightdata).arg(name_11).arg(name_2);
//        wstring wstr = str.toStdWString();
//        m_yangbangScreen->yangbangShowText(wstr.c_str(),colorId);

//    });
}

void Bridge::BridgeToEqptControl_connect()
{
//    connect(m_Headtimer,&QTimer::timeout,this,[=](){
//        m_Headtimer->stop();
//        m_EqptControl->SendToEqptControl_HeadGreen();
//    });
//    connect(m_Headtimer2,&QTimer::timeout,this,[=](){
//        m_Headtimer2->stop();
//        m_EqptControl->SendToEqptControl_HeadRed();
//    });

//    connect(m_Lasttimer,&QTimer::timeout,this,[=](){
//        m_Lasttimer->stop();
//        m_EqptControl->SendToEqptControl_LastGreen();
//    });
//    connect(m_Lasttimer2,&QTimer::timeout,this,[=](){
//        m_Lasttimer2->stop();
//        m_EqptControl->SendToEqptControl_LastRed();
//    });

//    connect(this,&Bridge::SendToEqptControl_threadStart,m_EqptControl,[=](){
//        EqptControl::GetInstance()->Tcp_start();
//    });
//    connect(this,&Bridge::SendToEqptControl_HeadGreen,m_EqptControl,[=](){
//        emit EqptControl::GetInstance()->SendToEqptControl_HeadGreen();
//    });
//    connect(this,&Bridge::SendToEqptControl_HeadRed,m_EqptControl,[=](){
//        emit EqptControl::GetInstance()->SendToEqptControl_HeadRed();
//    });
//    connect(this,&Bridge::SendToEqptControl_HeadTrunkUp,m_EqptControl,[=](){
//        emit EqptControl::GetInstance()->SendToEqptControl_HeadTrunkUp();
//    });
//    connect(this,&Bridge::SendToEqptControl_HeadTrunkUpRelease,m_EqptControl,[=](){
//        emit EqptControl::GetInstance()->SendToEqptControl_HeadTrunkUpRelease();
//    });
//    connect(this,&Bridge::SendToEqptControl_HeadTrunkLock,m_EqptControl,[=](){
//        emit EqptControl::GetInstance()->SendToEqptControl_HeadTrunkLock();
//    });
//    connect(this,&Bridge::SendToEqptControl_HeadTrunkUnLock,m_EqptControl,[=](){
//        emit EqptControl::GetInstance()->SendToEqptControl_HeadTrunkUnLock();
//    });
//    connect(this,&Bridge::SendToEqptControl_HeadTrunkDown,m_EqptControl,[=](){
//        emit EqptControl::GetInstance()->SendToEqptControl_HeadTrunkDown();
//    });
//    connect(this,&Bridge::SendToEqptControl_HeadTrunkDownRelease,m_EqptControl,[=](){
//        emit EqptControl::GetInstance()->SendToEqptControl_HeadTrunkDownRelease();
//    });


//    connect(this,&Bridge::SendToEqptControl_LastTrunkUp,m_EqptControl,[=](){
//        emit EqptControl::GetInstance()->SendToEqptControl_LastTrunkUp();
//    });
//    connect(this,&Bridge::SendToEqptControl_LastTrunkLock,m_EqptControl,[=](){
//        emit EqptControl::GetInstance()->SendToEqptControl_LastTrunkLock();
//    });
//    connect(this,&Bridge::SendToEqptControl_LastTrunkUnLock,m_EqptControl,[=](){
//        emit EqptControl::GetInstance()->SendToEqptControl_LastTrunkUnLock();
//    });
//    connect(this,&Bridge::SendToEqptControl_LastTrunkUpRelease,m_EqptControl,[=](){
//        emit EqptControl::GetInstance()->SendToEqptControl_LastTrunkUpRelease();
//    });
//    connect(this,&Bridge::SendToEqptControl_LastTrunkDown,m_EqptControl,[=](){
//        emit EqptControl::GetInstance()->SendToEqptControl_LastTrunkDown();
//    });
//    connect(this,&Bridge::SendToEqptControl_LastTrunkDownRelease,m_EqptControl,[=](){
//        emit EqptControl::GetInstance()->SendToEqptControl_LastTrunkDownRelease();
//    });
//    connect(this,&Bridge::SendToEqptControl_LastGreen,m_EqptControl,[=](){
//        emit EqptControl::GetInstance()->SendToEqptControl_LastGreen();
//    });
//    connect(this,&Bridge::SendToEqptControl_LastRed,m_EqptControl,[=](){
//        emit EqptControl::GetInstance()->SendToEqptControl_LastRed();
//    });
//    connect(this,&Bridge::SendToEqptControl_CartchPic,m_EqptControl,[=](){
//        emit EqptControl::GetInstance()->SendToEqptControl_CartchPic();
//    });
//    connect(m_EqptControl,&EqptControl::SendToBridge_data,this,[=](QString data){
//        qDebug()<<"m_EqptControl:"<<data;
//        m_EqptModel->RecvFromBridge_EqptData(data);
//    });
//    connect(m_EqptModel,&EqptModel::CoilStatus,this,[=](QString data){
//        qDebug()<<data;
//    });

}

void Bridge::BridgeToEqptModel_connect()
{
//    connect(m_EqptModel,&EqptModel::SendToBridge_HeadTrunk_Status,this,[=](int data){
//        if(data == 1){
//            m_Headtimer->start(1000);
//        }else{
//            m_Headtimer2->start(500);
//            //m_EqptControl->SendToEqptControl_HeadRed();
//        }
//    });
//    connect(m_EqptModel,&EqptModel::SendToBridge_LastTrunk_Status,this,[=](int data){
//        if(data == 1){
//            m_Lasttimer->start(1000);
//        }else{
//            m_Lasttimer2->start(500);
//            //m_EqptControl->SendToEqptControl_LastRed();
//        }
//    });
//    connect(m_EqptModel,&EqptModel::SendToBridge_StartCheck,this,[=](){
//        if(!m_subnum.isNull() && is_weight){
//            qDebug()<<"订单不为空,切承台有重量,启稳定判断";
//            is_startCheck = true;
//            emit SendToUi_ScanCodeWeightStart();
//            //m_VoiceForm->sayVoice("称众正在进行中,请稍后");
//        }
//        if(m_subnum.isNull() ||!is_weight){
//            qDebug()<<"订单为空,或者重量太小,不启稳定判断";
//            is_startCheck = false;
//        }
//    });

}

void Bridge::BridgeToCameraControl_connect()
{
//    connect(this,&Bridge::SendToCameraControl_Login,m_CameraControl,&CameraControl::OnClickedLogin);
//    connect(m_CameraControl,&CameraControl::SendToBridge_LoginOk,this,[=](){
//        qDebug()<<"抓拍机回复登陆成功信号";
//    });
//    connect(m_CameraControl,&CameraControl::SendToBridge_CarPic,this,
//            [=](QString data1,QString data2,QString data3){
//        if(data3.isNull()){
//            //无车牌
//            qDebug()<<"无车牌";
//            //is_carPlnum = false;
//        }
//        if(!data3.isNull()){
//            //有车牌
//            qDebug()<<"有车牌";
//            //is_carPlnum = true;
//            qDebug()<<data3;
//            m_plateNum = data3.toStdString();
//        }

//    });

}

void Bridge::BridgeToRightCarmeraControl_connect()
{
//    connect(this,&Bridge::SendToRightCarmeraControl_Login,m_RightCarmeraControl,&RightCarmeraControl::OnClickedLogin);
//    connect(this,&Bridge::SendToRightCarmeraControl_CatchRightpic,m_RightCarmeraControl,&RightCarmeraControl::OnClickedCapture);
}

void Bridge::BridgeToLeftCarmeraControl_connect()
{
//    connect(this,&Bridge::SendToLeftCarmeraControl_Login,m_LeftCarmeraControl,&LeftCarmeraControl::OnClickedLogin);
//    connect(this,&Bridge::SendToLeftCarmeraControl_CatchLeftpic,m_LeftCarmeraControl,&LeftCarmeraControl::OnClickedCapture);
}

void Bridge::BridgeToPicToBase64Model_connect()
{//右视图
//    connect(m_RightCarmeraControl,&RightCarmeraControl::SendToBridge_Rightpic,this,[=](QString data){
//        if(data.isEmpty()){
//            qDebug()<<"转换图片路径错误";
//            return;
//        }
//        emit SendToPicToBase64Model_Strat(data);
//    });
//    connect(this,&Bridge::SendToPicToBase64Model_Strat,
//            m_PicToBase64Model,&PicToBase64Model::RecvFromBridge_picPath);

//    connect(m_PicToBase64Model,&PicToBase64Model::SendToBridge_Base64data,this,[=](QByteArray data){
//        if(data.isEmpty()){
//            myHelper::ShowMessageBoxError("右视图转换异常!");
//        }else{
//            m_rSidePic = QByteToCStr(data);
//            PicNum =PicNum+1;
//            if(PicNum>1){
//                qDebug()<<"开始发送重量";
//                emit SendToTcpToolsModel_ScanCodeWeight();
//                PicNum = 0;
//            }
//        }

//    });
    //    //左视图
//    connect(m_LeftCarmeraControl,&LeftCarmeraControl::SendToBridge_Leftpic,this,[=](QString data){
//        if(data.isEmpty()){
//            qDebug()<<"转换图片路径错误";
//            return;
//        }
//        emit SendToPicToBase64Model_LeftPic_Strat(data);
//    });
//    connect(this,&Bridge::SendToPicToBase64Model_LeftPic_Strat,
//            m_PicToBase64Model_LeftPic,&PicToBase64Model_LeftPic::RecvFromBridge_picPath);

//    connect(m_PicToBase64Model_LeftPic,&PicToBase64Model_LeftPic::SendToBridge_Base64data,this,[=](QByteArray data){
//        if(data.isEmpty()){
//            myHelper::ShowMessageBoxError("左视图转换异常!");
//        }else{
//            m_lSidePic = QByteToCStr(data);
//            PicNum =PicNum+1;
//            if(PicNum>1){
//                qDebug()<<"开始发送重量"<<"写数据到数据库";
//                emit SendToTcpToolsModel_ScanCodeWeight();
//                PicNum = 0;
//            }
//        }
//    });
    //前抓拍
//    connect(m_CameraControl,&CameraControl::SendToBridge_CarPic,this,[=](QString data1,QString data2,QString data3){
//        if(data3.isEmpty()){
//            qDebug()<<"车牌识别失败,请重试";
//            return;
//        }
//        plateNum = data3;
//        picPath = data1;
//        emit SendToPicToBase64Model_CarPic_Strat(data1);
//        emit SendToPicToBase64Model_CarPlnumPic_Strat(data2);
//    });
//    connect(this,&Bridge::SendToPicToBase64Model_CarPic_Strat,
//            m_PicToBase64Model_CarPic,&PicToBase64Model_CarPic::RecvFromBridge_picPath);

//    connect(this,&Bridge::SendToPicToBase64Model_CarPlnumPic_Strat,
//            m_PicToBase64Model_CarPlnumPic,&PicToBase64Model_CarPlnumPic::RecvFromBridge_picPath);

//    connect(m_PicToBase64Model_CarPic,&PicToBase64Model_CarPic::SendToBridge_Base64data,this,[=](QByteArray data){
//        //车头图
//        if(data.isEmpty()){
//            myHelper::ShowMessageBoxError("钱抓拍视图转换异常!");
//        }else{
//            m_frontPic = QByteToCStr(data);
//        }
//    });
//    connect(m_PicToBase64Model_CarPlnumPic,&PicToBase64Model_CarPlnumPic::SendToBridge_Base64data,this,[=](QByteArray data){
//        //车牌图
//        if(data.isEmpty()){
//            myHelper::ShowMessageBoxError("钱抓拍视图转换异常!");
//        }else{
//            m_platePic = QByteToCStr(data);
//        }
//    });
}

void Bridge::BridgeToSqliteControl_connect()
{
    //    connect(this,&Bridge::SendToSqliteControl_OpenDB,m_SqliteControl,&SqliteControl::OpenDB);
}

void Bridge::BridgeToScanCodeControl_connect()
{
//    connect(this,&Bridge::SendToScanCodeControl_Start,m_ScanCodeControl,[=](){
//        m_ScanCodeControl->setComm(serialName,baudRate);
//    });
    connect(m_ScanCodeControl,&ScanCodeControl::SendToBridge_ScanCodeData,this,[=](QString data){
        if(!data.isNull()){
            if(m_subnum != data){
                m_busNum = data.toStdString();
                m_subnum = data;
            }
            if(m_subnum == data){
                return;
            }
        }
    });
}

void Bridge::BridgeToTcpToolsControl_connect()
{
//    connect(this,&Bridge::SendToTcpToolsControl_Connect,m_TcpToolsControl,[=](){
//        m_TcpToolsControl->setHostAndePort(ServerHost,ServerPort);
//    });
//    connect(m_TcpToolsControl,&TcpToolsControl::TCPSocketIsConnected,this,[=](){
//        qDebug()<<"服务器已连接";
//    });
//    connect(m_TcpToolsControl,&TcpToolsControl::SendToBridge_RecvData,this,[=](QByteArray data){
//        qDebug()<<"处理接受服务器的数据结果:"<<m_TcpToolsModel->RecvFromBridge_ServerData(data);
//    });
//    connect(this,SIGNAL(SendToTcpToolsControl_Register(QByteArray)),m_TcpToolsControl,SIGNAL(RecvFromBridge_Register(QByteArray)));
//    connect(this,SIGNAL(SendToTcpToolsControl_Enter1(QByteArray)),m_TcpToolsControl,SIGNAL(RecvFromBridge_Enter1(QByteArray)));
//    connect(this,SIGNAL(SendToTcpToolsControl_ScanEnter(QByteArray)),m_TcpToolsControl,SIGNAL(RecvFromBridge_ScanEnter(QByteArray)));
//    connect(this,SIGNAL(SendToTcpToolsControl_ScanCodeStart(QByteArray)),m_TcpToolsControl,SIGNAL(RecvFromBridge_ScanCodeStart(QByteArray)));
//    connect(this,SIGNAL(SendToTcpToolsControl_Enter2(QByteArray)),m_TcpToolsControl,SIGNAL(RecvFromBridge_Enter2(QByteArray)));
//    connect(this,SIGNAL(SendToTcpToolsControl_HeadTrunk(QByteArray)),m_TcpToolsControl,SIGNAL(RecvFromBridge_Enter2(QByteArray)));
//    connect(this,SIGNAL(SendToTcpToolsControl_Out(QByteArray)),m_TcpToolsControl,SIGNAL(RecvFromBridge_CarOut(QByteArray)));
//    connect(this,SIGNAL(SendToTcpToolsControl_ScanOut(QByteArray)),m_TcpToolsControl,SIGNAL(RecvFromBridge_CarScanOut(QByteArray)));
//    connect(this,SIGNAL(SendToTcpToolsControl_Weight(QByteArray)),m_TcpToolsControl,SIGNAL(RecvFromBridge_Weight(QByteArray)));
//    connect(this,SIGNAL(SendToTcpToolsControl_ScanCodeWeight(QByteArray)),m_TcpToolsControl,SIGNAL(RecvFromBridge_Weight(QByteArray)));
//    connect(this,SIGNAL(SendToTcpToolsControl_Error(QByteArray)),m_TcpToolsControl,SIGNAL(RecvFromBridge_Error(QByteArray)));
}

void Bridge::BridgeToTcpToolsModel_connect()
{
//    connect(this,&Bridge::SendToTcpToolsModel_Register,m_TcpToolsModel,[=](){
//        //注册
//        RegisterForm from;
//        from.poundNo = m_poundNo.toStdString();
//        from.stationCode = m_siteCode.toStdString();
//        from.userName = m_userName.toStdString();
//        QByteArray data = m_TcpToolsModel->SendToBridge_Register(from);
//        emit SendToTcpToolsControl_Register(data);
//    });
//    connect(this,&Bridge::SendToTcpToolsModel_Enter1,m_TcpToolsModel,[=](){
//        //模式1入场
//        m_interTime = strTime();
//        qDebug()<<"入场时间:"<<QString::fromStdString(m_interTime);
//        qDebug()<<"入场车牌:"<<QString::fromStdString(m_plateNum);
//        CarInForm from;
//        from.stationCode = m_poundNo.toStdString();
//        from.plateNum = m_plateNum;
//        from.interTime = m_interTime;
//        from.platePic = m_platePic;
//        from.frontPic = m_frontPic;
//        QByteArray data = m_TcpToolsModel->SendToBridge_Enter1(from);
//        emit SendToTcpToolsControl_Enter1(data);
//    });
//    connect(this,&Bridge::SendToTcpToolsModel_ScanEnter,m_TcpToolsModel,[=](){
//        //扫码入场
//        m_interTime = strTime();
//        qDebug()<<"入场时间:"<<QString::fromStdString(m_interTime);
//        qDebug()<<"入场车牌:"<<QString::fromStdString(m_plateNum);
//        CarInForm from;
//        from.interTime = m_interTime;
//        from.busNum = m_busNum;
//        from.frontPic = m_frontPic;
//        QByteArray data = m_TcpToolsModel->SendToBridge_ScanEnter(from);
//        emit SendToTcpToolsControl_Enter1(data);
//    });
//    connect(this,&Bridge::SendToTcpToolsModel_ScanCodeStart,m_TcpToolsModel,[=](){
//        //发送业务号
//        WeightForm from;
//        from.busNum = m_busNum;
//        QByteArray data = m_TcpToolsModel->SendToBridge_ScanCodeStrat(from);
//        emit SendToTcpToolsControl_ScanCodeStart(data);
//    });
//    connect(this,&Bridge::SendToTcpToolsModel_Enter2,m_TcpToolsModel,[=](){
//        //模式2入场
//        CarInForm from;
//        from.stationCode = m_poundNo.toStdString();
//        from.plateNum = m_plateNum;
//        from.interTime = m_interTime;
//        from.platePic = m_platePic;
//        from.frontPic = m_frontPic;
//        QByteArray data = m_TcpToolsModel->SendToBridge_Enter1(from);
//        emit SendToTcpToolsControl_Enter2(data);
//    });
//    connect(this,&Bridge::SendToTcpToolsModel_ScanCodeWeight,m_TcpToolsModel,[=](){
//        //扫码称重
//        m_interTime = strTime();
//        WeightForm from;
//        from.busNum = m_busNum;
//        from.poundNo = "001";
//        from.lSidePic = m_lSidePic;
//        from.rSidePic = m_rSidePic;
//        from.weightTime = m_interTime;
//        from.sumWeight = m_weightdata * 100;
//        QByteArray data = m_TcpToolsModel->SendToBridge_ScanCodeWeight(from);
//        emit SendToTcpToolsControl_ScanCodeWeight(data);
//    });
//    connect(this,&Bridge::SendToTcpToolsModel_HeadTrunk,m_TcpToolsModel,[=](){
//        //扫码称重发送
//        WeightForm from;
//        from.plateNum = m_plateNum;
//        from.plateNum = m_plateNum;
//        from.plateNum = m_plateNum;
//        //QByteArray data = m_TcpToolsModel->SendToBridge_ScanCodeWeight(from);
//        // emit SendToTcpToolsControl_HeadTrunk(data);
//    });
//    connect(this,&Bridge::SendToTcpToolsModel_Out,m_TcpToolsModel,[=](){
//        //出场
//        m_outTime = strTime();
//        qDebug()<<"出场时间:"<<QString::fromStdString(m_outTime);
//        qDebug()<<"出场车牌:"<<QString::fromStdString(m_plateNum);
//        CarOutForm from;
//        from.stationCode = m_poundNo.toStdString();
//        from.plateNum = m_plateNum;
//        from.outTime = m_outTime;
//        from.platePic = m_platePic;
//        from.frontPic = m_frontPic;
//        QByteArray data = m_TcpToolsModel->SendToBridge_Out(from);
//        emit SendToTcpToolsControl_Out(data);
//    });
//    connect(this,&Bridge::SendToTcpToolsModel_ScanOut,m_TcpToolsModel,[=](){
//        //扫码出场
//        m_outTime = strTime();
//        qDebug()<<"出场时间:"<<QString::fromStdString(m_outTime);
//        qDebug()<<"出场车牌:"<<QString::fromStdString(m_plateNum);
//        CarOutForm from;
//        from.busNum = m_busNum;
//        from.outTime = m_outTime;
//        from.frontPic = m_frontPic;
//        QByteArray data = m_TcpToolsModel->SendToBridge_ScanOut(from);
//        emit SendToTcpToolsControl_ScanOut(data);
//    });
//    connect(this,&Bridge::SendToTcpToolsModel_Weight,m_TcpToolsModel,[=](){
//        //重量
//        m_weightTime = strTime();
//        WeightForm from;
//        from.poundNo = m_poundNo.toStdString();
//        from.plateNum = m_plateNum;
//        from.weightTime = m_weightTime;
//        from.platePic = m_platePic;
//        from.frontPic = m_frontPic;
//        from.lSidePic = m_lSidePic;
//        from.rSidePic = m_rSidePic;
//        QByteArray data = m_TcpToolsModel->SendToBridge_Weight(from);
//        emit SendToTcpToolsControl_Weight(data);
//    });
//    connect(this,&Bridge::SendToTcpToolsModel_Error,m_TcpToolsModel,[=](){
//        //异常
//        ErrorForm from;
//        from.weightTime = m_poundNo.toStdString();
//        from.errorNo = m_ErrorNo;
//        QByteArray data = m_TcpToolsModel->SendToBridge_Error1(from);
//        emit SendToTcpToolsControl_Error(data);
//    });

    //服务器返回状态

//    connect(m_TcpToolsModel,&TcpToolsModel::SendToBridge_RegisterReply,this,[=](int data){
//        qDebug()<<"注册回应状态:"<<data;
//        if(data == 1){
//            myHelper::ShowMessageBoxInfo("站点注册成功!");
//        }else{
//            myHelper::ShowMessageBoxError("站点注册失败!");
//        }
//    });

//    connect(m_TcpToolsModel,&TcpToolsModel::SendToBridge_Enter1Reply,this,[=](int data){
//        qDebug()<<"入场回应状态:"<<data;
//        if(data == 1){

//            //myHelper::ShowMessageBoxInfo("站点注册成功!");
//        }else{
//            myHelper::ShowMessageBoxError("入场失败!");
//        }
//    });

//    connect(m_TcpToolsModel,&TcpToolsModel::SendToBridge_OutReply,this,[=](int data){
//        qDebug()<<"出场回应状态:"<<data;
//        if(data == 1){
//            //myHelper::ShowMessageBoxInfo("站点注册成功!");
//        }else{
//            myHelper::ShowMessageBoxError("出场失败!");
//        }
//    });

//    connect(m_TcpToolsModel,&TcpToolsModel::SendToBridge_WeightReply,this,[=](int data){
//        qDebug()<<"称重回应状态:"<<data;
//        if(data == 1){
//            //myHelper::ShowMessageBoxInfo("站点注册成功!");
//        }else{
//            myHelper::ShowMessageBoxError("称重失败!");
//        }
//    });

//    connect(m_TcpToolsModel,&TcpToolsModel::SendToBridge_HeadTrunkReply,this,[=](int data){
//        qDebug()<<"道闸回应状态:"<<data;
//        if(data == 1){
//            //myHelper::ShowMessageBoxInfo("站点注册成功!");
//        }else{
//            myHelper::ShowMessageBoxError("道闸失败!");
//        }
//    });

//    connect(m_TcpToolsModel,&TcpToolsModel::SendToBridge_Error1Reply,this,[=](int data){
//        qDebug()<<"异常回应状态:"<<data;
//        if(data == 1){
//            //myHelper::ShowMessageBoxInfo("站点注册成功!");
//        }else{
//            myHelper::ShowMessageBoxError("异常失败!");
//        }
//    });
//    connect(m_TcpToolsModel,&TcpToolsModel::SendToBridge_ScanEnterReply,this,[=](int data){
//        qDebug()<<"扫码入场回应状态:"<<data;
//        if(data == 1){
//            //myHelper::ShowMessageBoxInfo("扫码入场成功!");
//            emit m_EqptControl->SendToEqptControl_HeadTrunkUp();

//        }else{

//            //myHelper::ShowMessageBoxError("扫码入场失败!");

//        }
//    });
//    connect(m_TcpToolsModel,&TcpToolsModel::SendToBridge_ScanCodeStartReply,this,[=](int data){
//        qDebug()<<"业务流水号回应状态:"<<data;
//        if(data == 1){
//            emit m_EqptControl->SendToEqptControl_HeadTrunkUp();
//            emit SendToUi_ScanCodeReplay();

//        }else{
//            emit SendToUi_ScanCodeReplayError();

//            //myHelper::ShowMessageBoxError("扫码入场失败!");
//        }
//    });
//    connect(m_TcpToolsModel,&TcpToolsModel::SendToBridge_ScanCodeWeightReply,this,[=](int data){
//        qDebug()<<"称重回应状态:"<<data;
//        if(data == 1){
//            emit m_EqptControl->SendToEqptControl_LastTrunkUp();
//        }else{
//            myHelper::ShowMessageBoxError("称重失败失败!请重来");

//        }
//    });
}

void Bridge::BridgeToyangbangScreen_connect()
{
//    connect(this,&Bridge::SendToyangbangScreen_Login,this,[=](){
//        m_yangbangScreen->InitScreen(screenText.ip,screenText.prot);
//    });
}

string Bridge::QByteToCStr(QByteArray data)
{
    qDebug()<<"图片格式转换";
    return QString(data).toStdString();
}

string Bridge::strTime()
{
    QDateTime currentDateTime = QDateTime::currentDateTime();
    QString tim = currentDateTime.toString("yyyy-MM-dd hh:mm:ss");
    return tim.toStdString();
}

Bridge::~Bridge()
{

}

Bridge *Bridge::GetInstance()
{
    if (m_instance == nullptr)
    {
        QMutexLocker locker(&m_mutex);
        if (m_instance == nullptr)
        {
            m_instance = new Bridge();
        }
    }
    return m_instance;
}

void Bridge::CD_is_startCheck()
{
    is_startCheck = false;
}

QString Bridge::UpDataUi_WeighingData()
{
    return m_WeighingData_timely;
}

QString Bridge::UpDataUi_carInTime()
{
    return QString::fromStdString(m_interTime);
}

QString Bridge::UpDataUi_carOutTime()
{
    return QString::fromStdString(m_outTime);
}
