Skip to content
This repository has been archived by the owner on Jan 7, 2019. It is now read-only.

Commit

Permalink
[XPCC] Add ZeroMQ as transport layer for XPCC.
Browse files Browse the repository at this point in the history
This feature adds a ZeroMQ implementation of the XPCC backend as a
replacement for TIPC on hosted targets and examples to show this new
functionality.
  • Loading branch information
salkinium committed Oct 3, 2016
2 parents b21f502 + 55d7aea commit a00d3cc
Show file tree
Hide file tree
Showing 61 changed files with 1,132 additions and 140 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ addons:
- lib32z1
- lib32ncurses5
- lib32bz2-1.0
- libzmqpp-dev

before_install:
- export CC=gcc-4.8
Expand Down Expand Up @@ -66,5 +67,6 @@ env:
- TEST_SUITE="check=examples examples=nucleo_f411re"
- TEST_SUITE="check=examples examples=nucleo_f429zi"
- TEST_SUITE="check=examples examples=unittest"
- TEST_SUITE="check=examples examples=zmq"

script: "scons $TEST_SUITE"
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include "receiver.hpp"

// ----------------------------------------------------------------------------
component::Receiver::Receiver(uint8_t id, xpcc::Dispatcher *communication) :
component::Receiver::Receiver(uint8_t id, xpcc::Dispatcher &communication) :
xpcc::AbstractComponent(id, communication)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace component
class Receiver : public xpcc::AbstractComponent
{
public:
Receiver(uint8_t id, xpcc::Dispatcher *communication);
Receiver(uint8_t id, xpcc::Dispatcher &communication);

void
actionSetPosition(const xpcc::ResponseHandle& handle,
Expand Down
2 changes: 1 addition & 1 deletion examples/avr/communication/receiver/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ FLASH_STORAGE(uint8_t canFilter[]) =

namespace component
{
Receiver receiver(robot::component::RECEIVER, &dispatcher);
Receiver receiver(robot::component::RECEIVER, dispatcher);
}

// ----------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include "sender.hpp"

// ----------------------------------------------------------------------------
component::Sender::Sender(uint8_t id, xpcc::Dispatcher *communication) :
component::Sender::Sender(uint8_t id, xpcc::Dispatcher &communication) :
xpcc::AbstractComponent(id, communication),
positionCallback(this, &Sender::getPositionCallback),
timer(2000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace component
class Sender : public xpcc::AbstractComponent
{
public:
Sender(uint8_t id, xpcc::Dispatcher *communication);
Sender(uint8_t id, xpcc::Dispatcher &communication);

void
update();
Expand Down
2 changes: 1 addition & 1 deletion examples/avr/communication/sender/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ FLASH_STORAGE(uint8_t canFilter[]) =

namespace component
{
Sender sender(robot::component::SENDER, &dispatcher);
Sender sender(robot::component::SENDER, dispatcher);
}

// ----------------------------------------------------------------------------
Expand Down
82 changes: 0 additions & 82 deletions examples/avr/communication/xml/communication.dtd

This file was deleted.

44 changes: 44 additions & 0 deletions examples/communication/xml/communication.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<!DOCTYPE rca SYSTEM "communication.dtd">
<rca version="1.0">

<!-- Basic data types -->
<builtin name="int8_t" size="1" />
<builtin name="int16_t" size="2" />
<builtin name="int32_t" size="4" />
Expand All @@ -16,13 +17,27 @@
This type is defined to make it possible to send bools from everywhere.</description>
</typedef>

<!-- Aggregated data types -->
<struct name="position">
<description>Position of the Robot on the Playground.</description>

<element name="x" type="int16_t" unit="mm" />
<element name="y" type="int16_t" unit="mm" />
</struct>

<struct name="Location">
<description>Lage = Position + Orientierung</description>
<element name="x" type="int16_t" unit="mm" />
<element name="y" type="int16_t" unit="mm" />
<element name="phi" type="float" unit="rad" />
</struct>

<!-- Events -->
<event name="Robot Location" type="Location" id="0x13">
<description>The current Location of the Robot. Pivot point of the differential drive.</description>
</event>

<!-- Components -->
<component name="sender" id="0x01">

</component>
Expand All @@ -34,7 +49,28 @@
</actions>
</component>

<component name="odometry" id="0x03">
<actions>
<action name="set led red" id="0x09" parameterType="Bool" />
</actions>
<events>
<publish>
<event name="Robot Location" />
<!-- <event name="Odometry Speed" /> -->
<!-- <event name="Odometry Encoder Integration" /> -->
</publish>
</events>
</component>

<component name="gui" id="0x04">
<events>
<subscribe>
<event name="Robot Location" />
</subscribe>
</events>
</component>

<!-- Containers -->
<container name="sender">
<component name="sender" />
</container>
Expand All @@ -43,9 +79,17 @@
<component name="receiver" />
</container>

<container name="odometry">
<component name="odometry" />
</container>

<container name="senderreceiver">
<component name="sender" />
<component name="receiver" />
</container>

<container name="gui">
<component name="gui" />
</container>

</rca>
2 changes: 1 addition & 1 deletion examples/linux/can_debugger/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <xpcc/architecture.hpp>

#include <xpcc/architecture/interface/can.hpp>
#include <xpcc/architecture/platform/driver/can/hosted/canusb.hpp>
#include <xpcc/architecture/platform/driver/can/canusb/canusb.hpp>

#include <cstdlib>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include "receiver.hpp"

// ----------------------------------------------------------------------------
component::Receiver::Receiver(uint8_t id, xpcc::Dispatcher *communication) :
component::Receiver::Receiver(uint8_t id, xpcc::Dispatcher &communication) :
xpcc::AbstractComponent(id, communication)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace component
class Receiver : public xpcc::AbstractComponent
{
public:
Receiver(uint8_t id, xpcc::Dispatcher *communication);
Receiver(uint8_t id, xpcc::Dispatcher &communication);

void
actionSetPosition(const xpcc::ResponseHandle& handle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include "sender.hpp"

// ----------------------------------------------------------------------------
component::Sender::Sender(uint8_t id, xpcc::Dispatcher *communication) :
component::Sender::Sender(uint8_t id, xpcc::Dispatcher &communication) :
xpcc::AbstractComponent(id, communication),
positionCallback(this, &Sender::getPositionCallback),
timer(2000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace component
class Sender : public xpcc::AbstractComponent
{
public:
Sender(uint8_t id, xpcc::Dispatcher *communication);
Sender(uint8_t id, xpcc::Dispatcher &communication);

void
update();
Expand Down
22 changes: 15 additions & 7 deletions examples/linux/communication/basic/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
#include <xpcc/architecture.hpp>

#include <xpcc/communication.hpp>
#include <xpcc/communication/xpcc/backend/tipc.hpp>
// #include <xpcc/communication/xpcc/backend/tipc.hpp>
#include <xpcc/communication/xpcc/backend/zeromq.hpp>

#include <xpcc/debug/logger.hpp>

Expand All @@ -16,7 +17,13 @@
#include "communication/postman.hpp"
#include "communication/identifier.hpp"

xpcc::TipcConnector connector;
// Use TIPC on Linux only
// xpcc::TipcConnector connector;

// Use ZeroMQ on Linux and Darwin
const std::string endpointIn = "tcp://127.0.0.1:8211";
const std::string endpointOut = "tcp://127.0.0.1:8212";
static xpcc::ZeroMQConnector connector(endpointIn, endpointOut, xpcc::ZeroMQConnector::Mode::SubPush);

// create an instance of the generated postman
Postman postman;
Expand All @@ -25,19 +32,20 @@ xpcc::Dispatcher dispatcher(&connector, &postman);

namespace component
{
Sender sender(robot::component::SENDER, &dispatcher);
Receiver receiver(robot::component::RECEIVER, &dispatcher);
Sender sender(robot::component::SENDER, dispatcher);
Receiver receiver(robot::component::RECEIVER, dispatcher);
}

int
main()
{
connector.addReceiverId(robot::component::SENDER);
connector.addReceiverId(robot::component::RECEIVER);
// Required for TIPC on Linux only
// connector.addReceiverId(robot::component::SENDER);
// connector.addReceiverId(robot::component::RECEIVER);

XPCC_LOG_INFO << "Welcome to the communication test!" << xpcc::endl;

while (1)
while (true)
{
// deliver received messages
dispatcher.update();
Expand Down
5 changes: 4 additions & 1 deletion examples/linux/communication/basic/project.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
container = senderreceiver
source = ../../../communication/xml/communication.xml

[environment]
LINKCOM* = -lpthread -lzmqpp -lzmq

[build]
device = hosted/linux
device = hosted
buildpath = ${xpccpath}/build/linux/${name}
4 changes: 2 additions & 2 deletions examples/linux/gui/basic/project.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[build]
device = hosted
buildpath = ${xpccpath}/build/linux/${name}
buildpath = ${xpccpath}/build/linux/gui/${name}

[environment]
CXXCOM* = `pkg-config --libs --cflags gtkmm-2.4 cairomm-1.0 sdl`
LINKCOM* = `pkg-config --libs --cflags gtkmm-2.4 cairomm-1.0 sdl`
LINKCOM* = `pkg-config --libs --cflags gtkmm-2.4 cairomm-1.0 sdl` -lpthread -lzmqpp -lzmq
1 change: 1 addition & 0 deletions examples/zmq/1_stm32/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
communication/
4 changes: 4 additions & 0 deletions examples/zmq/1_stm32/SConstruct
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# path to the xpcc root directory
xpccpath = '../../..'
# execute the common SConstruct file
execfile(xpccpath + '/scons/SConstruct')
Loading

0 comments on commit a00d3cc

Please sign in to comment.