-
Notifications
You must be signed in to change notification settings - Fork 3
Func did for i2c #290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Func did for i2c #290
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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); | ||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| } | ||||||||
| if (this->i2c_->Ioctl(payload[0]) != core::ErrorCode::kOk) { | ||||||||
| ara::log::LogInfo() << "Wrong Input for payload i2c read"; | ||||||||
| return {}; | ||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| 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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
|
||||||||||
|
|
||||||||||
| 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 | ||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| 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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| 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); | ||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ?? CHATGPT PLS GIVE ME RANDOM ERROR CODE
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -22,8 +22,7 @@ namespace { | |||||||||
| const constexpr char* I2C_IPC_ADDR = "SRP.I2C"; | ||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| } | ||||||||||
| 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") {} | ||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
|
||||||||||
| core::ErrorCode I2CService::Init(std::shared_ptr<core::i2c::II2CDriver> i2c, | ||||||||||
| std::unique_ptr<srp::com::soc::ISocketStream> socket) { | ||||||||||
|
|
@@ -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]); | ||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. czemu? psuje to chyba wszystkie drivery do i2c.
Suggested change
|
||||||||||
| } | ||||||||||
| std::optional<std::vector<uint8_t>> I2CService::WriteRead(const std::vector<uint8_t> &payload, | ||||||||||
| std::shared_ptr<i2c::Header> headerPtr) { | ||||||||||
|
|
@@ -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( | ||||||||||
|
|
@@ -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; | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 { | ||
|
|
@@ -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); | ||
|
|
@@ -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; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nie prościej było używać i2c_controllera?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
|
|
||
There was a problem hiding this comment.
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