diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 2621370..0c6a887 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -1,19 +1,25 @@ { "configurations": [ { - "name": "Linux", + "name": "linux", + "compilerPath": "/opt/axcf2152-linux_sdk_2024/sysroots/x86_64-pokysdk-linux/usr/bin/arm-pxc-linux-gnueabi/arm-pxc-linux-gnueabi-g++", + "cStandard": "c99", + "cppStandard": "c++11", + "intelliSenseMode": "linux-gcc-arm", "includePath": [ "${workspaceFolder}/**", "/usr/include/**", - "/opt/plcnext_axcf2152_sdk_2023/sysroots/cortexa9t2hf-neon-pxc-linux-gnueabi/usr/include/**", - "${workspaceFolder}/src/projects/StarterKit/**" + "${workspaceFolder}/src/projects/StarterKit/**", + "/opt/axcf2152-linux_sdk_2024/sysroots/cortexa9t2hf-neon-pxc-linux-gnueabi/usr/include/**" ], - "defines": [], - "compilerPath": "/opt/plcnext_axcf2152_sdk_2023/sysroots/x86_64-pokysdk-linux/usr/bin/arm-pxc-linux-gnueabi/arm-pxc-linux-gnueabi-g++", - "cStandard": "c99", - "cppStandard": "c++14", - "intelliSenseMode": "gcc-arm", - "configurationProvider": "ms-vscode.cpptools" + "compilerArgs": [ + "--sysroot=/opt/axcf2152-linux_sdk_2024/sysroots/cortexa9t2hf-neon-pxc-linux-gnueabi", + "-march=armv7-a", + "-mthumb", + "-mfpu=neon", + "-mfloat-abi=hard", + "-mcpu=cortex-a9" + ] } ], "version": 4 diff --git a/.vscode/settings.json b/.vscode/settings.json index 173fea9..853d217 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -12,16 +12,17 @@ "clang-format.executable": "/usr/bin/clang-format-14", "clang-format.style": "file", "clang-format.language.c.enable": true, + "[cpp]": { + "editor.defaultFormatter": "xaver.clang-format" + }, "C_Cpp.files.exclude": { "**/build/**": true, }, "terminal.integrated.defaultProfile.linux": "zsh", "files.associations": { - "array": "cpp", "cctype": "cpp", "clocale": "cpp", "cmath": "cpp", - "csignal": "cpp", "cstdarg": "cpp", "cstddef": "cpp", "cstdio": "cpp", @@ -30,12 +31,15 @@ "ctime": "cpp", "cwchar": "cpp", "cwctype": "cpp", + "any": "cpp", + "array": "cpp", "atomic": "cpp", "strstream": "cpp", "bit": "cpp", "*.tcc": "cpp", "bitset": "cpp", "chrono": "cpp", + "cinttypes": "cpp", "compare": "cpp", "complex": "cpp", "concepts": "cpp", @@ -60,7 +64,6 @@ "optional": "cpp", "random": "cpp", "ratio": "cpp", - "regex": "cpp", "string_view": "cpp", "system_error": "cpp", "tuple": "cpp", @@ -84,14 +87,12 @@ "streambuf": "cpp", "thread": "cpp", "cfenv": "cpp", - "cinttypes": "cpp", "typeindex": "cpp", "typeinfo": "cpp", "variant": "cpp", "future": "cpp", "charconv": "cpp", "span": "cpp", - "any": "cpp", "*.ipp": "cpp", "codecvt": "cpp", "coroutine": "cpp", @@ -169,6 +170,5 @@ "italic": false } ], - "cmake.ignoreCMakeListsMissing": true, - "C_Cpp.default.compilerPath": "/opt/plcnext_axcf2152_sdk_2023/sysroots/x86_64-pokysdk-linux/usr/bin/arm-pxc-linux-gnueabi/arm-pxc-linux-gnueabi-g++" + "cmake.ignoreCMakeListsMissing": true } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index c43d537..f023533 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -26,7 +26,7 @@ "label": "plcnext_build", "detail": "Build a PLCNext PLM project. Note: do not use this method if the port definitions have changed since it does not generate the required code for this.", "type": "shell", - "command": "export BUILD_TYPE=Release && echo Build PLCNext project for project ${input:project_name} && cd src/projects/${input:project_name} && plcncli build --verbose && plcncli deploy && cp bin/${input:project_name}.pcwlx /home/plc/Windows_PLCNextEngineer_Libraries", + "command": "export BUILD_TYPE=Release && echo Build PLCNext project for project ${input:project_name} && echo Build PLCNext libs && cd src/libs/Utils && plcncli build && cd ../../projects/${input:project_name} && plcncli build --verbose && plcncli deploy", "group": { "kind": "build" }, @@ -36,7 +36,17 @@ "label": "plcnext_gen_build", "detail": "Build a PLCNext PLM project", "type": "shell", - "command": "export BUILD_TYPE=Release && echo Build PLCNext release project for project ${input:project_name} && cd src/projects/${input:project_name} && plcncli generate code --verbose && plcncli generate config --verbose && plcncli build --verbose && plcncli deploy && cp bin/${input:project_name}.pcwlx /home/plc/Windows_PLCNextEngineer_Libraries && echo 'File copied successfully'", + "command": "export BUILD_TYPE=Release && echo Build PLCNext release project for project ${input:project_name} && echo Build PLCNext libs && cd src/libs/Utils && plcncli build && cd ../../projects/${input:project_name} && plcncli generate code --verbose && plcncli generate config --verbose && plcncli build --verbose && plcncli deploy", + "group": { + "kind": "build" + }, + "problemMatcher": "$gcc" + }, + { + "label": "plcnext_libs_build", + "detail": "Build Libs", + "type": "shell", + "command": "export BUILD_TYPE=Release && echo Build PLCNext libs && cd src/libs/Utils && plcncli build ", "group": { "kind": "build" }, @@ -80,7 +90,7 @@ "id": "project_name", "description": "Name of project for plcnext", "default": "Hello", - "type": "promptString", + "type": "promptString" } ] } \ No newline at end of file diff --git a/CPPLINT.cfg b/CPPLINT.cfg index 6b320fc..e2cc532 100644 --- a/CPPLINT.cfg +++ b/CPPLINT.cfg @@ -1,3 +1,3 @@ # Remove annoying cpplint tests if they are too much/annoying filter=-legal/copyright,-whitespace/blank_line,-whitespace/end_of_line,-build/header_guard,-whitespace/comments,-readability/todo,-whitespace/newline,-whitespace/empty_loop_body -linelength=120 \ No newline at end of file +linelength=100 \ No newline at end of file diff --git a/src/libs/Utils/.gitignore b/src/libs/Utils/.gitignore new file mode 100644 index 0000000..9e6c307 --- /dev/null +++ b/src/libs/Utils/.gitignore @@ -0,0 +1,2 @@ +bin/* +intermediate/* \ No newline at end of file diff --git a/src/libs/Utils/CMakeLists.txt b/src/libs/Utils/CMakeLists.txt new file mode 100644 index 0000000..f9eae6f --- /dev/null +++ b/src/libs/Utils/CMakeLists.txt @@ -0,0 +1,132 @@ +cmake_minimum_required(VERSION 3.13) + +project(Utils) + +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release) +endif() + +set (ArpProgramming_ARP_IO_PROFIBUS_LIBRARY FALSE) + +################# create target ####################################################### + +file(GLOB_RECURSE Headers CONFIGURE_DEPENDS src/*.h src/*.hpp src/*.hxx) +file(GLOB_RECURSE PublicHeaders CONFIGURE_DEPENDS include/*.h include/*.hpp include/*.hxx) +file(GLOB_RECURSE Sources CONFIGURE_DEPENDS src/*.cpp) +add_library(${CMAKE_PROJECT_NAME} SHARED ${Headers} ${PublicHeaders} ${Sources}) + +####################################################################################### + +################# set install directories ############################################# + +string(REGEX REPLACE "^.*\\(([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*$" "\\1" _ARP_SHORT_DEVICE_VERSION ${ARP_DEVICE_VERSION}) +set(INCLUDE_INSTALL_DIR ${ARP_DEVICE}_${_ARP_SHORT_DEVICE_VERSION}/${CMAKE_BUILD_TYPE}/include) +set(LIB_INSTALL_DIR ${ARP_DEVICE}_${_ARP_SHORT_DEVICE_VERSION}/${CMAKE_BUILD_TYPE}/lib/${CMAKE_PROJECT_NAME}) + +####################################################################################### + +################# project include-paths ############################################### + +target_include_directories(${CMAKE_PROJECT_NAME} + PRIVATE + $ + PUBLIC + $ + $) + +####################################################################################### + +################# include arp cmake module path ####################################### + +list(INSERT CMAKE_MODULE_PATH 0 "${ARP_TOOLCHAIN_CMAKE_MODULE_PATH}") + +####################################################################################### + +################# set RPATH to ORIGIN for thrid party libraries ####################### +# Only by setting this is it possible to use libraries which are not already # +# installed in the default install locations on the target. # +####################################################################################### + +if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows" AND NOT "$ENV{SHELL}" MATCHES ".*[\/\\]bash($|.exe$)") + # With Windows there is a known issue with CMake: https://gitlab.kitware.com/cmake/cmake/-/issues/21291 + # This is currently the only way to set the RPATH to $ORIGIN in Windows + target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE "-Wl,-rpath,\$$ORIGIN") +else() + set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES INSTALL_RPATH $ORIGIN) +endif() + +####################################################################################### + +################# set link options #################################################### +# WARNING: Without --no-undefined the linker will not check, whether all necessary # +# libraries are linked. When a library which is necessary is not linked, # +# the firmware will crash and there will be NO indication why it crashed. # +####################################################################################### + +target_link_options(${CMAKE_PROJECT_NAME} PRIVATE LINKER:--no-undefined) + +####################################################################################### + +################# add link targets #################################################### + +find_package(ArpDevice REQUIRED) +find_package(ArpProgramming REQUIRED) + +target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE ArpDevice ArpProgramming) + +####################################################################################### + +################# configure cmake package config files ################################ +# IMPORTANT: The library version is set here. # +####################################################################################### + +include(CMakePackageConfigHelpers) +configure_package_config_file( + "Config.cmake.in" + "${CMAKE_PROJECT_NAME}Config.cmake" + INSTALL_DESTINATION ${ARP_DEVICE}_${_ARP_SHORT_DEVICE_VERSION}/${CMAKE_BUILD_TYPE}/cmake + PATH_VARS + INCLUDE_INSTALL_DIR + LIB_INSTALL_DIR + ) + +write_basic_package_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}ConfigVersion.cmake + VERSION 1.0.0 + COMPATIBILITY SameMajorVersion + ) + +####################################################################################### + +########## install public headers while retaining the directory structure ############# + +file(GLOB _DEPLOY_HEADERS_AND_DIRS include/*) +set(_DIRS_TO_DEPLOY "") +set(_FILES_TO_DEPLOY "") +foreach(ITEM ${_DEPLOY_HEADERS_AND_DIRS}) + if( IS_DIRECTORY "${ITEM}" ) + list( APPEND _DIRS_TO_DEPLOY "${ITEM}" ) + elseif(NOT ITEM MATCHES ".*ADD_PUBLIC_HEADERS_HERE") + list( APPEND _FILES_TO_DEPLOY "${ITEM}" ) + endif() +endforeach() +install( FILES ${_FILES_TO_DEPLOY} DESTINATION ${INCLUDE_INSTALL_DIR} ) +install( DIRECTORY ${_DIRS_TO_DEPLOY} DESTINATION ${INCLUDE_INSTALL_DIR} ) +unset(_FILES_TO_DEPLOY) +unset(_DIRS_TO_DEPLOY) +unset(_DEPLOY_HEADERS_AND_DIRS) + +####################################################################################### + +################# install CMake package and library ################################### + +install(TARGETS ${CMAKE_PROJECT_NAME} EXPORT ${CMAKE_PROJECT_NAME}-targets DESTINATION ${LIB_INSTALL_DIR}) +install(EXPORT ${CMAKE_PROJECT_NAME}-targets DESTINATION ${LIB_INSTALL_DIR}) +install( + FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}ConfigVersion.cmake" + DESTINATION "${ARP_DEVICE}_${_ARP_SHORT_DEVICE_VERSION}/${CMAKE_BUILD_TYPE}/cmake" + ) +unset(_ARP_SHORT_DEVICE_VERSION) + +####################################################################################### \ No newline at end of file diff --git a/src/libs/Utils/Config.cmake.in b/src/libs/Utils/Config.cmake.in new file mode 100644 index 0000000..c8281cc --- /dev/null +++ b/src/libs/Utils/Config.cmake.in @@ -0,0 +1,7 @@ +@PACKAGE_INIT@ + +include( "@PACKAGE_LIB_INSTALL_DIR@/Utils-targets.cmake" ) + +set_and_check(Utils_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@") + +check_required_components(Utils) \ No newline at end of file diff --git a/src/libs/Utils/How_to_use.txt b/src/libs/Utils/How_to_use.txt new file mode 100644 index 0000000..9768841 --- /dev/null +++ b/src/libs/Utils/How_to_use.txt @@ -0,0 +1,9 @@ ++ Copy eyerthing under the 'bin' directory of this project to the 'external' + directory of the consuming project ++ In the CMakeLists.txt of the consuming project add the following line before + the 'target_link_libraries' call + find_package(Utils REQUIRED) ++ Add in the CMakeLists.txt of the consuming project to the + 'target_link_libraries' call the previousely found package 'Utils' ++ Use public headers of this project by including them in the consuming project + e.g. '#include "Utils/UtilsClass.hpp"' \ No newline at end of file diff --git a/src/libs/Utils/docs/Timer.md b/src/libs/Utils/docs/Timer.md new file mode 100644 index 0000000..e8610c8 --- /dev/null +++ b/src/libs/Utils/docs/Timer.md @@ -0,0 +1,79 @@ +Timer Class Documentation +Overview +The Timer class provides a flexible way to implement timer-based functionalities similar to TON (Timer On Delay) and TOF (Timer Off Delay) used in ladder logic. This class allows you to configure and use the timer for different purposes based on the selected mode. + +Features +TON (Timer On Delay): Delays the output turning on after the input condition becomes true. +TOF (Timer Off Delay): Delays the output turning off after the input condition becomes false. +Get Elapsed Time: Allows you to retrieve the current elapsed time since the timer started. +Restart Timer: Resets the timer, clearing the internal state. +Usage +1. Include the Timer Header +Ensure that you include the Timer class header in your source file: + +2. Create a Timer Instance +To create a timer, you need to specify the mode (TON or TOF) and the timeout duration. + +cpp +Copy code +// Create a TON timer with a 1-second delay +Utils::Timer tonTimer(Utils::TimerMode::TON, std::chrono::milliseconds(1000)); + +// Create a TOF timer with a 1-second delay +Utils::Timer tofTimer(Utils::TimerMode::TOF, std::chrono::milliseconds(1000)); +3. Update the Timer +Call the update() method in your loop or control logic to process the input signal and get the timer's output. + +cpp +Copy code +bool input = /* your input condition */; + +bool tonOutput = tonTimer.update(input); // Update and get output for TON +bool tofOutput = tofTimer.update(input); // Update and get output for TOF +For TON mode: The output will be true only after the input has been true for the specified timeout duration. +For TOF mode: The output will stay true as long as the input remains true and will turn false after the timeout duration once the input becomes false. +4. Get Elapsed Time +You can retrieve the current elapsed time since the timer started in milliseconds using the getCurrentTime() method. + +cpp +Copy code +double tonTime = tonTimer.getCurrentTime(); // Get elapsed time for TON +double tofTime = tofTimer.getCurrentTime(); // Get elapsed time for TOF +5. Restart the Timer +If needed, you can reset the timer and clear its internal state using the restart() method. + +cpp +Copy code +tonTimer.restart(); // Restart the TON timer +tofTimer.restart(); // Restart the TOF timer +Example +Here’s a complete example demonstrating how to use the Timer class: + +cpp +Copy code +#include "UtilsTimer.hpp" + +int main() +{ + // Create timers + Utils::Timer tonTimer(Utils::TimerMode::TON, std::chrono::milliseconds(1000)); + Utils::Timer tofTimer(Utils::TimerMode::TOF, std::chrono::milliseconds(1000)); + + bool input = /* your input condition */; + + // Update timers + bool tonOutput = tonTimer.update(input); + bool tofOutput = tofTimer.update(input); + + // Get elapsed time + double tonTime = tonTimer.getCurrentTime(); + double tofTime = tofTimer.getCurrentTime(); + + // Optionally restart timers + tonTimer.restart(); + tofTimer.restart(); + + return 0; +} +Conclusion +The Timer class is a versatile tool for implementing timer-based logic in your application. With support for both TON and TOF modes, it offers a flexible solution for timing tasks. By following this guide, you can quickly integrate the Timer class into your project and start utilizing its features. \ No newline at end of file diff --git a/src/libs/Utils/external/ADD_DEPENDENT_LIBRARIES_HERE.txt b/src/libs/Utils/external/ADD_DEPENDENT_LIBRARIES_HERE.txt new file mode 100644 index 0000000..6a8363f --- /dev/null +++ b/src/libs/Utils/external/ADD_DEPENDENT_LIBRARIES_HERE.txt @@ -0,0 +1,19 @@ +The CLI will automatically set the CMAKE_PREFIX_PATH to find CMake packages to +this directory or a sub-directory of this directory. To decide which directory +to use for the CMAKE_PREFIX_PATH the CLI looks for a directory with the name +_. + +To choose such a directory the target_name must match the current build target +name and the version must be lower or equal to the current build target +version. If such a directory is found the CLI looks whether the directory +contains the current build type (Release, Debug, ...). If no such directory is +found it looks for a directory named "Release". + +If the CLI finds the build type directory or the "Release" directory it uses +this directory as CMAKE_PREFIX_PATH. If not it uses as fallback the found +target specific directory. If that is not found it uses the external directory. +If the CMAKE_PREFIX_PATH is already set by a command line option it will not +override the set value. + +Please make sure that if the libraries which are used by this project use other +libraries themself, that the library must have the RPATH set to $ORIGIN. \ No newline at end of file diff --git "a/src/libs/Utils/external/ADD_DEPENDENT_LIBRARIES_HERE.txt\357\200\272Zone.Identifier" "b/src/libs/Utils/external/ADD_DEPENDENT_LIBRARIES_HERE.txt\357\200\272Zone.Identifier" new file mode 100644 index 0000000..e69de29 diff --git a/src/libs/Utils/include/ADD_PUBLIC_HEADERS_HERE.txt b/src/libs/Utils/include/ADD_PUBLIC_HEADERS_HERE.txt new file mode 100644 index 0000000..c927b01 --- /dev/null +++ b/src/libs/Utils/include/ADD_PUBLIC_HEADERS_HERE.txt @@ -0,0 +1,3 @@ +This directory will automatically be deployed to the CMake package. Therefore +all headers that need to be visible to the user of the library need to be +placed here. \ No newline at end of file diff --git "a/src/libs/Utils/include/ADD_PUBLIC_HEADERS_HERE.txt\357\200\272Zone.Identifier" "b/src/libs/Utils/include/ADD_PUBLIC_HEADERS_HERE.txt\357\200\272Zone.Identifier" new file mode 100644 index 0000000..e69de29 diff --git a/src/libs/Utils/include/Utils/error.hpp b/src/libs/Utils/include/Utils/error.hpp new file mode 100644 index 0000000..4fbc71c --- /dev/null +++ b/src/libs/Utils/include/Utils/error.hpp @@ -0,0 +1,17 @@ +#pragma once + +/* Class that will allow error catching*/ + +namespace Utils +{ + +class Error +{ + public: + virtual bool hasWarning() = 0; + virtual bool hasError() = 0; + virtual void clearWarnings() = 0; + virtual void clear() = 0; +}; + +} // namespace Utils \ No newline at end of file diff --git a/src/libs/Utils/include/Utils/util.hpp b/src/libs/Utils/include/Utils/util.hpp new file mode 100644 index 0000000..895299b --- /dev/null +++ b/src/libs/Utils/include/Utils/util.hpp @@ -0,0 +1,107 @@ +#pragma once +#include "Arp/System/Commons/Chrono/SystemTick.hpp" +#include + +namespace Utils +{ + +using namespace Arp::System::Commons::Chrono; + +enum class TimerMode +{ + TON, // Timer On Delay + TOF // Timer Off Delay +}; + +class Timer +{ + public: + Timer(TimerMode mode, std::chrono::milliseconds timeout) + : mode_(mode), tTimeoutMicros_(timeout.count() * 1000), isTiming_(false), output_(false), + tStartMicros_(0) + { + } + + // Update function to process the input and return the timer's output + bool update(bool input) + { + const int64_t now = SystemTick::GetMicroTick().count(); + + if (mode_ == TimerMode::TON) + { + return updateTON(input, now); + } + else // TimerMode::TOF + { + return updateTOF(input, now); + } + } + + // Method to get the current elapsed time in milliseconds + double getElapsedTime() const + { + const int64_t now = SystemTick::GetMicroTick().count(); + return static_cast(now - tStartMicros_) / 1000.0; + } + + // Method to restart the timer + void restart() + { + tStartMicros_ = SystemTick::GetMicroTick().count(); + isTiming_ = false; + output_ = false; + } + + private: + TimerMode mode_; + int64_t tTimeoutMicros_; + bool isTiming_; + bool output_; + int64_t tStartMicros_; + + bool updateTON(bool input, int64_t now) + { + if (input) + { + if (!isTiming_) + { + tStartMicros_ = now; + isTiming_ = true; + } + if (now - tStartMicros_ >= tTimeoutMicros_) + { + return true; + } + } + else + { + isTiming_ = false; + } + return false; + } + + bool updateTOF(bool input, int64_t now) + { + if (!input) + { + if (!isTiming_) + { + tStartMicros_ = now; + isTiming_ = true; + output_ = true; + } + if (now - tStartMicros_ >= tTimeoutMicros_) + { + output_ = false; + } + } + else + { + isTiming_ = false; + output_ = true; + } + return output_; + } +}; + +} // namespace Utils diff --git a/src/libs/Utils/plcnext.proj b/src/libs/Utils/plcnext.proj new file mode 100644 index 0000000..c83536b --- /dev/null +++ b/src/libs/Utils/plcnext.proj @@ -0,0 +1,7 @@ + + + AXCF2152,2024.0.0 LTS (24.0.0.102) + consumablelibrary + 4.0 + Utils + \ No newline at end of file diff --git a/src/libs/Utils/src/util.cpp b/src/libs/Utils/src/util.cpp new file mode 100644 index 0000000..29dca82 --- /dev/null +++ b/src/libs/Utils/src/util.cpp @@ -0,0 +1 @@ +#include "Utils/util.hpp" \ No newline at end of file diff --git a/src/projects/StarterKit/CMakeLists.txt b/src/projects/StarterKit/CMakeLists.txt index b944d0c..67a628d 100644 --- a/src/projects/StarterKit/CMakeLists.txt +++ b/src/projects/StarterKit/CMakeLists.txt @@ -27,8 +27,11 @@ target_include_directories(${CMAKE_PROJECT_NAME} list(INSERT CMAKE_MODULE_PATH 0 "${ARP_TOOLCHAIN_CMAKE_MODULE_PATH}") +set (Utils_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../libs/Utils/bin/AXCF2152_24.0.0.102/${CMAKE_BUILD_TYPE}/cmake) + ####################################################################################### + ################# set RPATH to ORIGIN for third party libraries ####################### # Only by setting this is it possible to use libraries which are not already # # installed in the default install locations on the target. # @@ -58,8 +61,9 @@ target_link_options(${CMAKE_PROJECT_NAME} PRIVATE LINKER:--no-undefined) find_package(ArpDevice REQUIRED) find_package(ArpProgramming REQUIRED) +find_package(Utils CONFIG REQUIRED) -target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE ArpDevice ArpProgramming) +target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE ArpDevice ArpProgramming Utils) ####################################################################################### diff --git a/src/projects/StarterKit/intermediate/code/StarterKitLibrary.meta.cpp b/src/projects/StarterKit/intermediate/code/StarterKitLibrary.meta.cpp index 2f04153..7ed4176 100644 --- a/src/projects/StarterKit/intermediate/code/StarterKitLibrary.meta.cpp +++ b/src/projects/StarterKit/intermediate/code/StarterKitLibrary.meta.cpp @@ -53,7 +53,7 @@ using namespace Arp::Plc::Commons::Meta; { "Command", offsetof(::StarterKit::StarterKitProgram, command_), DataType::Struct, CTN(), sizeof(StarterKit::StarterKitProgram::StarterKitCommand), alignof(StarterKit::StarterKitProgram::StarterKitCommand), { }, StandardAttribute::Input | StandardAttribute::Opc }, { "Config", offsetof(::StarterKit::StarterKitProgram, config_), DataType::Struct, CTN(), sizeof(StarterKit::StarterKitProgram::StarterKitConfig), alignof(StarterKit::StarterKitProgram::StarterKitConfig), { }, StandardAttribute::Input | StandardAttribute::Opc }, { "Data", offsetof(::StarterKit::StarterKitProgram, data_), DataType::Struct, CTN(), sizeof(StarterKit::StarterKitProgram::StarterKitData), alignof(StarterKit::StarterKitProgram::StarterKitData), { }, StandardAttribute::Output | StandardAttribute::Opc }, - { "DIN01", offsetof(::StarterKit::StarterKitProgram, digitalIn1_), DataType::Boolean, String::Empty, sizeof(Arp::boolean), alignof(Arp::boolean), { }, StandardAttribute::Input | StandardAttribute::Opc }, + { "DIN01", offsetof(::StarterKit::StarterKitProgram, dIN01_), DataType::Boolean, String::Empty, sizeof(Arp::boolean), alignof(Arp::boolean), { }, StandardAttribute::Input | StandardAttribute::Opc }, { "DIN02", offsetof(::StarterKit::StarterKitProgram, dIN02_), DataType::Boolean, String::Empty, sizeof(Arp::boolean), alignof(Arp::boolean), { }, StandardAttribute::Input | StandardAttribute::Opc }, { "DIN03", offsetof(::StarterKit::StarterKitProgram, dIN03_), DataType::Boolean, String::Empty, sizeof(Arp::boolean), alignof(Arp::boolean), { }, StandardAttribute::Input | StandardAttribute::Opc }, { "DIN04", offsetof(::StarterKit::StarterKitProgram, dIN04_), DataType::Boolean, String::Empty, sizeof(Arp::boolean), alignof(Arp::boolean), { }, StandardAttribute::Input | StandardAttribute::Opc }, diff --git a/src/projects/StarterKit/plcnext.proj b/src/projects/StarterKit/plcnext.proj index 0490244..ed7e8af 100644 --- a/src/projects/StarterKit/plcnext.proj +++ b/src/projects/StarterKit/plcnext.proj @@ -5,5 +5,5 @@ StarterKit true true - AXCF2152,2023.0.0 LTS (23.0.0.65) + AXCF2152,2024.0.0 LTS (24.0.0.102) \ No newline at end of file diff --git a/src/projects/StarterKit/src/StarterKitProgram.cpp b/src/projects/StarterKit/src/StarterKitProgram.cpp index 1fbd431..51f3163 100644 --- a/src/projects/StarterKit/src/StarterKitProgram.cpp +++ b/src/projects/StarterKit/src/StarterKitProgram.cpp @@ -4,8 +4,9 @@ namespace StarterKit { -uint32 -StarterKitProgram::convertMillivoltsToRange(uint32 millivolts, uint32 minRange, uint32 maxRange) +uint32_t +StarterKitProgram::convertMillivoltsToRange(uint32_t millivolts, uint32_t minRange, + uint32_t maxRange) { // Convert millivolts to volts as a floating-point number double voltage = static_cast(millivolts) / 1000.0; @@ -16,14 +17,16 @@ StarterKitProgram::convertMillivoltsToRange(uint32 millivolts, uint32 minRange, // Cast the result to uint32 for return return scaled; -} +}; void StarterKitProgram::Execute() { // implement program - if (config_.allowOutputs && command_.setOutput) + // bool tonOutput = tonTimer.update(dIN02_); + + if (config_.allowOutputs && command_.setOutput || dIN01_) { // control two fans for cooling dOUT01_ = true; @@ -37,15 +40,13 @@ StarterKitProgram::Execute() if (command_.readAnalog1) { - uint32 analogReading = aiN1_; - - log.Info("Analog one reading: {0}", analogReading); + uint32_t analogReading = aiN1_; - const double scaledReading = convertMillivoltsToRange( - analogReading, config_.analogInOne.minRange, config_.analogInOne.maxRange); + const double scaledReading = convertMillivoltsToRange(aiN1_, config_.analogInOne.minRange, + config_.analogInOne.maxRange); log.Info("Scaled analog reading {0}", scaledReading); } -} +}; } // end of namespace StarterKit diff --git a/src/projects/StarterKit/src/StarterKitProgram.hpp b/src/projects/StarterKit/src/StarterKitProgram.hpp index f8d66b5..278401a 100644 --- a/src/projects/StarterKit/src/StarterKitProgram.hpp +++ b/src/projects/StarterKit/src/StarterKitProgram.hpp @@ -3,6 +3,9 @@ #include "Arp/System/Commons/Logging.h" #include "Arp/System/Core/Arp.h" #include "StarterKitComponent.hpp" +#include "Utils/error.hpp" +#include "Utils/util.hpp" + namespace StarterKit { @@ -85,7 +88,7 @@ class StarterKitProgram : public ProgramBase, private Loggable