Cluster Service and API - User Guide

For Application Developers Using the Cluster Service API

Version 1.0 | AGL Instrument Cluster Expert Group


Table of Contents

  1. Overview
  2. Architecture
  3. Getting Started
  4. API Reference
  5. Advanced Topics
  6. Support and Resources

Overview

The cluster-service provides a reusable IPC mechanism for automotive instrument cluster applications running on Automotive Grade Linux (AGL). It enables applications to receive real-time vehicle data such as speed, RPM, warning indicators (telltales), trip computer information, and more.

This software focuses to base software, not a final software. User can use reference implementation for demo. User should change for own real usage.

Usage

The command line options

--help       Print help strings.

--sound      Enable alarm sound.

--demo       Enable demo signals.  If this feature is enabled at build-time.

--can=NAME   Enable socket can feature (NAME=can if name, ex. can0).  If this feature is enabled at build-time.

Key Features

Dependency


Architecture

Communication Model

The cluster-service uses a push-based broadcast architecture:

┌────────────────────────────────────────────────────────┐
│                    CLUSTER SERVER                      │
│  ┌────────────┐      ┌──────────────┐                  │
│  │ Data       │─────▶│ Server Data  │                  │
│  │ Sources    │      │ Pool (Global)│                  │
│  │(CAN/Demo)  │      └──────┬───────┘                  │
│  └────────────┘             │                          │
│                             │                          │
│                   ┌─────────▼─────────┐                │
│                   │ Timer (16ms)      │                │
│                   │ + Smoothing       │                │
│                   └─────────┬─────────┘                │
│                             │                          │
│                             ▼                          │
│                   ┌──────────────────┐                 │
│                   │ Broadcast to ALL │                 │
│                   │ Clients          │                 │
│                   └─────────┬────────┘                 │
└─────────────────────────────┼──────────────────────────┘
                              │
                              │ SOCK_SEQPACKET
                              │ (Abstract Unix Socket)
                              │
        ┌─────────────────────┼─────────────────────┐
        │                     │                     │
        ▼                     ▼                     ▼
┌───────────────┐     ┌───────────────┐     ┌───────────────┐
│  CLIENT A     │     │  CLIENT B     │     │  CLIENT C     │
│ ┌───────────┐ │     │ ┌───────────┐ │     │ ┌───────────┐ │
│ │ Local     │ │     │ │ Local     │ │     │ │ Local     │ │
│ │ Data Pool │ │     │ │ Data Pool │ │     │ │ Data Pool │ │
│ └─────┬─────┘ │     │ └─────┬─────┘ │     │ └─────┬─────┘ │
│       │       │     │       │       │     │       │       │
│       ▼       │     │       ▼       │     │       ▼       │
│ ┌───────────┐ │     │ ┌───────────┐ │     │ ┌───────────┐ │
│ │ Callbacks │ │     │ │ Callbacks │ │     │ │ Callbacks │ │
│ └───────────┘ │     │ └───────────┘ │     │ └───────────┘ │
│       │       │     │       │       │     │       │       │
│       ▼       │     │       ▼       │     │       ▼       │
│  Application  │     │  Application  │     │  Application  │
└───────────────┘     └───────────────┘     └───────────────┘

Key Architectural Facts

  1. One-Way Communication: Clients ONLY receive data; they NEVER send to the server
  2. SOCK_SEQPACKET: Uses sequenced packet sockets (not stream sockets)
  3. Abstract Socket: Linux abstract socket namespace (no filesystem path)
  4. Two Data Pools:
  5. One global data pool in the server process
  6. Separate local data pool in each client process
  7. Broadcast Model: Server timer fires every 16ms and broadcasts identical packets to ALL connected clients
  8. Event-Driven: Clients use sd-event to receive broadcasts asynchronously

Data Flow

  1. Data Sources (demo generator or CAN) write to the server's global data pool
  2. Timer fires every 16ms in the server
  3. Server reads data from its data pool and applies smoothing (for speed/tacho)
  4. Server broadcasts the same packet to ALL client sockets
  5. Client event loop wakes up (EPOLLIN event)
  6. Client receives packet via data_pool_receive()
  7. Client updates its LOCAL data pool copy via data_pool_set_v1()
  8. Change detection triggers registered callbacks
  9. Application calls getter functions like getTurnR() which read from the local data pool

Getting Started

Installation

1. Build and Install the Cluster Service

# Clone the repository
git clone https://github.com/agl-ic-eg/cluster-service.git
cd cluster-service

# Generate configure script and configure with demo data source
./autogen.sh --enable-fake-data-source

# Build
make

# Install (may require sudo)
sudo make install

# Update library cache
sudo ldconfig

2. Start the Cluster Service

# Run the cluster service daemon
cluster-service &

Minimal Client Application

example/cluster-client.c

Configure options

--enable-fake-data-source : Enable fake data source (default is no)
--enable-socketcan-data-source : Enable socketcan data source (default is no)

API Reference

Initialization and Cleanup in libsystemd binding.

data_pool_client_setup_sdevent()

Connect to the cluster service and integrate with sd-event loop.

#include <cluster-api-sdevent.h>

int data_pool_client_setup_sdevent(
    sd_event *event,
    data_pool_client_handle_sdevent *handle
);

Parameters: - event: sd-event loop handle (must not be NULL) - handle: Pointer to receive client handle (must not be NULL)

Returns: - 0: Success - -1: Internal error (socket creation failed, connection failed, etc.) - -2: Argument error (NULL parameters)

Important Notes: - This function internally calls clusterInit() - do NOT call it manually - Creates a SOCK_SEQPACKET socket - Connects to the abstract Unix socket (no filesystem path) - Registers socket with the event loop for EPOLLIN events - You MUST run the event loop after calling this function to receive data

data_pool_client_cleanup_sdevent()

Disconnect from the cluster service and free resources.

int data_pool_client_cleanup_sdevent(
    data_pool_client_handle_sdevent handle
);

Reading Data

Refer to API document.


Advanced Topics

Thread Safety

Performance Characteristics


Support and Resources

Community


License

The cluster-service is licensed under the Apache License 2.0.

Copyright (c) 2021, Nippon Seiki Co., Ltd.

Copyright (C) 2024 Automotive Grade Linux.