Skip to content

On the communication component of the API

Benedek Horvath edited this page Sep 7, 2017 · 20 revisions

How to send messages to the railway track?

Implementing your own stack

Use find the protobuf definition of the Network messages that are used by the system. You should generate the Java / C++ / Python / etc. classes from those definitions and connect to the network via MQTT.

Using the services provided by the API

  1. You should extend from the AbstractRailRoadCommunicationComponent (v1.1 API), or from the AbstractCommunicationComponent (v2.0 API).

  2. In order to create a CommunicationStack (v1.1 API) use the CommunicationStackFactory (v1.1 API). In the v2.0 API you should use the MessagingService and the MessagingServiceFactory classes.

  3. In the AbstractRailRoadCommunicationComponent (v1.1 API) or the AbstractCommunicationComponent (v2.0 API) you should find a field called locator, which has a TrackCommunicationServiceLocator v1.1, v2.0. You should use its fields, if you would like to:

    • send commands to the network (set segment’s enabledness, set turnout’s direction, set train’s speed)

    • get status information about various elements (segment’s occupancy, segment’s enabledness, turnout’s direction)

    • register your listener for a particular message

How to use the TrackCommunicationServiceLocator?

  • Should you use the v2.0 API, you can find example classes, in the sample project, which explain how you can send commands and retrieve status information. These examples can be used in the v1.1 API in a similar way though.

  • The main difference between v1.1 and v2.0 versions of the *Locator is, in the latter version there are separate commanders for Train annd DCC commands, while in the first version they are included in the TrackElementCommander.

Fields of the TrackCommunicationServiceLocator v1.1:

TrackCommunicationServiceLocator v1.1

Fields of the TrackCommunicationServiceLocator v2.0:

TrackCommunicationServiceLocator v2.0

Clone this wiki locally