Skip to content

RTI Connector for Connext DDS is a lightweight technology that enables DDS data to be accessed with Go.

License

Notifications You must be signed in to change notification settings

rticommunity/rticonnextdds-connector-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rticonnextdds-connector-go

Coverage Go Report Card Build and Test

RTI Connector for Connext DDS

RTI Connector for Connext DDS is a quick and easy way to access the power and functionality of RTI Connext DDS. It is based on XML-Based Application Creation and Dynamic Data.

Connector was created by the RTI Research Group to quickly and easily develop demos and proofs of concept. It can be useful for anybody that needs a quick way to develop an application communicating over the Connext DDS Databus. Thanks to the binding with multiple programming languages, you can integrate with many other available technologies.

The Connector library is provided in binary form for select architectures. Language bindings and examples are provided in source format.

Go Connector leverages cgo to call its C library; this detail is hidden in a Go wrapper.

Examples

Simple Reader

package main
import (
	rti "github.com/rticommunity/rticonnextdds-connector-go"
	"log"
)

func main() {
	// Create a connector defined in the XML configuration
	connector, err := rti.NewConnector("MyParticipantLibrary::Zero", "./ShapeExample.xml")
	if err != nil {
		log.Panic(err)
	}
	// Delete the connector when this main function returns
	defer connector.Delete()
	
	// Get an input from the connector
	input, err := connector.GetInput("MySubscriber::MySquareReader")
	if err != nil {
		log.Panic(err)
	}

	// Get values from a received sample and print them
	for {
		connector.Wait(-1)
		input.Take()
		numOfSamples, _ := input.Samples.GetLength()
		for i := 0; i < numOfSamples; i++ {
			valid, _ := input.Infos.IsValid(i)
			if valid {
				color, _ := input.Samples.GetString(i, "color")
				x, _ := input.Samples.GetInt(i, "x")
				y, _ := input.Samples.GetInt(i, "y")
				shapesize, _ := input.Samples.GetInt(i, "shapesize")

				log.Println("---Received Sample---")
				log.Printf("color: %s\n", color)
				log.Printf("x: %d\n", x)
				log.Printf("y: %d\n", y)
				log.Printf("shapesize: %d\n", shapesize)
			}
		}
	}
}

Simple Writer

package main
import (
	"github.com/rticommunity/rticonnextdds-connector-go"
	"log"
	"time"
)

func main() {
	// Create a connector defined in the XML configuration
	connector, err := rti.NewConnector("MyParticipantLibrary::Zero", "./ShapeExample.xml")
	if err != nil {
		log.Panic(err)
	}
	// Delete the connector when this main function returns
	defer connector.Delete()

	// Get an output from the connector
	output, err := connector.GetOutput("MyPublisher::MySquareWriter")
	if err != nil {
		log.Panic(err)
	}

	// Set values to the instance and write the instance
	for i := 0; i < 10; i++ {
		output.Instance.SetInt("x", i)
		output.Instance.SetInt("y", i*2)
		output.Instance.SetInt("shapesize", 30)
		output.Instance.SetString("color", "BLUE")
		output.Write()
		log.Println("Writing...")
		time.Sleep(time.Second * 1)
	}
}

XML Configurations

<dds>
  <!-- Qos Library -->
  <qos_library name="QosLibrary">
    <qos_profile name="DefaultProfile" base_name="BuiltinQosLibExp::Generic.StrictReliable" is_default_qos="true">
      <participant_qos>
        <transport_builtin>
          <mask>UDPV4 | SHMEM</mask>
        </transport_builtin>
      </participant_qos>
    </qos_profile>
  </qos_library>
  <!-- types -->
  <types>
    <struct name="ShapeType" extensibility="extensible">
      <member name="color" stringMaxLength="128" id="0" type="string" key="true"/>
      <member name="x" id="1" type="long"/>
      <member name="y" id="2" type="long"/>
      <member name="shapesize" id="3" type="long"/>
    </struct>
    <enum name="ShapeFillKind" extensibility="extensible">
      <enumerator name="SOLID_FILL" value="0"/>
      <enumerator name="TRANSPARENT_FILL" value="1"/>
      <enumerator name="HORIZONTAL_HATCH_FILL" value="2"/>
      <enumerator name="VERTICAL_HATCH_FILL" value="3"/>
    </enum>
    <struct name="ShapeTypeExtended" baseType="ShapeType" extensibility="extensible">
      <member name="fillKind" id="4" type="nonBasic" nonBasicTypeName="ShapeFillKind"/>
      <member name="angle" id="5" type="float"/>
    </struct>
  </types>
  <!-- Domain Library -->
  <domain_library name="MyDomainLibrary">
    <domain name="MyDomain" domain_id="0">
      <register_type name="ShapeType" type_ref="ShapeType"/>
      <topic name="Square" register_type_ref="ShapeType"/>
    </domain>
  </domain_library>
  <!-- Participant library -->
  <domain_participant_library name="MyParticipantLibrary">
    <domain_participant name="Zero" domain_ref="MyDomainLibrary::MyDomain">
      <publisher name="MyPublisher">
        <data_writer name="MySquareWriter" topic_ref="Square"/>
      </publisher>
      <subscriber name="MySubscriber">
        <data_reader name="MySquareReader" topic_ref="Square"/>
      </subscriber>
    </domain_participant>
  </domain_participant_library>
</dds>

Please see examples for usage details.

Getting started

Using Go Modules

Be sure you have golang installed.

Import:

import "github.com/rticommunity/rticonnextdds-connector-go"

Please see examples for usage details.

Build:

$ go build reader.go

A dependency to the latest stable version of rticonnextdds-connector-go should be automatically added to your go.mod file.

Run:

To run your application, you need to add the Connector C library to your library path.

$ export LD_LIBRARY_PATH=$GOPATH//go/pkg/mod/github.com/rticommunity/rticonnextdds-connector-go\@{version}-{YYYYMMDDHHmm}-{commit_id}/rticonnextdds-connector/lib/linux-x64:$LD_LIBRARY_PATH
$ ./simple_reader

Platform support

Go Connector builds its library for few select architectures. If you need another architecture, please contact your RTI account manager or [email protected].

If you want to check the version of the libraries you can run the following command:

strings ./rticonnextdds-connector/lib/linux-x64/librtiddsconnector.so | grep BUILD

Threading model

The Connector Native API does not yet implement any mechanism for thread safety. Originally, the Connector native code was built to work with RTI Prototyper and Lua. That was a single-threaded loop. RTI then introduced support for JavaScript, Python, and Go. For now, you are responsible for protecting calls to Connector. Thread safety may be implemented in the future.

Support

Connector is an experimental RTI product. If you have questions, please use the RTI Community Forum. If you would like to report a bug or have a feature request, please create an issue.

Documentation

The best way to get started with Connector is to look at the examples; you will see that it is very easy to use.

Contributing

Contributions to the code, examples, documentation are really appreciated. Please follow the steps below for contributions.

  1. Sign the CLA.
  2. Create a fork and make your changes.
  3. Run tests and linters (make test lint).
  4. Push your branch.
  5. Open a new pull request.