#ifndef BRIDGE_H
#define BRIDGE_H

#include <QMutex>
#include <QObject>
#include <QThread>
#include <windows.h>
//#include "getPcInfo_model/globalapiclass.h" //获取电脑信息
//#include "meter_control/tcpcontrol.h"   //  仪表控制--TCP链接
//#include "meter_model/metermodel.h"     //  仪表数据处理
//#include "eqpt_control/eqptcontrol.h"   //  外围设备控制
//#include "eqpt_model/eqptmodel.h"
//#include "hkCapture_control/cameracontrol.h"    //  抓拍机控制模块
//#include "rightCarmera_control/rightcarmeracontrol.h"   // 右侧相机控制
//#include "leftCarmera_control/leftcarmeracontrol.h"   // 左侧相机控制
//#include "picToBase64_model/pictobase64model.h"     //图片转换控制
////#include "sqlite_control/sqlitecontrol.h"   //数据库管理模块
////#include "voice_view/voiceview.h"   // 语音管理模块
#include "scanCode_control/scancodecontrol.h"   //扫码模块
//#include "tcpTools_control/tcptoolscontrol.h"   //TCP控制模块
//#include "tcpTools_model/tcptoolsmodel.h"   //TCP数据管理模块

//#include "led_model/yangbangscreen.h"
//#include "weightinfo.h"
using namespace std;
class Bridge : public QObject
{
    Q_OBJECT
public:
    ~Bridge();
    //单例模式
    static Bridge* GetInstance();
    //声明模块
    //TcpControl *m_TcpControl;
    //MeterModel *m_MeterModel;

    QString m_subnum;   //缓存业务流水号
    //EqptControl *m_EqptControl;
    //EqptModel *m_EqptModel;
    //CameraControl *m_CameraControl;
    //RightCarmeraControl *m_RightCarmeraControl;
//    LeftCarmeraControl *m_LeftCarmeraControl;
//    PicToBase64Model *m_PicToBase64Model;
//    PicToBase64Model_LeftPic *m_PicToBase64Model_LeftPic;
//    PicToBase64Model_CarPic *m_PicToBase64Model_CarPic;
//    PicToBase64Model_CarPlnumPic *m_PicToBase64Model_CarPlnumPic;
    //    SqliteControl *m_SqliteControl;

    ScanCodeControl *m_ScanCodeControl;

//    TcpToolsControl *m_TcpToolsControl;
//    TcpToolsModel *m_TcpToolsModel;
//    yangbangScreen *m_yangbangScreen;


public:
    //更改状态
    void CD_is_startCheck();
    //通过回调函数,更新Ui界面数据;
    QString UpDataUi_WeighingData();
    QString UpDataUi_carInTime();
    QString UpDataUi_carOutTime();
signals:
    //仪表线程启动信号
    void SendToTcpControl_threadStart();
    //外围设备线程启动信号
    void SendToEqptControl_threadStart();
    //通过界面绿灯
    void SendToEqptControl_HeadGreen();
    void SendToEqptControl_HeadRed();
    void SendToEqptControl_HeadTrunkUp();
    void SendToEqptControl_HeadTrunkUpRelease();
    void SendToEqptControl_HeadTrunkLock();
    void SendToEqptControl_HeadTrunkUnLock();
    void SendToEqptControl_HeadTrunkDown();
    void SendToEqptControl_HeadTrunkDownRelease();
    void SendToEqptControl_LastTrunkUp();
    void SendToEqptControl_LastTrunkLock();
    void SendToEqptControl_LastTrunkUnLock();
    void SendToEqptControl_LastTrunkUpRelease();
    void SendToEqptControl_LastTrunkDown();
    void SendToEqptControl_LastTrunkDownRelease();
    void SendToEqptControl_LastGreen();
    void SendToEqptControl_LastRed();
    void SendToEqptControl_CartchPic();

    //抓拍机控制
    void SendToCameraControl_Login();
    void SendToCameraControl_Catchpic();
    //    //右侧相机
    void SendToRightCarmeraControl_Login();
    void SendToRightCarmeraControl_CatchRightpic();
    //    //左侧相机
    void SendToLeftCarmeraControl_Login();
    void SendToLeftCarmeraControl_CatchLeftpic();
    //图片转换
    void SendToPicToBase64Model_Strat(QString data);
    void SendToPicToBase64Model_LeftPic_Strat(QString data);
    void SendToPicToBase64Model_CarPic_Strat(QString data);
    void SendToPicToBase64Model_CarPlnumPic_Strat(QString data);
    // 数据库
    void SendToSqliteControl_OpenDB();  //打开数据库
    //    void SendToSqliteControl_InsertDB(Vehicle_info &info);  //插入数据库
    void SendToSqliteControl_DeletDB();  //删除数据库
    void SendToSqliteControl_UpDataDB();  //更新数据库
    void SendToSqliteControl_SelectDB();  //查询数据库

    //扫码
    void SendToScanCodeControl_Start();
    //TCP
    void SendToTcpToolsControl_Connect();   //连接服务器
    void SendToTcpToolsControl_Register(QByteArray data);   //连接服务器
    void SendToTcpToolsControl_Enter1(QByteArray data);   //模式一入场
    void SendToTcpToolsControl_ScanCodeStart(QByteArray data);   //发送扫码数据
    void SendToTcpToolsControl_ScanEnter(QByteArray data);   //扫码入场
    void SendToTcpToolsControl_Enter2(QByteArray data);   //模式二入场
    void SendToTcpToolsControl_HeadTrunk(QByteArray data);   //前道闸
    void SendToTcpToolsControl_Out(QByteArray data);   //出场
    void SendToTcpToolsControl_ScanOut(QByteArray data);   //出场
    void SendToTcpToolsControl_Weight(QByteArray data);   //称重
    void SendToTcpToolsControl_ScanCodeWeight(QByteArray data);   //扫码称重
    void SendToTcpToolsControl_Error(QByteArray data);   //异常

    //TCP_MODEL
    void SendToTcpToolsModel_Register();    //站点注册
    void SendToTcpToolsModel_Enter1();    //模式一入场
    void SendToTcpToolsModel_ScanEnter();    //扫码入场
    void SendToTcpToolsModel_ScanCodeStart();    //扫码开始称重
    void SendToTcpToolsModel_Enter2();    //模式二入场
    void SendToTcpToolsModel_HeadTrunk();    //前道闸
    void SendToTcpToolsModel_ScanCodeWeight();    //扫码称重
    void SendToTcpToolsModel_Out();    //出场
    void SendToTcpToolsModel_ScanOut();    //出场
    void SendToTcpToolsModel_Weight();    //称重
    void SendToTcpToolsModel_Error();    //异常
    //LCD 显示屏
    void SendToyangbangScreen_Login();  //登陆
    //发送给界面提示称重开始
    void SendToUi_ScanCodeWeightStart();
    void SendToUi_ScanCodeReplay();
    void SendToUi_ScanCodeReplayError();


public slots:

private:
    Bridge();

    static Bridge *m_instance;
    static QMutex  m_mutex;
    QThread *m_TcpControl_Thread;
    QThread *m_EqptControl_Thread;
    QThread *m_CameraControl_Thread;
    QThread *m_RightCarmeraControl_Thread;
    QThread *m_LeftCarmeraControl_Thread;
    QThread *m_PicToBase64Model_Thread;
    QThread *m_PicToBase64Model_LeftPic_Thread;
    QThread *m_PicToBase64Model_CarPic_Thread;
    QThread *m_PicToBase64Model_CarPlnumPic_Thread;
    QThread *m_SqliteControl_Thread;
    QThread *m_ScanCodeControl_Thread;
    QThread *m_TcpToolsControl_Thread;


    void BridgeToTcpControl_connect();  //  桥和仪表之间的通讯
    void BridgeToEqptControl_connect();  //  桥和外围设备之间的通讯
    void BridgeToEqptModel_connect();  //  桥和外围处理设备之间的通讯
    void BridgeToCameraControl_connect();  //  桥和抓拍机之间的通讯
    void BridgeToRightCarmeraControl_connect();  //  桥和右侧相机之间的通讯
    void BridgeToLeftCarmeraControl_connect();  //  桥和左侧相机之间的通讯
    void BridgeToPicToBase64Model_connect();  //  桥和图片转换器之间的通讯
    void BridgeToSqliteControl_connect();  //  桥和数据库之间的通讯
    void BridgeToScanCodeControl_connect();  //  桥和扫码模块之间的通讯
    void BridgeToTcpToolsControl_connect();  //  桥和TCP控制模块之间的通讯
    void BridgeToTcpToolsModel_connect();  //  桥和TCP控制模块之间的通讯
    void BridgeToyangbangScreen_connect();  //  桥和LCD控制模块之间的通讯

    string QByteToCStr(QByteArray data);
    string strTime();
private:
    //实时称重
    QString m_WeighingData_timely;  //实时称重数据
    QString plateNum = "";
    QString picPath = "";
    bool is_weight = false;
    bool is_startCheck = false;
    QTimer *m_Headtimer;
    QTimer *m_Headtimer2;
    QTimer *m_Lasttimer;
    QTimer *m_Lasttimer2;

};

#endif // BRIDGE_H
