-
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
63
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
63 commits
Select commit
Hold shift + click to select a range
1abe999
Create outline of build for CanVendorSystec
jsouter caf8377
Outline of Systec implementation for Windows
jsouter 6440de5
use switch case to handle systec read responses
jsouter df040c4
reconnect systec on a failed send
jsouter e89d908
fix header guard for CanVendorSystec
jsouter 9eba564
use std::copy to copy Systec can message data to CanFrame
jsouter 87ddd7d
small cleanups
jsouter 3a8298c
renames, cleanups, reorderings
jsouter dbc8a1e
fix whitespace issue with warning messages for Systec vendor
jsouter 8517d00
avoid std::copy by initializing vector with data directly
jsouter b9179c7
use lock guards on Systec handle map access
jsouter e9c11b5
use snake_case in CanVendorSystec
jsouter a9cf432
replace Windows specific thread calls with std library calls
jsouter 93fd7c5
don't copy beyond m_bDLC into Systec data vector
jsouter ebab3d2
remove comments copies from STCanScan.cpp
jsouter 540c026
use fallthrough attributes
jsouter 4850aff
Log send errors in systec and use fallthrough attributes
jsouter 70f52a8
only join systec thread if joinable
jsouter 88c9561
switch case formatting
jsouter a94c576
convert indentation to spaces
jsouter 74ee911
remove inline from handle map, make error text function a member method
jsouter bce764b
add uptime to diagnostics for Systec
jsouter c2b80ad
replace broken memcpy with std::copy, some reformatting
jsouter 17889fc
update CanVendorSystec docstring
jsouter dbc934e
check return codes of open and close on systec reconnect
jsouter be434c5
reduce [[ fallthrough ]] use to only where it prevents a warning
jsouter b348b1b
improve vendor return codes for systec
jsouter 0784fe2
make m_receive_thread_flag atomic
jsouter 44e2882
cleanup comments
jsouter be35575
add get_module_handle() method
jsouter bb9cc92
Use systec callback to signal when frame ready to read
jsouter 9a1f951
handle parsing of can and vcan port names for systec
jsouter 32f03f7
fix reconnect logic for multiple channels on same module
jsouter d461b91
fixes for systec build in cmake
jsouter 5b1cc9d
remove :: prefix for systec api calls
jsouter ede7de6
split up systec close logic, deinit hardware on failed open
jsouter 66f70cc
don't build systec for windows by default
jsouter ae0b19d
move reconnect_channel to new method
jsouter 18d14d7
remove erroneous FATAL_ERROR from systec.cmake message
jsouter 4af4598
remove check on message length in systec vendor_send
jsouter 17f4cc7
Add WIP systec test for pcaticswin11
jsouter 78178bd
update test_systec for ELMB id 15
jsouter 7755662
implement suggestions from review
jsouter 5fc4c1e
Use descriptive error messages for systec status in diagnostics.state
jsouter eba8463
fixes for test_systec
jsouter 24cf1c9
throw in systec if invalid bitrate specified
jsouter 8b0e775
wrap init_can_port in try block
jsouter f2b84aa
delay adding CanVendorSystec to port to vendor map
jsouter 9fc556d
Only call deinit on nonzero handles, clean up some logging messages
jsouter 38d9398
Improve logging for error messages
jsouter af2f3f0
Use std::optional for systec handles, avoid use of [] accessor
jsouter 389eb41
use convenience template to log error messages for all ucan calls
jsouter 7a7b349
remove reconnect_channel
jsouter 826cde5
Log status error messages and add to log_entries
jsouter f055593
fix broken if
jsouter 3b2079e
move lock_guard out of deinit_channel to prevent double lock acquisition
jsouter d903c0d
return early from vendor_diagnostics on error
jsouter 23d0853
add config option to deinit both channels when vendor_close called on…
jsouter 61aa60a
add systec to canmodule-utils.py on windows
jsouter 205159f
build systec dependency from zip file installer\
jsouter f55351a
black format python files
jsouter f07c9cd
cpplint fixes
jsouter b53784c
clang-format on CanVendorSystec
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 |
|---|---|---|
|
|
@@ -36,6 +36,13 @@ if (UNIX) | |
| 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 +70,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
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.
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.