Bladeren bron

Erste Version mit Qml-Plugin zur Ansicht.

Rind 5 jaren geleden
bovenliggende
commit
e95ca9a318

+ 1 - 1
gfativaflashutil.pro

@@ -18,7 +18,7 @@ CONFIG(release, debug|release) {
 linux-buildroot-g++ {
     QMAKE_CXXFLAGS += -D_TARGET_BUILD
     QMAKE_CFLAGS += -D_TARGET_BUILD
-	target.path += /opt/GfA/gfativaflashutil
+    target.path += /opt/GfA/tivaflashutil
 	INSTALLS += target
 }
 

+ 12 - 0
qmlplugin/Demo/.gitignore

@@ -0,0 +1,12 @@
+# git ls-files --others --exclude-from=.git/info/exclude
+# Lines that start with '#' are comments.
+# For a project mostly in C, the following would be a good set of
+# exclude patterns (uncomment them if you want to use them):
+# *.[oa]
+# *~
+
+Debug/
+Profile/
+Release/
+*.pro.user
+*.bak

+ 30 - 0
qmlplugin/Demo/Demo.pro

@@ -0,0 +1,30 @@
+QT += quick
+
+CONFIG += c++11
+
+# The following define makes your compiler emit warnings if you use
+# any Qt feature that has been marked deprecated (the exact warnings
+# depend on your compiler). Refer to the documentation for the
+# deprecated API to know how to port your code away from it.
+DEFINES += QT_DEPRECATED_WARNINGS
+
+# You can also make your code fail to compile if it uses deprecated APIs.
+# In order to do so, uncomment the following line.
+# You can also select to disable deprecated APIs only up to a certain version of Qt.
+#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
+
+SOURCES += \
+        main.cpp
+
+RESOURCES += qml.qrc
+
+# Additional import path used to resolve QML modules in Qt Creator's code model
+QML_IMPORT_PATH =
+
+# Additional import path used to resolve QML modules just for Qt Quick Designer
+QML_DESIGNER_IMPORT_PATH =
+
+# Default rules for deployment.
+qnx: target.path = /tmp/$${TARGET}/bin
+else: unix:!android: target.path = /opt/$${TARGET}/bin
+!isEmpty(target.path): INSTALLS += target

+ 20 - 0
qmlplugin/Demo/main.cpp

@@ -0,0 +1,20 @@
+#include <QGuiApplication>
+#include <QQmlApplicationEngine>
+
+int main(int argc, char *argv[])
+{
+    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
+
+    QGuiApplication app(argc, argv);
+
+    QQmlApplicationEngine engine;
+    const QUrl url(QStringLiteral("qrc:/main.qml"));
+    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
+                     &app, [url](QObject *obj, const QUrl &objUrl) {
+        if (!obj && url == objUrl)
+            QCoreApplication::exit(-1);
+    }, Qt::QueuedConnection);
+    engine.load(url);
+
+    return app.exec();
+}

+ 46 - 0
qmlplugin/Demo/main.qml

@@ -0,0 +1,46 @@
+import QtQuick 2.7
+import QtQuick.Window 2.2
+import gfa.plugins.qml.tivaflash 1.0
+
+Window {
+    visible: true
+    width: 640
+    height: 480
+    title: qsTr("Hello World")
+
+    Text {
+         id: idExecOut
+         x: 5
+         y: 60
+         width: 630
+         height: 300
+         color: "black"
+         font.pixelSize: 14
+         text: ""
+     }
+
+    TivaFlash {
+        id: idTivaFlash
+        tivaFlashUtilPath: "/opt/GfA/tivaflashutil/gfativaflashutil"
+        itfName: "/dev/ttyO4"
+        statNum: 1
+        mbSlaveId: 100
+        verbosity: 3
+
+        onExecOut:
+        {
+            idExecOut.text += out;
+            idExecOut.update();
+            console.log(out);
+        }
+	}
+
+    MouseArea {
+        anchors.fill: parent
+        onClicked:
+        {
+            idExecOut.text = "";
+        	idTivaFlash.showMatSer();
+        }
+    }
+}

+ 5 - 0
qmlplugin/Demo/qml.qrc

@@ -0,0 +1,5 @@
+<RCC>
+    <qresource prefix="/">
+        <file>main.qml</file>
+    </qresource>
+</RCC>

+ 13 - 0
qmlplugin/libgfativaflashplugin/.gitignore

@@ -0,0 +1,13 @@
+# git ls-files --others --exclude-from=.git/info/exclude
+# Lines that start with '#' are comments.
+# For a project mostly in C, the following would be a good set of
+# exclude patterns (uncomment them if you want to use them):
+# *.[oa]
+# *~
+
+Debug/
+Profile/
+Release/
+install.sh
+*.pro.user
+*.bak

+ 172 - 0
qmlplugin/libgfativaflashplugin/gfativaflash.cpp

@@ -0,0 +1,172 @@
+#include <stdio.h>
+#include <stdarg.h>
+#include <string>
+#include "gfativaflash.h"
+
+/////////////////////////////////////////////////////////////////////////////
+
+static std::string _formatString(const char *fmt, ...)
+{
+	int n;
+	std::string s;
+	char *p = NULL;
+	va_list ap;
+	va_start(ap, fmt);
+	n = ::vasprintf(&p, fmt, ap);
+	va_end(ap);
+	if(n >= 0)
+	{
+		s = p;
+		free(p);
+	}
+	return s;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+TivaFlash::TivaFlash(QObject *pParent) : QObject(pParent), m_statNum(0), m_nodeAddr(0), m_mbSlaveId(0), m_verbosity(-1)
+{
+	setObjectName("TivaFlash");
+}
+
+TivaFlash::~TivaFlash(void)
+{
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+int TivaFlash::execFlashUtil(const char *pszOpt)
+{
+	FILE* pd;
+	char buffer[256];
+	std::string strCmd;
+
+	strCmd = _formatString("\"%s\" %s 2>&1", m_tivaFlashUtilPath.c_str(), pszOpt);
+
+	if(m_verbosity >= 0)
+		strCmd += _formatString(" -v%d", m_verbosity);
+		
+	if((pd = popen(strCmd.c_str(), "r")))
+	{
+		while(fgets(buffer, sizeof buffer, pd))
+		{
+			onCmdOutput(buffer);
+		}
+
+		pclose(pd);
+	}
+
+	return 0;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+std::string TivaFlash::statNumOrNodeAddr(void) const
+{
+	std::string ret;
+
+	if(m_nodeAddr)
+		ret = _formatString("--node-addr=%d", m_nodeAddr);
+	else if(m_statNum)
+		ret = _formatString("--stat-num=%d", m_statNum);
+	
+	return ret;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+void TivaFlash::onCmdOutput(const char *pszOut) const
+{
+	emit execOut(QString(pszOut));
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+int TivaFlash::showHelp(void)
+{
+	const char *pszOpt = "--help";
+	return execFlashUtil(pszOpt);
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+int TivaFlash::showMatSer(void)
+{
+	std::string strOpt;
+	strOpt = _formatString("--show-mat-ser --itf-name=\"%s\" %s", m_itfName.c_str(), statNumOrNodeAddr().c_str());
+	if(m_mbSlaveId)
+		strOpt += _formatString(" --mb-slave-id=%d", m_mbSlaveId);
+	return execFlashUtil(strOpt.c_str());
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+QString TivaFlash::tivaFlashUtilPath(void) const
+{
+	return QString::fromStdString(m_tivaFlashUtilPath);
+}
+
+void TivaFlash::setTivaFlashUtilPath(const QString &val)
+{
+	m_tivaFlashUtilPath = val.toStdString();
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+QString TivaFlash::itfName(void) const
+{
+	return QString::fromStdString(m_itfName);
+}
+
+void TivaFlash::setItfName(const QString &val)
+{
+	m_itfName = val.toStdString();
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+int TivaFlash::statNum(void) const
+{
+	return m_statNum;
+}
+
+void TivaFlash::setStatNum(int val)
+{
+	m_statNum = val;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+int TivaFlash::nodeAddr(void) const
+{
+	return m_nodeAddr;
+}
+
+void TivaFlash::setNodeAddr(int val)
+{
+	m_nodeAddr = val;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+int TivaFlash::mbSlaveId(void) const
+{
+	return m_mbSlaveId;
+}
+
+void TivaFlash::setMbSlaveId(int val)
+{
+	m_mbSlaveId = val;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+int TivaFlash::verbosity(void) const
+{
+	return m_verbosity;
+}
+
+void TivaFlash::setVerbosity(int val)
+{
+	m_verbosity = val;
+}

+ 78 - 0
qmlplugin/libgfativaflashplugin/gfativaflash.h

@@ -0,0 +1,78 @@
+// gfativaflash.h :
+//
+
+#if !defined(AGD_GFATIVAFLASH_H__49F09E25_28B7_4178_B4B6_6DAFF98ABECD__INCLUDED_)
+#define AGD_GFATIVAFLASH_H__49F09E25_28B7_4178_B4B6_6DAFF98ABECD__INCLUDED_
+
+#include <string>
+#include <QObject>
+#include <QList>
+#include <QQmlListProperty>
+#include <qqmlparserstatus.h>
+
+#ifdef __cplusplus
+
+/////////////////////////////////////////////////////////////////////////////
+// gfativaflash.h - Declarations:
+
+typedef void (*PFN_READ_OUTPUT_CALLBACK)(const char *pszOut);
+
+/////////////////////////////////////////////////////////////////////////////
+
+class TivaFlash : public QObject
+{
+    Q_OBJECT
+    Q_PROPERTY(QString tivaFlashUtilPath READ tivaFlashUtilPath WRITE setTivaFlashUtilPath)
+    Q_PROPERTY(QString itfName READ itfName WRITE setItfName)
+    Q_PROPERTY(int statNum READ statNum WRITE setStatNum)
+    Q_PROPERTY(int nodeAddr READ nodeAddr WRITE setNodeAddr)
+    Q_PROPERTY(int mbSlaveId READ mbSlaveId WRITE setMbSlaveId)
+    Q_PROPERTY(int verbosity READ verbosity WRITE setVerbosity)
+
+public:
+    explicit TivaFlash(QObject *pParent = NULL);
+    virtual ~TivaFlash(void);
+
+public:
+	Q_INVOKABLE int showHelp(void);
+	Q_INVOKABLE int showMatSer(void);
+
+signals:
+	void execOut(QString out) const;
+
+private:
+	QString tivaFlashUtilPath(void) const;
+	void setTivaFlashUtilPath(const QString &val);
+
+	QString itfName(void) const;
+	void setItfName(const QString &val);
+
+	int statNum(void) const;
+	void setStatNum(int val);
+
+	int nodeAddr(void) const;
+	void setNodeAddr(int val);
+
+	int mbSlaveId(void) const;
+	void setMbSlaveId(int val);
+
+	int verbosity(void) const;
+	void setVerbosity(int val);
+
+private:
+	int execFlashUtil(const char *pszOpt);
+	void onCmdOutput(const char *pszOut) const;
+	std::string statNumOrNodeAddr(void) const;
+
+private:
+	std::string m_itfName;
+	std::string m_tivaFlashUtilPath;
+	int m_statNum;
+	int m_nodeAddr;
+	int m_mbSlaveId;
+	int m_verbosity;
+};
+
+/////////////////////////////////////////////////////////////////////////////
+#endif	//	__cplusplus
+#endif	//	!defined(AGD_GFATIVAFLASH_H__49F09E25_28B7_4178_B4B6_6DAFF98ABECD__INCLUDED_)

+ 14 - 0
qmlplugin/libgfativaflashplugin/gfativaflash_plugin.cpp

@@ -0,0 +1,14 @@
+#include "gfativaflash_plugin.h"
+#include "gfativaflash.h"
+#include <qqml.h>
+
+void TivaFlashPlugin::registerTypes(const char *uri)
+{
+    // gfa.plugins.qml.tivaflash
+    qmlRegisterType<TivaFlash>(uri, 1, 0, "TivaFlash");
+/*    qmlRegisterUncreatableType<Interface>(uri, 1, 0, "Interface", "return type only");
+    qmlRegisterUncreatableType<Inet>(uri, 1, 0, "Inet", "return type only");
+    qmlRegisterUncreatableType<Static>(uri, 1, 0, "Static", "return type only");
+    qmlRegisterUncreatableType<Dhcp>(uri, 1, 0, "Dhcp", "return type only");
+    qmlRegisterUncreatableType<IPv4Address>(uri, 1, 0, "IPv4Address", "return type only");*/
+}

+ 25 - 0
qmlplugin/libgfativaflashplugin/gfativaflash_plugin.h

@@ -0,0 +1,25 @@
+// gfativaflash_plugin.h :
+//
+
+#if !defined(AGD_GFATIVAFLASH_PLUGIN_H__C0A6A381_7F81_4454_A36E_DF5BC5C2CF47__INCLUDED_)
+#define AGD_GFATIVAFLASH_PLUGIN_H__C0A6A381_7F81_4454_A36E_DF5BC5C2CF47__INCLUDED_
+
+#include <QQmlExtensionPlugin>
+
+#ifdef __cplusplus
+
+/////////////////////////////////////////////////////////////////////////////
+// gfativaflash_plugin.h - Declarations:
+
+class TivaFlashPlugin : public QQmlExtensionPlugin
+{
+    Q_OBJECT
+    Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)
+
+public:
+    void registerTypes(const char *uri);
+};
+
+/////////////////////////////////////////////////////////////////////////////
+#endif	//	__cplusplus
+#endif	//	!defined(AGD_GFATIVAFLASH_PLUGIN_H__C0A6A381_7F81_4454_A36E_DF5BC5C2CF47__INCLUDED_)

+ 47 - 0
qmlplugin/libgfativaflashplugin/gfativaflashplugin.pro

@@ -0,0 +1,47 @@
+TEMPLATE = lib
+TARGET = gfativaflashplugin
+QT += qml
+CONFIG += qt plugin c++11
+
+CONFIG(debug, debug|release) {
+    QMAKE_CXXFLAGS -= -Os
+    QMAKE_CFLAGS -= -Os
+    QMAKE_CXXFLAGS += -D_DEBUG
+    QMAKE_CFLAGS += -D_DEBUG
+    QMAKE_LIBS += -lgfamininetd
+}
+
+CONFIG(release, debug|release) {
+    QMAKE_LIBS += -lgfamininet
+}
+
+uri = gfa.plugins.qml.tivaflash
+
+DISTFILES = qmldir
+
+!equals(_PRO_FILE_PWD_, $$OUT_PWD)
+{
+    copy_qmldir.target = $$OUT_PWD/qmldir
+    copy_qmldir.depends = $$_PRO_FILE_PWD_/qmldir
+    copy_qmldir.commands = $(COPY_FILE) \"$$replace(copy_qmldir.depends, /, $$QMAKE_DIR_SEP)\" \"$$replace(copy_qmldir.target, /, $$QMAKE_DIR_SEP)\"
+    QMAKE_EXTRA_TARGETS += copy_qmldir
+    PRE_TARGETDEPS += $$copy_qmldir.target
+}
+
+qmldir.files = qmldir
+
+#unix {
+    installPath = $$[QT_INSTALL_QML]/$$replace(uri, \\., /)
+    qmldir.path = $$installPath
+    target.path = $$installPath
+    INSTALLS += target qmldir
+#    message($${installPath})
+#}
+
+HEADERS += \
+    gfativaflash.h \
+    gfativaflash_plugin.h
+
+SOURCES += \
+    gfativaflash.cpp \
+    gfativaflash_plugin.cpp

+ 4 - 0
qmlplugin/libgfativaflashplugin/qmldir

@@ -0,0 +1,4 @@
+module gfa.plugins.qml.tivaflash
+plugin gfativaflashplugin
+classname TivaFlash
+typeinfo tivaflash.qmltypes