MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { pass_edge = 0; order = 3; taps = 25; alpha = 0.25; trans = 0.1; stop_dBs = 40; bits = 0; pts = 250; w = new double[pts]; for (int i=0;i<pts;i++) { w[i] = (double)i*i; } lpf_init(pts); Butterworth_on = NULL; Chebyshev_on = NULL; Elliptic_on = NULL; MaxflatFIR_on = NULL; MaxflatHalfband_on = NULL; RaisedCosine_on = NULL; RootRaisedCosine_on = NULL; EllipticHalfband_on = NULL; Remez_on = NULL; NotchIIR_on = NULL; CutBoost_on = NULL; graph_counter = 0; ui->setupUi(this); // setGeometry(400, 250, 542, 390); setup(ui->customPlot); setWindowTitle("QCustomPlot: "+demoName); statusBar()->clearMessage(); connect(ui->Butterworth, SIGNAL(released()), this, SLOT(BChanged())); connect(ui->Chebyshev, SIGNAL(released()), this, SLOT(CChanged())); connect(ui->Elliptic, SIGNAL(released()), this, SLOT(EChanged())); connect(ui->MaxflatFIR, SIGNAL(released()), this, SLOT(FChanged())); connect(ui->MaxflatHalfband, SIGNAL(released()), this, SLOT(FHChanged())); connect(ui->RaisedCosine, SIGNAL(released()), this, SLOT(RCChanged())); connect(ui->RootRaisedCosine, SIGNAL(released()), this, SLOT(RRCChanged())); connect(ui->EllipticHalfband, SIGNAL(released()), this, SLOT(EHChanged())); connect(ui->Remez, SIGNAL(released()), this, SLOT(RChanged())); connect(ui->NotchIIR, SIGNAL(released()), this, SLOT(NChanged())); connect(ui->CutBoost, SIGNAL(released()), this, SLOT(CBChanged())); connect(ui->customPlot, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(graphPressEvent(QMouseEvent*))); connect(ui->customPlot, SIGNAL(mouseMove(QMouseEvent*)), this, SLOT(graphMoveEvent(QMouseEvent*))); ui->customPlot->replot(); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { order = 13; alpha = 0.25; stop_dBs = 40; pts = 250; w = new double[pts]; for (int i=0;i<pts;i++) { w[i] = (double)i*i; } LPF.init(pts); MaxflatSubband_on = NULL; EllipticSubband_on = NULL; CutBoost_on = NULL; NotchIIR_on = NULL; graph_counter = 0; ui->setupUi(this); // setGeometry(400, 250, 542, 390); setup(ui->customPlot); setWindowTitle("QCustomPlot: "+demoName); statusBar()->clearMessage(); connect(ui->MaxflatSubband, SIGNAL(released()), this, SLOT(MChanged())); connect(ui->EllipticSubband, SIGNAL(released()), this, SLOT(EChanged())); connect(ui->CutBoost, SIGNAL(released()), this, SLOT(CChanged())); connect(ui->NotchIIR, SIGNAL(released()), this, SLOT(NChanged())); connect(ui->customPlot, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(graphPressEvent(QMouseEvent*))); connect(ui->customPlot, SIGNAL(mouseMove(QMouseEvent*)), this, SLOT(graphMoveEvent(QMouseEvent*))); ui->customPlot->replot(); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { pass_edge = 0; order = 3; trans = 0.1; stop_dBs = 40; pts = 250; w = new double[pts]; for (int i=0;i<pts;i++) { w[i] = (double)i*i; } lpf_init(pts); Butterworth_on = NULL; Chebyshev_on = NULL; Chebyshev2_on = NULL; Elliptic_on = NULL; graph_counter = 0; ui->setupUi(this); // setGeometry(400, 250, 542, 390); setup(ui->customPlot); setWindowTitle("QCustomPlot: "+demoName); statusBar()->clearMessage(); connect(ui->Butterworth, SIGNAL(released()), this, SLOT(BChanged())); connect(ui->Chebyshev, SIGNAL(released()), this, SLOT(CChanged())); connect(ui->Chebyshev2, SIGNAL(released()), this, SLOT(C2Changed())); connect(ui->Elliptic, SIGNAL(released()), this, SLOT(EChanged())); connect(ui->customPlot, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(graphPressEvent(QMouseEvent*))); connect(ui->customPlot, SIGNAL(mouseMove(QMouseEvent*)), this, SLOT(graphMoveEvent(QMouseEvent*))); ui->customPlot->replot(); }
void CompassPort::on()// метод для чтения из порта и его открытия, если не открыт { emit timerStop(); if(!portSensor->isOpen()) { if (portSensor->open(QIODevice::ReadWrite))// открываем порт если он еще не открыт { QSerialPortInfo *info = new QSerialPortInfo(*portSensor);//информация о порте для отладки m_state=1;// порт открыт delete info; } else { if(portSensor->isOpen())// если что-то пошло не так, закрываем порт portSensor->close(); } } if(portSensor->isOpen() && portSensor->waitForReadyRead(100))// работа с открытым портом { QString data; QByteArray ByteArray,ByteArrayStart,ByteArrayFinish; bool startFinded = false; m_state = 1; while(m_state)// пока порт открыт { //if(portSensor->waitForReadyRead(1)) { qint64 byteAvail = portSensor->bytesAvailable();// просматриваем кол-во доступных байн для чтения qApp->processEvents(); QThread::msleep(10);//усыпляем поток, чтобы не занимал времени( данные раз в 10 секунд) if(byteAvail >=23)// проверка кол-ва байт, для их обработки { ByteArray = portSensor->readAll();// чтение из буфера порта data = data.fromLocal8Bit(ByteArray).trimmed(); if(ByteArray[3]=='p')//то ли сообщение пришло(смотри даташит хоневеловского датчика) { QBitArray bitdata(184),two_bytes(16); for(int i = 0,j; i < 184; ++i)//формирование массива бит для парсинга сообщения { j=i/8; if(j<=18) bitdata[i] = ByteArray[j] & (1 << i%8); else break; } // //m_roll = Round(toDec(two_bytes,1)*1.41,1); m_roll = QString::number((short)((ByteArray.at(6)<<8) + (ByteArray.at(5)))*360.0/65536.0,10,1).toDouble(); emit rollChanged(m_roll); // for(int i=56,j=15;i<72&&j>=0;i++,j--){two_bytes[j]=bitdata[i];} //Pitch // m_pitch = Round(toDec(two_bytes,1)*1.41,1); m_pitch = QString::number((short)((ByteArray.at(8)<<8) + (ByteArray.at(7)))*360.0/65536.0,10,1).toDouble(); emit pitchChanged(m_pitch); for(int i=72,j=15;i<88&&j>=0;i++,j--){two_bytes[j]=bitdata[i];} //Azimuth // m_angle = Round(toDec(two_bytes,0)*1.41,1); for(int i=72,j=15;i<88&&j>=0;i++,j--){two_bytes[j]=bitdata[i];} //Azimuth m_angle = Round(toDec(two_bytes,0)*1.41,1); static int i=0; if(i<=1) { i++; } else { emit angleChanged(m_angle); i=0; } m_B= QString::number((short)((ByteArray.at(18)<<8) + (ByteArray.at(17)))*750.0/65536.0,10,1).toDouble(); emit BChanged(m_B); // for(int i=152,j=15;i<168&&j>=0;i++,j--){two_bytes[j]=bitdata[i];} //coef C // m_C = Round(toDec(two_bytes,1)*3,1); m_C= QString::number((short)((ByteArray.at(20)<<8) + (ByteArray.at(19)))*750.0/65536.0,10,1).toDouble(); emit CChanged(m_C); // for(int i=168,j=15;i<184&&j>=0;i++,j--){two_bytes[j]=bitdata[i];} //coef Z // m_Z = Round(toDec(two_bytes,1)*1.41,1); m_Z= QString::number((short)((ByteArray.at(22)<<8) + (ByteArray.at(21)))*750.0/65536.0,10,1).toDouble(); emit ZChanged(m_Z); m_state=0; qApp->processEvents(); } } // внимательно посмотреть этот код, кажется косяк с выбросами полей и курса в нем(!) else if(byteAvail >=4 && byteAvail <=23)// если сообщение не полное( разбито на два) { ByteArray= portSensor->readAll(); data = data.fromLocal8Bit(ByteArray).trimmed(); if(ByteArray[3]=='p' && startFinded == false) { ByteArrayStart = ByteArray; startFinded = true; } else if(startFinded == true) { ByteArrayFinish += ByteArray; ByteArray = ByteArrayStart + ByteArrayFinish; if(ByteArray.size() >= 23) { QBitArray bitdata(184),two_bytes(16); for(int i = 0,j; i < 184; ++i) { j=i/8; if(j<=23) bitdata[i] = ByteArray[j] & (1 << i%8); else break; } // //m_roll = Round(toDec(two_bytes,1)*1.41,1); m_roll = QString::number((short)((ByteArray.at(6)<<8) + (ByteArray.at(5)))*360.0/65536.0,10,1).toDouble(); emit rollChanged(m_roll); // for(int i=56,j=15;i<72&&j>=0;i++,j--){two_bytes[j]=bitdata[i];} //Pitch // m_pitch = Round(toDec(two_bytes,1)*1.41,1); m_pitch = QString::number((short)((ByteArray.at(8)<<8) + (ByteArray.at(7)))*360.0/65536.0,10,1).toDouble(); emit pitchChanged(m_pitch); for(int i=72,j=15;i<88&&j>=0;i++,j--){two_bytes[j]=bitdata[i];} //Azimuth // m_angle = Round(toDec(two_bytes,0)*1.41,1); for(int i=72,j=15;i<88&&j>=0;i++,j--){two_bytes[j]=bitdata[i];} //Azimuth m_angle = Round(toDec(two_bytes,0)*1.41,1); static int i=0; if(i<=1) { i++; } else { emit angleChanged(m_angle); i=0; } m_B= QString::number((short)((ByteArray.at(18)<<8) + (ByteArray.at(17)))*750.0/65536.0,10,1).toDouble(); emit BChanged(m_B); // for(int i=152,j=15;i<168&&j>=0;i++,j--){two_bytes[j]=bitdata[i];} //coef C // m_C = Round(toDec(two_bytes,1)*3,1); m_C= QString::number((short)((ByteArray.at(20)<<8) + (ByteArray.at(19)))*750.0/65536.0,10,1).toDouble(); emit CChanged(m_C); // for(int i=168,j=15;i<184&&j>=0;i++,j--){two_bytes[j]=bitdata[i];} //coef Z // m_Z = Round(toDec(two_bytes,1)*1.41,1); m_Z= QString::number((short)((ByteArray.at(22)<<8) + (ByteArray.at(21)))*750.0/65536.0,10,1).toDouble(); emit ZChanged(m_Z); m_state=0; startFinded = false; } } } } } } else { } emit timerStart(10); }