From c647d24c29c54311b39632cbf48e9dbc0dc30b83 Mon Sep 17 00:00:00 2001 From: GwnDaan Date: Mon, 16 Dec 2024 19:32:07 +0100 Subject: [PATCH] feat(hardware): add ntcan support --- CMakeLists.txt | 202 ++++++++++++++----------- cmake/FindCAN_Stack.cmake | 15 +- include/ConfigureHardwareComponent.hpp | 1 + src/ConfigureHardwareComponent.cpp | 38 +++-- src/Main.cpp | 1 + 5 files changed, 153 insertions(+), 104 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7820f46..421fcc6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,19 +11,23 @@ set(JUCE_WEB_BROWSER OFF) set(BUILD_TESTING OFF) if(WIN32) - set(CAN_DRIVER "WindowsPCANBasic") - list(APPEND CAN_DRIVER "TouCAN") - - if(NOT (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND MINGW)) - list(APPEND CAN_DRIVER "WindowsInnoMakerUSB2CAN") - else() - message(STATUS "InnoMaker hardware will not be supported in this build because you are using mingw") - endif() - list(APPEND CAN_DRIVER "SYS_TEC") + set(CAN_DRIVER "WindowsPCANBasic") + list(APPEND CAN_DRIVER "TouCAN") + + if(NOT (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND MINGW)) + list(APPEND CAN_DRIVER "WindowsInnoMakerUSB2CAN") + else() + message( + STATUS + "InnoMaker hardware will not be supported in this build because you are using mingw" + ) + endif() + list(APPEND CAN_DRIVER "SYS_TEC") + list(APPEND CAN_DRIVER "NTCAN") elseif(APPLE) - set(CAN_DRIVER "MacCANPCAN") + set(CAN_DRIVER "MacCANPCAN") else() - set(CAN_DRIVER "SocketCAN") + set(CAN_DRIVER "SocketCAN") endif() find_package(JUCE MODULE) @@ -32,21 +36,28 @@ find_package(Threads REQUIRED) juce_add_gui_app( AgISOVirtualTerminal - ICON_BIG doc/smallLogo.png + ICON_BIG + doc/smallLogo.png # image file to use as an icon ICON_SMALL ... - COMPANY_NAME "Open-Agriculture" - COMPANY_COPYRIGHT "Open-Agriculture" - COMPANY_WEBSITE "https://github.com/Open-Agriculture" - PRODUCT_NAME "AgISOVirtualTerminal" - NEEDS_CURL FALSE - NEEDS_WEB_BROWSER FALSE - DESCRIPTION "An ISO11783-6 Server") + COMPANY_NAME + "Open-Agriculture" + COMPANY_COPYRIGHT + "Open-Agriculture" + COMPANY_WEBSITE + "https://github.com/Open-Agriculture" + PRODUCT_NAME + "AgISOVirtualTerminal" + NEEDS_CURL + FALSE + NEEDS_WEB_BROWSER + FALSE + DESCRIPTION + "An ISO11783-6 Server") set_target_properties(AgISOVirtualTerminal PROPERTIES CXX_STANDARD 17) -target_compile_definitions(AgISOVirtualTerminal PRIVATE - JUCE_USE_CURL=0 - JUCE_WEB_BROWSER=0) +target_compile_definitions(AgISOVirtualTerminal PRIVATE JUCE_USE_CURL=0 + JUCE_WEB_BROWSER=0) juce_generate_juce_header(AgISOVirtualTerminal) @@ -87,80 +98,97 @@ target_sources( "src/StringEncodingConversions.cpp" "src/InputListComponent.cpp") - target_include_directories(AgISOVirtualTerminal PRIVATE ${CMAKE_CURRENT_LIST_DIR}/include) target_link_libraries( AgISOVirtualTerminal - PRIVATE juce::juce_gui_extra juce::juce_audio_basics juce::juce_audio_utils isobus::Isobus isobus::HardwareIntegration - isobus::Utility + PRIVATE juce::juce_gui_extra juce::juce_audio_basics juce::juce_audio_utils + isobus::Isobus isobus::HardwareIntegration isobus::Utility PUBLIC juce::juce_recommended_config_flags juce::juce_recommended_lto_flags) if(WIN32) - add_custom_command( - TARGET AgISOVirtualTerminal POST_BUILD - COMMAND "${CMAKE_COMMAND}" -E copy_if_different ${CMAKE_CURRENT_LIST_DIR}/lib/PCANBasic.dll "$" - VERBATIM - ) - - add_custom_command( - TARGET AgISOVirtualTerminal POST_BUILD - COMMAND "${CMAKE_COMMAND}" -E copy_if_different ${CMAKE_CURRENT_LIST_DIR}/lib/Usbcan64.dll "$" - VERBATIM - ) - - add_custom_command( - TARGET AgISOVirtualTerminal POST_BUILD - COMMAND "${CMAKE_COMMAND}" -E copy_if_different ${CMAKE_CURRENT_LIST_DIR}/lib/canal.dll "$" - VERBATIM - ) - - add_custom_command( - TARGET AgISOVirtualTerminal POST_BUILD - COMMAND "${CMAKE_COMMAND}" -E copy_if_different ${CMAKE_CURRENT_LIST_DIR}/lib/InnoMakerUsb2CanLib.dll "$" - VERBATIM - ) + add_custom_command( + TARGET AgISOVirtualTerminal + POST_BUILD + COMMAND + "${CMAKE_COMMAND}" -E copy_if_different + ${CMAKE_CURRENT_LIST_DIR}/lib/PCANBasic.dll + "$" + VERBATIM) + + add_custom_command( + TARGET AgISOVirtualTerminal + POST_BUILD + COMMAND + "${CMAKE_COMMAND}" -E copy_if_different + ${CMAKE_CURRENT_LIST_DIR}/lib/Usbcan64.dll + "$" + VERBATIM) + + add_custom_command( + TARGET AgISOVirtualTerminal + POST_BUILD + COMMAND + "${CMAKE_COMMAND}" -E copy_if_different + ${CMAKE_CURRENT_LIST_DIR}/lib/canal.dll + "$" + VERBATIM) + + add_custom_command( + TARGET AgISOVirtualTerminal + POST_BUILD + COMMAND + "${CMAKE_COMMAND}" -E copy_if_different + ${CMAKE_CURRENT_LIST_DIR}/lib/InnoMakerUsb2CanLib.dll + "$" + VERBATIM) endif() if(APPLE) -install( - TARGETS AgISOVirtualTerminal - RUNTIME - DESTINATION bin - BUNDLE DESTINATION . - COMPONENT applications - ) + install( + TARGETS AgISOVirtualTerminal + RUNTIME DESTINATION bin + BUNDLE DESTINATION . COMPONENT applications) else() -install( - TARGETS AgISOVirtualTerminal - RUNTIME - DESTINATION bin - COMPONENT applications - ) + install(TARGETS AgISOVirtualTerminal RUNTIME DESTINATION bin + COMPONENT applications) endif() if(MSVC) - install(FILES ${CMAKE_CURRENT_LIST_DIR}/lib/Usbcan64.dll DESTINATION bin COMPONENT applications) - install(FILES ${CMAKE_CURRENT_LIST_DIR}/lib/PCANBasic.dll DESTINATION bin COMPONENT applications) - install(FILES ${CMAKE_CURRENT_LIST_DIR}/lib/canal.dll DESTINATION bin COMPONENT applications) - install(FILES ${CMAKE_CURRENT_LIST_DIR}/lib/InnoMakerUsb2CanLib.dll DESTINATION bin COMPONENT applications) + install( + FILES ${CMAKE_CURRENT_LIST_DIR}/lib/Usbcan64.dll + DESTINATION bin + COMPONENT applications) + install( + FILES ${CMAKE_CURRENT_LIST_DIR}/lib/PCANBasic.dll + DESTINATION bin + COMPONENT applications) + install( + FILES ${CMAKE_CURRENT_LIST_DIR}/lib/canal.dll + DESTINATION bin + COMPONENT applications) + install( + FILES ${CMAKE_CURRENT_LIST_DIR}/lib/InnoMakerUsb2CanLib.dll + DESTINATION bin + COMPONENT applications) endif() -set (CPACK_PACKAGE_NAME "AgISOVirtualTerminal") -set (CPACK_PACKAGE_VENDOR "Open-Agriculture") -set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "An ISO11783-6 Server") -set (CPACK_PACKAGE_VERSION "1.2.0") -set (CPACK_PACKAGE_VERSION_MAJOR "1") -set (CPACK_PACKAGE_VERSION_MINOR "2") -set (CPACK_PACKAGE_VERSION_PATCH "0") -set (CPACK_PACKAGE_INSTALL_DIRECTORY "AgISOVirtualTerminal") -set (CPACK_COMPONENTS_ALL applications) -set (CPACK_COMPONENT_APPLICATIONS_DISPLAY_NAME "AgISOVirtualTerminal") -set (CPACK_COMPONENT_APPLICATIONS_DESCRIPTION "A free and open source ISO11783-6 Server") -set (CPACK_PACKAGE_CONTACT "delgrossoengineering@protonmail.com") -set (CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_LIST_DIR}/LICENSE") -set (CPACK_PACKAGE_EXECUTABLES "AgISOVirtualTerminal" "AgISOVirtualTerminal") +set(CPACK_PACKAGE_NAME "AgISOVirtualTerminal") +set(CPACK_PACKAGE_VENDOR "Open-Agriculture") +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "An ISO11783-6 Server") +set(CPACK_PACKAGE_VERSION "1.2.0") +set(CPACK_PACKAGE_VERSION_MAJOR "1") +set(CPACK_PACKAGE_VERSION_MINOR "2") +set(CPACK_PACKAGE_VERSION_PATCH "0") +set(CPACK_PACKAGE_INSTALL_DIRECTORY "AgISOVirtualTerminal") +set(CPACK_COMPONENTS_ALL applications) +set(CPACK_COMPONENT_APPLICATIONS_DISPLAY_NAME "AgISOVirtualTerminal") +set(CPACK_COMPONENT_APPLICATIONS_DESCRIPTION + "A free and open source ISO11783-6 Server") +set(CPACK_PACKAGE_CONTACT "delgrossoengineering@protonmail.com") +set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_LIST_DIR}/LICENSE") +set(CPACK_PACKAGE_EXECUTABLES "AgISOVirtualTerminal" "AgISOVirtualTerminal") set(CPACK_ALL_INSTALL_TYPES Full) set(CPACK_COMPONENT_LIBRARIES_INSTALL_TYPES Full) set(CPACK_COMPONENT_APPLICATIONS_INSTALL_TYPES Full) @@ -171,16 +199,16 @@ set(CPACK_NSIS_MUI_UNICON ${CPACK_NSIS_INSTALLED_ICON_NAME}) set(CPACK_NSIS_DISPLAY_NAME "AgISOVirtualTerminal") set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL ON) set(CMAKE_INSTALL_SYSTEM_RUNTIME_COMPONENT applications) -include (InstallRequiredSystemLibraries) +include(InstallRequiredSystemLibraries) if(APPLE) - set(CPACK_GENERATOR DragNDrop ${CPACK_GENERATOR}) - set(CPACK_GENERATOR "DragNDrop") - set(CPACK_DMG_FORMAT "UDBZ") - set(CPACK_DMG_VOLUME_NAME "${PROJECT_NAME}") - set(CPACK_SYSTEM_NAME "OSX") - set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}") - set(CPACK_PACKAGE_ICON ${CPACK_NSIS_INSTALLED_ICON_NAME}) + set(CPACK_GENERATOR DragNDrop ${CPACK_GENERATOR}) + set(CPACK_GENERATOR "DragNDrop") + set(CPACK_DMG_FORMAT "UDBZ") + set(CPACK_DMG_VOLUME_NAME "${PROJECT_NAME}") + set(CPACK_SYSTEM_NAME "OSX") + set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}") + set(CPACK_PACKAGE_ICON ${CPACK_NSIS_INSTALLED_ICON_NAME}) endif() # Must be after the last CPACK macros diff --git a/cmake/FindCAN_Stack.cmake b/cmake/FindCAN_Stack.cmake index 724f0d2..39bee85 100644 --- a/cmake/FindCAN_Stack.cmake +++ b/cmake/FindCAN_Stack.cmake @@ -1,9 +1,8 @@ -if (NOT TARGET isobus::isobus) -include(FetchContent) -FetchContent_Declare( - CAN_Stack - GIT_REPOSITORY https://github.com/Open-Agriculture/AgIsoStack-plus-plus.git - GIT_TAG 67e231298f2ca8367d437d903e396aa3bcefe080 -) -FetchContent_MakeAvailable(CAN_Stack) +if(NOT TARGET isobus::isobus) + include(FetchContent) + FetchContent_Declare( + CAN_Stack + GIT_REPOSITORY https://github.com/Open-Agriculture/AgIsoStack-plus-plus.git + GIT_TAG db00fa406a6d83bf8cb75cc32650eb29e0f396e9) + FetchContent_MakeAvailable(CAN_Stack) endif() diff --git a/include/ConfigureHardwareComponent.hpp b/include/ConfigureHardwareComponent.hpp index 8ceb34b..eaf3500 100644 --- a/include/ConfigureHardwareComponent.hpp +++ b/include/ConfigureHardwareComponent.hpp @@ -28,6 +28,7 @@ class ConfigureHardwareComponent : public Component ComboBox hardwareInterfaceSelector; TextEditor socketCANNameEditor; TextEditor touCANSerialEditor; + TextEditor ntCANChannelEditor; TextButton okButton; std::vector> &parentCANDrivers; diff --git a/src/ConfigureHardwareComponent.cpp b/src/ConfigureHardwareComponent.cpp index 071c3f8..46e43ee 100644 --- a/src/ConfigureHardwareComponent.cpp +++ b/src/ConfigureHardwareComponent.cpp @@ -10,11 +10,7 @@ #include "isobus/isobus/can_stack_logger.hpp" #include "isobus/utility/to_string.hpp" -#ifdef JUCE_WINDOWS -#include "isobus/hardware_integration/toucan_vscp_canal.hpp" -#elif JUCE_LINUX -#include "isobus/hardware_integration/socket_can_interface.hpp" -#endif +#include "isobus/hardware_integration/available_can_drivers.hpp" ConfigureHardwareComponent::ConfigureHardwareComponent(ConfigureHardwareWindow &parent, std::vector> &canDrivers) : okButton("OK"), @@ -30,16 +26,17 @@ ConfigureHardwareComponent::ConfigureHardwareComponent(ConfigureHardwareWindow & hardwareInterfaceSelector.setTextWhenNothingSelected("Select Hardware Interface"); #ifdef ISOBUS_WINDOWSINNOMAKERUSB2CAN_AVAILABLE - hardwareInterfaceSelector.addItemList({ "PEAK PCAN USB", "Innomaker2CAN", "TouCAN", "SysTec" }, 1); + hardwareInterfaceSelector.addItemList({ "PEAK PCAN USB", "Innomaker2CAN", "TouCAN", "SysTec", "NTCAN" }, 1); #else - hardwareInterfaceSelector.addItemList({ "PEAK PCAN USB", "Innomaker2CAN (not supported with mingw)", "TouCAN", "SysTec" }, 1); + hardwareInterfaceSelector.addItemList({ "PEAK PCAN USB", "Innomaker2CAN (not supported with mingw)", "TouCAN", "SysTec", "NTCAN" }, 1); #endif + int selectedID = 1; for (std::uint8_t i = 0; i < parentCANDrivers.size(); i++) { - if ((nullptr != parentCANDrivers.at(i)) && - (parentCANDrivers.at(i) == isobus::CANHardwareInterface::get_assigned_can_channel_frame_handler(0))) + if ((nullptr != parentCANDrivers.at(i)) && + (parentCANDrivers.at(i) == isobus::CANHardwareInterface::get_assigned_can_channel_frame_handler(0))) { selectedID = i + 1; break; @@ -57,6 +54,14 @@ ConfigureHardwareComponent::ConfigureHardwareComponent(ConfigureHardwareWindow & { touCANSerialEditor.setVisible(false); } + if (5 == hardwareInterfaceSelector.getSelectedId()) + { + ntCANChannelEditor.setVisible(true); + } + else + { + ntCANChannelEditor.setVisible(false); + } repaint(); }; addAndMakeVisible(hardwareInterfaceSelector); @@ -68,6 +73,12 @@ ConfigureHardwareComponent::ConfigureHardwareComponent(ConfigureHardwareWindow & touCANSerialEditor.setTopLeftPosition(10, 140); touCANSerialEditor.setInputFilter(inputFilter, true); addChildComponent(touCANSerialEditor); + ntCANChannelEditor.setName("NTCAN Channel"); + ntCANChannelEditor.setText("0"); + ntCANChannelEditor.setSize(getWidth() - 20, 30); + ntCANChannelEditor.setTopLeftPosition(10, 140); + ntCANChannelEditor.setInputFilter(inputFilter, true); + addChildComponent(ntCANChannelEditor); #elif JUCE_LINUX socketCANNameEditor.setName("SocketCAN Interface Name"); socketCANNameEditor.setText(std::static_pointer_cast(parentCANDrivers.at(0))->get_device_name()); @@ -84,6 +95,11 @@ ConfigureHardwareComponent::ConfigureHardwareComponent(ConfigureHardwareWindow & int serial = touCANSerialEditor.getText().trim().getIntValue(); std::static_pointer_cast(parentCANDrivers.at(hardwareInterfaceSelector.getSelectedId() - 1))->reconfigure(0, static_cast(serial)); } + else if (5 == hardwareInterfaceSelector.getSelectedId()) // NTCAN + { + int channel = ntCANChannelEditor.getText().trim().getIntValue(); + std::static_pointer_cast(parentCANDrivers.at(hardwareInterfaceSelector.getSelectedId() - 1))->reconfigure(channel); + } if (nullptr != isobus::CANHardwareInterface::get_assigned_can_channel_frame_handler(0)) { @@ -120,6 +136,10 @@ void ConfigureHardwareComponent::paint(Graphics &graphics) { graphics.drawFittedText("TouCAN Serial Number", touCANSerialEditor.getBounds().getX(), touCANSerialEditor.getBounds().getY() - 14, touCANSerialEditor.getBounds().getWidth(), 12, Justification::centredLeft, 1); } + else if (5 == hardwareInterfaceSelector.getSelectedId()) + { + graphics.drawFittedText("NTCAN Serial Number (42=Virtual)", touCANSerialEditor.getBounds().getX(), touCANSerialEditor.getBounds().getY() - 14, touCANSerialEditor.getBounds().getWidth(), 12, Justification::centredLeft, 1); + } #elif JUCE_LINUX graphics.drawFittedText("Socket CAN Interface Name", socketCANNameEditor.getBounds().getX(), socketCANNameEditor.getBounds().getY() - 14, socketCANNameEditor.getBounds().getWidth(), 12, Justification::centredLeft, 1); #endif diff --git a/src/Main.cpp b/src/Main.cpp index aa5aabd..ea6c5b3 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -84,6 +84,7 @@ class AgISOVirtualTerminalApplication : public juce::JUCEApplication #endif canDrivers.push_back(std::make_shared(static_cast(0), 0)); canDrivers.push_back(std::make_shared()); + canDrivers.push_back(std::make_shared(0)); #elif defined(JUCE_MAC) canDrivers.push_back(std::make_shared(PCAN_USBBUS1)); #else