Changeset - 8cac6c6afb36
[Not reviewed]
default
0 3 1
Hasan Yavuz Ă–ZDERYA - 11 years ago 2015-06-04 09:40:35
hy@ozderya.net
added endianness selection
4 files changed with 122 insertions and 23 deletions:
0 comments (0 inline, 0 general)
floatswap.h
Show inline comments
 
new file 100644
 
#include <byteswap.h>
 
#include <QtGlobal>
 

	
 
template <> inline float qbswap<float>(float source)
 
{
 
    float result;
 
    char* s = (char*) &source;
 
    char* t = (char*) &result;
 
    t[0] = s[3];
 
    t[1] = s[2];
 
    t[2] = s[1];
 
    t[3] = s[0];
 
    return result;
 
}
mainwindow.cpp
Show inline comments
 
@@ -4,55 +4,57 @@
 
  This file is part of serialplot.
 

	
 
  serialplot is free software: you can redistribute it and/or modify
 
  it under the terms of the GNU General Public License as published by
 
  the Free Software Foundation, either version 3 of the License, or
 
  (at your option) any later version.
 

	
 
  serialplot is distributed in the hope that it will be useful,
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  GNU General Public License for more details.
 

	
 
  You should have received a copy of the GNU General Public License
 
  along with serialplot.  If not, see <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#include "mainwindow.h"
 
#include "ui_mainwindow.h"
 
#include <QByteArray>
 
#include <QApplication>
 
#include <QFileDialog>
 
#include <QFile>
 
#include <QTextStream>
 
#include <QtDebug>
 
#include <QtEndian>
 
#include <qwt_plot.h>
 
#include <limits.h>
 
#include <cmath>
 
#include <iostream>
 

	
 
#include "utils.h"
 
#include "version.h"
 
#include "floatswap.h"
 

	
 
MainWindow::MainWindow(QWidget *parent) :
 
    QMainWindow(parent),
 
    ui(new Ui::MainWindow),
 
    portControl(&serialPort)
 
{
 
    ui->setupUi(this);
 
    ui->tabWidget->insertTab(0, &portControl, "Port");
 
    ui->tabWidget->setCurrentIndex(0);
 

	
 
    setupAboutDialog();
 

	
 
    // init UI signals
 

	
 
    // menu signals
 
    QObject::connect(ui->actionHelpAbout, &QAction::triggered,
 
              &aboutDialog, &QWidget::show);
 

	
 
    QObject::connect(ui->actionExportCsv, &QAction::triggered,
 
                     this, &MainWindow::onExportCsv);
 

	
 
    QObject::connect(&portControl, &PortControl::portToggled,
 
                     this, &MainWindow::onPortToggled);
 

	
 
@@ -498,48 +500,58 @@ void MainWindow::selectNumberFormat(Numb
 
            readSample = NULL; // in this mode
 
            break;
 
    }
 

	
 
    if (numberFormat == NumberFormat_ASCII)
 
    {
 
        QObject::disconnect(&(this->serialPort), &QSerialPort::readyRead, 0, 0);
 
        QObject::connect(&(this->serialPort), &QSerialPort::readyRead,
 
                         this, &MainWindow::onDataReadyASCII);
 
        portControl.enableSkipByte();
 
    }
 
    else
 
    {
 
        QObject::disconnect(&(this->serialPort), &QSerialPort::readyRead, 0, 0);
 
        QObject::connect(&(this->serialPort), &QSerialPort::readyRead,
 
                         this, &MainWindow::onDataReady);
 
        portControl.enableSkipByte(false);
 
    }
 
}
 

	
 
template<typename T> double MainWindow::readSampleAs()
 
{
 
    T data;
 
    this->serialPort.read((char*) &data, sizeof(data));
 

	
 
    if (ui->rbLittleE->isChecked())
 
    {
 
        data = qFromLittleEndian(data);
 
    }
 
    else
 
    {
 
        data = qFromBigEndian(data);
 
    }
 

	
 
    return double(data);
 
}
 

	
 
bool MainWindow::isDemoRunning()
 
{
 
    return ui->actionDemoMode->isChecked();
 
}
 

	
 
void MainWindow::demoTimerTimeout()
 
{
 
    demoCount++;
 
    if (demoCount > 100) demoCount = 0;
 

	
 
    if (!ui->actionPause->isChecked())
 
    {
 
        for (unsigned int ci = 0; ci < numOfChannels; ci++)
 
        {
 
            DataArray data(1);
 
            data.replace(0, (ci + 1)*demoCount);
 
            addChannelData(ci, data);
 
        }
 
    }
 
}
 

	
mainwindow.ui
Show inline comments
 
@@ -73,119 +73,191 @@
 
              <height>0</height>
 
             </size>
 
            </property>
 
            <property name="keyboardTracking">
 
             <bool>false</bool>
 
            </property>
 
            <property name="minimum">
 
             <number>1</number>
 
            </property>
 
            <property name="maximum">
 
             <number>32</number>
 
            </property>
 
           </widget>
 
          </item>
 
         </layout>
 
        </item>
 
        <item>
 
         <widget class="Line" name="line_2">
 
          <property name="orientation">
 
           <enum>Qt::Vertical</enum>
 
          </property>
 
         </widget>
 
        </item>
 
        <item>
 
         <layout class="QVBoxLayout" name="verticalLayout_5">
 
          <property name="leftMargin">
 
           <number>0</number>
 
          </property>
 
          <item>
 
         <widget class="QGroupBox" name="groupBox">
 
          <property name="title">
 
           <string>Number Format:</string>
 
          </property>
 
          <layout class="QGridLayout" name="gridLayout_2">
 
             <item row="2" column="0">
 
              <widget class="QRadioButton" name="rbUint32">
 
               <property name="text">
 
                <string>uint32</string>
 
               </property>
 
              </widget>
 
             </item>
 
             <item row="0" column="1">
 
              <widget class="QRadioButton" name="rbInt8">
 
               <property name="text">
 
                <string>int8</string>
 
               </property>
 
              </widget>
 
             </item>
 
           <item row="0" column="0">
 
            <widget class="QRadioButton" name="rbUint8">
 
             <property name="text">
 
              <string>uint8</string>
 
             </property>
 
             <property name="checked">
 
              <bool>true</bool>
 
             </property>
 
            </widget>
 
           </item>
 
           <item row="2" column="0">
 
            <widget class="QRadioButton" name="rbUint32">
 
             <property name="text">
 
              <string>uint32</string>
 
             <item row="3" column="1">
 
              <widget class="QRadioButton" name="rbASCII">
 
               <property name="toolTip">
 
                <string>Comma Separated Values</string>
 
             </property>
 
            </widget>
 
           </item>
 
           <item row="1" column="0">
 
            <widget class="QRadioButton" name="rbUint16">
 
             <property name="text">
 
              <string>uint16</string>
 
                <string>ASCII(CSV)</string>
 
             </property>
 
            </widget>
 
           </item>
 
           <item row="1" column="1">
 
            <widget class="QRadioButton" name="rbInt16">
 
             <property name="text">
 
              <string>int16</string>
 
             </property>
 
            </widget>
 
           </item>
 
           <item row="2" column="1">
 
            <widget class="QRadioButton" name="rbInt32">
 
             <property name="text">
 
              <string>int32</string>
 
             </property>
 
            </widget>
 
           </item>
 
           <item row="3" column="0">
 
            <widget class="QRadioButton" name="rbFloat">
 
             <property name="text">
 
              <string>float</string>
 
             </property>
 
            </widget>
 
           </item>
 
           <item row="0" column="1">
 
            <widget class="QRadioButton" name="rbInt8">
 
             <item row="1" column="0">
 
              <widget class="QRadioButton" name="rbUint16">
 
             <property name="text">
 
              <string>int8</string>
 
             </property>
 
            </widget>
 
           </item>
 
           <item row="3" column="1">
 
            <widget class="QRadioButton" name="rbASCII">
 
             <property name="toolTip">
 
              <string>Comma Separated Values</string>
 
             </property>
 
             <property name="text">
 
              <string>ASCII(CSV)</string>
 
                <string>uint16</string>
 
             </property>
 
            </widget>
 
           </item>
 
          </layout>
 
         </widget>
 
        </item>
 
        <item>
 
           <spacer name="verticalSpacer_2">
 
            <property name="orientation">
 
             <enum>Qt::Vertical</enum>
 
            </property>
 
            <property name="sizeHint" stdset="0">
 
             <size>
 
              <width>20</width>
 
              <height>1</height>
 
             </size>
 
            </property>
 
           </spacer>
 
          </item>
 
         </layout>
 
        </item>
 
        <item>
 
         <layout class="QVBoxLayout" name="verticalLayout_4">
 
          <property name="leftMargin">
 
           <number>0</number>
 
          </property>
 
          <item>
 
           <widget class="QGroupBox" name="groupBox_2">
 
            <property name="sizePolicy">
 
             <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
 
              <horstretch>0</horstretch>
 
              <verstretch>0</verstretch>
 
             </sizepolicy>
 
            </property>
 
            <property name="title">
 
             <string>Byte Order:</string>
 
            </property>
 
            <layout class="QVBoxLayout" name="verticalLayout">
 
             <item>
 
              <widget class="QRadioButton" name="rbLittleE">
 
               <property name="text">
 
                <string>Little Endian</string>
 
               </property>
 
               <property name="checked">
 
                <bool>true</bool>
 
               </property>
 
              </widget>
 
             </item>
 
             <item>
 
              <widget class="QRadioButton" name="rbBigE">
 
               <property name="text">
 
                <string>Big Endian</string>
 
               </property>
 
              </widget>
 
             </item>
 
            </layout>
 
           </widget>
 
          </item>
 
          <item>
 
           <spacer name="verticalSpacer">
 
            <property name="orientation">
 
             <enum>Qt::Vertical</enum>
 
            </property>
 
            <property name="sizeHint" stdset="0">
 
             <size>
 
              <width>20</width>
 
              <height>1</height>
 
             </size>
 
            </property>
 
           </spacer>
 
          </item>
 
         </layout>
 
        </item>
 
        <item>
 
         <spacer name="horizontalSpacer_3">
 
          <property name="orientation">
 
           <enum>Qt::Horizontal</enum>
 
          </property>
 
          <property name="sizeType">
 
           <enum>QSizePolicy::MinimumExpanding</enum>
 
          </property>
 
          <property name="sizeHint" stdset="0">
 
           <size>
 
            <width>20</width>
 
            <height>20</height>
 
           </size>
 
          </property>
 
         </spacer>
 
        </item>
 
       </layout>
 
      </widget>
 
      <widget class="QWidget" name="tabPlot">
 
       <attribute name="title">
 
        <string>Plot</string>
 
       </attribute>
 
       <layout class="QHBoxLayout" name="horizontalLayout_4">
 
        <item>
 
         <spacer name="horizontalSpacer_2">
serialplot.pro
Show inline comments
 
@@ -20,33 +20,34 @@
 
#-------------------------------------------------
 
#
 
# Project created by QtCreator 2015-03-04T08:20:06
 
#
 
#-------------------------------------------------
 

	
 
QT       += core gui serialport
 

	
 
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
 

	
 
TARGET = serialplot
 
TEMPLATE = app
 

	
 
CONFIG += qwt
 

	
 

	
 
SOURCES += main.cpp\
 
        mainwindow.cpp \
 
    customcheckablebutton.cpp \
 
    portcontrol.cpp
 

	
 
HEADERS  += mainwindow.h \
 
    utils.h \
 
    customcheckablebutton.h \
 
    portcontrol.h
 
    portcontrol.h \
 
    floatswap.h
 

	
 
FORMS    += mainwindow.ui \
 
    about_dialog.ui \
 
    portcontrol.ui
 

	
 
INCLUDEPATH += qmake/
 

	
 
CONFIG += c++11
0 comments (0 inline, 0 general)