Interacting with the Pub Sub Server - AboudyKreidieh/truck-code GitHub Wiki

Table of Contents

Introduction

This page provides an overview of QNX's persistent publish/subscriber server and describes how the truck-code framework's API leverages this service to communicate messages between processes. This page will only provide a brief overview of PPS, for a more detailed description refer to this resource.

Overview of QNX PPS

Persistent Publish Subscribe, or PPS, is a publish-subscribe server developed within the QNX operating operating system. It can be imported into any C++ program by including the following package:

#include <sys/pps.h>

PPS Objects

PPS supports asynchronous communication between processes via PPS objects, or unique files generated by the publish/subscribe server within the /pps/ directory. These objects consist of a title variable preceded by an @ symbol, and an attribute-value pairing separated by two colons. For example, a time object with attributes for hours, minutes, and seconds may be represented as follows:

@Time
second::38
hour::17
minute::04

This object and unique attributes within the object can be created, modified, and deleted in real-time via method calls from the pps package. or through default c++ methods such as open() read(), and sprintf() while using the O_WRONLY flag to publish only, and the O_RDWR flag to publish and subscribe. For examples of how this is performed with the pps package, review the section of the resource in the introduction titled "Encoding PPS data" and check out our source code on publishing messages.

Subscribing to Objects

Subscriptions in PPS are handle by subscribing to individual objects. This can be done in one of two modes, full or delta. In full mode, the entire published object is returned whenever an subscriber calls for it. Alternately, in delta mode, only the attributes that have been added, modified, or deleted are returned to the subscriber. The former method is used by this framework to ensure computational efficiency. For examples of how this is performed with the pps package, review the section of the resource in the introduction titled "Decoding PPS data" and check out our source code on subscribing to and updating messages.

Sending and Receiving Messages

Interfacing with the publish/subscribe server is abstracted in this framework and handled by the PubSub object located with src/utils/pub_sub.h. This object is responsible for creating connections with the the appropriate PPS objects, the sending and receiving of messages via this connection. In order to create a new PubSub object, type:

#include "utils/pub_sub.h"

PubSub *ps = new PubSub()

The PubSub object is currently designed to handle publishing and subscribing certain J1939 messages. To subscribe a specific object, use the subscribe method with the input parameter being PGN number of the messages, as described in include/jbus/j1939_utils.h. For example, in you would like to subscribe to TSC1 messages, type:

#include "jbus/j1939_utils.h"

ps->subscribe(TSC1)

Each PubSub object can subscribe to multiple J1939 messages. In order to retrieve subscription results from all variables that have changed, type:

res = ps->get_subscription_results()

This will return a map<int, void*> object, whose keys are the object number (i.e. PGN number of the J1939 message) and whose variables are the actual message. The TSC1 message, for example, could be extracted as follows:

#include "jbus/j1939_struct.h"

j1939_tsc1_typ *tsc1_subscribed = res[TSC1]

Warning: The repository currently creates a new object every time this method is called. This needs to be resolved in future releases.

If alternatively you would like to use the PubSub object for publishing new messages within the server, this can be done by typing:

j1939_tsc1_typ *tsc1_published = new j1939_tsc1_typ()
ps->publish(TSC1, tsc1_published)
⚠️ **GitHub.com Fallback** ⚠️