コード例 #1
0
ファイル: kompas.cpp プロジェクト: Navi-Dals/Compass
Kompas::Kompas(QWidget *parent) :
    QWidget(parent)
{
    m_comp_state=1;
    m_dempf=2;
    m_tmCourse = true;
    m_coef_A=0;
    m_last=0;
    m_last2=0;
    m_angle=0;
    m_fractPart=0;
    m_fullangle=0;
    m_state=0;
    m_supply=0;
    m_connect_state=0;
    m_connect=0;
    m_color=0;
    m_skl=0;
    m_savedCourse=0;
    m_roll=0;
    m_pitch=0;
    m_afterComma=0;
    m_lastAngle=0;
    m_lastAngle1=0;
    m_sum=0;
    m_con=0;
    m_con1=0;
    m_summ_ang=0;
    m_infoVisibility=false;
    m_savedCourseVisibility=false;
    kompasThread = new QThread(this);
    kompasThread1 = new QThread(this);
    settings = new kompasSettings(parent);
    port = new QSerialPort;
    timer = new QTimer(this);

    dial = new DialogComp(this);

    connect(timer, SIGNAL(timeout()),kompasThread1, SLOT(start()));

    connect(kompasThread1,SIGNAL(started()),this,SLOT(on()));

    connect(kompasThread,SIGNAL(started()),this,SLOT(initComp()));
    connect(this,SIGNAL(compStarted()),dial,SLOT(show()));

    connect(settings,SIGNAL(revertRequest()),this,SLOT(revert()));
    //connect(kompas->kompasThread,SIGNAL(finished()),kompas,SLOT(off()));
    timer->start(10);


}
コード例 #2
0
ファイル: compassport.cpp プロジェクト: NustyNUts/MKF1
void CompassPort::initComp()//инициализация компенсации
{
    emit timerStop();// останавливаем прием курса
    emit compStarted();// сообщаем о начале компенсации
    m_compInProgress = true;
    // формируем сообщение для датчика о начале компенсации
    QByteArray dataForWrite;
    dataForWrite.insert(0,0x0d);
    dataForWrite.insert(1,0x0a);
    dataForWrite.insert(2,0x7e);
    dataForWrite.insert(3,0x72);
    dataForWrite.insert(4,0x01);
    dataForWrite.insert(5,0x01);
    dataForWrite.insert(6,0x09);
    //--------------------
    if(portSensor->isOpen())// проверка открыт ли порт
    {

        portSensor->write(dataForWrite,7);// передача сообщения датчику для начала компенсации
        if(!portSensor->waitForBytesWritten(1000))
        {
        }
        while(m_compInProgress)// пока калибровка не закончится
        {

            qApp->processEvents();// магическая строчка чтобы не тупили пользовательские интерфейсы
            if(portSensor->isOpen() && portSensor->waitForReadyRead(1000))// ждем данных
            {
                QString data;
                QByteArray ByteArray;
                qint64 byteAvail = portSensor->bytesAvailable();
                qApp->processEvents();
                if(byteAvail >=19)// буфер наполнился
                {
                    ByteArray = portSensor->readAll();// читаем из порта
                    data = data.fromLocal8Bit(ByteArray).trimmed();
                    if(ByteArray[3]=='r'&& ByteArray[0]=='\r' && ByteArray[1]=='\n' && ByteArray[2]=='~')// если сообщение нужное нам( смотри даташит)
                    {
                        //формирование массива бит для парсинга
                        QBitArray bitdata(152),one_byte(8);
                        for(int i = 0,j; i < 152; ++i)
                        {
                            j=i/8;
                            if(j<=19)
                                bitdata[i] = ByteArray[j] & (1 << i%8);
                            else
                                break;
                        }
                        // парс сообщения о состоянии бинов
                        for(int i=56,j=7;i<64 && j>=0;i++,j--){one_byte[j]=bitdata[i];}
                        //dial->setBar(7,toDecInt(one_byte));
                        emit dialCompProgressChanged(7,toDecInt(one_byte));
                        for(int i=64,j=7;i<72 && j>=0;i++,j--){one_byte[j]=bitdata[i];}
                        //dial->setBar(6,toDecInt(one_byte));
                        emit dialCompProgressChanged(6,toDecInt(one_byte));
                        for(int i=72,j=7;i<80 && j>=0;i++,j--){one_byte[j]=bitdata[i];}
                        //dial->setBar(5,toDecInt(one_byte));
                        emit dialCompProgressChanged(5,toDecInt(one_byte));
                        for(int i=80,j=7;i<88 && j>=0;i++,j--){one_byte[j]=bitdata[i];}
                        //dial->setBar(4,toDecInt(one_byte));
                        emit dialCompProgressChanged(4,toDecInt(one_byte));
                        for(int i=88,j=7;i<96 && j>=0;i++,j--){one_byte[j]=bitdata[i];}
                        //dial->setBar(3,toDecInt(one_byte));
                        emit dialCompProgressChanged(3,toDecInt(one_byte));
                        for(int i=96,j=7;i<104 && j>=0;i++,j--){one_byte[j]=bitdata[i];}
                        //dial->setBar(2,toDecInt(one_byte));
                        emit dialCompProgressChanged(2,toDecInt(one_byte));
                        for(int i=104,j=7;i<112 && j>=0;i++,j--){one_byte[j]=bitdata[i];}
                        //dial->setBar(1,toDecInt(one_byte));
                        emit dialCompProgressChanged(1,toDecInt(one_byte));
                        for(int i=112,j=7;i<120 && j>=0;i++,j--){one_byte[j]=bitdata[i];}
                        //dial->setBar(0,toDecInt(one_byte));
                        emit dialCompProgressChanged(0,toDecInt(one_byte));
                        //---------------------------------------------------------
                        // состоние компенсации
                        for(int i=48,j=7;i<56 && j>=0;i++,j--){one_byte[j]=bitdata[i];}
                        if(toDecInt(one_byte)==1)
                        {
                            //dial->setLabel("Success");
                            emit dialCompStatusChanged("НОРМА");
                        }
                        else if(toDecInt(one_byte)==0)
                        {
                            //dial->setLabel("No error");
                            emit dialCompStatusChanged("");
                        }
                        else if(toDecInt(one_byte)==2)
                        {
                            //dial->setLabel("Compensation Already Started");
                            emit dialCompStatusChanged("");
                        }
                        else if(toDecInt(one_byte)==3)
                        {
                            //dial->setLabel("Compensation Not Started");
                            emit dialCompStatusChanged("ОТКАЗ");
                        }
                        else if(toDecInt(one_byte)==4)
                        {
                            //dial->setLabel("Compensation Timeout");
                            emit dialCompStatusChanged("ВРЕМЯ");
                        }
                        else if(toDecInt(one_byte)==5)
                        {
                            //dial->setLabel("Compensation Computation Failure");
                            emit dialCompStatusChanged("ОШИБКА");
                        }
                        else if(toDecInt(one_byte)==6)
                        {
                            //dial->setLabel("New Computed Parameters No Better");
                            emit dialCompStatusChanged("НОРМА");
                        }
                        else if(toDecInt(one_byte)==7)
                        {
                            //dial->setLabel("Flash Write Fail");
                            emit dialCompStatusChanged("ОТКАЗ");
                        }
                        //----------------------------
                        qApp->processEvents();
                    }

                }
                // посылаем сообщение для получения данных о калибровке
                dataForWrite.insert(5,0x02);
                dataForWrite.insert(6,0x0a);
                portSensor->write(dataForWrite,7);
                if(!portSensor->waitForBytesWritten(1000))
                {
                }
                //-----------------------
            }
        }
    }
    emit compFinished();// калибровка закончена
    emit timerStart(10);// продолжаем прием сообщений о курсе
    m_compInProgress = false;
}
コード例 #3
0
ファイル: kompas.cpp プロジェクト: Navi-Dals/Compass
void Kompas::initComp()
{
    timer->stop();
    emit compStarted();
    QByteArray dataForWrite;
    dataForWrite.insert(0,0x0d);
    dataForWrite.insert(1,0x0a);
    dataForWrite.insert(2,0x7e);
    dataForWrite.insert(3,0x72);
    dataForWrite.insert(4,0x01);
    dataForWrite.insert(5,0x01);
    dataForWrite.insert(6,0x09);
    qDebug()<<dataForWrite;
    if(port->isOpen())
    {
        port->write(dataForWrite,7);
        if(!port->waitForBytesWritten(1000))
        {
            qDebug()<<"Error while writing data";
        }
        while(dial->isVisible())
        {

            if(port->isOpen() && port->waitForReadyRead(1000))
            {

                QString data;
                QByteArray ByteArray;
                qint64 byteAvail = port->bytesAvailable();
                qApp->processEvents();
                if(byteAvail >=19)
                {
                    ByteArray = port->readAll();
                    data = data.fromLocal8Bit(ByteArray).trimmed();
                    if(ByteArray[3]=='r'&& ByteArray[0]=='\r' && ByteArray[1]=='\n' && ByteArray[2]=='~')
                    {
                        QBitArray bitdata(152),one_byte(8);
                        for(int i = 0,j; i < 152; ++i)
                        {
                            j=i/8;
                            if(j<=19)
                                bitdata[i] = ByteArray[j] & (1 << i%8);
                            else
                                break;
                        }

                        for(int i=56,j=7;i<64,j>=0;i++,j--){one_byte[j]=bitdata[i];} qDebug()<<toDecInt(one_byte)<<" "<<one_byte;
                        dial->setBar(7,toDecInt(one_byte));
                        for(int i=64,j=7;i<72,j>=0;i++,j--){one_byte[j]=bitdata[i];} qDebug()<<toDecInt(one_byte)<<" "<<one_byte;
                        dial->setBar(6,toDecInt(one_byte));
                        for(int i=72,j=7;i<80,j>=0;i++,j--){one_byte[j]=bitdata[i];} qDebug()<<toDecInt(one_byte)<<" "<<one_byte;
                        dial->setBar(5,toDecInt(one_byte));
                        for(int i=80,j=7;i<88,j>=0;i++,j--){one_byte[j]=bitdata[i];} qDebug()<<toDecInt(one_byte)<<" "<<one_byte;
                        dial->setBar(4,toDecInt(one_byte));
                        for(int i=88,j=7;i<96,j>=0;i++,j--){one_byte[j]=bitdata[i];} qDebug()<<toDecInt(one_byte)<<" "<<one_byte;
                        dial->setBar(3,toDecInt(one_byte));
                        for(int i=96,j=7;i<104,j>=0;i++,j--){one_byte[j]=bitdata[i];} qDebug()<<toDecInt(one_byte)<<" "<<one_byte;
                        dial->setBar(2,toDecInt(one_byte));
                        for(int i=104,j=7;i<112,j>=0;i++,j--){one_byte[j]=bitdata[i];} qDebug()<<toDecInt(one_byte)<<" "<<one_byte;
                        dial->setBar(1,toDecInt(one_byte));
                        for(int i=112,j=7;i<120,j>=0;i++,j--){one_byte[j]=bitdata[i];} qDebug()<<toDecInt(one_byte)<<" "<<one_byte;
                        dial->setBar(0,toDecInt(one_byte));

                        //dial->setBar(3,5);

                        //for(int i=80,j=7;i<88,j>=0;i++,j--){one_byte[j]=bitdata[i];} /*qDebug()<<(progress = toDec(one_byte,0));*/qDebug()<<one_byte;

                        //for(int i=0,j=7;i<8,j>=0;i++,j--){one_byte[j]=bitdata[i];} /*qDebug()<<(progress = toDec(one_byte,0));*/qDebug()<<one_byte;
                        qDebug()<<bitdata;
                        for(int i=48,j=7;i<56,j>=0;i++,j--){one_byte[j]=bitdata[i];} qDebug()<<"Status"<<toDecInt(one_byte)<<" "<<one_byte;
                        if(toDecInt(one_byte)==1)
                        {
                            dial->setLabel("Success");
                        }
                        else if(toDecInt(one_byte)==0)
                        {
                            dial->setLabel("No error");
                        }
                        else if(toDecInt(one_byte)==2)
                        {
                            dial->setLabel("Compensation Already Started");
                        }
                        else if(toDecInt(one_byte)==3)
                        {
                            dial->setLabel("Compensation Not Started");
                        }
                        else if(toDecInt(one_byte)==4)
                        {
                            dial->setLabel("Compensation Timeout");
                        }
                        else if(toDecInt(one_byte)==5)
                        {
                            dial->setLabel("Compensation Computation Failure");
                        }
                        else if(toDecInt(one_byte)==6)
                        {
                            dial->setLabel("New Computed Parameters No Better");
                        }
                        else if(toDecInt(one_byte)==7)
                        {
                            dial->setLabel("Flash Write Fail");
                        }
                        //m_state=0;

                        qApp->processEvents();
                    }

                }
                dataForWrite.insert(5,0x02);
                dataForWrite.insert(6,0x0a);
                port->write(dataForWrite,7);
                if(!port->waitForBytesWritten(1000))
                {
                    qDebug()<<"Error while writing data";
                }
            }
        }
    }
    timer->start(10);
    //delete dial;
    for(int i=0;i<8;i++)
        dial->setBar(i,0);
}