12
Recipe to Build Open Splice DDS Ver 6.3.xxx Hello World Example Over Qt 5.2 1. This recipe is developed to help those who could face problem in deploying Open Splice DDS Ver 6.3.xxx over Qt 5.2. This recipe would help them to develop GUI based applications over LINUX. 2. Following are steps wise details :- Pre-requisite: According to my station following is the configuration:-. a. Ubuntu 13.10 b. Qt 5.2.0 based on (GCC 4.6.1, 32 bit) c. GCC 4.8.1 d. autoconf e. automake f. build-essential g. OpenSpliceDDSV6.3.130716OSS-HDE-x86.linux-gcc4.6-glibc2.15 for LINUX kernel 3.0 and above. (Download from following link) http://www.prismtech.com/opensplice/opensplice-dds-community/software-downloads ) Step No 1: Configure Environmental Settings 3. Create a folder opensplice in /home/xxxxx.xxx copy the above downloaded open splice api folder and unzip. Or you can unzip anywhere else but for easy reference use /home folder. 4. Open a Terminal in Ubuntu and go inside the folder as mentioned below:- >cd /home/xxxxx.xxxx/opensplice/HDE/x86.linux2.6 >ls -all {This command is use to check the directory. Check availability of file release.com.} >chmod 777 release.com Note: This command make release.com an executable 5. release.com contains environmental settings which are mandatory to build any application based on open splice DDS. Open release.com in any text editor analyze it. As mentioned below:-

Recipe to build open splice dds 6.3.xxx Hello World example over Qt 5.2

Embed Size (px)

Citation preview

Page 1: Recipe to build open splice dds 6.3.xxx Hello World example over Qt 5.2

Recipe to Build Open Splice DDS Ver 6.3.xxx Hello World Example Over Qt 5.2 1. This recipe is developed to help those who could face problem in deploying Open SpliceDDS Ver 6.3.xxx over Qt 5.2. This recipe would help them to develop GUI based applications overLINUX.

2. Following are steps wise details :-

Pre-requisite: According to my station following is the configuration:-.

a. Ubuntu 13.10b. Qt 5.2.0 based on (GCC 4.6.1, 32 bit)c. GCC 4.8.1d. autoconfe. automake

f. build-essentialg. OpenSpliceDDSV6.3.130716OSS-HDE-x86.linux-gcc4.6-glibc2.15 for LINUX

kernel 3.0 and above. (Download from following link) http://www.prismtech.com/opensplice/opensplice-dds-community/software-downloads )

Step No 1: Configure Environmental Settings

3. Create a folder opensplice in /home/xxxxx.xxx copy the above downloaded open splice apifolder and unzip. Or you can unzip anywhere else but for easy reference use /home folder.

4. Open a Terminal in Ubuntu and go inside the folder as mentioned below:-

>cd /home/xxxxx.xxxx/opensplice/HDE/x86.linux2.6>ls -all {This command is use to check the directory. Check availability of file

release.com.} >chmod 777 release.com Note: This command make release.com an executable

5. release.com contains environmental settings which are mandatory to build any applicationbased on open splice DDS. Open release.com in any text editor analyze it. As mentioned below:-

Page 2: Recipe to build open splice dds 6.3.xxx Hello World example over Qt 5.2

6. At line OSPL_HOME=”/home/..../opensplice/HDE/.... ” you can add your own addresswhere you had un-ziped the folder. Moreover, edit CPATH variable and replace with followingpaths:-

CPATH=$OSPL_HOME/include/dcps/C++/CCPP:$OSPL_HOME/include/dcps/C++/isocpp:$OSPL_HOME/include/dcps/C++/SACPP:$OSPL_HOME/include:$OSPL_HOME/include/sys:${CPATH:=}

7. There are three ways to load these environmental setting:-

Option 1: Just write following line on the command prompt. >. ./release.com

8. This suppose to work but if due to some reasons setting are not loaded then we have to loadeach setting manually mentioned in option 2. but to check setting are loaded, write following linesand check the response.

> echo $OSPL_HOME> echo $OSPL_TARGET > echo $PATH > echo $LD_LIBRARY_PATH > echo $CPATH> echo $OSPL_URI> echo $OSPL_TMPL_PATH

Option 2: Load each line over command prompt one by one and check

SPLICE_JDK=jdk export SPLICE_JDK export OSPL_HOME="/home/....../opensplice/HDE/x86.linux2.6" echo $OSPL_HOMEexport OSPL_TARGET=x86.linux2.6 echo $OSPL_TARGET export PATH=$OSPL_HOME/bin:$PATH

Page 3: Recipe to build open splice dds 6.3.xxx Hello World example over Qt 5.2

echo $PATH export LD_LIBRARY_PATH=$OSPL_HOME/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH echo $LD_LIBRARY_PATH export CPATH=$OSPL_HOME/include:$OSPL_HOME/include/sys:${CPATH:=} echo $CPATHexport OSPL_URI=file://$OSPL_HOME/etc/config/ospl.xml echo $OSPL_URIexport OSPL_TMPL_PATH=$OSPL_HOME/etc/idlpp echo $OSPL_TMPL_PATH$OSPL_HOME/etc/java/defs.$SPLICE_JDK

Option 3: Open the file /etc/environment as root and update. Add lines mentioned in option # 2 (Note: load each setting manually on terminal and copy output of echo $xxxx command;for reference setting are mentioned below):-

>sudo nano /etc/environment

9. nano is a text editor if it is not install use following command and connect to INTERNET.

>sudo apt-get update>sudo apt-get install nano

10. update the environment file .

11. Add following lines as mentioned in above picture (../adilkhan/ would be replace with yoursystem folder address).

PATH=/home/xxx.xxxx/opensplice/HDE/x86.linux2.6/etc/idlpp:/home/xxx.xxxx/opensplice/HDE/x86.linux2.6/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games OSPL_HOME=/home/xxx.xxxx/opensplice/HDE/x86.linux2.6 OSPL_TARGET=x86.linux2.6 LD_LIBRARY_PATH=/home/xxx.xxxx/opensplice/HDE/x86.linux2.6/lib CPATH=/home/xxx.xxxx/opensplice/HDE/x86.linux2.6/include:/home/xxx.xxxx/opensplice/HDE/x86.linux2.6/include/sys:/home/xxx.xxxx/opensplice/HDE/x86.linux2.6/include/dcps/C++/SACPP:/home/xxx.xxxx/opensplice/HDE/x86.linux2.6/include/dcps/C++/CCPP:/home/xxx.xxxx/opensplice/HDE/x86.linux2.6/include/dcps/C++/isocpp OSPL_URI=file:///home/xxx.xxxx/opensplice/HDE/x86.linux2.6/etc/config/ospl.xml

Page 4: Recipe to build open splice dds 6.3.xxx Hello World example over Qt 5.2

OSPL_TMPL_PATH=/home/xxx.xxxx/opensplice/HDE/x86.linux2.6/etc/idlpp QTDIR=/home/xxx.xxxx/Qt5.2.0/5.2.0/gcc CLASSPATH=/home/xxx.xxxx/opensplice/HDE/x86.linux2.6/jar/dcpssaj.jar:/home/xxx.xxxx/opensplice/HDE/x86.linux2.6/jar/dcpscj.jar:$CLASSPATH

12. Now, execute following line on terminal.

>source /etc/environment

10. Important Note : Always load these setting using any of the above options.

Step No 2: Starting Qt 5.2 Creator

11. Open terminal and load environmental setting as mentioned in Step No 1.

12. Using same terminal instance, navigate to Qt 5.2 folder. Note: If other terminal is use toload Qt Creator, then environmental setting shall not be valid.

>cd /home/.../opensplice/HDE/x86.linux2.6>. ./release.com>cd /home/..../Qt5.2/Tools/QtCreator/bin>./qtcreator

Step No 3: Hello World Publisher

13. This recipe takes you step by step to convert Hello World example into QT based GUIapplication. However, this is not a tutorial to Qt but, I shall be using Qt terminologies directly:-

(a) Create two new projects using Qt Widget Application:-

Page 5: Recipe to build open splice dds 6.3.xxx Hello World example over Qt 5.2

(b) Add project name HelloWorldDDS_Publisher for first and HelloWorldDDS_Subscriber for second.

(c) Copy Checkstatus.cpp & .h / DDSEntityManager.cpp & .h / HelloWorldData.idlfrom opensplice HelloWorld (C++) example folder into project folder separately (copyingseparately is just to keep it isolated). Open another terminal load environmental settings,then go into project folder where HelloWorldData.idl file is copied and execute followingcommand. It would generate requisite file to configure topic and its type support:-

> idlpp -S -l cpp HelloWorldData.idl

(d) Add above generated files as existing files along with Checkstatus.cpp & .h / DDSEntityManager.cpp & .h into the project.

(e) Go inside project build setting and edit build environment. Add all the Paths andsetting mentioned in Step # 1 : option # 3.

Page 6: Recipe to build open splice dds 6.3.xxx Hello World example over Qt 5.2

(f) Add library. Select external library then select LINUX as platform and browse. Go into a folder /home/..../opensplice/HDE/x86.linux2.6/lib and add each library one by one. This will update HelloWorldDDS_Publisher.pro and HelloWorldDDS_Subscriber.pro as shown in picture.

(g) Create user interface as shown below:-

-

(h) Edit mainwindow.cpp & .h files of both the projects as per attached Appendix A & B. However, complete project folder is also available with this document.

(j) Build the application, If there is some error try to find out over INTERNET or consult me over INTERNET for any query ([email protected])

14. Execute both projects on same or different computers and connect these computers overLAN or WiFi and enjoy DDS communication . It is better to launch from terminal after loadingenvironmental settings.

16. Use this recipe and play with different idl files and multiple QoS (quality of service).

You are allowed to share this recipe with any body.

Regards

Adil Khan

Page 7: Recipe to build open splice dds 6.3.xxx Hello World example over Qt 5.2

Appendix “A”

Publisher mainwindow.cpp

#include "mainwindow.h"#include "ui_mainwindow.h"#include "QString"#include <string>#include <sstream>#include <iostream>#include "DDSEntityManager.h"#include "ccpp_HelloWorldData.h"#include "os.h"#include "ccpp_dds_dcps.h"//#include "subscriberthread.h"#include <unistd.h>#include "CheckStatus.h"

using namespace DDS;

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

//QObject::connect(subscriberthread, SIGNAL(receivedtext(QString)), ui->plainTextEdit_Subscribe, SLOT(setPlainText(QString)));

DDSEntityManager mgr;

// create domain participant mgr.createParticipant("HelloWorld example");

//create type mt = new MsgTypeSupport(); mgr.registerType(mt.in());

//create Topic char topic_name[] = "HelloWorldData_Msg"; mgr.createTopic(topic_name);

//create Publisher mgr.createPublisher();

// create DataWriter : // If autodispose_unregistered_instances is set to true (default value), // you will have to start the subscriber before the publisher bool autodispose_unregistered_instances = false; mgr.createWriter(autodispose_unregistered_instances);

// Publish Events DataWriter_var dwriter = mgr.getWriter(); MsgDataWriter_var HelloWorldWriter = MsgDataWriter::_narrow(dwriter.in());

Msg msgInstance; /* Example on Stack */ msgInstance.userID = 1; msgInstance.message = DDS::string_dup("Hello World");

Page 8: Recipe to build open splice dds 6.3.xxx Hello World example over Qt 5.2

ui->plainTextEdit_Publish->setPlainText("Start Message:-"); ui->plainTextEdit_Publish->setPlainText( "userID : " + QString(msgInstance.userID)); ui->plainTextEdit_Publish->setPlainText("Message : " + QString( msgInstance.message));

ReturnCode_t status = HelloWorldWriter->write(msgInstance, DDS::HANDLE_NIL); checkStatus(status, "MsgDataWriter::write"); //os_nanoSleep(delay_1s);

/* Remove the DataWriters */ mgr.deleteWriter();

/* Remove the Publisher. */ mgr.deletePublisher();

/* Remove the Topics. */ mgr.deleteTopic(); /* Remove Participant. */ mgr.deleteParticipant();}MainWindow::~MainWindow(){ delete ui;}void MainWindow::on_Create_Participants_clicked(){ DDSEntityManager mgr; // create domain participant mgr.createParticipant("HelloWorld example");

//create type mt = new MsgTypeSupport(); mgr.registerType(mt.in());

//create Topic char topic_name[] = "HelloWorldData_Msg"; mgr.createTopic(topic_name);

//create Publisher mgr.createPublisher();

// create DataWriter : // If autodispose_unregistered_instances is set to true (default value), // you will have to start the subscriber before the publisher bool autodispose_unregistered_instances = false; mgr.createWriter(autodispose_unregistered_instances);

// Publish Events DataWriter_var dwriter = mgr.getWriter(); MsgDataWriter_var HelloWorldWriter = MsgDataWriter::_narrow(dwriter.in());

Msg msgInstance; /* Example on Stack */QString message; message = ui->transmit_text->toPlainText(); msgInstance.userID = 1; msgInstance.message = message.toUtf8().constData(); ui->plainTextEdit_Publish->setPlainText("Start Message:-"); ui->plainTextEdit_Publish->setPlainText( "userID : " + QString(msgInstance.userID));

Page 9: Recipe to build open splice dds 6.3.xxx Hello World example over Qt 5.2

ui->plainTextEdit_Publish->setPlainText("Message : " + QString( msgInstance.message));

ReturnCode_t status = HelloWorldWriter->write(msgInstance, DDS::HANDLE_NIL); checkStatus(status, "MsgDataWriter::write"); //os_nanoSleep(delay_1s);

/* Remove the DataWriters */ mgr.deleteWriter();

/* Remove the Publisher. */ mgr.deletePublisher();

/* Remove the Topics. */ mgr.deleteTopic();

/* Remove Participant. */ mgr.deleteParticipant();}void MainWindow::on_Quit_clicked(){ QCoreApplication::exit();}/**************************************************************************/mainwindow.h

#ifndef MAINWINDOW_H#define MAINWINDOW_H

#include <QMainWindow>#include "ccpp_HelloWorldData.h"#include "ccpp_dds_dcps.h"//#include "subscriberthread.h"

using namespace HelloWorldData; // Very important to declare this namespace

namespace Ui {

class MainWindow;}

class MainWindow : public QMainWindow{

Q_OBJECTpublic:

explicit MainWindow(QWidget *parent = 0); ~MainWindow();

//subscriberthread* subs=new subscriberthread; MsgTypeSupport_var mt;

Ui::MainWindow *ui;private slots:

void on_Create_Participants_clicked(); void on_Quit_clicked();

private: //MsgTypeSupport_var mt;

};#endif // MAINWINDOW_H

Page 10: Recipe to build open splice dds 6.3.xxx Hello World example over Qt 5.2

Appendix “B” : Subscriber mainwindow.cpp

#include "mainwindow.h"#include "ui_mainwindow.h"#include "QString"#include <string>#include <sstream>#include <iostream>#include "DDSEntityManager.h"#include "ccpp_HelloWorldData.h"#include "os.h"#include "ccpp_dds_dcps.h"//#include "subscriberthread.h"#include <unistd.h>#include "CheckStatus.h"#include <qthread.h>using namespace DDS;

DDSEntityManager subs;MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){ ui->setupUi(this);

}

MainWindow::~MainWindow(){ delete ui;}

void MainWindow::on_Subscribe_clicked(){ MsgSeq msgList; SampleInfoSeq infoSeq;

// create domain participants subs.createParticipant("HelloWorld example");

//create type MsgTypeSupport_var mt = new MsgTypeSupport(); subs.registerType(mt.in());

//create Topic char topic_name[] = "HelloWorldData_Msg"; subs.createTopic(topic_name);

//create Subscriber subs.createSubscriber();

// create DataReader subs.createReader();

DataReader_var dreader = subs.getReader(); MsgDataReader_var HelloWorldReader = MsgDataReader::_narrow(dreader.in()); checkHandle(HelloWorldReader.in(), "MsgDataReader::_narrow");

Page 11: Recipe to build open splice dds 6.3.xxx Hello World example over Qt 5.2

ui->plainTextEdit_Subscribe->setPlainText("=== [Subscriber] Ready ..."); // Q_EMIT receivedtext("=== [Subscriber] Ready ...");

bool closed = false; ReturnCode_t status = - 1; int count = 0; while (!closed && count < 1500) // We dont want the example to run indefinitely { status = HelloWorldReader->take(msgList, infoSeq, LENGTH_UNLIMITED, ANY_SAMPLE_STATE, ANY_VIEW_STATE, ANY_INSTANCE_STATE); checkStatus(status, "msgDataReader::take"); for (DDS::ULong j = 0; j < msgList.length(); j++) { ui->plainTextEdit_Subscribe->setPlainText("=== [Subscriber] message received :");// cout << " userID : " << msgList[j].userID << endl; // cout << " Message : \"" << msgList[j].message << "\"" << endl;

ui->plainTextEdit_Subscribe->setPlainText(QString::number(msgList[j].userID));ui->plainTextEdit_Subscribe->setPlainText(QString(msgList[j].message));

closed = true; } status = HelloWorldReader->return_loan(msgList, infoSeq); checkStatus(status, "MsgDataReader::return_loan"); //QThread::msleep(8); ++count; } //cleanup subs.deleteReader(); subs.deleteSubscriber(); subs.deleteTopic(); subs.deleteParticipant();

}

void MainWindow::on_Quit_clicked(){

QCoreApplication::exit();

}

/**************************************************************************/mainwindow.h

#ifndef MAINWINDOW_H#define MAINWINDOW_H

#include <QMainWindow>#include "ccpp_HelloWorldData.h"#include "ccpp_dds_dcps.h"//#include "subscriberthread.h"

using namespace HelloWorldData; // very important to declare this namespace

Page 12: Recipe to build open splice dds 6.3.xxx Hello World example over Qt 5.2

namespace Ui {class MainWindow;}

class MainWindow : public QMainWindow{ Q_OBJECT

public:

explicit MainWindow(QWidget *parent = 0); ~MainWindow();

MsgTypeSupport_var mt; Ui::MainWindow *ui;private slots:

void on_Subscribe_clicked();

void on_Quit_clicked();

private:

};

#endif // MAINWINDOW_H