Changes between Initial Version and Version 1 of PacpusTutorialsNewComponent


Ignore:
Timestamp:
05/13/16 10:21:26 (8 years ago)
Author:
DHERBOMEZ Gérald
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • PacpusTutorialsNewComponent

    v1 v1  
     1= Introduction =
     2
     3In this tutorial we will learn how to add a new component to an existing PACPUS project.
     4Before starting, please make sure that your installation of PACPUS framework works fine, follow the guide here: GettingStarted
     5
     6= Goal =
     7
     8So we will add a component to the [source:pacpussensors pacpussensors] project that will generate a string and send it to an ouput.
     9
     10= Explanations =
     11
     12== step 1: getting the source code of the project and compile it ==
     13
     14Go to your development folder, typically it may ~/dev/pacpus and get the source code of the SVN repository and compile the project:
     15
     16{{{
     17svn co https://devel.hds.utc.fr/svn/pacpussensors/trunk pacpussensors
     18}}}
     19
     20We will keep only the PacpusSocket plugin for this example. Edit the CMakeLists.txt in the pacpussensors directory and comment all {{{add_subdirectory(...)}}} commands except of {{{add_subdirectory(PacpusSocket)}}}. You will get something like this:
     21
     22{{{
     23# ========================================
     24# Build the PacpusSensors' modules
     25# ========================================
     26#
     27# In the following list add the plugin you want to build.
     28# Paths are relative to the root of the project.
     29#
     30
     31#add_subdirectory(Alasca)
     32#add_subdirectory(CanGateway)       #require kvaser libcan
     33#add_subdirectory(PtGreyCameras)
     34#add_subdirectory(Dualshock)
     35#add_subdirectory(NMEA0183)
     36#add_subdirectory(Gps)              #require NMEA0183
     37#add_subdirectory(SpanCPTComponent) #require NMEA0183
     38#add_subdirectory(Sick)
     39add_subdirectory(PacpusSocket)
     40#add_subdirectory(OpencvVideo)
     41#add_subdirectory(Wifibot)         #depends on PacpusSocket, change PacpusSocket to PacpusUdpSocket
     42#add_subdirectory(Ladybug)         #require Ladybug spherical camera's driver, not compiled yet
     43#add_subdirectory(StdDbtPlayerComponents)
     44#add_subdirectory(TelnetClient)
     45#add_subdirectory(VelodyneComponent)
     46}}}
     47
     48To compile the project we will do it with QtCreator (please read the page to knwow how to configure correctly the project regarding pacpus needs). Open the software, then select the menu {{{File->Open File or Project}}} and choose the root {{{CMakeLists.txt}}} (in ~/dev/pacpus/pacpussensors/ if you have followed the guidelines).
     49
     50In the Build menu, launch the building process, the results of a correct compilation is:
     51{{{
     52[100%] Built target PacpusSocket
     53Install the project...
     54-- Install configuration: ""
     55-- Installing: /opt/pacpus/0.2.3/bin/libPacpusSocket.so
     56-- Removed runtime path from "/opt/pacpus/0.2.3/bin/libPacpusSocket.so"
     57-- Installing: /opt/pacpus/0.2.3/include/PacpusSocket
     58-- Up-to-date: /opt/pacpus/0.2.3/include/PacpusSocket/PacpusUDPSocket.h
     59-- Installing: /opt/pacpus/0.2.3/include/PacpusSocket/PacpusSocketConfig.h
     60-- Installing: /opt/pacpus/0.2.3/include/PacpusSocket/PacpusSocketPlugin.h
     61-- Up-to-date: /opt/pacpus/0.2.3/include/PacpusSocket/PacpusSocketAirplug.h
     62}}}
     63
     64The PacpusSocket.so plugin and headers files should be installed in your PACPUS_ROOT folder.
     65
     66
     67== Step 2: writing the StringGenerator component ==
     68
     69We will add the {{{StringGenerator}}} component to the {{{pacpussensors}}} project. Instead of adding a new plugin, we will include this component to the {{{PacpusSocket}}} plugin.
     70
     71So go to the !PacpusSocket folder and create 2 new files:
     72- {{{StringGenerator.h}}}: the declaration of the component, the class may inherit from {{{QObject}}} (needed for the input/output mechanism) and {{{ComponentBase}}} (mandatory to be a pacpus component)
     73- {{{StringGenerator.cpp}}}: the implementation of the component that must follow the component interface, ie:
     74  - a declaration of a {{{ComponentFactory}}}: {{{static ComponentFactory <MyClassComponent> sFactory("MyComponentTypeForTheXml");}}}
     75  - a specific constructor with a QString parameter: {{{MyClassComponent::MyClassComponent(QString name) : ComponentBase(name)}}}
     76  - the 5 pacpus methods:
     77     - {{{void MyClassComponent::startActivity()}}}
     78     - {{{void MyClassComponent::stopActivity()}}}
     79     - {{{ComponentBase::COMPONENT_CONFIGURATION  MyClassComponent::configureComponent(XmlComponentConfig config)}}}
     80     - {{{void MyClassComponent::addInputs()}}}
     81     - {{{void MyClassComponent::addOutputs()}}}
     82
     83
     84
     85
     86