Skip to content

Commit

Permalink
Add readme and sample code
Browse files Browse the repository at this point in the history
  • Loading branch information
jwillemsen committed Mar 31, 2023
0 parents commit 0984c00
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# R2DDS

This repository contains a sample ruby script to read/write ShapeType samples to DDS.

Using the DDS Dynamic API a Ruby language binding for DDS could be developed. A small proof of concept was created using the type specific data reader/writer but that would require C++ code generation for each new IDL defined type.
20 changes: 20 additions & 0 deletions test/shapes/ShapeType.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* @file test.idl
* @author
*
* @brief DDS Shapes example
*
* @copyright Copyright (c) Remedy IT Expertise BV
* Chamber of commerce Rotterdam nr.276339, The Netherlands
*/

#pragma DCPS_DATA_TYPE "ShapeType"
#pragma DCPS_DATA_KEY "ShapeType color"

struct ShapeType {
string color;
long x;
long y;
long shapesize;
};

83 changes: 83 additions & 0 deletions test/shapes/client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#--------------------------------------------------------------------
#
# Author: Johnny Willemsen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the R2DDS LICENSE which is
# included with this program.
#
# Copyright (c) Remedy IT Expertise BV
#--------------------------------------------------------------------

require 'optparse'
require 'lib/assert.rb'
include TestUtil::Assertions

OPTIONS = {
:dcps_debuglevel => 0,
}

ARGV.options do |opts|
script_name = File.basename($0)
opts.banner = "Usage: ruby #{script_name} [options]"

opts.separator ""

opts.on("--d LVL",
"Set DCPSDebugLevel value.",
"Default: 0") { |v| OPTIONS[:dcps_debuglevel]=v }

opts.separator ""

opts.on("-h", "--help",
"Show this help message.") { puts opts; exit }

opts.parse!
end

require 'dds'

class ShapeListener < DDS::DataReaderListener
def initialize()
end

def on_data_available(reader)
puts "Ruby on_data_available!"
shape = ShapeType.new("ORANGE", 10, 10, 10)
reader.read (shape);
puts "Read sample #{shape.color()} #{shape.x()} #{shape.y()} #{shape.shapesize()}";
end
end

begin

dfp = DDS.DomainParticipantFactory_init()
dp = dfp.create_participant()
topic = dp.create_topic()
pub = dp.create_publisher()
sub = dp.create_subscriber()
dw = pub.create_datawriter(topic)

listener = ShapeListener.new()

dr = sub.create_datareader(topic, listener)

$i = 0
$num = 10
shape = ShapeType.new("ORANGE", 10, 10, 10)

while $i < $num do
dw.write(shape)
shape.shapesize = $i * 10
shape.x = $i * 10 + 10
shape.y = $i * 10 + 10
shape.color = "RED"
$i=$i+1
sleep(1)
end

pub = dp.delete_contained_entities()

ensure

end

0 comments on commit 0984c00

Please sign in to comment.