July 24, 2024
Integrating HVAC Management in Android with DDS

As trendy autos turn out to be extra linked and feature-rich, the necessity for environment friendly and dependable communication protocols has grown. One of many important elements of automotive programs is the HVAC (Heating, Air flow, and Air Conditioning) system, which reinforces passenger consolation. This text explores the best way to combine HVAC management in Android with the DDS (Knowledge Distribution Service) protocol, enabling sturdy and scalable communication inside automotive programs.

This text builds upon the ideas mentioned in our earlier article, “Controlling HVAC Module in Vehicles Utilizing Android: A Dive into SOME/IP Integration.” It’s endorsed to learn that article first, because it covers the mixing of HVAC with SOME/IP, offering foundational information that can be useful for understanding the DDS integration described right here.

What’s HVAC?

HVAC programs in autos are accountable for sustaining a cushty cabin surroundings. These programs regulate temperature, airflow, and air high quality inside the automobile. Key elements embrace:

  • Heaters: Heat the cabin utilizing warmth from the engine or an electrical heater.
  • Air Conditioners: Cool the cabin by compressing and increasing refrigerant.
  • Air flow: Ensures contemporary air circulation inside the automobile.
  • Air Filters: Take away mud and pollution from incoming air.

Efficient HVAC management is essential for passenger consolation, and integrating this management with an Android system permits for a extra intuitive person expertise.

Detailed Overview of the DDS Protocol

Introduction to DDS

Knowledge Distribution Service (DDS) is a middleware protocol and API normal for data-centric connectivity. It permits scalable, real-time, reliable, high-performance, and interoperable knowledge exchanges between publishers and subscribers. DDS is particularly standard in mission-critical purposes like aerospace, protection, automotive, telecommunications, and healthcare on account of its robustness and adaptability.

Key Functionalities of DDS

  • Knowledge-Centric Publish-Subscribe (DCPS): DDS operates on the publish-subscribe mannequin the place knowledge producers (publishers) and knowledge shoppers (subscribers) talk by way of matters. This mannequin decouples the communication individuals in each time and house, enhancing scalability and adaptability.
  • High quality of Service (QoS): DDS offers in depth QoS insurance policies that may be configured to fulfill particular software necessities. These insurance policies management numerous elements of information supply, comparable to reliability, sturdiness, latency, and useful resource utilization.
  • Computerized Discovery: DDS contains built-in mechanisms for the automated discovery of individuals, matters, and knowledge readers/writers. This characteristic simplifies the setup and upkeep of communication programs, as entities can be part of and go away the community dynamically with out handbook configuration.
  • Actual-Time Capabilities: DDS is designed for real-time purposes, providing low latency and excessive throughput. It helps real-time knowledge distribution, making certain well timed supply and processing of data.
  • Interoperability and Portability: DDS is standardized by the Object Administration Group (OMG), which ensures interoperability between completely different DDS implementations and portability throughout numerous platforms.

Construction of DDS

Area Participant: The central entity in a DDS system is the area participant. It acts because the container for publishers, subscribers, matters, and QoS settings. A participant joins a site recognized by a novel ID, permitting completely different units of individuals to speak inside remoted domains.

Writer and Subscriber:

  • Writer: A writer manages knowledge writers and handles the dissemination of information to subscribers.
  • Subscriber: A subscriber manages knowledge readers and processes incoming knowledge from publishers.

Matter: Subjects are named entities representing an information kind and the QoS settings. They’re the factors of connection between publishers and subscribers. Subjects outline the construction and semantics of the information exchanged.

Knowledge Author and Knowledge Reader:

  • Knowledge Author: Knowledge writers are accountable for publishing knowledge on a subject.
  • Knowledge Reader: Knowledge readers subscribe to a subject and obtain knowledge from corresponding knowledge writers.

High quality of Service (QoS) Insurance policies: QoS insurance policies outline the contract between knowledge writers and knowledge readers. They embrace settings comparable to:

  • Reliability: Controls whether or not knowledge is delivered reliably (with acknowledgment) or best-effort.
  • Sturdiness: Determines how lengthy knowledge needs to be retained by the middleware.
  • Deadline: Specifies the utmost time allowed between consecutive knowledge samples.
  • Latency Finances: Units the suitable delay from knowledge writing to studying.

Guaranteeing Communication Correctness

DDS ensures right communication by way of numerous mechanisms:

  • Dependable Communication: Utilizing QoS insurance policies, DDS can assure dependable knowledge supply. For instance, the Reliability QoS will be set to “RELIABLE,” making certain that the subscriber acknowledges all knowledge samples.
  • Knowledge Consistency: DDS maintains knowledge consistency utilizing mechanisms like coherent entry, which ensures {that a} group of information modifications is utilized atomically.
  • Deadline and Liveliness: These QoS insurance policies be certain that knowledge is delivered inside specified time constraints. The Deadline coverage ensures that knowledge is up to date at anticipated intervals, whereas the Liveliness coverage verifies that individuals are nonetheless energetic.
  • Sturdiness: DDS helps numerous sturdiness ranges to make sure knowledge persistence. This ensures that late-joining subscribers can nonetheless entry historic knowledge.
  • Possession Power: In situations the place a number of publishers can publish on the identical matter, the Possession Power QoS coverage determines which writer’s knowledge needs to be used when conflicts happen.

Constructing the CycloneDDS Library for Android

To combine HVAC management in Android with the DDS protocol, we’ll use the CycloneDDS library. CycloneDDS is an open-source implementation of the DDS protocol, offering sturdy and environment friendly knowledge distribution. The supply code for CycloneDDS is on the market at Eclipse CycloneDDS GitHub, and the directions for constructing it for Android are detailed at CycloneDDS Android Port.

Stipulations

Earlier than beginning the construct course of, guarantee you’ve the next stipulations put in:

  • Android NDK: Obtain and set up the newest model from the Android NDK website.
  • CMake: Obtain and set up CMake from the CMake web site.
  • An acceptable construct surroundings (e.g., Linux or macOS).

Step-by-Step Construct Directions

1. Clone the CycloneDDS Repository: First, clone the CycloneDDS repository to your native machine:

git clone https://github.com/eclipse-cyclonedds/cyclonedds.git
cd cyclonedds

2. Set Up the Android NDK: Be certain that the Android NDK is correctly put in and its path is added to your surroundings variables.

export ANDROID_NDK_HOME=/path/to/your/android-ndk
export PATH=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH

3. Create a Construct Listing: Create a separate construct listing to maintain the construct recordsdata organized:

mkdir build-android
cd build-android

4. Configure the Construct with CMake: Use CMake to configure the construct for the Android platform. Regulate the ANDROID_ABI parameter primarily based in your goal structure (e.g., armeabi-v7a, arm64-v8a, x86, x86_64):

cmake -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_HOME/construct/cmake/android.toolchain.cmake 
      -DANDROID_ABI=arm64-v8a 
      -DANDROID_PLATFORM=android-21 
      -DCMAKE_BUILD_TYPE=Launch 
      -DBUILD_SHARED_LIBS=OFF 
      -DCYCLONEDDS_ENABLE_SSL=NO 
      ..

5. Construct the CycloneDDS Library: Run the construct course of utilizing CMake. This step compiles the CycloneDDS library for the required Android structure:

cmake --build .

Integrating CycloneDDS with VHAL

After constructing the CycloneDDS library, the subsequent step is to combine it with the VHAL (Car {Hardware} Abstraction Layer) software.

1. Copy the Constructed Library: Copy the libddsc.a file from the construct output to the VHAL software listing:

cp path/to/build-android/libddsc.a path/to/your/android/supply/{hardware}/interfaces/automotive/automobile/2.0/default/

2. Modify the Android.bp File: Add the CycloneDDS library to the Android.bp file positioned within the {hardware}/interfaces/automotive/automobile/2.0/default/ listing:

cc_prebuilt_library_static 
    title: "libdds",
    vendor: true,
    srcs: ["libddsc.a"],
    strip: 
        none: true,
    ,

3. Replace the VHAL Service Goal: In the identical Android.bp file, add the libdds library to the static_libs part of the android.{hardware}[email protected] goal:

cc_binary 
    title: "android.{hardware}[email protected]",
    srcs: ["VehicleService.cpp"],
    shared_libs: [
        "liblog",
        "libutils",
        "libbinder",
        "libhidlbase",
        "libhidltransport",
        "[email protected]",
    ],
    static_libs: [
        "[email protected]",
        "[email protected]",
        "[email protected]",
        "libdds",
    ],
    vendor: true,

Defining the Knowledge Mannequin with IDL

To allow DDS-based communication for HVAC management in our Android software, we have to outline an information mannequin utilizing the Interface Definition Language (IDL). On this instance, we’ll create a easy IDL file named hvacDriver.idl that describes the constructions used for HVAC management, comparable to fan pace, temperature, and air distribution.

hvacDriver.idl

Create a file named hvacDriver.idl with the next content material:

module HVACDriver

    struct FanSpeed
    
        octet worth;
    ;

    struct Temperature
    
        float worth;
    ;

    struct AirDistribution
    
        octet worth;
    ;
;

Producing C Code from IDL

As soon as the IDL file is created, we are able to use the idlc (IDL compiler) instrument offered by CycloneDDS to generate the corresponding C code. The generated recordsdata will embrace hvacDriver.h and hvacDriver.c, which include the information constructions and serialization/deserialization code wanted for DDS communication.

Run the next command to generate the C code:

idlc hvacDriver.idl

This command will produce two recordsdata:

  • hvacDriver.h
  • hvacDriver.c

Integrating the Generated Code with VHAL

After producing the C code, the subsequent step is to combine these recordsdata into the VHAL (Car {Hardware} Abstraction Layer) software.

Copy the Generated Information: Copy the generated hvacDriver.h and hvacDriver.c recordsdata to the VHAL software listing:

cp hvacDriver.h path/to/your/android/supply/{hardware}/interfaces/automotive/automobile/2.0/default/
cp hvacDriver.c path/to/your/android/supply/{hardware}/interfaces/automotive/automobile/2.0/default/

Embrace the Generated Header: Within the VHAL supply recordsdata the place you plan to make use of the HVAC knowledge constructions, embrace the generated header file. For example, in VehicleService.cpp, you may add:

#embrace “hvacDriver.h”

Modify the Android.bp File: Replace the Android.bp file within the {hardware}/interfaces/automotive/automobile/2.0/default/ listing to compile the generated C recordsdata and hyperlink them along with your software:

cc_library_static 
    title: "hvacDriver",
    vendor: true,
    srcs: ["hvacDriver.c"],


cc_binary 
    title: "android.{hardware}[email protected]",
    srcs: ["VehicleService.cpp"],
    shared_libs: [
        "liblog",
        "libutils",
        "libbinder",
        "libhidlbase",
        "libhidltransport",
        "[email protected]",
    ],
    static_libs: [
        "[email protected]",
        "[email protected]",
        "[email protected]",
        "libdds",
        "hvacDriver",
    ],
    vendor: true,

Implementing DDS within the VHAL Utility

To allow DDS-based communication inside the VHAL (Car {Hardware} Abstraction Layer) software, we have to implement a service that handles DDS operations. This service can be encapsulated within the HVACDDSService class, which is able to embrace strategies for initialization and working the service.

Step-by-Step Implementation

1. Create the HVACDDSService Class: First, we’ll outline the HVACDDSService class with strategies for initializing the DDS entities and working the service to deal with communication.

2. Initialization: The init technique will create a DDS participant, and for every construction (FanSpeed, Temperature, AirDistribution), it is going to create a subject, reader, and author.

3. Working the Service: The run technique will repeatedly learn messages from the DDS readers and set off a callback operate to deal with knowledge modifications.

void HVACDDSService::init() 

/* Create a Participant. */
participant = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL);
if(participant < 0)

LOG(ERROR) << "[DDS] " << __func__ << " dds_create_participant: " << dds_strretcode(-participant);

/* Create a Matter. */
qos = dds_create_qos();
dds_qset_reliability(qos, DDS_RELIABILITY_RELIABLE, DDS_SECS(10));
dds_qset_durability(qos, DDS_DURABILITY_TRANSIENT_LOCAL);

topic_temperature = dds_create_topic(participant, &Driver_Temperature_desc, "HVACDriver_Temperature", qos, NULL);
if(topic_temperature < 0)

LOG(ERROR) << "[DDS] " << __func__ << " dds_create_topic(temperature): "<< dds_strretcode(-topic_temperature);

reader_temperature = dds_create_reader(participant, topic_temperature, NULL, NULL);
if(reader_temperature < 0)

LOG(ERROR) << "[DDS] " << __func__ << " dds_create_reader(temperature): " << dds_strretcode(-reader_temperature);

writer_temperature = dds_create_writer(participant, topic_temperature, NULL, NULL);
if(writer_temperature < 0)

LOG(ERROR) << "[DDS] " << __func__ << " dds_create_writer(temperature): " << dds_strretcode(-writer_temperature);

.....

void HVACDDSService::run()

samples_temperature[0] = Driver_Temperature__alloc();
samples_fanspeed[0] = Driver_FanSpeed__alloc();
samples_airdistribution[0] = Driver_AirDistribution__alloc();

whereas (true)

bool no_data = true;

rc = dds_take(reader_temperature, samples_temperature, infos, MAX_SAMPLES, MAX_SAMPLES);
if (rc < 0)

LOG(ERROR) << "[DDS] " << __func__ << " temperature dds_take: " << dds_strretcode(-rc);

/* Examine if we learn some knowledge and it's legitimate. */
if ((rc > 0) && (infos[0].valid_data))

no_data = false;

Driver_Temperature *msg = (Driver_Temperature *) samples_temperature[0];
LOG(INFO) << "[DDS] " << __func__ << " === [Subscriber] Message temperature(" << (float)msg->worth << ")";
if (tempChanged_)

std::stringstream ss;
ss << std::fastened << std::setprecision(2) << msg->worth;
tempChanged_(ss.str());

......

if(no_data)

/* Polling sleep. */
dds_sleepfor (DDS_MSECS (20));


Constructing and Deploying the Utility

After implementing the HVACDDSService class and integrating it into your VHAL software, the subsequent steps contain constructing the applying and deploying it to your Android system.

Constructing the Utility

1. Construct the VHAL Utility: Be certain that your Android construct surroundings is ready up appropriately and that each one obligatory dependencies are in place. Then, navigate to the basis of your Android supply tree and run the construct command:

supply construct/envsetup.sh
lunch <goal>
m -j android.{hardware}[email protected]

2. Confirm the Construct: Examine that the construct completes efficiently and that the binary to your VHAL service is created. The output binary needs to be positioned within the out/goal/product/<system>/system/vendor/bin/ listing.

Deploying the Utility

1. Push the Binary to the Gadget: Join your Android system to your improvement machine by way of USB, and use adb to push the constructed binary to the system:

adb push out/goal/product/<system>/system/vendor/bin/android.{hardware}[email protected] /vendor/bin/

2. Restart system

Conclusion

On this article, now we have lined the steps to combine DDS (Knowledge Distribution Service) communication for HVAC management in an Android Automotive surroundings utilizing the CycloneDDS library. Right here’s a abstract of the important thing factors:

1. CycloneDDS Library Setup:

  • Cloned and constructed CycloneDDS for Android.
  • Built-in the constructed library into the VHAL software.

2. Knowledge Mannequin Definition:

  • Outlined a easy knowledge mannequin for HVAC management utilizing IDL.
  • Generated the required C code from the IDL definitions.

3. HVACDDSService Implementation:

  • Created the HVACDDSService class to handle DDS operations.
  • Applied strategies for initialization (init) and runtime processing (run).
  • Arrange DDS entities comparable to individuals, matters, readers, and writers.
  • Built-in DDS service into the VHAL software’s major loop.

4. Constructing and Deploying the Utility

  • Constructed the VHAL software and deployed it to the Android system.
  • Ensured right permissions and efficiently began the VHAL service.

By following these steps, you may leverage DDS for environment friendly, scalable, and dependable communication in automotive programs, enhancing HVAC programs’ management and monitoring capabilities in Android Automotive environments. This integration showcases the potential of DDS in automotive purposes, offering a sturdy framework for knowledge trade throughout completely different elements and companies.