Skip to content
Open
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
1 change: 1 addition & 0 deletions deployment/cpu/ec/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ cpu_def(
"//deployment/apps/logger_service:FileLoggerApp",
"//deployment/apps/prim_service:PrimerService",
"//deployment/mw/timestamp_mw:timestamp_service",

],
)

Expand Down
2 changes: 2 additions & 0 deletions deployment/mw/i2c/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ filegroup(
name = "instance",
srcs = [
"app_config.json",
"//deployment/system_definition/diag/jobs/i2c_service/i2c_write:i2c_Write_job",
"//deployment/system_definition/diag/jobs/i2c_service/i2c_read:i2c_Read_job",
Comment on lines +7 to +8
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIe żeby coś ale DiD natywnie wspiera write i read

],
visibility = ["//mw/i2c_service:__subpackages__"],
)
Expand Down
10 changes: 10 additions & 0 deletions deployment/mw/i2c/app_config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"include": [
"deployment/system_definition/diag/jobs/i2c_service/i2c_write/i2c_Write_did.json",
"deployment/system_definition/diag/jobs/i2c_service/i2c_read/i2c_Read_did.json"
],
"package": "srp.mw",
"adaptive_application": {
Expand Down Expand Up @@ -41,6 +43,14 @@
}
},
"provide": [
{
"name": "i2c_Write_did as i2c_Write_did",
"on": "diag"
},
{
"name": "i2c_Read_did as i2c_Read_did",
"on": "diag"
}
]
}
}
Expand Down
13 changes: 10 additions & 3 deletions mw/i2c_service/service/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@ i2c_drivers_deps = select({

cc_library(
name = "i2c_lib",
srcs = ["i2c_service.cpp"],
hdrs = ["i2c_service.h"],
srcs = ["i2c_service.cpp",
"i2c_mw_read.cpp"
],
hdrs = [
"i2c_service.h",
"i2c_mw_write.h",
"i2c_mw_read.h",
],
visibility = ["//mw/i2c_service:__subpackages__"],
deps = [
"//communication-core/sockets:socket_ipc",
"//mw/i2c_service/data:i2c_factory",
"@srp_platform//ara/exec:adaptive_application_lib",
"//core/common:condition_lib",
] + i2c_drivers_deps,
"@srp_platform//ara/diag:uds_lib",
] + i2c_drivers_deps,
)
34 changes: 34 additions & 0 deletions mw/i2c_service/service/i2c_mw_read.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "mw/i2c_service/service/i2c_mw_read.h"
#include "mw/i2c_service/service/i2c_service.h"

namespace srp {
namespace mw {

I2CMWREAD::I2CMWREAD(const ara::core::InstanceSpecifier &specifier, I2CService* service, std::shared_ptr<
core::i2c::II2CDriver> i2c_)
: ara::diag::GenericDiD{specifier}, i2c_service_(service), i2c_(i2c_) {}

ara::core::Result<void> I2CMWREAD::Write(const std::vector<uint8_t> &payload) noexcept {
if (payload.size() < 3 || !payload.size()%2) {
ara::log::LogInfo() << "Wrong payload size: " << payload.size();
return ara::diag::MakeErrorCode(ara::diag::UdsDiagErrc::kSubFunctionNotSupported);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return ara::diag::MakeErrorCode(ara::diag::UdsDiagErrc::kSubFunctionNotSupported);
return ara::diag::MakeErrorCode(ara::diag::UdsDiagErrc::kInvalidMessageLengthFormat);

}
if (this->i2c_->Ioctl(payload[0]) != core::ErrorCode::kOk) {
ara::log::LogInfo() << "Wrong Input for payload i2c read";
return {};
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return {};
return ara::diag::MakeErrorCode(ara::diag::UdsDiagErrc::kRequestSequenceError);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ten błąd tyczy się sytułacji ze w zlej kolejnosci przysyłasz dane powinien być bład o długości zapytania jest takie

}

ara::log::LogInfo() << "Receive diag write req, calling I2CService::WriteRead";
std::vector<uint8_t> vec(payload.begin() + 1, payload.end());
auto result = i2c_service_->WriteRead(vec, nullptr);

if (result == std::nullopt) {
ara::log::LogInfo() << "Wrong Input for i2c WriteRead";
return ara::diag::MakeErrorCode(ara::diag::UdsDiagErrc::kConditionsNotCorrect);
}

return {};
}
Comment on lines +11 to +31
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I jak mam odczytać co zwróciła funkcja? chyba metoda read powinna zwracac wynik ostatniej operacji?


} // namespace mw
} // namespace srp
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} // namespace srp
} // namespace srp

35 changes: 35 additions & 0 deletions mw/i2c_service/service/i2c_mw_read.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#ifndef MW_I2C_READ_I2C_READ_H_
#define MW_I2C_READ_I2C_READ_H_

#include <vector>
#include <memory>
#include "ara/log/log.h"
#include "core/i2c/i2c_driver.hpp"
#include "ara/diag/generic_data_identifier.h"
#include "ara/diag/uds_error_domain.h"

namespace srp {
namespace mw {

class I2CService;

class I2CMWREAD : public ara::diag::GenericDiD {
private:
srp::mw::I2CService* i2c_service_;
std::shared_ptr<core::i2c::II2CDriver> i2c_;
ara::core::Result<ara::diag::OperationOutput> Read() noexcept override {
return ara::diag::MakeErrorCode(ara::diag::UdsDiagErrc::kRequestOutOfRange);
}
Comment on lines +20 to +22
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ara::core::Result<ara::diag::OperationOutput> Read() noexcept override {
return ara::diag::MakeErrorCode(ara::diag::UdsDiagErrc::kRequestOutOfRange);
}
ara::core::Result<ara::diag::OperationOutput> Read() noexcept override;



ara::core::Result<void> Write(const std::vector<uint8_t> &payload) noexcept override;

public:
I2CMWREAD(const ara::core::InstanceSpecifier &specifier, I2CService* service,std::shared_ptr<
core::i2c::II2CDriver> i2c_);
};

} // namespace mw
} // namespace srp

#endif
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#endif
#endif

74 changes: 74 additions & 0 deletions mw/i2c_service/service/i2c_mw_write.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* @file i2c_mw_write.h
* @author Wiktor Laska
* @brief
* @version 0.1
* @date 2025-12-10
*
* @copyright Copyright (c) 2024
*
*/
#ifndef MW_I2C_READ_READ_I2C_READ_H_
#define MW_I2C_READ_READ_I2C_READ_H_
#include <string>
#include <vector>
#include <memory>
#include <sstream>
#include <unordered_map>
#include <bitset>
#include "ara/log/log.h"
#include "core/i2c/i2c_driver.hpp"
#include "ara/diag/generic_data_identifier.h"
#include "ara/diag/uds_error_domain.h"
#include "mw/i2c_service/service/i2c_service.h"
namespace srp {
namespace mw {


class I2CMWWRITE : public ara::diag::GenericDiD {
private:
std::shared_ptr<core::i2c::II2CDriver> i2c_;
/**
* @brief Callback for 0x22 UDS job (Read data by id) *optional
*
* @return DiagResponse
*/
ara::core::Result<ara::diag::OperationOutput> Read() noexcept override {
return ara::diag::MakeErrorCode(
ara::diag::UdsDiagErrc::kRequestOutOfRange);
}
Comment on lines +36 to +39
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ara::core::Result<ara::diag::OperationOutput> Read() noexcept override {
return ara::diag::MakeErrorCode(
ara::diag::UdsDiagErrc::kRequestOutOfRange);
}
ara::core::Result<ara::diag::OperationOutput> Read() noexcept override {
return ara::diag::MakeErrorCode(
ara::diag::UdsDiagErrc::kSubFunctionNotSupported);
}



ara::core::Result<void> Write(
const std::vector<uint8_t> &payload) noexcept override {
if (payload.size()%2 != 1 || payload.size() < 3) {
ara::log::LogWarn() << "Invalid payload size: " << payload.size();
return ara::diag::MakeErrorCode(
ara::diag::UdsDiagErrc::kSubFunctionNotSupported);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Czemu te kody błędów wyglądają jakby je czat losował na kole fortuny?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moja wina, uznałem że jest odpowiedni kod błędu, doczytam i poprawię na odpowiedni

}
ara::log::LogInfo() << "Receive diag write req for address:" << payload[0] << ", with size: "
<< (uint16_t)payload.size();
if (this->i2c_->Ioctl(payload[0]) != core::ErrorCode::kOk) {
ara::log::LogInfo() << "Wrong Input for payload i2c write";
return {};
}
Comment on lines +51 to +54
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Czemu błąd daje ten sam wynik jak powodzenie operacji?

std::vector<uint8_t> vec(payload.begin() + 1, payload.end());
if (this->i2c_->Write(vec) == core::ErrorCode::kOk) {
ara::log::LogInfo() << "Wrong Input for i2c Write";
return ara::diag::MakeErrorCode(
ara::diag::UdsDiagErrc::kSubFunctionNotSupported);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?? CHATGPT PLS GIVE ME RANDOM ERROR CODE

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

użyłem błędu z funkcji wyżej "by działało" co podałeś

}
return {};
}

public:
I2CMWWRITE(const ara::core::InstanceSpecifier &specifier, std::shared_ptr<
core::i2c::II2CDriver> i2c_d)
: ara::diag::GenericDiD{specifier}, i2c_(i2c_d) {
}
};

} // namespace mw
} // namespace srp

#endif
12 changes: 9 additions & 3 deletions mw/i2c_service/service/i2c_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ namespace {
const constexpr char* I2C_IPC_ADDR = "SRP.I2C";
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const constexpr char* I2C_IPC_ADDR = "SRP.I2C";
const constexpr char* I2C_IPC_ADDR = "SRP.I2C";
constexpr auto I2C_WRITE_DID_INSTANCE = "/srp/mw/i2cMWService/i2c_Write_did";
constexpr auto I2C_READ_DID_INSTANCE = "/srp/mw/i2cMWService/i2c_Read_did";

}
I2CService::I2CService():
i2c_logger_(ara::log::LoggingMenager::GetInstance()->CreateLogger("i2c", "", ara::log::LogLevel::kInfo)) {}

i2c_logger_(ara::log::LoggingMenager::GetInstance()->CreateLogger("i2c", "", ara::log::LogLevel::kInfo)),did_instance("/srp/mw/i2cMWService/i2c_Write_did"), read_instance("/srp/mw/i2cMWService/i2c_Read_did") {}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
i2c_logger_(ara::log::LoggingMenager::GetInstance()->CreateLogger("i2c", "", ara::log::LogLevel::kInfo)),did_instance("/srp/mw/i2cMWService/i2c_Write_did"), read_instance("/srp/mw/i2cMWService/i2c_Read_did") {}
i2c_logger_(ara::log::LoggingMenager::GetInstance()->CreateLogger("i2c", "", ara::log::LogLevel::kInfo)), did_instance(I2C_WRITE_DID_INSTANCE ), read_instance(I2C_READ_DID_INSTANCE) {}


core::ErrorCode I2CService::Init(std::shared_ptr<core::i2c::II2CDriver> i2c,
std::unique_ptr<srp::com::soc::ISocketStream> socket) {
Expand All @@ -42,7 +41,7 @@ std::optional<std::vector<uint8_t>> I2CService::ReadWrite(
i2c_logger_.LogWarn() << ("Invalid payload size");
return std::nullopt;
}
return i2c_->ReadWrite(payload[0], payload[1]);
return i2c_->ReadWrite(payload[0]);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

czemu? psuje to chyba wszystkie drivery do i2c.

Suggested change
return i2c_->ReadWrite(payload[0]);
return i2c_->ReadWrite(payload[0], payload[1]);

}
std::optional<std::vector<uint8_t>> I2CService::WriteRead(const std::vector<uint8_t> &payload,
std::shared_ptr<i2c::Header> headerPtr) {
Expand Down Expand Up @@ -119,6 +118,8 @@ std::vector<uint8_t> I2CService::RxCallback(const std::string& ip, const std::ui
int I2CService::Run(const std::stop_token& token) {
core::condition::wait(token);
this->sock_->StopRXThread();
pin_did_->StopOffer();
read_did_->StopOffer();
return core::ErrorCode::kOk;
}
int I2CService::Initialize(
Expand All @@ -136,6 +137,11 @@ int I2CService::Initialize(
this->sock_->SetRXCallback(std::bind(&I2CService::RxCallback, this, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3));
this->sock_->StartRXThread();

pin_did_ = std::make_unique<I2CMWWRITE>(this->did_instance, this->i2c_);
read_did_ = std::make_unique<I2CMWREAD>(this->read_instance, this, this->i2c_);
pin_did_->Offer();
read_did_->Offer();
return core::ErrorCode::kOk;
}

Expand Down
14 changes: 13 additions & 1 deletion mw/i2c_service/service/i2c_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
#include "ara/exec/adaptive_application.h"
#include "communication-core/sockets/stream_ipc_socket.h"
#include "core/i2c/i2c_driver.hpp"

#include "mw/i2c_service/service/i2c_mw_write.h"

#include "mw/i2c_service/service/i2c_mw_read.h"
#include "mw/i2c_service/data/header.h"
namespace srp {
namespace mw {
Expand All @@ -30,6 +34,14 @@ class I2CService final : public ara::exec::AdaptiveApplication {
std::unique_ptr<srp::com::soc::ISocketStream> sock_;

protected:
std::unique_ptr<I2CMWWRITE> pin_did_;
std::unique_ptr<I2CMWREAD> read_did_;
const ara::core::InstanceSpecifier did_instance;

const ara::core::InstanceSpecifier read_instance;



core::ErrorCode Init(
std::shared_ptr<core::i2c::II2CDriver> i2c,
std::unique_ptr<srp::com::soc::ISocketStream> socket);
Expand All @@ -45,7 +57,7 @@ class I2CService final : public ara::exec::AdaptiveApplication {
std::vector<uint8_t> ActionLogic(
const std::shared_ptr<srp::i2c::Header> headerPtr,
std::optional<std::vector<uint8_t>> payload);

friend class I2CMWREAD;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nie prościej było używać i2c_controllera?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

możliwe, choć nie wiedziałem że jest taka opcja

public:
int Run(const std::stop_token& token) override;
int Initialize(const std::map<ara::core::StringView, ara::core::StringView>
Expand Down
Loading