diff --git a/floatswap.h b/floatswap.h new file mode 100644 --- /dev/null +++ b/floatswap.h @@ -0,0 +1,14 @@ +#include +#include + +template <> inline float qbswap(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; +} diff --git a/mainwindow.cpp b/mainwindow.cpp --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -32,6 +33,7 @@ #include "utils.h" #include "version.h" +#include "floatswap.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), @@ -519,6 +521,16 @@ template double MainWindow:: { T data; this->serialPort.read((char*) &data, sizeof(data)); + + if (ui->rbLittleE->isChecked()) + { + data = qFromLittleEndian(data); + } + else + { + data = qFromBigEndian(data); + } + return double(data); } diff --git a/mainwindow.ui b/mainwindow.ui --- a/mainwindow.ui +++ b/mainwindow.ui @@ -94,75 +94,147 @@ - - - Number Format: + + + 0 - - - - - uint8 - - - true - - - - - - - uint32 - - - - - - - uint16 - - - - - - - int16 - - - - - - - int32 - - - - - - - float - - - - - - - int8 - - - - - - - Comma Separated Values - - - ASCII(CSV) - - - - - + + + + Number Format: + + + + + + uint32 + + + + + + + int8 + + + + + + + uint8 + + + true + + + + + + + Comma Separated Values + + + ASCII(CSV) + + + + + + + int16 + + + + + + + int32 + + + + + + + float + + + + + + + uint16 + + + + + + + + + + Qt::Vertical + + + + 20 + 1 + + + + + + + + + + 0 + + + + + + 0 + 0 + + + + Byte Order: + + + + + + Little Endian + + + true + + + + + + + Big Endian + + + + + + + + + + Qt::Vertical + + + + 20 + 1 + + + + + diff --git a/serialplot.pro b/serialplot.pro --- a/serialplot.pro +++ b/serialplot.pro @@ -41,7 +41,8 @@ SOURCES += main.cpp\ HEADERS += mainwindow.h \ utils.h \ customcheckablebutton.h \ - portcontrol.h + portcontrol.h \ + floatswap.h FORMS += mainwindow.ui \ about_dialog.ui \