Skip to content
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

Libs added #4

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
24 changes: 15 additions & 9 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 7 additions & 7 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -60,7 +64,6 @@
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"regex": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
Expand All @@ -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",
Expand Down Expand Up @@ -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
}
16 changes: 13 additions & 3 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -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"
},
Expand Down Expand Up @@ -80,7 +90,7 @@
"id": "project_name",
"description": "Name of project for plcnext",
"default": "Hello",
"type": "promptString",
"type": "promptString"
}
]
}
2 changes: 1 addition & 1 deletion CPPLINT.cfg
Original file line number Diff line number Diff line change
@@ -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
linelength=100
2 changes: 2 additions & 0 deletions src/libs/Utils/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin/*
intermediate/*
132 changes: 132 additions & 0 deletions src/libs/Utils/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${INCLUDE_INSTALL_DIR}>)

#######################################################################################

################# 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)

#######################################################################################
7 changes: 7 additions & 0 deletions src/libs/Utils/Config.cmake.in
Original file line number Diff line number Diff line change
@@ -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)
9 changes: 9 additions & 0 deletions src/libs/Utils/How_to_use.txt
Original file line number Diff line number Diff line change
@@ -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"'
79 changes: 79 additions & 0 deletions src/libs/Utils/docs/Timer.md
Original file line number Diff line number Diff line change
@@ -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.
Loading
Loading