Changeset - a9d626540c2c
[Not reviewed]
settings
0 6 0
Hasan Yavuz Ă–ZDERYA - 9 years ago 2016-09-06 02:42:09
hy@ozderya.net
implemented settings for framed reader
6 files changed with 105 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/dataformatpanel.cpp
Show inline comments
 
@@ -164,24 +164,25 @@ void DataFormatPanel::saveSettings(QSett
 
    }
 
    else // framed reader
 
    {
 
        format = "custom";
 
    }
 
    settings->setValue(SG_DataFormat_Format, format);
 

	
 
    settings->endGroup();
 

	
 
    // save reader settings
 
    bsReader.saveSettings(settings);
 
    asciiReader.saveSettings(settings);
 
    framedReader.saveSettings(settings);
 
}
 

	
 
void DataFormatPanel::loadSettings(QSettings* settings)
 
{
 
    settings->beginGroup(SettingGroup_DataFormat);
 

	
 
    // load selected format
 
    QString format = settings->value(
 
        SG_DataFormat_Format, QString()).toString();
 

	
 
    if (format == "binary")
 
    {
 
@@ -195,13 +196,14 @@ void DataFormatPanel::loadSettings(QSett
 
    }
 
    else if (format == "custom")
 
    {
 
        selectReader(&framedReader);
 
        ui->rbFramed->setChecked(true);
 
    } // else current selection stays
 

	
 
    settings->endGroup();
 

	
 
    // load reader settings
 
    bsReader.loadSettings(settings);
 
    asciiReader.loadSettings(settings);
 
    framedReader.loadSettings(settings);
 
}
src/framedreader.cpp
Show inline comments
 
@@ -344,12 +344,22 @@ template<typename T> double FramedReader
 

	
 
    if (_settingsWidget.endianness() == LittleEndian)
 
    {
 
        data = qFromLittleEndian(data);
 
    }
 
    else
 
    {
 
        data = qFromBigEndian(data);
 
    }
 

	
 
    return double(data);
 
}
 

	
 
void FramedReader::saveSettings(QSettings* settings)
 
{
 
    _settingsWidget.saveSettings(settings);
 
}
 

	
 
void FramedReader::loadSettings(QSettings* settings)
 
{
 
    _settingsWidget.loadSettings(settings);
 
}
src/framedreader.h
Show inline comments
 
@@ -11,39 +11,45 @@
 
  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/>.
 
*/
 

	
 
#ifndef FRAMEDREADER_H
 
#define FRAMEDREADER_H
 

	
 
#include <QSettings>
 

	
 
#include "abstractreader.h"
 
#include "framedreadersettings.h"
 

	
 
/**
 
 * Reads data in a customizable framed format.
 
 */
 
class FramedReader : public AbstractReader
 
{
 
    Q_OBJECT
 

	
 
public:
 
    explicit FramedReader(QIODevice* device, ChannelManager* channelMan, QObject *parent = 0);
 
    QWidget* settingsWidget();
 
    unsigned numOfChannels();
 
    void enable(bool enabled = true);
 
    /// Stores settings into a `QSettings`
 
    void saveSettings(QSettings* settings);
 
    /// Loads settings from a `QSettings`.
 
    void loadSettings(QSettings* settings);
 

	
 
public slots:
 
    void pause(bool);
 

	
 
private:
 
    /// bit wise fields for `settingsValid` member
 
    enum SettingInvalidFlag
 
    {
 
        SYNCWORD_INVALID = 1,
 
        FRAMESIZE_INVALID = 2
 
    };
 

	
src/framedreadersettings.cpp
Show inline comments
 
@@ -11,24 +11,25 @@
 
  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 <QButtonGroup>
 

	
 
#include "utils.h"
 
#include "setting_defines.h"
 
#include "framedreadersettings.h"
 
#include "ui_framedreadersettings.h"
 

	
 
FramedReaderSettings::FramedReaderSettings(QWidget *parent) :
 
    QWidget(parent),
 
    ui(new Ui::FramedReaderSettings)
 
{
 
    ui->setupUi(this);
 

	
 
    ui->leSyncWord->setMode(false); // hex mode
 
    ui->leSyncWord->setText("AA BB");
 

	
 
@@ -141,12 +142,82 @@ unsigned FramedReaderSettings::frameSize
 
    }
 
}
 

	
 
bool FramedReaderSettings::isChecksumEnabled()
 
{
 
    return ui->cbChecksum->isChecked();
 
}
 

	
 
bool FramedReaderSettings::isDebugModeEnabled()
 
{
 
    return ui->cbDebugMode->isChecked();
 
}
 

	
 
void FramedReaderSettings::saveSettings(QSettings* settings)
 
{
 
    settings->beginGroup(SettingGroup_CustomFrame);
 
    settings->setValue(SG_CustomFrame_NumOfChannels, numOfChannels());
 
    settings->setValue(SG_CustomFrame_NumberFormat, numberFormatToStr(numberFormat()));
 
    settings->setValue(SG_CustomFrame_Endianness,
 
                       endianness() == LittleEndian ? "little" : "big");
 
    settings->setValue(SG_CustomFrame_FrameStart, ui->leSyncWord->text());
 
    settings->setValue(SG_CustomFrame_FixedSize, ui->rbFixedSize->isChecked());
 
    settings->setValue(SG_CustomFrame_FrameSize, ui->spSize->value());
 
    settings->setValue(SG_CustomFrame_Checksum, ui->cbChecksum->isChecked());
 
    settings->setValue(SG_CustomFrame_DebugMode, ui->cbDebugMode->isChecked());
 
    settings->endGroup();
 
}
 

	
 
void FramedReaderSettings::loadSettings(QSettings* settings)
 
{
 
    settings->beginGroup(SettingGroup_CustomFrame);
 

	
 
    // load number of channels
 
    ui->spNumOfChannels->setValue(
 
        settings->value(SG_CustomFrame_NumOfChannels, numOfChannels()).toInt());
 

	
 
    // load number format
 
    NumberFormat nfSetting =
 
        strToNumberFormat(settings->value(SG_CustomFrame_NumberFormat,
 
                                          QString()).toString());
 
    if (nfSetting == NumberFormat_INVALID) nfSetting = numberFormat();
 
    ui->nfBox->setSelection(nfSetting);
 

	
 
    // load endianness
 
    QString endiannessSetting =
 
        settings->value(SG_CustomFrame_Endianness, QString()).toString();
 
    if (endiannessSetting == "little")
 
    {
 
        ui->endiBox->setSelection(LittleEndian);
 
    }
 
    else if (endiannessSetting == "big")
 
    {
 
        ui->endiBox->setSelection(BigEndian);
 
    } // else don't change
 

	
 
    // load frame start
 
    QString frameStartSetting =
 
        settings->value(SG_CustomFrame_FrameStart, ui->leSyncWord->text()).toString();
 
    auto validator = ui->leSyncWord->validator();
 
    validator->fixup(frameStartSetting);
 
    int pos = 0;
 
    if (validator->validate(frameStartSetting, pos) != QValidator::Invalid)
 
    {
 
        ui->leSyncWord->setText(frameStartSetting);
 
    }
 

	
 
    // load frame size
 
    ui->spSize->setValue(
 
        settings->value(SG_CustomFrame_FrameSize, ui->spSize->value()).toInt());
 
    ui->rbFixedSize->setChecked(
 
        settings->value(SG_CustomFrame_FixedSize, ui->rbFixedSize->isChecked()).toBool());
 

	
 
    // load checksum
 
    ui->cbChecksum->setChecked(
 
        settings->value(SG_CustomFrame_Checksum, ui->cbChecksum->isChecked()).toBool());
 

	
 
    // load debug mode
 
    ui->cbDebugMode->setChecked(
 
        settings->value(SG_CustomFrame_DebugMode, ui->cbDebugMode->isChecked()).toBool());
 

	
 
    settings->endGroup();
 
}
src/framedreadersettings.h
Show inline comments
 
@@ -13,24 +13,25 @@
 
  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/>.
 
*/
 

	
 
#ifndef FRAMEDREADERSETTINGS_H
 
#define FRAMEDREADERSETTINGS_H
 

	
 
#include <QWidget>
 
#include <QByteArray>
 
#include <QSettings>
 

	
 
#include "numberformatbox.h"
 
#include "endiannessbox.h"
 

	
 
namespace Ui {
 
class FramedReaderSettings;
 
}
 

	
 
class FramedReaderSettings : public QWidget
 
{
 
    Q_OBJECT
 

	
 
@@ -38,24 +39,28 @@ public:
 
    explicit FramedReaderSettings(QWidget *parent = 0);
 
    ~FramedReaderSettings();
 

	
 
    void showMessage(QString message, bool error = false);
 

	
 
    unsigned numOfChannels();
 
    NumberFormat numberFormat();
 
    Endianness endianness();
 
    QByteArray syncWord();
 
    unsigned frameSize(); /// If frame bye is enabled `0` is returned
 
    bool isChecksumEnabled();
 
    bool isDebugModeEnabled();
 
    /// Save settings into a `QSettings`
 
    void saveSettings(QSettings* settings);
 
    /// Loads settings from a `QSettings`.
 
    void loadSettings(QSettings* settings);
 

	
 
signals:
 
    /// If sync word is invalid (empty or 1 nibble missing at the end)
 
    /// signaled with an empty array
 
    void syncWordChanged(QByteArray);
 
    /// `0` indicates frame size byte is enabled
 
    void frameSizeChanged(unsigned);
 
    void checksumChanged(bool);
 
    void numOfChannelsChanged(unsigned);
 
    void numberFormatChanged(NumberFormat);
 
    void debugModeChanged(bool);
 

	
src/setting_defines.h
Show inline comments
 
@@ -16,24 +16,25 @@
 
  You should have received a copy of the GNU General Public License
 
  along with serialplot.  If not, see <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#ifndef SETTING_DEFINES_H
 
#define SETTING_DEFINES_H
 

	
 
const char SettingGroup_MainWindow[] = "MainWindow";
 
const char SettingGroup_Port[] = "Port";
 
const char SettingGroup_DataFormat[] = "DataFormat";
 
const char SettingGroup_Binary[] = "DataFormat_Binary";
 
const char SettingGroup_ASCII[] = "DataFormat_ASCII";
 
const char SettingGroup_CustomFrame[] = "DataFormat_CustomFrame";
 
const char SettingGroup_Channels[] = "Channels";
 
const char SettingGroup_Plot[] = "Plot";
 
const char SettingGroup_Commands[] = "Commands";
 

	
 
// mainwindow setting keys
 
const char SG_MainWindow_Size[] = "size";
 
const char SG_MainWindow_Pos[] = "pos";
 
const char SG_MainWindow_ActivePanel[] = "activePanel";
 
const char SG_MainWindow_HidePanels[] = "hidePanels";
 

	
 
// port setting keys
 
const char SG_Port_SelectedPort[] = "selectedPort";
 
@@ -45,13 +46,23 @@ const char SG_Port_FlowControl[] = "flow
 

	
 
// data format panel keys
 
const char SG_DataFormat_Format[] = "format";
 

	
 
// binary stream reader keys
 
const char SG_Binary_NumOfChannels[] = "numOfChannels";
 
const char SG_Binary_NumberFormat[] = "numberFormat";
 
const char SG_Binary_Endianness[] = "endianness";
 

	
 
// ascii reader keys
 
const char SG_ASCII_NumOfChannels[] = "numOfChannels";
 

	
 
// framed reader keys
 
const char SG_CustomFrame_NumOfChannels[] = "numOfChannels";
 
const char SG_CustomFrame_FrameStart[] = "frameStart";
 
const char SG_CustomFrame_FixedSize[] = "fixedSize";
 
const char SG_CustomFrame_FrameSize[] = "frameSize";
 
const char SG_CustomFrame_NumberFormat[] = "numberFormat";
 
const char SG_CustomFrame_Endianness[] = "endianness";
 
const char SG_CustomFrame_Checksum[] = "checksum";
 
const char SG_CustomFrame_DebugMode[] = "debugMode";
 

	
 
#endif // SETTING_DEFINES_H
0 comments (0 inline, 0 general)