-
Notifications
You must be signed in to change notification settings - Fork 6
Cc 17 windows systec vendor #102
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
parasxos
wants to merge
13
commits into
master
Choose a base branch
from
CC-17_Windows-systec-vendor
base: master
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
13 commits
Select commit
Hold shift + click to select a range
2030697
Outline of Systec implementation for Windows
jsouter c585ba2
replace Windows specific thread calls with std library calls
jsouter aa7fe5d
check return codes of open and close on systec reconnect
jsouter 28f82f0
add get_module_handle() method
jsouter 0cd080d
split up systec close logic, deinit hardware on failed open
jsouter 6263988
Implement comments from review
jsouter 9dbbfa6
Use std::optional for systec handles, avoid use of [] accessor
jsouter d00dd6a
Improve logging for error messages
jsouter f20b8f9
add config option to deinit both channels when vendor_close called on…
jsouter 554c092
Add WIP systec test for pcaticswin11
jsouter f1e1ce9
Lint fixes for CI
jsouter 3a008aa
build systec on windows by default
jsouter 25baf24
remove close-both-channels option
jsouter 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,13 +29,24 @@ set(VENDOR_SOURCES | |
| src/main/CanVendorAnagate.cpp | ||
| ) | ||
|
|
||
| if (NOT DEFINED CANMODULE_BUILD_SYSTEC_WINDOWS) | ||
| set(CANMODULE_BUILD_SYSTEC_WINDOWS ON) | ||
| endif() | ||
|
|
||
| if (UNIX) | ||
| include(cmake/libsocketcan.cmake) | ||
| include_directories(${LIBSOCKETCAN_INCLUDE_DIR}) | ||
| list(APPEND VENDOR_SOURCES | ||
| src/main/CanVendorSocketCan.cpp | ||
| src/main/CanVendorSocketCanSystec.cpp | ||
| ) | ||
| elseif ("${CANMODULE_BUILD_SYSTEC_WINDOWS}" STREQUAL ON) | ||
| include(cmake/systec.cmake) | ||
| include_directories(${SYSTEC_PATH_HEADERS}) | ||
| list(APPEND VENDOR_SOURCES | ||
| src/main/CanVendorSystec.cpp | ||
| ) | ||
| add_compile_definitions(CANMODULE_BUILD_SYSTEC_WINDOWS) | ||
| endif() | ||
|
|
||
| if (NOT DEFINED CAN_MODULE_MAIN_ONLY) | ||
|
|
@@ -63,11 +74,18 @@ if (UNIX) | |
| libsocketcan | ||
| ) | ||
| else() | ||
| target_include_directories(CanModuleMain PUBLIC ${systec_BINARY_DIR}/Examples/Include) | ||
| target_link_libraries(CanModuleMain PUBLIC | ||
| ${anagate_SOURCE_DIR}/Win64/AnaGateCanDll64.lib | ||
| ) | ||
| ${anagate_SOURCE_DIR}/Win64/AnaGateCanDll64.lib) | ||
| file(COPY "${anagate_SOURCE_DIR}/Win64/AnaGateCan64.dll" | ||
| DESTINATION "${CMAKE_BINARY_DIR}/Release") | ||
|
|
||
| if ("${CANMODULE_BUILD_SYSTEC_WINDOWS}" STREQUAL ON) | ||
|
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. Is systec planned to be supported also in the power supplies and/or several OPC Servers? or is it only a single-case? The answer will tell us if having a variable to activate that part of the build is good or bad idea. |
||
| target_link_libraries(CanModuleMain PUBLIC | ||
| ${systec_BINARY_DIR}/Examples/lib/USBCAN64.lib) | ||
| file(COPY "${systec_BINARY_DIR}/Examples/lib/USBCAN64.dll" | ||
| DESTINATION "${CMAKE_BINARY_DIR}/Release") | ||
| endif() | ||
| endif() | ||
|
|
||
| if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") | ||
|
|
||
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,40 @@ | ||
| include(FetchContent) | ||
|
|
||
| if(NOT DEFINED SYSTEC_LIBRARY) | ||
| set(SYSTEC_LIBRARY "https://www.systec-electronic.com/media/default/Redakteur/produkte/Interfaces_Gateways/sysWORXX_USB_CANmodul_Series/Downloads/SO-387.zip") | ||
| endif() | ||
|
|
||
| set(SYSTEC_FETCHCONTENT_ARGS | ||
| URL "${SYSTEC_LIBRARY}" | ||
| DOWNLOAD_EXTRACT_TIMESTAMP True | ||
| ) | ||
|
|
||
| if(EXISTS "${SYSTEC_LIBRARY}") | ||
| message(STATUS "Using local Systec archive: ${SYSTEC_LIBRARY}") | ||
| elseif(SYSTEC_LIBRARY MATCHES "^https?://") | ||
| message(STATUS "Downloading Systec archive: ${SYSTEC_LIBRARY}") | ||
| else() | ||
| message(FATAL_ERROR "SYSTEC_LIBRARY must be an existing local archive or an http(s) URL. Got: ${SYSTEC_LIBRARY}") | ||
| endif() | ||
|
|
||
| FetchContent_Declare( | ||
| Systec | ||
| ${SYSTEC_FETCHCONTENT_ARGS} | ||
| ) | ||
|
|
||
| FetchContent_MakeAvailable(Systec) | ||
|
|
||
| execute_process( | ||
| COMMAND ${systec_SOURCE_DIR}/SO-387.exe /SP- /VERYSILENT /DIR=${systec_BINARY_DIR} /LOG=${systec_SOURCE_DIR}/build.log | ||
| WORKING_DIRECTORY ${systec_SOURCE_DIR} | ||
| RESULT_VARIABLE systec_build_result | ||
| OUTPUT_VARIABLE systec_build_output | ||
| ) | ||
|
|
||
| if(NOT systec_build_result EQUAL 0) | ||
| message(FATAL_ERROR "Error installing USB-CANmodul Utility Disk: ${systec_build_output}") | ||
| endif() | ||
|
|
||
| if (WIN32) | ||
| add_compile_definitions(WIN32) | ||
| endif() |
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,74 @@ | ||
| #ifndef SRC_INCLUDE_CANVENDORSYSTEC_H_ | ||
| #define SRC_INCLUDE_CANVENDORSYSTEC_H_ | ||
|
|
||
| #include <Winsock2.h> | ||
| #include <tchar.h> | ||
| #include <usbcan32.h> | ||
| #include <windows.h> | ||
|
|
||
| #include <atomic> | ||
| #include <cstdint> | ||
| #include <map> | ||
| #include <memory> | ||
| #include <mutex> //NOLINT | ||
| #include <optional> | ||
| #include <string> | ||
| #include <thread> | ||
| #include <unordered_map> | ||
|
|
||
| #include "CanDevice.h" | ||
| #include "CanDiagnostics.h" | ||
| #include "CanVendorLoopback.h" | ||
|
|
||
| /** | ||
| * @struct CanVendorSystec | ||
| * @brief Represents a specific implementation of a CanDevice for Systec devices | ||
| * on Windows utilising libraries from USB-CANmodul Utility Disk. | ||
| * | ||
| * This struct provides methods for opening, closing, sending, and receiving CAN | ||
| * frames using the Systec CAN-over-USB interface. It also provides diagnostics | ||
| * information. | ||
| */ | ||
| struct CanVendorSystec : CanDevice { | ||
| explicit CanVendorSystec(const CanDeviceArguments& args); | ||
| ~CanVendorSystec() { vendor_close(); } | ||
| int SystecRxThread(); | ||
| static std::string_view UsbCanGetErrorText(uint16_t err_code); | ||
| static std::string UsbCanGetStatusText(uint16_t err_code); | ||
|
|
||
| private: | ||
| std::atomic<bool> m_module_in_use{false}; | ||
| std::atomic<size_t> m_queued_reads; | ||
| int m_module_number; | ||
| int m_channel_number; | ||
| int m_port_number; | ||
| DWORD m_baud_rate; | ||
| std::thread m_SystecRxThread; | ||
|
|
||
| std::optional<tUcanHandle> get_module_handle() { | ||
| if (auto mapping = m_module_to_handle_map.find(m_module_number); | ||
| mapping != m_module_to_handle_map.end()) { | ||
| return mapping->second; | ||
| } | ||
| return std::nullopt; | ||
| } | ||
|
|
||
| CanReturnCode vendor_open() noexcept override; | ||
| CanReturnCode vendor_close() noexcept override; | ||
| CanReturnCode vendor_send(const CanFrame& frame) noexcept override; | ||
| CanDiagnostics vendor_diagnostics() noexcept override; | ||
|
|
||
| CanReturnCode init_can_port(); | ||
| static std::mutex m_handles_lock; | ||
| static std::unordered_map<int, tUcanHandle> m_module_to_handle_map; | ||
| static std::unordered_map<int, CanVendorSystec*> m_port_to_vendor_map; | ||
|
|
||
| friend void systec_receive(tUcanHandle UcanHandle_p, DWORD bEvent_p, | ||
| BYTE bChannel_p, void* pArg_p); | ||
|
|
||
| CanReturnCode deinit_channel(tUcanHandle handle) noexcept; | ||
| CanReturnCode deinit_other_channel(tUcanHandle handle, | ||
| CanVendorSystec* other) noexcept; | ||
| }; | ||
|
|
||
| #endif // SRC_INCLUDE_CANVENDORSYSTEC_H_ |
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.
Uh oh!
There was an error while loading. Please reload this page.