OSDN Git Service

Alpha 1 development in progress
authortkawata <tkawata@users.sourceforge.jp>
Fri, 27 Apr 2012 14:02:14 +0000 (23:02 +0900)
committertkawata <tkawata@users.sourceforge.jp>
Fri, 27 Apr 2012 14:02:14 +0000 (23:02 +0900)
- Added the serial port baud rate setting to property.xml
- Remember the previous serial port settings.

Samples/Samples/Sample3_Arduino1/property.xml
Source/DNEngine.cpp
Source/DNEngine.h
Source/DNSettings.cpp [new file with mode: 0644]
Source/DNSettings.h [new file with mode: 0644]
Source/DNSettingsImpl.h [new file with mode: 0644]
Source/QtDennco/mainwindow.cpp
Source/Source.pro
Source/platform/qt/qtdnserialportimpl.cpp
Source/platform/qt/qtdnsettingsimpl.cpp [new file with mode: 0644]

index e742219..365dfd4 100644 (file)
@@ -4,5 +4,6 @@
 <UIPath>/ui/index.html</UIPath>
 <EnableHTTPServer>no</EnableHTTPServer> <!-- not implemented yet -->
 <EnableSerialServer>yes</EnableSerialServer>
+<SerialSpeed>9600</SerialSpeed>
 
 </dennco>
\ No newline at end of file
index 09606cf..c698036 100644 (file)
 #include "DNGlobal.h"
 #include "DNUtils.h"
 #include "TKLog.h"
+#include "DNSettings.h"
 
 #include <stdlib.h>
 #include <sstream>
 #include <iostream>
 
 DNEngine::DNEngine(const char *contentPath) :
-    mContainer(NULL),mPortNumber(9080),mHTTPServer(NULL),mSerialServer(NULL),mValid(false), mDoTickThread(NULL)
+    mContainer(NULL),mPortNumber(9080),mHTTPServer(NULL),mSerialServer(NULL),mSerialServerEnabled(false),mValid(false), mDoTickThread(NULL)
 {
     mTimeKeeper = new DNTimeKeeper();
     mContainer = TKContainer::createContainer();
@@ -100,6 +101,15 @@ DNEngine::DNEngine(const char *contentPath) :
         return;
     }
 
+    if (mSerialServerEnabled)
+    {
+        mSerialServerEnabled = startSerialServer();
+    }
+    else
+    {
+        stopSerialServer();
+    }
+
     mValid = true;
 }
 
@@ -177,7 +187,9 @@ bool DNEngine::parseSettingFile(const char *contentRoot)
             DNXMLElement *e = element->inner;
             while(e)
             {
-                if (e->name == "TickIntervalSec")
+                std::string pname = upperString(e->name);
+
+                if (pname == "TICKINTERVALSEC")
                 {
                     std::istringstream is(e->text);
                     float t = 0.0;
@@ -202,25 +214,29 @@ bool DNEngine::parseSettingFile(const char *contentRoot)
                         }
                     }
                 }
-                else if (e->name == "UIPath")
+                else if (pname == "UIPATH")
                 {
                     mUIPath = e->text;
                 }
-                else if (e->name == "EnableHTTPServer")
+                else if (pname == "ENABLEHTTPSERVER")
                 {
 
                 }
-                else if (e->name == "EnableSerialServer")
+                else if (pname == "ENABLESERIALSERVER")
                 {
                     if ( upperString(e->text) == "YES")
                     {
-                        startSerialServer();
+                        mSerialServerEnabled = true;
                     }
                     else
                     {
-                        stopSerialServer();
+                        mSerialServerEnabled = false;
                     }
                 }
+                else if (pname == "SERIALSPEED")
+                {
+                    DNSettings::setValue(DNSettings::SERIAL_RATE, e->text);
+                }
                 e = e->next;
             }
         }
index e5ebcd9..93977d2 100644 (file)
@@ -67,6 +67,7 @@ private:
     int             mPortNumber;
     DNServerHTTP    *mHTTPServer;
     DNServerSerialPort  *mSerialServer;
+    bool            mSerialServerEnabled;
     DNTimeKeeper    *mTimeKeeper;
     bool            mValid;
     std::string     mUIPath;
diff --git a/Source/DNSettings.cpp b/Source/DNSettings.cpp
new file mode 100644 (file)
index 0000000..19bad77
--- /dev/null
@@ -0,0 +1,41 @@
+//  Copyright (c) 2012 Dennco Project
+//
+// This program 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.
+//
+// This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+
+//
+//  Created by tkawata on Apr/27/2012.
+//
+#include "DNSettings.h"
+#include "DNSettingsImpl.h"
+
+const char *DNSettings::CONTEXT_PATH        = "content_path";
+
+const char *DNSettings::SERIAL_PORTNAME     = "serial portName";
+const char *DNSettings::SERIAL_RATE         = "serial rate";
+const char *DNSettings::SERIAL_DATABITS     = "serial databits";
+const char *DNSettings::SERIAL_PARITY       = "serial parity";
+const char *DNSettings::SERIAL_STOPBITS     = "serial stopbits";
+const char *DNSettings::SERIAL_FLOWCONTROL  = "serial flowControl";
+
+//static
+std::string DNSettings::getValue(const char *key, std::string defaultValue)
+{
+    return DNSettingsImpl::getValue(key, defaultValue);
+}
+
+//static
+void DNSettings::setValue(const char *key, std::string value)
+{
+    DNSettingsImpl::setValue(key, value);
+}
diff --git a/Source/DNSettings.h b/Source/DNSettings.h
new file mode 100644 (file)
index 0000000..7014364
--- /dev/null
@@ -0,0 +1,44 @@
+//  Copyright (c) 2012 Dennco Project
+//
+// This program 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.
+//
+// This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+
+//
+//  Created by tkawata on Apr/27/2012.
+//
+#ifndef DNSETTINGS_H
+#define DNSETTINGS_H
+
+#include <string>
+
+class DNSettings
+{
+public:
+    static const char *CONTEXT_PATH;
+
+    static const char *SERIAL_PORTNAME;
+    static const char *SERIAL_RATE;
+    static const char *SERIAL_DATABITS;
+    static const char *SERIAL_PARITY;
+    static const char *SERIAL_STOPBITS;
+    static const char *SERIAL_FLOWCONTROL;
+
+    static std::string getValue(const char *key, std::string defaultValue = "");
+    static void setValue(const char *key, std::string value);
+
+
+private:
+    DNSettings() {}
+};
+
+#endif // DNSETTINGS_H
diff --git a/Source/DNSettingsImpl.h b/Source/DNSettingsImpl.h
new file mode 100644 (file)
index 0000000..2a1ed2a
--- /dev/null
@@ -0,0 +1,34 @@
+//  Copyright (c) 2012 Dennco Project
+//
+// This program 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.
+//
+// This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+
+//
+//  Created by tkawata on Apr/27/2012.
+//
+#ifndef DNSETTINGSIMPL_H
+#define DNSETTINGSIMPL_H
+
+#include <string>
+
+class DNSettingsImpl
+{
+public:
+    static std::string getValue(const char* key, std::string defaultValue);
+    static void setValue(const char* key, std::string value);
+
+private:
+    DNSettingsImpl() {}
+};
+
+#endif // DNSETTINGSIMPL_H
index 28e5420..6f3d0a8 100644 (file)
@@ -22,7 +22,6 @@
 #include <QFileDialog>
 #include <QDir>
 #include <QDebug>
-#include <QSettings>
 #include <QWebFrame>
 
 #include "TKLog.h"
@@ -31,6 +30,7 @@
 #include "DNEngine.h"
 #include "TKConsole.h"
 #include "dnwebinterface.h"
+#include "DNSettings.h"
 
 //static
 QWidget *MainWindow::instance = NULL;
@@ -44,9 +44,8 @@ MainWindow::MainWindow(QWidget *parent) :
     instance = this;
     ui->setupUi(this);
 
-    QSettings settings("dennco project", "dennco engine");
-    QVariant defaultPath(QDir::homePath());
-    QString  contentPath = settings.value("content_path", defaultPath).toString();
+    QString defaultPath(QDir::homePath());
+    QString contentPath = QString::fromStdString(DNSettings::getValue(DNSettings::CONTEXT_PATH, defaultPath.toStdString()));
 
     ui->filePath->setText(contentPath);
 
@@ -85,8 +84,7 @@ void MainWindow::on_chooseDirButton_clicked()
     {
         ui->filePath->setText(dirPath);
 
-        QSettings settings("dennco project", "dennco engine");
-        settings.setValue("content_path", QVariant(dirPath));
+        DNSettings::setValue(DNSettings::CONTEXT_PATH, dirPath.toStdString());
     }
 }
 
index 5b4327b..2bf52d1 100644 (file)
@@ -58,7 +58,9 @@ SOURCES += QtDennco/mainwindow.cpp \
     DNServerHTTP.cpp \
     DNServerSerialPort.cpp \
     DNSerialPort.cpp \
-    platform/qt/qtdnserialportimpl.cpp
+    platform/qt/qtdnserialportimpl.cpp \
+    DNSettings.cpp \
+    platform/qt/qtdnsettingsimpl.cpp
 
 
 HEADERS  += QtDennco/mainwindow.h \
@@ -118,7 +120,9 @@ HEADERS  += QtDennco/mainwindow.h \
     DNSerialPort.h \
     DNSerialPortImpl.h \
     platform/qt/qtdnserialportimpl.h \
-    DNServerHTTPImpl.h
+    DNServerHTTPImpl.h \
+    DNSettings.h \
+    DNSettingsImpl.h
 
 FORMS    += QtDennco/mainwindow.ui
 FORMS    += QtDennco/portinfodialog.ui
index a3ba5e7..76538e5 100644 (file)
@@ -24,6 +24,7 @@
 #include "mainwindow.h"
 #include "TKLog.h"
 #include "DNUtils.h"
+#include "DNSettings.h"
 
 #include <QThread>
 #include <QtCore/QVariant>
@@ -393,6 +394,68 @@ QtDNSerialPortSettingDialog::QtDNSerialPortSettingDialog(QWidget *parent)
     connect(ui->portsComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(procItemPortChanged(int)));
     connect(ui->okPushButton, SIGNAL(clicked()), this, SLOT(procOKButtonClick()));
     connect(ui->cancelPushButton, SIGNAL(clicked()), this, SLOT(procCancelButtonClick()));
+
+    //default setting
+    QString defaultPortName = QString::fromStdString(DNSettings::getValue(DNSettings::SERIAL_PORTNAME , ""));
+    for (int i = 0; i < ui->portsComboBox->count(); i++)
+    {
+        if (ui->portsComboBox->itemText(i) == defaultPortName)
+        {
+            ui->portsComboBox->setCurrentIndex(i);
+            break;
+        }
+    }
+
+    QString defaultBaudRate = QString::fromStdString(DNSettings::getValue(DNSettings::SERIAL_RATE, "9600"));
+    for (int i = 0; i < ui->ratesComboBox->count(); i++)
+    {
+        if (ui->ratesComboBox->itemText(i) == defaultBaudRate)
+        {
+            ui->ratesComboBox->setCurrentIndex(i);
+            break;
+        }
+    }
+
+    QString defaultDataBits = QString::fromStdString(DNSettings::getValue(DNSettings::SERIAL_DATABITS, "8"));
+    for (int i = 0; i < ui->dataBitsComboBox->count(); i++)
+    {
+        if (ui->dataBitsComboBox->itemText(i) == defaultDataBits)
+        {
+            ui->dataBitsComboBox->setCurrentIndex(i);
+            break;
+        }
+    }
+
+    QString defaultParity = QString::fromStdString(DNSettings::getValue(DNSettings::SERIAL_PARITY, "No parity"));
+    for (int i = 0; i < ui->parityComboBox->count(); i++)
+    {
+        if (ui->parityComboBox->itemText(i) == defaultParity)
+        {
+            ui->parityComboBox->setCurrentIndex(i);
+            break;
+        }
+    }
+
+    QString defaultStopBits = QString::fromStdString(DNSettings::getValue(DNSettings::SERIAL_STOPBITS, "one stop"));
+    for (int i = 0; i < ui->stopBitsComboBox->count(); i++)
+    {
+        if (ui->stopBitsComboBox->itemText(i) == defaultStopBits)
+        {
+            ui->stopBitsComboBox->setCurrentIndex(i);
+            break;
+        }
+    }
+
+    QString defaultFlowControl = QString::fromStdString(DNSettings::getValue(DNSettings::SERIAL_FLOWCONTROL, "No flow control"));
+    for (int i = 0; i < ui->flowControlComboBox->count(); i++)
+    {
+        if (ui->flowControlComboBox->itemText(i) == defaultFlowControl)
+        {
+            ui->flowControlComboBox->setCurrentIndex(i);
+            break;
+        }
+    }
+
 }
 
 QtDNSerialPortSettingDialog::~QtDNSerialPortSettingDialog()
@@ -538,5 +601,13 @@ void QtDNSerialPortSettingDialog::procCancelButtonClick()
 
 bool QtDNSerialPortSettingDialog::isOK()
 {
+    // save selections
+    DNSettings::setValue(DNSettings::SERIAL_PORTNAME, ui->portsComboBox->currentText().toStdString());
+    DNSettings::setValue(DNSettings::SERIAL_RATE, ui->ratesComboBox->currentText().toStdString());
+    DNSettings::setValue(DNSettings::SERIAL_DATABITS, ui->dataBitsComboBox->currentText().toStdString());
+    DNSettings::setValue(DNSettings::SERIAL_PARITY, ui->parityComboBox->currentText().toStdString());
+    DNSettings::setValue(DNSettings::SERIAL_STOPBITS, ui->stopBitsComboBox->currentText().toStdString());
+    DNSettings::setValue(DNSettings::SERIAL_FLOWCONTROL, ui->flowControlComboBox->currentText().toStdString());
+
     return mIsOK;
 }
diff --git a/Source/platform/qt/qtdnsettingsimpl.cpp b/Source/platform/qt/qtdnsettingsimpl.cpp
new file mode 100644 (file)
index 0000000..600c672
--- /dev/null
@@ -0,0 +1,42 @@
+//  Copyright (c) 2012 Dennco Project
+//
+// This program 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.
+//
+// This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+
+//
+//  Created by tkawata on Apr/27/2012.
+//
+#include "DNSettingsImpl.h"
+
+#include <QString>
+#include <QSettings>
+#include <QVariant>
+
+#include <string>
+
+//static
+std::string DNSettingsImpl::getValue(const char *key, std::string defaultValue)
+{
+    QSettings settings("dennco project", "dennco engine");
+    QString  result = settings.value(QString(key), QString::fromStdString(defaultValue)).toString();
+
+    return result.toStdString();
+}
+
+//static
+void DNSettingsImpl::setValue(const char *key, std::string value)
+{
+    QSettings settings("dennco project", "dennco engine");
+    settings.setValue(QString(key), QVariant(QString::fromStdString(value)));
+}
+