-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0984c00
Showing
3 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |