//#pragma execution_character_set("utf-8")
#include "widget.h"
#include "ui_widget.h"
#include <QMessageBox>
Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    connect(ui->btnConn,SIGNAL(clicked()),this,SLOT(slotConnect()));
    connect(ui->btnDis,SIGNAL(clicked()),this,SLOT(slotDisCon()));
     connect(&m_TcpClent,SIGNAL(SigRectMsg(QByteArray & )),this,SLOT(slotRec(QByteArray &)));
     ui->editIp->setText("192.168.1.11");
     ui->spnPort->setRange(1,1000000);
      ui->spnPort->setValue(5086);
}

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

void Widget::slotConnect()
{
    QString  sIP = ui->editIp->text();
    int port    = ui->spnPort->value();
    if( m_TcpClent.connectServer(sIP,port))
    {
         QMessageBox::information(this,"succeed"," succeed");
    }
    else
    {
        QMessageBox::warning(this,"failed"," failed");
    }

}
void Widget::slotDisCon()
{

    if( m_TcpClent.disConnectServer())
    {
         QMessageBox::information(this,"succeed"," succeed");
    }
    else
    {
        QMessageBox::warning(this,"failed"," failed");
    }
}
void Widget::slotSend()
{


}
void Widget::slotRec(QByteArray & data)
{
    qDebug()<<"data---"<<data<<endl;
    DataPacket datapack;
    datapack.deserialize(data);
#if  0

   qDebug()<<QString::fromLocal8Bit("包序号:")+QString::number(datapack.packetSeq)<<endl;;
   qDebug()<<QString::fromLocal8Bit("数据块长度 :")+QString::number(datapack.dataLength)<<endl;;;       // 数据块长度 (2 bytes)
   qDebug()<<QString::fromLocal8Bit("电量:")+QString::number(datapack.batteryLevel)<<endl;;;      // 电量 (1 byte)
   qDebug()<<QString::fromLocal8Bit("通道数量:")+QString::number(datapack.channelCount)<<endl;;;      // 通道数量 (1 byte)
   qDebug()<<QString::fromLocal8Bit("俯仰角:")+QString::number(datapack.pitchAngle)<<endl;;;        // 俯仰角 (2 bytes)
   qDebug()<<QString::fromLocal8Bit("滚动角:")+QString::number(datapack.rollAngle)<<endl;;;         // 滚动角 (2 bytes)
   qDebug()<<QString::fromLocal8Bit("偏航角:")+QString::number(datapack.yawAngle)<<endl;;;          // 偏航角 (2 bytes)
   qDebug()<<QString::fromLocal8Bit("心电:")+QString::number(datapack.ecg)<<endl;;;              // 心电 (2 bytes)
   qDebug()<<QString::fromLocal8Bit("血氧:")+QString::number(datapack.spo2)<<endl;;;             // 血氧 (2 bytes)


    qDebug()<<"packetSeq :"+QString::number(datapack.packetSeq)<<endl;;
    qDebug()<<"dataLength:"+QString::number(datapack.dataLength)<<endl;;;       // 数据块长度 (2 bytes)
    qDebug()<<"batteryLevel"+QString::number(datapack.batteryLevel)<<endl;;;      // 电量 (1 byte)
    qDebug()<<"channelCount"+QString::number(datapack.channelCount)<<endl;;;      // 通道数量 (1 byte)
    qDebug()<<"pitchAngle"+QString::number(datapack.pitchAngle)<<endl;;;        // 俯仰角 (2 bytes)
    qDebug()<<"rollAngle"+QString::number(datapack.rollAngle)<<endl;;;         // 滚动角 (2 bytes)
    qDebug()<<"yawAngle"+QString::number(datapack.yawAngle)<<endl;;;          // 偏航角 (2 bytes)
    qDebug()<<"ecg"+QString::number(datapack.ecg)<<endl;;;              // 心电 (2 bytes)
    qDebug()<<"spo2"+QString::number(datapack.spo2)<<endl;;;             // 血氧 (2 bytes)

#endif

}
