Skip to content

Commit

Permalink
[#14] Addressed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
RaviprasadBS authored and SebastianSchildt committed Feb 5, 2025
1 parent 9323d72 commit 473760f
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 26 deletions.
2 changes: 1 addition & 1 deletion can-protocol-adapter/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion can-protocol-adapter/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ RELEASE="$2"

# Run cargo clippy with -D warnings
echo "Running cargo clippy..."
cargo clippy -- -D warnings 2>&1 | tee $CLIPPY_LOG
cargo clippy -- -W warnings -D warnings 2>&1 | tee $CLIPPY_LOG
if [ $? -ne 0 ]; then
echo "Clippy failed! Check $CLIPPY_LOG for details."
exit 1
Expand Down
3 changes: 2 additions & 1 deletion can-protocol-adapter/doc/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ The CAN ID used for receiving messages.

### socket_can_type:
Specifies the socket type for CAN communication, set to "SOCK_DGRAM", which is typical for datagram-based communication.
For more information on the SocketCAN API and its parameters, please refer to the official documentation [here](https://crates.io/crates/socketcan)

### socket_can_protocol:
Defines the protocol for CAN communication. The default is "CAN_ISOTP", which refers to the ISO-15765 standard for transport protocols, used to handle large messages across the CAN bus.
Expand All @@ -68,7 +69,7 @@ This section defines the list of parameter requests (PIDs) that the system will
"interval_ms": 500,
"dbc_signal_name": "S01PID0D_VehicleSpeed",
"vss_signal": {
"signal_name": "Vehicle.CAN.Speed",
"signal_name": "Vehicle.OBD.Speed",
"datatype": "float",
"unit": "km/h"
}
Expand Down
2 changes: 1 addition & 1 deletion can-protocol-adapter/doc/v0.1.0-initial-version.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

- JSON based user configuration for CAN interfaces, requests/responses and VSS to PID mapping.
- Supports socket-can and ISOTP (ISO 15765-2) standards.
- CAN frame decoding using use-defined DBC files.
- CAN frame decoding using user-defined DBC files.
- User defined VSS datapoint registration and publish.
- Supports kuksa.val.v1.VAL gRPC service interface.

Expand Down
2 changes: 1 addition & 1 deletion can-protocol-adapter/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ members = [
]

[workspace.dependencies]
databroker-proto = { path = "../submodules/kuksa-databroker/databroker-proto/databroker-proto" }
databroker-proto = { path = "../submodules/kuksa-databroker/databroker-proto" }
# prost has no features
prost = "0.11"
# prost-types has no features
Expand Down
16 changes: 8 additions & 8 deletions can-protocol-adapter/src/can/comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
********************************************************************************/
use super::decoder;
use super::socket;
use crate::kuksa_feeder::feeder::Feeder;
use crate::kuksa_provider::provider::Provider;
use crate::time::Instant;
use crate::utils::adapter_config::AdapterConfig;
use log::{debug, error, trace, warn};
Expand Down Expand Up @@ -108,7 +108,7 @@ pub async fn send_can_data(
pub async fn receive_can_data(
socket: Arc<Mutex<socket::Socket>>,
adapter_config: Arc<AdapterConfig>,
feeder: Arc<Mutex<Feeder>>,
provider: Arc<Mutex<Provider>>,
decoder: Arc<Mutex<decoder::Decoder>>,
mut res_rx: mpsc::Receiver<usize>,
res_tx: mpsc::Sender<bool>,
Expand All @@ -124,7 +124,7 @@ pub async fn receive_can_data(
let delay_duration = Duration::from_millis(entry.response_timeout_ms as u64);
// Sleep for the configured response timeout to allow the CAN response to arrive.
sleep(delay_duration).await;
//Lock the socket mutex for exclusive access and read data from the socket.
//Lock the socket mutex for exclusive access and read data from the socket.
let mut socket_lock = socket.lock().await;
let (notify, data) = match socket_lock.read_socket() {
// Define data outside the match arm.
Expand Down Expand Up @@ -166,14 +166,14 @@ pub async fn receive_can_data(
"Decoded value for signal {}: {}",
dbc_signal, decoded_value
);
// Set the decoded value in the feeder.
// Set the decoded value in the provider.
let vss_signal = entry.vss_signal.signal_name.clone();
let vss_datatype = entry.vss_signal.datatype.clone();
let _feeder_handle = tokio::spawn({
let feeder_instance = feeder.clone();
let _provider_handle = tokio::spawn({
let provider_instance = provider.clone();
async move {
let mut feeder = feeder_instance.lock().await;
if let Err(e) = feeder
let mut provider = provider_instance.lock().await;
if let Err(e) = provider
.set_datapoint_values(
&vss_signal,
decoded_value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
pub mod feeder;
pub mod provider;
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ use std::error::Error as StdError;
use databroker_proto::kuksa::val::{self as proto, v1::Datapoint};
use kuksa::KuksaClient;
use proto::v1;
/// The `Feeder` struct manages the connection to a Kuksa Data Broker
/// The `Provider` struct manages the connection to a Kuksa Data Broker
/// and provides methods to interact with it.
pub struct Feeder {
pub struct Provider {
client: Option<KuksaClient>,
broker_ip: String,
broker_port: String,
}

impl Feeder {
impl Provider {
pub fn new(broker_ip: String, broker_port: String) -> Self {
Self {
client: None,
Expand Down
18 changes: 9 additions & 9 deletions can-protocol-adapter/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ use tokio::sync::Mutex;
use tokio::time::{self};

mod can;
mod kuksa_feeder;
mod kuksa_provider;
mod utils;

use can::comm;
use can::decoder::Decoder;
use kuksa_feeder::feeder::Feeder;
use kuksa_provider::provider::Provider;
use utils::adapter_config::AdapterConfig;
use utils::adapter_utils;

Expand Down Expand Up @@ -63,9 +63,9 @@ async fn main() -> Result<(), Box<dyn Error>> {
let broker_ip = adapter_config.general_config.broker_ip.clone();
let broker_port = adapter_config.general_config.broker_port.clone();

// Create a new Feeder instance and connect to the data broker.
let mut feeder = Feeder::new(broker_ip.clone(), broker_port.clone());
match feeder.connect_to_databroker().await {
// Create a new Provider instance and connect to the data broker.
let mut provider = Provider::new(broker_ip.clone(), broker_port.clone());
match provider.connect_to_databroker().await {
Ok(_) => {
debug!(
"Successfully connected to the databroker to {}:{}",
Expand Down Expand Up @@ -96,7 +96,7 @@ async fn main() -> Result<(), Box<dyn Error>> {

// Register the user defined datapoints with the data broker.
let datapoints = adapter_utils::datapoints_from_config(&adapter_config);
match feeder.register_datapoints(datapoints).await {
match provider.register_datapoints(datapoints).await {
Ok(_) => {
info!("Successfully registered datapoints.");
}
Expand All @@ -121,7 +121,7 @@ async fn main() -> Result<(), Box<dyn Error>> {

// Create shared resources using Arc and Mutex.
let shared_socket = Arc::new(Mutex::new(socket));
let shared_feeder = Arc::new(Mutex::new(feeder));
let shared_provider = Arc::new(Mutex::new(provider));
let shared_decoder = Arc::new(Mutex::new(decoder));
let adapter_config = Arc::new(adapter_config);

Expand All @@ -138,12 +138,12 @@ async fn main() -> Result<(), Box<dyn Error>> {
let receive_task_handle = tokio::spawn({
let socket_instance = Arc::clone(&shared_socket);
let adapter_config = Arc::clone(&adapter_config);
let feeder_instance = Arc::clone(&shared_feeder);
let provider_instance = Arc::clone(&shared_provider);
async move {
comm::receive_can_data(
socket_instance,
adapter_config,
feeder_instance,
provider_instance,
shared_decoder,
pid_rx,
res_tx,
Expand Down

0 comments on commit 473760f

Please sign in to comment.