///////////////////////////////////////////////////////////////////////////////////
/// 指定窓の画面をキャプチャして指定ファイルにPNG形式で保存する
void CaptureScreen(CWnd *pWnd, const std::wstring &szFilePath) {

    CRect rectClient;
    pWnd->GetClientRect( &rectClient );

    CClientDC dc(pWnd);

    CDC dc2;
    dc2.CreateCompatibleDC( &dc );

    CBitmap bitmap;
    bitmap.CreateCompatibleBitmap(&dc, rectClient.Width(), rectClient.Height() );

    auto pOldBitmap = dc2.SelectObject( &bitmap );

    dc2.BitBlt(0,0, rectClient.Width(), rectClient.Height(), &dc, 0, 0, SRCCOPY );

    int nWidthAdjust = rectClient.Width();
    if ( nWidthAdjust % 4 ) { nWidthAdjust += 4 - nWidthAdjust % 4;}

    std::vector<BYTE> bitdata( nWidthAdjust * rectClient.Height() * 3 );

    dc2.SelectObject( pOldBitmap );

    BITMAPINFO bitmapinfo;
    ZeroMemory(&bitmapinfo, sizeof(BITMAPINFO) );
    bitmapinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bitmapinfo.bmiHeader.biWidth = nWidthAdjust;
    bitmapinfo.bmiHeader.biHeight = rectClient.Height();
    bitmapinfo.bmiHeader.biPlanes = 1;
    bitmapinfo.bmiHeader.biBitCount = 24;
    bitmapinfo.bmiHeader.biCompression = BI_RGB;
    GetDIBits( dc2, bitmap, 0, rectClient.Height(), bitdata.data(), &bitmapinfo, DIB_RGB_COLORS );


    boost::gil::rgb8_image_t img( nWidthAdjust, rectClient.Height() );
    copy_pixels(boost::gil::interleaved_view(nWidthAdjust, rectClient.Height(), (const boost::gil::rgb8_pixel_t*)bitdata.data(), nWidthAdjust*3), view(img));
    png_write_view(CStringA(szFilePath.c_str()), boost::gil::flipped_up_down_view( const_view(img) ) );
}
Exemple #2
0
void CompassPort::revert()// метод для сброса датчика
{
    emit timerStop();// останавливаем прием курса
    // формируем сообщения для сброса
    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,0x04);
    dataForWrite.insert(6,0x0c);
    bool receivedMsg = false;
    //----------------------

    if(portSensor->isOpen())
    {

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

            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=40,j=7;i<48 && j>=0;i++,j--){one_byte[j]=bitdata[i];}
                        if(toDecInt(one_byte)==0)
                        {
                            //settings->setLabel("Compass Compensation Off");
                            //emit revertStatusChanged("Датчик сброшен");
                        }
                        else if(toDecInt(one_byte)==1)
                        {
                            //settings->setLabel("Compass Compensation Data Collection");
                            //emit revertStatusChanged("Сбор данных...");
                        }
                        else if(toDecInt(one_byte)==2)
                        {
                            //settings->setLabel("Compass Compensation Computation in Progress");
                            //emit revertStatusChanged("Вычисление...");
                        }
                        else if(toDecInt(one_byte)==3)
                        {
                            //settings->setLabel("Compass Compensation Procedure Abort");
                           // emit revertStatusChanged("Процедура прервана");
                        }
                        for(int i=48,j=7;i<56 && j>=0;i++,j--){one_byte[j]=bitdata[i];}

                        qApp->processEvents();
                        receivedMsg = true;// сообщение о сбросе получено
                    }
                }
                //запрашиваем состояние сброса
                dataForWrite.insert(5,0x02);
                dataForWrite.insert(6,0x0a);
                portSensor->write(dataForWrite,7);
                if(!portSensor->waitForBytesWritten(1000))
                {
                }
                //----------------------
            }
        }
    }
    emit timerStart(10);// продолжаем получение курса
}
Exemple #3
0
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;
}
Exemple #4
0
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);
}
Exemple #5
0
void Kompas::revert()
{
    timer->stop();
    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,0x04);
    dataForWrite.insert(6,0x0c);
    qDebug()<<"Here 1";
    bool receivedMsg = false;

    if(port->isOpen())
    {
        port->write(dataForWrite,7);
        if(!port->waitForBytesWritten(1000))
        {
            qDebug()<<"Error while writing data";
        }
        while(!receivedMsg)
        {

            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=40,j=7;i<48,j>=0;i++,j--){one_byte[j]=bitdata[i];} qDebug()<<"Status"<<toDecInt(one_byte)<<" "<<one_byte;
                        if(toDecInt(one_byte)==0)
                        {
                            settings->setLabel("Compass Compensation Off");
                        }
                        else if(toDecInt(one_byte)==1)
                        {
                            settings->setLabel("Compass Compensation Data Collection");
                        }
                        else if(toDecInt(one_byte)==2)
                        {
                            settings->setLabel("Compass Compensation Computation in Progress");
                        }
                        else if(toDecInt(one_byte)==3)
                        {
                            settings->setLabel("Compass Compensation Procedure Abort");
                        }
                        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)
//                        {
//                            settings->setLabel("Success");
//                        }
//                        else if(toDecInt(one_byte)==0)
//                        {
//                            settings->setLabel("No error");
//                        }
//                        else if(toDecInt(one_byte)==2)
//                        {
//                            settings->setLabel("Compensation Already Started");
//                        }
//                        else if(toDecInt(one_byte)==3)
//                        {
//                            settings->setLabel("Compensation Not Started");
//                        }
//                        else if(toDecInt(one_byte)==4)
//                        {
//                            settings->setLabel("Compensation Timeout");
//                        }
//                        else if(toDecInt(one_byte)==5)
//                        {
//                            settings->setLabel("Compensation Computation Failure");
//                        }
//                        else if(toDecInt(one_byte)==6)
//                        {
//                            settings->setLabel("New Computed Parameters No Better");
//                        }
//                        else if(toDecInt(one_byte)==7)
//                        {
//                            settings->setLabel("Flash Write Fail");
//                        }
                        //m_state=0;

                        qApp->processEvents();
                        receivedMsg = true;
                    }
                }
                dataForWrite.insert(5,0x02);
                dataForWrite.insert(6,0x0a);
                port->write(dataForWrite,7);
                if(!port->waitForBytesWritten(1000))
                {
                    qDebug()<<"Error while writing data";
                }
            }
        }
    }
    timer->start(10);
}
Exemple #6
0
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);
}
Exemple #7
0
void Kompas::on()
{

    timer->stop();
    QSerialPortInfo *info = new QSerialPortInfo(*port);
    if(!(port->isOpen() && info->portName() == settings->m_name_COM))
    {
        if(port->isOpen())
            port->close();

        qDebug()<<settings->m_name_COM;
        port->setPortName(settings->m_name_COM);
        if (port->open(QIODevice::ReadWrite))
        {
            QFile file("dataRead.dat");
            if (file.open(QIODevice::ReadOnly | QIODevice::Text))
            {
               QTextStream stream(&file);
               m_skl = stream.readLine().toInt();
               m_coef_A = stream.readLine().toInt();
               file.close();
            }

            updateSettings();
            QSerialPortInfo *info = new QSerialPortInfo(*port);
            qDebug() << "Name        : " << info->portName();
            qDebug() << "Description : " << info->description();
            qDebug() << "Manufacturer: " << info->manufacturer();
            qDebug() << "BaudRate: " << port->baudRate();
            qDebug() << "Parity: " << port->parity();
            qDebug() << "Data bits: " << port->dataBits();
            qDebug() << "Stop Bits: " << port->stopBits();
            delete info;
            m_state=1;
            emit stateChanged();
            m_connect_state=1;
            emit connect_stateChanged();
            qDebug()<<"state = 1 ON";
            qDebug()<<settings->m_name_COM<<"opened";
        }
        else
        {
            if(port->isOpen())
                port->close();
            qDebug()<<"Error while opening";
        }
    }
    if(port->isOpen() && port->waitForReadyRead(1000))
    {
        QString data;
        QByteArray ByteArray;
        m_state = 1;
        while(m_state)
        {
            qint64 byteAvail = port->bytesAvailable();
            qApp->processEvents();
            if(byteAvail >=13)
            {
                ByteArray = port->readAll();
                data = data.fromLocal8Bit(ByteArray).trimmed();
                if(ByteArray[3]=='p')
                {
                    QBitArray bitdata(104),two_bytes(16);
                    for(int i = 0,j; i < 104; ++i)
                    {
                        j=i/8;
                        if(j<=13)
                            bitdata[i] = ByteArray[j] & (1 << i%8);
                        else
                            break;
                    }

                    for(int i=40,j=15;i<56&&j>=0;i++,j--){two_bytes[j]=bitdata[i];} //Roll
                    setRoll(Round(toDec(two_bytes,1)*1.41,1));
                    for(int i=56,j=15;i<72&&j>=0;i++,j--){two_bytes[j]=bitdata[i];} //Pitch
                    setPitch(Round(toDec(two_bytes,1)*1.41,1));
                    for(int i=72,j=15;i<88&&j>=0;i++,j--){two_bytes[j]=bitdata[i];} //Azimuth

                    setAngle(Round(toDec(two_bytes,0)*1.41,1));
                    m_state=0;
                    qApp->processEvents();
                }
            }
        }
    }
    else
    {
        qDebug()<<"WaitForReadyRead failed";
        qDebug()<<port->error();
    }
    kompasThread1->quit();
    timer->start(10);
}