Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ Cargo.lock
*.log
compile_commands.json

# Bazel
bazel-*

# HTML
*.html
*.htm
Expand Down
51 changes: 51 additions & 0 deletions score/mw/diag.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/********************************************************************************
* Copyright (c) 2025 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

#ifndef SCORE_MW_DIAG_H
#define SCORE_MW_DIAG_H

/// @file diag.h
/// @brief Main diagnostic API header
/// @details Include this header to access the complete diagnostic API for both UDS and SOVD

#include "diag/types.h"
#include "diag/sovd.h"
#include "diag/uds.h"

/// @namespace mw::diag
/// @brief Root namespace for diagnostic middleware
///
/// This namespace contains the abstraction layer API for diagnostic services,
/// supporting both UDS (Unified Diagnostic Services) and SOVD (Service-Oriented
/// Vehicle Diagnostics) protocols.
///
/// @namespace mw::diag::uds
/// @brief UDS-specific diagnostic services
///
/// Contains interfaces and utilities for implementing UDS diagnostic services
/// according to ISO 14229-1, including:
/// - Read/Write Data by Identifier (0x22/0x2E)
/// - Routine Control (0x31)
/// - Generic UDS service handling
/// - Serialization helpers
///
/// @namespace mw::diag::sovd
/// @brief SOVD-specific diagnostic services
///
/// Contains interfaces for implementing SOVD diagnostic services, including:
/// - Data resources (read-only, writable, and read-write)
/// - Operations (with various invocation policies)
/// - Diagnostic entities and modes
/// - JSON-based request/response handling

#endif // SCORE_MW_DIAG_H
35 changes: 35 additions & 0 deletions score/mw/diag/diagnostic_services_collection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/********************************************************************************
* Copyright (c) 2025 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

#ifndef SCORE_MW_DIAG_DIAGNOSTIC_SERVICES_COLLECTION_H
#define SCORE_MW_DIAG_DIAGNOSTIC_SERVICES_COLLECTION_H

namespace mw::diag {

/// @brief Abstract base class for diagnostic services collections
/// @details Provides lifetime control for contained services
class DiagnosticServicesCollection {
public:
virtual ~DiagnosticServicesCollection() = default;

protected:
DiagnosticServicesCollection() = default;
DiagnosticServicesCollection(const DiagnosticServicesCollection&) = delete;
DiagnosticServicesCollection& operator=(const DiagnosticServicesCollection&) = delete;
DiagnosticServicesCollection(DiagnosticServicesCollection&&) = default;
DiagnosticServicesCollection& operator=(DiagnosticServicesCollection&&) = default;
};

} // namespace mw::diag

#endif // SCORE_MW_DIAG_DIAGNOSTIC_SERVICES_COLLECTION_H
29 changes: 29 additions & 0 deletions score/mw/diag/sovd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/********************************************************************************
* Copyright (c) 2025 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

#ifndef SCORE_MW_DIAG_SOVD_H
#define SCORE_MW_DIAG_SOVD_H

/// @file sovd.h
/// @brief Convenience header for SOVD diagnostic API
/// @details Include this header to access all SOVD-related types and interfaces

#include "sovd/data_resource.h"
#include "sovd/diagnostic_entity.h"
#include "sovd/diagnostic_reply.h"
#include "sovd/diagnostic_request.h"
#include "sovd/diagnostic_services_collection.h"
#include "sovd/operation.h"
#include "sovd/types.h"

#endif // SCORE_MW_DIAG_SOVD_H
73 changes: 73 additions & 0 deletions score/mw/diag/sovd/data_resource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/********************************************************************************
* Copyright (c) 2025 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

#ifndef SCORE_MW_DIAG_SOVD_DATA_RESOURCE_H
#define SCORE_MW_DIAG_SOVD_DATA_RESOURCE_H

#include "diagnostic_reply.h"
#include "diagnostic_request.h"
#include "types.h"

namespace mw::diag::sovd {

/// @brief Interface for read-only SOVD data resources
class ReadOnlyDataResource {
public:
virtual ~ReadOnlyDataResource() = default;

/// @brief Get the current value of the data resource
/// @return Result containing JSON data reply or error
virtual Result<JsonDataReply> Get() = 0;

protected:
ReadOnlyDataResource() = default;
ReadOnlyDataResource(const ReadOnlyDataResource&) = delete;
ReadOnlyDataResource& operator=(const ReadOnlyDataResource&) = delete;
ReadOnlyDataResource(ReadOnlyDataResource&&) = default;
ReadOnlyDataResource& operator=(ReadOnlyDataResource&&) = default;
};

/// @brief Interface for writable SOVD data resources
class WritableDataResource {
public:
virtual ~WritableDataResource() = default;

/// @brief Update the value of the data resource
/// @param request The diagnostic request containing the new value
/// @return Result indicating success or error
virtual Result<void> Put(const DiagnosticRequest& request) = 0;

protected:
WritableDataResource() = default;
WritableDataResource(const WritableDataResource&) = delete;
WritableDataResource& operator=(const WritableDataResource&) = delete;
WritableDataResource(WritableDataResource&&) = default;
WritableDataResource& operator=(WritableDataResource&&) = default;
};

/// @brief Interface for SOVD data resources supporting both read and write
class DataResource : public ReadOnlyDataResource, public WritableDataResource {
public:
~DataResource() override = default;

protected:
DataResource() = default;
DataResource(const DataResource&) = delete;
DataResource& operator=(const DataResource&) = delete;
DataResource(DataResource&&) = default;
DataResource& operator=(DataResource&&) = default;
};

} // namespace mw::diag::sovd

#endif // SCORE_MW_DIAG_SOVD_DATA_RESOURCE_H
115 changes: 115 additions & 0 deletions score/mw/diag/sovd/data_resource_mock.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/********************************************************************************
* Copyright (c) 2025 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

#ifndef SCORE_MW_DIAG_SOVD_DATA_RESOURCE_MOCK_H
#define SCORE_MW_DIAG_SOVD_DATA_RESOURCE_MOCK_H

#include "data_resource.h"
#include <string>

namespace mw::diag::sovd {

/// @brief Mock implementation of ReadOnlyDataResource for testing
class ReadOnlyDataResourceMock : public ReadOnlyDataResource {
public:
/// @brief Construct mock read-only data resource
/// @param id Resource identifier
explicit ReadOnlyDataResourceMock(std::pmr::string id)
: resource_id_(std::move(id)) {}

/// @brief Get data resource value
/// @return Result containing JSON data reply
Result<JsonDataReply> Get() override {
JsonDataReply reply;
// Mock: return sample JSON data
// reply.data_ would contain: {"id": "resource_id", "value": 42}

return Result<JsonDataReply>(reply);
}

private:
std::pmr::string resource_id_;
};

/// @brief Mock implementation of WritableDataResource for testing
class WritableDataResourceMock : public WritableDataResource {
public:
/// @brief Construct mock writable data resource
/// @param id Resource identifier
explicit WritableDataResourceMock(std::pmr::string id)
: resource_id_(std::move(id)) {}

/// @brief Update data resource value
/// @param request Diagnostic request with new data
/// @return Result indicating success or error
Result<void> Put(const DiagnosticRequest& request) override {
// Mock: validate and store request data
if (request.data.empty()) {
Error err;
err.sovd_error = "invalid_data";
err.vendor_error = "DATA_001";
err.vendor_message = "Request data is empty";
return Result<void>(err);
}

last_request_data_ = request.data.json_data;

return Result<void>();
}

/// @brief Get last request data (for testing)
const std::pmr::string& GetLastRequestData() const { return last_request_data_; }

private:
std::pmr::string resource_id_;
std::pmr::string last_request_data_;
};

/// @brief Mock implementation of DataResource (read + write) for testing
class DataResourceMock : public DataResource {
public:
/// @brief Construct mock data resource
/// @param id Resource identifier
explicit DataResourceMock(std::pmr::string id)
: resource_id_(std::move(id)),
stored_value_(42) {} // Default value

/// @brief Get data resource value
/// @return Result containing JSON data reply
Result<JsonDataReply> Get() override {
JsonDataReply reply;
// Mock: return current stored value as JSON
// reply.data_ would contain: {"id": "resource_id", "value": stored_value_}

return Result<JsonDataReply>(reply);
}

/// @brief Update data resource value
/// @param request Diagnostic request with new data
/// @return Result indicating success or error
Result<void> Put([[maybe_unused]] const DiagnosticRequest& request) override {
// Mock: parse and update stored value
// In real implementation, would parse JSON from request.data
stored_value_++;

return Result<void>();
}

private:
std::pmr::string resource_id_;
int stored_value_;
};

} // namespace mw::diag::sovd

#endif // SCORE_MW_DIAG_SOVD_DATA_RESOURCE_MOCK_H
Loading