其他分享
首页 > 其他分享> > 2021-02-26

2021-02-26

作者:互联网

数据解析

/*******************************************************************
 * 函数功能:接收遥控器传来的数据并进行解析
 * 调用:放在定时器中断服务函数中定时接收
 * 时间:2020.12.5
********************************************************************/
void MainWindow::rec_buffer()//接收操纵杆
{
    buffer = serial->readAll();
    buffer = buffer.toHex();

    QString rDate;
    QByteArray fPLatLeverPercent,fPFanLeverPercent,fPMainLeverPercent,fPLonLeverPercent,
               fPoil1LeverPercent,fPoil2LeverPercent,byteFlyingMode;
    rDate = QString(buffer);
    if(buffer != NULL)
    {
        if(rDate[0] == '0'&&rDate[1] == 'f'&&rDate.length() >= 70)
        {
            //qDebug("%s",qPrintable(rDate));
            rDate.remove(0, 2);
            fPLatLeverPercent = rDate.left(4).toLocal8Bit();
            rDate.remove(0, 4);
            fPFanLeverPercent = rDate.left(4).toLocal8Bit();
            rDate.remove(0, 4);
            fPMainLeverPercent = rDate.left(4).toLocal8Bit();
            rDate.remove(0, 4);
            fPLonLeverPercent = rDate.left(4).toLocal8Bit();
            rDate.remove(0, 4);
            byteFlyingMode = rDate.left(4).toLocal8Bit();
            rDate.remove(0, 4);
            fPoil1LeverPercent = rDate.left(4).toLocal8Bit();
            rDate.remove(0, 4);
            fPoil2LeverPercent = rDate.left(4).toLocal8Bit();
            rDate.remove(0, 4);

            gl_intPLatLeverPercent = (int16_t)fPLatLeverPercent.toInt(nullptr, 16);
            gl_intPFanLeverPercent = (int16_t)fPFanLeverPercent.toInt(nullptr, 16);
            gl_intPMainLeverPercent = (uint16_t)fPMainLeverPercent.toInt(nullptr, 16);
            gl_intPLonLeverPercent = (int16_t)fPLonLeverPercent.toInt(nullptr, 16);
            gl_intPOil1LeverPercent = (uint16_t)fPoil1LeverPercent.toInt(nullptr, 16);
            gl_intPOil2LeverPercent = (uint16_t)fPoil2LeverPercent.toInt(nullptr, 16);

        }
    }
    buffer.clear();
}

标签:02,26,toLocal8Bit,16,buffer,remove,rDate,2021,left
来源: https://blog.csdn.net/qq_42066648/article/details/114118835