#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QSerialPortInfo>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    m_Bridge = new Bridge();
    connect(ui->pbn_sure,&QPushButton::clicked,this,[=](){
        if(ui->lineEdit_EPC->text().isEmpty()){
            qDebug()<<"请检查识别卡";
            return ;
        }
        if(ui->lineEdit_carPlnum->text().isEmpty()){
            qDebug()<<"请检查输入的车牌信息";
            return ;
        }
        emit m_Bridge->SendToTCPSocketHelperBinding(ui->lineEdit_EPC->text(),ui->lineEdit_carPlnum->text());
    });

    connect(ui->actionRegister,&QAction::triggered,this,[=](){
        //点击注册
        emit m_Bridge->SendToTCPSocketHelperConnect();
        emit m_Bridge->SendToTCPSocketHelperRegister();
    });

    ReadWindow_init();
    Updata_ui();
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::ReadWindow_init()
{
    setWindowTitle("车辆ID绑定");
    ui->lineEdit_EPC->setFixedHeight(this->height()/4);
    ui->lineEdit_carPlnum->setFixedHeight(this->height()/4);
    ui->lineEdit_carPlnum->setPlaceholderText("请输入要绑定的车牌号");
    ui->lineEdit_EPC->setPlaceholderText("请将车辆识别卡放入识别区");
    ui->lineEdit_EPC->setReadOnly(true);
    emit m_Bridge->SendToReadEPCControl_Start_Read("COM2",57600);
}

void MainWindow::Updata_ui()
{
    connect(m_Bridge,&Bridge::SendToWindow,this,[=](int data){
        ui->lineEdit_EPC->setText(QString::number(data));
    });
}
