-
Notifications
You must be signed in to change notification settings - Fork 0
Implement serial communication functions and refactor existing code #19
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
Open
Katze719
wants to merge
9
commits into
main
Choose a base branch
from
upgrade/cpp-core-v2-linux
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b3946e5
Implement serial communication functions and refactor existing code
Katze719 79933db
refactor: Add tcflush calls to serial configuration functions and imp…
Katze719 98fc8f5
chore: Upgrade GCC version to 16 and update CMake configuration in wo…
Katze719 ef20ef6
refactor: Update CI workflows to enhance code coverage and Deno integ…
Katze719 d462fa5
fix: Add sudo to package installation commands and skip tests in GitH…
Katze719 98b59bd
fix: max arg length, use temp file instead
Mqxx 5e6c9cb
fix: Specify gcov tool for lcov capture in code coverage workflow
Katze719 6f8f860
refactor: Remove outdated code coverage workflow for C++
Katze719 ee3bf67
refactor: comments
Katze719 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
|
Mqxx marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| #pragma once | ||
|
|
||
| #include <cpp_core/error_callback.h> | ||
| #include <cpp_core/error_handling.hpp> | ||
| #include <cpp_core/serial_config.hpp> | ||
| #include <cpp_core/status_code.h> | ||
| #include <cpp_core/validation.hpp> | ||
|
|
||
| #include <atomic> | ||
| #include <cerrno> | ||
| #include <string_view> | ||
| #include <system_error> | ||
|
|
||
| namespace cpp_bindings_linux::detail | ||
| { | ||
| using IoCallbackT = void (*)(int); | ||
| using StatusCodeValue = cpp_core::StatusCodeValue; | ||
| using cpp_core::FlowControl; | ||
| using cpp_core::Parity; | ||
| using cpp_core::StatusCode; | ||
| using cpp_core::StopBits; | ||
|
|
||
| inline std::atomic<ErrorCallbackT> g_error_callback{nullptr}; | ||
|
|
||
| template <typename Code> constexpr auto statusValue(Code code) -> StatusCodeValue | ||
| { | ||
| return static_cast<StatusCodeValue>(code); | ||
| } | ||
|
|
||
| inline auto effectiveErrorCallback(ErrorCallbackT error_callback) -> ErrorCallbackT | ||
| { | ||
| return error_callback != nullptr ? error_callback : g_error_callback.load(std::memory_order_acquire); | ||
| } | ||
|
|
||
| inline auto defaultValidationMessage(StatusCodeValue code) -> std::string_view | ||
| { | ||
| switch (code) | ||
| { | ||
| case static_cast<StatusCodeValue>(StatusCode::Configuration::kSetBaudrateError): | ||
| return "Invalid baudrate: must be >= 300"; | ||
| case static_cast<StatusCodeValue>(StatusCode::Configuration::kSetDataBitsError): | ||
| return "Invalid data bits: must be 5-8"; | ||
| case static_cast<StatusCodeValue>(StatusCode::Configuration::kSetParityError): | ||
| return "Invalid parity: must be 0, 1, or 2"; | ||
| case static_cast<StatusCodeValue>(StatusCode::Configuration::kSetStopBitsError): | ||
| return "Invalid stop bits: must be 0, 1, or 2"; | ||
| case static_cast<StatusCodeValue>(StatusCode::Configuration::kSetFlowControlError): | ||
| return "Invalid flow control mode: must be 0, 1, or 2"; | ||
| default: | ||
| return "Invalid serial setting"; | ||
| } | ||
| } | ||
|
|
||
| template <typename Ret> | ||
|
Member
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. What is |
||
| inline auto failMsg(ErrorCallbackT error_callback, StatusCodeValue code, std::string_view message) -> Ret | ||
| { | ||
| return cpp_core::failMsg<Ret>(effectiveErrorCallback(error_callback), code, message); | ||
| } | ||
|
|
||
| template <typename Ret> | ||
| inline auto failErrno(ErrorCallbackT error_callback, StatusCodeValue code) -> Ret | ||
| { | ||
| return cpp_core::failMsg<Ret>(effectiveErrorCallback(error_callback), code, | ||
| std::error_code(errno, std::generic_category()).message()); | ||
| } | ||
|
|
||
| template <typename Ret> inline auto failValidation(ErrorCallbackT error_callback, StatusCodeValue code) -> Ret | ||
| { | ||
| return failMsg<Ret>(error_callback, code, defaultValidationMessage(code)); | ||
| } | ||
|
|
||
| } // namespace cpp_bindings_linux::detail | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why the change? Isn't this just the test file?