Home
[RDK Central Wiki]
CMF
[Code Releases]
Let's introduce a ccsponrust application as a PoC evaluating a capability of interacting with CPE Data model via rbus broker.
Here's a list of basic features of the application:
The implementation showcases the flexibility and capability of Rust applications in managing and interacting with the RDKB data model, highlighting Rust's potential for developing robust and efficient system-level applications.
The project of ccsponrust could be found on: ccsponrust-main.tar.bz2
To satisfy the rbus libraries dependency in the project, a rbus_stub library is available.
This stub library includes all the functions used in ccsponrust and doesn't require dozens of rbus libraries from the RDKB image for specific architectures at the compilation stage.
This rbus_stub could be skipped if a compiler has an access to all the libraries. And new path should be set in build.rs file of the project. It is helpful then the project is a part of Yocto recipe
//build.rs
fn main() {
println!("cargo:rustc-link-search=native=/src/rbus_stub");
println!("cargo:rustc-link-lib=dylib=rbus");
}
In order to make the development easier, let's create a Dockerfile with steps to create a cross-compile environment to build Rust apps for RPi and RDK-B.
Create docker file from base image:
Docker file content:
# Use your base image
FROM javrv/ubuntu18_04_rdkb_dunfell:v1
# Install curl, Rust, and add the ARM target
RUN apt-get update && apt-get install -y curl gcc-arm-linux-gnueabihf
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"
RUN rustup target add armv7-unknown-linux-gnueabihf
# Setup cross-compilation configuration
RUN echo "[target.armv7-unknown-linux-gnueabihf]\nlinker = \"arm-linux-gnueabihf-gcc\"" > /root/.cargo/config
WORKDIR /src
Command to create the image from Docker
docker build -t rust_rpi_rdkb_image:v1 .
Run docker image from the ccsponrust project folder. The project should be cloned from git repository
docker run -it --mount type=bind,source="$(pwd)",target=/src --rm rust_rpi_rdkb_image:v1 /bin/bash
Compile the project
cargo build --target=armv7-unknown-linux-gnueabihf --release
after the application will be built, should the strip command be ran to decrease the size of the application. The rust doesn’t do it by default.
arm-linux-gnueabihf-strip target/armv7-unknown-linux-gnueabihf/release/ccsponrust
And the application is ready for use on RPI.
Please see previous section on how to create an SD card for your RPi.
Copy the application to RPI from the application release folder:
root@259cf4027f4f:/src# cd ./target/armv7-unknown-linux-gnueabihf/release/
root@259cf4027f4f:/src/target/armv7-unknown-linux-gnueabihf/release# ll
total 424
drwxr-xr-x 7 root root 4096 Sep 13 11:52 ./
drwxr-xr-x 3 root root 4096 Sep 13 11:52 ../
-rw-r--r-- 1 root root 0 Sep 13 11:52 .cargo-lock
drwxr-xr-x 6 root root 4096 Sep 13 11:52 .fingerprint/
drwxr-xr-x 4 root root 4096 Sep 13 11:52 build/
-rwxr-xr-x 2 root root 397736 Sep 13 11:52 ccsponrust*
-rw-r--r-- 1 root root 93 Sep 13 11:52 ccsponrust.d
drwxr-xr-x 2 root root 4096 Sep 13 11:52 deps/
drwxr-xr-x 2 root root 4096 Sep 13 11:52 examples/
drwxr-xr-x 2 root root 4096 Sep 13 11:52 incremental/
root@259cf4027f4f:/src/target/armv7-unknown-linux-gnueabihf/release# scp ./ccsponrust root@<RPI WAN IP>:/usr/bin/
The authenticity of host '<RPI WAN IP> (<RPI WAN IP>)' can't be established.
ECDSA key fingerprint is SHA256:x8mqAS8tNWVGTcTSQd6JoRTS3xFDQa0iKIogCallOtk.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '<RPI WAN IP>' (ECDSA) to the list of known hosts.
root@<RPI WAN IP>'s password: <Type here root password if any>
ccsponrust
Let's start the application on RPi now.
The aplication is relying on librbus.so library.
At first start most probably it will fail with:
root@RaspberryPi-Gateway:~# ccsponrust
ccsponrust: error while loading shared libraries: librbus.so: cannot open shared object file: No such file or directory
root@RaspberryPi-Gateway:~#
Create as symlink to the existing rbus lib.
root@RaspberryPi-Gateway:~# ls -la /usr/lib/librbus.so*
lrwxrwxrwx 1 root root 17 Sep 12 14:47 /usr/lib/librbus.so.0 -> librbus.so.2.0.11
-rwxr-xr-x 1 root root 138548 Sep 12 14:47 /usr/lib/librbus.so.2.0.11
root@RaspberryPi-Gateway:~#
root@RaspberryPi-Gateway:~#
root@RaspberryPi-Gateway:~# ln -s /usr/lib/librbus.so.2.0.11 /usr/lib/librbus.so
root@RaspberryPi-Gateway:~#
Start ccsponrust on Raspberry Pi.
Usage:
ccsponrust --command get|set|subscribe --component <component> --name <name> [--value <value>] [--timeout <timeout>]
Example:
ccsponrust --command get --component gl_component --name Device.WiFi.SSID.1.SSID
Example:
ccsponrust --command set --component gl_component --name Device.WiFi.SSID.1.SSID --value test_string
Example:
ccsponrust --command subscribe --component gl_component --name Device.WiFi.SSID.1.SSID --timeout 3600
root@RaspberryPi-Gateway:~# ccsponrust --command set --component gl_component --name Device.ManagementServer.URL --value https://new-acswg.g.comcast.net
Start executing command: set; component: gl_component; name: Device.ManagementServer.URL
open_rbus result: ok
value: https://new-acswg.g.comcast.net
set_rbus_value result: ok
close_rbus result: ok
root@RaspberryPi-Gateway:~# ccsponrust --command get --component gl_component --name Device.ManagementServer.URL
Start executing command: get; component: gl_component; name: Device.ManagementServer.URL
open_rbus result: ok
get_rbus_value result: ok
value: https://new-acswg.g.comcast.net/cwmpWeb/DigestCPEMgt?target=/CPEMgt
close_rbus result: ok
root@RaspberryPi-Gateway:~# ccsponrust --command subscribe --component gl_component --name Device.WiFi.Radio.2.Channel --timeout 36000
Start executing command: subscribe; component: gl_component; name: Device.WiFi.Radio.2.Channel
open_rbus result: ok
-----------Old Value:--------------
value: 44
-----------New Value:--------------
value: 157
--------------------------------
-----------Old Value:--------------
value: 157
-----------New Value:--------------
value: 48
--------------------------------
^C
root@RaspberryPi-Gateway:~#
or
root@RaspberryPi-Gateway:~# ccsponrust --command subscribe --component gl_component --name Device.WiFi.Radio.2.Channel --timeout 36000
Start executing command: subscribe; component: gl_component; name: Device.WiFi.Radio.2.Channel
open_rbus result: ok
-----------Old Value:--------------
value: 44
-----------New Value:--------------
value: 157
--------------------------------
-----------Old Value:--------------
value: 157
-----------New Value:--------------
value: 48
--------------------------------
^C
root@RaspberryPi-Gateway:~#
After starting subscribtion enter RDKB Web UI and change related values for 5GHz Wi-Fi AP: SSID or Channel.
A notification after applying on the UI will be caught by ccsponrust application.
Note! Application can change only parameters available for reading and writing for R-Bus from RDKB middleware side.
Some values of data model like Device.WiFi.SSID.1.SSID doesn’t support set in data model, and it is not possible to set new values for this parameter using rbus.